mirror of
https://github.com/SMGCommunity/Petari.git
synced 2024-11-23 13:40:02 +00:00
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
import hashlib
|
|
import struct
|
|
import util
|
|
import sys
|
|
|
|
def getCodeFromDOL(sym, functionSize):
|
|
with open("baserom.dol", "rb") as f:
|
|
data = f.read()
|
|
# verify that the dol is legit
|
|
hash = hashlib.sha256(data).hexdigest().upper()
|
|
assert hash == "8B7F28D193170F998F92E02EA638107822FB72073691D0893EB18857BE0C6FCF" or hash == "69F93FCC0FA34837347B5AC05168BC783ADCACB3C02697CFDA087A3B63ABC9E0"
|
|
|
|
# grab .text offset and start offset
|
|
txtOffset, = struct.unpack_from(">I", data, 4)
|
|
startOffset, = struct.unpack_from(">I", data, 0x4C)
|
|
addr = util.findAddrFromSym(sym)
|
|
|
|
assert addr != 0
|
|
|
|
addrOffset = int(addr, 16) - startOffset
|
|
funcSize = util.findAddrSizeFromSym(sym)
|
|
|
|
# first check we can do for matching is to check the function size
|
|
# we can immediately terminate if this is not the same
|
|
if int(funcSize,16) != functionSize:
|
|
print("ERROR: Function size mismatch!")
|
|
sys.exit(1)
|
|
|
|
return data[txtOffset + addrOffset:txtOffset + addrOffset + functionSize] |