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. critical error

critical error

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelp
4 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.
  • M Offline
    M Offline
    mpapeo
    wrote on last edited by
    #1

    Why do i get a critical error here in this code. I want to read succesive pages in a process memory int main(int argc, char **argv[]) { PROCESS_INFORMATION pi; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ HANDLE hProcess; BYTE buf[200000]; DWORD bufsize = sizeof buf; DWORD baseaddr = 0; LPCVOID lpAddress = 0; PMEMORY_BASIC_INFORMATION lpBuffer = 0; DWORD dwLength = 0; DWORD flNewProtect =0; PDWORD lpflOldProtect = 0; DWORD dwSize =0; LPCVOID lpBaseAddress = 0; DWORD nSize = 0; DWORD buff = 0; LPDWORD lpNumberOfBytesRead = sizeof buf; if (argc !=2) { printf("Error in the input line, Usage: Inputfile"); exit(0); } //menu(); printf("Process %d creates a child process\n",GetCurrentProcessId());//print out our process ID GetStartupInfo(&si); // Call CreateProcess, telling it to run an exe file CreateProcess(NULL,/* lpApplicationName */ argv[1],/* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE, /* dwCreationFlags */ NULL, /* lpEnvironment */ NULL, /* lpCurDir */ &si, /* lpStartupInfo */ &pi /* lpProcInfo */ ); hProcess = pi.hProcess; printf("New Process ID: %d ",pi.dwProcessId); printf("has started \n"); VirtualQueryEx( hProcess, // handle to process lpAddress, // address of region lpBuffer,// address of information buffer dwLength,// size of buffer GetLastError() ); //*to avoid crashing VirtualProtectEx( hProcess, // handle to process lpAddress, // address of region of committed pages dwSize, // size of region flNewProtect, // desired access protection lpflOldProtect );// address of variable to get old protection ZeroMemory(buf, sizeof(buf)); if( ReadProcessMemory( hProcess, lpBaseAddress, nSize, bufsize, buff ) == FALSE ) { printf("\nProcess ID %d ",pi.dwProcessId); printf (" memory read failed (errcode: %d)", GetLastError()); printf("\nmemory read: \n",&buf); } else { printf("\nProcess ID %d ",pi.dwProcessId); printf("memory read: \n",buf); } return (0); } oam

    J 1 Reply Last reply
    0
    • M mpapeo

      Why do i get a critical error here in this code. I want to read succesive pages in a process memory int main(int argc, char **argv[]) { PROCESS_INFORMATION pi; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ HANDLE hProcess; BYTE buf[200000]; DWORD bufsize = sizeof buf; DWORD baseaddr = 0; LPCVOID lpAddress = 0; PMEMORY_BASIC_INFORMATION lpBuffer = 0; DWORD dwLength = 0; DWORD flNewProtect =0; PDWORD lpflOldProtect = 0; DWORD dwSize =0; LPCVOID lpBaseAddress = 0; DWORD nSize = 0; DWORD buff = 0; LPDWORD lpNumberOfBytesRead = sizeof buf; if (argc !=2) { printf("Error in the input line, Usage: Inputfile"); exit(0); } //menu(); printf("Process %d creates a child process\n",GetCurrentProcessId());//print out our process ID GetStartupInfo(&si); // Call CreateProcess, telling it to run an exe file CreateProcess(NULL,/* lpApplicationName */ argv[1],/* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE, /* dwCreationFlags */ NULL, /* lpEnvironment */ NULL, /* lpCurDir */ &si, /* lpStartupInfo */ &pi /* lpProcInfo */ ); hProcess = pi.hProcess; printf("New Process ID: %d ",pi.dwProcessId); printf("has started \n"); VirtualQueryEx( hProcess, // handle to process lpAddress, // address of region lpBuffer,// address of information buffer dwLength,// size of buffer GetLastError() ); //*to avoid crashing VirtualProtectEx( hProcess, // handle to process lpAddress, // address of region of committed pages dwSize, // size of region flNewProtect, // desired access protection lpflOldProtect );// address of variable to get old protection ZeroMemory(buf, sizeof(buf)); if( ReadProcessMemory( hProcess, lpBaseAddress, nSize, bufsize, buff ) == FALSE ) { printf("\nProcess ID %d ",pi.dwProcessId); printf (" memory read failed (errcode: %d)", GetLastError()); printf("\nmemory read: \n",&buf); } else { printf("\nProcess ID %d ",pi.dwProcessId); printf("memory read: \n",buf); } return (0); } oam

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #2

      Well to start with you can not do things like this: LPDWORD lpNumberOfBytesRead = sizeof buf; The variable lpNumberOfBytesRead is a pointer and a pointer holds the address of where the data is stored. What the above line is doing is setting the address to the value sizeof(buf), which is not an address. Change to: DWORD NumberOfBytesRead = sizeof(buf); or this (since its initial value may not matter) DWORD NumberOfBytesRead = 0; and pass like this SomeFunction(...,...,&NumberOfBytesRead); Now the following from your code, should make any C++ compiler choke (fail with errors): ReadProcessMemory( hProcess, lpBaseAddress, nSize, // This should be a pointer to buffer bufsize, buff ); // This should be a pointer to DWORD The correct arguments are ReadProcessMemory( hProcess, lpBaseAddress, buf, bufsize, &NumberOfBytesRead); or ReadProcessMemory( hProcess, lpBaseAddress, buf, sizeof(buf), &NumberOfBytesRead); I have no doudt that there are several other things wrong with this code, but the above should help you get started on figuring out what they are. INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

      M 1 Reply Last reply
      0
      • J John R Shaw

        Well to start with you can not do things like this: LPDWORD lpNumberOfBytesRead = sizeof buf; The variable lpNumberOfBytesRead is a pointer and a pointer holds the address of where the data is stored. What the above line is doing is setting the address to the value sizeof(buf), which is not an address. Change to: DWORD NumberOfBytesRead = sizeof(buf); or this (since its initial value may not matter) DWORD NumberOfBytesRead = 0; and pass like this SomeFunction(...,...,&NumberOfBytesRead); Now the following from your code, should make any C++ compiler choke (fail with errors): ReadProcessMemory( hProcess, lpBaseAddress, nSize, // This should be a pointer to buffer bufsize, buff ); // This should be a pointer to DWORD The correct arguments are ReadProcessMemory( hProcess, lpBaseAddress, buf, bufsize, &NumberOfBytesRead); or ReadProcessMemory( hProcess, lpBaseAddress, buf, sizeof(buf), &NumberOfBytesRead); I have no doudt that there are several other things wrong with this code, but the above should help you get started on figuring out what they are. INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

        M Offline
        M Offline
        mpapeo
        wrote on last edited by
        #3

        Yep i looked at that and there were mistakes, but the main problem comes from the virtualqueryEx function which has to do most of the things. Because i have to read pages using it... So it gives this error msg: "The value of ESP was not properly saved across a function call." error code 5: Illegal function call error code 998: from virtualqueryex function oam

        J 1 Reply Last reply
        0
        • M mpapeo

          Yep i looked at that and there were mistakes, but the main problem comes from the virtualqueryEx function which has to do most of the things. Because i have to read pages using it... So it gives this error msg: "The value of ESP was not properly saved across a function call." error code 5: Illegal function call error code 998: from virtualqueryex function oam

          J Offline
          J Offline
          John R Shaw
          wrote on last edited by
          #4

          The code you gave should not compile on any compiler period! Let alone give any error messages when run. I can not remember ever seeing so many basic programming errors. If by some miricle it did run, then (Yep) it would probubly crash. Heck you stand a better chance of crashing the whole system than making that code work (as written). As for VirtualQueryEx: Why are you even trying to call it? The call appears to be used to retrieve information that needs to be stored in the structure pointed to by lpBuffer, but lpBuffer does not point to a structure, it points to NULL. The only reason the dwLength argument is correct, is that it is 0, since lpBuffer is NULL. You are also passing it a 5th argument GetLastError, for who knows what reason (it only takes 4 arguments and this is not one of them). I recomend you start all over again from scatch. What ever it is you are trying to accomplish, this will not do it. P.S. Sorry but if I was an employer, the code you gave would get you fired. INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

          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