forked from bongtrop/hbctool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix FunctionHeader Overflowed and add hasm dump feature
- Loading branch information
Pongsakorn Sommalai
committed
Jan 10, 2021
1 parent
62647c2
commit c01b503
Showing
9 changed files
with
85 additions
and
19 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,4 +135,8 @@ dmypy.json | |
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
cython_debug/ | ||
|
||
# Custom | ||
output/* | ||
!output/.gitkeep |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,45 @@ | ||
from util import * | ||
import json | ||
import os | ||
|
||
def to_hasm(f, hbc): | ||
def dump(hbc, path): | ||
assert not os.path.exists(path), f"'{path}' exists." | ||
os.makedirs(path) | ||
# Write all obj to metadata.json | ||
json.dump(hbc.getObj(), open(f"{path}/metadata.json", "w")) | ||
|
||
stringCount = hbc.getStringCount() | ||
functionCount = hbc.getFunctionCount() | ||
|
||
f = open(f"{path}/instruction.hasm", "w") | ||
for i in range(functionCount): | ||
functionName, paramCount, registerCount, symbolCount, inst, _ = hbc.getFunction(i) | ||
functionName, paramCount, registerCount, symbolCount, insts, _ = hbc.getFunction(i) | ||
# Function<>1270(2 params, 1 registers, 0 symbols): | ||
f.write(f"Function<{functionName.decode()}>{i}({paramCount} params, {registerCount} registers, {symbolCount} symbols):\n") | ||
for opcode, operands in insts: | ||
f.write(f"\t{opcode.ljust(20,' ')}\t") | ||
o = [] | ||
ss = [] | ||
for ii, v in enumerate(operands): | ||
t, is_str, val = v | ||
o.append(f"{t}:{val}") | ||
|
||
if is_str: | ||
s = hbc.getString(val) | ||
ss.append((ii, val, s)) | ||
|
||
|
||
f.write(f"{', '.join(o)}\n") | ||
if len(ss) > 0: | ||
for ii, val, s in ss: | ||
try: | ||
s = f"\"{s.decode()}\"" | ||
except UnicodeDecodeError: | ||
s = f"hex({s.hex()})" | ||
|
||
f.write(f"\t; Oper[{ii}]: String({val}) {s}\n") | ||
|
||
f.write("\n") | ||
|
||
f.write("EndFunction\n\n") | ||
f.close() |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
from hbc import parseFromFile | ||
|
||
def to_hasm(): | ||
pass | ||
|
||
import hasm | ||
|
||
if __name__ == "__main__": | ||
hbc = parseFromFile(open("hbc/hbc74/example/index.android.bundle", "rb")) | ||
functionName, paramCount, registerCount, symbolCount, inst, _ = hbc.getFunction(3819) | ||
|
||
|
||
pass |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from hbc import parseFromFile | ||
import hasm | ||
|
||
if __name__ == "__main__": | ||
hbc = parseFromFile(open("hbc/hbc74/example/index.android.bundle", "rb")) | ||
hasm.dump(hbc, "output/test") |