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. Error when dumping PE file

Error when dumping PE file

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 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
    sawerr
    wrote on last edited by
    #1

    Hi In my program i want to use BOOL MapAndLoad( PSTR ImageName, PSTR DllPath, PLOADED_IMAGE LoadedImage, BOOL DotDll, BOOL ReadOnly ); function in Imagehlp.h . CPE::CPE(CString fileName, CString filePath):fileName(fileName),filePath(filePath) { LOADED_IMAGE loi; ::MapAndLoad((LPSTR)(LPCTSTR)fileName, (LPSTR)(LPCTSTR)filePath, &loi,FALSE, TRUE); int i = loi.NumberOfSections; char q[50]; sprintf(q,"%d",i); MessageBox(NULL, q,NULL,0); } When i compiled and execute it. It gives error Messagebox with value -858993460 . I changed my projects setting use multibyte character set. wchar_t to char. But can not find solution. What is wrong with this code? How can i fix it? Thanks.

    D 1 Reply Last reply
    0
    • S sawerr

      Hi In my program i want to use BOOL MapAndLoad( PSTR ImageName, PSTR DllPath, PLOADED_IMAGE LoadedImage, BOOL DotDll, BOOL ReadOnly ); function in Imagehlp.h . CPE::CPE(CString fileName, CString filePath):fileName(fileName),filePath(filePath) { LOADED_IMAGE loi; ::MapAndLoad((LPSTR)(LPCTSTR)fileName, (LPSTR)(LPCTSTR)filePath, &loi,FALSE, TRUE); int i = loi.NumberOfSections; char q[50]; sprintf(q,"%d",i); MessageBox(NULL, q,NULL,0); } When i compiled and execute it. It gives error Messagebox with value -858993460 . I changed my projects setting use multibyte character set. wchar_t to char. But can not find solution. What is wrong with this code? How can i fix it? Thanks.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      sawerr wrote:

      What is wrong with this code?

      You did not check the return value from MapAndLoad(), nor did you call GetLastError().


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      S 1 Reply Last reply
      0
      • D David Crow

        sawerr wrote:

        What is wrong with this code?

        You did not check the return value from MapAndLoad(), nor did you call GetLastError().


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        S Offline
        S Offline
        sawerr
        wrote on last edited by
        #3

        I checked the return value, it is not TRUE MapAndLoad() is not working. I changed code because of pstr parameters. CPE::CPE(CString fileName, CString filePath):fileName(fileName),filePath(filePath) { char *ch1 = strdup(fileName); char *ch2 = strdup(filePath); MessageBox(NULL, ch1, ch2, 0); PLOADED_IMAGE loi = ::ImageLoad((PSTR)ch1, (PSTR)ch2); BOOL b = ::MapAndLoad(ch1, ch2, loi,TRUE, TRUE); if(b == TRUE) { MessageBox(NULL, "DONE", NULL, 0); } ULONG i = loi->NumberOfSections; char q[50]; sprintf(q,"%d",i); MessageBox(NULL, q,NULL,0); } fileName and filePath parameters correct (they are coming from CFileDialog) but it gives run-time error in line ULONG i = loi->NumberOfSections; Unhandled exception at 0x76c977f2 in PEInside.exe: 0xC0000005: Access violation writing location 0x00000004. Do you have any suggestions?

        D 1 Reply Last reply
        0
        • S sawerr

          I checked the return value, it is not TRUE MapAndLoad() is not working. I changed code because of pstr parameters. CPE::CPE(CString fileName, CString filePath):fileName(fileName),filePath(filePath) { char *ch1 = strdup(fileName); char *ch2 = strdup(filePath); MessageBox(NULL, ch1, ch2, 0); PLOADED_IMAGE loi = ::ImageLoad((PSTR)ch1, (PSTR)ch2); BOOL b = ::MapAndLoad(ch1, ch2, loi,TRUE, TRUE); if(b == TRUE) { MessageBox(NULL, "DONE", NULL, 0); } ULONG i = loi->NumberOfSections; char q[50]; sprintf(q,"%d",i); MessageBox(NULL, q,NULL,0); } fileName and filePath parameters correct (they are coming from CFileDialog) but it gives run-time error in line ULONG i = loi->NumberOfSections; Unhandled exception at 0x76c977f2 in PEInside.exe: 0xC0000005: Access violation writing location 0x00000004. Do you have any suggestions?

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          If MapAndLoad() is returning 0, why are you then proceeding to dereference loi?

          sawerr wrote:

          Do you have any suggestions?

          Yes.

          BOOL b = ::MapAndLoad(ch1, ch2, loi, TRUE, TRUE);
          if (b)
          {
          CString q;

          q.Format("%lu", loi->NumberOfSections);
          AfxMessageBox(q);
          

          }
          else
          {
          CString q;

          q.Format("%lu", GetLastError());
          AfxMessageBox(q);
          

          }


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          S 1 Reply Last reply
          0
          • D David Crow

            If MapAndLoad() is returning 0, why are you then proceeding to dereference loi?

            sawerr wrote:

            Do you have any suggestions?

            Yes.

            BOOL b = ::MapAndLoad(ch1, ch2, loi, TRUE, TRUE);
            if (b)
            {
            CString q;

            q.Format("%lu", loi->NumberOfSections);
            AfxMessageBox(q);
            

            }
            else
            {
            CString q;

            q.Format("%lu", GetLastError());
            AfxMessageBox(q);
            

            }


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            S Offline
            S Offline
            sawerr
            wrote on last edited by
            #5

            Thanks for your help your last post really help me, i understood how i must write. Thank you. Good works...

            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