| 154 | |
| 155 | |
| 156 | bool khook::GetSystemServiceTable() { |
| 157 | if (!_ntTable) { |
| 158 | #ifndef _WIN64 |
| 159 | // x86 code |
| 160 | UNICODE_STRING name = RTL_CONSTANT_STRING(L"KeServiceDescriptorTable"); |
| 161 | _ntTable = (SystemServiceTable*)MmGetSystemRoutineAddress(&name); |
| 162 | #else |
| 163 | // x64 code |
| 164 | PEParser parser(_kernelImageBase); |
| 165 | for (int i = 0; parser.GetSectionCount(); i++) { |
| 166 | auto pSec = parser.GetSectionHeader(i); |
| 167 | if (pSec->Characteristics & IMAGE_SCN_MEM_NOT_PAGED && |
| 168 | pSec->Characteristics & IMAGE_SCN_MEM_EXECUTE && |
| 169 | !(pSec->Characteristics & IMAGE_SCN_MEM_DISCARDABLE) && |
| 170 | (*(PULONG)pSec->Name != 'TINI') && |
| 171 | (*(PULONG)pSec->Name != 'EGAP')) { |
| 172 | ULONG_PTR searchAddr = (ULONG_PTR)((PUCHAR)_kernelImageBase + pSec->VirtualAddress); |
| 173 | ULONG_PTR maxAddress = searchAddr + pSec->Misc.VirtualSize; |
| 174 | UCHAR pattern[] = { 0x8B, 0xF8, 0xC1, 0xEF, 0x07, 0x83, 0xE7, 0x20, 0x25, 0xFF, 0x0F, 0x00, 0x00 }; |
| 175 | ULONG_PTR label = Helpers::SearchSignature(searchAddr,pattern, sizeof(pattern), pSec->Misc.VirtualSize); |
| 176 | if (label == 0) |
| 177 | return false; |
| 178 | searchAddr = label + sizeof(pattern); |
| 179 | UCHAR signature[] = { 0x4c,0x8d,0x15 }; |
| 180 | // IA32_LSTAR 0xC0000082H |
| 181 | // �����������˸����ϵ���ת��������������������__readmsr����ʹ�ˡ� |
| 182 | ULONG size = maxAddress - searchAddr; |
| 183 | ULONG_PTR addr = Helpers::SearchSignature(searchAddr, signature, sizeof(signature), size); |
| 184 | if (addr == 0) |
| 185 | return false; |
| 186 | ULONG_PTR offsetAddr = addr + sizeof(signature); |
| 187 | ULONG_PTR offset = 0; |
| 188 | memcpy(&offset, (void*)offsetAddr, 4); |
| 189 | if (offset == 0) { |
| 190 | return false; |
| 191 | } |
| 192 | // 7Ϊָ��� |
| 193 | _ntTable = (SystemServiceTable*)(addr + offset + 7); |
| 194 | } |
| 195 | } |
| 196 | #endif // !_WIN64 |
| 197 | } |
| 198 | return true; |
| 199 | } |
| 200 | |
| 201 | bool khook::GetShadowSystemServiceNumber(PUNICODE_STRING symbolName, PULONG index) { |
| 202 | PLIST_ENTRY head = _shadowServiceNameList.GetHead(); |
nothing calls this directly
no test coverage detected