Skip to content

Commit

Permalink
Merge pull request #177 from JonathanSalwan/fix-unprintable-strings
Browse files Browse the repository at this point in the history
Fix --string: replace non-printable characters with dots
  • Loading branch information
SweetVishnya authored Mar 11, 2022
2 parents 2799019 + 4dfdf6d commit 40d4145
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ropgadget/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import binascii
import cmd
import re
import string

from capstone import CS_MODE_32

Expand Down Expand Up @@ -155,7 +156,7 @@ def __lookingForMIPSgadgets(self, mips_option):
print("\nUnique gadgets found: %d" % gadget_counter)
return True

def __lookingForAString(self, string):
def __lookingForAString(self, s):
if not self.__checksBeforeManipulations():
return False

Expand All @@ -169,11 +170,13 @@ def __lookingForAString(self, string):
section = self._sectionInRange(section)
if not section:
continue
allRef = [m.start() for m in re.finditer(string.encode(), section["opcodes"])]
allRef = [m.start() for m in re.finditer(s.encode(), section["opcodes"])]
for ref in allRef:
vaddr = self.__offset + section["vaddr"] + ref
match = section["opcodes"][ref:ref + len(string)]
print("0x{{0:0{}x}} : {{1}}".format(8 if arch == CS_MODE_32 else 16).format(vaddr, match.decode()))
match = section["opcodes"][ref:ref + len(s)]
printable = string.printable.encode()
match = "".join((chr(m) if isinstance(m, int) else m) if m in printable else "." for m in match)
print("0x{{0:0{}x}} : {{1}}".format(8 if arch == CS_MODE_32 else 16).format(vaddr, match))
return True

def __lookingForOpcodes(self, opcodes):
Expand Down

0 comments on commit 40d4145

Please sign in to comment.