How can I read the headers from a WinNT portable executable file using Perl?

霸气de小男生 提交于 2019-12-05 08:08:12

问题


I want to work with PE files in Perl and didn't find a module, so I think I will write my own (already did that in delphi once).

I only got one problem, when mapping the executable to a buffer, how can i search for octals like 0x00004550 (IMAGE_NT_SIGNATURE), convert them back to writeable strings etc?


回答1:


There is a Perl module to manipulate portable executables: Win32::Exe.

I don't have a clue on your exact question, but if you still want to write your own library, Win32::Exe might be a good reference.




回答2:


For converting that value to a bytestring representation, use pack. The constant you are dealing is a little-endian 32 bit value, so 'V' in the template.

$ perl -e 'print pack q[V], 0x00004550' | hd
00000000  50 45 00 00                                       |PE..|
00000004

See perldoc -f pack for details.

You probably won't need to search for strings like "PE\0\0", just use them to verify whether the file you are reading actually is a PE file. The 'PE' section usually comes right after the DOS ('MZ') section which has its own length field.

(I agree that Win32::Exe may be worth a look, depending on what you want to do.)



来源:https://stackoverflow.com/questions/1418855/how-can-i-read-the-headers-from-a-winnt-portable-executable-file-using-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!