bytes unpadLeft(bytes _b) { unsigned int i = 0; if (_b.size() == 0) return _b; while (i < _b.size() && _b[i] == byte(0)) i++; if (i != 0) _b.erase(_b.begin(), _b.begin() + i); return _b; }
string eth::disassemble(bytes const& _mem) { stringstream ret; uint numerics = 0; for (auto it = _mem.begin(); it != _mem.end(); ++it) { byte n = *it; auto iit = c_instructionInfo.find((Instruction)n); if (numerics || iit == c_instructionInfo.end() || (byte)iit->first != n) // not an instruction or expecting an argument... { if (numerics) numerics--; ret << "0x" << hex << (int)n << " "; } else { auto const& ii = iit->second; ret << ii.name << " "; numerics = ii.additional; } } return ret.str(); }
bytes padded(bytes _b, unsigned _l) { while (_b.size() < _l) _b.insert(_b.begin(), 0); return asBytes(asString(_b).substr(_b.size() - max(_l, _l))); }
bool operator==(const bytes& rhs) const { return std::equal(begin(), end(), rhs.begin()); }
bytes(const bytes& o) { std::copy(o.begin(), o.end(), data); }