Skip to content

Commit 5a278f6

Browse files
committed
fix: When reecovering strings from code, also look for string data in both read-only sections and segments
Fixes #2, for real this time.
1 parent 6d91d33 commit 5a278f6

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

binja_plugin/actions.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,46 @@ def run(self):
262262
self.bv.segments,
263263
)
264264
)
265-
if len(readonly_segments) == 0:
266-
logger.log_error("Could not find any read-only segment in binary, exiting")
267-
return None
265+
266+
readonly_sections = list(
267+
filter(
268+
lambda section: section.semantics
269+
== SectionSemantics.ReadOnlyDataSectionSemantics,
270+
self.bv.sections.values(),
271+
)
272+
)
273+
274+
if len(readonly_segments) == 0 and len(readonly_sections) == 0:
275+
logger.log_error(
276+
"Could not find any read-only segments or sections in binary, exiting"
277+
)
278+
return
268279

269280
# TODO: Since the xref from data method is more reliable, we probably want to always do that as the first pass
270281
# track which ones didn't work after that first pass, and only do the ones that didn't work after the first pass here
271282

272283
# Obtain all data vars which are themselves already identified char arays, in readonly data segments.
273284
# TODO: what about non-ascii strings? will binja type them to char arrays in its initial autoanalysis?
274285
self.bv.begin_undo_actions()
275-
char_array_data_vars_in_ro_segment: List[DataVariable] = []
286+
char_array_data_vars_in_readonly_data: List[DataVariable] = []
276287
for _data_var_addr, candidate_string_slice_data in self.bv.data_vars.items():
277288
if isinstance(candidate_string_slice_data.type, ArrayType):
278-
for readonly_segment in readonly_segments:
279-
if candidate_string_slice_data.address in readonly_segment:
280-
char_array_data_vars_in_ro_segment.append(
289+
for readonly_segment_or_section in (
290+
readonly_segments + readonly_sections
291+
):
292+
if (
293+
candidate_string_slice_data.address
294+
in readonly_segment_or_section
295+
):
296+
char_array_data_vars_in_readonly_data.append(
281297
candidate_string_slice_data
282298
)
283299
logger.log_debug(
284300
f"Found char array var at {candidate_string_slice_data.address:#x} ({candidate_string_slice_data}) with value {candidate_string_slice_data.value} "
285301
)
286302

287303
# Find cross-references to those data vars, from code.
288-
for data_var in char_array_data_vars_in_ro_segment:
304+
for data_var in char_array_data_vars_in_readonly_data:
289305
code_refs = self.bv.get_code_refs(data_var.address)
290306
for code_ref in code_refs:
291307
if code_ref.mlil is not None:

0 commit comments

Comments
 (0)