#include "decompiler.h" #include #include #include #include "parser.h" #define SIMPLE(X) f << X << std::endl; pos++; break // [RZC 05/05/2021] To solve alignment problems on ARM architectures we have to first copy the 4 bytes to an aligned byte array, then cast it to float #define FVAR(X) memcpy(data, &code[pos+1], 4); f << X << " " << *((float*)data) << std::endl; pos += 5; break #define IVAR(X) memcpy(data, &code[pos+1], 4); f << X << " " << *((uint32_t*)data) << std::endl; pos += 5; break void decompiler_save(const uint8_t *code, const int size) { uint8_t data[4]; int pos = 0; float fval = 0; uint32_t ival = 0; std::ofstream f("decompiled.txt"); if (f.is_open()) { while (pos < size) { switch (code[pos]) { case OP_NOP: SIMPLE("NOP"); case OP_PUSH: FVAR("PUSH"); case OP_POP: SIMPLE("POP"); case OP_DUP: SIMPLE("DUP"); case OP_SWAP: SIMPLE("SWAP"); case OP_LD: IVAR("LD"); case OP_ST: IVAR("ST"); case OP_LDL: IVAR("LDL"); case OP_STL: IVAR("STL"); case OP_JMP: IVAR("JMP"); case OP_JNT: IVAR("JNT"); case OP_JTR: IVAR("JTR"); case OP_RET: SIMPLE("RET"); case OP_CALL: IVAR("CALL"); case OP_CALLEX: IVAR("CALLEX"); case OP_ADD: SIMPLE("ADD"); case OP_SUB: SIMPLE("SUB"); case OP_MUL: SIMPLE("MUL"); case OP_DIV: SIMPLE("DIV"); case OP_MOD: SIMPLE("MOD"); case OP_AND: SIMPLE("AND"); case OP_OR: SIMPLE("OR"); case OP_NOT: SIMPLE("NOT"); case OP_NEG: SIMPLE("NEG"); case OP_INC: SIMPLE("INC"); case OP_DEC: SIMPLE("DEC"); case OP_CONCAT: SIMPLE("CONCAT"); case OP_EQ: SIMPLE("EQ"); case OP_NEQ: SIMPLE("NEQ"); case OP_LT: SIMPLE("LT"); case OP_GT: SIMPLE("GT"); case OP_LEQ: SIMPLE("LEQ"); case OP_GEQ: SIMPLE("GEQ"); case OP_SLEEP: SIMPLE("SLEEP"); } } f.close(); } }