Initial commit
This commit is contained in:
parent
10c5b7816c
commit
d0036e0a44
99
script.py
Executable file
99
script.py
Executable file
@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import binaryninja
|
||||
import argparse
|
||||
import angr
|
||||
import os
|
||||
import json
|
||||
|
||||
from cle.backends import Region, Regions
|
||||
from IPython import embed
|
||||
from typing import List, Dict
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("file", help="File to analyze")
|
||||
parser.add_argument("-d", "--debug", help="Enable debug mode", action = "store_true", default = False)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
class WrappedBin:
|
||||
def __init__(self, filename: str):
|
||||
self.angr: angr.Project = angr.Project(filename)
|
||||
|
||||
"""
|
||||
Interface
|
||||
"""
|
||||
class Analysis:
|
||||
def __init__(self, target: WrappedBin):
|
||||
self.target = target
|
||||
|
||||
def name(self) -> str:
|
||||
pass
|
||||
def execute(self):
|
||||
pass
|
||||
|
||||
def __get_relevant_vars__(self) -> Dict:
|
||||
# get all attributes of the instance
|
||||
instance_vars = vars(self)
|
||||
# filter out attributes that belong to the parent class
|
||||
return {k: str(v) for k, v in instance_vars.items() if not k.startswith("__") and k != "target"}
|
||||
|
||||
def __json_dumps__(self) -> str:
|
||||
return json.dumps(self.__get_relevant_vars__())
|
||||
|
||||
class AnalysisManager:
|
||||
def __init__(self, target: WrappedBin, tasks: List[Analysis] = []):
|
||||
self.target: WrappedBin = target
|
||||
self.tasks: List[Analysis] = []
|
||||
|
||||
for t in tasks:
|
||||
self.add_task(t)
|
||||
|
||||
def add_task(self, task: Analysis):
|
||||
self.tasks.append(task(self.target))
|
||||
|
||||
def run_tasks(self):
|
||||
n_tasks = len(self.tasks)
|
||||
|
||||
print("Starting analyses...")
|
||||
|
||||
for n, t in enumerate(self.tasks):
|
||||
print(f"\t[{n + 1}/{n_tasks}] Running {t.name()}")
|
||||
|
||||
ret = t.execute()
|
||||
|
||||
if ret:
|
||||
print(ret)
|
||||
|
||||
print("Done")
|
||||
|
||||
|
||||
class LoaderFacts(Analysis):
|
||||
def name(self) -> str:
|
||||
return "Loader Facts"
|
||||
|
||||
def execute(self):
|
||||
self.sections: Regions = self.target.angr.loader.all_objects[0].sections
|
||||
self.aslr: bool = self.target.angr.loader.aslr
|
||||
|
||||
return self.__json_dumps__()
|
||||
|
||||
|
||||
def main():
|
||||
if not os.path.exists(args.file):
|
||||
print("File does not exist")
|
||||
exit(1)
|
||||
|
||||
target = WrappedBin(args.file)
|
||||
tasks = [ LoaderFacts ]
|
||||
am = AnalysisManager(target, tasks)
|
||||
|
||||
am.run_tasks()
|
||||
|
||||
if args.debug:
|
||||
embed()
|
||||
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user