Skip to content

Commit

Permalink
Fix conflicts with utils module
Browse files Browse the repository at this point in the history
  • Loading branch information
alset0326 committed Jan 28, 2018
1 parent fa569e0 commit b75925a
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 296 deletions.
Empty file added __init__.py
Empty file.
Empty file added lib/__init__.py
Empty file.
5 changes: 3 additions & 2 deletions lib/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
from __future__ import print_function

import os
from utils import *
import config

from lib.utils import *
from lib import config

if config.prefix == '':
warning('Cross compile toolchain not found! You can install it from https://github.com/jsnyder/arm-eabi-toolchain')
Expand Down
1 change: 1 addition & 0 deletions lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from subprocess import Popen, PIPE


Expand Down
431 changes: 215 additions & 216 deletions lib/shellcode.py

Large diffs are not rendered by default.

23 changes: 16 additions & 7 deletions lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
import itertools
import functools
from subprocess import *
import config
import codecs

import six
from six import StringIO
from six.moves import range
from six.moves import input
from six.moves import reload_module as reload
from six.moves import cPickle as pickle
from lib import six
from lib.six import StringIO
from lib.six.moves import range
from lib.six.moves import input
from lib.six.moves import reload_module as reload
from lib.six.moves import cPickle as pickle

from lib import config


# http://wiki.python.org/moin/PythonDecoratorLibrary#Memoize
Expand Down Expand Up @@ -954,3 +955,11 @@ def pickle_loads(s):
return pickle.loads(s, encoding='iso-8859-1')
else:
return pickle.loads(s)


def import_plugin(name):
return __import__('plugins.' + name, fromlist=['plugins'])


def reload_plugin(name):
reload_module('plugins.' + name)
89 changes: 35 additions & 54 deletions peda-arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,22 @@
PEDAFILE = os.path.abspath(os.path.expanduser(__file__))
if os.path.islink(PEDAFILE):
PEDAFILE = os.readlink(PEDAFILE)
sys.path.insert(0, os.path.dirname(PEDAFILE) + "/plugins/")
sys.path.insert(0, os.path.dirname(PEDAFILE) + "/lib/")
sys.path.insert(0, os.path.dirname(PEDAFILE))

# Use six library to provide Python 2/3 compatibility
import six
from six.moves import range
from six.moves import input
from lib import six
from lib.six.moves import range
from lib.six.moves import input
from lib.six.moves import cPickle as pickle
from lib.six.moves import input

try:
import six.moves.cPickle as pickle
except ImportError:
import pickle

from skeleton import *
from shellcode import *
from utils import *
import config
from asm import *
from lib.skeleton import *
from lib.shellcode import *
from lib.utils import *
from lib import config
from lib.asm import *

info('Loading components.')

