Skip to content

Commit ea5dc1a

Browse files
committed
REL: add new section for trampoline code to section header table
1 parent 9613fdf commit ea5dc1a

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

chb/app/CHVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
chbversion: str = "0.3.0-20250825"
1+
chbversion: str = "0.3.0-20250826"

chb/cmdline/XComparison.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,36 @@ def new_userdata(self) -> Dict[str, Any]:
347347
seg["status"] = "new"
348348
sectionheaders["segment_" + str(ph2.index)] = seg
349349
result["section-headers"] = sectionheaders
350+
elif len(self.newsections) == 0 and len(self.newcode) == 1:
351+
newaddr = self.newcode[0][0]
352+
newsize = str(int(self.newcode[0][1], 16) - int(newaddr, 16))
353+
sectionheaders = {}
354+
for (name, (optsh1, optsh2)) in self.sectionheaderpairs.items():
355+
if optsh1 is not None and optsh2 is not None:
356+
if (
357+
(optsh1.vaddr == optsh2.vaddr)
358+
and (optsh1.size != optsh2.size)):
359+
sec1offset = optsh1.get_default_attribute_value(
360+
"sh_offset", "0x0")
361+
offsetdiff = int(optsh1.vaddr, 16) - int(sec1offset, 16)
362+
363+
sec1: Dict[str, str] = {}
364+
sec1["addr"] = optsh1.vaddr
365+
sec1["size"] = optsh1.size
366+
sec1["offset"] = optsh1.get_default_attribute_value(
367+
"sh_offset", "0x0")
368+
sectionheaders[name] = sec1
369+
370+
sec2offset = str(int(newaddr, 16) - offsetdiff)
371+
sec2: Dict[str, str] = {}
372+
sec2["addr"] = newaddr
373+
sec2["size"] = newsize
374+
sec2["type"] = "0x1"
375+
sec2["flags"] = "0x6"
376+
sec2["status"] = "new"
377+
sec2["offset"] = sec2offset
378+
sectionheaders[".trampolinecode"] = sec2
379+
result["section-headers"] = sectionheaders
350380
return result
351381

352382
def prepare_report(self) -> str:

chb/cmdline/relationalcmds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def relational_prepare_command(args: argparse.Namespace) -> NoReturn:
217217
with open(save_aux_userdata + ".json", "w") as fp:
218218
json.dump(userhints.hints, fp, indent=2)
219219

220-
if len(xcomparison.newsegments) > 0:
220+
if len(xcomparison.newsegments) > 0 or len(xcomparison.newcode) > 0:
221221
tmpfilename = os.path.join(path2, "tmp_userdata.json")
222222
tmpuserdata: Dict[str, Any] = {}
223223
tmpuserdata["userdata"] = userhints.hints

0 commit comments

Comments
 (0)