Skip to content

Instantly share code, notes, and snippets.

@novakirby
Last active May 14, 2020 01:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save novakirby/1a7736224e9668013397958eb015931f to your computer and use it in GitHub Desktop.
Save novakirby/1a7736224e9668013397958eb015931f to your computer and use it in GitHub Desktop.
fp_resign.py
# -*- 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
@odwdinc
Copy link

odwdinc commented Dec 21, 2018

no go?

Traceback (most recent call last):
File "tes.py", line 37, in
sign(argv[-0x1])
File "tes.py", line 26, in sign
crc32 = crc32r()
File "tes.py", line 17, in init
u0.clear()
AttributeError: 'list' object has no attribute 'clear'

@odwdinc
Copy link

odwdinc commented Dec 21, 2018

n/m python3 not python2 :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment