Hi, everyone,
I write the following code by using pefile to wish get all the imported symbols by an binary file, but I came across a wired situation:
=============
def parsePE(pe_file_path):
pe = pefile.PE(pe_file_path, fast_load=False)
imp_cnt = 0
# listing the imported symbols: DIRECTORY_ENTRY_IMPORT, DIRECTORY_ENTRY_DELAY_IMPORT
if hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):
for entry in pe.DIRECTORY_ENTRY_IMPORT:
print entry.dll
imp_cnt += len(entry.imports)
for imp in entry.imports:
print '\t', hex(imp.address),
imp.name, imp.ordinal, entry.dll
print "imp_cnt: ", imp_cnt
=============
The following is part of my results(which contain the wrong parts):
=============
ole32.dll
0x10494650 OleDuplicateData None ole32.dll
0x10494654 CoUninitialize None ole32.dll
0x10494658 CoInitializeEx None ole32.dll
0x1049465c StringFromCLSID None ole32.dll
0x10494660 OleUninitialize None ole32.dll
0x10494664 OleInitialize None ole32.dll
0x10494668 OleFlushClipboard None ole32.dll
0x1049466c CoTaskMemFree None ole32.dll
0x10494670 DoDragDrop None ole32.dll
0x10494674 CoCreateInstance None ole32.dll
0x10494678 ReleaseStgMedium None ole32.dll
0x1049467c OleGetClipboard None ole32.dll
0x10494680 RegisterDragDrop None ole32.dll
0x10494684 RevokeDragDrop None ole32.dll
0x10494688 OleSetClipboard None ole32.dll
OLEAUT32.dll
0x10493f0c None 6 OLEAUT32.dll
0x10493f10 None 2 OLEAUT32.dll
0x10493f14 None 7 OLEAUT32.dll
0x10493f18 None 4 OLEAUT32.dll
0x10493f1c None 9 OLEAUT32.dll
0x10493f20 None 185 OLEAUT32.dll
0x10493f24 None 21 OLEAUT32.dll
0x10493f28 None 20 OLEAUT32.dll
0x10493f2c None 19 OLEAUT32.dll
0x10493f30 None 22 OLEAUT32.dll
0x10493f34 None 16 OLEAUT32.dll
0x10493f38 None 411 OLEAUT32.dll
=============
As you can see, for the symbols associated with ordinal, my code just didnot print the symbol name, instead a non value; but for the symbols without associated ordinal, the result is right, it can print address, name, and the dll file name.
Anyone can give me some suggestions for this? Did I miss some points here?
Thanks in advance!