Skip to content

Commit

Permalink
The win32k system call numbers start with 0x1000
Browse files Browse the repository at this point in the history
  • Loading branch information
BeneficialCode committed Jul 7, 2024
1 parent f479fcd commit ce25143
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 19 deletions.
1 change: 1 addition & 0 deletions KernelLibrary/khook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ bool khook::HookSSDT(const char* apiName, void* newfunc) {
_info->Index = index;
_info->Old = oldValue;
_info->New = newValue;
// The lower 4 bits store the number of arguments passed on the stack to the system call
_info->OriginalAddress = (oldValue >> 4) + base;
#else
newValue = (ULONG)newfunc;
Expand Down
14 changes: 0 additions & 14 deletions KernelLibrary/khook.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,6 @@ enum class HookType {
ShadowSSDT
};

//#define VIRTUAL_ADDRESS_BITS 48
//#define VIRTUAL_ADDRESS_MASK ((((ULONG_PTR)1) << VIRTUAL_ADDRESS_BITS) - 1)
//
//#define MiGetPteAddress(va) \
// ((PMMPTE)(((((ULONG_PTR)(va) & VIRTUAL_ADDRESS_MASK) >> PTI_SHIFT) << PTE_SHIFT) + PTE_BASE))
//
//#define MiGetPxeAddress(va) ((PMMPTE)PXE_BASE + MiGetPxeOffset(va))
//
//#define MiGetPpeAddress(va) \
// ((PMMPTE)(((((ULONG_PTR)(va) & VIRTUAL_ADDRESS_MASK) >> PPI_SHIFT) << PTE_SHIFT) + PPE_BASE))
//
//#define MiGetPdeAddress(va) \
// ((PMMPTE)(((((ULONG_PTR)(va) & VIRTUAL_ADDRESS_MASK) >> PDI_SHIFT) << PTE_SHIFT) + PDE_BASE))

class khook{
public:

Expand Down
5 changes: 3 additions & 2 deletions WinArk/KernelHookView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ LRESULT CKernelHookView::OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPara
return 0;
}

// System Service Dispatch Table
void CKernelHookView::InitSSDTHookTable() {
BarDesc bars[] = {
{12,"Service Number",0},
{20,"System Call Number",0},
{55,"Service Name",0},
{20,"Original Address",0},
{10,"Is Hook",0},
Expand Down Expand Up @@ -97,7 +98,7 @@ void CKernelHookView::InitSSDTHookTable() {

void CKernelHookView::InitShadowSSDTHookTable() {
BarDesc bars[] = {
{15,"Service Number",0},
{20,"System Call Number",0},
{55,"Service Name",0},
{20,"Original Address",0},
{10,"Is Hook",0},
Expand Down
2 changes: 0 additions & 2 deletions WinArk/NtDll.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

//#include <winternl.h>

#pragma comment(lib, "ntdll")

#define DIRECTORY_QUERY (0x0001)
Expand Down
1 change: 1 addition & 0 deletions WinArk/SSDTHookTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ ULONG_PTR CSSDTHookTable::GetOrignalAddress(DWORD number) {
uintptr_t rva = (uintptr_t)_KiServiceTable - (uintptr_t)_kernelBase;
ULONG_PTR imageBase = (ULONG_PTR)_fileMapVA;
#ifdef _WIN64
// On 64-bit Windows systems, the stored values in SSDT are not absolute address
auto CheckAddressMethod = [&]()->bool {
auto pEntry = (char*)_fileMapVA + rva + 8 * number;
ULONGLONG value = *(ULONGLONG*)pEntry;
Expand Down
3 changes: 2 additions & 1 deletion WinArk/ShadowSSDTTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ int CShadowSSDTHookTable::ParseTableEntry(CString& s, char& mask, int& select, S
switch (column)
{
case 0:
s.Format(L"%d (0x%-x)", info.ServiceNumber, info.ServiceNumber);
// The win32k system call numbers start with 0x1000
s.Format(L"%d (0x%-x)", info.ServiceNumber + 0x1000, info.ServiceNumber + 0x1000);
break;
case 1:
s = Helpers::StringToWstring(info.ServiceFunctionName).c_str();
Expand Down

0 comments on commit ce25143

Please sign in to comment.