Last active
May 14, 2020 01:29
-
-
Save novakirby/1a7736224e9668013397958eb015931f to your computer and use it in GitHub Desktop.
fp_resign.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
""" | |
import sys, struct | |
class crc32r: | |
def __init__(self, p0 = 0xEDB88320): | |
p0 |= 0x80000000 | |
u0 = [0x0] * 0x100 | |
i = 0x1 | |
while i & 0xFF: | |
t0 = i | |
for j in range(0x8): | |
b = bool(t0 & 0x1) | |
t0 >>= 0x1 | |
if b : t0 ^= p0 | |
u0[i] = t0 | |
i += 0x1 | |
self.u0 = tuple(u0) | |
u0.clear() | |
def calc0(self, s, inXOR = 0xFFFFFFFF, outXOR = 0xFFFFFFFF): | |
u = self.u0 | |
t = inXOR | |
for k in s : t = (t >> 0x8) ^ u[(k ^ t) & 0xFF] | |
return t ^ outXOR | |
def sign(fName): | |
crc32 = crc32r() | |
with open(fName, "rb+") as f: | |
f.seek(0xE0, 0x0) | |
t = crc32.calc0(f.read(0xD4), 0x0) | |
f.seek(0xDC, 0x0) | |
f.write(struct.pack("<I", t)) | |
if __name__ == "__main__": | |
if sys.stdin.isatty(): | |
argv = sys.argv | |
if 0x2 <= len(argv) <= 0x3: | |
sign(argv[-0x1]) | |
else: | |
print("Usage : fp_resign.py file") | |
else: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
n/m python3 not python2 :(