Skip to content

Commit

Permalink
commands: verify-ref: support no name
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Jul 21, 2020
1 parent d459958 commit 86f2b63
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
12 changes: 5 additions & 7 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
22 changes: 14 additions & 8 deletions fa/commands/verify_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion fa/signatures/test-project-ida/test-ida-context.sig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/test_commands/test_idalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 86f2b63

Please sign in to comment.