getfunction inline asm option

This commit is contained in:
Seeky 2022-10-31 19:27:21 +00:00
parent a27d8424c6
commit 409de2dada

View File

@ -9,7 +9,7 @@ from tempfile import NamedTemporaryFile
import common as c
def get_function(binary: c.Binary, source: c.SourceDesc, addr: int, extra: bool) -> str:
def get_function(binary: c.Binary, source: c.SourceDesc, addr: int, extra: bool, inline=False) -> str:
# Get context
ctx = c.DOL_CTX if binary == c.Binary.DOL else c.REL_CTX
assert os.path.exists(ctx.labels), "Error: analysis has not ran!"
@ -17,12 +17,13 @@ def get_function(binary: c.Binary, source: c.SourceDesc, addr: int, extra: bool)
# Disassemble function
extraflag = "-e" if extra else ""
srcflag = f"-n {source}" if isinstance(source, str) else ""
inlineflag = "-i" if inline else ""
with NamedTemporaryFile(suffix=".s", delete=False) as tmp:
try:
tmp.close()
ret = system(
f"{c.DISASSEMBLER} {ctx.binary} {ctx.labels} {ctx.relocs} {tmp.name} -f {addr:x} "
f"-m {c.GAME_SYMBOLS} {srcflag} -q {extraflag}"
f"-m {c.GAME_SYMBOLS} {srcflag} -q {extraflag} {inlineflag}"
)
assert ret == 0, f"Disassembly error code {ret}"
with open(tmp.name) as f:
@ -40,6 +41,7 @@ if __name__=="__main__":
parser.add_argument("-d", "--dol", action="store_true", help="Prioritise dol-local symbols")
parser.add_argument("-r", "--rel", action="store_true", help="Prioritise rel-local symbols")
parser.add_argument("-n", "--source-name", type=str, help="Prioritise source-local symbols")
parser.add_argument("-i", "--inline", action="store_true", help="Output as inline assembly")
args = parser.parse_args()
# Find address
@ -50,4 +52,4 @@ if __name__=="__main__":
# Find containing binary
binary, source = c.get_containing_slice(addr)
print(get_function(binary, source, addr, args.extra))
print(get_function(binary, source, addr, args.extra, args.inline))