git subrepo clone git@github.com:compihu/platform-test-f4-ll.git platforms/platform-test-f4-ll
subrepo: subdir: "platforms/platform-test-f4-ll" merged: "bc41134" upstream: origin: "git@github.com:compihu/platform-test-f4-ll.git" branch: "master" commit: "bc41134" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "87ee373"
This commit is contained in:
parent
46ce55c6a0
commit
95af4ce0d8
460 changed files with 84105 additions and 0 deletions
3
platforms/platform-test-f4-ll/subhook/tests/.gitignore
vendored
Normal file
3
platforms/platform-test-f4-ll/subhook/tests/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
*.o
|
||||
foo
|
||||
a.out
|
103
platforms/platform-test-f4-ll/subhook/tests/CMakeLists.txt
Normal file
103
platforms/platform-test-f4-ll/subhook/tests/CMakeLists.txt
Normal file
|
@ -0,0 +1,103 @@
|
|||
find_package(Yasm REQUIRED)
|
||||
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 4 OR SUBHOOK_FORCE_32BIT)
|
||||
set(BITS 32)
|
||||
else()
|
||||
set(BITS 64)
|
||||
endif()
|
||||
|
||||
set(asm_file foo_${BITS}.asm)
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT SUBHOOK_FORCE_32BIT)
|
||||
if(WIN32)
|
||||
set(asm_file foo_64_win.asm)
|
||||
elseif(UNIX)
|
||||
set(asm_file foo_64_unix.asm)
|
||||
set(asm_obj_file ${asm_file}.o)
|
||||
endif()
|
||||
endif()
|
||||
if(NOT asm_obj_file)
|
||||
set(asm_obj_file ${asm_file}.obj)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
set(asm_format "win${BITS}")
|
||||
elseif(APPLE)
|
||||
set(asm_format "macho${BITS}")
|
||||
else()
|
||||
set(asm_format "elf${BITS}")
|
||||
endif()
|
||||
|
||||
set(options "-f" "${asm_format}")
|
||||
if(APPLE OR (WIN32 AND (CMAKE_SIZEOF_VOID_P EQUAL 4 OR SUBHOOK_FORCE_32BIT)))
|
||||
list(APPEND options "--prefix=_")
|
||||
endif()
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
list(APPEND options "-DUSE_PLT")
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${asm_obj_file}"
|
||||
COMMAND "${YASM_EXECUTABLE}" ${options} "-o"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${asm_obj_file}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${asm_file}"
|
||||
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${asm_file}"
|
||||
)
|
||||
|
||||
add_executable(subhook_test_exe
|
||||
test.c
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${asm_obj_file}"
|
||||
)
|
||||
set_target_properties(subhook_test_exe PROPERTIES OUTPUT_NAME test)
|
||||
|
||||
enable_language(CXX)
|
||||
add_executable(subhook_cxx_test_exe
|
||||
test.cpp
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${asm_obj_file}"
|
||||
)
|
||||
set_target_properties(subhook_cxx_test_exe PROPERTIES OUTPUT_NAME test++)
|
||||
|
||||
foreach(target subhook_test_exe subhook_cxx_test_exe)
|
||||
if(SUBHOOK_FORCE_32BIT)
|
||||
if(APPLE)
|
||||
set_target_properties(${target} PROPERTIES OSX_ARCHITECTURES i386)
|
||||
endif()
|
||||
if(UNIX)
|
||||
set_property(TARGET ${target} APPEND_STRING PROPERTY
|
||||
COMPILE_FLAGS " -m32")
|
||||
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -m32")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_link_libraries(${target} subhook)
|
||||
|
||||
if(MSVC)
|
||||
set_property(TARGET ${target}
|
||||
APPEND_STRING PROPERTY LINK_FLAGS " /INCREMENTAL:NO")
|
||||
endif()
|
||||
|
||||
if(APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT SUBHOOK_FORCE_32BIT)
|
||||
set_property(TARGET ${target} APPEND_STRING PROPERTY
|
||||
LINK_FLAGS " -Wl,-no_pie")
|
||||
endif()
|
||||
|
||||
add_test(NAME ${target}_test COMMAND $<TARGET_FILE:${target}>)
|
||||
|
||||
set(expected_output
|
||||
"Testing initial install
|
||||
foo_hooked\\(\\) called
|
||||
foo\\(\\) called
|
||||
Testing re-install
|
||||
foo_hooked\\(\\) called
|
||||
foo\\(\\) called
|
||||
Testing trampoline
|
||||
foo_hooked_tr\\(\\) called
|
||||
foo\\(\\) called
|
||||
")
|
||||
set_tests_properties(${target}_test PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "${expected_output}")
|
||||
|
||||
if(WIN32 AND NOT SUBHOOK_STATIC)
|
||||
set_tests_properties(${target}_test PROPERTIES
|
||||
ENVIRONMENT PATH=$<TARGET_FILE_DIR:subhook>)
|
||||
endif()
|
||||
endforeach()
|
5
platforms/platform-test-f4-ll/subhook/tests/foo.cpp
Normal file
5
platforms/platform-test-f4-ll/subhook/tests/foo.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include <stdio.h>
|
||||
|
||||
extern "C" void foo() {
|
||||
puts("foo() called");
|
||||
}
|
31
platforms/platform-test-f4-ll/subhook/tests/foo_32.asm
Normal file
31
platforms/platform-test-f4-ll/subhook/tests/foo_32.asm
Normal file
|
@ -0,0 +1,31 @@
|
|||
extern puts
|
||||
global foo
|
||||
|
||||
section .rodata
|
||||
|
||||
message:
|
||||
db 'foo() called', 0
|
||||
|
||||
section .text
|
||||
|
||||
;; Long nop macros for nasm/yasm borrowed from nasm-utils:
|
||||
;; https://github.com/travisdowns/nasm-utils
|
||||
%define nop1 nop ; just a nop, included for completeness
|
||||
%define nop2 db 0x66, 0x90 ; 66 NOP
|
||||
%define nop3 db 0x0F, 0x1F, 0x00 ; NOP DWORD ptr [EAX]
|
||||
%define nop4 db 0x0F, 0x1F, 0x40, 0x00 ; NOP DWORD ptr [EAX + 00H]
|
||||
%define nop5 db 0x0F, 0x1F, 0x44, 0x00, 0x00 ; NOP DWORD ptr [EAX + EAX*1 + 00H]
|
||||
%define nop6 db 0x66, 0x0F, 0x1F, 0x44, 0x00, 0x00 ; 66 NOP DWORD ptr [EAX + EAX*1 + 00H]
|
||||
%define nop7 db 0x0F, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00 ; NOP DWORD ptr [EAX + 00000000H]
|
||||
%define nop8 db 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 ; NOP DWORD ptr [EAX + EAX*1 + 00000000H]
|
||||
%define nop9 db 0x66, 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 ; 66 NOP DWORD ptr [EAX + EAX*1 + 00000000H]
|
||||
|
||||
foo:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
sub esp, 4 ; align the stack to a 16-byte boundary
|
||||
push message
|
||||
call puts
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
24
platforms/platform-test-f4-ll/subhook/tests/foo_64_unix.asm
Normal file
24
platforms/platform-test-f4-ll/subhook/tests/foo_64_unix.asm
Normal file
|
@ -0,0 +1,24 @@
|
|||
bits 64
|
||||
|
||||
extern puts
|
||||
global foo
|
||||
|
||||
section .data
|
||||
|
||||
message:
|
||||
db 'foo() called', 0
|
||||
|
||||
section .text
|
||||
|
||||
foo:
|
||||
nop
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
lea rdi, [rel message]
|
||||
%ifdef USE_PLT
|
||||
call puts wrt ..plt
|
||||
%else
|
||||
call puts
|
||||
%endif
|
||||
pop rbp
|
||||
ret
|
22
platforms/platform-test-f4-ll/subhook/tests/foo_64_win.asm
Normal file
22
platforms/platform-test-f4-ll/subhook/tests/foo_64_win.asm
Normal file
|
@ -0,0 +1,22 @@
|
|||
bits 64
|
||||
|
||||
extern puts
|
||||
global foo
|
||||
|
||||
section .data
|
||||
|
||||
message:
|
||||
db 'foo() called', 0
|
||||
|
||||
section .text
|
||||
|
||||
foo:
|
||||
nop
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
sub rsp, 32
|
||||
mov rcx, qword message
|
||||
call puts
|
||||
add rsp, 32
|
||||
pop rbp
|
||||
ret
|
6
platforms/platform-test-f4-ll/subhook/tests/foo_main.c
Normal file
6
platforms/platform-test-f4-ll/subhook/tests/foo_main.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
extern void foo(void);
|
||||
|
||||
int main() {
|
||||
foo();
|
||||
return 0;
|
||||
}
|
6
platforms/platform-test-f4-ll/subhook/tests/foo_main.cpp
Normal file
6
platforms/platform-test-f4-ll/subhook/tests/foo_main.cpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
extern "C" void foo(void);
|
||||
|
||||
int main() {
|
||||
foo();
|
||||
return 0;
|
||||
}
|
82
platforms/platform-test-f4-ll/subhook/tests/test.c
Normal file
82
platforms/platform-test-f4-ll/subhook/tests/test.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <subhook.h>
|
||||
|
||||
typedef void (*foo_func_t)(void);
|
||||
|
||||
#ifdef SUBHOOK_X86
|
||||
#if defined SUBHOOK_WINDOWS
|
||||
#define FOO_CALL __cdecl
|
||||
#elif defined SUBHOOK_UNIX
|
||||
#define FOO_CALL __attribute__((cdecl))
|
||||
#endif
|
||||
#endif
|
||||
#ifndef FOO_CALL
|
||||
#define FOO_CALL
|
||||
#endif
|
||||
|
||||
extern void FOO_CALL foo(void);
|
||||
foo_func_t foo_tr = NULL;
|
||||
|
||||
void foo_hooked(void) {
|
||||
puts("foo_hooked() called");
|
||||
}
|
||||
|
||||
void foo_hooked_tr(void) {
|
||||
puts("foo_hooked_tr() called");
|
||||
foo_tr();
|
||||
}
|
||||
|
||||
int main() {
|
||||
puts("Testing initial install");
|
||||
|
||||
subhook_t foo_hook = subhook_new((void *)foo,
|
||||
(void *)foo_hooked,
|
||||
SUBHOOK_64BIT_OFFSET);
|
||||
if (foo_hook == NULL || subhook_install(foo_hook) < 0) {
|
||||
puts("Install failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo();
|
||||
if (subhook_remove(foo_hook) < 0) {
|
||||
puts("Remove failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo();
|
||||
|
||||
puts("Testing re-install");
|
||||
|
||||
if (subhook_install(foo_hook) < 0) {
|
||||
puts("Install failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo();
|
||||
if (subhook_remove(foo_hook) < 0) {
|
||||
puts("Remove failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo();
|
||||
|
||||
subhook_free(foo_hook);
|
||||
|
||||
puts("Testing trampoline");
|
||||
|
||||
subhook_t foo_hook_tr = subhook_new((void *)foo,
|
||||
(void *)foo_hooked_tr,
|
||||
SUBHOOK_64BIT_OFFSET);
|
||||
if (subhook_install(foo_hook_tr) < 0) {
|
||||
puts("Install failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo_tr = (foo_func_t)subhook_get_trampoline(foo_hook_tr);
|
||||
if (foo_tr == NULL) {
|
||||
puts("Failed to build trampoline");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo();
|
||||
|
||||
subhook_free(foo_hook_tr);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
77
platforms/platform-test-f4-ll/subhook/tests/test.cpp
Normal file
77
platforms/platform-test-f4-ll/subhook/tests/test.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <subhook.h>
|
||||
|
||||
typedef void (*foo_func_t)();
|
||||
|
||||
#ifdef SUBHOOK_X86
|
||||
#if defined SUBHOOK_WINDOWS
|
||||
#define FOO_CALL __cdecl
|
||||
#elif defined SUBHOOK_UNIX
|
||||
#define FOO_CALL __attribute__((cdecl))
|
||||
#endif
|
||||
#endif
|
||||
#ifndef FOO_CALL
|
||||
#define FOO_CALL
|
||||
#endif
|
||||
|
||||
extern "C" void FOO_CALL foo();
|
||||
foo_func_t foo_tr = 0;
|
||||
|
||||
void foo_hooked() {
|
||||
std::cout << "foo_hooked() called" << std::endl;;
|
||||
}
|
||||
|
||||
void foo_hooked_tr() {
|
||||
std::cout << "foo_hooked_tr() called" << std::endl;
|
||||
foo_tr();
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Testing initial install" << std::endl;
|
||||
|
||||
subhook::Hook foo_hook((void *)foo,
|
||||
(void *)foo_hooked,
|
||||
subhook::HookFlag64BitOffset);
|
||||
if (!foo_hook.Install()) {
|
||||
std::cout << "Install failed" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo();
|
||||
if (!foo_hook.Remove()) {
|
||||
std::cout << "Remove failed" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo();
|
||||
|
||||
std::cout << "Testing re-install" << std::endl;
|
||||
|
||||
if (!foo_hook.Install()) {
|
||||
std::cout << "Install failed" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo();
|
||||
if (!foo_hook.Remove()) {
|
||||
std::cout << "Remove failed" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo();
|
||||
|
||||
std::cout << "Testing trampoline" << std::endl;
|
||||
|
||||
subhook::Hook foo_hook_tr((void *)foo,
|
||||
(void *)foo_hooked_tr,
|
||||
subhook::HookFlag64BitOffset);
|
||||
if (!foo_hook_tr.Install()) {
|
||||
std::cout << "Install failed" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo_tr = (foo_func_t)foo_hook_tr.GetTrampoline();
|
||||
if (foo_tr == 0) {
|
||||
std::cout << "Failed to build trampoline" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
foo();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue