Skip to content

Commit

Permalink
Merge pull request #209 from rdbo/v5-rewrite
Browse files Browse the repository at this point in the history
V5 rewrite
  • Loading branch information
rdbo authored Apr 7, 2024
2 parents 70745c8 + aa8ca00 commit ab7d88a
Show file tree
Hide file tree
Showing 104 changed files with 5,773 additions and 6,295 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-linux-i686.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:

- name: Install Dependencies
run: |
apt-get -y install cmake make gcc-multilib g++-multilib python3
sudo apt-get -y install cmake make gcc-multilib g++-multilib python3
- name: Configure and Build
run: |
mkdir build
cmake -S . -B build -DCMAKE_SYSTEM_PROCESSOR="i686" -DCMAKE_C_FLAGS="-m32" -DCMAKE_CXX_FLAGS="-m32" -DCMAKE_BUILD_TYPE=Debug -DLIBMEM_BUILD_TESTS=ON -DLIBMEM_BUILD_STATIC=ON
cmake -S . -B build -DLIBMEM_ARCH="i686" -DCMAKE_C_FLAGS="-m32 -fpermissive" -DCMAKE_CXX_FLAGS="-m32 -fpermissive" -DCMAKE_BUILD_TYPE=Debug -DLIBMEM_BUILD_TESTS=ON -DLIBMEM_BUILD_STATIC=ON
cd build
make -j 4
cd ..
Expand All @@ -28,4 +28,4 @@ jobs:
echo "Starting target..."
./build/tests/target &
echo "Starting unit tests..."
./build/tests/unit
sudo ./build/tests/unit
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
path = external/keystone
url = https://github.com/keystone-engine/keystone
branch = master
[submodule "LIEF"]
path = external/LIEF
url = https://github.com/lief-project/LIEF
branch = master
[submodule "injector"]
path = external/injector
url = https://github.com/rdbo/injector
Expand Down
46 changes: 19 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@ option(LIBMEM_BUILD_STATIC
OFF
)

set(LIBMEM_ARCH ${CMAKE_SYSTEM_PROCESSOR} CACHE STRING "Force a specific architecture")

message(STATUS
"[*] Build tests: ${LIBMEM_BUILD_TESTS}"
"[*] Architecture: ${LIBMEM_ARCH}"
)

message(STATUS
"[*] Deep tests: ${LIBMEM_DEEP_TESTS}"
"[*] Build tests: ${LIBMEM_BUILD_TESTS}"
)

message(STATUS
"[*] Build static library: ${LIBMEM_BUILD_STATIC}"
"[*] Deep tests: ${LIBMEM_DEEP_TESTS}"
)

message(STATUS
"[*] Build for 32 bits: ${LIBMEM_BUILD_32}"
"[*] Build static library: ${LIBMEM_BUILD_STATIC}"
)