if sys.version_info.major is 3:
pyversion = 3
else:
pyversion = 2
# tode
REGISTERS = {
32: ['r' + str(i) for i in range(13)] + 'sp lr pc'.split(),
64: ['x' + str(i) for i in range(31)] + 'sp pc'.split()
Expand Down Expand Up @@ -1347,37 +1337,37 @@ def testjump(self, inst=None):

cond = match.group(2)
if (
cond == ''
cond == ''
) or (
cond == 'al'
cond == 'al'
) or (
cond == "eq" and flags["Z"]
cond == "eq" and flags["Z"]
) or (
cond == "ne" and not flags["Z"]
cond == "ne" and not flags["Z"]
) or (
(cond == 'cs' or cond == 'hs') and flags['C']
(cond == 'cs' or cond == 'hs') and flags['C']
) or (
(cond == 'cc' or cond == 'lo') and not flags['C']
(cond == 'cc' or cond == 'lo') and not flags['C']
) or (
cond == 'mi' and flags['N']
cond == 'mi' and flags['N']
) or (
cond == 'pl' and not flags['N']
cond == 'pl' and not flags['N']
) or (
cond == 'vs' and flags['V']
cond == 'vs' and flags['V']
) or (
cond == 'vc' and not flags['V']
cond == 'vc' and not flags['V']
) or (
cond == 'hi' and flags['C'] and not flags['Z']
cond == 'hi' and flags['C'] and not flags['Z']
) or (
cond == 'ls' and (not flags['C'] or flags['Z'])
cond == 'ls' and (not flags['C'] or flags['Z'])
) or (
cond == 'ge' and flags['N'] == flags['V']
cond == 'ge' and flags['N'] == flags['V']
) or (
cond == 'lt' and flags['N'] != flags['V']
cond == 'lt' and flags['N'] != flags['V']
) or (
cond == 'gt' and not flags['Z'] and flags['N'] == flags['V']
cond == 'gt' and not flags['Z'] and flags['N'] == flags['V']
) or (
cond == 'le' and flags['Z'] and flags['N'] != flags['V']
cond == 'le' and flags['Z'] and flags['N'] != flags['V']
):
return next_addr
else:
Expand Down Expand Up @@ -1417,9 +1407,9 @@ def testjump_cb(self, inst=None):
next_addr = 0

if (
cond == 'z' and r == 0
cond == 'z' and r == 0
) or (
cond == 'nz' and r != 0
cond == 'nz' and r != 0
):
return next_addr
else:
Expand Down Expand Up @@ -6120,32 +6110,23 @@ def list_shellcode():
while True:
for os in oslist:
msg('%s %s' % (yellow('[+]'), green(os)))
if pyversion is 2:
os = input('%s' % blue('os:'))
if pyversion is 3:
os = input('%s' % blue('os:'))
os = input('%s' % blue('os:'))
if os in oslist: # check if os exist
break
else:
warning("Wrong input! Try Again.")
while True:
for job in joblist:
msg('%s %s' % (yellow('[+]'), green(job)))
if pyversion is 2:
job = raw_input('%s' % blue('job:'))
if pyversion is 3:
job = input('%s' % blue('job:'))
job = input('%s' % blue('job:'))
if job != '':
break
else:
warning("Please enter a function.")
while True:
for encode in encodelist:
msg('%s %s' % (yellow('[+]'), green(encode)))
if pyversion is 2:
encode = raw_input('%s' % blue('encode:'))
if pyversion is 3:
encode = input('%s' % blue('encode:'))
encode = input('%s' % blue('encode:'))
if encode != '':
break
else:
Expand Down Expand Up @@ -6351,7 +6332,7 @@ def plugin(self, *arg):
self.plugin.__func__.options = []
for f in os.listdir(os.path.dirname(PEDAFILE) + "/plugins/"):
if f.endswith('-plugin.py'):
tmp = f[:-10]
tmp = f.rstrip('-plugin.py')
self.plugin.__func__.options.append(tmp)
files.append(green(tmp) + red('*') if tmp in self.plugins else tmp)
msg('\t'.join(files))
Expand All @@ -6361,7 +6342,7 @@ def plugin(self, *arg):
warning('Please use "plugin %s reload" to force reload.)' % name)
return
info('Plugin %s is reloading.' % name)
m = reload_module('%s-plugin' % name)
m = reload_plugin('%s-plugin' % name)
if m is None or not hasattr(m, 'invoke') or not callable(getattr(m, 'invoke')):
error('Reload plugin failed. Please check the plugin file or restart gdb.')
return
Expand All @@ -6372,7 +6353,7 @@ def plugin(self, *arg):
if not os.path.exists(os.path.dirname(PEDAFILE) + "/plugins/%s-plugin.py" % name):
error('Plugin %s does not Exist!!' % name)
return
m = __import__('%s-plugin' % name)
m = import_plugin('%s-plugin' % name)
if not hasattr(m, 'invoke') or not callable(getattr(m, 'invoke')):
error('Not a valid plugin file!')
return
Expand Down
Empty file added plugins/__init__.py
Empty file.
14 changes: 3 additions & 11 deletions plugins/v8-plugin.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
from sys import modules
import os

try:
reload is None
except NameError:
try:
from importlib import reload
except ImportError:
try:
from imp import reload
except ImportError:
pass
from lib.six.moves import reload_module as reload
from lib.utils import import_plugin

invoke = None

Expand All @@ -36,7 +28,7 @@ def main():
except:
print('Choosing default 0')
choose = 0
module = __import__(plugins[choose])
module = import_plugin(plugins[choose])
invoke = module.invoke


Expand Down
6 changes: 3 additions & 3 deletions plugins/v8_plugin_44_0_2403_119.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@
"""

import struct
import config
import traceback
from utils import *
from v8_globals_44_0_2403_119 import *
from lib.utils import *
from lib import config


def has_smi_tag(v):
Expand Down Expand Up @@ -923,7 +923,7 @@ class Map: public HeapObject;
kMaximumBitField2FastSmiElementValue = (ElementsKind.FAST_SMI_ELEMENTS + 1) << ElementsKindBits_kShift - 1
kMaximumBitField2FastHoleyElementValue = (ElementsKind.FAST_HOLEY_ELEMENTS + 1) << ElementsKindBits_kShift - 1
kMaximumBitField2FastHoleySmiElementValue = (
ElementsKind.FAST_HOLEY_SMI_ELEMENTS + 1) << ElementsKindBits_kShift - 1
ElementsKind.FAST_HOLEY_SMI_ELEMENTS + 1) << ElementsKindBits_kShift - 1

# ------ kInstanceSizesOffset details ---------
@staticmethod
Expand Down
6 changes: 3 additions & 3 deletions plugins/v8_plugin_48_0_2564_8.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@
"""

import struct
import config
import traceback
from utils import *
from v8_globals_48_0_2564_8 import *
from lib import config
from lib.utils import *


def has_smi_tag(v):
Expand Down Expand Up @@ -917,7 +917,7 @@ class Map: public HeapObject;
kMaximumBitField2FastSmiElementValue = (ElementsKind.FAST_SMI_ELEMENTS + 1) << ElementsKindBits_kShift - 1
kMaximumBitField2FastHoleyElementValue = (ElementsKind.FAST_HOLEY_ELEMENTS + 1) << ElementsKindBits_kShift - 1
kMaximumBitField2FastHoleySmiElementValue = (
ElementsKind.FAST_HOLEY_SMI_ELEMENTS + 1) << ElementsKindBits_kShift - 1
ElementsKind.FAST_HOLEY_SMI_ELEMENTS + 1) << ElementsKindBits_kShift - 1

# ------ kInstanceSizesOffset details ---------
@staticmethod
Expand Down

0 comments on commit b75925a

Please sign in to comment.