From 1ddfafcd57ed6b47c31462e278503f9c0b82f858 Mon Sep 17 00:00:00 2001 From: Max Power Date: Tue, 12 Nov 2024 13:44:13 -0800 Subject: [PATCH] Allow program optimization by using the #pragma optimize directive on unoptimizable function --- Example/HWSyscalls-Example/HWSyscalls-Example.vcxproj | 3 ++- Example/HWSyscalls-Example/HWSyscalls.cpp | 2 ++ README.md | 4 +--- Src/HWSyscalls.cpp | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Example/HWSyscalls-Example/HWSyscalls-Example.vcxproj b/Example/HWSyscalls-Example/HWSyscalls-Example.vcxproj index e57aab6..65e2689 100644 --- a/Example/HWSyscalls-Example/HWSyscalls-Example.vcxproj +++ b/Example/HWSyscalls-Example/HWSyscalls-Example.vcxproj @@ -130,8 +130,9 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - Disabled + MaxSpeed stdcpp20 + true Console diff --git a/Example/HWSyscalls-Example/HWSyscalls.cpp b/Example/HWSyscalls-Example/HWSyscalls.cpp index 4e11569..5a15ef4 100644 --- a/Example/HWSyscalls-Example/HWSyscalls.cpp +++ b/Example/HWSyscalls-Example/HWSyscalls.cpp @@ -183,9 +183,11 @@ DWORD64 FindSyscallReturnAddress(DWORD64 functionAddress, WORD syscallNumber) { #pragma endregion +#pragma optimize("", off) UINT64 PrepareSyscall(char* functionName) { return ntFunctionAddress; } +#pragma optimize("", on) bool SetMainBreakpoint() { // Dynamically find the GetThreadContext and SetThreadContext functions diff --git a/README.md b/README.md index 90e221c..e372028 100644 --- a/README.md +++ b/README.md @@ -91,9 +91,7 @@ The debug verbosity can be turned on or off by changing the `HWSYSCALLS_DEBUG` d ## Setup -To compile this project you will need Visual Studio 2019 and forward. -It is important to note that this project was made only for x64 environments and needs to be compiled without optimization. -You can disable it from Project Settings -> C/C++ -> Optimization -> Optimization (Disabled /Od). +To compile this project you will need Visual Studio 2019 and forward. Furthermore, it is important to note that this project was made only for x64 environments. ## Example diff --git a/Src/HWSyscalls.cpp b/Src/HWSyscalls.cpp index 4e11569..5a15ef4 100644 --- a/Src/HWSyscalls.cpp +++ b/Src/HWSyscalls.cpp @@ -183,9 +183,11 @@ DWORD64 FindSyscallReturnAddress(DWORD64 functionAddress, WORD syscallNumber) { #pragma endregion +#pragma optimize("", off) UINT64 PrepareSyscall(char* functionName) { return ntFunctionAddress; } +#pragma optimize("", on) bool SetMainBreakpoint() { // Dynamically find the GetThreadContext and SetThreadContext functions