Last active
September 29, 2018 21:38
-
-
Save RektInator/293c4ec20b462612b54bd6303c8ffa10 to your computer and use it in GitHub Desktop.
This file contains 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
#define WIN32_LEAN_AND_MEAN | |
#include <Windows.h> | |
#include <functional> | |
typedef enum _HARDERROR_RESPONSE_OPTION { | |
OptionAbortRetryIgnore, | |
OptionOk, | |
OptionOkCancel, | |
OptionRetryCancel, | |
OptionYesNo, | |
OptionYesNoCancel, | |
OptionShutdownSystem | |
} HARDERROR_RESPONSE_OPTION, *PHARDERROR_RESPONSE_OPTION; | |
typedef enum _HARDERROR_RESPONSE { | |
ResponseReturnToCaller, | |
ResponseNotHandled, | |
ResponseAbort, | |
ResponseCancel, | |
ResponseIgnore, | |
ResponseNo, | |
ResponseOk, | |
ResponseRetry, | |
ResponseYes | |
} HARDERROR_RESPONSE, *PHARDERROR_RESPONSE; | |
template <typename T> std::function < T > ImportFunction(const std::string& dll, const std::string& function) | |
{ | |
auto dllHandle = GetModuleHandleA(&dll[0]); | |
auto procAddr = GetProcAddress(dllHandle, &function[0]); | |
return std::function < T >(reinterpret_cast<T*>(procAddr)); | |
} | |
int main() | |
{ | |
BOOLEAN hasPerms; | |
HARDERROR_RESPONSE response; | |
auto result = ImportFunction<NTSTATUS __stdcall(ULONG, BOOLEAN, BOOLEAN, PBOOLEAN)>("ntdll.dll", "RtlAdjustPrivilege") | |
(19, true, false, &hasPerms); | |
result = ImportFunction<NTSTATUS __stdcall(NTSTATUS, ULONG, LPCSTR, PVOID, HARDERROR_RESPONSE_OPTION, PHARDERROR_RESPONSE)>("ntdll.dll", "NtRaiseHardError") | |
(0xC000007B /*0x0000000A*/, 0, nullptr, nullptr, OptionShutdownSystem, &response); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment