-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from doronz88/feature/union
Feature/union
- Loading branch information
Showing
6 changed files
with
120 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
from typing import List | ||
|
||
from fa.commands.locate import locate_single | ||
from fa.fa_types import IDA_MODULE | ||
from fa.utils import ArgumentParserNoExit | ||
|
||
try: | ||
import ida_bytes | ||
import ida_name | ||
from ida_idaapi import BADADDR | ||
except ImportError: | ||
pass | ||
|
||
|
||
def get_parser(): | ||
def get_parser() -> ArgumentParserNoExit: | ||
p = ArgumentParserNoExit('set-name', | ||
description='set symbol name') | ||
p.add_argument('name') | ||
return p | ||
|
||
|
||
def set_name(addresses, name, interpreter): | ||
def is_address_nameless(addr: int) -> bool: | ||
return not ida_bytes.f_has_user_name(ida_bytes.get_flags(addr), None) | ||
|
||
|
||
def set_name(addresses: List[int], name: str, interpreter) -> List[int]: | ||
for ea in addresses: | ||
if IDA_MODULE: | ||
current_name = ida_name.get_ea_name(ea) | ||
remote_addr = locate_single(current_name) | ||
if current_name == name: | ||
continue | ||
|
||
# we want to avoid accidental renames from bad sigs, therefore we assert the following: | ||
assert remote_addr == BADADDR, f'Rename failed, name already used at {hex(remote_addr)} ({hex(ea)})' | ||
assert is_address_nameless(ea), f'Rename failed, address has a different name {current_name} ({hex(ea)})' | ||
|
||
interpreter.set_symbol(name, ea) | ||
return addresses | ||
|
||
|
||
def run(segments, args, addresses, interpreter=None, **kwargs): | ||
def run(segments, args, addresses: List[int], interpreter=None, **kwargs) -> List[int]: | ||
return set_name(addresses, args.name, interpreter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from argparse import RawTextHelpFormatter | ||
from typing import List | ||
|
||
from fa import utils | ||
|
||
DESCRIPTION = '''union two or more variables | ||
EXAMPLE: | ||
results = [0, 4, 8] | ||
store a | ||
... | ||
results = [0, 12, 20] | ||
store b | ||
-> union a b | ||
results = [0, 4, 8, 12, 20] | ||
''' | ||
|
||
|
||
def get_parser() -> utils.ArgumentParserNoExit: | ||
p = utils.ArgumentParserNoExit('union', | ||
description=DESCRIPTION, | ||
formatter_class=RawTextHelpFormatter) | ||
p.add_argument('variables', nargs='+', help='variable names') | ||
p.add_argument('--piped', '-p', action='store_true') | ||
return p | ||
|
||
|
||
def run(segments, args, addresses: List[int], interpreter=None, **kwargs) -> List[int]: | ||
if args.piped: | ||
first_var = addresses | ||
else: | ||
first_var = interpreter.get_variable(args.variables.pop(0)) | ||
|
||
results = set(first_var) | ||
|
||
for c in args.variables: | ||
results.update(interpreter.get_variable(c)) | ||
|
||
return list(results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters