├── Demo.png ├── README.md ├── wowJit.sln └── wowJit ├── wowJit.cpp ├── wowJit.vcxproj ├── wowJit.vcxproj.filters └── wowJit.vcxproj.user /Demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaaddress1/wow64Jit/5c879be8c401f5b4c811b01c07674540abd8c08f/Demo.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wowJit 2 | ### Call 32bit NtDLL API directly from WoW64 Layer (C++) 3 | 4 | basicly inspired by [ReWolf: Mixing x86 with x64 code](http://blog.rewolf.pl/blog/?p=102) 5 | 6 | ![](Demo.png) 7 | -------------------------------------------------------------------------------- /wowJit.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30611.23 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wowJit", "wowJit\wowJit.vcxproj", "{23930329-C132-475A-B5D9-450565AA8230}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {23930329-C132-475A-B5D9-450565AA8230}.Debug|x64.ActiveCfg = Debug|x64 17 | {23930329-C132-475A-B5D9-450565AA8230}.Debug|x64.Build.0 = Debug|x64 18 | {23930329-C132-475A-B5D9-450565AA8230}.Debug|x86.ActiveCfg = Debug|Win32 19 | {23930329-C132-475A-B5D9-450565AA8230}.Debug|x86.Build.0 = Debug|Win32 20 | {23930329-C132-475A-B5D9-450565AA8230}.Release|x64.ActiveCfg = Release|x64 21 | {23930329-C132-475A-B5D9-450565AA8230}.Release|x64.Build.0 = Release|x64 22 | {23930329-C132-475A-B5D9-450565AA8230}.Release|x86.ActiveCfg = Release|Win32 23 | {23930329-C132-475A-B5D9-450565AA8230}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {96A95E8B-E9BC-47BE-9037-8F5EB59733E4} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /wowJit/wowJit.cpp: -------------------------------------------------------------------------------- 1 | /* wowJit - Call 32bit NtDLL API directly from WoW64 Layer 2 | * author: aaaddress1@chroot.org 3 | * 4 | * inspired by ReWolf's blog: Mixing x86 with x64 code 5 | * > http://blog.rewolf.pl/blog/?p=102 6 | */ 7 | #include 8 | #include 9 | using namespace std; 10 | #pragma warning(disable:4996) 11 | #define errorExit(msg) { OutputDebugStringA(msg), exit(-1); } 12 | 13 | size_t getBytecodeOfNtAPI(const char* ntAPItoLookup) { 14 | static BYTE* dumpImage = 0; 15 | if (dumpImage == nullptr) { 16 | // read whole PE static binary. 17 | FILE* fileptr; BYTE* buffer; LONGLONG filelen; 18 | fileptr = fopen("C:/Windows/SysWoW64/ntdll.dll", "rb"); 19 | fseek(fileptr, 0, SEEK_END); 20 | filelen = ftell(fileptr); 21 | rewind(fileptr); 22 | buffer = (BYTE*)malloc((filelen + 1) * sizeof(char)); 23 | fread(buffer, filelen, 1, fileptr); 24 | 25 | // dump static PE binary into image. 26 | PIMAGE_NT_HEADERS ntHdr = (IMAGE_NT_HEADERS*)(buffer + ((IMAGE_DOS_HEADER*)buffer)->e_lfanew); 27 | dumpImage = (BYTE*)malloc(ntHdr->OptionalHeader.SizeOfImage); 28 | memcpy(dumpImage, buffer, ntHdr->OptionalHeader.SizeOfHeaders); 29 | for (size_t i = 0; i < ntHdr->FileHeader.NumberOfSections; i++) { 30 | auto curr = PIMAGE_SECTION_HEADER(size_t(ntHdr) + sizeof(IMAGE_NT_HEADERS))[i]; 31 | memcpy(dumpImage + curr.VirtualAddress, buffer + curr.PointerToRawData, curr.SizeOfRawData); 32 | } 33 | free(buffer); 34 | fclose(fileptr); 35 | } 36 | // EAT parse. 37 | PIMAGE_NT_HEADERS ntHdr = (IMAGE_NT_HEADERS*)(dumpImage + ((IMAGE_DOS_HEADER*)dumpImage)->e_lfanew); 38 | auto a = ntHdr->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]; 39 | PIMAGE_EXPORT_DIRECTORY ied = (PIMAGE_EXPORT_DIRECTORY)((LPBYTE)dumpImage + a.VirtualAddress); 40 | uint32_t* addrOfNames = (uint32_t*)((size_t)dumpImage + ied->AddressOfNames); 41 | uint16_t* addrOfNameOrds = (uint16_t*)((size_t)dumpImage + ied->AddressOfNameOrdinals); 42 | uint32_t* AddrOfFuncAddrs = (uint32_t*)((size_t)dumpImage + ied->AddressOfFunctions); 43 | if (ied->NumberOfNames == 0) return (size_t)0; 44 | for (DWORD i = 0; i < ied->NumberOfNames; i++) 45 | if (!stricmp((char*)((size_t)dumpImage + addrOfNames[i]), ntAPItoLookup)) 46 | return ((size_t)dumpImage + AddrOfFuncAddrs[addrOfNameOrds[i]]); 47 | return 0; 48 | } 49 | 50 | template NTSTATUS NtAPI(const char* szNtApiToCall, Args... a) { 51 | uint8_t stub_template[] = { 52 | /* +00 - mov eax, 00000000 */ 0xB8, 0x00, 0x00, 0x00, 0x00, 53 | /* +05 - call fs: [0xC0] */ 0x64, 0xFF, 0x15, 0xC0, 0x00, 0x00, 0x00, 54 | /* +0C - ret */ 0xC3 55 | }; 56 | PCHAR apiAddr = PCHAR(getBytecodeOfNtAPI(szNtApiToCall)); 57 | if (*apiAddr - '\xB8') errorExit("this NtAPI not supported."); 58 | PCHAR jit_stub = (PCHAR)VirtualAlloc(0, sizeof(stub_template), MEM_COMMIT, PAGE_EXECUTE_READWRITE); 59 | memcpy(jit_stub, stub_template, sizeof(stub_template)); 60 | *(uint32_t *)&jit_stub[0x01] = *(uint32_t *)&apiAddr[1]; 61 | auto ret = ((NTSTATUS(__cdecl*)(...))jit_stub)(forward(a)...); 62 | VirtualFree(jit_stub, sizeof(stub_template), MEM_FREE); 63 | return ret; 64 | } 65 | 66 | int main() { 67 | DWORD PID; 68 | if (!GetWindowThreadProcessId(FindWindowA("notepad", NULL), &PID)) 69 | errorExit("notepad not exist?"); 70 | 71 | if (HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID)) { 72 | NtAPI("ZwTerminateProcess", hProcess, 1); 73 | errorExit("done."); 74 | } 75 | else errorExit("fetch hProcess fail."); 76 | } 77 | -------------------------------------------------------------------------------- /wowJit/wowJit.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {23930329-c132-475a-b5d9-450565aa8230} 25 | wowJit 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Level3 100 | true 101 | true 102 | true 103 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 104 | true 105 | Disabled 106 | 107 | 108 | Console 109 | true 110 | true 111 | true 112 | 113 | 114 | 115 | 116 | Level3 117 | true 118 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 119 | true 120 | 121 | 122 | Console 123 | true 124 | 125 | 126 | 127 | 128 | Level3 129 | true 130 | true 131 | true 132 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 133 | true 134 | 135 | 136 | Console 137 | true 138 | true 139 | true 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /wowJit/wowJit.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 來源檔案 20 | 21 | 22 | -------------------------------------------------------------------------------- /wowJit/wowJit.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | --------------------------------------------------------------------------------