本文整理匯總了Python中r2pipe.open方法的典型用法代碼示例。如果您正苦於以下問題:Python r2pipe.open方法的具體用法?Python r2pipe.open怎麽用?Python r2pipe.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類r2pipe
的用法示例。
在下文中一共展示了r2pipe.open方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cache
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def cache(filename):
"""
A simple decorator to cache results to disk.
"""
def decorator(func):
"""Note: it is the function that is finally returned"""
def cached_function(*args):
"""Note: needed to access the returned value"""
try:
return pickle.load(open(filename, "r"))
except IOError:
value = func(*args)
pickle.dump(value, open(filename, "w"))
return value
return cached_function
return decorator
示例2: get_r2pipe
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def get_r2pipe(filename, offset, options=None):
"""
Get a r2pipe handle ready to analyse a flashair binary.
"""
# Set the miasm architecture
os.putenv("R2M2_ARCH", "mepl")
# Use the r2m2 architecture
default_options = ["-a", "r2m2"]
# Map the binary at a given location
default_options += ["-m", hex(offset)]
# Decrease r2 verbosity
default_options += ["-e", "bin.verbose=false"]
# Add user specified options
if isinstance(options, list):
default_options += options
return r2pipe.open(filename, default_options)
示例3: run_analysis
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def run_analysis(self):
"""Main analysis method.
:returns: Dictionary containing analysis results.
"""
log.info('Static Analysis started.')
# start radare2
self._r2 = r2pipe.open(self._file.path, ['-2'])
self._r2.cmd('aaa')
# binary info
self._r2_info()
# strings
self._load_strings()
self._r2.quit()
log.info('Static Analysis finished.')
return self._output
示例4: get_function_information
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def get_function_information(file_name):
func_list = []
r2_ins = r2pipe.open(file_name, flags=["-2"])
'''
Commands = ['aa', 'afr', '& aap', '& aac', '& aar', '& aaE',
'& aaf', '& aas', '& aae', '& aav', '&&', 'afva', 'afta']
for command in tqdm(Commands, desc="Analysis Running"):
r2_ins.cmd(command)
'''
r2_ins.cmd('aaa')
try:
func_list = r2_ins.cmdj('aflj')
except:
func_list = []
r2_ins.quit()
return func_list
示例5: carve
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def carve(file_path, offset, size, magic=None):
r2 = r2pipe.open(file_path, ['-z'])
if magic:
magic_bytes = hexlify(bytes(magic, 'ascii'))
print('[+] Checking for magic: %s - %x' % (magic, int(magic_bytes, 16)))
header = r2.cmd("p8 %x @ %s" % (len(magic), offset))
if bytes(header, 'ascii') != magic_bytes:
print("[+] No magic found, exiting...")
exit()
else:
print("[+] Magic found, carving...")
r2.cmd("s %s" % (offset))
r2.cmd('wtf %s.%s %s' % (file_path, offset, size))
print("[+] Carving to %s.%s" % (file_path, offset))
return '%s.%s' % (file_path, offset)
示例6: main
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def main():
parser = argparse.ArgumentParser(description='Carve binaries from MiniDumps.')
parser.add_argument('dmp', help='The MiniDump file to carve from')
parser.add_argument('offset', help='Offset to carve from')
parser.add_argument('size', help='Size of binary to carve')
parser.add_argument('-b', type=str, help='Magic bytes to check for, e.g. MZ')
parser.add_argument('-p', '--patch', action='store_true', help='Patch carved PE files')
args = parser.parse_args()
# FIXME: Won't redirect r2pipe, will have to 2>/dev/null for now!
f = open(os.devnull, 'w')
sys.stderr = f
output_file = carve(args.dmp, args.offset, args.size, args.b)
if args.patch:
patch(output_file)
示例7: __init__
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def __init__(self, name):
self.name = name
self.r2 = r2pipe.open()
bininfo = self.r2.cmdj("ij")["bin"]
self.arch = bininfo["arch"]
self.bits = bininfo["bits"]
self.regs = self.r2.cmdj("drlj")
self.switch_flagspace(self.name)
self.sections = self.get_sections()
imports = self.get_imports()
self.imports = {}
for imp in imports:
self.imports[imp["plt"]] = imp["name"]
exports = self.get_exports()
self.exports = {}
for exp in exports:
self.exports[exp["name"]] = exp["vaddr"]
示例8: __init__
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def __init__(self, filename, anal, debug=False, force_replace=False, write=False):
self.debug = debug
self.force = force_replace
flags = []
if write:
flags.append("-w")
print("[INFO] Opening file with r2")
self.r2 = r2pipe.open(filename, flags)
info = json.loads(self.r2.cmd("ij").replace("\\", "\\\\"))
if "bin" not in info.keys():
raise Exception("[ERROR] File type not supported")
if not info["bin"]["bits"] in constants.supported_bits or \
not info["bin"]["arch"] in constants.supported_archs:
raise Exception("[ERROR] Architecture not supported")
self.arch = info["bin"]["arch"]
self.bits = info["bin"]["bits"]
if anal:
print("[INFO] Analyzing functions with r2")
self.r2.cmd("aaa")
示例9: main
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def main():
import os
for i, filename in enumerate(os.listdir("occult_dist")):
if i % 8 != int(sys.argv[1]):
continue
solution_file = "%s.solution" % filename
if os.path.exists(solution_file):
continue
print(i, filename)
try:
sol = solve(filename)
except ValueError:
print("oops failed on %s" % filename)
continue
# data = sol.encode("base64")
with open(solution_file, "wb") as f:
f.write(sol)
#print("Send this:" + data)
#sock.send(data + "\n")
示例10: main
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def main():
print(solve("df8737d9d5aee3cee6320e7313414458fdfb10552a8e6c8ea45753102ba4509a"))
return
import os
for i, filename in enumerate(os.listdir("bc9cd8ff91a55ecee73caf85c3d55e45")):
if i % 8 != int(sys.argv[1]):
continue
solution_file = "%s.solution" % filename
if os.path.exists(solution_file):
continue
print(i, filename)
try:
sol = solve(filename)
if not sol:
continue
except ValueError:
print("oops failed on %s" % filename)
continue
# data = sol.encode("base64")
with open(solution_file, "wb") as f:
f.write(sol)
#print("Send this:" + data)
#sock.send(data + "\n")
示例11: get_base_addr
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def get_base_addr(file_name):
r2_ins = r2pipe.open(file_name, flags=["-2"])
return r2_ins.cmdj('ij')['bin']['baddr']
示例12: open_file
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def open_file(self, filename):
self.r2_obj = r2pipe.open(filename)
return self.r2_obj
示例13: __init__
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def __init__(self, path, cache_path):
self.exe_path = path
self.__r2p = r2pipe.open(path)
self.__cache_file = os.path.join(cache_path, os.path.basename(path)+'.cache')
self.__data = {}
self.__need_save_cache = False
self.__cached = self.__check_cache()
self.__analyzed = False
if not self.__cached:
self.analyze()
示例14: __init__
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def __init__(self):
# open empty, we'll open files later
self.r2 = r2pipe.open('--')
self.opcodeAddrs = []
示例15: open
# 需要導入模塊: import r2pipe [as 別名]
# 或者: from r2pipe import open [as 別名]
def open(self, path):
# not using 'oc' command because it resets r2's -q flag, don't know what
# else.
# close all
self.cmd('o--')
# then open the new file
# TODO: escaping?
self.cmd('o {}', path)
self.analyze()
self.opcodeAddrs = self._getOpcodeAddrs()
self.symbolFlags = SortedListWithKey(self.getFlags('symbols'),
key=lambda f: f['offset'])