MCPcopy Create free account
hub / github.com/HoShiMin/Kernel-Bridge / ExecuteShellCode

Function ExecuteShellCode

Kernel-Bridge/API/KernelShells.cpp:11–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

KbExecuteShellCodeFunction · 0.85

Calls 3

IsSmepPresentFunction · 0.85
DisableSmepFunction · 0.85
EnableSmepFunction · 0.85

Tested by

no test coverage detected