|
@ -21,6 +21,7 @@ |
|
|
|
|
|
|
|
|
#include "Instruction.h" |
|
|
#include "Instruction.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <functional> |
|
|
#include <libdevcore/Common.h> |
|
|
#include <libdevcore/Common.h> |
|
|
#include <libdevcore/CommonIO.h> |
|
|
#include <libdevcore/CommonIO.h> |
|
|
#include <libdevcore/Log.h> |
|
|
#include <libdevcore/Log.h> |
|
@ -294,27 +295,42 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo = |
|
|
{ Instruction::SUICIDE, { "SUICIDE", 0, 1, 0, true, ZeroTier } } |
|
|
{ Instruction::SUICIDE, { "SUICIDE", 0, 1, 0, true, ZeroTier } } |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
string dev::eth::disassemble(bytes const& _mem) |
|
|
void dev::eth::eachInstruction( |
|
|
|
|
|
bytes const& _mem, |
|
|
|
|
|
function<void(Instruction,u256 const&)> const& _onInstruction |
|
|
|
|
|
) |
|
|
{ |
|
|
{ |
|
|
stringstream ret; |
|
|
|
|
|
unsigned numerics = 0; |
|
|
|
|
|
for (auto it = _mem.begin(); it != _mem.end(); ++it) |
|
|
for (auto it = _mem.begin(); it != _mem.end(); ++it) |
|
|
{ |
|
|
{ |
|
|
byte n = *it; |
|
|
Instruction instr = Instruction(*it); |
|
|
auto iit = c_instructionInfo.find((Instruction)n); |
|
|
size_t additional = 0; |
|
|
if (numerics || iit == c_instructionInfo.end() || (byte)iit->first != n) // not an instruction or expecting an argument...
|
|
|
if (isValidInstruction(instr)) |
|
|
|
|
|
additional = instructionInfo(instr).additional; |
|
|
|
|
|
u256 data; |
|
|
|
|
|
for (size_t i = 0; i < additional; ++i) |
|
|
{ |
|
|
{ |
|
|
if (numerics) |
|
|
data <<= 8; |
|
|
numerics--; |
|
|
if (it != _mem.end() && ++it != _mem.end()) |
|
|
ret << "0x" << hex << (int)n << " "; |
|
|
data |= *it; |
|
|
} |
|
|
} |
|
|
|
|
|
_onInstruction(instr, data); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string dev::eth::disassemble(bytes const& _mem) |
|
|
|
|
|
{ |
|
|
|
|
|
stringstream ret; |
|
|
|
|
|
eachInstruction(_mem, [&](Instruction _instr, u256 const& _data) { |
|
|
|
|
|
if (!isValidInstruction(_instr)) |
|
|
|
|
|
ret << "0x" << hex << int(_instr) << " "; |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
auto const& ii = iit->second; |
|
|
InstructionInfo info = instructionInfo(_instr); |
|
|
ret << ii.name << " "; |
|
|
ret << info.name << " "; |
|
|
numerics = ii.additional; |
|
|
if (info.additional) |
|
|
|
|
|
ret << "0x" << hex << _data << " "; |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
return ret.str(); |
|
|
return ret.str(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|