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

ε祈祈猫儿з 提交于 2019-12-03 23:05:53
Mark Rushakoff

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.

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.)

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