Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ropper/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ def _initBadInstructions(self):

def _initCategories(self):
self._categories = {
gadget.Category.STACK_PIVOT : (('^sub (?P<dst>.sp), (?P<src>[x0-9a-fA-F]+)$','^add (?P<dst>.sp), (?P<src>[x0-9a-fA-F]+)$','^mov (?P<dst>.sp), .+ ptr \[(?P<src>...)\]$','^mov (?P<dst>.sp), (?P<src>...)$','^xchg (?P<dst>.sp), (?P<src>...)$','^xchg (?P<dst>...), (?P<src>.sp)$','ret.+'),('push','mov','call','jmp')),
gadget.Category.LOAD_MEM : (('mov (?P<dst>...), .+ ptr \[(?P<src>...)\]',),('push','mov','call','jmp')),
gadget.Category.WRITE_MEM : (('^mov .+ ptr \[(?P<dst>...)\], (?P<src>...)$',),('push','mov','call','jmp')),
gadget.Category.STACK_PIVOT : (('^sub (?P<dst>.sp), (?P<src>[x0-9a-fA-F]+)$','^add (?P<dst>.sp), (?P<src>[x0-9a-fA-F]+)$',r'^mov (?P<dst>.sp), .+ ptr \[(?P<src>...)\]$','^mov (?P<dst>.sp), (?P<src>...)$','^xchg (?P<dst>.sp), (?P<src>...)$','^xchg (?P<dst>...), (?P<src>.sp)$','ret.+'),('push','mov','call','jmp')),
gadget.Category.LOAD_MEM : ((r'mov (?P<dst>...), .+ ptr \[(?P<src>...)\]',),('push','mov','call','jmp')),
gadget.Category.WRITE_MEM : ((r'^mov .+ ptr \[(?P<dst>...)\], (?P<src>...)$',),('push','mov','call','jmp')),
gadget.Category.LOAD_REG : (('pop (?P<dst>...)',),('push','mov','call','jmp')),
gadget.Category.JMP : (('^jmp (?P<dst>...)$',),()),
gadget.Category.CALL : (('^call (?P<dst>...)$',),('push','mov','call','jmp')),
Expand Down Expand Up @@ -294,9 +294,9 @@ def _initBadInstructions(self):

def _initCategories(self):
self._categories = {
gadget.Category.STACK_PIVOT : (('^mov (?P<dst>.sp), .+ ptr \[(?P<src>...)\]$','^mov (?P<dst>.sp), (?P<src>...)$','^xchg (?P<dst>.sp), (?P<src>...)$','^xchg (?P<dst>...), (?P<src>.sp)$','ret.+'),('push','mov','call','jmp')),
gadget.Category.LOAD_MEM : (('mov (?P<dst>r..), .+ ptr \[(?P<src>r..)\]',),('push','mov','call','jmp')),
gadget.Category.WRITE_MEM : (('^mov .+ ptr \[(?P<dst>r..)\], (?P<src>r..)$',),('push','mov','call','jmp')),
gadget.Category.STACK_PIVOT : ((r'^mov (?P<dst>.sp), .+ ptr \[(?P<src>...)\]$','^mov (?P<dst>.sp), (?P<src>...)$','^xchg (?P<dst>.sp), (?P<src>...)$','^xchg (?P<dst>...), (?P<src>.sp)$','ret.+'),('push','mov','call','jmp')),
gadget.Category.LOAD_MEM : ((r'mov (?P<dst>r..), .+ ptr \[(?P<src>r..)\]',),('push','mov','call','jmp')),
gadget.Category.WRITE_MEM : ((r'^mov .+ ptr \[(?P<dst>r..)\], (?P<src>r..)$',),('push','mov','call','jmp')),
gadget.Category.LOAD_REG : (('pop (?P<dst>r..)',),('push','mov','call','jmp')),
gadget.Category.JMP : (('^jmp (?P<dst>r..)$',),()),
gadget.Category.CALL : (('^call (?P<dst>r..)$',),('push','mov','call','jmp')),
Expand Down
2 changes: 1 addition & 1 deletion ropper/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def do_search(self, text):
if len(text) == 0:
self.help_search()
return
match = re.match('/\d+/', text)
match = re.match(r'/\d+/', text)
qual = None
if match:
qual = int(match.group(0)[1:-1])
Expand Down
4 changes: 2 additions & 2 deletions ropper/rop.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _formatOpcodeString(self, opcode, regex=True):
if opcode.find(b) % 2 == 0:
opcode = opcode.replace(b,b'%s%s' % (hexlify(b'\\'),b))

m = re.search(b'\?', opcode)
m = re.search(rb'\?', opcode)
while m:
if m.start() % 2 == 0:
char = opcode[m.start()+1]
Expand All @@ -184,7 +184,7 @@ def _formatOpcodeString(self, opcode, regex=True):

opcode = opcode[:m.start()-1] + hexlify(b'['+pack('B',start)+b'-'+pack('B',end)+b']') + opcode[m.start()+1:]

m = re.search(b'\?', opcode)
m = re.search(rb'\?', opcode)
try:

opcode = unhexlify(opcode)
Expand Down
4 changes: 2 additions & 2 deletions ropper/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

class Searcher(object):

CONSTRAINT_REGEX = '(\[?[a-zA-Z0-9]+\]?)([\+\*\-=/])?=(\[?[a-zA-Z0-9]+\]?)$'
CONSTRAINT_REGEX = r'(\[?[a-zA-Z0-9]+\]?)([\+\*\-=/])?=(\[?[a-zA-Z0-9]+\]?)$'

def prepareFilter(self, filter):
filter = filter.replace('\\','\\\\')
Expand Down Expand Up @@ -257,6 +257,6 @@ class SearcherMIPS(Searcher):

def prepareFilter(self, filter):
filter = super(SearcherMIPS, self).prepareFilter(filter)
filter = filter.replace('$','\$')
filter = filter.replace('$',r'\$')

return filter
4 changes: 2 additions & 2 deletions ropper/z3helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class ConstraintCompiler(object):

NUMBER_REGEX = '(-?[0-9]+)'
REG_REGEX = '(?P<{}>[a-zA-Z0-9]+)'
ADJUST_REGEX = '([\\+\-\*/=]=)'
ASSIGNMENT_REGEX = '('+REG_REGEX.format('reg_dst_1') + ' *' + ADJUST_REGEX + ' *('+NUMBER_REGEX+'|'+REG_REGEX.format('reg_src_1')+'|(\[)'+REG_REGEX.format('reg_src_2')+'(\])))'
ADJUST_REGEX = '([\\+\\-\\*/=]=)'
ASSIGNMENT_REGEX = '('+REG_REGEX.format('reg_dst_1') + ' *' + ADJUST_REGEX + ' *('+NUMBER_REGEX+'|'+REG_REGEX.format('reg_src_1')+r'|(\[)'+REG_REGEX.format('reg_src_2')+r'(\])))'
POP_REGEX = '((pop) +'+REG_REGEX.format('reg_dst_2')+')'
CONSTRAINT_REGEX = '(' + ASSIGNMENT_REGEX + '|' + POP_REGEX + ')'

Expand Down
4 changes: 2 additions & 2 deletions testcases/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_opcode_failures(self):

if version_info.major == 3 and version_info.minor >= 2:
# Wrong question mark position
with self.assertRaisesRegex(RopperError,'A \? for the highest 4 bit of a byte is not supported.*'):
with self.assertRaisesRegex(RopperError,r'A \? for the highest 4 bit of a byte is not supported.*'):
self.rs.searchOpcode('ff?4')
# Wrong lengh
with self.assertRaisesRegex(RopperError,'The length of the opcode has to be a multiple of two'):
Expand All @@ -94,7 +94,7 @@ def test_opcode_failures(self):
self.rs.searchOpcode('ff4r')
else:
# Wrong question mark position
with self.assertRaisesRegexp(RopperError,'A \? for the highest 4 bit of a byte is not supported.*'):
with self.assertRaisesRegexp(RopperError,r'A \? for the highest 4 bit of a byte is not supported.*'):
self.rs.searchOpcode('ff?4')
# Wrong lengh
with self.assertRaisesRegexp(RopperError,'The length of the opcode has to be a multiple of two'):
Expand Down