diff --git a/mythril/interfaces/cli.py b/mythril/interfaces/cli.py index 1c024947..579772ce 100644 --- a/mythril/interfaces/cli.py +++ b/mythril/interfaces/cli.py @@ -208,17 +208,17 @@ def main(): print(outputs[args.outform]) elif args.statespace_json: + if not mythril.contracts: exit_with_error(args.outform, "input files do not contain any valid contracts") - for nr, contract_statespace in enumerate(mythril.dump_statespaces(address=address, max_depth=args.max_depth)): + statespace = mythril.dump_statespace(mythril.contracts[0], address=address, max_depth=args.max_depth) - contract, statespace = contract_statespace - try: - with open("%s_%d_%s.json" % (args.statespace_json, nr, contract.name), "w") as f: - json.dump(statespace, f) - except Exception as e: - exit_with_error(args.outform, "Error saving json: " + str(e)) + try: + with open(args.statespace_json, "w") as f: + json.dump(statespace, f) + except Exception as e: + exit_with_error(args.outform, "Error saving json: " + str(e)) else: parser.print_help() diff --git a/mythril/mythril.py b/mythril/mythril.py index 444f34c1..16860488 100644 --- a/mythril/mythril.py +++ b/mythril/mythril.py @@ -296,16 +296,13 @@ class Mythril(object): self._update_signatures(self.sigs) return address, contracts - def dump_statespaces(self, contracts=None, address=None, max_depth=12): - statespaces = [] + def dump_statespace(self, contract, address=None, max_depth=12): - for contract in (contracts or self.contracts): - sym = SymExecWrapper(contract, address, - dynloader=DynLoader(self.eth) if self.dynld else None, - max_depth=max_depth) - statespaces.append((contract, get_serializable_statespace(sym))) + sym = SymExecWrapper(contract, address, + dynloader=DynLoader(self.eth) if self.dynld else None, + max_depth=max_depth) - return statespaces + return get_serializable_statespace(sym) def graph_html(self, contract, address, max_depth=12, enable_physics=False, phrackify=False): sym = SymExecWrapper(contract, address,