@@ -8,22 +8,21 @@ def ascii_to_hex(input_string):
88 hex_string = input_string .encode ().hex ()
99 return hex_string
1010
11- def replace_bytes_in_file (file_path , offset , search_bytes , replace_bytes ):
12- with open (file_path , 'rb+ ' ) as file :
13- file .seek ( offset )
11+ def replace_hex_bytes_at_offset (file_path , offset , replace_hex ):
12+ with open (file_path , 'rb' ) as file :
13+ file_data = file .read ( )
1414
15- # Read the content at the specified offset
16- data = file .read (len (search_bytes ))
15+ replace_bytes = bytes .fromhex (replace_hex )
1716
18- # Check if the bytes at the specified offset match the search_bytes
19- if data == search_bytes :
20- # Move the file pointer back to the beginning of the replacement area
21- file . seek ( offset )
17+ # Ensure the offset is within the file size
18+ if offset >= 0 and offset + len ( replace_bytes ) <= len ( file_data ) :
19+ # Replace the hex bytes at the specified offset with the new hex bytes
20+ file_data = file_data [: offset ] + replace_bytes + file_data [ offset + len ( replace_bytes ):]
2221
23- # Replace the bytes with the new ones
24- file .write (replace_bytes )
25- else :
26- pass
22+ with open ( file_path , 'wb' ) as file :
23+ file .write (file_data )
24+ else :
25+ print ( "Invalid offset or replacement size." )
2726
2827def replace_hex_bytes (file_path , search_hex , replace_hex ):
2928 with open (file_path , 'rb' ) as file :
@@ -113,7 +112,6 @@ def patch_ip(ip):
113112def patch_sunset_time ():
114113 file_path = './data/ipa/Payload/minecraftearthtf.app/minecraftearthtf'
115114 offset = 0x1129080
116- search_bytes = b'\xEA \x05 \x00 \x54 '
117- replace_bytes = b'\xE1 \x05 \x00 \x54 '
115+ bytes_to_replace_with = 'E1050054'
118116
119- replace_bytes_in_file (file_path , offset , search_bytes , replace_bytes )
117+ replace_hex_bytes_at_offset (file_path , offset , bytes_to_replace_with )
0 commit comments