官术网_书友最值得收藏!

How to do it...

In the following steps, we will parse the PE header of a file, and then print out notable portions of it:

  1. Import the PE file and use it to parse the PE header of your desired file:
import pefile

desired_file = "python-3.7.2-amd64.exe"
pe = pefile.PE(desired_file)
  1. List the imports of the PE file:
for entry in pe.DIRECTORY_ENTRY_IMPORT:
print(entry.dll)
for imp in entry.imports:
print("\t", hex(imp.address), imp.name)

A small portion of the output is shown here:

  1. List the sections of the PE file:
for section in pe.sections:
print(
section.Name,
hex(section.VirtualAddress),
hex(section.Misc_VirtualSize),
section.SizeOfRawData,
)

The output of the previous code is as follows:

  1. Print a full dump of the parsed information:
print(pe.dump_info())

A small portion of the output is displayed here:

主站蜘蛛池模板: 孝义市| 白水县| 太原市| 北安市| 保德县| 兴安县| 夏邑县| 抚宁县| 涪陵区| 滁州市| 黔南| 合江县| 溧阳市| 卫辉市| 德格县| 棋牌| 新泰市| 稷山县| 新野县| 榆林市| 化德县| 邵武市| 开阳县| 定结县| 阜康市| 黔东| 新疆| 宁陕县| 逊克县| 桂平市| 加查县| 会宁县| 三明市| 罗江县| 肥城市| 阿拉善盟| 仙居县| 阿拉善盟| 阳高县| 延安市| 郑州市|