@@ -469,7 +469,7 @@ def __len__(self):
469469 return length
470470
471471
472- class diff :
472+ class cpatch :
473473 class PatchHeader (ctypes .LittleEndianStructure ):
474474 VERSION_MAJOR = 1
475475 VERSION_MINOR = 0
@@ -591,6 +591,7 @@ def _cleanup_jumps(cls, old: bytes, instructions: list[Instr]) -> list[Instr]:
591591 if len (instructions ) >= 2 and isinstance (instructions [1 ], SetAddrInstr ):
592592 # ADDR, COPY, ADRR
593593 if instr .shift == - instructions [1 ].shift :
594+ print (copy .length )
594595 # Replace with a write instead
595596 merged .append (WriteInstr (old [instr .new : instr .new + copy .length ]))
596597 replaced = True
@@ -845,9 +846,9 @@ def generate(
845846 bin_new : bytes ,
846847 verbose : bool ,
847848 ) -> bytes :
848- meta , instructions = diff ._gen_patch_instr (bin_original , bin_new )
849- patch_data = diff ._gen_patch_data (instructions )
850- patch_header = diff ._gen_patch_header (meta , patch_data )
849+ meta , instructions = cls ._gen_patch_instr (bin_original , bin_new )
850+ patch_data = cls ._gen_patch_data (instructions )
851+ patch_header = cls ._gen_patch_header (meta , patch_data )
851852 bin_patch = patch_header + patch_data
852853 ratio = 100 * len (bin_patch ) / meta ["new" ]["len" ]
853854
@@ -901,14 +902,14 @@ def validation(cls, bin_original: bytes, invalid_length: bool, invalid_crc: bool
901902 )
902903 instructions .append (CopyInstr (len (bin_original ) - 544 ))
903904
904- meta , _ = diff ._gen_patch_instr (bin_original , bin_original )
905+ meta , _ = cls ._gen_patch_instr (bin_original , bin_original )
905906 if invalid_length :
906907 meta ["new" ]["len" ] -= 1
907908 if invalid_crc :
908909 meta ["new" ]["crc" ] -= 1
909910
910- patch_data = diff ._gen_patch_data (instructions )
911- patch_header = diff ._gen_patch_header (meta , patch_data )
911+ patch_data = cls ._gen_patch_data (instructions )
912+ patch_header = cls ._gen_patch_header (meta , patch_data )
912913 bin_patch = patch_header + patch_data
913914
914915 # Validate that file can be reconstructed
@@ -924,7 +925,7 @@ def patch(
924925 bin_original : bytes ,
925926 bin_patch : bytes ,
926927 ) -> bytes :
927- meta , instructions = diff ._patch_load (bin_patch )
928+ meta , instructions = cls ._patch_load (bin_patch )
928929 patched = b""
929930 orig_offset = 0
930931
@@ -984,7 +985,7 @@ def dump(
984985 cls ,
985986 bin_patch : bytes ,
986987 ):
987- meta , instructions = diff ._patch_load (bin_patch )
988+ meta , instructions = cls ._patch_load (bin_patch )
988989 total_write_bytes = 0
989990
990991 print (f"Original File: { meta ['original' ]['len' ]:6d} bytes" )
@@ -1003,7 +1004,7 @@ def dump(
10031004
10041005 print ("" )
10051006 print ("Total WRITE data:" )
1006- print (f"\t { total_write_bytes } bytes ({ 100 * total_write_bytes / len (bin_patch ):.2f} %)" )
1007+ print (f"\t { total_write_bytes } bytes ({ 100 * total_write_bytes / len (bin_patch ):.2f} %)" )
10071008
10081009 print ("" )
10091010 print ("Instruction Count:" )
@@ -1050,7 +1051,7 @@ def dump(
10501051 # Run requested command
10511052 if args .command == "generate" :
10521053 with open (args .original , "rb" ) as f_orig , open (args .new , "rb" ) as f_new :
1053- patch = diff .generate (
1054+ patch = cpatch .generate (
10541055 f_orig .read (- 1 ),
10551056 f_new .read (- 1 ),
10561057 args .verbose ,
@@ -1059,14 +1060,14 @@ def dump(
10591060 f_output .write (patch )
10601061 elif args .command == "validation" :
10611062 with open (args .input_file , "rb" ) as f_input :
1062- patch = diff .validation (f_input .read (- 1 ), args .invalid_length , args .invalid_crc )
1063+ patch = cpatch .validation (f_input .read (- 1 ), args .invalid_length , args .invalid_crc )
10631064 with open (args .patch , "wb" ) as f_output :
10641065 f_output .write (patch )
10651066 elif args .command == "patch" :
10661067 with open (args .original , "rb" ) as f_orig , open (args .patch , "rb" ) as f_patch :
1067- output = diff .patch (f_orig .read (- 1 ), f_patch .read (- 1 ))
1068+ output = cpatch .patch (f_orig .read (- 1 ), f_patch .read (- 1 ))
10681069 with open (args .output , "wb" ) as f_output :
10691070 f_output .write (output )
10701071 elif args .command == "dump" :
10711072 with open (args .patch , "rb" ) as f_patch :
1072- diff .dump (f_patch .read (- 1 ))
1073+ cpatch .dump (f_patch .read (- 1 ))
0 commit comments