Skip to content

Commit bc6636e

Browse files
committed
Have patch candidate JSON include function stub addrs
1 parent 0ace37b commit bc6636e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

chb/cmdline/reportcmds.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,40 @@ def report_buffer_bounds(args: argparse.Namespace) -> NoReturn:
11271127
exit(0)
11281128

11291129

1130+
def collect_known_fn_addrs(app: "AppAccess", patchcallsites: list) -> dict:
1131+
function_addr = {}
1132+
def consider_pair(faddr: str, fname: Optional[str]):
1133+
if fname and fname not in function_addr:
1134+
function_addr[fname] = faddr
1135+
def consider(faddr: str):
1136+
fname = (
1137+
app.function_name(faddr)
1138+
if app.has_function_name(faddr)
1139+
else None)
1140+
consider_pair(faddr, fname)
1141+
1142+
for (faddr, blocks) in app.call_instructions().items():
1143+
consider(faddr)
1144+
for (baddr, instrs) in blocks.items():
1145+
for instr in instrs:
1146+
calltgt = instr.call_target
1147+
# The main thing we're trying to capture here is any
1148+
# name->address mappings that CodeHawk recovered with
1149+
# heuristics, which (for now) means shared object stubs.
1150+
if calltgt.is_so_target:
1151+
opcode = instr.opcode # type: ignore
1152+
if "MIPS" in repr(opcode): # ugly but concise!
1153+
# No support (or need?) for MIPS just yet
1154+
continue
1155+
optgt = opcode.opargs[0]
1156+
tgtname = cast(StubTarget, calltgt).stub.name
1157+
if optgt.is_absolute:
1158+
tgtaddr = optgt.opkind.address.get_hex()
1159+
consider_pair(tgtaddr, tgtname)
1160+
1161+
return function_addr
1162+
1163+
11301164
def report_patch_candidates(args: argparse.Namespace) -> NoReturn:
11311165

11321166
# arguments
@@ -1194,6 +1228,8 @@ def include_target(target: 'CallTarget') -> bool:
11941228

11951229
patchcallsites = libcalls.patch_callsites()
11961230

1231+
function_addr = collect_known_fn_addrs(app, patchcallsites)
1232+
11971233
content: Dict[str, Any] = {}
11981234
if xjson:
11991235
xinfodata = xinfo.to_json_result()
@@ -1232,6 +1268,7 @@ def include_target(target: 'CallTarget') -> bool:
12321268

12331269
patch_records.append(jresult.content)
12341270

1271+
content["function-addr"] = function_addr
12351272
content["patch-records"] = patch_records
12361273
chklogger.logger.debug("Number of patch callsites: %s", len(content['patch-records']))
12371274

0 commit comments

Comments
 (0)