MCPcopy Create free account
hub / github.com/NoMercy-ac/NoMercy / ExecuteShellCode

Function ExecuteShellCode

Source/Client/NM_Sys/API/KernelShells.cpp:12–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10{
11 _IRQL_requires_max_(APC_LEVEL)
12 ULONG ExecuteShellCode(_ShellCode Shell, OPTIONAL IN OUT PVOID Argument)
13 {
14 static volatile LONG EnteringsCount = 0;
15 InterlockedIncrement(&EnteringsCount);
16
17 ULONG Result = 0;
18
19 KFLOATING_SAVE FpuState = {};
20 BOOLEAN FpuSaved = KeSaveFloatingPointState(&FpuState) == STATUS_SUCCESS;
21
22 KAFFINITY PreviousAffinity = KeQueryActiveProcessors();
23 KeSetSystemAffinityThread(1); // Executing on 1st core of 1st processor
24
25 if (CPU::IsSmepPresent())
26 CPU::DisableSmep();
27
28 __try
29 {
30 Result = Shell(Importer::GetKernelProcAddress, Argument);
31 }
32 __except (EXCEPTION_EXECUTE_HANDLER)
33 {
34 Result = static_cast<ULONG>(-1);
35 }
36
37 InterlockedDecrement(&EnteringsCount);
38 if (!InterlockedCompareExchange(&EnteringsCount, 0, 0) && CPU::IsSmepPresent())
39 CPU::EnableSmep();
40
41 KeSetSystemAffinityThread(PreviousAffinity);
42
43 if (FpuSaved)
44 KeRestoreFloatingPointState(&FpuState);
45
46 return Result;
47 }
48}

Callers 1

KbExecuteShellCodeFunction · 0.85

Calls 3

IsSmepPresentFunction · 0.85
DisableSmepFunction · 0.85
EnableSmepFunction · 0.85

Tested by

no test coverage detected