From 86f2b63df39a1d7298cd3bc75a55bd309e618f25 Mon Sep 17 00:00:00 2001 From: DoronZ Date: Wed, 22 Jul 2020 01:28:56 +0300 Subject: [PATCH] commands: verify-ref: support no name --- commands.md | 12 +++++----- fa/commands/verify_ref.py | 22 ++++++++++++------- .../test-project-ida/test-ida-context.sig | 10 ++++++++- tests/test_commands/test_idalink.py | 5 ++++- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/commands.md b/commands.md index 7e56221..2084fc1 100644 --- a/commands.md +++ b/commands.md @@ -729,17 +729,15 @@ optional arguments: ``` ## verify-ref ``` -usage: verify-ref [-h] [--code] [--data] name +usage: verify-ref [-h] [--code] [--data] [--name NAME] verifies a given reference exists to current result set -positional arguments: - name - optional arguments: - -h, --help show this help message and exit - --code include code references - --data include data references + -h, --help show this help message and exit + --code include code references + --data include data references + --name NAME symbol name ``` ## verify-segment ``` diff --git a/fa/commands/verify_ref.py b/fa/commands/verify_ref.py index 02b03a0..5f1114f 100644 --- a/fa/commands/verify_ref.py +++ b/fa/commands/verify_ref.py @@ -16,16 +16,17 @@ def get_parser(): default=False, help='include code references') p.add_argument('--data', action='store_true', default=False, help='include data references') - p.add_argument('name') + p.add_argument('--name', default=None, help='symbol name') return p @context.ida_context -def verify_ref(addresses, name, code=False, data=False): - symbol = locate(name) +def verify_ref(addresses, name=None, code=False, data=False): + if name is not None: + symbol = locate(name) - if symbol == idc.BADADDR: - return + if symbol == idc.BADADDR: + return for address in addresses: refs = [] @@ -38,9 +39,14 @@ def verify_ref(addresses, name, code=False, data=False): continue for ref in refs: - if address + 4 != ref and symbol == ref: - yield address - break + if name is not None: + if address + 4 != ref and symbol == ref: + yield address + break + else: + if address + 4 != ref: + yield address + break @utils.yield_unique diff --git a/fa/signatures/test-project-ida/test-ida-context.sig b/fa/signatures/test-project-ida/test-ida-context.sig index fa950cd..c8e7fa9 100644 --- a/fa/signatures/test-project-ida/test-ida-context.sig +++ b/fa/signatures/test-project-ida/test-ida-context.sig @@ -24,11 +24,19 @@ function-lines verify-operand ldr --op0 0 set-name test_verify_operand + checkpoint ref + + verify-ref --code --data + set-name test_verify_ref_no_name goto-ref --data set-name test_verify_goto_ref - locate test_verify_operand + back-to-checkpoint ref + verify-ref --name test_verify_goto_ref --code --data + set-name test_verify_ref_name + + locate test_function_lines set-name test_locate clear diff --git a/tests/test_commands/test_idalink.py b/tests/test_commands/test_idalink.py index 9e8eb3f..5872c14 100644 --- a/tests/test_commands/test_idalink.py +++ b/tests/test_commands/test_idalink.py @@ -95,6 +95,9 @@ def test_ida_symbols(ida, sample_elf): assert symbols['test_function_end'] == 0x125c assert symbols['test_function_lines'] == 0x1248 assert symbols['test_verify_operand'] == 0x1250 + assert symbols['test_verify_ref_no_name'] == 0x1250 assert symbols['test_verify_goto_ref'] == 0x125c - assert symbols['test_locate'] == symbols['test_verify_operand'] + assert symbols['test_verify_ref_name'] == 0x1250 + assert symbols['test_locate'] == symbols['test_function_lines'] + assert symbols['test_find_immediate'] == 0x1240 assert symbols['test_find_immediate'] == 0x1240