-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiat.py
36 lines (28 loc) · 806 Bytes
/
iat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pefile
def get_iat(pe):
iat = []
for entry in pe.DIRECTORY_ENTRY_IMPORT:
for imp in entry.imports:
iat.append(imp.name)
return iat
def set_iat(pe, original_iat, new_iat):
"""
Set original_iat to new_iat
"""
if len(new_iat) < len(original_iat):
new_iat += b'\x00' * (len(original_iat) - len(new_iat))
for entry in pe.DIRECTORY_ENTRY_IMPORT:
for imp in entry.imports:
if imp.name == original_iat:
imp.name = new_iat
return pe
def main():
pe = pefile.PE("demo.exe")
iat = get_iat(pe)
print(iat)
new_pe = set_iat(pe, b'MessageBoxA', b'GetParent')
new_iat = get_iat(new_pe)
print(new_iat)
new_pe.write("demo_new.exe")
if __name__ == "__main__":
main()