From 2fd4effab5828c78632c4e155fd9b3a2ee794673 Mon Sep 17 00:00:00 2001 From: schecthellraiser606 Date: Sun, 15 Feb 2026 13:47:55 +0900 Subject: [PATCH 1/2] fix: update comment handling in render-binja-import-script.py - ret of get_comment_at is str + set_comment is unkown in ver5.2 --- scripts/render-binja-import-script.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/render-binja-import-script.py b/scripts/render-binja-import-script.py index b63dd93e9..30dd4a6a4 100644 --- a/scripts/render-binja-import-script.py +++ b/scripts/render-binja-import-script.py @@ -76,7 +76,6 @@ def render_binja_script(result_document: ResultDocument) -> str: def AppendComment(ea, s): - s = s.encode('ascii') refAddrs = [] for ref in bv.get_code_refs(ea): refAddrs.append(ref) @@ -100,7 +99,6 @@ def AppendLvarComment(fva, s): # stack var comments are not a thing in Binary Ninja so just add at top of function # and at location where it's used as an arg - s = s.encode('ascii') fn = bv.get_function_at(fva) for addr in [fva, pc]: @@ -113,7 +111,7 @@ def AppendLvarComment(fva, s): return string = string + "\\n" + s - fn.set_comment(addr, string) + fn.set_comment_at(addr, string) print("Annotating %d strings from FLOSS for %s") %s From 8d369da332b76221684da6f029b874f64dbe192c Mon Sep 17 00:00:00 2001 From: schecthellraiser606 Date: Sun, 15 Mar 2026 23:55:02 +0900 Subject: [PATCH 2/2] fix: fix Binary Ninja import script's AppendComment and AppendLvarComment functions - Remove undefined `pc` variable reference in AppendLvarComment - Add fallback handling when get_code_refs returns no references in AppendComment - Add null check for get_functions_containing to prevent crash - Add bv.set_comment_at fallback when function is not found - Add int() conversion for address parameters for type safety - Change `return` to `continue` in AppendComment loop to annotate all references --- scripts/render-binja-import-script.py | 55 +++++++++++++++++++-------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/scripts/render-binja-import-script.py b/scripts/render-binja-import-script.py index 30dd4a6a4..d869c19b8 100644 --- a/scripts/render-binja-import-script.py +++ b/scripts/render-binja-import-script.py @@ -75,13 +75,30 @@ def render_binja_script(result_document: ResultDocument) -> str: def AppendComment(ea, s): - - refAddrs = [] - for ref in bv.get_code_refs(ea): - refAddrs.append(ref) + ea = int(ea) + refAddrs = list(bv.get_code_refs(ea)) + + if not refAddrs: + fnc = bv.get_functions_containing(ea) + if fnc: + fn = fnc[0] + string = fn.get_comment_at(ea) + if not string: + fn.set_comment_at(ea, s) + elif s not in string: + fn.set_comment_at(ea, string + "\\n" + s) + else: + string = bv.get_comment_at(ea) + if not string: + bv.set_comment_at(ea, s) + elif s not in string: + bv.set_comment_at(ea, string + "\\n" + s) + return for addr in refAddrs: fnc = bv.get_functions_containing(addr.address) + if not fnc: + continue fn = fnc[0] string = fn.get_comment_at(addr.address) @@ -90,28 +107,34 @@ def AppendComment(ea, s): string = s # no existing comment else: if s in string: # ignore duplicates - return + continue string = string + "\\n" + s fn.set_comment_at(addr.address, string) -def AppendLvarComment(fva, s): +def AppendLvarComment(fva, s): # stack var comments are not a thing in Binary Ninja so just add at top of function - # and at location where it's used as an arg + fva = int(fva) fn = bv.get_function_at(fva) + if not fn: + string = bv.get_comment_at(fva) + if not string: + bv.set_comment_at(fva, s) + elif s not in string: + bv.set_comment_at(fva, string + "\\n" + s) + return - for addr in [fva, pc]: - string = fn.get_comment_at(addr) + string = fn.get_comment_at(fva) - if not string: - string = s - else: - if s in string: # ignore duplicates - return - string = string + "\\n" + s + if not string: + string = s + else: + if s in string: # ignore duplicates + return + string = string + "\\n" + s - fn.set_comment_at(addr, string) + fn.set_comment_at(fva, string) print("Annotating %d strings from FLOSS for %s") %s