Skip to content

Commit

Permalink
convert all EOLs CRLF->LF
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Aug 29, 2020
1 parent c8d2ffb commit 345265b
Show file tree
Hide file tree
Showing 53 changed files with 4,351 additions and 4,350 deletions.
1,346 changes: 673 additions & 673 deletions LICENSE

Large diffs are not rendered by default.

1,006 changes: 503 additions & 503 deletions README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,8 @@ optional arguments:
```
## xrefs-to
```
usage: xrefs-to [-h] [--function-start] [--or] [--and] [--name NAME] [--bytes BYTES]
usage: xrefs-to [-h] [--function-start] [--or] [--and] [--name NAME]
[--bytes BYTES]
search for xrefs pointing at given parameter
Expand Down
100 changes: 50 additions & 50 deletions elf_loader.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
from elftools.elf import elffile
import click

from fa import fainterp


class ElfLoader(fainterp.FaInterp):
def __init__(self):
super(ElfLoader, self).__init__()
self._elf = None

def reload_segments(self):
pass

def set_input(self, input_):
self._elf = elffile.ELFFile(input_)
self.endianity = '<' if self._elf.little_endian else '>'

self._segments = {}
for s in self._elf.iter_segments():
if s.header['p_type'] != 'PT_LOAD':
continue
self.segments[s.header['p_vaddr']] = s.data()

@property
def segments(self):
return self._segments


@click.command()
@click.argument('elf_file', type=click.File('rb'))
@click.argument('signatures_root')
@click.argument('project')
def main(elf_file, signatures_root, project):
interp = ElfLoader()
interp.set_input(elf_file)
interp.set_signatures_root(signatures_root)
interp.set_project(project)

for k, v in interp.symbols().items():
if isinstance(v, list) or isinstance(v, set):
if len(v) > 1:
print('# {} multiple matches'.format(k))
continue
v = v.pop()
print('{} = 0x{:x};'.format(k, v))


if __name__ == '__main__':
main()
from elftools.elf import elffile
import click

from fa import fainterp


class ElfLoader(fainterp.FaInterp):
def __init__(self):
super(ElfLoader, self).__init__()
self._elf = None

def reload_segments(self):
pass

def set_input(self, input_):
self._elf = elffile.ELFFile(input_)
self.endianity = '<' if self._elf.little_endian else '>'

self._segments = {}
for s in self._elf.iter_segments():
if s.header['p_type'] != 'PT_LOAD':
continue
self.segments[s.header['p_vaddr']] = s.data()

@property
def segments(self):
return self._segments


@click.command()
@click.argument('elf_file', type=click.File('rb'))
@click.argument('signatures_root')
@click.argument('project')
def main(elf_file, signatures_root, project):
interp = ElfLoader()
interp.set_input(elf_file)
interp.set_signatures_root(signatures_root)
interp.set_project(project)

for k, v in interp.symbols().items():
if isinstance(v, list) or isinstance(v, set):
if len(v) > 1:
print('# {} multiple matches'.format(k))
continue
v = v.pop()
print('{} = 0x{:x};'.format(k, v))


if __name__ == '__main__':
main()
44 changes: 22 additions & 22 deletions fa/commands/add.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from argparse import RawTextHelpFormatter
from fa import utils

DESCRIPTION = '''add an hard-coded value into resultset
EXAMPLE:
results = []
-> add 80
result = [80]
'''


def get_parser():
p = utils.ArgumentParserNoExit('add',
description=DESCRIPTION,
formatter_class=RawTextHelpFormatter)
p.add_argument('value')
return p


def run(segments, args, addresses, interpreter=None, **kwargs):
return addresses + [eval(args.value)]
from argparse import RawTextHelpFormatter
from fa import utils

DESCRIPTION = '''add an hard-coded value into resultset
EXAMPLE:
results = []
-> add 80
result = [80]
'''


def get_parser():
p = utils.ArgumentParserNoExit('add',
description=DESCRIPTION,
formatter_class=RawTextHelpFormatter)
p.add_argument('value')
return p


def run(segments, args, addresses, interpreter=None, **kwargs):
return addresses + [eval(args.value)]
66 changes: 33 additions & 33 deletions fa/commands/add_offset_range.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
from argparse import RawTextHelpFormatter
from fa import utils


DESCRIPTION = '''adds a python-range to resultset
EXAMPLE:
result = [0, 0x200]
-> add-offset-range 0 4 8
result = [0, 4, 8, 0x200, 0x204, 0x208]
'''


def get_parser():
p = utils.ArgumentParserNoExit('add-offset-range',
description=DESCRIPTION,
formatter_class=RawTextHelpFormatter)
p.add_argument('start')
p.add_argument('end')
p.add_argument('step')
return p


def add_offset_range(addresses, start, end, step):
for ea in addresses:
for i in range(start, end, step):
yield ea + i


def run(segments, args, addresses, interpreter=None, **kwargs):
gen = add_offset_range(addresses, eval(args.start), eval(args.end),
eval(args.step))
return list(gen)
from argparse import RawTextHelpFormatter
from fa import utils


DESCRIPTION = '''adds a python-range to resultset
EXAMPLE:
result = [0, 0x200]
-> add-offset-range 0 4 8
result = [0, 4, 8, 0x200, 0x204, 0x208]
'''


def get_parser():
p = utils.ArgumentParserNoExit('add-offset-range',
description=DESCRIPTION,
formatter_class=RawTextHelpFormatter)
p.add_argument('start')
p.add_argument('end')
p.add_argument('step')
return p


