Skip to content

Commit

Permalink
Avoid unnecessarily initializing disassembler
Browse files Browse the repository at this point in the history
  • Loading branch information
wheremyfoodat committed Apr 28, 2024
1 parent 5161ef8 commit f77c972
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/capstone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Common {
bool initialized = false;

public:
bool isInitialized() { return initialized; }
void init(cs_arch arch, cs_mode mode) { initialized = (cs_open(arch, mode, &handle) == CS_ERR_OK); }

CapstoneDisassembler() {}
Expand Down
6 changes: 5 additions & 1 deletion src/lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ static int getButtonThunk(lua_State* L) {
}

static int disassembleARMThunk(lua_State* L) {
static Common::CapstoneDisassembler disassembler(CS_ARCH_ARM, CS_MODE_ARM);
static Common::CapstoneDisassembler disassembler;
// We want the disassembler to only be fully initialized when this function is first used
if (!disassembler.isInitialized()) {
disassembler.init(CS_ARCH_ARM, CS_MODE_ARM);
}

const u32 pc = u32(lua_tonumber(L, 1));
const u32 instruction = u32(lua_tonumber(L, 2));
Expand Down

0 comments on commit f77c972

Please sign in to comment.