0

I am new to Python, and have an assignment to create a Python script that read any pe file whether .exe or .dll. The problem when I use the pefile reader located at https://github.com/erocarrera/pefile I am following the usage exactly as below:

import pefile
pe =  pefile.PE(‘/path/to/pefile.exe’)
pe.OPTIONAL_HEADER.AddressOfEntryPoint

the first and second statement succeeded but the third one failed with: AttributeError: 'PE' object has no attribute OPTIONAL_HEADER

Can someone help on this please.

idjaw
  • 25,487
  • 7
  • 64
  • 83
Tony_Mod
  • 1
  • 2
  • The second statement looks like the pefile example, (stupid question now) are you replacing the path from the example by a real path to a exe file? Also, check if you have any output if you replace the 3rd statement by " print(pe.dump_info()) ". – FelipeS Sep 29 '16 at 03:25
  • Have a look at this link: http://stackoverflow.com/questions/29737609/how-can-i-obtain-a-pe-files-instructions-using-python – FelipeS Sep 29 '16 at 03:36
  • Thanks for your reply. Yes I am replacing the file with a real one like pe = pefile.PE('helloWorld.exe') – Tony_Mod Sep 29 '16 at 04:02
  • I also tried the print(pe.dump_info()) but getting another AttributeError: PE has no attribute DOS_HEADER. – Tony_Mod Sep 29 '16 at 04:04
  • Thanks again, I looked at that linked already, when I run the script from the link I got the same Attribute error, PE has no OPTIONAL_HEADER attribute. This seems like something tiny I am missing but just can't figure it out. – Tony_Mod Sep 29 '16 at 04:08
  • Reading the `pefile` code, I don't see any way the constructor could run successfully (i.e. not raise an exception), but not set the `OPTIONAL_HEADER` and other attributes. Are you sure you're not looking at some other object named `pe` after the second line in your example code failed? – Blckknght Sep 29 '16 at 04:30

0 Answers0