You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: binja_plugin/actions.py
+48-16Lines changed: 48 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -328,27 +328,59 @@ def run(self):
328
328
ifdetailed_operand[0] =="src"andisinstance(
329
329
detailed_operand[1], MediumLevelILConst
330
330
):
331
+
candidate_string_slice_data_addr=data_var.address
331
332
candidate_string_slice_data=data_var.value
332
-
candidate_string_slice_length=detailed_operand[
333
+
candidate_string_slice_len=detailed_operand[
333
334
1
334
335
].value.value
335
-
logger.log_info(
336
-
f"Reference to data var at {data_var.address:#x} with value {candidate_string_slice_data} is followed by store of integer with value {candidate_string_slice_length}"
f"Reference to candidate string in code at {code_ref.address:#x} with data at {candidate_string_slice_data_addr:#x} with value {candidate_string_slice_data} is followed by store of integer with value {candidate_string_slice_len}"
# Filter out any potential string slice which has length 0
341
+
ifcandidate_string_slice_len==0:
342
+
continue
343
+
# Filter out any potential string slice which is too long
344
+
if (
345
+
candidate_string_slice_len>=0x1000
346
+
): # TODO: maybe change this limit
347
+
continue
348
+
349
+
# Attempt to read out the pointed to value as a string slice, with the length obtained above.
350
+
try:
351
+
candidate_string_slice=self.bv.read(
352
+
addr=candidate_string_slice_data_addr,
353
+
length=candidate_string_slice_len,
354
+
)
355
+
exceptExceptionaserr:
356
+
logger.log_error(
357
+
f"Failed to read from address {candidate_string_slice_data_addr} with length {candidate_string_slice_len}: {err}"
358
+
)
359
+
continue
360
+
361
+
# Sanity check whether the recovered string is valid UTF-8
362
+
try:
363
+
candidate_utf8_string= (
364
+
candidate_string_slice.decode("utf-8")
365
+
)
366
+
367
+
logger.log_info(
368
+
f'Recovered string referenced in code at {code_ref.address:#x}, with data at addr {candidate_string_slice_data_addr:#x}, len {candidate_string_slice_len}: "{candidate_utf8_string}"'
369
+
)
370
+
371
+
self.bv.define_user_data_var(
372
+
addr=data_var.address,
373
+
var_type=Type.array(
374
+
type=Type.char(),
375
+
count=candidate_string_slice_len,
376
+
),
377
+
)
378
+
379
+
exceptUnicodeDecodeErroraserr:
380
+
logger.log_warn(
381
+
f"Candidate string slice {candidate_string_slice} does not decode to a valid UTF-8 string; excluding from final results: {err}"
0 commit comments