mirror of
https://github.com/maximumspatium/PowerRomDasm.git
synced 2025-02-17 03:30:29 +00:00
Fix detokenizer for OF 1.x images.
This commit is contained in:
parent
e3616ecc59
commit
4e75ac0f3c
7
detok.py
7
detok.py
@ -169,6 +169,7 @@ FORTH_WORDS = {
|
|||||||
0xFD : ('version1', ['fcode_hdr', 'offset8']),
|
0xFD : ('version1', ['fcode_hdr', 'offset8']),
|
||||||
0x102 : ('my-address', []),
|
0x102 : ('my-address', []),
|
||||||
0x103 : ('my-space', []),
|
0x103 : ('my-space', []),
|
||||||
|
0x104 : ('memmap', []),
|
||||||
0x110 : ('property', []),
|
0x110 : ('property', []),
|
||||||
0x111 : ('encode-int', []),
|
0x111 : ('encode-int', []),
|
||||||
0x112 : ('encode+', []),
|
0x112 : ('encode+', []),
|
||||||
@ -179,6 +180,7 @@ FORTH_WORDS = {
|
|||||||
0x11A : ('device-type', []),
|
0x11A : ('device-type', []),
|
||||||
0x11C : ('is-install', []),
|
0x11C : ('is-install', []),
|
||||||
0x11D : ('is-remove', []),
|
0x11D : ('is-remove', []),
|
||||||
|
0x11F : ('new-device', []),
|
||||||
0x125 : ('get-msecs', []),
|
0x125 : ('get-msecs', []),
|
||||||
0x126 : ('ms', []),
|
0x126 : ('ms', []),
|
||||||
0x128 : ('decode-phys', []),
|
0x128 : ('decode-phys', []),
|
||||||
@ -192,10 +194,12 @@ FORTH_WORDS = {
|
|||||||
0x18B : ('fb8-install', []),
|
0x18B : ('fb8-install', []),
|
||||||
0x201 : ('device-name', []),
|
0x201 : ('device-name', []),
|
||||||
0x203 : ('my-self', []),
|
0x203 : ('my-self', []),
|
||||||
|
0x204 : ('find-package', []),
|
||||||
0x207 : ('find-method', []),
|
0x207 : ('find-method', []),
|
||||||
0x209 : ('$call-parent', []),
|
0x209 : ('$call-parent', []),
|
||||||
0x20A : ('my-parent', []),
|
0x20A : ('my-parent', []),
|
||||||
0x20B : ('ihandle>phandle', []),
|
0x20B : ('ihandle>phandle', []),
|
||||||
|
0x20F : ('$open-package', []),
|
||||||
0x216 : ('abort', []),
|
0x216 : ('abort', []),
|
||||||
0x21A : ('get-my-property', []),
|
0x21A : ('get-my-property', []),
|
||||||
0x21B : ('decode-int', []),
|
0x21B : ('decode-int', []),
|
||||||
@ -331,5 +335,4 @@ class DeTokenizer():
|
|||||||
elif tok_num in self.user_dict: # check user dictionary
|
elif tok_num in self.user_dict: # check user dictionary
|
||||||
print("0x%X ; %s" % (tok_num, self.user_dict[tok_num]))
|
print("0x%X ; %s" % (tok_num, self.user_dict[tok_num]))
|
||||||
else:
|
else:
|
||||||
print("Token %X not found at offset 0x%X!" % (tok_num, self.pos))
|
print("0x%X ; %s" % (tok_num, 'undefined_' + format(tok_num, 'x')))
|
||||||
crash()
|
|
||||||
|
18
detok_of.py
18
detok_of.py
@ -1,7 +1,7 @@
|
|||||||
'''
|
'''
|
||||||
DeTokenizer for Apple OpenFirmware.
|
DeTokenizer for Apple OpenFirmware.
|
||||||
|
|
||||||
Author: Max Poliakovski 2019-2021
|
Author: Max Poliakovski 2019-2022
|
||||||
'''
|
'''
|
||||||
import struct
|
import struct
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
@ -42,9 +42,6 @@ def populate_user_dict(src_dict, dst_dict):
|
|||||||
dst_dict[tok_num] = word['name']
|
dst_dict[tok_num] = word['name']
|
||||||
|
|
||||||
# add Apple specific FCodes for managing stack frames
|
# add Apple specific FCodes for managing stack frames
|
||||||
for i in range(0,9):
|
|
||||||
dst_dict[0x407 + i] = '(pushlocals_%s)' % i
|
|
||||||
|
|
||||||
for i in range(0,8):
|
for i in range(0,8):
|
||||||
dst_dict[0x410 + i] = '(local@%s)' % i
|
dst_dict[0x410 + i] = '(local@%s)' % i
|
||||||
dst_dict[0x418 + i] = '(local!%s)' % i
|
dst_dict[0x418 + i] = '(local!%s)' % i
|
||||||
@ -60,6 +57,10 @@ def main():
|
|||||||
dest='of_offset',
|
dest='of_offset',
|
||||||
help='offset to OF container (autodetect attempt if omitted)',
|
help='offset to OF container (autodetect attempt if omitted)',
|
||||||
metavar='OF_OFFSET', required=True)
|
metavar='OF_OFFSET', required=True)
|
||||||
|
parser.add_argument('--of_version', type=int,
|
||||||
|
dest='of_version',
|
||||||
|
help='Open Firmware version used to produce the input token stream',
|
||||||
|
metavar='OF_VERSION', default=2)
|
||||||
opts = parser.parse_args()
|
opts = parser.parse_args()
|
||||||
|
|
||||||
with open(opts.rom_path, 'rb') as infile:
|
with open(opts.rom_path, 'rb') as infile:
|
||||||
@ -89,6 +90,15 @@ def main():
|
|||||||
|
|
||||||
populate_user_dict(dict, detokenizer.user_dict)
|
populate_user_dict(dict, detokenizer.user_dict)
|
||||||
|
|
||||||
|
# OF v1.x uses 0x401,XX sequences for (pushlocals_XX)
|
||||||
|
# where the 2nd byte XX specifies the number of locals to push
|
||||||
|
# OF v2.x uses FCodes in the range 0x407...0x40F for the same purpose
|
||||||
|
if opts.of_version == 1:
|
||||||
|
detokenizer.builtin_dict[0x401] = ('(pushlocals)', ['offset'])
|
||||||
|
else:
|
||||||
|
for i in range(0,9):
|
||||||
|
detokenizer.user_dict[0x407 + i] = '(pushlocals_%s)' % i
|
||||||
|
|
||||||
detokenizer.decode_stream()
|
detokenizer.decode_stream()
|
||||||
|
|
||||||
print("\nDetokenizing device packages...")
|
print("\nDetokenizing device packages...")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user