Skip to content

Commit

Permalink
add --output parameter to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
blattm committed May 11, 2022
1 parent 2510874 commit 970f280
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 11 additions & 7 deletions roamer/RoAMer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ def communicate_with_unpacker(self):
connection.close()
sock.close()

def run_folder(self, target_path):
def run_folder(self, target_path, output_folder = None):
for filename in os.listdir(target_path):
sample = os.path.join(target_path, filename)
if os.path.isfile(sample):
self.run_file(sample)
self.run_file(sample, output_folder=output_folder)

def run_file(self, target_path):
def run_file(self, target_path, output_folder = None):
LOG.info("Unpacking %s", target_path)
unpacker_files = self.gather_files_for_unpacker(target_path)
self.prepare_vm()
Expand All @@ -134,18 +134,22 @@ def run_file(self, target_path):
LOG.error(json.loads(returned_raw_data))
else:
LOG.info("persisting dumps ...")
persist_data(target_path, json.loads(returned_raw_data), self.ident)
if output_folder is None:
output_path = target_path
else:
output_path = os.path.join(output_folder, os.path.basename(target_path))
persist_data(output_path, json.loads(returned_raw_data), self.ident)
else:
LOG.info("Nothing returned by unpacker")
self.vm_controller.stop_vm(self.vm_name)
time.sleep(5)

def run(self, target_path):
def run(self, target_path, output_folder = None):
try:
if os.path.isdir(target_path):
self.run_folder(target_path)
self.run_folder(target_path, output_folder=output_folder)
elif os.path.isfile(target_path):
self.run_file(target_path)
self.run_file(target_path, output_folder=output_folder)
else:
LOG.error("Target was neither file nor directory, aborting.")
except Exception:
Expand Down
3 changes: 2 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
parser.add_argument('--snapshot', action='store', help='This can be used to force a snapshot past the config-file', default="")
parser.add_argument('--config', action='store', help="Which config shall be used?", default="config")
parser.add_argument('--ident', action="store", help="Configure an identifier for the output.", default="")
parser.add_argument('--output', action="store", help="Specify a custom output folder for the dumps", default=None)

args = parser.parse_args()
roamer = RoAMer(importlib.import_module(args.config), args.headless, args.vm, args.snapshot, args.ident)
roamer.run(args.Samples)
roamer.run(args.Samples, output_folder=args.output)

0 comments on commit 970f280

Please sign in to comment.