Skip to content

Commit

Permalink
Merge pull request #169 from JonathanSalwan/linter
Browse files Browse the repository at this point in the history
Add Python linter
  • Loading branch information
SweetVishnya committed Jan 17, 2021
2 parents c8b2440 + a30c6f3 commit 82ea700
Show file tree
Hide file tree
Showing 23 changed files with 536 additions and 451 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: CI

on:
push:
branches:
- master
pull_request:

jobs:
Expand All @@ -13,6 +11,8 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Python code style linter
uses: wemake-services/wemake-python-styleguide@0.14.1
- name: Build
run: |
python2 -m pip install --upgrade setuptools wheel
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Usage
--dump Outputs the gadget bytes
--silent Disables printing of gadgets during analysis
--align ALIGN Align gadgets addresses (in bytes)
--mipsrop <rtype> Mips useful gadgets finder
--mipsrop <rtype> MIPS useful gadgets finder
stackfinder|system|tails|lia0|registers

How can I contribute ?
----------------------
Expand Down
5 changes: 3 additions & 2 deletions ropgadget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import ropgadget.binary
import ropgadget.core
import ropgadget.gadgets
import ropgadget.loaders
import ropgadget.options
import ropgadget.rgutils
import ropgadget.ropchain
import ropgadget.updateAlert
import ropgadget.version
import ropgadget.loaders
import ropgadget.ropchain


def main():
import sys
Expand Down
20 changes: 10 additions & 10 deletions ropgadget/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import sys

from ropgadget.updateAlert import UpdateAlert
from ropgadget.version import *
from ropgadget.version import *


class Args(object):
def __init__(self, arguments=None):
Expand All @@ -19,9 +20,8 @@ def __init__(self, arguments=None):

# If no custom arguments are provided, use the program arguments
if not arguments:
arguments = sys.argv[1:]
custom_arguments_provided = False

arguments = sys.argv[1:]
custom_arguments_provided = False

self.__parse(arguments, custom_arguments_provided)

Expand Down Expand Up @@ -85,7 +85,7 @@ def __parse(self, arguments, custom_arguments_provided=False):
parser.add_argument("--re", type=str, metavar="<re>", help="Regular expression")
parser.add_argument("--offset", type=str, metavar="<hexaddr>", help="Specify an offset for gadget addresses")
parser.add_argument("--ropchain", action="store_true", help="Enable the ROP chain generation")
parser.add_argument("--thumb" , action="store_true", help="Use the thumb mode for the search engine (ARM only)")
parser.add_argument("--thumb", action="store_true", help="Use the thumb mode for the search engine (ARM only)")
parser.add_argument("--console", action="store_true", help="Use an interactive console for search engine")
parser.add_argument("--norop", action="store_true", help="Disable ROP search engine")
parser.add_argument("--nojop", action="store_true", help="Disable JOP search engine")
Expand All @@ -97,7 +97,7 @@ def __parse(self, arguments, custom_arguments_provided=False):
parser.add_argument("--dump", action="store_true", help="Outputs the gadget bytes")
parser.add_argument("--silent", action="store_true", help="Disables printing of gadgets during analysis")
parser.add_argument("--align", type=int, help="Align gadgets addresses (in bytes)")
parser.add_argument("--mipsrop", type=str, metavar="<rtype>",help="Mips useful gadgets finder")
parser.add_argument("--mipsrop", type=str, metavar="<rtype>", help="MIPS useful gadgets finder stackfinder|system|tails|lia0|registers")

self.__args = parser.parse_args(arguments)

Expand Down Expand Up @@ -131,10 +131,10 @@ def __parse(self, arguments, custom_arguments_provided=False):
raise ValueError("[Error] The start value must be greater than end value")

def __printVersion(self):
print("Version: %s" %(PYROPGADGET_VERSION))
print("Author: Jonathan Salwan" )
print("Author page: https://twitter.com/JonathanSalwan" )
print("Project page: http://shell-storm.org/project/ROPgadget/" )
print("Version: %s" % (PYROPGADGET_VERSION))
print("Author: Jonathan Salwan")
print("Author page: https://twitter.com/JonathanSalwan")
print("Project page: http://shell-storm.org/project/ROPgadget/")

def getArgs(self):
return self.__args
29 changes: 18 additions & 11 deletions ropgadget/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
## http://shell-storm.org/project/ROPgadget/
##

from ropgadget.loaders.elf import *
from ropgadget.loaders.pe import *
from ropgadget.loaders.raw import *
from ropgadget.loaders.macho import *
from ropgadget.loaders.universal import *
from binascii import unhexlify

from ropgadget.loaders.elf import *
from ropgadget.loaders.macho import *
from ropgadget.loaders.pe import *
from ropgadget.loaders.raw import *
from ropgadget.loaders.universal import *


class Binary(object):
def __init__(self, options):
self.__fileName = options.binary
Expand All @@ -27,16 +29,21 @@ def __init__(self, options):
print("[Error] Can't open the binary or binary not found")
return None

if options.rawArch and options.rawMode:
self.__binary = Raw(self.__rawBinary, options.rawArch, options.rawMode, options.rawEndian)
if options.rawArch and options.rawMode:
self.__binary = Raw(
self.__rawBinary,
options.rawArch,
options.rawMode,
options.rawEndian,
)
elif self.__rawBinary[:4] == unhexlify(b"7f454c46"):
self.__binary = ELF(self.__rawBinary)
self.__binary = ELF(self.__rawBinary)
elif self.__rawBinary[:2] == unhexlify(b"4d5a"):
self.__binary = PE(self.__rawBinary)
self.__binary = PE(self.__rawBinary)
elif self.__rawBinary[:4] == unhexlify(b"cafebabe"):
self.__binary = UNIVERSAL(self.__rawBinary)
self.__binary = UNIVERSAL(self.__rawBinary)
elif self.__rawBinary[:4] == unhexlify(b"cefaedfe") or self.__rawBinary[:4] == unhexlify(b"cffaedfe"):
self.__binary = MACHO(self.__rawBinary)
self.__binary = MACHO(self.__rawBinary)
else:
print("[Error] Binary format not supported")
return None
Expand Down
Loading

0 comments on commit 82ea700

Please sign in to comment.