Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ name = "remill-template"
CMAKE_MODULE_PATH = "${CMAKE_SOURCE_DIR}/cmake"
GFLAGS_USE_TARGET_NAMESPACE = true

[subdir.helpers]

[find-package.LLVM-Wrapper]
[find-package.remill]

Expand Down
95 changes: 95 additions & 0 deletions helpers/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions helpers/aarch64/RemillHelpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
Original author: https://github.com/fvrmatteo
Reference: https://secret.club/2021/09/08/vmprotect-llvm-lifting-1.html
Remill helpers for tests:
https://github.com/lifting-bits/remill/blob/1fb647502b443cbd190e211b18f78979b857fd50/tests/AArch64/Run.cpp#L118-L663
*/

#include <remill/Arch/AArch64/Runtime/State.h>

// NOTE: We disable tail calls because it can cause the DSEPass to make false assumptions
#define HELPER extern "C" __attribute__((always_inline)) __attribute__((disable_tail_calls))

// Memory layout (0 length arrays treated as a simple pointer to unknown memory)

extern "C" uint8_t RAM[0];

// Implementation of the Remill memory access (read/write) intrinsics

HELPER uint8_t __remill_read_memory_8(Memory *m, addr_t a) {
uint8_t v = 0;
__builtin_memcpy(&v, &RAM[a], sizeof(v));
return v;
}

HELPER uint16_t __remill_read_memory_16(Memory *m, addr_t a) {
uint16_t v = 0;
__builtin_memcpy(&v, &RAM[a], sizeof(v));
return v;
}

HELPER uint32_t __remill_read_memory_32(Memory *m, addr_t a) {
uint32_t v = 0;
__builtin_memcpy(&v, &RAM[a], sizeof(v));
return v;
}

HELPER uint64_t __remill_read_memory_64(Memory *m, addr_t a) {
uint64_t v = 0;
__builtin_memcpy(&v, &RAM[a], sizeof(v));
return v;
}

HELPER Memory *__remill_write_memory_8(Memory *m, addr_t a, uint8_t v) {
__builtin_memcpy(&RAM[a], &v, sizeof(v));
return m;
}

HELPER Memory *__remill_write_memory_16(Memory *m, addr_t a, uint16_t v) {
__builtin_memcpy(&RAM[a], &v, sizeof(v));
return m;
}

HELPER Memory *__remill_write_memory_32(Memory *m, addr_t a, uint32_t v) {
__builtin_memcpy(&RAM[a], &v, sizeof(v));
return m;
}

HELPER Memory *__remill_write_memory_64(Memory *m, addr_t a, uint64_t v) {
__builtin_memcpy(&RAM[a], &v, sizeof(v));
return m;
}

// Implementation of the Remill flag and comparison computation intrinsics

HELPER bool __remill_flag_computation_zero(bool result, ...) {
return result;
}

HELPER bool __remill_flag_computation_sign(bool result, ...) {
return result;
}

HELPER bool __remill_flag_computation_overflow(bool result, ...) {
return result;
}

HELPER bool __remill_flag_computation_carry(bool result, ...) {
return result;
}

HELPER bool __remill_compare_sle(bool result) {
return result;
}

HELPER bool __remill_compare_slt(bool result) {
return result;
}

HELPER bool __remill_compare_sge(bool result) {
return result;
}

HELPER bool __remill_compare_sgt(bool result) {
return result;
}

HELPER bool __remill_compare_ule(bool result) {
return result;
}

HELPER bool __remill_compare_ult(bool result) {
return result;
}

HELPER bool __remill_compare_ugt(bool result) {
return result;
}

HELPER bool __remill_compare_uge(bool result) {
return result;
}

HELPER bool __remill_compare_eq(bool result) {
return result;
}

HELPER bool __remill_compare_neq(bool result) {
return result;
}

// Implementation of the remill hint calls

HELPER Memory *__remill_function_return(State *, addr_t, Memory *memory) {
return memory;
}
Empty file.
32 changes: 32 additions & 0 deletions helpers/build.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# To compile the helpers:
# cmake -P build.cmake

set(HELPER_CLANG_FLAGS "@HELPER_CLANG_FLAGS@")
set(HELPER_CLANG_EXECUTABLE "@HELPER_CLANG_EXECUTABLE@")
set(HELPER_DIR "@HELPER_DIR@")

message(STATUS "[@arch@] Directory: ${CMAKE_CURRENT_BINARY_DIR}")

function(compile_helper basename)
set(source "${HELPER_DIR}/${basename}.cpp")

if(NOT EXISTS "${source}")
message(STATUS "[@arch@] Not found: ${basename}.cpp (skipping)")
return()
endif()

message(STATUS "[@arch@] Compiling ${basename}.cpp")
execute_process(
COMMAND "${HELPER_CLANG_EXECUTABLE}" -c "${source}" ${HELPER_CLANG_FLAGS}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
COMMAND "${HELPER_CLANG_EXECUTABLE}" -S "${source}" ${HELPER_CLANG_FLAGS}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMAND_ERROR_IS_FATAL ANY
)
endfunction()

compile_helper(RemillHelpers)
compile_helper(RemillHotpatch)
Loading