You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The updated checksum is then packed into a 4-byte little-endian integer and written back into the dex data, starting from the 9th byte.
89
90
The updated signature is then written back into the dex data, starting from the 13th byte.
90
91
"""
92
+
ifrepair_sha1:
93
+
signature=hashlib.sha1(dex_data[32:]).digest()
94
+
print(f"Signature: {signature.hex()}")
95
+
dex_data[12:32] =signature
96
+
91
97
checksum=zlib.adler32(dex_data[12:])
92
-
signature=hashlib.sha1(dex_data[32:]).digest()
93
98
print(f"Checksum: {checksum:#x}")
94
-
print(f"Signature: {signature.hex()}")
95
-
96
99
dex_data[8:12] =struct.pack("<I", checksum)
97
-
dex_data[12:32] =signature
100
+
98
101
returndex_data
99
102
100
103
101
104
defrepair_dex(
102
105
dex_path: str,
106
+
repair_sha1: bool=False,
103
107
output_dex_path: str=None,
104
108
):
105
109
"""
106
110
This function repairs dex files in the given path. If the path is a directory, it will repair all dex files within that directory. If the path is a file, it will repair that specific dex file.
107
111
108
112
Parameters:
109
113
dex_path (str): The path to the dex file or directory containing dex files.
114
+
repair_sha1 (bool, optional): If True, the SHA-1 signature is updated. If False, the SHA-1 signature is not updated. Default is False.
110
115
output_dex_path (str, optional): The output path for the repaired dex files. If not provided, the repaired dex files will be overwritten in the original location.
111
116
112
117
Returns:
@@ -125,19 +130,22 @@ def repair_dex(
125
130
ifnotos.path.isdir(output_dex_path):
126
131
raiseDexRepairError(f"{output_dex_path} not a directory!")
This function repairs a single dex file by fixing the DEX magic number and updating the checksum and signature in the DEX header. The repaired dex file is then written to the output path if it is provided, or to the original path if it is not.
138
145
139
146
Parameters:
140
147
dex_file_path (str): The path to the dex file to be repaired.
148
+
repair_sha1 (bool, optional): If True, the SHA-1 signature is updated. If False, the SHA-1 signature is not updated. Default is False.
141
149
output_dex_path (str, optional): The output path for the repaired dex file. If not provided, the repaired dex file will be overwritten in the original location.
0 commit comments