Skip to content

Commit 1825079

Browse files
committed
Add tests directory and TestDLL project; improve CMake configuration
1 parent ff78b85 commit 1825079

6 files changed

Lines changed: 97 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ add_subdirectory(Neptune)
1818
add_subdirectory(NThread)
1919
add_subdirectory(NThreadOSUtils)
2020

21+
# Testleri derlemeye dahil et
22+
add_subdirectory(tests)
23+
2124
set(GHOSTINJECTOR_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
2225
set(GHOSTINJECTOR_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
2326

src/main.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,24 @@
3232
#include "ntmem.h"
3333
#include "ntosutilswin.h"
3434

35-
void print_usage() {
36-
printf("GhostInjector - DLL Injection tool for Windows processes\n\n");
37-
printf("Examples:\n");
38-
printf(" ghostinjector.exe 1234 mydll.dll\n");
39-
printf(" ghostinjector.exe 5678 first.dll second.dll third.dll\n\n");
40-
printf("Usage:\n");
41-
printf(" ghostinjector.exe <process_id> <dll_path> [dll_path2 ...]\n");
42-
printf(" ghostinjector.exe -h | --help\n");
35+
void print_usage()
36+
{
37+
printf("GhostInjector - DLL Injection tool for Windows processes\n\n");
38+
printf("Examples:\n");
39+
printf(" ghostinjector.exe 1234 mydll.dll\n");
40+
printf(" ghostinjector.exe 5678 first.dll second.dll third.dll\n\n");
41+
printf("Usage:\n");
42+
printf(" ghostinjector.exe <process_id> <dll_path> [dll_path2 ...]\n");
43+
printf(" ghostinjector.exe -h | --help\n");
4344
}
4445

4546
int main(int argc, char *argv[])
4647
{
4748
if (HAS_ERR(neptune_init()))
4849
return EXIT_FAILURE;
4950

50-
if (argc < 3 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
51+
if (argc < 3 || strcmp(argv[1], "-h") == 0 ||
52+
strcmp(argv[1], "--help") == 0) {
5153
print_usage();
5254
neptune_destroy();
5355
return EXIT_SUCCESS;
@@ -109,7 +111,8 @@ int main(int argc, char *argv[])
109111
const char *dll_path = argv[i];
110112

111113
#ifdef LOG_LEVEL_1
112-
LOG_INFO("Injecting DLL [%d/%d]: %s", i - 1, argc - 2, dll_path);
114+
LOG_INFO("Injecting DLL [%d/%d]: %s", i - 1, argc - 2,
115+
dll_path);
113116
#endif
114117

115118
size_t dll_path_len = strlen(dll_path);
@@ -120,7 +123,7 @@ int main(int argc, char *argv[])
120123
#ifdef LOG_LEVEL_1
121124
LOG_ERROR("ntm_create failed for %s", dll_path);
122125
#endif
123-
continue;
126+
continue;
124127
}
125128

126129
void *local = NTM_LOCAL(ntmem);
@@ -139,7 +142,8 @@ int main(int argc, char *argv[])
139142
LOG_INFO("DLL Path Address(%p)", dll_path_addr);
140143
#endif
141144

142-
void *load_library_ret = ntu_ucall((void *)load_library_func, dll_path_addr);
145+
void *load_library_ret =
146+
ntu_ucall((void *)load_library_func, dll_path_addr);
143147

144148
#ifdef LOG_LEVEL_1
145149
LOG_INFO("LoadLibrary returned: %p", load_library_ret);

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Bu dizindeki diğer test projelerini ekleyin
2+
add_subdirectory(TestDLL)

tests/TestDLL/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(TestDLL C)
3+
4+
set(CMAKE_C_STANDARD 99)
5+
6+
string(TOLOWER ${PROJECT_NAME} library_name)
7+
8+
add_library(${library_name} SHARED src/dllmain.c)
9+
10+
target_include_directories(${library_name} PRIVATE ../../Neptune/include)
11+
12+
target_link_libraries(${library_name} PRIVATE Neptune)
13+
14+
target_compile_definitions(${library_name} PRIVATE
15+
LOG_LEVEL_2
16+
"LOG_FILE_PATH=L\"C:\\\\ghostinjectortest.log\""
17+
LOG_ON_STDOUT=0
18+
)
19+
20+
set_target_properties(${library_name} PROPERTIES PREFIX "")

tests/TestDLL/src/dllmain.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 Serkan Aksoy
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#include <windows.h>
26+
#include "neptune.h"
27+
#include "log.h"
28+
#include "nerror.h"
29+
30+
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
31+
{
32+
(void)hinstDLL;
33+
(void)lpvReserved;
34+
35+
switch (fdwReason) {
36+
case DLL_PROCESS_ATTACH:
37+
if (HAS_ERR(neptune_init())) {
38+
return FALSE;
39+
}
40+
41+
DWORD pid = GetCurrentProcessId();
42+
DWORD tid = GetCurrentThreadId();
43+
44+
LOG_INFO("Injected into PID: %lu, Thread ID: %lu", pid, tid);
45+
break;
46+
47+
case DLL_PROCESS_DETACH:
48+
neptune_destroy();
49+
break;
50+
}
51+
52+
return TRUE;
53+
}

toolchain-mingw.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
44
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
55
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
66

7+
set(CMAKE_EXE_LINKER_FLAGS "-s")
8+
set(CMAKE_SHARED_LINKER_FLAGS "-s")
9+
710
# Optimize for size in release builds
811
string(APPEND CMAKE_C_FLAGS_RELEASE " -Os")

0 commit comments

Comments
 (0)