Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
301 changes: 266 additions & 35 deletions README.md

Large diffs are not rendered by default.

Binary file added docs/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/metame-process.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screen_aft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screen_bef.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions metame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def main():
parser.print_help()
sys.exit(1)

import os
if not os.path.exists(args.input):
print("[ERROR] Input file does not exist: %s" % args.input)
sys.exit(1)

r = r2parser.R2Parser(args.input, True, debug=args.debug, force_replace=args.force)
patches = r.iterate_fcn()
r.close()
Expand Down
26 changes: 14 additions & 12 deletions metame/r2parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import metame.x86handler as x86handler
import metame.x64handler as x64handler
import metame.constants as constants

import r2pipe
Expand All @@ -18,20 +18,22 @@ def __init__(self, filename, anal, debug=False, force_replace=False, write=False
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"]
bin_info = info.get("bin", {})
if not bin_info:
raise Exception("[ERROR] File type not supported or binary metadata missing")
self.arch = bin_info.get("arch")
self.bits = bin_info.get("bits")
if not self.arch or not self.bits:
raise Exception("[ERROR] Architecture or bits details missing in file metadata")
if self.bits not in constants.supported_bits or self.arch not in constants.supported_archs:
raise Exception("[ERROR] Architecture (%s) or bits (%s) not supported" % (self.arch, self.bits))
if anal:
print("[INFO] Analyzing functions with r2")
self.r2.cmd("aaa")

def iterate_fcn(self):
if self.arch == "x86":
arch = x86handler.X86Handler(self.bits, self.debug, self.force)
arch = x64handler.X64Handler(self.bits, self.debug, self.force)
replacements = []
print("[INFO] Loading functions information")
fcns = json.loads(self.r2.cmd("aflj"))
Expand All @@ -40,9 +42,9 @@ def iterate_fcn(self):
if f["type"] == "fcn":
try:
fcn_ctx = json.loads(self.r2.cmd("pdfj @%s" % f["name"]))
except:
print("[ERROR] Error disassembling function %s" % f["name"])
replacements += arch.replace_fcn_opcodes(fcn_ctx)
replacements += arch.replace_fcn_opcodes(fcn_ctx)
except Exception as e:
print("[ERROR] Error disassembling function %s: %s" % (f["name"], e))
return replacements

def patch_binary(self, patches):
Expand Down
Loading