Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from Carbonara-Project/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
andreafioraldi authored Dec 18, 2017
2 parents d147e1b + 99fe9b6 commit 76e8bc7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 16 deletions.
69 changes: 54 additions & 15 deletions carbonara_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
import time
import requests
import progressbar
import json
import os
from guanciale import *

def main():
if len(sys.argv) < 2 or sys.argv[1] == "-help":
print "usage: python carbonara-cli.py [OPTIONS] <binary file>"
print
exit(0)

args = {}
binary = None
hasdb = False
Expand All @@ -32,9 +29,25 @@ def __exit__(self, type, value, traceback):

status.Status = ProgressBarStatus

r2plugin = False
if "R2PIPE_IN" in os.environ:
r2plugin = True

if (len(sys.argv) < 2 or sys.argv[1] == "-help") and not r2plugin:
print "usage: python carbonara-cli.py [OPTIONS] <binary file>"
print
exit(0)

i = 1
while i < len(sys.argv):
if sys.argv[i] == "-r2proj":
if sys.argv[i] == "-p" or sys.argv[i] == "--proc":
if i == len(sys.argv) -1:
print "error: arg '--proc': expected one argument"
print "ABORT"
exit(1)
args["proc"] = sys.argv[i+1]
i += 1
elif sys.argv[i] == "-r2proj":
if i == len(sys.argv) -1:
print "error: arg '-r2proj': expected one argument"
print "ABORT"
Expand Down Expand Up @@ -95,28 +108,54 @@ def __exit__(self, type, value, traceback):
args["r2"] = dbfile
i += 1

if binary == None:
if binary == None and not r2plugin:
print "error: binary file not provided"
print "ABORT"
exit(1)

start_time = time.time()

try:
bi = BinaryInfo(binary)
if r2plugin and binary == None:
bi = BinaryInfo(R2PLUGIN)
else:
bi = BinaryInfo(binary)
except IOError as err:
print "error: %s" % err
print "ABORT"
exit(1)
if "proc" not in args:
bi.addAdditionalInfo()
bi.addStrings()

if "idb" in args:
bi.fromIdaDB(args["idb"])
bi.grabProcedures("idapro", args["idb"])
elif "r2" in args:
bi.fromR2Project(args["r2"])
bi.grabProcedures("radare2", args["r2"])
else:
bi.generateInfo()
data = bi.toJson()

outfile = open(os.path.basename(sys.argv[1]) + ".analysis.json", "w")
bi.grabProcedures("radare2")

if "proc" in args:
pdata = bi.processSingle(args["proc"])
if pdata == None:
print "error: procedure not found"
exit(1)
try:
data = json.dumps(pdata, indent=2)
except IOError as err:
print "error: %s" % err
print "ABORT"
exit(1)
outfile = open(os.path.basename(bi.filename) + "_" + hex(pdata["procedure"]["offset"]) + ".procedure.json", "w")
else:
try:
data = json.dumps(bi.processAll(), indent=2)
except IOError as err:
print "error: %s" % err
print "ABORT"
exit(1)
outfile = open(os.path.basename(bi.filename) + ".analysis.json", "w")

outfile.write(data)
outfile.close()

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from setuptools import setup

VER = "1.0.4"
VER = "1.0.5"

setup(
name='carbonara_cli',
Expand Down

0 comments on commit 76e8bc7

Please sign in to comment.