def add_offset_range(addresses, start, end, step):
for ea in addresses:
for i in range(start, end, step):
yield ea + i


def run(segments, args, addresses, interpreter=None, **kwargs):
gen = add_offset_range(addresses, eval(args.start), eval(args.end),
eval(args.step))
return list(gen)
18 changes: 9 additions & 9 deletions fa/commands/alias
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ppc32-big-find-all = keystone-find-opcodes KS_ARCH_PPC KS_MODE_BIG_ENDIAN|KS_MODE_PPC32
ppc32-find-all = keystone-find-opcodes --bele KS_ARCH_PPC KS_MODE_PPC32
ppc32-big-verify = keystone-verify-opcodes KS_ARCH_PPC KS_MODE_BIG_ENDIAN|KS_MODE_PPC32
ppc32-verify = keystone-verify-opcodes --bele KS_ARCH_PPC KS_MODE_PPC32
arm-find-all = keystone-find-opcodes --bele KS_ARCH_ARM KS_MODE_ARM
thumb-find-all = keystone-find-opcodes --bele KS_ARCH_ARM KS_MODE_THUMB
arm-verify = keystone-verify-opcodes --bele KS_ARCH_ARM KS_MODE_ARM
find-imm = find-immediate
save = store
ppc32-big-find-all = keystone-find-opcodes KS_ARCH_PPC KS_MODE_BIG_ENDIAN|KS_MODE_PPC32
ppc32-find-all = keystone-find-opcodes --bele KS_ARCH_PPC KS_MODE_PPC32
ppc32-big-verify = keystone-verify-opcodes KS_ARCH_PPC KS_MODE_BIG_ENDIAN|KS_MODE_PPC32
ppc32-verify = keystone-verify-opcodes --bele KS_ARCH_PPC KS_MODE_PPC32
arm-find-all = keystone-find-opcodes --bele KS_ARCH_ARM KS_MODE_ARM
thumb-find-all = keystone-find-opcodes --bele KS_ARCH_ARM KS_MODE_THUMB
arm-verify = keystone-verify-opcodes --bele KS_ARCH_ARM KS_MODE_ARM
find-imm = find-immediate
save = store
52 changes: 26 additions & 26 deletions fa/commands/align.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
from argparse import RawTextHelpFormatter
from fa import utils

DESCRIPTION = '''align results to given base (round-up)
EXAMPLE:
results = [0, 2, 4, 6, 8]
-> align 4
results = [0, 4, 4, 8, 8]
'''


def get_parser():
p = utils.ArgumentParserNoExit('align',
description=DESCRIPTION,
formatter_class=RawTextHelpFormatter)
p.add_argument('value')
return p


def align(addresses, value):
return [((ea + (value - 1)) // value) * value for ea in addresses]


def run(segments, args, addresses, interpreter=None, **kwargs):
return list(align(addresses, eval(args.value)))
from argparse import RawTextHelpFormatter
from fa import utils

DESCRIPTION = '''align results to given base (round-up)
EXAMPLE:
results = [0, 2, 4, 6, 8]
-> align 4
results = [0, 4, 4, 8, 8]
'''


def get_parser():
p = utils.ArgumentParserNoExit('align',
description=DESCRIPTION,
formatter_class=RawTextHelpFormatter)
p.add_argument('value')
return p


def align(addresses, value):
return [((ea + (value - 1)) // value) * value for ea in addresses]


def run(segments, args, addresses, interpreter=None, **kwargs):
return list(align(addresses, eval(args.value)))
62 changes: 31 additions & 31 deletions fa/commands/b.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
from argparse import RawTextHelpFormatter
from fa import utils

DESCRIPTION = '''branch unconditionally to label
EXAMPLE:
results = []
add 1
-> b skip
add 2
label skip
add 3
results = [1, 3]
'''


def get_parser():
p = utils.ArgumentParserNoExit('b',
description=DESCRIPTION,
formatter_class=RawTextHelpFormatter)
p.add_argument('label', help='label to jump to')
return p


def run(segments, args, addresses, interpreter=None, **kwargs):
interpreter.set_pc(args.label)
# pc is incremented by 1, after each instruction
interpreter.dec_pc()
return addresses
from argparse import RawTextHelpFormatter
from fa import utils

DESCRIPTION = '''branch unconditionally to label
EXAMPLE:
results = []
add 1
-> b skip
add 2
label skip
add 3
results = [1, 3]
'''


def get_parser():
p = utils.ArgumentParserNoExit('b',
description=DESCRIPTION,
formatter_class=RawTextHelpFormatter)
p.add_argument('label', help='label to jump to')
return p


def run(segments, args, addresses, interpreter=None, **kwargs):
interpreter.set_pc(args.label)
# pc is incremented by 1, after each instruction
interpreter.dec_pc()
return addresses
32 changes: 16 additions & 16 deletions fa/commands/find.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from fa import utils


def get_parser():
p = utils.ArgumentParserNoExit('find',
description='find another symbol defined '
'in other SIG files')
p.add_argument('name', help='symbol name')
return p


def run(segments, args, addresses, interpreter=None, **kwargs):
interpreter.find(args.name)

# return an empty result-set
return []
from fa import utils


def get_parser():
p = utils.ArgumentParserNoExit('find',
description='find another symbol defined '
'in other SIG files')
p.add_argument('name', help='symbol name')
return p


def run(segments, args, addresses, interpreter=None, **kwargs):
interpreter.find(args.name)

# return an empty result-set
return []
Loading

0 comments on commit 345265b

Please sign in to comment.