-
Notifications
You must be signed in to change notification settings - Fork 1
TestDeletionRace for SWBP deletion race condition #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+179
−110
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| #include <cstdio> | ||
| #include <cstdlib> | ||
| #include "TitanEngine.h" | ||
|
|
||
| static PROCESS_INFORMATION g_pi; | ||
| static ULONG_PTR g_raceFunction = 0; | ||
| static ULONG_PTR g_raceCounter = 0; | ||
| static bool g_deleted = false; | ||
| static unsigned int g_hits = 0; | ||
| static unsigned int g_finalCount = 0; | ||
|
|
||
| static const unsigned int DELETE_AFTER = 10; | ||
|
|
||
| static void cbBreakpoint() | ||
| { | ||
| g_hits++; | ||
|
|
||
| if (!g_deleted && g_hits >= DELETE_AFTER) | ||
| { | ||
| printf("hit #%u, deleting breakpoint\n", g_hits); | ||
| DeleteBPX(g_raceFunction); | ||
| g_deleted = true; | ||
| } | ||
| } | ||
|
|
||
| static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* info) | ||
| { | ||
| wchar_t path[MAX_PATH] = L""; | ||
| GetFinalPathNameByHandleW(info->hFile, path, MAX_PATH, VOLUME_NAME_DOS); | ||
|
|
||
| auto base = (ULONG_PTR)info->lpBaseOfImage; | ||
| auto hLib = LoadLibraryExW(path, nullptr, DONT_RESOLVE_DLL_REFERENCES); | ||
| if (hLib) | ||
| { | ||
| auto addr = (ULONG_PTR)GetProcAddress(hLib, "RaceFunction"); | ||
| if (addr) | ||
| g_raceFunction = addr - (ULONG_PTR)hLib + base; | ||
|
|
||
| addr = (ULONG_PTR)GetProcAddress(hLib, "RaceCounter"); | ||
| if (addr) | ||
| g_raceCounter = addr - (ULONG_PTR)hLib + base; | ||
|
|
||
| FreeLibrary(hLib); | ||
| } | ||
|
|
||
| if (g_raceFunction) | ||
| { | ||
| printf("RaceFunction: %p\n", (void*)g_raceFunction); | ||
| SetBPX(g_raceFunction, UE_BREAKPOINT, (void*)cbBreakpoint); | ||
| } | ||
| } | ||
|
|
||
| static void cbExitProcess(EXIT_PROCESS_DEBUG_INFO* info) | ||
| { | ||
| if (g_raceCounter) | ||
| { | ||
| SIZE_T n; | ||
| ReadProcessMemory(g_pi.hProcess, (LPVOID)g_raceCounter, &g_finalCount, sizeof(g_finalCount), &n); | ||
| } | ||
|
|
||
| printf("\nRaceCounter: %u (expected 5001)\n", g_finalCount); | ||
| printf("Exit code: %u\n", info->dwExitCode); | ||
| printf("BP hits: %u\n", g_hits); | ||
|
|
||
| bool ok = (g_finalCount == 5001) && (info->dwExitCode == 0); | ||
| printf("Result: %s\n", ok ? "PASS" : "FAIL"); | ||
| } | ||
|
|
||
| int wmain(int argc, wchar_t** argv) | ||
| { | ||
| if (argc < 2) | ||
| { | ||
| puts("Usage: TestDeletionRace <DebugMe.exe>"); | ||
| return 1; | ||
| } | ||
|
|
||
| auto pi = (PROCESS_INFORMATION*)InitDebugW(argv[1], nullptr, nullptr); | ||
| if (!pi) | ||
| { | ||
| puts("InitDebugW failed"); | ||
| return 1; | ||
| } | ||
| g_pi = *pi; | ||
|
|
||
| SetCustomHandler(UE_CH_CREATEPROCESS, (void*)cbCreateProcess); | ||
| SetCustomHandler(UE_CH_EXITPROCESS, (void*)cbExitProcess); | ||
|
|
||
| DebugLoop(); | ||
|
|
||
| return (g_finalCount == 5001) ? 0 : 1; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.