Skip to content

Commit 4e5d4da

Browse files
authored
fix arm/thumb sys gadget discovery (#220)
1 parent 4d3e297 commit 4e5d4da

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

ropgadget/gadgets.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,24 @@ def addSYSGadgets(self, section):
436436
gadgets = [] # TODO
437437
elif arch == CS_ARCH_ARM:
438438
if self.__options.thumb or self.__options.rawMode == "thumb":
439-
gadgets = [
440-
[br"\x00-\xff]{1}\xef", 2, 2] # FIXME: svc
441-
]
439+
if arch_endian == CS_MODE_BIG_ENDIAN:
440+
gadgets = [
441+
[br"\xdf[\x00-\xff]", 2, 2] # svc imm8
442+
]
443+
else:
444+
gadgets = [
445+
[br"[\x00-\xff]\xdf", 2, 2] # svc imm8
446+
]
442447
arch_mode = CS_MODE_THUMB
443448
else:
444-
gadgets = [
445-
[br"\x00-\xff]{3}\xef", 4, 4] # FIXME: svc
446-
]
449+
if arch_endian == CS_MODE_BIG_ENDIAN:
450+
gadgets = [
451+
[br"[\x0f\x1f\x2f\x3f\x4f\x5f\x6f\x7f\x8f\x9f\xaf\xbf\xcf\xdf\xef][\x00-\xff]{3}", 4, 4] # svc{cond} imm24
452+
]
453+
else:
454+
gadgets = [
455+
[br"[\x00-\xff]{3}[\x0f\x1f\x2f\x3f\x4f\x5f\x6f\x7f\x8f\x9f\xaf\xbf\xcf\xdf\xef]", 4, 4] # svc{cond} imm24
456+
]
447457
arch_mode = CS_MODE_ARM
448458
elif arch == CS_ARCH_RISCV:
449459

test-suite-binaries/ref_output.bz2

17.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)