rdbo / libmem

Advanced Game Hacking Library for C, Modern C++, Rust and Python (Windows/Linux/FreeBSD) (Process/Memory Hacking) (Hooking/Detouring) (Cross Platform) (x86/x64/ARM/ARM64) (DLL/SO Injection) (Internal/External) (Assembler/Disassembler)
GNU Affero General Public License v3.0
738 stars 90 forks source link

Figure out a way to allow more assembler/disassembler modes #225

Closed rdbo closed 1 month ago

rdbo commented 1 month ago

Some architectures have lots of modes, e.g ARM. ARM has thumb mode, v8 mode, etc What I'm thinking is to interpret those as different architectures:

enum {
        LM_ARCH_ARM,
        LM_ARCH_ARMV8,
        LM_ARCH_ARM_THUMB,
        LM_ARCH_X86_16,
        LM_ARCH_X86,
        LM_ARCH_X64,
        // ...
}

In addition to this, I could also deprecate the bits parameter from the LM_AssembleEx and LM_DisassembleEx functions

rdbo commented 1 month ago

Another point in favor of this is that some architectures don't have multiple bit size support. For example, the ARM architecture can only be 32 bits. It is never 64 bits. 64 bit ARM is a completely different arch, ARM64/AARCH64

rdbo commented 1 month ago

One difficulty found because of this transition (branch: arch-breaking) is that you can no longer assemble/disassemble for remote processes using LM_GetArchitecture() as the architecture, and process.bits as the bits. To counter that, I added a field arch to lm_process_t which contains the detailed architecture of that process.

Another problem that arrived from that is: how should libmem guess its architecture? But now I realize, libmem has always assumed the architectures. For example, if you are running a x86/x64 machine, and the process is 32 bits, libmem has always been assuming that the process is x86_32. Which means this behavior has always been there, just not explicitly. Now it has become explicit:

static inline lm_arch_t
get_architecture_from_bits(lm_size_t bits)
{
        // ...
}

This function has been added to guess the architecture of a process based on its bits.

Now you can use process.arch to assemble/disassemble for remote processes without doing the guessing yourself and leaving that up to libmem.

rdbo commented 1 month ago

arch-breaking branch was merged, let's hope this doesn't come back to haunt me in the future.