-
Notifications
You must be signed in to change notification settings - Fork 4
/
find_reloc.py
38 lines (29 loc) · 1.04 KB
/
find_reloc.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
37
38
#!/usr/bin/env python3
import argparse
import os
import struct
def getLastWord(filepath):
with open(filepath, "rb") as f:
f.seek(-4, os.SEEK_END)
return struct.unpack('>I', bytes(f.read()))[0]
def determineIfReloc(filepath):
lastWord = getLastWord(filepath)
fileSize = os.stat(filepath).st_size
if lastWord == fileSize:
print(f"{os.path.split(filepath)[1]},{fileSize:X},reloc")
else:
print(f"{os.path.split(filepath)[1]},{fileSize:X},")
def main():
description = "Finds files that look like ov."
epilog = ""
parser = argparse.ArgumentParser(description=description, epilog=epilog, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("dir", help="Directory to search.")
args = parser.parse_args()
# dir = os.fsencode(args.dir)
for file in os.listdir(args.dir):
# filename = os.fsdecode(file)
# print(filename)
# determineIfReloc(file)
determineIfReloc(os.path.join(args.dir, file))
if __name__ == "__main__":
main()