message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
Expand All @@ -55,9 +57,6 @@ set(CAPSTONE_IMPORT_DIR "${PROJECT_BINARY_DIR}/external/capstone-engine-prefix/s
set(KEYSTONE_DIR "${EXTERNAL_DEPENDENCIES_DIR}/keystone")
set(KEYSTONE_INC "${KEYSTONE_DIR}/include")
set(KEYSTONE_IMPORT_DIR "${PROJECT_BINARY_DIR}/external/keystone-engine-prefix/src/keystone-engine-build/llvm/lib")
set(LIEF_DIR "${EXTERNAL_DEPENDENCIES_DIR}/LIEF")
set(LIEF_IMPORT_DIR "${PROJECT_BINARY_DIR}/external/lief-project-prefix/src/lief-project-build")
set(LIEF_INC "${LIEF_DIR}/include" "${LIEF_IMPORT_DIR}/include")
set(LLVM_DIR "${EXTERNAL_DEPENDENCIES_DIR}/llvm")
set(LLVM_INC "${LLVM_DIR}/include")
set(INJECTOR_DIR "${EXTERNAL_DEPENDENCIES_DIR}/injector")
Expand All @@ -68,33 +67,27 @@ add_library(capstone STATIC IMPORTED)
set_target_properties(capstone PROPERTIES IMPORTED_LOCATION ${CAPSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}capstone${CMAKE_STATIC_LIBRARY_SUFFIX})
add_library(keystone STATIC IMPORTED)
set_target_properties(keystone PROPERTIES IMPORTED_LOCATION ${KEYSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}keystone${CMAKE_STATIC_LIBRARY_SUFFIX})
add_library(LIEF STATIC IMPORTED)
set_target_properties(LIEF PROPERTIES IMPORTED_LOCATION ${LIEF_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}LIEF${CMAKE_STATIC_LIBRARY_SUFFIX})
# End of external dependencies

set(LIBMEM_DIR "${PROJECT_SOURCE_DIR}")
set(LIBMEM_INC "${LIBMEM_DIR}/include")
file(GLOB LIBMEM_SRC "${LIBMEM_DIR}/src/*.c" "${LIBMEM_DIR}/src/*.cpp")
set(INTERNAL_DIR "${LIBMEM_DIR}/internal")

if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
file(GLOB_RECURSE LIBMEM_INTERNAL_SRC "${LIBMEM_DIR}/src/internal/win/*.c")
else()
file(GLOB_RECURSE LIBMEM_INTERNAL_SRC "${LIBMEM_DIR}/src/internal/unix/*.c")
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
file(GLOB_RECURSE LIBMEM_OS_SRC "${LIBMEM_DIR}/src/internal/linux/*.c")
set(LIBMEM_INTERNAL_SRC ${LIBMEM_INTERNAL_SRC} ${LIBMEM_OS_SRC})
elseif(${CMAKE_SYSTEM_NAME STREQUAL FreeBSD})
file(GLOB_RECURSE LIBMEM_OS_SRC "${LIBMEM_DIR}/src/internal/bsd/*.c")
set(LIBMEM_INTERNAL_SRC ${LIBMEM_INTERNAL_SRC} ${LIBMEM_OS_SRC})
file(GLOB_RECURSE LIBMEM_SRC "${LIBMEM_DIR}/src/win/*.c" "${LIBMEM_DIR}/src/common/*.c" "${INTERNAL_DIR}/winutils/*.c" "${INTERNAL_DIR}/demangler/*.cpp")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
if(${LIBMEM_ARCH} STREQUAL x86_64)
set(LIBMEM_ARCH_SRC "${LIBMEM_DIR}/src/common/arch/x86.c" "${LIBMEM_DIR}/src/linux/ptrace/x64/*.c")
elseif(${LIBMEM_ARCH} STREQUAL i686 OR ${LIBMEM_ARCH} STREQUAL i386)
set(LIBMEM_ARCH_SRC "${LIBMEM_DIR}/src/common/arch/x86.c" "${LIBMEM_DIR}/src/linux/ptrace/x86/*.c")
endif()
file(GLOB LIBMEM_SRC ${LIBMEM_ARCH_SRC} "${LIBMEM_DIR}/src/linux/*.c" "${LIBMEM_DIR}/src/linux/ptrace/*.c" "${LIBMEM_DIR}/src/common/*.c" "${INTERNAL_DIR}/posixutils/*.c" "${INTERNAL_DIR}/elfutils/*.c" "${INTERNAL_DIR}/demangler/*.cpp")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
file(GLOB_RECURSE LIBMEM_SRC "${LIBMEM_DIR}/src/freebsd/*.c" "${LIBMEM_DIR}/src/common/*.c" "${INTERNAL_DIR}/posixutils/*.c" "${INTERNAL_DIR}/elfutils/*.c" "${INTERNAL_DIR}/demangler/*.cpp")
endif()
set(LIBMEM_SRC
${LIBMEM_SRC}
${LIBMEM_INTERNAL_SRC}
)
set(LIBMEM_DEPS
capstone
keystone
LIEF
llvm
)

Expand All @@ -117,13 +110,12 @@ if (LIBMEM_BUILD_STATIC)
else()
add_library(libmem SHARED ${LIBMEM_SRC})
endif()
target_include_directories(libmem PRIVATE "${LIBMEM_DIR}/src")
target_include_directories(libmem PRIVATE "${LIBMEM_DIR}/src" "${INTERNAL_DIR}")

include_directories(${PROJECT_SOURCE_DIR}
${LIBMEM_INC}
${CAPSTONE_INC}
${KEYSTONE_INC}
${LIEF_INC}
${LLVM_INC}
${INJECTOR_INC}
)
Expand All @@ -138,7 +130,6 @@ target_compile_definitions(libmem PUBLIC LM_EXPORT)
add_dependencies(libmem
capstone-engine
keystone-engine
lief-project
)

if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
Expand All @@ -148,6 +139,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN
psapi
ntdll
)
target_compile_definitions(libmem PUBLIC alloca=_alloca)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux OR ${CMAKE_SYSTEM_NAME} STREQUAL Android)
set(LIBMEM_DEPS
${LIBMEM_DEPS}
Expand Down
31 changes: 0 additions & 31 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,6 @@ ExternalProject_Add(keystone-engine SOURCE_DIR ${KEYSTONE_DIR} INSTALL_COMMAND "
add_library(keystone STATIC IMPORTED)
set_target_properties(keystone PROPERTIES IMPORTED_LOCATION ${KEYSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}keystone${CMAKE_STATIC_LIBRARY_SUFFIX})

set(LIEF_CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}
-DLIEF_USE_CCACHE=OFF
-DLIEF_ENABLE_JSON=OFF
-DLIEF_FROZEN_ENABLED=OFF
-DLIEF_MACHO=OFF
-DLIEF_OAT=OFF
-DLIEF_DEX=OFF
-DLIEF_VDEX=OFF
-DLIEF_ART=OFF
-DLIEF_EXTERNAL_LEAF=OFF
-DLIEF_EXTERNAL_SPAN_DIR=OFF
-DLIEF_FUZZING=OFF
-DLIEF_PROFILING=OFF
-DLIEF_COVERAGE=OFF
-DLIEF_EXAMPLES=OFF
-DLIEF_TESTS=OFF
-DLIEF_DOC=OFF
)
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
set(LIEF_CMAKE_ARGS ${LIEF_CMAKE_ARGS} -DLIEF_ELF=OFF)
else()
set(LIEF_CMAKE_ARGS ${LIEF_CMAKE_ARGS} -DLIEF_PE=OFF)
endif()
ExternalProject_Add(lief-project SOURCE_DIR ${LIEF_DIR} INSTALL_COMMAND "" CMAKE_ARGS ${LIEF_CMAKE_ARGS})
add_library(LIEF STATIC IMPORTED)
set_target_properties(LIEF PROPERTIES IMPORTED_LOCATION ${LIEF_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}LIEF${CMAKE_STATIC_LIBRARY_SUFFIX})

add_subdirectory("${LLVM_DIR}")

if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
Expand Down
1 change: 0 additions & 1 deletion external/LIEF
Submodule LIEF deleted from 6ddc7e
Loading

0 comments on commit ab7d88a

Please sign in to comment.