├── src ├── WsaUtil.cpp ├── NtUtil.h ├── vcpkg.json ├── WsaUtil.h ├── resource.h ├── socksifier.h ├── socksifier.vcxproj.filters ├── NtUtil.cpp ├── socksifier.rc ├── socksifier.vcxproj ├── socksifier.cpp └── NtApi.h ├── assets ├── blk1DOYFW7.png ├── fLj62LY1rn.png └── iyMLDzGjVq.png ├── socksifier.sln.DotSettings ├── appveyor.yml ├── socksifier.sln ├── README.md ├── .gitignore └── LICENSE /src/WsaUtil.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nefarius/socksifier/HEAD/src/WsaUtil.cpp -------------------------------------------------------------------------------- /assets/blk1DOYFW7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nefarius/socksifier/HEAD/assets/blk1DOYFW7.png -------------------------------------------------------------------------------- /assets/fLj62LY1rn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nefarius/socksifier/HEAD/assets/fLj62LY1rn.png -------------------------------------------------------------------------------- /assets/iyMLDzGjVq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nefarius/socksifier/HEAD/assets/iyMLDzGjVq.png -------------------------------------------------------------------------------- /src/NtUtil.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | LPWSTR GetObjectName(HANDLE hObject); 4 | 5 | LPWSTR GetObjectTypeName(HANDLE hObject); 6 | -------------------------------------------------------------------------------- /src/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "socksifier", 3 | "version": "1.0.0", 4 | "description": "socksifier", 5 | "license": "MIT", 6 | "supports": "!(arm | uwp)", 7 | "dependencies": [ 8 | "spdlog", 9 | "detours" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /src/WsaUtil.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void LogWSAError(); 4 | 5 | BOOL BindAndConnectExSync( 6 | SOCKET s, 7 | const struct sockaddr* name, 8 | int namelen 9 | ); 10 | 11 | BOOL WSARecvSync( 12 | SOCKET s, 13 | PCHAR buffer, 14 | ULONG length 15 | ); 16 | 17 | BOOL WSASendSync( 18 | SOCKET s, 19 | PCHAR buffer, 20 | ULONG length 21 | ); 22 | -------------------------------------------------------------------------------- /src/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by socksifier.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /socksifier.sln.DotSettings: -------------------------------------------------------------------------------- 1 | 2 | True 3 | True 4 | True 5 | True 6 | True 7 | True 8 | True 9 | True -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.1.{build} 2 | image: Visual Studio 2022 3 | install: 4 | - cmd: | 5 | cd "C:\Tools\vcpkg" 6 | git pull > NUL 7 | .\bootstrap-vcpkg.bat > NUL 8 | cd %appveyor_build_folder% 9 | skip_commits: 10 | files: 11 | - '**/*.md' 12 | before_build: 13 | - cmd: vcpkg integrate install 14 | - cmd: vcpkg upgrade --no-dry-run 15 | - cmd: vcpkg install spdlog:x86-windows-static spdlog:x64-windows-static detours:x86-windows-static detours:x64-windows-static 16 | - ps: Invoke-WebRequest "https://github.com/nefarius/vpatch/releases/latest/download/vpatch.exe" -OutFile vpatch.exe 17 | - cmd: vpatch.exe --stamp-version "%APPVEYOR_BUILD_VERSION%" --target-file ".\src\%APPVEYOR_PROJECT_NAME%.rc" --resource.file-version --resource.product-version 18 | configuration: Release 19 | platform: 20 | - x86 21 | - x64 22 | build: 23 | project: socksifier.sln 24 | artifacts: 25 | - path: 'bin**\*.dll' 26 | cache: 27 | - c:\tools\vcpkg\installed\ 28 | deploy: 29 | release: v$(APPVEYOR_BUILD_VERSION) 30 | description: 'Socksifier DLL' 31 | provider: GitHub 32 | auth_token: 33 | secure: GvOeZH3msooHWqoQj46UsLaojyMsnudmNdfEMUSJJfrIBuLwAYaMeI5FcxKSFVv7 34 | artifact: /.*\.DLL/ 35 | draft: false 36 | prerelease: false 37 | on: 38 | branch: master 39 | APPVEYOR_REPO_TAG: true -------------------------------------------------------------------------------- /src/socksifier.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 4 | // WinAPI 5 | // 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | // 12 | // Custom 13 | // 14 | #include "NtApi.h" 15 | #include "NtUtil.h" 16 | #include "WsaUtil.h" 17 | 18 | // 19 | // STL 20 | // 21 | #include 22 | 23 | // 24 | // Logging 25 | // 26 | #include 27 | #include 28 | #include 29 | 30 | typedef struct settings 31 | { 32 | INT proxy_address; 33 | USHORT proxy_port; 34 | } setting_t; 35 | 36 | extern LPFN_CONNECTEX ConnectExPtr; 37 | 38 | extern setting_t g_Settings; 39 | 40 | extern std::map g_UdpRoutingMap; 41 | 42 | EXTERN_C int (WINAPI* real_connect)(SOCKET s, const struct sockaddr* name, int namelen); 43 | 44 | EXTERN_C int (WINAPI* real_bind)( 45 | SOCKET s, 46 | const sockaddr* addr, 47 | int namelen 48 | ); 49 | 50 | EXTERN_C int (WINAPI* real_WSASendTo)( 51 | SOCKET s, 52 | LPWSABUF lpBuffers, 53 | DWORD dwBufferCount, 54 | LPDWORD lpNumberOfBytesSent, 55 | DWORD dwFlags, 56 | const sockaddr* lpTo, 57 | int iTolen, 58 | LPWSAOVERLAPPED lpOverlapped, 59 | LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine 60 | ); 61 | 62 | EXTERN_C int (WINAPI* real_WSARecvFrom)( 63 | SOCKET s, 64 | LPWSABUF lpBuffers, 65 | DWORD dwBufferCount, 66 | LPDWORD lpNumberOfBytesRecvd, 67 | LPDWORD lpFlags, 68 | sockaddr* lpFrom, 69 | LPINT lpFromlen, 70 | LPWSAOVERLAPPED lpOverlapped, 71 | LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine 72 | ); 73 | 74 | EXTERN_C int (WINAPI* real_closesocket)( 75 | SOCKET s 76 | ); 77 | -------------------------------------------------------------------------------- /socksifier.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34330.188 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "socksifier", "src\socksifier.vcxproj", "{B844F1AD-D2C4-4DB6-B312-81D40B10DC17}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B880635B-6C9A-41BC-BC41-DE56239F2425}" 9 | ProjectSection(SolutionItems) = preProject 10 | .gitignore = .gitignore 11 | appveyor.yml = appveyor.yml 12 | LICENSE = LICENSE 13 | README.md = README.md 14 | EndProjectSection 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|x64 = Debug|x64 19 | Debug|x86 = Debug|x86 20 | Release|x64 = Release|x64 21 | Release|x86 = Release|x86 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {B844F1AD-D2C4-4DB6-B312-81D40B10DC17}.Debug|x64.ActiveCfg = Debug|x64 25 | {B844F1AD-D2C4-4DB6-B312-81D40B10DC17}.Debug|x64.Build.0 = Debug|x64 26 | {B844F1AD-D2C4-4DB6-B312-81D40B10DC17}.Debug|x86.ActiveCfg = Debug|Win32 27 | {B844F1AD-D2C4-4DB6-B312-81D40B10DC17}.Debug|x86.Build.0 = Debug|Win32 28 | {B844F1AD-D2C4-4DB6-B312-81D40B10DC17}.Release|x64.ActiveCfg = Release|x64 29 | {B844F1AD-D2C4-4DB6-B312-81D40B10DC17}.Release|x64.Build.0 = Release|x64 30 | {B844F1AD-D2C4-4DB6-B312-81D40B10DC17}.Release|x86.ActiveCfg = Release|Win32 31 | {B844F1AD-D2C4-4DB6-B312-81D40B10DC17}.Release|x86.Build.0 = Release|Win32 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | GlobalSection(ExtensibilityGlobals) = postSolution 37 | SolutionGuid = {2ACA13E8-F738-4754-A067-E552AA7CF1A4} 38 | EndGlobalSection 39 | EndGlobal 40 | -------------------------------------------------------------------------------- /src/socksifier.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;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 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | 46 | 47 | Resource Files 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/NtUtil.cpp: -------------------------------------------------------------------------------- 1 | #include "socksifier.h" 2 | 3 | LPWSTR GetObjectName(HANDLE hObject) 4 | { 5 | LPWSTR lpwsReturn = nullptr; 6 | const auto pNTQO = reinterpret_cast(GetProcAddress( 7 | GetModuleHandle("NTDLL.DLL"), 8 | "NtQueryObject" 9 | )); 10 | 11 | if (pNTQO != nullptr) 12 | { 13 | DWORD dwSize = sizeof(OBJECT_NAME_INFORMATION); 14 | POBJECT_NAME_INFORMATION pObjectInfo = (POBJECT_NAME_INFORMATION)new BYTE[dwSize]; 15 | NTSTATUS ntReturn = pNTQO(hObject, ObjectNameInformation, pObjectInfo, dwSize, &dwSize); 16 | 17 | if (ntReturn == STATUS_BUFFER_OVERFLOW) 18 | { 19 | delete pObjectInfo; 20 | pObjectInfo = (POBJECT_NAME_INFORMATION)new BYTE[dwSize]; 21 | ntReturn = pNTQO(hObject, ObjectNameInformation, pObjectInfo, dwSize, &dwSize); 22 | } 23 | 24 | if ((ntReturn >= STATUS_SUCCESS) && (pObjectInfo->Buffer != nullptr)) 25 | { 26 | lpwsReturn = (LPWSTR)new BYTE[pObjectInfo->Length + sizeof(WCHAR)]; 27 | ZeroMemory(lpwsReturn, pObjectInfo->Length + sizeof(WCHAR)); 28 | CopyMemory(lpwsReturn, pObjectInfo->Buffer, pObjectInfo->Length); 29 | } 30 | 31 | delete pObjectInfo; 32 | } 33 | 34 | return lpwsReturn; 35 | } 36 | 37 | LPWSTR GetObjectTypeName(HANDLE hObject) 38 | { 39 | LPWSTR lpwsReturn = nullptr; 40 | const auto pNTQO = reinterpret_cast(GetProcAddress( 41 | GetModuleHandle("NTDLL.DLL"), 42 | "NtQueryObject" 43 | )); 44 | 45 | if (pNTQO != nullptr) 46 | { 47 | DWORD dwSize = sizeof(PUBLIC_OBJECT_TYPE_INFORMATION); 48 | PPUBLIC_OBJECT_TYPE_INFORMATION pObjectInfo = (PPUBLIC_OBJECT_TYPE_INFORMATION)new BYTE[dwSize]; 49 | NTSTATUS ntReturn = pNTQO(hObject, ObjectTypeInformation, pObjectInfo, dwSize, &dwSize); 50 | 51 | if (ntReturn == STATUS_BUFFER_OVERFLOW || ntReturn == STATUS_INFO_LENGTH_MISMATCH) 52 | { 53 | delete pObjectInfo; 54 | pObjectInfo = (PPUBLIC_OBJECT_TYPE_INFORMATION)new BYTE[dwSize]; 55 | ntReturn = pNTQO(hObject, ObjectTypeInformation, pObjectInfo, dwSize, &dwSize); 56 | } 57 | 58 | if ((ntReturn >= STATUS_SUCCESS) && (pObjectInfo->TypeName.Buffer != nullptr)) 59 | { 60 | lpwsReturn = (LPWSTR)new BYTE[pObjectInfo->TypeName.Length + sizeof(WCHAR)]; 61 | ZeroMemory(lpwsReturn, pObjectInfo->TypeName.Length + sizeof(WCHAR)); 62 | CopyMemory(lpwsReturn, pObjectInfo->TypeName.Buffer, pObjectInfo->TypeName.Length); 63 | } 64 | 65 | delete pObjectInfo; 66 | } 67 | 68 | return lpwsReturn; 69 | } 70 | -------------------------------------------------------------------------------- /src/socksifier.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Version 51 | // 52 | 53 | VS_VERSION_INFO VERSIONINFO 54 | FILEVERSION 1,0,0,0 55 | PRODUCTVERSION 1,0,0,0 56 | FILEFLAGSMASK 0x3fL 57 | #ifdef _DEBUG 58 | FILEFLAGS 0x1L 59 | #else 60 | FILEFLAGS 0x0L 61 | #endif 62 | FILEOS 0x40004L 63 | FILETYPE 0x2L 64 | FILESUBTYPE 0x0L 65 | BEGIN 66 | BLOCK "StringFileInfo" 67 | BEGIN 68 | BLOCK "080904b0" 69 | BEGIN 70 | VALUE "CompanyName", "Nefarius" 71 | VALUE "FileDescription", "One DLL to redirect them all to a SOCKS5 server." 72 | VALUE "FileVersion", "1.0.0.0" 73 | VALUE "InternalName", "socksifi.dll" 74 | VALUE "LegalCopyright", "Copyright (C) Nefarius 2019-2021" 75 | VALUE "OriginalFilename", "socksifi.dll" 76 | VALUE "ProductName", "Socksifier" 77 | VALUE "ProductVersion", "1.0.0.0" 78 | END 79 | END 80 | BLOCK "VarFileInfo" 81 | BEGIN 82 | VALUE "Translation", 0x809, 1200 83 | END 84 | END 85 | 86 | #endif // English (United States) resources 87 | ///////////////////////////////////////////////////////////////////////////// 88 | 89 | 90 | 91 | #ifndef APSTUDIO_INVOKED 92 | ///////////////////////////////////////////////////////////////////////////// 93 | // 94 | // Generated from the TEXTINCLUDE 3 resource. 95 | // 96 | 97 | 98 | ///////////////////////////////////////////////////////////////////////////// 99 | #endif // not APSTUDIO_INVOKED 100 | 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Socksifier 2 | 3 | A Windows DLL which hooks low-level [Winsock 2](https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-start-page-2) APIs to redirect sockets to a SOCKS5 proxy server. 4 | 5 | [![Build status](https://ci.appveyor.com/api/projects/status/bwesvx70s524t30w/branch/master?svg=true)](https://ci.appveyor.com/project/nefarius/socksifier/branch/master) [![GitHub All Releases](https://img.shields.io/github/downloads/Nefarius/Socksifier/total)](https://somsubhra.github.io/github-release-stats/?username=Nefarius&repository=Socksifier) 6 | 7 | ## Motivation 8 | 9 | Over time less and less modern network-enabled applications offer the user with the ability to specify an HTTP or SOCKS proxy server. For this specific need, so called "proxification" applications exist, which are unfortunately scarce and closed-source. This fork is an attempt to provide a modern, *working* and **open** solution for this very specific case. 10 | 11 | ## How it works 12 | 13 | Socksifier is a self-contained DLL with no external dependencies (except the APIs shipped with Windows) that is meant to [get loaded into the process](https://web.archive.org/web/20131012071541/http://blog.opensecurityresearch.com/2013/01/windows-dll-injection-basics.html) who's connections should get "proxified" and achieves this by [API-hooking](https://www.codeproject.com/Articles/2082/API-hooking-revealed) the low-level [`connect`](https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect), [`bind`](https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-bind), [`WSASendTo`](https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendto), [`WSARecvFrom`](https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsarecvfrom) and [`closesocket`](https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-closesocket) functions. API-hooking is performed upon library load using the well-known and battle-tested [Microsoft Detours](https://github.com/Microsoft/Detours) library. 14 | 15 | After the hook is established, the process's existing connection handles get enumerated and terminated, forcing the network layer of the application to re-establish them, but now calling the hooked API-variant instead. 16 | 17 | The detoured functions contain the logic necessary to re-route the to-be-established socket connection to a SOCKS5 proxy by performing the necessary protocol-specific handshake and upon success simply returns the socket back to the callee, which is now transparently talking to the proxy instead of the origin destination (e.g. HTTP(S) or WebSocket connection). 18 | 19 | ## Limitations 20 | 21 | This project has been designed for and tested with [Electron](https://www.electronjs.org/)-based applications and [Shadowsocks](https://shadowsocks.org/) as SOCKS5 proxy **only**. Rudimentary **UDP tunneling support** for [WebRTC](https://webrtc.org/) sessions is implemented, but should be considered experimental. 22 | 23 | Other use-cases might work but are left to the reader to discover by experimentation. 24 | 25 | Currently **only IPv4** support is implemented. 26 | 27 | ## Disclaimer 28 | 29 | This project makes heavy use of code and mechanisms unfortunately widely (ab)used by malware (loading foreign code into processes, manipulating handles and network traffic flow), therefore might trigger anti-virus/anti-cheat solutions. Make sure to add an exclusion to your AV in case this becomes and issue and *refrain* from injecting into anti-cheat protected games as this *might* pose the risk of a false-positive ban. You have been warned ❤️ 30 | 31 | **The reader is highly encouraged to study the code and build the project by themselves** instead of trusting the provided binaries. 32 | 33 | ## How to build 34 | 35 | You can build individual projects of the solution within Visual Studio 2022 (any edition is fine). 36 | 37 | ## Getting started 38 | 39 | You can get pre-built binaries (x86, x64) [at the release page](../../releases/latest). 40 | 41 | To enable the redirection you just have to inject the DLL into your target process. Either use a [DLL injector tool](https://github.com/nefarius/Injector) or make injection persistent across application launches with additional help from [LoadDLLViaAppInit](https://blog.didierstevens.com/2009/12/23/loaddllviaappinit/) or similar tools (IAT patching and alike). 42 | 43 | Optionally set up the following environment variables to configure the DLL. Default values are used if omitted. 44 | 45 | - `SOCKSIFIER_ADDRESS` - IP address of the SOCKS5 proxy to connect to (defaults to `127.0.0.1`) 46 | - `SOCKSIFIER_PORT` - Port of the SOCKS5 proxy to connect to (defaults to `1080`) 47 | 48 | The default values assume that a [Shadowsocks client](https://github.com/shadowsocks/shadowsocks-windows) is running and listening on localhost. 49 | 50 | ## Diagnostics 51 | 52 | The library logs to the Windows Debugger Backend and can be observed with [DebugView++](https://github.com/CobaltFusion/DebugViewPP) or similar. 53 | 54 | ![iyMLDzGjVq.png](assets/iyMLDzGjVq.png) 55 | 56 | ## Example 57 | 58 | Observe the change in network connections with e.g. [NirSoft CurrPorts](https://www.nirsoft.net/utils/cports.html). 59 | 60 | ### Before 61 | 62 | ![fLj62LY1rn.png](assets/fLj62LY1rn.png) 63 | 64 | ### After 65 | 66 | ![blk1DOYFW7.png](assets/blk1DOYFW7.png) 67 | 68 | ## Sources & 3rd party credits 69 | 70 | This project benefits from these awesome projects and articles ❤ (appearance in no special order): 71 | 72 | - [Windows Sockets Error Codes](https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2) 73 | - [WSAEWOULDBLOCK error on non-blocking Connect()](https://stackoverflow.com/questions/14016579/wsaewouldblock-error-on-non-blocking-connect) 74 | - [ConnectEx function](https://docs.microsoft.com/en-gb/windows/win32/api/mswsock/nc-mswsock-lpfn_connectex) 75 | - [connect function](https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect) 76 | - [WSAGetOverlappedResult function](https://docs.microsoft.com/en-gb/windows/win32/api/winsock2/nf-winsock2-wsagetoverlappedresult) 77 | - [Working ConnectEx example](https://gist.github.com/joeyadams/4158972) 78 | - [Simple SOCKS5 client written in C++](https://github.com/rudolfovich/socks5-client) 79 | - [WSock Socks5 proxy forwarding POC](https://github.com/duketwo/WinsockConnectHookSocks5) 80 | - [SOCKS Protocol Version 5](https://tools.ietf.org/html/rfc1928) 81 | - [shadowsocks-windows](https://github.com/shadowsocks/shadowsocks-windows) 82 | - [Sysinternals - Enumerate socket handles](https://web.archive.org/web/20120525235842/http://forum.sysinternals.com/socket-handles_topic1193.html) 83 | - [Get name of all handles in current process](https://stackoverflow.com/q/8719252/490629) 84 | - [Get a list of Handles of a process](https://www.cplusplus.com/forum/windows/95774/) 85 | - [Hijacking connections without injections: a ShadowMoving approach to the art of pivoting](https://adepts.of0x.cc/shadowmove-hijack-socket/) 86 | - [Lateral Movement by Duplicating Existing Sockets](https://www.ired.team/offensive-security/lateral-movement/shadowmove-lateral-movement-by-stealing-duplicating-existing-connected-sockets) 87 | - [SYSTEM_HANDLE_TABLE_ENTRY_INFO](https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/ex/sysinfo/handle_table_entry.htm?ts=0,115) 88 | - [Get Handle of Open Sockets of a Program](https://stackoverflow.com/q/16262114/490629) 89 | - [Why does SOCKS5 require to relay UDP over UDP?](https://stackoverflow.com/q/41967217/490629) 90 | - [shadowsocks-rust](https://github.com/shadowsocks/shadowsocks-rust) 91 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Nuget personal access tokens and Credentials 210 | nuget.config 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio LightSwitch build output 301 | **/*.HTMLClient/GeneratedArtifacts 302 | **/*.DesktopClient/GeneratedArtifacts 303 | **/*.DesktopClient/ModelManifest.xml 304 | **/*.Server/GeneratedArtifacts 305 | **/*.Server/ModelManifest.xml 306 | _Pvt_Extensions 307 | 308 | # Paket dependency manager 309 | .paket/paket.exe 310 | paket-files/ 311 | 312 | # FAKE - F# Make 313 | .fake/ 314 | 315 | # CodeRush personal settings 316 | .cr/personal 317 | 318 | # Python Tools for Visual Studio (PTVS) 319 | __pycache__/ 320 | *.pyc 321 | 322 | # Cake - Uncomment if you are using it 323 | # tools/** 324 | # !tools/packages.config 325 | 326 | # Tabs Studio 327 | *.tss 328 | 329 | # Telerik's JustMock configuration file 330 | *.jmconfig 331 | 332 | # BizTalk build output 333 | *.btp.cs 334 | *.btm.cs 335 | *.odx.cs 336 | *.xsd.cs 337 | 338 | # OpenCover UI analysis results 339 | OpenCover/ 340 | 341 | # Azure Stream Analytics local run output 342 | ASALocalRun/ 343 | 344 | # MSBuild Binary and Structured Log 345 | *.binlog 346 | 347 | # NVidia Nsight GPU debugger configuration file 348 | *.nvuser 349 | 350 | # MFractors (Xamarin productivity tool) working folder 351 | .mfractor/ 352 | 353 | # Local History for Visual Studio 354 | .localhistory/ 355 | 356 | # BeatPulse healthcheck temp database 357 | healthchecksdb 358 | 359 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 360 | MigrationBackup/ 361 | 362 | # Ionide (cross platform F# VS Code tools) working folder 363 | .ionide/ 364 | 365 | # Fody - auto-generated XML schema 366 | FodyWeavers.xsd 367 | 368 | # VS Code files for those working on multiple tools 369 | .vscode/* 370 | !.vscode/settings.json 371 | !.vscode/tasks.json 372 | !.vscode/launch.json 373 | !.vscode/extensions.json 374 | *.code-workspace 375 | 376 | # Local History for Visual Studio Code 377 | .history/ 378 | 379 | # Windows Installer files from build outputs 380 | *.cab 381 | *.msi 382 | *.msix 383 | *.msm 384 | *.msp 385 | 386 | # JetBrains Rider 387 | .idea/ 388 | *.sln.iml 389 | /docs 390 | /src/vcpkg_installed 391 | -------------------------------------------------------------------------------- /src/socksifier.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | $([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0')) 6 | 10.0 7 | $(WindowsTargetPlatformVersion) 8 | 9 | 10 | x86-windows-static 11 | x64-windows-static 12 | 13 | 14 | 15 | Debug 16 | Win32 17 | 18 | 19 | Release 20 | Win32 21 | 22 | 23 | Debug 24 | x64 25 | 26 | 27 | Release 28 | x64 29 | 30 | 31 | 32 | 15.0 33 | {B844F1AD-D2C4-4DB6-B312-81D40B10DC17} 34 | Win32Proj 35 | 36 | 37 | 38 | DynamicLibrary 39 | true 40 | v143 41 | 42 | 43 | DynamicLibrary 44 | false 45 | v143 46 | 47 | 48 | DynamicLibrary 49 | true 50 | v143 51 | 52 | 53 | DynamicLibrary 54 | false 55 | v143 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | true 77 | $(SolutionDir)bin\$(PlatformShortName)\ 78 | $(ProjectName)_$(PlatformShortName) 79 | 80 | 81 | true 82 | $(SolutionDir)bin\$(PlatformShortName)\ 83 | $(ProjectName)_$(PlatformShortName) 84 | 85 | 86 | $(SolutionDir)bin\$(PlatformShortName)\ 87 | $(ProjectName)_$(PlatformShortName) 88 | 89 | 90 | $(SolutionDir)bin\$(PlatformShortName)\ 91 | $(ProjectName)_$(PlatformShortName) 92 | 93 | 94 | true 95 | 96 | 97 | true 98 | 99 | 100 | true 101 | 102 | 103 | 104 | WIN32;_DEBUG;_WINDOWS;_USRDLL;SOCKSIFIER_EXPORTS;%(PreprocessorDefinitions) 105 | MultiThreadedDebug 106 | Level3 107 | ProgramDatabase 108 | Disabled 109 | stdcpp17 110 | 111 | 112 | MachineX86 113 | true 114 | Windows 115 | 116 | 117 | 118 | 119 | WIN32;NDEBUG;_WINDOWS;_USRDLL;SOCKSIFIER_EXPORTS;%(PreprocessorDefinitions) 120 | MultiThreaded 121 | Level3 122 | ProgramDatabase 123 | stdcpp17 124 | 125 | 126 | MachineX86 127 | true 128 | Windows 129 | true 130 | true 131 | 132 | 133 | 134 | 135 | MultiThreadedDebug 136 | stdcpp17 137 | 138 | 139 | 140 | 141 | MultiThreaded 142 | stdcpp17 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /src/socksifier.cpp: -------------------------------------------------------------------------------- 1 | #include "socksifier.h" 2 | 3 | #include 4 | 5 | #pragma comment(lib, "Ws2_32.lib") 6 | 7 | #pragma region Detoured function definitions 8 | 9 | EXTERN_C_START 10 | 11 | int (WINAPI* real_connect)(SOCKET s, const struct sockaddr* name, int namelen) = connect; 12 | 13 | int (WINAPI* real_bind)( 14 | SOCKET s, 15 | const sockaddr* addr, 16 | int namelen 17 | ) = bind; 18 | 19 | int (WINAPI* real_WSASendTo)( 20 | SOCKET s, 21 | LPWSABUF lpBuffers, 22 | DWORD dwBufferCount, 23 | LPDWORD lpNumberOfBytesSent, 24 | DWORD dwFlags, 25 | const sockaddr* lpTo, 26 | int iTolen, 27 | LPWSAOVERLAPPED lpOverlapped, 28 | LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine 29 | ) = WSASendTo; 30 | 31 | int (WINAPI* real_WSARecvFrom)( 32 | SOCKET s, 33 | LPWSABUF lpBuffers, 34 | DWORD dwBufferCount, 35 | LPDWORD lpNumberOfBytesRecvd, 36 | LPDWORD lpFlags, 37 | sockaddr* lpFrom, 38 | LPINT lpFromlen, 39 | LPWSAOVERLAPPED lpOverlapped, 40 | LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine 41 | ) = WSARecvFrom; 42 | 43 | int (WINAPI* real_closesocket)( 44 | SOCKET s 45 | ) = closesocket; 46 | 47 | EXTERN_C_END 48 | 49 | #pragma endregion 50 | 51 | #pragma region Global objects 52 | 53 | setting_t g_Settings; 54 | 55 | std::map g_UdpRoutingMap; 56 | 57 | LPFN_CONNECTEX ConnectExPtr = nullptr; 58 | 59 | #pragma endregion 60 | 61 | 62 | // 63 | // Hooks https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect 64 | // 65 | int WINAPI my_connect(SOCKET s, const struct sockaddr* name, int namelen) 66 | { 67 | const auto logger = spdlog::get("socksifier")->clone("socksifier.connect"); 68 | 69 | logger->debug("my_connect called"); 70 | 71 | // 72 | // One-time initialization 73 | // 74 | static std::once_flag flag; 75 | std::call_once(flag, [&sock = s]() 76 | { 77 | const auto logger = spdlog::get("socksifier")->clone("socksifier.connect"); 78 | logger->info("Requesting pointer to ConnectEx()"); 79 | 80 | DWORD numBytes = 0; 81 | GUID guid = WSAID_CONNECTEX; 82 | 83 | // 84 | // Request ConnectEx function pointer 85 | // 86 | const auto ret = WSAIoctl( 87 | sock, 88 | SIO_GET_EXTENSION_FUNCTION_POINTER, 89 | static_cast(&guid), 90 | sizeof(guid), 91 | static_cast(&ConnectExPtr), 92 | sizeof(ConnectExPtr), 93 | &numBytes, 94 | nullptr, 95 | nullptr 96 | ); 97 | 98 | if (!ret) 99 | { 100 | logger->info("ConnectEx() pointer acquired"); 101 | } 102 | else 103 | { 104 | logger->error("Failed to retrieve ConnectEx() pointer, error: {}", WSAGetLastError()); 105 | ConnectExPtr = nullptr; 106 | } 107 | }); 108 | 109 | const struct sockaddr_in* dest = (const struct sockaddr_in*)name; 110 | 111 | char addr[INET_ADDRSTRLEN]; 112 | inet_ntop(AF_INET, &(dest->sin_addr), addr, INET_ADDRSTRLEN); 113 | const auto dest_port = ntohs(dest->sin_port); 114 | 115 | // 116 | // These destinations we don't usually wanna proxy 117 | // 118 | if (ConnectExPtr == nullptr || !strcmp(addr, "127.0.0.1") || !strcmp(addr, "0.0.0.0")) 119 | { 120 | return real_connect(s, name, namelen); 121 | } 122 | 123 | logger->info("Original connect destination: {}:{}", addr, dest_port); 124 | 125 | struct sockaddr_in proxy; 126 | proxy.sin_addr.s_addr = g_Settings.proxy_address; 127 | proxy.sin_family = AF_INET; 128 | proxy.sin_port = g_Settings.proxy_port; 129 | 130 | inet_ntop(AF_INET, &(proxy.sin_addr), addr, INET_ADDRSTRLEN); 131 | logger->info("Connecting to SOCKS proxy: {}:{}", addr, ntohs(proxy.sin_port)); 132 | 133 | // 134 | // This handles non-blocking socket connections via extended Winsock API 135 | // 136 | if (BindAndConnectExSync( 137 | s, 138 | reinterpret_cast(&proxy), 139 | sizeof(proxy) 140 | )) 141 | { 142 | logger->debug("Proxy connection established"); 143 | } 144 | else 145 | { 146 | logger->error("Proxy connection failed"); 147 | LogWSAError(); 148 | return SOCKET_ERROR; 149 | } 150 | 151 | // 152 | // Prepare greeting payload 153 | // 154 | char greetProxy[3]; 155 | greetProxy[0] = 0x05; // Version (always 0x05) 156 | greetProxy[1] = 0x01; // Number of authentication methods 157 | greetProxy[2] = 0x00; // NO AUTHENTICATION REQUIRED 158 | 159 | logger->debug("Sending greeting to proxy"); 160 | 161 | if (WSASendSync(s, greetProxy, sizeof(greetProxy))) 162 | { 163 | char response[2] = {0}; 164 | 165 | if (WSARecvSync(s, response, sizeof(response)) 166 | && response[0] == 0x05 /* expected version */ 167 | && response[1] == 0x00 /* success value */) 168 | { 169 | logger->debug("Proxy accepted greeting without authentication"); 170 | } 171 | else 172 | { 173 | logger->error("Proxy greeting failed"); 174 | LogWSAError(); 175 | return SOCKET_ERROR; 176 | } 177 | } 178 | else 179 | { 180 | logger->error("Failed to greet SOCKS proxy server"); 181 | LogWSAError(); 182 | return SOCKET_ERROR; 183 | } 184 | 185 | // 186 | // Prepare remote connect request 187 | // 188 | char remoteBind[10]; 189 | remoteBind[0] = 0x05; // Version (always 0x05) 190 | remoteBind[1] = 0x01; // Connect command 191 | remoteBind[2] = 0x00; // Reserved 192 | remoteBind[3] = 0x01; // Type (IP V4 address) 193 | remoteBind[4] = (dest->sin_addr.s_addr >> 0) & 0xFF; 194 | remoteBind[5] = (dest->sin_addr.s_addr >> 8) & 0xFF; 195 | remoteBind[6] = (dest->sin_addr.s_addr >> 16) & 0xFF; 196 | remoteBind[7] = (dest->sin_addr.s_addr >> 24) & 0xFF; 197 | remoteBind[8] = (dest->sin_port >> 0) & 0xFF; 198 | remoteBind[9] = (dest->sin_port >> 8) & 0xFF; 199 | 200 | logger->debug("Sending connect request to proxy"); 201 | 202 | if (WSASendSync(s, remoteBind, sizeof(remoteBind))) 203 | { 204 | char response[10] = {0}; 205 | 206 | if (WSARecvSync(s, response, sizeof(response)) 207 | && response[1] == 0x00 /* success value */) 208 | { 209 | logger->info("Remote connection established"); 210 | } 211 | else 212 | { 213 | logger->error("Consuming proxy response failed"); 214 | LogWSAError(); 215 | return SOCKET_ERROR; 216 | } 217 | } 218 | else 219 | { 220 | logger->error("Failed to instruct proxy to remote connect"); 221 | LogWSAError(); 222 | return SOCKET_ERROR; 223 | } 224 | 225 | return ERROR_SUCCESS; 226 | } 227 | 228 | // 229 | // Hooks https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-bind 230 | // 231 | int WINAPI my_bind( 232 | SOCKET s, 233 | const sockaddr* addr, 234 | int namelen 235 | ) 236 | { 237 | const auto logger = spdlog::get("socksifier")->clone("socksifier.bind"); 238 | 239 | logger->debug("my_bind called ({})", s); 240 | 241 | int optType = -1; 242 | int optLen = sizeof(int); 243 | 244 | // 245 | // We need to know the socket type 246 | // 247 | if (getsockopt(s, SOL_SOCKET, SO_TYPE, reinterpret_cast(&optType), &optLen) != 0) 248 | return real_bind(s, addr, namelen); 249 | 250 | const struct sockaddr_in* dest = (const struct sockaddr_in*)addr; 251 | 252 | // 253 | // Not of interest to intercept 254 | // 255 | if (optType != SOCK_DGRAM || g_UdpRoutingMap.count(s)) 256 | return real_bind(s, addr, namelen); 257 | 258 | logger->info("Binding UDP socket, tracking socket handle"); 259 | 260 | SOCKET sTun = INVALID_SOCKET; 261 | 262 | do 263 | { 264 | // 265 | // Create and bind temporary TCP socket for SOCKS5 handshake 266 | // 267 | 268 | sTun = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 269 | 270 | if (sTun == INVALID_SOCKET) 271 | { 272 | logger->error("socket failed: {}", WSAGetLastError()); 273 | LogWSAError(); 274 | break; 275 | } 276 | 277 | SOCKADDR_IN tbAddr; 278 | ZeroMemory(&tbAddr, sizeof(tbAddr)); 279 | tbAddr.sin_family = AF_INET; 280 | tbAddr.sin_addr.s_addr = INADDR_ANY; // Any 281 | tbAddr.sin_port = 0; // Any 282 | 283 | auto rc = real_bind(sTun, reinterpret_cast(&tbAddr), sizeof(tbAddr)); 284 | 285 | if (rc != 0) 286 | { 287 | logger->error("bind failed: {}", WSAGetLastError()); 288 | LogWSAError(); 289 | break; 290 | } 291 | 292 | SOCKADDR_IN proxy; 293 | proxy.sin_addr.s_addr = g_Settings.proxy_address; 294 | proxy.sin_family = AF_INET; 295 | proxy.sin_port = g_Settings.proxy_port; 296 | 297 | rc = real_connect(sTun, reinterpret_cast(&proxy), sizeof(proxy)); 298 | 299 | if (rc != 0) 300 | { 301 | logger->error("connect failed: {}", WSAGetLastError()); 302 | LogWSAError(); 303 | break; 304 | } 305 | 306 | // 307 | // Prepare greeting payload 308 | // 309 | char greetProxy[3]; 310 | greetProxy[0] = 0x05; // Version (always 0x05) 311 | greetProxy[1] = 0x01; // Number of authentication methods 312 | greetProxy[2] = 0x00; // NO AUTHENTICATION REQUIRED 313 | 314 | logger->debug("Sending greeting to proxy"); 315 | 316 | if (send(sTun, greetProxy, sizeof(greetProxy), 0) != sizeof(greetProxy)) 317 | { 318 | logger->error("Proxy greeting failed"); 319 | LogWSAError(); 320 | break; 321 | } 322 | 323 | char response[2] = {0}; 324 | 325 | if (recv(sTun, response, sizeof(response), 0) 326 | && response[0] == 0x05 /* expected version */ 327 | && response[1] == 0x00 /* success value */) 328 | { 329 | logger->debug("Proxy accepted greeting without authentication"); 330 | } 331 | else 332 | { 333 | logger->error("Proxy greeting failed"); 334 | LogWSAError(); 335 | break; 336 | } 337 | 338 | // 339 | // Prepare remote connect request 340 | // 341 | char udpAssociate[10]; 342 | ZeroMemory(udpAssociate, ARRAYSIZE(udpAssociate)); 343 | udpAssociate[0] = 0x05; // Version (always 0x05) 344 | udpAssociate[1] = 0x03; // UDP ASSOCIATE command 345 | udpAssociate[2] = 0x00; // Reserved 346 | udpAssociate[3] = 0x01; // Type (IP V4 address) 347 | // 348 | // TODO: this doesn't really matter, as Shadowsocks uses 349 | // the encapsulated UDP header to determine the real 350 | // remote endpoint to use. 351 | // 352 | udpAssociate[4] = (dest->sin_addr.s_addr >> 0) & 0xFF; 353 | udpAssociate[5] = (dest->sin_addr.s_addr >> 8) & 0xFF; 354 | udpAssociate[6] = (dest->sin_addr.s_addr >> 16) & 0xFF; 355 | udpAssociate[7] = (dest->sin_addr.s_addr >> 24) & 0xFF; 356 | udpAssociate[8] = (dest->sin_port >> 0) & 0xFF; 357 | udpAssociate[9] = (dest->sin_port >> 8) & 0xFF; 358 | 359 | logger->debug("Sending UDP ASSOCIATE to proxy"); 360 | 361 | // 362 | // Request UDP relay endpoint 363 | // 364 | if (send(sTun, udpAssociate, sizeof(udpAssociate), 0) != sizeof(udpAssociate)) 365 | { 366 | logger->error("UDP ASSOCIATE failed"); 367 | LogWSAError(); 368 | break; 369 | } 370 | 371 | char udpAssociateResp[10] = {0}; 372 | 373 | // 374 | // Parse response, contains endpoint 375 | // 376 | if (recv(sTun, udpAssociateResp, sizeof(udpAssociateResp), 0) 377 | && response[1] == 0x00 /* success value */) 378 | { 379 | // 380 | // This is the endpoint the UDP relay is listening on 381 | // 382 | SOCKADDR_IN udpEndpoint; 383 | udpEndpoint.sin_addr.s_addr = ( 384 | udpAssociateResp[4] << 0 | 385 | udpAssociateResp[5] << 8 | 386 | udpAssociateResp[6] << 16 | 387 | udpAssociateResp[7] << 24 388 | ); 389 | udpEndpoint.sin_port = (udpAssociateResp[8] << 0 | udpAssociateResp[9] << 8); 390 | udpEndpoint.sin_family = dest->sin_family; 391 | 392 | char address[INET_ADDRSTRLEN]; 393 | inet_ntop(AF_INET, &(udpEndpoint.sin_addr), address, INET_ADDRSTRLEN); 394 | const auto dest_port = ntohs(udpEndpoint.sin_port); 395 | 396 | logger->info("Received UDP relay endpoint {}:{} for socket {}", 397 | address, dest_port, s); 398 | 399 | // 400 | // Keep track to start forwarding in my_WSASendTo 401 | // 402 | g_UdpRoutingMap.insert(std::pair(s, udpEndpoint)); 403 | } 404 | else 405 | { 406 | logger->error("UDP ASSOCIATE response failed"); 407 | LogWSAError(); 408 | break; 409 | } 410 | } 411 | while (FALSE); 412 | 413 | // 414 | // Not required anymore after we got the new endpoint 415 | // 416 | if (sTun != INVALID_SOCKET) 417 | real_closesocket(sTun); 418 | 419 | return real_bind(s, addr, namelen); 420 | } 421 | 422 | // 423 | // Hooks https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendto 424 | // 425 | int WINAPI my_WSASendTo( 426 | SOCKET s, 427 | LPWSABUF lpBuffers, 428 | DWORD dwBufferCount, 429 | LPDWORD lpNumberOfBytesSent, 430 | DWORD dwFlags, 431 | const sockaddr* lpTo, 432 | int iTolen, 433 | LPWSAOVERLAPPED lpOverlapped, 434 | LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine 435 | ) 436 | { 437 | const auto logger = spdlog::get("socksifier")->clone("socksifier.udp.WSASendTo"); 438 | 439 | const PSOCKADDR_IN dest = (PSOCKADDR_IN)lpTo; 440 | 441 | do 442 | { 443 | // 444 | // TCP tunnel through SOCKS5 exists for this socket 445 | // 446 | if (!g_UdpRoutingMap.count(s)) 447 | break; 448 | 449 | const PSOCKADDR_IN sTun = &g_UdpRoutingMap[s]; 450 | WSABUF destBuffer; 451 | DWORD num; 452 | 453 | // 454 | // Allocate new buffer with enough space for additional origin header 455 | // 456 | destBuffer.len = lpBuffers->len + 10; 457 | destBuffer.buf = static_cast(malloc(destBuffer.len)); 458 | 459 | if (destBuffer.buf == nullptr) 460 | break; 461 | 462 | ZeroMemory(destBuffer.buf, destBuffer.len); 463 | 464 | destBuffer.buf[3] = 0x01; // IP V4 address 465 | destBuffer.buf[4] = (dest->sin_addr.s_addr >> 0) & 0xFF; 466 | destBuffer.buf[5] = (dest->sin_addr.s_addr >> 8) & 0xFF; 467 | destBuffer.buf[6] = (dest->sin_addr.s_addr >> 16) & 0xFF; 468 | destBuffer.buf[7] = (dest->sin_addr.s_addr >> 24) & 0xFF; 469 | destBuffer.buf[8] = (dest->sin_port >> 0) & 0xFF; 470 | destBuffer.buf[9] = (dest->sin_port >> 8) & 0xFF; 471 | 472 | memcpy(&destBuffer.buf[10], lpBuffers->buf, lpBuffers->len); 473 | 474 | char originAddr[INET_ADDRSTRLEN], relayAddr[INET_ADDRSTRLEN]; 475 | inet_ntop(AF_INET, &(dest->sin_addr), originAddr, INET_ADDRSTRLEN); 476 | inet_ntop(AF_INET, &(sTun->sin_addr), relayAddr, INET_ADDRSTRLEN); 477 | 478 | logger->debug("Relaying UDP packet for {}:{} to {}:{}", 479 | originAddr, ntohs(dest->sin_port), relayAddr, ntohs(sTun->sin_port)); 480 | 481 | const auto ret = real_WSASendTo( 482 | s, 483 | &destBuffer, 484 | 1, 485 | &num, 486 | 0, 487 | reinterpret_cast(sTun), 488 | sizeof(*sTun), 489 | lpOverlapped, 490 | lpCompletionRoutine 491 | ); 492 | 493 | free(destBuffer.buf); 494 | return ret; 495 | } 496 | while (FALSE); 497 | 498 | char addr[INET_ADDRSTRLEN]; 499 | inet_ntop(AF_INET, &(dest->sin_addr), addr, INET_ADDRSTRLEN); 500 | const auto dest_port = ntohs(dest->sin_port); 501 | 502 | logger->debug("Sending packet to origin {}:{}", addr, dest_port); 503 | 504 | return real_WSASendTo( 505 | s, 506 | lpBuffers, 507 | dwBufferCount, 508 | lpNumberOfBytesSent, 509 | dwFlags, 510 | lpTo, 511 | iTolen, 512 | lpOverlapped, 513 | lpCompletionRoutine 514 | ); 515 | } 516 | 517 | // 518 | // Hooks https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsarecvfrom 519 | // 520 | int WINAPI my_WSARecvFrom( 521 | SOCKET s, 522 | LPWSABUF lpBuffers, 523 | DWORD dwBufferCount, 524 | LPDWORD lpNumberOfBytesRecvd, 525 | LPDWORD lpFlags, 526 | sockaddr* lpFrom, 527 | LPINT lpFromlen, 528 | LPWSAOVERLAPPED lpOverlapped, 529 | LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine 530 | ) 531 | { 532 | const auto logger = spdlog::get("socksifier")->clone("socksifier.udp.WSARecvFrom"); 533 | 534 | const struct sockaddr_in* dest = (const struct sockaddr_in*)lpFrom; 535 | 536 | char addr[INET_ADDRSTRLEN]; 537 | inet_ntop(AF_INET, &(dest->sin_addr), addr, INET_ADDRSTRLEN); 538 | const auto dest_port = ntohs(dest->sin_port); 539 | 540 | logger->debug("Received UDP packet from {}:{}", addr, dest_port); 541 | 542 | // 543 | // TODO: better error checking, works with CEF (as of now) 544 | // 545 | const auto ret = real_WSARecvFrom( 546 | s, 547 | lpBuffers, 548 | dwBufferCount, 549 | lpNumberOfBytesRecvd, 550 | lpFlags, 551 | lpFrom, 552 | lpFromlen, 553 | lpOverlapped, 554 | lpCompletionRoutine 555 | ); 556 | 557 | do 558 | { 559 | if (!g_UdpRoutingMap.count(s)) 560 | break; 561 | 562 | logger->debug("Relayed socket, stripping UDP header"); 563 | 564 | #ifdef _DEBUG 565 | const std::vector aBuffer(lpBuffers->buf, lpBuffers->buf + *lpNumberOfBytesRecvd); 566 | logger->debug("({:04d}) -> {:Xpn}", 567 | *lpNumberOfBytesRecvd, 568 | spdlog::to_hex(aBuffer) 569 | ); 570 | #endif 571 | 572 | SOCKADDR_IN originEndpoint; 573 | originEndpoint.sin_addr.s_addr = ( 574 | lpBuffers->buf[4] << 0 | 575 | lpBuffers->buf[5] << 8 | 576 | lpBuffers->buf[6] << 16 | 577 | lpBuffers->buf[7] << 24 578 | ); 579 | originEndpoint.sin_port = (lpBuffers->buf[8] << 0 | lpBuffers->buf[9] << 8); 580 | 581 | char originAddress[INET_ADDRSTRLEN]; 582 | inet_ntop(AF_INET, &(originEndpoint.sin_addr), originAddress, INET_ADDRSTRLEN); 583 | const auto originPort = ntohs(originEndpoint.sin_port); 584 | 585 | logger->debug("Received UDP packet from origin endpoint {}:{}", 586 | originAddress, originPort); 587 | 588 | // 589 | // Skip the UDP encapsulation header and adjust packet size 590 | // 591 | memmove(lpBuffers->buf, &lpBuffers->buf[10], *lpNumberOfBytesRecvd -= 10); 592 | 593 | #ifdef _DEBUG 594 | const std::vector bBuffer(lpBuffers->buf, lpBuffers->buf + *lpNumberOfBytesRecvd); 595 | logger->debug("({:04d}) -> {:Xpn}", 596 | *lpNumberOfBytesRecvd, 597 | spdlog::to_hex(bBuffer) 598 | ); 599 | #endif 600 | } 601 | while (FALSE); 602 | 603 | return ret; 604 | } 605 | 606 | // 607 | // Hooks https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-closesocket 608 | // 609 | int WINAPI my_closesocket( 610 | SOCKET s 611 | ) 612 | { 613 | const auto logger = spdlog::get("socksifier")->clone("socksifier.closesocket"); 614 | 615 | logger->debug("my_closesocket called"); 616 | 617 | // 618 | // Clean up invalidated handle 619 | // 620 | g_UdpRoutingMap.erase(s); 621 | 622 | return real_closesocket(s); 623 | } 624 | 625 | 626 | // 627 | // Finds and kills existing TCP connections within this process 628 | // 629 | DWORD WINAPI SocketEnumMainThread(LPVOID Params) 630 | { 631 | UNREFERENCED_PARAMETER(Params); 632 | 633 | const auto logger = spdlog::get("socksifier")->clone("socksifier.SocketEnumMainThread"); 634 | auto pid = GetCurrentProcessId(); 635 | 636 | logger->info("Attempting to reap open TCP connections for PID {}", pid); 637 | 638 | WSAPROTOCOL_INFOW wsaProtocolInfo = {0}; 639 | 640 | const auto pNTQSI = reinterpret_cast(GetProcAddress( 641 | GetModuleHandle("NTDLL.DLL"), 642 | "NtQuerySystemInformation" 643 | )); 644 | 645 | if (pNTQSI == nullptr) 646 | { 647 | logger->error("Failed to acquire NtQuerySystemInformation API"); 648 | return 1; 649 | } 650 | 651 | DWORD dwSize = sizeof(SYSTEM_HANDLE_INFORMATION); 652 | 653 | auto* pHandleInfo = reinterpret_cast(new BYTE[dwSize]); 654 | 655 | NTSTATUS ntReturn = pNTQSI(SystemHandleInformation, pHandleInfo, dwSize, &dwSize); 656 | 657 | // 658 | // Get required buffer size for all handle meta-data 659 | // 660 | while (ntReturn == STATUS_INFO_LENGTH_MISMATCH) 661 | { 662 | delete pHandleInfo; 663 | 664 | // 665 | // The handle count can change between these calls, so just 666 | // allocate a bit more memory and it should be fine! 667 | // 668 | dwSize += 1024; 669 | 670 | pHandleInfo = (PSYSTEM_HANDLE_INFORMATION)new BYTE[dwSize]; 671 | 672 | ntReturn = pNTQSI(SystemHandleInformation, pHandleInfo, dwSize, &dwSize); 673 | } 674 | 675 | if (ntReturn != STATUS_SUCCESS) 676 | { 677 | logger->error("NtQuerySystemInformation failed with status {}", ntReturn); 678 | return 1; 679 | } 680 | 681 | // 682 | // Walk all handles 683 | // 684 | for (DWORD dwIdx = 0; dwIdx < pHandleInfo->NumberOfHandles; dwIdx++) 685 | { 686 | const PSYSTEM_HANDLE_TABLE_ENTRY_INFO pEntry = &pHandleInfo->Handles[dwIdx]; 687 | 688 | // 689 | // Skip processes other than ours 690 | // 691 | if (pEntry->UniqueProcessId != pid) 692 | continue; 693 | 694 | auto* handle = reinterpret_cast(pHandleInfo->Handles[dwIdx].HandleValue); 695 | 696 | // 697 | // Attempt to get object name 698 | // 699 | LPCWSTR objectName = GetObjectName(handle); 700 | 701 | if (objectName == nullptr) 702 | continue; 703 | 704 | // 705 | // Check if handle belongs to "Ancillary Function Driver" (network stack) 706 | // 707 | if (wcscmp(objectName, L"\\Device\\Afd") != 0) 708 | { 709 | delete objectName; 710 | continue; 711 | } 712 | 713 | delete objectName; 714 | 715 | logger->info("Found open socket, identifying"); 716 | 717 | int optType = -1; 718 | int optLen = sizeof(int); 719 | 720 | // 721 | // We need to know the socket type; don't terminate UDP 722 | // 723 | if (getsockopt( 724 | reinterpret_cast(handle), 725 | SOL_SOCKET, 726 | SO_TYPE, 727 | reinterpret_cast(&optType), &optLen) != 0 728 | ) 729 | { 730 | logger->warn("Failed to get socket type, moving on"); 731 | LogWSAError(); 732 | continue; 733 | } 734 | 735 | if (optType == SOCK_DGRAM) 736 | { 737 | logger->info("Handle belongs to UDP socket, skipping"); 738 | continue; 739 | } 740 | 741 | // 742 | // Duplication is both a validity check and useful for logging 743 | // 744 | const NTSTATUS status = WSADuplicateSocketW( 745 | reinterpret_cast(handle), 746 | GetCurrentProcessId(), 747 | &wsaProtocolInfo 748 | ); 749 | 750 | if (status != STATUS_SUCCESS) 751 | { 752 | // 753 | // Not a socket handle, ignore 754 | // 755 | if (WSAGetLastError() == WSAENOTSOCK) 756 | continue; 757 | 758 | logger->warn("Couldn't duplicate, moving on"); 759 | LogWSAError(); // For diagnostics, ignore otherwise 760 | continue; 761 | } 762 | 763 | // 764 | // Create new duplicated socket 765 | // 766 | const SOCKET targetSocket = WSASocketW( 767 | wsaProtocolInfo.iAddressFamily, 768 | wsaProtocolInfo.iSocketType, 769 | wsaProtocolInfo.iProtocol, 770 | &wsaProtocolInfo, 771 | 0, 772 | WSA_FLAG_OVERLAPPED 773 | ); 774 | 775 | if (targetSocket != INVALID_SOCKET) 776 | { 777 | struct sockaddr_in sockaddr; 778 | int len = sizeof(SOCKADDR_IN); 779 | 780 | // 781 | // This call should succeed now 782 | // 783 | if (getpeername(targetSocket, reinterpret_cast(&sockaddr), &len) == 0) 784 | { 785 | char addr[INET_ADDRSTRLEN]; 786 | ZeroMemory(addr, ARRAYSIZE(addr)); 787 | inet_ntop(AF_INET, &(sockaddr.sin_addr), addr, INET_ADDRSTRLEN); 788 | 789 | logger->info("Duplicated socket {}, closing", addr); 790 | 791 | // 792 | // Close duplicate 793 | // 794 | real_closesocket(targetSocket); 795 | 796 | // 797 | // Terminate original socket 798 | // 799 | CloseHandle(handle); 800 | } 801 | else LogWSAError(); // For diagnostics, ignore otherwise 802 | } 803 | else LogWSAError(); // For diagnostics, ignore otherwise 804 | } 805 | 806 | delete pHandleInfo; 807 | 808 | return 0; 809 | } 810 | 811 | // 812 | // Main DLL entry point 813 | // 814 | BOOL WINAPI DllMain(HINSTANCE dll_handle, DWORD reason, LPVOID reserved) 815 | { 816 | if (DetourIsHelperProcess()) 817 | { 818 | return TRUE; 819 | } 820 | 821 | switch (reason) 822 | { 823 | case DLL_PROCESS_ATTACH: 824 | 825 | { 826 | // 827 | // Observe best with https://github.com/CobaltFusion/DebugViewPP 828 | // 829 | auto sink = std::make_shared(); 830 | #ifdef _DEBUG 831 | sink->set_level(spdlog::level::debug); 832 | #else 833 | sink->set_level(spdlog::level::info); 834 | #endif 835 | 836 | auto logger = std::make_shared("socksifier", sink); 837 | 838 | #ifdef _DEBUG 839 | logger->set_level(spdlog::level::debug); 840 | #else 841 | logger->set_level(spdlog::level::info); 842 | #endif 843 | 844 | logger->flush_on(spdlog::level::info); 845 | 846 | set_default_logger(logger); 847 | 848 | // 849 | // Default values 850 | // 851 | CHAR addressVar[MAX_PATH] = "127.0.0.1"; 852 | CHAR portVar[MAX_PATH] = "1080"; 853 | 854 | // 855 | // Optional variables 856 | // 857 | GetEnvironmentVariableA("SOCKSIFIER_ADDRESS", addressVar, ARRAYSIZE(addressVar)); 858 | GetEnvironmentVariableA("SOCKSIFIER_PORT", portVar, ARRAYSIZE(portVar)); 859 | 860 | inet_pton(AF_INET, addressVar, &g_Settings.proxy_address); 861 | g_Settings.proxy_port = _byteswap_ushort(static_cast(strtol(portVar, nullptr, 10))); 862 | 863 | spdlog::info("Using SOCKS proxy: {}:{}", addressVar, portVar); 864 | } 865 | 866 | DisableThreadLibraryCalls(dll_handle); 867 | DetourRestoreAfterWith(); 868 | 869 | DetourTransactionBegin(); 870 | DetourUpdateThread(GetCurrentThread()); 871 | DetourAttach(&static_cast(real_connect), my_connect); 872 | DetourAttach(&static_cast(real_bind), my_bind); 873 | DetourAttach(&static_cast(real_WSASendTo), my_WSASendTo); 874 | DetourAttach(&static_cast(real_WSARecvFrom), my_WSARecvFrom); 875 | DetourAttach(&static_cast(real_closesocket), my_closesocket); 876 | DetourTransactionCommit(); 877 | 878 | // 879 | // Start socket enumeration in new thread 880 | // 881 | CreateThread( 882 | nullptr, 883 | 0, 884 | reinterpret_cast(SocketEnumMainThread), 885 | nullptr, 886 | 0, 887 | nullptr 888 | ); 889 | 890 | break; 891 | 892 | case DLL_PROCESS_DETACH: 893 | 894 | spdlog::info("Detaching from process with PID {}", GetCurrentProcessId()); 895 | 896 | DetourTransactionBegin(); 897 | DetourUpdateThread(GetCurrentThread()); 898 | DetourDetach(&static_cast(real_connect), my_connect); 899 | DetourDetach(&static_cast(real_bind), my_bind); 900 | DetourDetach(&static_cast(real_WSASendTo), my_WSASendTo); 901 | DetourDetach(&static_cast(real_WSARecvFrom), my_WSARecvFrom); 902 | DetourDetach(&static_cast(real_closesocket), my_closesocket); 903 | DetourTransactionCommit(); 904 | break; 905 | } 906 | return TRUE; 907 | } 908 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /src/NtApi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | // http://www.exploit-monday.com/2013/06/undocumented-ntquerysysteminformation.html 5 | 6 | // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 7 | 8 | 9 | enum _SYSTEM_INFORMATION_CLASS 10 | { 11 | SystemBasicInformation = 0x0000, 12 | SystemProcessorInformation = 0x0001, 13 | SystemPerformanceInformation = 0x0002, 14 | SystemTimeOfDayInformation = 0x0003, 15 | SystemPathInformation = 0x0004, 16 | SystemProcessInformation = 0x0005, 17 | SystemCallCountInformation = 0x0006, 18 | SystemDeviceInformation = 0x0007, 19 | SystemProcessorPerformanceInformation = 0x0008, 20 | SystemFlagsInformation = 0x0009, 21 | SystemCallTimeInformation = 0x000A, 22 | SystemModuleInformation = 0x000B, 23 | SystemLocksInformation = 0x000C, 24 | SystemStackTraceInformation = 0x000D, 25 | SystemPagedPoolInformation = 0x000E, 26 | SystemNonPagedPoolInformation = 0x000F, 27 | SystemHandleInformation = 0x0010, 28 | SystemObjectInformation = 0x0011, 29 | SystemPageFileInformation = 0x0012, 30 | SystemVdmInstemulInformation = 0x0013, 31 | SystemVdmBopInformation = 0x0014, 32 | SystemFileCacheInformation = 0x0015, 33 | SystemPoolTagInformation = 0x0016, 34 | SystemInterruptInformation = 0x0017, 35 | SystemDpcBehaviorInformation = 0x0018, 36 | SystemFullMemoryInformation = 0x0019, 37 | SystemLoadGdiDriverInformation = 0x001A, 38 | SystemUnloadGdiDriverInformation = 0x001B, 39 | SystemTimeAdjustmentInformation = 0x001C, 40 | SystemSummaryMemoryInformation = 0x001D, 41 | SystemMirrorMemoryInformation = 0x001E, 42 | SystemPerformanceTraceInformation = 0x001F, 43 | SystemCrashDumpInformation = 0x0020, 44 | SystemExceptionInformation = 0x0021, 45 | SystemCrashDumpStateInformation = 0x0022, 46 | SystemKernelDebuggerInformation = 0x0023, 47 | SystemContextSwitchInformation = 0x0024, 48 | SystemRegistryQuotaInformation = 0x0025, 49 | SystemExtendServiceTableInformation = 0x0026, 50 | SystemPrioritySeperation = 0x0027, 51 | SystemVerifierAddDriverInformation = 0x0028, 52 | SystemVerifierRemoveDriverInformation = 0x0029, 53 | SystemProcessorIdleInformation = 0x002A, 54 | SystemLegacyDriverInformation = 0x002B, 55 | SystemCurrentTimeZoneInformation = 0x002C, 56 | SystemLookasideInformation = 0x002D, 57 | SystemTimeSlipNotification = 0x002E, 58 | SystemSessionCreate = 0x002F, 59 | SystemSessionDetach = 0x0030, 60 | SystemSessionInformation = 0x0031, 61 | SystemRangeStartInformation = 0x0032, 62 | SystemVerifierInformation = 0x0033, 63 | SystemVerifierThunkExtend = 0x0034, 64 | SystemSessionProcessInformation = 0x0035, 65 | SystemLoadGdiDriverInSystemSpace = 0x0036, 66 | SystemNumaProcessorMap = 0x0037, 67 | SystemPrefetcherInformation = 0x0038, 68 | SystemExtendedProcessInformation = 0x0039, 69 | SystemRecommendedSharedDataAlignment = 0x003A, 70 | SystemComPlusPackage = 0x003B, 71 | SystemNumaAvailableMemory = 0x003C, 72 | SystemProcessorPowerInformation = 0x003D, 73 | SystemEmulationBasicInformation = 0x003E, 74 | SystemEmulationProcessorInformation = 0x003F, 75 | SystemExtendedHandleInformation = 0x0040, 76 | SystemLostDelayedWriteInformation = 0x0041, 77 | SystemBigPoolInformation = 0x0042, 78 | SystemSessionPoolTagInformation = 0x0043, 79 | SystemSessionMappedViewInformation = 0x0044, 80 | SystemHotpatchInformation = 0x0045, 81 | SystemObjectSecurityMode = 0x0046, 82 | SystemWatchdogTimerHandler = 0x0047, 83 | SystemWatchdogTimerInformation = 0x0048, 84 | SystemLogicalProcessorInformation = 0x0049, 85 | SystemWow64SharedInformationObsolete = 0x004A, 86 | SystemRegisterFirmwareTableInformationHandler = 0x004B, 87 | SystemFirmwareTableInformation = 0x004C, 88 | SystemModuleInformationEx = 0x004D, 89 | SystemVerifierTriageInformation = 0x004E, 90 | SystemSuperfetchInformation = 0x004F, 91 | SystemMemoryListInformation = 0x0050, 92 | SystemFileCacheInformationEx = 0x0051, 93 | SystemThreadPriorityClientIdInformation = 0x0052, 94 | SystemProcessorIdleCycleTimeInformation = 0x0053, 95 | SystemVerifierCancellationInformation = 0x0054, 96 | SystemProcessorPowerInformationEx = 0x0055, 97 | SystemRefTraceInformation = 0x0056, 98 | SystemSpecialPoolInformation = 0x0057, 99 | SystemProcessIdInformation = 0x0058, 100 | SystemErrorPortInformation = 0x0059, 101 | SystemBootEnvironmentInformation = 0x005A, 102 | SystemHypervisorInformation = 0x005B, 103 | SystemVerifierInformationEx = 0x005C, 104 | SystemTimeZoneInformation = 0x005D, 105 | SystemImageFileExecutionOptionsInformation = 0x005E, 106 | SystemCoverageInformation = 0x005F, 107 | SystemPrefetchPatchInformation = 0x0060, 108 | SystemVerifierFaultsInformation = 0x0061, 109 | SystemSystemPartitionInformation = 0x0062, 110 | SystemSystemDiskInformation = 0x0063, 111 | SystemProcessorPerformanceDistribution = 0x0064, 112 | SystemNumaProximityNodeInformation = 0x0065, 113 | SystemDynamicTimeZoneInformation = 0x0066, 114 | SystemCodeIntegrityInformation = 0x0067, 115 | SystemProcessorMicrocodeUpdateInformation = 0x0068, 116 | SystemProcessorBrandString = 0x0069, 117 | SystemVirtualAddressInformation = 0x006A, 118 | SystemLogicalProcessorAndGroupInformation = 0x006B, 119 | SystemProcessorCycleTimeInformation = 0x006C, 120 | SystemStoreInformation = 0x006D, 121 | SystemRegistryAppendString = 0x006E, 122 | SystemAitSamplingValue = 0x006F, 123 | SystemVhdBootInformation = 0x0070, 124 | SystemCpuQuotaInformation = 0x0071, 125 | SystemNativeBasicInformation = 0x0072, 126 | SystemErrorPortTimeouts = 0x0073, 127 | SystemLowPriorityIoInformation = 0x0074, 128 | SystemBootEntropyInformation = 0x0075, 129 | SystemVerifierCountersInformation = 0x0076, 130 | SystemPagedPoolInformationEx = 0x0077, 131 | SystemSystemPtesInformationEx = 0x0078, 132 | SystemNodeDistanceInformation = 0x0079, 133 | SystemAcpiAuditInformation = 0x007A, 134 | SystemBasicPerformanceInformation = 0x007B, 135 | SystemQueryPerformanceCounterInformation = 0x007C, 136 | SystemSessionBigPoolInformation = 0x007D, 137 | SystemBootGraphicsInformation = 0x007E, 138 | SystemScrubPhysicalMemoryInformation = 0x007F, 139 | SystemBadPageInformation = 0x0080, 140 | SystemProcessorProfileControlArea = 0x0081, 141 | SystemCombinePhysicalMemoryInformation = 0x0082, 142 | SystemEntropyInterruptTimingInformation = 0x0083, 143 | SystemConsoleInformation = 0x0084, 144 | SystemPlatformBinaryInformation = 0x0085, 145 | SystemThrottleNotificationInformation = 0x0086, 146 | SystemHypervisorProcessorCountInformation = 0x0087, 147 | SystemDeviceDataInformation = 0x0088, 148 | SystemDeviceDataEnumerationInformation = 0x0089, 149 | SystemMemoryTopologyInformation = 0x008A, 150 | SystemMemoryChannelInformation = 0x008B, 151 | SystemBootLogoInformation = 0x008C, 152 | SystemProcessorPerformanceInformationEx = 0x008D, 153 | SystemSpare0 = 0x008E, 154 | SystemSecureBootPolicyInformation = 0x008F, 155 | SystemPageFileInformationEx = 0x0090, 156 | SystemSecureBootInformation = 0x0091, 157 | SystemEntropyInterruptTimingRawInformation = 0x0092, 158 | SystemPortableWorkspaceEfiLauncherInformation = 0x0093, 159 | SystemFullProcessInformation = 0x0094, 160 | MaxSystemInfoClass = 0x0095 161 | }; 162 | 163 | // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 164 | 165 | typedef struct _UNICODE_STRING { // Size = 8 166 | USHORT Length; // Size = 2 | Offset = 0 167 | USHORT MaximumLength; // Size = 2 | Offset = 2 168 | PWSTR Buffer; // Size = 4 | Offset = 4 169 | } UNICODE_STRING; 170 | typedef UNICODE_STRING* PUNICODE_STRING; 171 | typedef const UNICODE_STRING* PCUNICODE_STRING; 172 | 173 | 174 | struct _SYSTEM_BASIC_INFORMATION // Size = 44 175 | { 176 | ULONG Reserved; // Size = 4 | Offset = 0 177 | ULONG TimerResolution; // Size = 4 | Offset = 4 178 | ULONG PageSize; // Size = 4 | Offset = 8 179 | ULONG NumberOfPhysicalPages; // Size = 4 | Offset = 12 180 | ULONG LowestPhysicalPageNumber; // Size = 4 | Offset = 16 181 | ULONG HighestPhysicalPageNumber; // Size = 4 | Offset = 20 182 | ULONG AllocationGranularity; // Size = 4 | Offset = 24 183 | ULONG MinimumUserModeAddress; // Size = 4 | Offset = 28 184 | ULONG MaximumUserModeAddress; // Size = 4 | Offset = 32 185 | ULONG ActiveProcessorsAffinityMask; // Size = 4 | Offset = 36 186 | UCHAR NumberOfProcessors; // Size = 1 | Offset = 40 187 | }; 188 | 189 | struct _SYSTEM_PROCESSOR_INFORMATION // Size=12 190 | { 191 | USHORT ProcessorArchitecture; // Size=2 Offset=0 192 | USHORT ProcessorLevel; // Size=2 Offset=2 193 | USHORT ProcessorRevision; // Size=2 Offset=4 194 | USHORT MaximumProcessors; // Size=2 Offset=6 195 | ULONG ProcessorFeatureBits; // Size=4 Offset=8 196 | }; 197 | 198 | struct _SYSTEM_PERFORMANCE_INFORMATION // Size=344 199 | { 200 | LARGE_INTEGER IdleProcessTime; // Size=8 Offset=0 201 | LARGE_INTEGER IoReadTransferCount; // Size=8 Offset=8 202 | LARGE_INTEGER IoWriteTransferCount; // Size=8 Offset=16 203 | LARGE_INTEGER IoOtherTransferCount; // Size=8 Offset=24 204 | ULONG IoReadOperationCount; // Size=4 Offset=32 205 | ULONG IoWriteOperationCount; // Size=4 Offset=36 206 | ULONG IoOtherOperationCount; // Size=4 Offset=40 207 | ULONG AvailablePages; // Size=4 Offset=44 208 | ULONG CommittedPages; // Size=4 Offset=48 209 | ULONG CommitLimit; // Size=4 Offset=52 210 | ULONG PeakCommitment; // Size=4 Offset=56 211 | ULONG PageFaultCount; // Size=4 Offset=60 212 | ULONG CopyOnWriteCount; // Size=4 Offset=64 213 | ULONG TransitionCount; // Size=4 Offset=68 214 | ULONG CacheTransitionCount; // Size=4 Offset=72 215 | ULONG DemandZeroCount; // Size=4 Offset=76 216 | ULONG PageReadCount; // Size=4 Offset=80 217 | ULONG PageReadIoCount; // Size=4 Offset=84 218 | ULONG CacheReadCount; // Size=4 Offset=88 219 | ULONG CacheIoCount; // Size=4 Offset=92 220 | ULONG DirtyPagesWriteCount; // Size=4 Offset=96 221 | ULONG DirtyWriteIoCount; // Size=4 Offset=100 222 | ULONG MappedPagesWriteCount; // Size=4 Offset=104 223 | ULONG MappedWriteIoCount; // Size=4 Offset=108 224 | ULONG PagedPoolPages; // Size=4 Offset=112 225 | ULONG NonPagedPoolPages; // Size=4 Offset=116 226 | ULONG PagedPoolAllocs; // Size=4 Offset=120 227 | ULONG PagedPoolFrees; // Size=4 Offset=124 228 | ULONG NonPagedPoolAllocs; // Size=4 Offset=128 229 | ULONG NonPagedPoolFrees; // Size=4 Offset=132 230 | ULONG FreeSystemPtes; // Size=4 Offset=136 231 | ULONG ResidentSystemCodePage; // Size=4 Offset=140 232 | ULONG TotalSystemDriverPages; // Size=4 Offset=144 233 | ULONG TotalSystemCodePages; // Size=4 Offset=148 234 | ULONG NonPagedPoolLookasideHits; // Size=4 Offset=152 235 | ULONG PagedPoolLookasideHits; // Size=4 Offset=156 236 | ULONG AvailablePagedPoolPages; // Size=4 Offset=160 237 | ULONG ResidentSystemCachePage; // Size=4 Offset=164 238 | ULONG ResidentPagedPoolPage; // Size=4 Offset=168 239 | ULONG ResidentSystemDriverPage; // Size=4 Offset=172 240 | ULONG CcFastReadNoWait; // Size=4 Offset=176 241 | ULONG CcFastReadWait; // Size=4 Offset=180 242 | ULONG CcFastReadResourceMiss; // Size=4 Offset=184 243 | ULONG CcFastReadNotPossible; // Size=4 Offset=188 244 | ULONG CcFastMdlReadNoWait; // Size=4 Offset=192 245 | ULONG CcFastMdlReadWait; // Size=4 Offset=196 246 | ULONG CcFastMdlReadResourceMiss; // Size=4 Offset=200 247 | ULONG CcFastMdlReadNotPossible; // Size=4 Offset=204 248 | ULONG CcMapDataNoWait; // Size=4 Offset=208 249 | ULONG CcMapDataWait; // Size=4 Offset=212 250 | ULONG CcMapDataNoWaitMiss; // Size=4 Offset=216 251 | ULONG CcMapDataWaitMiss; // Size=4 Offset=220 252 | ULONG CcPinMappedDataCount; // Size=4 Offset=224 253 | ULONG CcPinReadNoWait; // Size=4 Offset=228 254 | ULONG CcPinReadWait; // Size=4 Offset=232 255 | ULONG CcPinReadNoWaitMiss; // Size=4 Offset=236 256 | ULONG CcPinReadWaitMiss; // Size=4 Offset=240 257 | ULONG CcCopyReadNoWait; // Size=4 Offset=244 258 | ULONG CcCopyReadWait; // Size=4 Offset=248 259 | ULONG CcCopyReadNoWaitMiss; // Size=4 Offset=252 260 | ULONG CcCopyReadWaitMiss; // Size=4 Offset=256 261 | ULONG CcMdlReadNoWait; // Size=4 Offset=260 262 | ULONG CcMdlReadWait; // Size=4 Offset=264 263 | ULONG CcMdlReadNoWaitMiss; // Size=4 Offset=268 264 | ULONG CcMdlReadWaitMiss; // Size=4 Offset=272 265 | ULONG CcReadAheadIos; // Size=4 Offset=276 266 | ULONG CcLazyWriteIos; // Size=4 Offset=280 267 | ULONG CcLazyWritePages; // Size=4 Offset=284 268 | ULONG CcDataFlushes; // Size=4 Offset=288 269 | ULONG CcDataPages; // Size=4 Offset=292 270 | ULONG ContextSwitches; // Size=4 Offset=296 271 | ULONG FirstLevelTbFills; // Size=4 Offset=300 272 | ULONG SecondLevelTbFills; // Size=4 Offset=304 273 | ULONG SystemCalls; // Size=4 Offset=308 274 | ULONGLONG CcTotalDirtyPages; // Size=8 Offset=312 275 | ULONGLONG CcDirtyPageThreshold; // Size=8 Offset=320 276 | LONGLONG ResidentAvailablePages; // Size=8 Offset=328 277 | ULONGLONG SharedCommittedPages; // Size=8 Offset=336 278 | }; 279 | 280 | struct _SYSTEM_TIMEOFDAY_INFORMATION // Size=48 281 | { 282 | LARGE_INTEGER BootTime; // Size=8 Offset=0 283 | LARGE_INTEGER CurrentTime; // Size=8 Offset=8 284 | LARGE_INTEGER TimeZoneBias; // Size=8 Offset=16 285 | ULONG TimeZoneId; // Size=4 Offset=24 286 | ULONG Reserved; // Size=4 Offset=28 287 | ULONGLONG BootTimeBias; // Size=8 Offset=32 288 | ULONGLONG SleepTimeBias; // Size=8 Offset=40 289 | }; 290 | 291 | typedef struct _SYSTEM_PROCESS_INFORMATION // Size=184 292 | { 293 | ULONG NextEntryOffset; // Size=4 Offset=0 294 | ULONG NumberOfThreads; // Size=4 Offset=4 295 | LARGE_INTEGER WorkingSetPrivateSize; // Size=8 Offset=8 296 | ULONG HardFaultCount; // Size=4 Offset=16 297 | ULONG NumberOfThreadsHighWatermark; // Size=4 Offset=20 298 | ULONGLONG CycleTime; // Size=8 Offset=24 299 | LARGE_INTEGER CreateTime; // Size=8 Offset=32 300 | LARGE_INTEGER UserTime; // Size=8 Offset=40 301 | LARGE_INTEGER KernelTime; // Size=8 Offset=48 302 | UNICODE_STRING ImageName; // Size=8 Offset=56 303 | LONG BasePriority; // Size=4 Offset=64 304 | PVOID UniqueProcessId; // Size=4 Offset=68 305 | PVOID InheritedFromUniqueProcessId; // Size=4 Offset=72 306 | ULONG HandleCount; // Size=4 Offset=76 307 | ULONG SessionId; // Size=4 Offset=80 308 | ULONG UniqueProcessKey; // Size=4 Offset=84 309 | ULONG PeakVirtualSize; // Size=4 Offset=88 310 | ULONG VirtualSize; // Size=4 Offset=92 311 | ULONG PageFaultCount; // Size=4 Offset=96 312 | ULONG PeakWorkingSetSize; // Size=4 Offset=100 313 | ULONG WorkingSetSize; // Size=4 Offset=104 314 | ULONG QuotaPeakPagedPoolUsage; // Size=4 Offset=108 315 | ULONG QuotaPagedPoolUsage; // Size=4 Offset=112 316 | ULONG QuotaPeakNonPagedPoolUsage; // Size=4 Offset=116 317 | ULONG QuotaNonPagedPoolUsage; // Size=4 Offset=120 318 | ULONG PagefileUsage; // Size=4 Offset=124 319 | ULONG PeakPagefileUsage; // Size=4 Offset=128 320 | ULONG PrivatePageCount; // Size=4 Offset=132 321 | LARGE_INTEGER ReadOperationCount; // Size=8 Offset=136 322 | LARGE_INTEGER WriteOperationCount; // Size=8 Offset=144 323 | LARGE_INTEGER OtherOperationCount; // Size=8 Offset=152 324 | LARGE_INTEGER ReadTransferCount; // Size=8 Offset=160 325 | LARGE_INTEGER WriteTransferCount; // Size=8 Offset=168 326 | LARGE_INTEGER OtherTransferCount; // Size=8 Offset=176 327 | } SYSTEM_PROCESS_INFORMATION; 328 | 329 | struct _SYSTEM_CALL_COUNT_INFORMATION // Size=8 330 | { 331 | ULONG Length; // Size=4 Offset=0 332 | ULONG NumberOfTables; // Size=4 Offset=4 333 | }; 334 | 335 | struct _SYSTEM_DEVICE_INFORMATION // Size=24 336 | { 337 | ULONG NumberOfDisks; // Size=4 Offset=0 338 | ULONG NumberOfFloppies; // Size=4 Offset=4 339 | ULONG NumberOfCdRoms; // Size=4 Offset=8 340 | ULONG NumberOfTapes; // Size=4 Offset=12 341 | ULONG NumberOfSerialPorts; // Size=4 Offset=16 342 | ULONG NumberOfParallelPorts; // Size=4 Offset=20 343 | }; 344 | 345 | struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION // Size=48 346 | { 347 | LARGE_INTEGER IdleTime; // Size=8 Offset=0 348 | LARGE_INTEGER KernelTime; // Size=8 Offset=8 349 | LARGE_INTEGER UserTime; // Size=8 Offset=16 350 | LARGE_INTEGER DpcTime; // Size=8 Offset=24 351 | LARGE_INTEGER InterruptTime; // Size=8 Offset=32 352 | ULONG InterruptCount; // Size=4 Offset=40 353 | }; 354 | 355 | typedef enum _SYSTEM_GLOBAL_FLAGS 356 | { 357 | FLG_DISABLE_DBGPRINT = 0x08000000, 358 | FLG_KERNEL_STACK_TRACE_DB = 0x00002000, 359 | FLG_USER_STACK_TRACE_DB = 0x00001000, 360 | FLG_DEBUG_INITIAL_COMMAND = 0x00000004, 361 | FLG_DEBUG_INITIAL_COMMAND_EX = 0x04000000, 362 | FLG_HEAP_DISABLE_COALESCING = 0x00200000, 363 | FLG_DISABLE_PAGE_KERNEL_STACKS = 0x00080000, 364 | FLG_DISABLE_PROTDLLS = 0x80000000, 365 | FLG_DISABLE_STACK_EXTENSION = 0x00010000, 366 | FLG_CRITSEC_EVENT_CREATION = 0x10000000, 367 | FLG_APPLICATION_VERIFIER = 0x00000100, 368 | FLG_ENABLE_HANDLE_EXCEPTIONS = 0x40000000, 369 | FLG_ENABLE_CLOSE_EXCEPTIONS = 0x00400000, 370 | FLG_ENABLE_CSRDEBUG = 0x00020000, 371 | FLG_ENABLE_EXCEPTION_LOGGING = 0x00800000, 372 | FLG_HEAP_ENABLE_FREE_CHECK = 0x00000020, 373 | FLG_HEAP_VALIDATE_PARAMETERS = 0x00000040, 374 | FLG_HEAP_ENABLE_TAGGING = 0x00000800, 375 | FLG_HEAP_ENABLE_TAG_BY_DLL = 0x00008000, 376 | FLG_HEAP_ENABLE_TAIL_CHECK = 0x00000010, 377 | FLG_HEAP_VALIDATE_ALL = 0x00000080, 378 | FLG_ENABLE_KDEBUG_SYMBOL_LOAD = 0x00040000, 379 | FLG_ENABLE_HANDLE_TYPE_TAGGING = 0x01000000, 380 | FLG_HEAP_PAGE_ALLOCS = 0x02000000, 381 | FLG_POOL_ENABLE_TAGGING = 0x00000400, 382 | FLG_ENABLE_SYSTEM_CRIT_BREAKS = 0x00100000, 383 | FLG_MAINTAIN_OBJECT_TYPELIST = 0x00004000, 384 | FLG_MONITOR_SILENT_PROCESS_EXIT = 0x00000200, 385 | FLG_SHOW_LDR_SNAPS = 0x00000002, 386 | FLG_STOP_ON_EXCEPTION = 0x00000001, 387 | FLG_STOP_ON_HUNG_GUI = 0x00000008 388 | } SYSTEM_GLOBAL_FLAGS; 389 | 390 | struct _SYSTEM_FLAGS_INFORMATION // Size=4 391 | { 392 | SYSTEM_GLOBAL_FLAGS Flags; // Size=4 Offset=0 393 | }; 394 | 395 | struct _SYSTEM_CALL_TIME_INFORMATION // Size=16 396 | { 397 | ULONG Length; // Size=4 Offset=0 398 | ULONG TotalCalls; // Size=4 Offset=4 399 | LARGE_INTEGER TimeOfCalls[1]; // Size=8 Offset=8 400 | }; 401 | 402 | typedef struct _SYSTEM_MODULE // Size=280 403 | { 404 | USHORT Reserved1; // Size=2 Offset=0 405 | USHORT Reserved2; // Size=2 Offset=2 406 | ULONG ImageBaseAddress; // Size=4 Offset=4 407 | ULONG ImageSize; // Size=4 Offset=8 408 | ULONG Flags; // Size=4 Offset=12 409 | USHORT Index; // Size=2 Offset=16 410 | USHORT Rank; // Size=2 Offset=18 411 | USHORT LoadCount; // Size=2 Offset=20 412 | USHORT NameOffset; // Size=2 Offset=22 413 | UCHAR Name[256]; // Size=256 Offset=24 414 | } SYSTEM_MODULE; 415 | 416 | struct _SYSTEM_MODULE_INFORMATION // Size=284 417 | { 418 | ULONG Count; // Size=4 Offset=0 419 | SYSTEM_MODULE Modules[1]; // Size=280 Offset=4 420 | }; 421 | 422 | typedef struct _SYSTEM_LOCK // Size=36 423 | { 424 | PVOID Address; // Size=4 Offset=0 425 | USHORT Type; // Size=2 Offset=4 426 | USHORT Reserved1; // Size=2 Offset=6 427 | ULONG ExclusiveOwnerThreadId; // Size=4 Offset=8 428 | ULONG ActiveCount; // Size=4 Offset=12 429 | ULONG ContentionCount; // Size=4 Offset=16 430 | ULONG Reserved2[2]; // Size=8 Offset=20 431 | ULONG NumberOfSharedWaiters; // Size=4 Offset=28 432 | ULONG NumberOfExclusiveWaiters; // Size=4 Offset=32 433 | } SYSTEM_LOCK; 434 | 435 | struct _SYSTEM_LOCK_INFORMATION // Size=40 436 | { 437 | ULONG Count; // Size=4 Offset=0 438 | SYSTEM_LOCK Locks[1]; // Size=36 Offset=4 439 | }; 440 | 441 | typedef enum _SYSTEM_HANDLE_FLAGS 442 | { 443 | PROTECT_FROM_CLOSE = 1, 444 | INHERIT = 2 445 | } SYSTEM_HANDLE_FLAGS; 446 | 447 | typedef struct _SYSTEM_HANDLE_TABLE_ENTRY_INFO // Size=16 448 | { 449 | USHORT UniqueProcessId; // Size=2 Offset=0 450 | USHORT CreatorBackTraceIndex; // Size=2 Offset=2 451 | UCHAR ObjectTypeIndex; // Size=1 Offset=4 452 | BYTE HandleAttributes; // Size=1 Offset=5 453 | USHORT HandleValue; // Size=2 Offset=6 454 | PVOID Object; // Size=4 Offset=8 455 | ULONG GrantedAccess; // Size=4 Offset=12 456 | } SYSTEM_HANDLE_TABLE_ENTRY_INFO, *PSYSTEM_HANDLE_TABLE_ENTRY_INFO; 457 | 458 | typedef struct _SYSTEM_HANDLE_INFORMATION // Size=20 459 | { 460 | ULONG NumberOfHandles; // Size=4 Offset=0 461 | SYSTEM_HANDLE_TABLE_ENTRY_INFO Handles[1]; // Size=16 Offset=4 462 | } SYSTEM_HANDLE_INFORMATION, * PSYSTEM_HANDLE_INFORMATION; 463 | 464 | struct _SYSTEM_OBJECTTYPE_INFORMATION // Size=56 465 | { 466 | ULONG NextEntryOffset; // Size=4 Offset=0 467 | ULONG NumberOfObjects; // Size=4 Offset=4 468 | ULONG NumberOfHandles; // Size=4 Offset=8 469 | ULONG TypeIndex; // Size=4 Offset=12 470 | ULONG InvalidAttributes; // Size=4 Offset=16 471 | GENERIC_MAPPING GenericMapping; // Size=16 Offset=20 472 | ULONG ValidAccessMask; // Size=4 Offset=36 473 | ULONG PoolType; // Size=4 Offset=40 474 | UCHAR SecurityRequired; // Size=1 Offset=44 475 | UCHAR WaitableObject; // Size=1 Offset=45 476 | UNICODE_STRING TypeName; // Size=8 Offset=48 477 | }; 478 | 479 | typedef struct _OBJECT_NAME_INFORMATION // Size=8 480 | { 481 | UNICODE_STRING Name; // Size=8 Offset=0 482 | } OBJECT_NAME_INFORMATION; 483 | 484 | struct _SYSTEM_OBJECT_INFORMATION // Size=48 485 | { 486 | ULONG NextEntryOffset; // Size=4 Offset=0 487 | PVOID Object; // Size=4 Offset=4 488 | PVOID CreatorUniqueProcess; // Size=4 Offset=8 489 | USHORT CreatorBackTraceIndex; // Size=2 Offset=12 490 | USHORT Flags; // Size=2 Offset=14 491 | LONG PointerCount; // Size=4 Offset=16 492 | LONG HandleCount; // Size=4 Offset=20 493 | ULONG PagedPoolCharge; // Size=4 Offset=24 494 | ULONG NonPagedPoolCharge; // Size=4 Offset=28 495 | PVOID ExclusiveProcessId; // Size=4 Offset=32 496 | PVOID SecurityDescriptor; // Size=4 Offset=36 497 | OBJECT_NAME_INFORMATION NameInfo; // Size=8 Offset=40 498 | }; 499 | 500 | struct _SYSTEM_PAGEFILE_INFORMATION // Size=24 501 | { 502 | ULONG NextEntryOffset; // Size=4 Offset=0 503 | ULONG TotalSize; // Size=4 Offset=4 504 | ULONG TotalInUse; // Size=4 Offset=8 505 | ULONG PeakUsage; // Size=4 Offset=12 506 | UNICODE_STRING PageFileName; // Size=8 Offset=16 507 | }; 508 | 509 | struct _SYSTEM_VDM_INSTEMUL_INFO // Size=136 510 | { 511 | ULONG SegmentNotPresent; // Size=4 Offset=0 512 | ULONG VdmOpcode0F; // Size=4 Offset=4 513 | ULONG OpcodeESPrefix; // Size=4 Offset=8 514 | ULONG OpcodeCSPrefix; // Size=4 Offset=12 515 | ULONG OpcodeSSPrefix; // Size=4 Offset=16 516 | ULONG OpcodeDSPrefix; // Size=4 Offset=20 517 | ULONG OpcodeFSPrefix; // Size=4 Offset=24 518 | ULONG OpcodeGSPrefix; // Size=4 Offset=28 519 | ULONG OpcodeOPER32Prefix; // Size=4 Offset=32 520 | ULONG OpcodeADDR32Prefix; // Size=4 Offset=36 521 | ULONG OpcodeINSB; // Size=4 Offset=40 522 | ULONG OpcodeINSW; // Size=4 Offset=44 523 | ULONG OpcodeOUTSB; // Size=4 Offset=48 524 | ULONG OpcodeOUTSW; // Size=4 Offset=52 525 | ULONG OpcodePUSHF; // Size=4 Offset=56 526 | ULONG OpcodePOPF; // Size=4 Offset=60 527 | ULONG OpcodeINTnn; // Size=4 Offset=64 528 | ULONG OpcodeINTO; // Size=4 Offset=68 529 | ULONG OpcodeIRET; // Size=4 Offset=72 530 | ULONG OpcodeINBimm; // Size=4 Offset=76 531 | ULONG OpcodeINWimm; // Size=4 Offset=80 532 | ULONG OpcodeOUTBimm; // Size=4 Offset=84 533 | ULONG OpcodeOUTWimm; // Size=4 Offset=88 534 | ULONG OpcodeINB; // Size=4 Offset=92 535 | ULONG OpcodeINW; // Size=4 Offset=96 536 | ULONG OpcodeOUTB; // Size=4 Offset=100 537 | ULONG OpcodeOUTW; // Size=4 Offset=104 538 | ULONG OpcodeLOCKPrefix; // Size=4 Offset=108 539 | ULONG OpcodeREPNEPrefix; // Size=4 Offset=112 540 | ULONG OpcodeREPPrefix; // Size=4 Offset=116 541 | ULONG OpcodeHLT; // Size=4 Offset=120 542 | ULONG OpcodeCLI; // Size=4 Offset=124 543 | ULONG OpcodeSTI; // Size=4 Offset=128 544 | ULONG BopCount; // Size=4 Offset=132 545 | }; 546 | 547 | struct _SYSTEM_FILECACHE_INFORMATION // Size=36 548 | { 549 | ULONG CurrentSize; // Size=4 Offset=0 550 | ULONG PeakSize; // Size=4 Offset=4 551 | ULONG PageFaultCount; // Size=4 Offset=8 552 | ULONG MinimumWorkingSet; // Size=4 Offset=12 553 | ULONG MaximumWorkingSet; // Size=4 Offset=16 554 | ULONG CurrentSizeIncludingTransitionInPages; // Size=4 Offset=20 555 | ULONG PeakSizeIncludingTransitionInPages; // Size=4 Offset=24 556 | ULONG TransitionRePurposeCount; // Size=4 Offset=28 557 | ULONG Flags; // Size=4 Offset=32 558 | }; 559 | 560 | typedef struct _SYSTEM_POOLTAG // Size=28 561 | { 562 | UCHAR Tag[4]; // Size=4 Offset=0 563 | ULONG PagedAllocs; // Size=4 Offset=4 564 | ULONG PagedFrees; // Size=4 Offset=8 565 | ULONG PagedUsed; // Size=4 Offset=12 566 | ULONG NonPagedAllocs; // Size=4 Offset=16 567 | ULONG NonPagedFrees; // Size=4 Offset=20 568 | ULONG NonPagedUsed; // Size=4 Offset=24 569 | } SYSTEM_POOLTAG; 570 | 571 | struct _SYSTEM_POOLTAG_INFORMATION // Size=32 572 | { 573 | ULONG Count; // Size=4 Offset=0 574 | SYSTEM_POOLTAG TagInfo[1]; // Size=28 Offset=4 575 | }; 576 | 577 | struct _SYSTEM_INTERRUPT_INFORMATION // Size=24 578 | { 579 | ULONG ContextSwitches; // Size=4 Offset=0 580 | ULONG DpcCount; // Size=4 Offset=4 581 | ULONG DpcRate; // Size=4 Offset=8 582 | ULONG TimeIncrement; // Size=4 Offset=12 583 | ULONG DpcBypassCount; // Size=4 Offset=16 584 | ULONG ApcBypassCount; // Size=4 Offset=20 585 | }; 586 | 587 | struct _SYSTEM_DPC_BEHAVIOR_INFORMATION // Size=20 588 | { 589 | ULONG Spare; // Size=4 Offset=0 590 | ULONG DpcQueueDepth; // Size=4 Offset=4 591 | ULONG MinimumDpcRate; // Size=4 Offset=8 592 | ULONG AdjustDpcThreshold; // Size=4 Offset=12 593 | ULONG IdealDpcRate; // Size=4 Offset=16 594 | }; 595 | 596 | struct _SYSTEM_LOADED_GDI_DRIVER_INFORMATION // Size=28 597 | { 598 | UNICODE_STRING DriverName; // Size=8 Offset=0 599 | PVOID ImageAddress; // Size=4 Offset=8 600 | PVOID SectionPointer; // Size=4 Offset=12 601 | PVOID EntryPoint; // Size=4 Offset=16 602 | PIMAGE_EXPORT_DIRECTORY ExportSectionPointer; // Size=4 Offset=20 603 | ULONG ImageLength; // Size=4 Offset=24 604 | }; 605 | 606 | struct _SYSTEM_UNLOADED_GDI_DRIVER_INFORMATION // Size=28 607 | { 608 | PVOID ImageAddress; // Size=4 Offset=0 609 | }; 610 | 611 | struct _SYSTEM_CRASH_DUMP_INFORMATION 612 | { 613 | HANDLE CrashDumpSectionHandle; // Size=4 Offset=0 614 | }; 615 | 616 | struct _SYSTEM_EXCEPTION_INFORMATION // Size=16 617 | { 618 | ULONG AlignmentFixupCount; // Size=4 Offset=0 619 | ULONG ExceptionDispatchCount; // Size=4 Offset=4 620 | ULONG FloatingEmulationCount; // Size=4 Offset=8 621 | ULONG ByteWordEmulationCount; // Size=4 Offset=12 622 | }; 623 | 624 | typedef enum _SYSTEM_CRASH_DUMP_CONFIGURATION_CLASS 625 | { 626 | SystemCrashDumpDisable = 0, 627 | SystemCrashDumpReconfigure = 1, 628 | SystemCrashDumpInitializationComplete = 2 629 | } SYSTEM_CRASH_DUMP_CONFIGURATION_CLASS; 630 | 631 | struct _SYSTEM_CRASH_DUMP_STATE_INFORMATION // Size=4 632 | { 633 | SYSTEM_CRASH_DUMP_CONFIGURATION_CLASS CrashDumpConfigurationClass; // Size=4 Offset=0 634 | }; 635 | 636 | struct _SYSTEM_KERNEL_DEBUGGER_INFORMATION // Size=2 637 | { 638 | UCHAR KernelDebuggerEnabled; // Size=1 Offset=0 639 | UCHAR KernelDebuggerNotPresent; // Size=1 Offset=1 640 | }; 641 | 642 | struct _SYSTEM_PRIORITY_SEPARATION 643 | { 644 | ULONG PrioritySeparation; // Size=4 Offset=0 645 | }; 646 | 647 | 648 | struct _SYSTEM_TIME_ZONE_INFORMATION 649 | { 650 | LONG Bias; 651 | WCHAR StandardName[32]; 652 | SYSTEMTIME StandardDate; 653 | LONG StandardBias; 654 | WCHAR DaylightName[32]; 655 | SYSTEMTIME DaylightDate; 656 | LONG DaylightBias; 657 | }; 658 | 659 | struct _SYSTEM_CONTEXT_SWITCH_INFORMATION // Size=48 660 | { 661 | ULONG ContextSwitches; // Size=4 Offset=0 662 | ULONG FindAny; // Size=4 Offset=4 663 | ULONG FindLast; // Size=4 Offset=8 664 | ULONG FindIdeal; // Size=4 Offset=12 665 | ULONG IdleAny; // Size=4 Offset=16 666 | ULONG IdleCurrent; // Size=4 Offset=20 667 | ULONG IdleLast; // Size=4 Offset=24 668 | ULONG IdleIdeal; // Size=4 Offset=28 669 | ULONG PreemptAny; // Size=4 Offset=32 670 | ULONG PreemptCurrent; // Size=4 Offset=36 671 | ULONG PreemptLast; // Size=4 Offset=40 672 | ULONG SwitchToIdle; // Size=4 Offset=44 673 | }; 674 | 675 | struct _SYSTEM_REGISTRY_QUOTA_INFORMATION // Size=12 676 | { 677 | ULONG RegistryQuotaAllowed; // Size=4 Offset=0 678 | ULONG RegistryQuotaUsed; // Size=4 Offset=4 679 | ULONG PagedPoolSize; // Size=4 Offset=8 680 | }; 681 | 682 | struct _SYSTEM_PROCESSOR_IDLE_INFORMATION // Size=48 683 | { 684 | ULONGLONG IdleTime; // Size=8 Offset=0 685 | ULONGLONG C1Time; // Size=8 Offset=8 686 | ULONGLONG C2Time; // Size=8 Offset=16 687 | ULONGLONG C3Time; // Size=8 Offset=24 688 | ULONG C1Transitions; // Size=4 Offset=32 689 | ULONG C2Transitions; // Size=4 Offset=36 690 | ULONG C3Transitions; // Size=4 Offset=40 691 | ULONG Padding; // Size=4 Offset=44 692 | }; 693 | 694 | struct _SYSTEM_LEGACY_DRIVER_INFORMATION // Size=12 695 | { 696 | ULONG VetoType; // Size=4 Offset=0 697 | UNICODE_STRING VetoList; // Size=8 Offset=4 698 | }; 699 | 700 | typedef enum _POOL_TYPE { 701 | NonPagedPool, 702 | NonPagedPoolExecute = NonPagedPool, 703 | PagedPool, 704 | NonPagedPoolMustSucceed = NonPagedPool + 2, 705 | DontUseThisType, 706 | NonPagedPoolCacheAligned = NonPagedPool + 4, 707 | PagedPoolCacheAligned, 708 | NonPagedPoolCacheAlignedMustS = NonPagedPool + 6, 709 | MaxPoolType, 710 | NonPagedPoolBase = 0, 711 | NonPagedPoolBaseMustSucceed = NonPagedPoolBase + 2, 712 | NonPagedPoolBaseCacheAligned = NonPagedPoolBase + 4, 713 | NonPagedPoolBaseCacheAlignedMustS = NonPagedPoolBase + 6, 714 | NonPagedPoolSession = 32, 715 | PagedPoolSession = NonPagedPoolSession + 1, 716 | NonPagedPoolMustSucceedSession = PagedPoolSession + 1, 717 | DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1, 718 | NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1, 719 | PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1, 720 | NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1, 721 | NonPagedPoolNx = 512, 722 | NonPagedPoolNxCacheAligned = NonPagedPoolNx + 4, 723 | NonPagedPoolSessionNx = NonPagedPoolNx + 32 724 | } POOL_TYPE; 725 | 726 | struct _SYSTEM_LOOKASIDE_INFORMATION // Size=32 727 | { 728 | USHORT CurrentDepth; // Size=2 Offset=0 729 | USHORT MaximumDepth; // Size=2 Offset=2 730 | ULONG TotalAllocates; // Size=4 Offset=4 731 | ULONG AllocateMisses; // Size=4 Offset=8 732 | ULONG TotalFrees; // Size=4 Offset=12 733 | ULONG FreeMisses; // Size=4 Offset=16 734 | POOL_TYPE Type; // Size=4 Offset=20 735 | ULONG Tag; // Size=4 Offset=24 736 | ULONG Size; // Size=4 Offset=28 737 | }; 738 | 739 | struct _SYSTEM_SET_TIME_SLIP_EVENT 740 | { 741 | HANDLE TimeSlipEvent; 742 | }; 743 | 744 | struct _SYSTEM_SESSION 745 | { 746 | ULONG SessionId; 747 | }; 748 | 749 | struct _SYSTEM_RANGE_START_INFORMATION 750 | { 751 | PVOID SystemRangeStart; 752 | }; 753 | 754 | typedef struct _SYSTEM_VERIFIER_INFORMATION // Size=104 755 | { 756 | ULONG NextEntryOffset; // Size=4 Offset=0 757 | ULONG Level; // Size=4 Offset=4 758 | UNICODE_STRING DriverName; // Size=8 Offset=8 759 | ULONG RaiseIrqls; // Size=4 Offset=16 760 | ULONG AcquireSpinLocks; // Size=4 Offset=20 761 | ULONG SynchronizeExecutions; // Size=4 Offset=24 762 | ULONG AllocationsAttempted; // Size=4 Offset=28 763 | ULONG AllocationsSucceeded; // Size=4 Offset=32 764 | ULONG AllocationsSucceededSpecialPool; // Size=4 Offset=36 765 | ULONG AllocationsWithNoTag; // Size=4 Offset=40 766 | ULONG TrimRequests; // Size=4 Offset=44 767 | ULONG Trims; // Size=4 Offset=48 768 | ULONG AllocationsFailed; // Size=4 Offset=52 769 | ULONG AllocationsFailedDeliberately; // Size=4 Offset=56 770 | ULONG Loads; // Size=4 Offset=60 771 | ULONG Unloads; // Size=4 Offset=64 772 | ULONG UnTrackedPool; // Size=4 Offset=68 773 | ULONG CurrentPagedPoolAllocations; // Size=4 Offset=72 774 | ULONG CurrentNonPagedPoolAllocations; // Size=4 Offset=76 775 | ULONG PeakPagedPoolAllocations; // Size=4 Offset=80 776 | ULONG PeakNonPagedPoolAllocations; // Size=4 Offset=84 777 | ULONG PagedPoolUsageInBytes; // Size=4 Offset=88 778 | ULONG NonPagedPoolUsageInBytes; // Size=4 Offset=92 779 | ULONG PeakPagedPoolUsageInBytes; // Size=4 Offset=96 780 | ULONG PeakNonPagedPoolUsageInBytes; // Size=4 Offset=100 781 | } SYSTEM_VERIFIER_INFORMATION; 782 | 783 | struct _SYSTEM_SESSION_PROCESS_INFORMATION // Size=12 784 | { 785 | ULONG SessionId; // Size=4 Offset=0 786 | ULONG SizeOfBuf; // Size=4 Offset=4 787 | PVOID Buffer; // Size=4 Offset=8 788 | }; 789 | 790 | typedef struct _SYSTEM_POOL_BLOCK 791 | { 792 | BOOLEAN Allocated; 793 | USHORT Unknown; 794 | ULONG Size; 795 | CHAR Tag[4]; 796 | } SYSTEM_POOL_BLOCK; 797 | 798 | struct _SYSTEM_POOL_BLOCKS_INFORMATION 799 | { 800 | ULONG PoolSize; 801 | PVOID PoolBase; 802 | USHORT PoolAlignment; 803 | ULONG NumberOfBlocks; 804 | SYSTEM_POOL_BLOCK PoolBlocks[1]; 805 | }; 806 | 807 | typedef struct _SYSTEM_MEMORY_USAGE 808 | { 809 | PVOID Name; 810 | USHORT Valid; 811 | USHORT Standby; 812 | USHORT Modified; 813 | USHORT PageTables; 814 | } SYSTEM_MEMORY_USAGE; 815 | 816 | struct _SYSTEM_MEMORY_USAGE_INFORMATION 817 | { 818 | ULONG Reserved; 819 | PVOID EndOfData; 820 | SYSTEM_MEMORY_USAGE MemoryUsage[1]; 821 | }; 822 | 823 | typedef struct _CLIENT_ID // Size=8 824 | { 825 | PVOID UniqueProcess; // Size=4 Offset=0 826 | PVOID UniqueThread; // Size=4 Offset=4 827 | } CLIENT_ID; 828 | 829 | typedef struct _SYSTEM_THREAD_INFORMATION // Size=64 830 | { 831 | LARGE_INTEGER KernelTime; // Size=8 Offset=0 832 | LARGE_INTEGER UserTime; // Size=8 Offset=8 833 | LARGE_INTEGER CreateTime; // Size=8 Offset=16 834 | ULONG WaitTime; // Size=4 Offset=24 835 | PVOID StartAddress; // Size=4 Offset=28 836 | CLIENT_ID ClientId; // Size=8 Offset=32 837 | LONG Priority; // Size=4 Offset=40 838 | LONG BasePriority; // Size=4 Offset=44 839 | ULONG ContextSwitches; // Size=4 Offset=48 840 | ULONG ThreadState; // Size=4 Offset=52 841 | ULONG WaitReason; // Size=4 Offset=56 842 | } SYSTEM_THREAD_INFORMATION; 843 | 844 | typedef struct _SYSTEM_EXTENDED_THREAD_INFORMATION // Size=96 845 | { 846 | SYSTEM_THREAD_INFORMATION ThreadInfo; // Size=64 Offset=0 847 | PVOID StackBase; // Size=4 Offset=64 848 | PVOID StackLimit; // Size=4 Offset=68 849 | PVOID Win32StartAddress; // Size=4 Offset=72 850 | PVOID TebBase; // Size=4 Offset=76 851 | ULONG Reserved2; // Size=4 Offset=80 852 | ULONG Reserved3; // Size=4 Offset=84 853 | ULONG Reserved4; // Size=4 Offset=88 854 | } SYSTEM_EXTENDED_THREAD_INFORMATION; 855 | 856 | // I have not validated this structure 857 | struct _SYSTEM_EXTENDED_PROCESS_INFORMATION 858 | { 859 | SYSTEM_PROCESS_INFORMATION ProcessInfo; 860 | SYSTEM_EXTENDED_THREAD_INFORMATION ThreadInfo; 861 | }; 862 | 863 | struct _SYSTEM_PROCESSOR_POWER_INFORMATION // Size=72 864 | { 865 | UCHAR CurrentFrequency; // Size=1 Offset=0 866 | UCHAR ThermalLimitFrequency; // Size=1 Offset=1 867 | UCHAR ConstantThrottleFrequency; // Size=1 Offset=2 868 | UCHAR DegradedThrottleFrequency; // Size=1 Offset=3 869 | UCHAR LastBusyFrequency; // Size=1 Offset=4 870 | UCHAR LastC3Frequency; // Size=1 Offset=5 871 | UCHAR LastAdjustedBusyFrequency; // Size=1 Offset=6 872 | UCHAR ProcessorMinThrottle; // Size=1 Offset=7 873 | UCHAR ProcessorMaxThrottle; // Size=1 Offset=8 874 | ULONG NumberOfFrequencies; // Size=4 Offset=12 875 | ULONG PromotionCount; // Size=4 Offset=16 876 | ULONG DemotionCount; // Size=4 Offset=20 877 | ULONG ErrorCount; // Size=4 Offset=24 878 | ULONG RetryCount; // Size=4 Offset=28 879 | ULONGLONG CurrentFrequencyTime; // Size=8 Offset=32 880 | ULONGLONG CurrentProcessorTime; // Size=8 Offset=40 881 | ULONGLONG CurrentProcessorIdleTime; // Size=8 Offset=48 882 | ULONGLONG LastProcessorTime; // Size=8 Offset=56 883 | ULONGLONG LastProcessorIdleTime; // Size=8 Offset=64 884 | }; 885 | 886 | struct SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX // Size=28 887 | { 888 | PVOID Object; // Size=4 Offset=0 889 | ULONG UniqueProcessId; // Size=4 Offset=4 890 | ULONG HandleValue; // Size=4 Offset=8 891 | ULONG GrantedAccess; // Size=4 Offset=12 892 | USHORT CreatorBackTraceIndex; // Size=2 Offset=16 893 | USHORT ObjectTypeIndex; // Size=2 Offset=18 894 | ULONG HandleAttributes; // Size=4 Offset=20 895 | ULONG Reserved; // Size=4 Offset=24 896 | }; 897 | 898 | struct _SYSTEM_HANDLE_INFORMATION_EX // Size=36 899 | { 900 | ULONG NumberOfHandles; // Size=4 Offset=0 901 | ULONG Reserved; // Size=4 Offset=4 902 | SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX Handles[1]; // Size=36 Offset=8 903 | }; 904 | 905 | typedef struct _SYSTEM_BIGPOOL_ENTRY // Size=12 906 | { 907 | PVOID VirtualAddress; // Size=4 Offset=0 908 | ULONG SizeInBytes; // Size=4 Offset=4 909 | UCHAR Tag[4]; // Size=4 Offset=8 910 | } SYSTEM_BIGPOOL_ENTRY; 911 | 912 | struct _SYSTEM_BIGPOOL_INFORMATION // Size=16 913 | { 914 | ULONG Count; // Size=4 Offset=0 915 | SYSTEM_BIGPOOL_ENTRY AllocatedInfo[1]; // Size=12 Offset=4 916 | }; 917 | 918 | struct _SYSTEM_SESSION_POOLTAG_INFORMATION // Size=40 919 | { 920 | ULONG NextEntryOffset; // Size=4 Offset=0 921 | ULONG SessionId; // Size=4 Offset=4 922 | ULONG Count; // Size=4 Offset=8 923 | SYSTEM_POOLTAG TagInfo[1]; // Size=28 Offset=12 924 | }; 925 | 926 | struct _SYSTEM_SESSION_MAPPED_VIEW_INFORMATION // Size=20 927 | { 928 | ULONG NextEntryOffset; // Size=4 Offset=0 929 | ULONG SessionId; // Size=4 Offset=4 930 | ULONG ViewFailures; // Size=4 Offset=8 931 | ULONG NumberOfBytesAvailable; // Size=4 Offset=12 932 | ULONG NumberOfBytesAvailableContiguous; // Size=4 Offset=16 933 | }; 934 | 935 | typedef struct _HOTPATCH_HOOK_DESCRIPTOR // Size=40 936 | { 937 | ULONGLONG TargetAddress; // Size=8 Offset=0 938 | ULONGLONG MappedAddress; // Size=8 Offset=8 939 | ULONG CodeOffset; // Size=4 Offset=16 940 | ULONG CodeSize; // Size=4 Offset=20 941 | ULONG OrigCodeOffset; // Size=4 Offset=24 942 | ULONG ValidationOffset; // Size=4 Offset=28 943 | ULONG ValidationSize; // Size=4 Offset=32 944 | } HOTPATCH_HOOK_DESCRIPTOR; 945 | 946 | struct _SYSTEM_HOTPATCH_CODE_INFORMATION_KERNEL_INFO // Size=4 947 | { 948 | USHORT NameOffset; // Size=2 Offset=0 949 | USHORT NameLength; // Size=2 Offset=2 950 | }; 951 | 952 | struct _SYSTEM_HOTPATCH_CODE_INFORMATION_USERMODE_INFO // Size=14 953 | { 954 | USHORT NameOffset; // Size=2 Offset=0 955 | USHORT NameLength; // Size=2 Offset=2 956 | USHORT TargetNameOffset; // Size=2 Offset=4 957 | USHORT TargetNameLength; // Size=2 Offset=6 958 | USHORT ColdpatchImagePathOffset; // Size=2 Offset=8 959 | USHORT ColdpatchImagePathLength; // Size=2 Offset=10 960 | UCHAR PatchingFinished; // Size=1 Offset=12 961 | }; 962 | 963 | struct _SYSTEM_HOTPATCH_CODE_INFORMATION_INJECTION_INFO // Size=24 964 | { 965 | USHORT NameOffset; // Size=2 Offset=0 966 | USHORT NameLength; // Size=2 Offset=2 967 | USHORT TargetNameOffset; // Size=2 Offset=4 968 | USHORT TargetNameLength; // Size=2 Offset=6 969 | USHORT ColdpatchImagePathOffset; // Size=2 Offset=8 970 | USHORT ColdpatchImagePathLength; // Size=2 Offset=10 971 | ULONGLONG TargetProcess; // Size=8 Offset=16 972 | }; 973 | 974 | struct _SYSTEM_HOTPATCH_CODE_INFORMATION_ATOMIC_SWAP // Size=24 975 | { 976 | ULONGLONG ParentDirectory; // Size=8 Offset=0 977 | ULONGLONG ObjectHandle1; // Size=8 Offset=8 978 | ULONGLONG ObjectHandle2; // Size=8 Offset=16 979 | }; 980 | 981 | struct _SYSTEM_HOTPATCH_CODE_INFORMATION_CODE_INFO // Size=48 982 | { 983 | ULONG DescriptorsCount; // Size=4 Offset=0 984 | HOTPATCH_HOOK_DESCRIPTOR CodeDescriptors[1]; // Size=40 Offset=8 985 | }; 986 | 987 | typedef enum _WATCHDOG_INFORMATION_CLASS 988 | { 989 | WdInfoTimeoutValue = 0, 990 | WdInfoResetTimer = 1, 991 | WdInfoStopTimer = 2, 992 | WdInfoStartTimer = 3, 993 | WdInfoTriggerAction = 4, 994 | WdInfoState = 5 995 | } WATCHDOG_INFORMATION_CLASS; 996 | 997 | struct _SYSTEM_WATCHDOG_TIMER_INFORMATION // Size=8 998 | { 999 | WATCHDOG_INFORMATION_CLASS WdInfoClass; // Size=4 Offset=0 1000 | ULONG DataValue; // Size=4 Offset=4 1001 | }; 1002 | 1003 | struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION_PROCESSOR_CORE // Size=1 1004 | { 1005 | UCHAR Flags; // Size=1 Offset=0 1006 | }; 1007 | 1008 | struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION_NUMA_CODE // Size=4 1009 | { 1010 | ULONG NodeNumber; // Size=4 Offset=0 1011 | }; 1012 | 1013 | 1014 | 1015 | typedef enum _SYSTEM_FIRMWARE_TABLE_ACTION 1016 | { 1017 | SystemFirmwareTable_Enumerate = 0, 1018 | SystemFirmwareTable_Get = 1 1019 | } SYSTEM_FIRMWARE_TABLE_ACTION; 1020 | 1021 | struct _SYSTEM_FIRMWARE_TABLE_INFORMATION // Size=20 1022 | { 1023 | ULONG ProviderSignature; // Size=4 Offset=0 1024 | SYSTEM_FIRMWARE_TABLE_ACTION Action; // Size=4 Offset=4 1025 | ULONG TableID; // Size=4 Offset=8 1026 | ULONG TableBufferLength; // Size=4 Offset=12 1027 | UCHAR TableBuffer[1]; // Size=1 Offset=16 1028 | }; 1029 | 1030 | struct _SYSTEM_VERIFIER_TRIAGE_INFORMATION // Size=544 1031 | { 1032 | ULONG ActionTaken; // Size=4 Offset=0 1033 | ULONG CrashData[5]; // Size=20 Offset=4 1034 | ULONG VerifierMode; // Size=4 Offset=24 1035 | ULONG VerifierFlags; // Size=4 Offset=28 1036 | WCHAR VerifierTargets[256]; // Size=512 Offset=32 1037 | }; 1038 | 1039 | struct _SYSTEM_MEMORY_LIST_INFORMATION // Size=88 1040 | { 1041 | ULONG ZeroPageCount; // Size=4 Offset=0 1042 | ULONG FreePageCount; // Size=4 Offset=4 1043 | ULONG ModifiedPageCount; // Size=4 Offset=8 1044 | ULONG ModifiedNoWritePageCount; // Size=4 Offset=12 1045 | ULONG BadPageCount; // Size=4 Offset=16 1046 | ULONG PageCountByPriority[8]; // Size=32 Offset=20 1047 | ULONG RepurposedPagesByPriority[8]; // Size=32 Offset=52 1048 | ULONG ModifiedPageCountPageFile; // Size=4 Offset=84 1049 | }; 1050 | 1051 | struct _SYSTEM_THREAD_CID_PRIORITY_INFORMATION // Size=12 1052 | { 1053 | CLIENT_ID ClientId; // Size=8 Offset=0 1054 | LONG Priority; // Size=4 Offset=8 1055 | }; 1056 | 1057 | struct _SYSTEM_PROCESSOR_IDLE_CYCLE_TIME_INFORMATION // Size=8 1058 | { 1059 | ULONGLONG CycleTime; // Size=8 Offset=0 1060 | }; 1061 | 1062 | typedef struct _SYSTEM_VERIFIER_ISSUE // Size=16 1063 | { 1064 | ULONG IssueType; // Size=4 Offset=0 1065 | PVOID Address; // Size=4 Offset=4 1066 | ULONG Parameters[2]; // Size=8 Offset=8 1067 | } SYSTEM_VERIFIER_ISSUE; 1068 | 1069 | struct _SYSTEM_VERIFIER_CANCELLATION_INFORMATION // Size=2068 1070 | { 1071 | ULONG CancelProbability; // Size=4 Offset=0 1072 | ULONG CancelThreshold; // Size=4 Offset=4 1073 | ULONG CompletionThreshold; // Size=4 Offset=8 1074 | ULONG CancellationVerifierDisabled; // Size=4 Offset=12 1075 | ULONG AvailableIssues; // Size=4 Offset=16 1076 | SYSTEM_VERIFIER_ISSUE Issues[128]; // Size=2048 Offset=20 1077 | }; 1078 | 1079 | struct _SYSTEM_REF_TRACE_INFORMATION // Size=20 1080 | { 1081 | UCHAR TraceEnable; // Size=1 Offset=0 1082 | UCHAR TracePermanent; // Size=1 Offset=1 1083 | UNICODE_STRING TraceProcessName; // Size=8 Offset=4 1084 | UNICODE_STRING TracePoolTags; // Size=8 Offset=12 1085 | }; 1086 | 1087 | struct _SYSTEM_SPECIAL_POOL_INFORMATION // Size=8 1088 | { 1089 | ULONG PoolTag; // Size=4 Offset=0 1090 | ULONG Flags; // Size=4 Offset=4 1091 | }; 1092 | 1093 | struct _SYSTEM_PROCESS_ID_INFORMATION // Size=12 1094 | { 1095 | PVOID ProcessId; // Size=4 Offset=0 1096 | UNICODE_STRING ImageName; // Size=8 Offset=4 1097 | }; 1098 | 1099 | 1100 | struct _SYSTEM_BOOT_ENVIRONMENT_INFORMATION // Size=32 1101 | { 1102 | GUID BootIdentifier; // Size=16 Offset=0 1103 | FIRMWARE_TYPE FirmwareType; // Size=4 Offset=16 1104 | ULONGLONG BootFlags; // Size=8 Offset=24 1105 | }; 1106 | 1107 | struct _SYSTEM_VERIFIER_INFORMATION_EX // Size=36 1108 | { 1109 | ULONG VerifyMode; // Size=4 Offset=0 1110 | ULONG OptionChanges; // Size=4 Offset=4 1111 | UNICODE_STRING PreviousBucketName; // Size=8 Offset=8 1112 | ULONG IrpCancelTimeoutMsec; // Size=4 Offset=16 1113 | ULONG VerifierExtensionEnabled; // Size=4 Offset=20 1114 | ULONG Reserved[3]; // Size=12 Offset=24 1115 | }; 1116 | 1117 | struct _SYSTEM_IMAGE_FILE_EXECUTION_OPTIONS_INFORMATION // Size=8 1118 | { 1119 | ULONG FlagsToEnable; // Size=4 Offset=0 1120 | ULONG FlagsToDisable; // Size=4 Offset=4 1121 | }; 1122 | 1123 | struct _SYSTEM_PREFETCH_PATCH_INFORMATION // Size=4 1124 | { 1125 | ULONG PrefetchPatchCount; // Size=4 Offset=0 1126 | }; 1127 | 1128 | struct _SYSTEM_VERIFIER_FAULTS_INFORMATION // Size=24 1129 | { 1130 | ULONG Probability; // Size=4 Offset=0 1131 | ULONG MaxProbability; // Size=4 Offset=4 1132 | UNICODE_STRING PoolTags; // Size=8 Offset=8 1133 | UNICODE_STRING Applications; // Size=8 Offset=16 1134 | }; 1135 | 1136 | struct _SYSTEM_SYSTEM_PARTITION_INFORMATION // Size=8 1137 | { 1138 | UNICODE_STRING SystemPartition; // Size=8 Offset=0 1139 | }; 1140 | 1141 | struct _SYSTEM_SYSTEM_DISK_INFORMATION // Size=8 1142 | { 1143 | UNICODE_STRING SystemDisk; // Size=8 Offset=0 1144 | }; 1145 | 1146 | struct _SYSTEM_CODEINTEGRITY_INFORMATION // Size=8 1147 | { 1148 | ULONG Length; // Size=4 Offset=0 1149 | ULONG CodeIntegrityOptions; // Size=4 Offset=4 1150 | }; 1151 | 1152 | struct _SYSTEM_PROCESSOR_MICROCODE_UPDATE_INFORMATION // Size=4 1153 | { 1154 | ULONG Operation; // Size=4 Offset=0 1155 | }; 1156 | 1157 | 1158 | struct _SYSTEM_REGISTRY_APPEND_STRING_PARAMETERS // Size=36 1159 | { 1160 | PVOID KeyHandle; // Size=4 Offset=0 1161 | PUNICODE_STRING ValueNamePointer; // Size=4 Offset=4 1162 | ULONG_PTR RequiredLengthPointer; // Size=4 Offset=8 1163 | PUCHAR Buffer; // Size=4 Offset=12 1164 | ULONG BufferLength; // Size=4 Offset=16 1165 | ULONG Type; // Size=4 Offset=20 1166 | PUCHAR AppendBuffer; // Size=4 Offset=24 1167 | ULONG AppendBufferLength; // Size=4 Offset=28 1168 | UCHAR CreateIfDoesntExist; // Size=1 Offset=32 1169 | UCHAR TruncateExistingValue; // Size=1 Offset=33 1170 | }; 1171 | 1172 | struct _SYSTEM_VHD_BOOT_INFORMATION // Size=12 1173 | { 1174 | UCHAR OsDiskIsVhd; // Size=1 Offset=0 1175 | ULONG OsVhdFilePathOffset; // Size=4 Offset=4 1176 | WCHAR OsVhdParentVolume[1]; // Size=2 Offset=8 1177 | }; 1178 | 1179 | struct _SYSTEM_ERROR_PORT_TIMEOUTS // Size=8 1180 | { 1181 | ULONG StartTimeout; // Size=4 Offset=0 1182 | ULONG CommTimeout; // Size=4 Offset=4 1183 | }; 1184 | 1185 | struct _SYSTEM_LOW_PRIORITY_IO_INFORMATION // Size=40 1186 | { 1187 | ULONG LowPriReadOperations; // Size=4 Offset=0 1188 | ULONG LowPriWriteOperations; // Size=4 Offset=4 1189 | ULONG KernelBumpedToNormalOperations; // Size=4 Offset=8 1190 | ULONG LowPriPagingReadOperations; // Size=4 Offset=12 1191 | ULONG KernelPagingReadsBumpedToNormal; // Size=4 Offset=16 1192 | ULONG LowPriPagingWriteOperations; // Size=4 Offset=20 1193 | ULONG KernelPagingWritesBumpedToNormal; // Size=4 Offset=24 1194 | ULONG BoostedIrpCount; // Size=4 Offset=28 1195 | ULONG BoostedPagingIrpCount; // Size=4 Offset=32 1196 | ULONG BlanketBoostCount; // Size=4 Offset=36 1197 | }; 1198 | 1199 | struct _SYSTEM_VERIFIER_COUNTERS_INFORMATION // Size=168 1200 | { 1201 | SYSTEM_VERIFIER_INFORMATION Legacy; // Size=104 Offset=0 1202 | ULONG RaiseIrqls; // Size=4 Offset=104 1203 | ULONG AcquireSpinLocks; // Size=4 Offset=108 1204 | ULONG SynchronizeExecutions; // Size=4 Offset=112 1205 | ULONG AllocationsWithNoTag; // Size=4 Offset=116 1206 | ULONG AllocationsFailed; // Size=4 Offset=120 1207 | ULONG AllocationsFailedDeliberately; // Size=4 Offset=124 1208 | ULONG LockedBytes; // Size=4 Offset=128 1209 | ULONG PeakLockedBytes; // Size=4 Offset=132 1210 | ULONG MappedLockedBytes; // Size=4 Offset=136 1211 | ULONG PeakMappedLockedBytes; // Size=4 Offset=140 1212 | ULONG MappedIoSpaceBytes; // Size=4 Offset=144 1213 | ULONG PeakMappedIoSpaceBytes; // Size=4 Offset=148 1214 | ULONG PagesForMdlBytes; // Size=4 Offset=152 1215 | ULONG PeakPagesForMdlBytes; // Size=4 Offset=156 1216 | ULONG ContiguousMemoryBytes; // Size=4 Offset=160 1217 | ULONG PeakContiguousMemoryBytes; // Size=4 Offset=164 1218 | }; 1219 | 1220 | struct _SYSTEM_ACPI_AUDIT_INFORMATION // Size=8 1221 | { 1222 | ULONG RsdpCount; // Size=4 Offset=0 1223 | struct 1224 | { 1225 | ULONG SameRsdt : 1; // Size=4 Offset=4 BitOffset=0 BitCount=1 1226 | ULONG SlicPresent : 1; // Size=4 Offset=4 BitOffset=1 BitCount=1 1227 | ULONG SlicDifferent : 1; // Size=4 Offset=4 BitOffset=2 BitCount=1 1228 | }; 1229 | }; 1230 | 1231 | struct _SYSTEM_BASIC_PERFORMANCE_INFORMATION // Size=16 1232 | { 1233 | ULONG AvailablePages; // Size=4 Offset=0 1234 | ULONG CommittedPages; // Size=4 Offset=4 1235 | ULONG CommitLimit; // Size=4 Offset=8 1236 | ULONG PeakCommitment; // Size=4 Offset=12 1237 | }; 1238 | 1239 | typedef struct _QUERY_PERFORMANCE_COUNTER_FLAGS // Size=4 1240 | { 1241 | struct 1242 | { 1243 | ULONG KernelTransition : 1; // Size=4 Offset=0 BitOffset=0 BitCount=1 1244 | ULONG Reserved : 31; // Size=4 Offset=0 BitOffset=1 BitCount=31 1245 | }; 1246 | ULONG ul; // Size=4 Offset=0 1247 | } QUERY_PERFORMANCE_COUNTER_FLAGS; 1248 | 1249 | struct _SYSTEM_QUERY_PERFORMANCE_COUNTER_INFORMATION // Size=12 1250 | { 1251 | ULONG Version; // Size=4 Offset=0 1252 | QUERY_PERFORMANCE_COUNTER_FLAGS Flags; // Size=4 Offset=4 1253 | QUERY_PERFORMANCE_COUNTER_FLAGS ValidFlags; // Size=4 Offset=8 1254 | }; 1255 | 1256 | struct _SYSTEM_SESSION_BIGPOOL_INFORMATION // Size=24 1257 | { 1258 | ULONG NextEntryOffset; // Size=4 Offset=0 1259 | ULONG SessionId; // Size=4 Offset=4 1260 | ULONG Count; // Size=4 Offset=8 1261 | SYSTEM_BIGPOOL_ENTRY AllocatedInfo[1]; // Size=12 Offset=12 1262 | }; 1263 | 1264 | typedef enum _SYSTEM_PIXEL_FORMAT 1265 | { 1266 | SystemPixelFormatUnknown = 0, 1267 | SystemPixelFormatR8G8B8 = 1, 1268 | SystemPixelFormatR8G8B8X8 = 2, 1269 | SystemPixelFormatB8G8R8 = 3, 1270 | SystemPixelFormatB8G8R8X8 = 4 1271 | } SYSTEM_PIXEL_FORMAT; 1272 | 1273 | struct _SYSTEM_BOOT_GRAPHICS_INFORMATION // Size=32 1274 | { 1275 | LARGE_INTEGER FrameBuffer; // Size=8 Offset=0 1276 | ULONG Width; // Size=4 Offset=8 1277 | ULONG Height; // Size=4 Offset=12 1278 | ULONG PixelStride; // Size=4 Offset=16 1279 | ULONG Flags; // Size=4 Offset=20 1280 | SYSTEM_PIXEL_FORMAT Format; // Size=4 Offset=24 1281 | }; 1282 | 1283 | typedef struct _PEBS_DS_SAVE_AREA // Size=96 1284 | { 1285 | ULONGLONG BtsBufferBase; // Size=8 Offset=0 1286 | ULONGLONG BtsIndex; // Size=8 Offset=8 1287 | ULONGLONG BtsAbsoluteMaximum; // Size=8 Offset=16 1288 | ULONGLONG BtsInterruptThreshold; // Size=8 Offset=24 1289 | ULONGLONG PebsBufferBase; // Size=8 Offset=32 1290 | ULONGLONG PebsIndex; // Size=8 Offset=40 1291 | ULONGLONG PebsAbsoluteMaximum; // Size=8 Offset=48 1292 | ULONGLONG PebsInterruptThreshold; // Size=8 Offset=56 1293 | ULONGLONG PebsCounterReset0; // Size=8 Offset=64 1294 | ULONGLONG PebsCounterReset1; // Size=8 Offset=72 1295 | ULONGLONG PebsCounterReset2; // Size=8 Offset=80 1296 | ULONGLONG PebsCounterReset3; // Size=8 Offset=88 1297 | } PEBS_DS_SAVE_AREA; 1298 | 1299 | typedef struct _PROCESSOR_PROFILE_CONTROL_AREA // Size=96 1300 | { 1301 | PEBS_DS_SAVE_AREA PebsDsSaveArea; // Size=96 Offset=0 1302 | } *PPROCESSOR_PROFILE_CONTROL_AREA; 1303 | 1304 | struct _SYSTEM_PROCESSOR_PROFILE_CONTROL_AREA // Size=8 1305 | { 1306 | PPROCESSOR_PROFILE_CONTROL_AREA ProcessorProfileControlArea; // Size=4 Offset=0 1307 | UCHAR Allocate; // Size=1 Offset=4 1308 | }; 1309 | 1310 | struct _SYSTEM_ENTROPY_TIMING_INFORMATION // Size=12 1311 | { 1312 | PVOID EntropyRoutine; // Size=4 Offset=0 VOID (* EntropyRoutine)(PVOID,ULONG) 1313 | PVOID InitializationRoutine; // Size=4 Offset=4 VOID ( * InitializationRoutine)(PVOID,ULONG,PVOID) 1314 | PVOID InitializationContext; // Size=4 Offset=8 1315 | }; 1316 | 1317 | struct _SYSTEM_CONSOLE_INFORMATION // Size=4 1318 | { 1319 | ULONG DriverLoaded : 1; // Size=4 Offset=0 BitOffset=0 BitCount=1 1320 | ULONG Spare : 31; // Size=4 Offset=0 BitOffset=1 BitCount=31 1321 | }; 1322 | 1323 | struct _SYSTEM_PLATFORM_BINARY_INFORMATION // Size=24 1324 | { 1325 | ULONGLONG PhysicalAddress; // Size=8 Offset=0 1326 | PVOID HandoffBuffer; // Size=4 Offset=8 1327 | PVOID CommandLineBuffer; // Size=4 Offset=12 1328 | ULONG HandoffBufferSize; // Size=4 Offset=16 1329 | ULONG CommandLineBufferSize; // Size=4 Offset=20 1330 | }; 1331 | 1332 | struct _SYSTEM_DEVICE_DATA_INFORMATION // Size=28 1333 | { 1334 | UNICODE_STRING DeviceId; // Size=8 Offset=0 1335 | UNICODE_STRING DataName; // Size=8 Offset=8 1336 | ULONG DataType; // Size=4 Offset=16 1337 | ULONG DataBufferLength; // Size=4 Offset=20 1338 | PVOID DataBuffer; // Size=4 Offset=24 1339 | }; 1340 | 1341 | typedef struct _PHYSICAL_CHANNEL_RUN // Size=32 1342 | { 1343 | ULONG NodeNumber; // Size=4 Offset=0 1344 | ULONG ChannelNumber; // Size=4 Offset=4 1345 | ULONGLONG BasePage; // Size=8 Offset=8 1346 | ULONGLONG PageCount; // Size=8 Offset=16 1347 | ULONG Flags; // Size=4 Offset=24 1348 | } PHYSICAL_CHANNEL_RUN; 1349 | 1350 | struct _SYSTEM_MEMORY_TOPOLOGY_INFORMATION // Size=48 1351 | { 1352 | ULONGLONG NumberOfRuns; // Size=8 Offset=0 1353 | ULONG NumberOfNodes; // Size=4 Offset=8 1354 | ULONG NumberOfChannels; // Size=4 Offset=12 1355 | PHYSICAL_CHANNEL_RUN Run[1]; // Size=32 Offset=16 1356 | }; 1357 | 1358 | struct _SYSTEM_MEMORY_CHANNEL_INFORMATION // Size=40 1359 | { 1360 | ULONG ChannelNumber; // Size=4 Offset=0 1361 | ULONG ChannelHeatIndex; // Size=4 Offset=4 1362 | ULONGLONG TotalPageCount; // Size=8 Offset=8 1363 | ULONGLONG ZeroPageCount; // Size=8 Offset=16 1364 | ULONGLONG FreePageCount; // Size=8 Offset=24 1365 | ULONGLONG StandbyPageCount; // Size=8 Offset=32 1366 | }; 1367 | 1368 | struct _SYSTEM_BOOT_LOGO_INFORMATION // Size=8 1369 | { 1370 | ULONG Flags; // Size=4 Offset=0 1371 | ULONG BitmapOffset; // Size=4 Offset=4 1372 | }; 1373 | 1374 | struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION_EX // Size=72 1375 | { 1376 | LARGE_INTEGER IdleTime; // Size=8 Offset=0 1377 | LARGE_INTEGER KernelTime; // Size=8 Offset=8 1378 | LARGE_INTEGER UserTime; // Size=8 Offset=16 1379 | LARGE_INTEGER DpcTime; // Size=8 Offset=24 1380 | LARGE_INTEGER InterruptTime; // Size=8 Offset=32 1381 | ULONG InterruptCount; // Size=4 Offset=40 1382 | ULONG Spare0; // Size=4 Offset=44 1383 | LARGE_INTEGER AvailableTime; // Size=8 Offset=48 1384 | LARGE_INTEGER Spare1; // Size=8 Offset=56 1385 | LARGE_INTEGER Spare2; // Size=8 Offset=64 1386 | }; 1387 | 1388 | struct _SYSTEM_SECUREBOOT_POLICY_INFORMATION // Size=24 1389 | { 1390 | GUID PolicyPublisher; // Size=16 Offset=0 1391 | ULONG PolicyVersion; // Size=4 Offset=16 1392 | ULONG PolicyOptions; // Size=4 Offset=20 1393 | }; 1394 | 1395 | struct _SYSTEM_SECUREBOOT_INFORMATION // Size=2 1396 | { 1397 | UCHAR SecureBootEnabled; // Size=1 Offset=0 1398 | UCHAR SecureBootCapable; // Size=1 Offset=1 1399 | }; 1400 | 1401 | struct _SYSTEM_PORTABLE_WORKSPACE_EFI_LAUNCHER_INFORMATION // Size=1 1402 | { 1403 | UCHAR EfiLauncherEnabled; // Size=1 Offset=0 1404 | }; 1405 | 1406 | 1407 | 1408 | // ------------------------------------------------------------ ------------- 1409 | 1410 | typedef struct _OBJECT_TYPE_INFORMATION 1411 | { 1412 | UNICODE_STRING Name; 1413 | ULONG TotalNumberOfObjects; 1414 | ULONG TotalNumberOfHandles; 1415 | ULONG TotalPagedPoolUsage; 1416 | ULONG TotalNonPagedPoolUsage; 1417 | ULONG TotalNamePoolUsage; 1418 | ULONG TotalHandleTableUsage; 1419 | ULONG HighWaterNumberOfObjects; 1420 | ULONG HighWaterNumberOfHandles; 1421 | ULONG HighWaterPagedPoolUsage; 1422 | ULONG HighWaterNonPagedPoolUsage; 1423 | ULONG HighWaterNamePoolUsage; 1424 | ULONG HighWaterHandleTableUsage; 1425 | ULONG InvalidAttributes; 1426 | GENERIC_MAPPING GenericMapping; 1427 | ULONG ValidAccess; 1428 | BOOLEAN SecurityRequired; 1429 | BOOLEAN MaintainHandleCount; 1430 | USHORT MaintainTypeList; 1431 | POOL_TYPE PoolType; 1432 | ULONG PagedPoolUsage; 1433 | ULONG NonPagedPoolUsage; 1434 | } OBJECT_TYPE_INFORMATION, * POBJECT_TYPE_INFORMATION; 1435 | 1436 | // ------------------------------------------------------------ ------------- 1437 | 1438 | 1439 | 1440 | typedef LONG NTSTATUS; 1441 | 1442 | 1443 | typedef struct _IO_STATUS_BLOCK 1444 | { 1445 | union 1446 | { 1447 | NTSTATUS Status; 1448 | 1449 | PVOID Pointer; 1450 | }; 1451 | 1452 | ULONG_PTR Information; 1453 | } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; 1454 | 1455 | 1456 | typedef void (WINAPI* PIO_APC_ROUTINE)(PVOID, PIO_STATUS_BLOCK, DWORD); 1457 | 1458 | 1459 | typedef LONG TDI_STATUS; 1460 | 1461 | typedef PVOID CONNECTION_CONTEXT; ; // connection context 1462 | 1463 | 1464 | typedef struct _TDI_REQUEST 1465 | { 1466 | union 1467 | { 1468 | HANDLE AddressHandle; 1469 | 1470 | CONNECTION_CONTEXT ConnectionContext; 1471 | 1472 | HANDLE ControlChannel; 1473 | } Handle; 1474 | 1475 | 1476 | PVOID RequestNotifyObject; 1477 | 1478 | PVOID RequestContext; 1479 | 1480 | TDI_STATUS TdiStatus; 1481 | } TDI_REQUEST, *PTDI_REQUEST; 1482 | 1483 | 1484 | typedef struct _TDI_CONNECTION_INFORMATION 1485 | { 1486 | LONG UserDataLength; // length of user data buffer 1487 | 1488 | PVOID UserData; // pointer to user data buffer 1489 | 1490 | LONG OptionsLength; // length of following buffer 1491 | 1492 | PVOID Options; // pointer to buffer containing options 1493 | 1494 | LONG RemoteAddressLength; // length of following buffer 1495 | 1496 | PVOID RemoteAddress; // buffer containing the remote address 1497 | } TDI_CONNECTION_INFORMATION, *PTDI_CONNECTION_INFORMATION; 1498 | 1499 | 1500 | typedef struct _TDI_REQUEST_QUERY_INFORMATION 1501 | { 1502 | TDI_REQUEST Request; 1503 | 1504 | ULONG QueryType; // class of information to be queried. 1505 | 1506 | PTDI_CONNECTION_INFORMATION RequestConnectionInformation; 1507 | } TDI_REQUEST_QUERY_INFORMATION, *PTDI_REQUEST_QUERY_INFORMATION; 1508 | 1509 | 1510 | #define TDI_QUERY_ADDRESS_INFO 0x00000003 1511 | 1512 | #define IOCTL_TDI_QUERY_INFORMATION CTL_CODE(FILE_DEVICE_TRANSPORT, 4, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) 1513 | 1514 | 1515 | typedef VOID* POBJECT; 1516 | 1517 | 1518 | typedef struct __PUBLIC_OBJECT_TYPE_INFORMATION { 1519 | UNICODE_STRING TypeName; 1520 | ULONG Reserved[22]; 1521 | } PUBLIC_OBJECT_TYPE_INFORMATION, * PPUBLIC_OBJECT_TYPE_INFORMATION; 1522 | 1523 | 1524 | typedef UNICODE_STRING* POBJECT_NAME_INFORMATION; 1525 | 1526 | 1527 | #define ObjectBasicInformation 0 1528 | #define ObjectNameInformation 1 1529 | #define ObjectTypeInformation 2 1530 | 1531 | #define STATUS_SUCCESS ((NTSTATUS)0x00000000L) 1532 | #define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L) 1533 | #define STATUS_BUFFER_OVERFLOW ((NTSTATUS)0x80000005L) 1534 | 1535 | // ------------------------------------------------------------ ------------- 1536 | 1537 | 1538 | typedef NTSTATUS (NTAPI* tNtQuerySystemInformation)( 1539 | _SYSTEM_INFORMATION_CLASS SystemInformationClass, 1540 | PVOID SystemInformation, 1541 | ULONG SystemInformationLength, 1542 | PULONG ReturnLength 1543 | ); 1544 | 1545 | typedef NTSTATUS (NTAPI* tNtQueryObject)( 1546 | HANDLE Handle, 1547 | DWORD ObjectInformationClass, 1548 | PVOID ObjectInformation, 1549 | ULONG ObjectInformationLength, 1550 | PULONG ReturnLength 1551 | ); 1552 | 1553 | typedef NTSTATUS (NTAPI* tNtDeviceIoControlFile)( 1554 | HANDLE FileHandle, 1555 | HANDLE Event, 1556 | PIO_APC_ROUTINE ApcRoutine, 1557 | PVOID ApcContext, 1558 | PIO_STATUS_BLOCK IoStatusBlock, 1559 | ULONG IoControlCode, 1560 | PVOID InputBuffer, 1561 | ULONG InputBufferLength, 1562 | PVOID OutputBuffer, 1563 | ULONG OutputBufferLength 1564 | ); 1565 | 1566 | typedef NTSTATUS (NTAPI* tNtDuplicateObject)( 1567 | HANDLE SourceProcessHandle, 1568 | HANDLE SourceHandle, 1569 | HANDLE TargetProcessHandle, 1570 | PHANDLE TargetHandle, 1571 | ACCESS_MASK DesiredAccess, 1572 | ULONG Attributes, 1573 | ULONG Options 1574 | ); 1575 | 1576 | LPWSTR GetObjectName(HANDLE hObject); 1577 | 1578 | LPWSTR GetObjectTypeName(HANDLE hObject); 1579 | --------------------------------------------------------------------------------