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
799 stars 95 forks source link

Break down OS-specific functions into separate files #146

Open rdbo opened 10 months ago

rdbo commented 10 months ago

Example:

src/
  win/
    handle.c
  bsd/
    ptrace.c
  linux/
    ptrace.c
  unix/
    ptrace.c

Unix will compile for both Linux and BSD. Linux will compile for Linux (android also, bc android uses Linux)

illegal-instruction-co commented 10 months ago

Since we are using iteration of files to build them, i think this is good aproach to order and manage them.

Other alternatives;

  1. File prefixes
    bsd_
    win_
    lin_
    un_
  2. definitions from CMakeLists.txt

CMakeLists.txt

if(WIN32)
    add_definitions(-DLM_BUILD_TYPE_WIN=1)
endif()

Code:

#ifdef LM_BUILD_TYPE_WIN
// windows code
#endif 
rdbo commented 10 months ago

@illegal-instruction-co

For (2); Currently those definitions are in the C header files, but they can be passed to CMake also IIRC: Right now it looks like this:

#if LM_OS == LM_OS_WIN
// ...
#endif

But there is an option that forces the operating system (and there are options also for architecture, and everything, really):

#if defined(LM_FORCE_OS_WIN)
#   define LM_OS LM_OS_WIN
#elif defined(LM_FORCE_OS_LINUX)
#   define LM_OS LM_OS_LINUX
#elif defined(LM_FORCE_OS_BSD)
#   define LM_OS LM_OS_BSD
#elif defined(LM_FORCE_OS_ANDROID)
#   define LM_OS LM_OS_ANDROID
#endif