Display func name in CFG, add example

pull/88/head
Bernhard Mueller 7 years ago
parent c4984cce08
commit e2eee11218
  1. 13
      mythril/analysis/callgraph.py
  2. 33
      solidity_examples/calls.sol

@ -1,4 +1,5 @@
from z3 import Z3Exception, simplify
from laser.ethereum.svm import NodeFlags
import re
@ -127,15 +128,20 @@ def serialize(statespace, color_map):
for node_key in statespace.nodes:
code = statespace.nodes[node_key].get_cfg_dict()['code']
node = statespace.nodes[node_key]
code = node.get_cfg_dict()['code']
code = re.sub("([0-9a-f]{8})[0-9a-f]+", lambda m: m.group(1) + "(...)", code)
if NodeFlags.FUNC_ENTRY in node.flags:
code = re.sub("JUMPDEST", "%d %s" % (node.start_addr, node.function_name), code)
code_split = code.split("\\n")
truncated_code = code if (len(code_split) < 7) else "\\n".join(code_split[:6]) + "\\n(click to expand +)"
color = color_map[statespace.nodes[node_key].get_cfg_dict()['contract_name']]
color = color_map[node.get_cfg_dict()['contract_name']]
nodes.append("{id: '" + str(node_key) + "', color: " + color + ", size: 150, 'label': '" + truncated_code + "', 'fullLabel': '" + code + "', 'truncLabel': '" + truncated_code + "', 'isExpanded': false}")
@ -158,8 +164,7 @@ def serialize(statespace, color_map):
return "var nodes = [\n" + ",\n".join(nodes) + "\n];\nvar edges = [\n" + ",\n".join(edges) + "\n];"
def generate_graph(statespace, physics = False):
def generate_graph(statespace, physics=False):
i = 0

@ -0,0 +1,33 @@
pragma solidity ^0.4.17;
contract Callee {
function theFunction() payable {
}
}
contract Caller {
address public fixed_address;
address public stored_address;
function Caller(address addr) {
fixed_address = addr;
}
function thisisfine() public {
Callee(fixed_address).theFunction();
}
function calluseraddress(address addr) {
addr.call();
}
function callstoredaddress() {
stored_address.call();
}
function setstoredaddress(address addr) {
stored_address = addr;
}
}
Loading…
Cancel
Save