Skip to content

Commit 869617a

Browse files
committed
Add an AntiDebugHandle test (and make sure it doesn't trigger)
References: - x64dbg/x64dbg#2749 - x64dbg/x64dbg#1364 - x64dbg/TitanEngine#5 - x64dbg/x64dbg#2504
1 parent 74e1c7c commit 869617a

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

CMakeLists.txt

+34
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,40 @@ target_link_options(MemoryTest PRIVATE
142142
unset(CMKR_TARGET)
143143
unset(CMKR_SOURCES)
144144

145+
# Target AntiDebugHandle
146+
set(CMKR_TARGET AntiDebugHandle)
147+
set(AntiDebugHandle_SOURCES "")
148+
149+
list(APPEND AntiDebugHandle_SOURCES
150+
"src/AntiDebugHandle/AntiDebugHandle.cpp"
151+
)
152+
153+
list(APPEND AntiDebugHandle_SOURCES
154+
cmake.toml
155+
)
156+
157+
set(CMKR_SOURCES ${AntiDebugHandle_SOURCES})
158+
add_executable(AntiDebugHandle)
159+
160+
if(AntiDebugHandle_SOURCES)
161+
target_sources(AntiDebugHandle PRIVATE ${AntiDebugHandle_SOURCES})
162+
endif()
163+
164+
get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT)
165+
if(NOT CMKR_VS_STARTUP_PROJECT)
166+
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT AntiDebugHandle)
167+
endif()
168+
169+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${AntiDebugHandle_SOURCES})
170+
171+
target_link_options(AntiDebugHandle PRIVATE
172+
"/DYNAMICBASE:NO"
173+
"/INCREMENTAL:NO"
174+
)
175+
176+
unset(CMKR_TARGET)
177+
unset(CMKR_SOURCES)
178+
145179
# Target TestTitanEngine
146180
set(CMKR_TARGET TestTitanEngine)
147181
set(TestTitanEngine_SOURCES "")

cmake.toml

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ sources = ["src/DebugMe/*.cpp"]
2323
type = "test"
2424
sources = ["src/MemoryTest/*.cpp"]
2525

26+
[target.AntiDebugHandle]
27+
type = "test"
28+
sources = ["src/AntiDebugHandle/*.cpp"]
29+
2630
[target.TestTitanEngine]
2731
type = "executable"
2832
sources = ["src/TestTitanEngine/*.cpp", "src/TestTitanEngine/*.h"]
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <Windows.h>
2+
#include <cstdio>
3+
#include <cinttypes>
4+
5+
int main()
6+
{
7+
puts("");
8+
9+
wchar_t executablePath[MAX_PATH] = L"";
10+
GetModuleFileNameW(0, executablePath, _countof(executablePath));
11+
12+
auto hNtdll = CreateFileW(L"C:\\Windows\\system32\\ntdll.dll", GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, nullptr);
13+
printf("[AntiDebugHandle] ntdll: 0x%zX (LastError: %u)\n", (uintptr_t)hNtdll, GetLastError());
14+
15+
auto hExe = CreateFileW(executablePath, GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, nullptr);
16+
printf("[AntiDebugHandle] exe: 0x%zX (LastError: %u)\n", (uintptr_t)hExe, GetLastError());
17+
18+
puts("");
19+
}

src/DebugLoop/DebugLoop.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ int main(int argc, char** argv)
295295

296296
case LOAD_DLL_DEBUG_EVENT:
297297
{
298+
const auto& dll = debugEvent.u.LoadDll;
299+
if (dll.hFile)
300+
{
301+
CloseHandle(dll.hFile);
302+
}
298303
}
299304
break;
300305

0 commit comments

Comments
 (0)