-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModify.py
More file actions
31 lines (27 loc) · 978 Bytes
/
Modify.py
File metadata and controls
31 lines (27 loc) · 978 Bytes
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
from pathlib import Path
from strongarm.macho import MachoParser, MachoBinary
# Load an input file
macho_parser = MachoParser(Path() / "TestApp")
# Read the ARM64 slice and perform some operations
binary: MachoBinary = macho_parser.get_arm64_slice()
# Read cstring segment information
cstring = binary.section_with_name("__cstring", "__TEXT")
pointer: int = cstring.address
size: int = cstring.size + pointer
# Parse cstrings
while pointer < size:
str = binary.read_string_at_address(pointer)
if str == None:
pointer += 1
continue
if str == "Select a Landmark":
print("Found the string.")
break
pointer += str.__len__() + 1
# Overwrite the text
modified_binary = binary.write_bytes(bytes.fromhex('48656c6c6f20277374726f6e6761726d27'), pointer, True)
# Persist the modified binary to disk
modified_binary.write_binary(Path() / "ModifiedTestApp")
# Validate modification
print(modified_binary.read_string_at_address(pointer))
# Prints Hello 'strongarm'