Skip to content

Commit

Permalink
endianness: Considered.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoviceLive committed Mar 6, 2016
1 parent d000446 commit d344477
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


__author__ = 'Gu Zhengxiong'
__version__ = '0.4.0'
__version__ = '0.4.1'


PROGRAM_NAME = 'Pat'
Expand Down
6 changes: 4 additions & 2 deletions pat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
'-V', '--version', prog_name=PROGRAM_NAME)
@click.argument('argument', required=True)
@click.argument('sets', nargs=-1)
@click.option('-b', '--big-endian', is_flag=True,
help='Use big-endian.')
@click.option('-O', '--optimal', type=int,
help='Use the optimal profile in this position.')
@click.option('-o', '--output', type=click.File('w'),
help='Write to this file.')
@click.option('-c', '--clipboard', is_flag=True,
help='Output to the clipboard.')
def main(argument, sets, optimal, output, clipboard):
def main(argument, sets, big_endian, optimal, output, clipboard):
"""Customizable Exploit Pattern Utility."""
if sets and optimal:
pat = Pat.from_chars(''.join(sets), optimal)
Expand All @@ -66,7 +68,7 @@ def main(argument, sets, optimal, output, clipboard):
sys.exit(1)
else:
target = argument
index = pat.locate_pattern(target)
index = pat.locate_pattern(target, big_endian)
if index:
print(index)
else:
Expand Down
4 changes: 3 additions & 1 deletion pat/pat.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ def create_pattern(self, count):
pattern = None
return pattern

def locate_pattern(self, pattern):
def locate_pattern(self, pattern, big_endian=False):
"""Locate the pattern."""
space, self.space = tee(self.space)
if pattern.startswith('0x'):
target = unhexlify(pattern[2:]).decode('utf-8')
if not big_endian:
target = target[::-1]
else:
target = pattern
for index, one in enumerate(window(space, self.position)):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


__author__ = 'Gu Zhengxiong'
__version__ = '0.4.0'
__version__ = '0.4.1'

PROGRAM_NAME = 'Pat'
PACKAGE_NAME = 'pat'
Expand Down
5 changes: 3 additions & 2 deletions tests/test_pat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def test_create_pattern():

def test_locate_pattern():
tests = {
'Aa0': 0, 'Zz9': 20277, 'n2A': 397
'Aa0': 0, 'Zz9': 20277, 'n2A': 397,
'0x31634130': 62, '0x41326341': 66, '0x63413363': 70
}
for one in tests:
assert pat.locate_pattern(one) == tests[one]
assert pat.locate_pattern(one, big_endian=False) == tests[one]

0 comments on commit d344477

Please sign in to comment.