Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ReadProcessMemory (or "What's wrong with my code?")

ReadProcessMemory (or "What's wrong with my code?")

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Steve The Plant
    wrote on last edited by
    #1

    I'm trying to write a debugger for another program I've written, but I'm having trouble getting OutputDebugString messages from it. While it seems to me I'm doing everything ok, I get garbage as the string, even though the event correctly reports the size of the string. DEBUG_EVENT oDebugEvent; if (WaitForDebugEvent(&oDebugEvent, INFINITE)) { if (oDebugEvent.dwDebugEventCode == OUTPUT_DEBUG_STRING_EVENT) { char strTempString[1000] = ""; if (!ReadProcessMemory((HANDLE)dwProcessHandle, oDebugEvent.u.DebugString.lpDebugStringData, strTempString, oDebugEvent.u.DebugString.nDebugStringLength, NULL)) { printf("ReadProcessMemory() FAILED\n"); printf("ERROR NUMER: %d", GetLastError()); } else { printf("%s\n", strTempString); } } ContinueDebugEvent(oDebugEvent.dwProcessId, oDebugEvent.dwThreadId, DBG_CONTINUE); } The only thing I wonder about is the oDebugEvent.u.DebugString.lpDebugStringData I'm passing to ReadProcessMemory(). In MSDN, ReadProcessMemory() needs a "Pointer to the base address in the specified process from which to read." Does this mean I'm not passing the right value to it? If not, then what? Steve The Plant ps: as a side note, I've tried to indent the code, but it just shows up as a chunk. Anyway to fix that?

    P 1 Reply Last reply
    0
    • S Steve The Plant

      I'm trying to write a debugger for another program I've written, but I'm having trouble getting OutputDebugString messages from it. While it seems to me I'm doing everything ok, I get garbage as the string, even though the event correctly reports the size of the string. DEBUG_EVENT oDebugEvent; if (WaitForDebugEvent(&oDebugEvent, INFINITE)) { if (oDebugEvent.dwDebugEventCode == OUTPUT_DEBUG_STRING_EVENT) { char strTempString[1000] = ""; if (!ReadProcessMemory((HANDLE)dwProcessHandle, oDebugEvent.u.DebugString.lpDebugStringData, strTempString, oDebugEvent.u.DebugString.nDebugStringLength, NULL)) { printf("ReadProcessMemory() FAILED\n"); printf("ERROR NUMER: %d", GetLastError()); } else { printf("%s\n", strTempString); } } ContinueDebugEvent(oDebugEvent.dwProcessId, oDebugEvent.dwThreadId, DBG_CONTINUE); } The only thing I wonder about is the oDebugEvent.u.DebugString.lpDebugStringData I'm passing to ReadProcessMemory(). In MSDN, ReadProcessMemory() needs a "Pointer to the base address in the specified process from which to read." Does this mean I'm not passing the right value to it? If not, then what? Steve The Plant ps: as a side note, I've tried to indent the code, but it just shows up as a chunk. Anyway to fix that?

      P Offline
      P Offline
      Paolo Messina
      wrote on last edited by
      #2

      Hi, Just some stupid ideas: - could it be a Unicode/Ansi mismatch? (DebugString.fUnicode) - a dynamic buffer to store the result would be better, since you know the exact length of the string (otherwise you could have a buffer overrun) As for the indent problem, use <PRE> </PRE> tags to enclose the source code. Cheers, Paolo ------ "airplane is cool, but space shuttle is even better" (J. Kaczorowski)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups