diff --git a/eth/main.cpp b/eth/main.cpp index 75395ffc0..0831a1924 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -83,6 +83,7 @@ void interactiveHelp() << " balance Gives the current balance." << endl << " transact Executes a given transaction." << endl << " send Executes a given transaction with current secret." << endl + << " inspect Dumps a contract to /.evm." << endl << " exit Exits the application." << endl; } @@ -288,6 +289,62 @@ int main(int argc, char** argv) Address dest = h160(fromHex(rechex)); c.transact(us.secret(), dest, amount); } + else if (cmd == "inspect") + { + string rechex; + iss >> rechex; + + c.lock(); + auto hba = h160(fromHex(rechex)); + auto h = h160((byte const*)hba.data(), h160::ConstructFromPointer); + + stringstream s; + auto mem = c.state().contractMemory(h); + u256 next = 0; + unsigned numerics = 0; + bool unexpectedNumeric = false; + for (auto i: mem) + { + if (next < i.first) + { + unsigned j; + for (j = 0; j <= numerics && next + j < i.first; ++j) + s << (j < numerics || unexpectedNumeric ? " 0" : " STOP"); + unexpectedNumeric = false; + numerics -= min(numerics, j); + if (next + j < i.first) + s << "\n@" << showbase << hex << i.first << " "; + } + else if (!next) + { + s << "@" << showbase << hex << i.first << " "; + } + auto iit = c_instructionInfo.find((Instruction)(unsigned)i.second); + if (numerics || iit == c_instructionInfo.end() || (u256)(unsigned)iit->first != i.second) // not an instruction or expecting an argument... + { + if (numerics) + numerics--; + else + unexpectedNumeric = true; + s << " " << showbase << hex << i.second; + } + else + { + auto const& ii = iit->second; + s << " " << ii.name; + numerics = ii.additional; + } + next = i.first + 1; + } + + string outFile = getDataDir() + "/" + rechex + ".evm"; + ofstream ofs; + ofs.open(outFile, ofstream::binary); + ofs.write(s.str().c_str(), s.str().length()); + ofs.close(); + + c.unlock(); + } else if (cmd == "help") { interactiveHelp();