diff --git a/commands.md b/commands.md index d5dbd80..11606d1 100644 --- a/commands.md +++ b/commands.md @@ -28,6 +28,7 @@ Below is the list of available commands: - [make-comment](#make-comment) - [make-function](#make-function) - [make-literal](#make-literal) +- [make-offset](#make-offset) - [make-unknown](#make-unknown) - [max-xrefs](#max-xrefs) - [min-xrefs](#min-xrefs) @@ -593,6 +594,25 @@ convert into a literal options: -h, --help show this help message and exit ``` +## make-offset +``` +usage: make-offset [-h] [-l LEN] + +convert into an offset EXAMPLE: + 0x00000200: 01 02 03 04 + 0x00000204: 00 02 00 00 + + results = [0x204] + -> make-offset + results = [0x204] + + 0x00000200: 01 02 03 04 + 0x00000204: byte_200 + +options: + -h, --help show this help message and exit + -l, --len LEN length of offset in bytes +``` ## make-unknown ``` usage: make-unknown [-h] diff --git a/fa/commands/make_offset.py b/fa/commands/make_offset.py new file mode 100644 index 0000000..5c48b07 --- /dev/null +++ b/fa/commands/make_offset.py @@ -0,0 +1,52 @@ +from fa import context, utils + +try: + import ida_auto + import ida_offset + import idaapi + from idc import REF_OFF8, REF_OFF16, REF_OFF32, REF_OFF64 +except ImportError: + pass + + +DESCRIPTION = '''convert into an offset + +EXAMPLE: + 0x00000200: 01 02 03 04 + 0x00000204: 00 02 00 00 + + results = [0x204] + -> make-offset + results = [0x204] + + 0x00000200: 01 02 03 04 + 0x00000204: byte_200 +''' + + +def get_parser(): + p = utils.ArgumentParserNoExit('make-offset', + description=DESCRIPTION) + p.add_argument('-l', '--len', type=int, default=0, help='length of offset in bytes') + return p + + +@context.ida_context +def make_offset(addresses: list[int], offset_len: int = 0): + offset_length_to_ref_type = { + 0: REF_OFF64 if idaapi.get_inf_structure().is_64bit() else REF_OFF32, + 1: REF_OFF8, + 2: REF_OFF16, + 4: REF_OFF32, + 8: REF_OFF64, + } + for ea in addresses: + ida_offset.op_offset(ea, 0, offset_length_to_ref_type[offset_len]) + + ida_auto.auto_wait() + + return addresses + + +def run(segments, args, addresses, interpreter=None, **kwargs): + return make_offset(addresses, args.len) diff --git a/fa/commands/next_instruction.py b/fa/commands/next_instruction.py index f4151ee..12021ce 100644 --- a/fa/commands/next_instruction.py +++ b/fa/commands/next_instruction.py @@ -1,5 +1,6 @@ from argparse import ArgumentParser, RawTextHelpFormatter from typing import Iterable, List, Optional, Tuple + from fa import context, utils try: diff --git a/ide-completions/sublime/sig.sublime-completions b/ide-completions/sublime/sig.sublime-completions index e2e578b..f86082d 100644 --- a/ide-completions/sublime/sig.sublime-completions +++ b/ide-completions/sublime/sig.sublime-completions @@ -136,6 +136,11 @@ "kind": "snippet", "contents": "make-literal " }, + { + "trigger": "make-offset", + "kind": "snippet", + "contents": "make-offset ${1:-l} ${2:LEN}" + }, { "trigger": "make-unknown", "kind": "snippet",