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. How to get the original size of a pe file

How to get the original size of a pe file

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorial
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.
  • W Offline
    W Offline
    white jungle
    wrote on last edited by
    #1

    I just want to know how to get a pe file's size through the PE file its self.That is no API is used,just look up the data structure of the pe. I have checked the winnt.h and can't find a useful data member to show the size of the pe file.

    Don't look at me in that way!

    K 1 Reply Last reply
    0
    • W white jungle

      I just want to know how to get a pe file's size through the PE file its self.That is no API is used,just look up the data structure of the pe. I have checked the winnt.h and can't find a useful data member to show the size of the pe file.

      Don't look at me in that way!

      K Offline
      K Offline
      Karismatic
      wrote on last edited by
      #2

      Hey, I consider you must be using MFC Use a CFile object to get the length of the file and that length would be the size of file in bytes like this.. CFile obj; double len; CString sLen; if(obj.Open("C:\\a\\a.exe",CFile::modeRead)) { len = obj.GetLength(); len /= 1024; sLen.Format("%10f",len); AfxMessageBox(sLen); } obj.Close(); This code will give you the size of PE file in kilobytes Regards, Pankaj Sachdeva

      W 1 Reply Last reply
      0
      • K Karismatic

        Hey, I consider you must be using MFC Use a CFile object to get the length of the file and that length would be the size of file in bytes like this.. CFile obj; double len; CString sLen; if(obj.Open("C:\\a\\a.exe",CFile::modeRead)) { len = obj.GetLength(); len /= 1024; sLen.Format("%10f",len); AfxMessageBox(sLen); } obj.Close(); This code will give you the size of PE file in kilobytes Regards, Pankaj Sachdeva

        W Offline
        W Offline
        white jungle
        wrote on last edited by
        #3

        But if I have a pe file and then I append some data to the file,I want to get the original pe file size,not the size after modified! I skim the winnt.h and find that I must sum all the section size and directory size to count the size of pe file.I want to if there is a structure member in the pe file that can show me the size directly! Thanks for help!

        ---------- Don't look at me in that way!

        K 1 Reply Last reply
        0
        • W white jungle

          But if I have a pe file and then I append some data to the file,I want to get the original pe file size,not the size after modified! I skim the winnt.h and find that I must sum all the section size and directory size to count the size of pe file.I want to if there is a structure member in the pe file that can show me the size directly! Thanks for help!

          ---------- Don't look at me in that way!

          K Offline
          K Offline
          Karismatic
          wrote on last edited by
          #4

          tell me exactly what are you creating then may be i'll be able to help you Regards, Pankaj Sachdeva

          W 1 Reply Last reply
          0
          • K Karismatic

            tell me exactly what are you creating then may be i'll be able to help you Regards, Pankaj Sachdeva

            W Offline
            W Offline
            white jungle
            wrote on last edited by
            #5

            At first!Thank you for help! I just want to get the orginal pe file's size,maybe the pe file was modified by some other program(ex.Append some data to the end of the orginal pe file).So the size I get from API is not the size of the original file. I want to get the original pe file size ,so I have to follow the pe format and sum all it's section size and directory size. Can you help me on getting a easy way to find out the original file size! Thank you very much! ---------- Don't look at me in that way!

            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