#include "bridge.hh" //#include "../target/cxxbridge/sleigh-sys/src/lib.rs.h" #include "sleigh-sys/src/lib.rs.h" #include unique_ptr newDecompiler(RustLoadImage *loadImage, unique_ptr spec) { auto l = unique_ptr(new RustLoadImageProxy(loadImage)); return make_unique(move(l), move(spec)); } unique_ptr
newAddress() { return make_unique
(); } uint32_t getAddrSpaceType(const AddrSpace &space) { return (uint32_t)space.getType(); } unique_ptr
getVarnodeDataAddress(const VarnodeData &data) { return make_unique
(data.getAddr()); } unique_ptr newContext() { return unique_ptr(new ContextInternal()); } unique_ptr newDocumentStorage(const std::string &s) { static std::mutex lock; std::lock_guard guard(lock); auto doc = make_unique(); std::stringstream ss; ss << s; auto root = doc->parseDocument(ss)->getRoot(); doc->registerTag(root); return doc; } void RustLoadImageProxy::loadFill(uint1 *ptr, int4 size, const Address &address) { return inner->load_fill(ptr, size, address); } void RustLoadImageProxy::adjustVma(long adjust) { return inner->adjust_vma(adjust); } void RustPCodeEmitProxy::dump(const Address &addr, OpCode opc, VarnodeData *outvar, VarnodeData *vars, int4 isize) { inner->dump(addr, (uint32_t)opc, outvar, vars, isize); } int32_t Decompiler::translate(RustPCodeEmit *emit, uint64_t addr) const { auto address = Address(this->getDefaultCodeSpace(), addr); auto p = RustPCodeEmitProxy(emit); int32_t n = 0; try { n = this->oneInstruction(p, address); } catch (...) { // TODO } return n; } int32_t Decompiler::disassemble(RustAssemblyEmit *emit, uint64_t addr) const { auto address = Address(this->getDefaultCodeSpace(), addr); auto p = RustAssemblyEmitProxy(emit); int32_t n = 0; try { n = this->printAssembly(p, address); } catch (...) { // TODO } return n; } uint32_t getVarnodeSize(const VarnodeData &data) { return data.size; } void RustAssemblyEmitProxy::dump(const Address &addr, const string &mnem, const string &body) { this->inner->dump(addr, mnem, body); }