├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── test.yml ├── .gitignore ├── .npmignore ├── .prettierrc ├── .vscode ├── c_cpp_properties.json ├── extensions.json ├── launch.json ├── notes.txt ├── settings.json └── tasks.json ├── LICENSE ├── README-zh.md ├── README.md ├── _config.yml ├── docs ├── assets │ ├── css │ │ └── main.css │ ├── images │ │ ├── icons.png │ │ ├── icons@2x.png │ │ ├── widgets.png │ │ └── widgets@2x.png │ └── js │ │ ├── main.js │ │ └── search.json ├── classes │ └── _lib_win_win_.winwin.html ├── enums │ └── _lib_win_win_.librarynames.html ├── globals.html ├── index.html ├── interfaces │ ├── _lib_ts_common_._asynccallback.html │ ├── _lib_ts_common_._refbuffer.html │ ├── _lib_ts_common_.ffiwin32fns.html │ ├── _lib_ts_common_.refbuffer.html │ ├── _lib_ts_common_.tswin32fnsbasic.html │ ├── _lib_ts_kernel32_err_handling_api_.errhandlingapi.html │ ├── _lib_ts_kernel32_lib_loader_api_fns_.libloaderapifns.html │ ├── _lib_ts_kernel32_process_threads_api_fns_.processthreadsapifns.html │ ├── _lib_ts_kernel32_sys_info_api_.sysinfoapifns.html │ ├── _lib_ts_ref_.ref.html │ ├── _lib_ts_ref_.type.html │ ├── _lib_ts_user32_win_user_fns_.winuserfns.html │ ├── _lib_win_win_.overwriteoptions.html │ └── _lib_win_win_.winwinoptions.html └── modules │ ├── _lib_cpp_comctl32_comm_ctrl_constant_.html │ ├── _lib_cpp_kernel32_err_handling_api_.html │ ├── _lib_cpp_kernel32_lib_loader_api_fns_.html │ ├── _lib_cpp_kernel32_lib_loader_api_type_.html │ ├── _lib_cpp_kernel32_process_threads_api_fns_.html │ ├── _lib_cpp_kernel32_sys_info_api_.html │ ├── _lib_cpp_user32_base_tsd_.html │ ├── _lib_cpp_user32_user_macro_fns_.html │ ├── _lib_cpp_user32_win_base_.html │ ├── _lib_cpp_user32_win_common_.html │ ├── _lib_cpp_user32_win_def_.html │ ├── _lib_cpp_user32_win_gdi_.html │ ├── _lib_cpp_user32_win_nls_.html │ ├── _lib_cpp_user32_win_nt_.html │ ├── _lib_cpp_user32_win_ternl_.html │ ├── _lib_cpp_user32_win_user_constant_.html │ ├── _lib_cpp_user32_win_user_fns_.html │ ├── _lib_cpp_user32_win_user_struct_.html │ ├── _lib_cpp_user32_win_user_type_.html │ ├── _lib_cpp_utils_.html │ ├── _lib_ts_common_.html │ ├── _lib_ts_kernel32_err_handling_api_.html │ ├── _lib_ts_kernel32_lib_loader_api_fns_.html │ ├── _lib_ts_kernel32_lib_loader_api_type_.html │ ├── _lib_ts_kernel32_process_threads_api_fns_.html │ ├── _lib_ts_kernel32_sys_info_api_.html │ ├── _lib_ts_ref_.html │ ├── _lib_ts_user32_base_tsd_.html │ ├── _lib_ts_user32_guid_def_.html │ ├── _lib_ts_user32_win_base_.html │ ├── _lib_ts_user32_win_def_.html │ ├── _lib_ts_user32_win_gdi_.html │ ├── _lib_ts_user32_win_nls_.html │ ├── _lib_ts_user32_win_nt_.html │ ├── _lib_ts_user32_win_ternl_.html │ ├── _lib_ts_user32_win_user_fns_.html │ ├── _lib_ts_user32_win_user_struct_.html │ ├── _lib_ts_user32_win_user_type_.html │ └── _lib_win_win_.html ├── example ├── create-thread.js ├── create-window.js └── mouse-hook.js ├── jest.config.js ├── lib ├── cpp │ ├── comctl32 │ │ ├── comm_ctrl_constant.ts │ │ └── index.ts │ ├── index.ts │ ├── kernel32 │ │ ├── err_handling_api.ts │ │ ├── index.ts │ │ ├── lib_loader_api_fns.ts │ │ ├── lib_loader_api_type.ts │ │ ├── process_threads_api_fns.ts │ │ └── sys_info_api.ts │ ├── string │ │ └── index.ts │ ├── user32 │ │ ├── base_tsd.ts │ │ ├── index.ts │ │ ├── user_macro_fns.ts │ │ ├── win_base.ts │ │ ├── win_common.ts │ │ ├── win_def.ts │ │ ├── win_gdi.ts │ │ ├── win_nls.ts │ │ ├── win_nt.ts │ │ ├── win_ternl.ts │ │ ├── win_user_constant.ts │ │ ├── win_user_fns.ts │ │ ├── win_user_struct.ts │ │ └── win_user_type.ts │ └── utils.ts ├── index.ts ├── library.ts ├── ts │ ├── common.ts │ ├── index.ts │ ├── kernel32 │ │ ├── err_handling_api.ts │ │ ├── index.ts │ │ ├── lib_loader_api_fns.ts │ │ ├── lib_loader_api_type.ts │ │ ├── process_threads_api_fns.ts │ │ └── sys_info_api.ts │ ├── ref.ts │ └── user32 │ │ ├── base_tsd.ts │ │ ├── guid_def.ts │ │ ├── index.ts │ │ ├── win_base.ts │ │ ├── win_def.ts │ │ ├── win_gdi.ts │ │ ├── win_nls.ts │ │ ├── win_nt.ts │ │ ├── win_ternl.ts │ │ ├── win_user_fns.ts │ │ ├── win_user_struct.ts │ │ └── win_user_type.ts └── win32-ffi.ts ├── package.json ├── scripts └── win_cpp_fns_to_ts_generator.js ├── tea.yaml ├── temp └── legacy │ ├── libloaderapi.ffi.5n69s0sihf800.txt │ ├── libloaderapi.type.5n69s0sihf800.txt │ ├── processthreadsapi.ffi.5n92fwp7u6000.txt │ ├── processthreadsapi.type.5n92fwp7u6000.txt │ ├── winuser.ffi.fns.5n6huvp09fs00.txt │ └── winuser.type.fns.5n6huvp09fs00.txt ├── tsconfig.json └── typedoc.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_size = 2 6 | indent_style = tab 7 | trim_trailing_whitespace = false 8 | insert_final_newline = false 9 | 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | build 4 | temp 5 | example 6 | test 7 | jest.config.js 8 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es6": true, 5 | "node": true 6 | }, 7 | "extends": [ 8 | "plugin:@typescript-eslint/eslint-recommended", 9 | "plugin:@typescript-eslint/recommended", 10 | "eslint:recommended" 11 | ], 12 | "parser": "@typescript-eslint/parser", 13 | "plugins": [ 14 | "@typescript-eslint" 15 | ], 16 | "parserOptions": { 17 | "ecmaVersion": 2019, 18 | "sourceType": "module" 19 | }, 20 | "rules": { 21 | "semi": "warn", 22 | "no-multiple-empty-lines": [ 23 | "error", 24 | { 25 | "max": 1 26 | } 27 | ], 28 | "no-undef": "error", 29 | "no-multi-spaces": [ 30 | "error", 31 | { 32 | "ignoreEOLComments": true 33 | } 34 | ], 35 | "no-unused-vars": "warn", 36 | "no-console": [ 37 | "error", 38 | { 39 | "allow": [ 40 | "warn", 41 | "log", 42 | "trace", 43 | "time", 44 | "timeEnd", 45 | "info", 46 | "table", 47 | "error" 48 | ] 49 | } 50 | ], 51 | "@typescript-eslint/no-var-requires": 0, 52 | "@typescript-eslint/no-non-null-assertion": 0, 53 | "@typescript-eslint/no-explicit-any": 0, 54 | "@typescript-eslint/no-empty-interface": 0, 55 | "@typescript-eslint/explicit-function-return-type": 0, 56 | "@typescript-eslint/no-object-literal-type-assertion": 0, 57 | "@typescript-eslint/explicit-member-accessibility": 0, 58 | "@typescript-eslint/triple-slash-reference": 0, 59 | "@typescript-eslint/no-empty-function": 0, 60 | "import/no-unresolved": 0, 61 | "@typescript-eslint/ban-ts-ignore": 0, 62 | "no-extra-boolean-cast": 0, 63 | "no-mixed-spaces-and-tabs": 0, 64 | // 修复interface unused 的问题 65 | "@typescript-eslint/no-unused-vars": [ 66 | "error", 67 | { 68 | "args": "none" 69 | } 70 | ], 71 | "@typescript-eslint/no-use-before-define": 0 72 | } 73 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | linguist-language=cpp -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # name: Test 2 | 3 | # on: 4 | # push: 5 | # branches: 6 | # - "master" 7 | # paths-ignore: 8 | # - "temp/**" 9 | # - "example/**" 10 | # - ".vscode/**" 11 | # - "docs/**" 12 | # - "*.md" 13 | 14 | # jobs: 15 | # build: 16 | # runs-on: {{matrix.os}} 17 | # strategy: 18 | # matrix: 19 | # os: [windows-latest] 20 | # node: [14, 16] 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | build/ 3 | coverage 4 | node_modules/ 5 | *.log 6 | package-lock.json 7 | bak 8 | .unotes 9 | test 10 | .vscode/settings.json 11 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | temp 2 | bak 3 | .unotes 4 | lib 5 | docs -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "singleQuote": true 4 | } -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "C:/Program Files (x86)/Windows Kits/10/Include", 8 | "C:/Program Files (x86)/Windows Kits/", 9 | "C:/Users/sewer/Desktop/behinder/addon/node_modules/node-addon-api", 10 | "C:/Users/sewer/.node-gyp/10.16.3/include/node", 11 | "C:/Qt/Qt5.9.9/5.9.9/msvc2015_64/include" 12 | ], 13 | "defines": [ 14 | "_DEBUG", 15 | "UNICODE", 16 | "_UNICODE" 17 | ], 18 | "windowsSdkVersion": "10.0.18362.0", 19 | "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe", 20 | "cStandard": "c11", 21 | "cppStandard": "c++17", 22 | "intelliSenseMode": "msvc-x64" 23 | } 24 | ], 25 | "version": 4 26 | } -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. 3 | // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp 4 | 5 | // List of extensions which should be recommended for users of this workspace. 6 | "recommendations": [ 7 | 8 | ], 9 | // List of extensions recommended by VS Code that should not be recommended for users of this workspace. 10 | "unwantedRecommendations": [ 11 | 12 | ] 13 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "(Windows) Launch", 9 | "type": "cppvsdbg", 10 | "request": "launch", 11 | "program": "C:/Users/sewer/nvm/v10.16.3/node.exe", 12 | "args": [ 13 | "${workspaceFolder}/lib/index.js" 14 | ], 15 | "stopAtEntry": false, 16 | "cwd": "${workspaceFolder}", 17 | "environment": [], 18 | "externalConsole": false, 19 | "preLaunchTask": "npm-run-dev", 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /.vscode/notes.txt: -------------------------------------------------------------------------------- 1 | ShowWindow 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace Napi; 10 | using namespace std; 11 | 12 | template 13 | 14 | size_t GetLength(T &arr) 15 | { 16 | return sizeof(arr) / sizeof(arr[0]); 17 | } 18 | 19 | Value HasWindowHandle(CallbackInfo &info) 20 | { 21 | Env env = info.Env(); 22 | // cout << info[0].IsBuffer(); 23 | // Uint32Array array = info[0].As(); 24 | 25 | // if (info[0].IsBuffer()) 26 | // { 27 | 28 | // ArrayBuffer::New(env ,info[0]); 29 | // Buffer::New(env, info[0], GetLength(info), ); 30 | // } 31 | // cout << env << endl; 32 | // HWND window_handle = FindWindow(_T("Progman"), nullptr); 33 | 34 | // HWND window_handle = FindWindow(_T("Progman"), nullptr); 35 | // int result; 36 | // RECT rect; 37 | // GetWindowRect(window_handle, &rect); 38 | // SendMessageTimeout(window_handle, 0x052c, 0, 0, SMTO_NORMAL, 0x3e8, (PDWORD_PTR)&result); 39 | // cout << rect.right - rect.left << rect.bottom - rect.top << endl; 40 | return String::New(env, "Hello World"); 41 | } 42 | 43 | void FindWindowHandle(const CallbackInfo &info) 44 | { 45 | // Env env = info.Env(); 46 | 47 | // cout << info[0].As().ToString(); 48 | 49 | if (info[0].IsBuffer()) 50 | { 51 | Buffer val = info[0].As>(); 52 | LPCSTR data_string = val.Data(); 53 | 54 | // int data_len = strlen(data_string); 55 | // wchar_t *w_data_string = new wchar_t[data_len]; 56 | // MultiByteToWideChar(0, 0, data_string, data_len, w_data_string, 0); 57 | HWND window_handle = FindWindowA(data_string, nullptr); 58 | RECT rect; 59 | GetWindowRect(window_handle, &rect); 60 | cout << "width:" << rect.bottom - rect.top << "\n"; 61 | } 62 | } 63 | 64 | int pWindowCount = 0; 65 | int cWindowCount = 0; 66 | BOOL CALLBACK EnumChildWindowsProc(HWND handle, LPARAM lParam) 67 | { 68 | LPSTR child_title = ""; 69 | 70 | GetWindowTextA(handle, child_title, 100); 71 | printf("\t=====child:%hs\n", child_title); 72 | return true; 73 | } 74 | 75 | BOOL CALLBACK EnumWindowsProc(HWND handle, LPARAM lParam) 76 | { 77 | 78 | if (GetParent(handle) == nullptr && IsWindowVisible(handle)) 79 | { 80 | #ifdef UNICODE 81 | WCHAR *title = new WCHAR[100]; 82 | GetWindowText(handle, title, 100); 83 | #else 84 | char *title = new char[100]; 85 | GetWindowText(handle, title, 100); 86 | #endif 87 | printf("%s %d\n", title, IsWindowUnicode(handle)); 88 | EnumChildWindows(handle, EnumChildWindowsProc, NULL); 89 | } 90 | return true; 91 | } 92 | 93 | void EnumAllWindows(const CallbackInfo &info) 94 | { 95 | EnumWindows(EnumWindowsProc, NULL); 96 | } 97 | 98 | void EnumDesktop(const CallbackInfo &info) 99 | { 100 | HWND handle = GetDesktopWindow(); 101 | handle = GetWindow(handle, GW_CHILD); 102 | #ifdef UNICODE 103 | WCHAR *title = new WCHAR[200]; 104 | #else 105 | char *title = new char[200]; 106 | #endif 107 | GetWindowText(handle, title, 200); 108 | cout << title; 109 | // int num = 1; 110 | // while (handle != NULL) 111 | // { 112 | // GetWindowText(handle, title, 200); 113 | // cout << num++ << ": " << title << endl; 114 | // handle = GetNextWindow(handle, GW_HWNDNEXT); 115 | // } 116 | } 117 | 118 | void CreateAWindow(const CallbackInfo &info) 119 | { 120 | const wchar_t CLASS_NAME[] = L"Demo"; 121 | // WNDCLASS wc = {}; 122 | // wc. 123 | } 124 | 125 | Object Init(Env env, Object exports) 126 | { 127 | 128 | exports.Set(String::New(env, "findWindowHandle"), Function::New(env, FindWindowHandle)); 129 | exports.Set(String::New(env, "enumAllWindows"), Function::New(env, EnumAllWindows)); 130 | exports.Set(String::New(env, "enumDesktop"), Function::New(env, EnumDesktop)); 131 | exports.Set(String::New(env, "createWindow"), Function::New(env, CreateAWindow)); 132 | return exports; 133 | } 134 | 135 | NODE_API_MODULE(behinder, Init); -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.enabled": false 3 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "npm", 6 | "script": "dev", 7 | "group": { 8 | "kind": "build", 9 | "isDefault": true 10 | }, 11 | "problemMatcher": [], 12 | "label": "npm-run-dev", 13 | "detail": "node-gyp build --debug" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /README-zh.md: -------------------------------------------------------------------------------- 1 | 2 | # Win-Win 3 | 4 | 5 | ## Usage 6 | 7 | 1. 如果无法获取确定的C++参数类型,所以 你可创建一个文件 重写这个函数 8 | 9 | ```ts 10 | overwrite.ts 11 | 12 | import { CPP, ref } from 'win-win'; 13 | export const customFns = { 14 | CallNextHookEx: [CPP.LRESULT, [CPP.HHOOK, CPP.INT, CPP.WPARAM, ref.refType(CPP.MOUSEHOOKSTRUCT)]] 15 | }; 16 | ``` 17 | 18 | ```ts 19 | index.ts 20 | 21 | import { customFns } from './overwrite'; 22 | WinWin.overwrite({ user32Fns: customFns }); 23 | ``` 24 | 25 | ## Notice 26 | 27 | - ***win-win 不可能包含所有win api 如果没有提示,那就意味着你需要自己定义*** 28 | 29 | - win-win 没有包含Comctl32, 因为几乎都是宏定义的函数 但是你可以用`SendMessage`实现, winwin提供了部分常量 30 | 31 | --- 32 |
33 | 34 | ## Tutorial 35 |
36 | 37 | - Struct 38 | 39 | ```ts 40 | import {ref, DefStruct,CPP} from 'win-win'; 41 | 42 | const Struct = DefStruct(ref); 43 | 44 | const MSG = Struct({ 45 | hwnd: CPP.HWND, 46 | message: CPP.UINT, 47 | wParam: CPP.WPARAM, 48 | lParam: CPP.LPARAM, 49 | time: CPP.DWORD, 50 | pt: CPP.POINT 51 | }); 52 | const msg = new MSG(); 53 | console.log(msg.ref()); 54 | ``` 55 | 56 | --- 57 |
58 | 59 | - 由于ffi无法 使用 c++ #define 的宏函数, 所以MAKEWPARAM,MAKELPARAM等等只能实现对数字的s操作 具体见`*_macro_fns.ts`的文件 60 | 61 | ```ts 62 | 63 | export const MAKELONG = (a: number, b: number): number => (a & 0xfff) | ((b & 0xfff) << 16); 64 | 65 | ``` 66 | --- 67 |
68 | 69 | - ffi 无法强制类型转换, 所以你需要使用refType 定义好类型 70 | 71 | - c++ 72 | 73 | ```cpp 74 | MOUSEHOOKSTRUCT* mouse = (MOUSEHOOKSTRUCT*)(lParam) 75 | ``` 76 | 77 | - ts 78 | 79 | ```ts 80 | ffi.Callback(CPP.LRESULT, [CPP.INT, CPP.WPARAM, ref.refType(CPP.MOUSEHOOKSTRUCT)],(nCode: TS.INT, wParam: TS.WPARAM, lParam: TS.RefStruct) => {}) 81 | ``` 82 | --- 83 |
84 | 85 | - 创建线程 86 | ```ts 87 | const { WinWin, ffi, CPP, L } = require('win-win'); 88 | 89 | const { CreateThread, MessageBoxW } = new WinWin().winFns(); 90 | 91 | const proc = ffi.Callback('int32', ['void*'], () => { 92 | MessageBoxW(0, L("exmpale"), null, CPP.MB_OK | CPP.MB_ICONEXCLAMATION); 93 | }); 94 | 95 | CreateThread(null, 0, proc, Buffer.alloc(0), 0, Buffer.alloc(0)); 96 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## win32-ffi 2 | 3 | win32 api binding for nodejs 4 | 5 | ## Install 6 | 7 | `npm i win32-ffi`/`yarn add win32-ffi` 8 | 9 | ## Usage 10 | 11 |
12 | 13 | * Since ffi cannot use the macro function of c++ #define, MAKEWPARAM, MAKELPARAM, etc. can only realize the operation of the numbers. For details, please refer to the document of `user_macro_fns.ts` 14 | 15 | ```ts 16 | export const MAKELONG = (a: number, b: number): number => (a & 0xfff) | ((b & 0xfff) << 16); 17 | ``` 18 | 19 | --- 20 | 21 |
22 | 23 | - ffi cannot force type conversion, so you need to use refType to define the type 24 | 25 | c++ 26 | 27 | ```cpp 28 | MOUSEHOOKSTRUCT* mouse = (MOUSEHOOKSTRUCT*)(lParam) 29 | ``` 30 | 31 | ts 32 | 33 | ```ts 34 | ffi.Callback(CPP.LRESULT, [CPP.INT, CPP.WPARAM, ref.refType(CPP.MOUSEHOOKSTRUCT)],(nCode: TS.INT, wParam: TS.WPARAM, lParam: TS.RefStruct) => {}) 35 | ``` 36 | 37 | --- 38 | 39 | ### Electron 40 | 41 | ```ts 42 | 43 | // get system endianness, cast Buffer to decimal 44 | const bufferCastInt32 = function (buf: Buffer): number { 45 | return os.endianness() == "LE" ? buf.readInt32LE() : buf.readInt32BE(); 46 | }; 47 | 48 | const mainWindow = new BrowserWindow({ 49 | frame: false, 50 | transparent: true, 51 | webPreferences: { 52 | nodeIntegration: true, 53 | webSecurity: false, 54 | webviewTag: true, 55 | sandbox: false, 56 | enableRemoteModule: true 57 | } 58 | }); 59 | 60 | const decimalHwnd = bufferCastInt32(mainWindow.getNativeWindowHandle()); 61 | SetWindowPos(decimalHwnd, 0, 0, 0, 100, 100, CPP.SWP_NOZORDER); 62 | 63 | ``` 64 | 65 | ### Samples 66 | 67 | - Create thread 68 | 69 | ```ts 70 | const { Win32ffi, ffi, CPP, L, NULL } = require('win32-ffi'); 71 | 72 | const { CreateThread, MessageBoxW } = new Win32ffi().winFns(); 73 | 74 | const proc = ffi.Callback(CPP.INT, [CPP.PVOID], () => { 75 | MessageBoxW(0, L("exmpale"), null, CPP.MB_OK | CPP.MB_ICONEXCLAMATION); 76 | }); 77 | 78 | CreateThread(null, 0, proc, NULL, 0, NULL); 79 | ``` 80 | 81 | - Create Mouse Hook 82 | 83 | ```ts 84 | const _createMouseHookProc = () => ffi.Callback(CPP.LRESULT, [CPP.INT, CPP.WPARAM, ref.refType(CPP.StructMOUSEHOOKSTRUCT)], 85 | (nCode: TS.INT, wParam: TS.WPARAM, lParam: TS.RefStruct) => { 86 | const mouse: TS.MOUSEHOOKSTRUCT = lParam.deref(); 87 | const pt = mouse.pt; 88 | const { x, y } = pt; 89 | const currentHwnd = WindowFromPoint(mouse.pt); 90 | return CallNextHookEx(0, nCode, wParam, lParam); // need overwrite 91 | } 92 | ) 93 | 94 | const _mouseHook = SetWindowsHookExW(CPP.WH_MOUSE_LL, this._createMouseHookProc(), 0, 0); 95 | const msg: TS.RefStruct = new CPP.StructMSG(); 96 | 97 | while (GetMessageW(msg.ref(), 0, 0, 0) && this._trigger) { 98 | TranslateMessage(msg.ref()); 99 | DispatchMessageW(msg.ref()); 100 | } 101 | 102 | UnhookWindowsHookEx(_mouseHook); 103 | ``` 104 | 105 | ### More Examples 106 | 107 | **[Exmaples](./example)** 108 | 109 | ### [API DOCS](https://deskbtm.github.io/win32-ffi/) 110 | 111 | ### Main Api 112 | 113 | * Win32ffi 114 | 115 | ```ts 116 | const win32ffi =new Win32ffi(); 117 | 118 | win32ffi.user32(); 119 | win32ffi.kernel32(); 120 | 121 | const winFns = win32ffi.winFns(); // include user32 and kernel32 122 | 123 | const _createEnumWindowProc = () => ffi.Callback(CPP.BOOL, [CPP.HWND, CPP.LPARAM], 124 | (hWnd: TS.HWND) => { 125 | ...... 126 | return true; 127 | }); 128 | 129 | winFns.EnumWindows(this._createEnumWindowProc(), 0); 130 | ``` 131 | 132 | * L, _T, TEXT _[https://docs.microsoft.com/en-us/windows/win32/learnwin32/working-with-strings]()_ 133 | 134 | ```ts 135 | const tmp: TS.HWND = FindWindowExW(0, 0, L('progman'), null); 136 | ``` 137 | 138 | * ref see [http://tootallnate.github.io/ref/](http://tootallnate.github.io/ref/) 139 | * ffi [https://www.npmjs.com/package/ffi-napi](https://www.npmjs.com/package/ffi-napi) 140 | * NULL = ref.NULL 141 | * Struct 142 | win320ffi provides litte struct e.g `StructRECT` `StructMSG` `StructMOUSEHOOKSTRUCT`... see win_user_struct.ts for more details 143 | 144 | ```ts 145 | import {ref, StructType,CPP} from 'win32-ffi'; 146 | 147 | const Struct = StructType(ref); 148 | 149 | const MSG = Struct({ 150 | hwnd: CPP.HWND, 151 | message: CPP.UINT, 152 | wParam: CPP.WPARAM, 153 | lParam: CPP.LPARAM, 154 | time: CPP.DWORD, 155 | pt: CPP.POINT 156 | }); 157 | const msg = new MSG(); 158 | console.log(msg.ref()); 159 | ``` 160 | 161 | * TS: ts types 162 | * CPP: c++ types that refer to ffi 163 | 164 | Warning 165 | 166 | * If you can't get the certain C++ parameter types, you can create a file and rewrite this function 167 | 168 | ```ts 169 | overwrite.ts 170 | 171 | import { CPP, ref } from 'win32-ffi'; 172 | export const customFns = { 173 | CallNextHookEx: [CPP.LRESULT, [CPP.HHOOK, CPP.INT, CPP.WPARAM, ref.refType(CPP.MOUSEHOOKSTRUCT)]] 174 | }; 175 | ``` 176 | 177 | ```ts 178 | index.ts 179 | 180 | import { customFns } from './overwrite'; 181 | Win32ffi.assign({ user32Fns: customFns }); 182 | ``` 183 | 184 | * win32-ffi does not include Comctl32, because almost all macro-defined functions, but you can use `SendMessage` to achieve, win32ffi provides 185 | * **It is impossible to include all win32 api. If there is no prompt, it means you need to define it by yourself. And you can get type details from visual studio.** 186 | 187 | ## License 188 | 189 | The scripts and documentation in this project are released under the [Apache 2.0 License](./LICENSE) 190 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman 2 | include: 3 | - "_*_.html" 4 | - "_*_.*.html" 5 | -------------------------------------------------------------------------------- /docs/assets/images/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deskbtm/win32-ffi/068f4c866f7359969a83b72726627d3ff1048c74/docs/assets/images/icons.png -------------------------------------------------------------------------------- /docs/assets/images/icons@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deskbtm/win32-ffi/068f4c866f7359969a83b72726627d3ff1048c74/docs/assets/images/icons@2x.png -------------------------------------------------------------------------------- /docs/assets/images/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deskbtm/win32-ffi/068f4c866f7359969a83b72726627d3ff1048c74/docs/assets/images/widgets.png -------------------------------------------------------------------------------- /docs/assets/images/widgets@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deskbtm/win32-ffi/068f4c866f7359969a83b72726627d3ff1048c74/docs/assets/images/widgets@2x.png -------------------------------------------------------------------------------- /docs/interfaces/_lib_ts_common_.ffiwin32fns.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | FfiWin32Fns | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 65 |

Interface FfiWin32Fns

66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |

Hierarchy

74 |
    75 |
  • 76 | FfiWin32Fns 77 |
  • 78 |
79 |
80 |
81 |

Indexable

82 |
[fnName: string]: any[]
83 |
84 |
85 | 135 |
136 |
137 |
138 |
139 |

Legend

140 |
141 |
    142 |
  • Object literal
  • 143 |
  • Variable
  • 144 |
  • Function
  • 145 |
  • Type alias
  • 146 |
  • Type alias with type parameter
  • 147 |
148 |
    149 |
  • Interface
  • 150 |
  • Interface with type parameter
  • 151 |
152 |
    153 |
  • Enumeration
  • 154 |
155 |
    156 |
  • Class
  • 157 |
158 |
159 |
160 |
161 |
162 |

Generated using TypeDoc

163 |
164 |
165 | 166 | 167 | -------------------------------------------------------------------------------- /docs/modules/_lib_cpp_kernel32_err_handling_api_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/cpp/kernel32/err_handling_api" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/cpp/kernel32/err_handling_api"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Object literals

75 | 78 |
79 |
80 |
81 |
82 |
83 |

Object literals

84 |
85 | 86 |

Const errHandlingApi

87 |
errHandlingApi: object
88 | 93 |
94 | 95 |

GetLastError

96 |
GetLastError: (string | never[])[] = [DWORD, []]
97 | 102 |
103 |
104 |
105 |
106 | 125 |
126 |
127 |
128 |
129 |

Legend

130 |
131 |
    132 |
  • Object literal
  • 133 |
  • Variable
  • 134 |
  • Function
  • 135 |
  • Type alias
  • 136 |
  • Type alias with type parameter
  • 137 |
138 |
    139 |
  • Interface
  • 140 |
  • Interface with type parameter
  • 141 |
142 |
    143 |
  • Enumeration
  • 144 |
145 |
    146 |
  • Class
  • 147 |
148 |
149 |
150 |
151 |
152 |

Generated using TypeDoc

153 |
154 |
155 | 156 | 157 | -------------------------------------------------------------------------------- /docs/modules/_lib_cpp_kernel32_sys_info_api_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/cpp/kernel32/sys_info_api" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/cpp/kernel32/sys_info_api"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Object literals

75 | 78 |
79 |
80 |
81 |
82 |
83 |

Object literals

84 |
85 | 86 |

Const sysInfoApiFns

87 |
sysInfoApiFns: object
88 | 93 |
94 | 95 |

GetTickCount

96 |
GetTickCount: (string | never[])[] = [DWORD, []]
97 | 102 |
103 |
104 |
105 |
106 | 125 |
126 |
127 |
128 |
129 |

Legend

130 |
131 |
    132 |
  • Object literal
  • 133 |
  • Variable
  • 134 |
  • Function
  • 135 |
  • Type alias
  • 136 |
  • Type alias with type parameter
  • 137 |
138 |
    139 |
  • Interface
  • 140 |
  • Interface with type parameter
  • 141 |
142 |
    143 |
  • Enumeration
  • 144 |
145 |
    146 |
  • Class
  • 147 |
148 |
149 |
150 |
151 |
152 |

Generated using TypeDoc

153 |
154 |
155 | 156 | 157 | -------------------------------------------------------------------------------- /docs/modules/_lib_cpp_user32_win_nls_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/cpp/user32/win_nls" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/cpp/user32/win_nls"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Variables

75 | 79 |
80 |
81 |
82 |
83 |
84 |

Variables

85 |
86 | 87 |

Const LCID

88 |
LCID: "int32" = _DWORD
89 | 94 |
95 |
96 | 97 |

Const LCTYPE

98 |
LCTYPE: "int32" = _DWORD
99 | 104 |
105 |
106 |
107 | 129 |
130 |
131 |
132 |
133 |

Legend

134 |
135 |
    136 |
  • Object literal
  • 137 |
  • Variable
  • 138 |
  • Function
  • 139 |
  • Type alias
  • 140 |
  • Type alias with type parameter
  • 141 |
142 |
    143 |
  • Interface
  • 144 |
  • Interface with type parameter
  • 145 |
146 |
    147 |
  • Enumeration
  • 148 |
149 |
    150 |
  • Class
  • 151 |
152 |
153 |
154 |
155 |
156 |

Generated using TypeDoc

157 |
158 |
159 | 160 | 161 | -------------------------------------------------------------------------------- /docs/modules/_lib_cpp_user32_win_ternl_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/cpp/user32/win_ternl" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/cpp/user32/win_ternl"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Variables

75 | 78 |
79 |
80 |
81 |
82 |
83 |

Variables

84 |
85 | 86 |

Const UNICODE_STRING

87 |
UNICODE_STRING: "CString" = "CString"
88 | 93 |
94 |
95 |
96 | 115 |
116 |
117 |
118 |
119 |

Legend

120 |
121 |
    122 |
  • Object literal
  • 123 |
  • Variable
  • 124 |
  • Function
  • 125 |
  • Type alias
  • 126 |
  • Type alias with type parameter
  • 127 |
128 |
    129 |
  • Interface
  • 130 |
  • Interface with type parameter
  • 131 |
132 |
    133 |
  • Enumeration
  • 134 |
135 |
    136 |
  • Class
  • 137 |
138 |
139 |
140 |
141 |
142 |

Generated using TypeDoc

143 |
144 |
145 | 146 | 147 | -------------------------------------------------------------------------------- /docs/modules/_lib_ts_kernel32_err_handling_api_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/ts/kernel32/err_handling_api" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/ts/kernel32/err_handling_api"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Interfaces

75 | 78 |
79 |
80 |
81 |
82 |
83 | 102 |
103 |
104 |
105 |
106 |

Legend

107 |
108 |
    109 |
  • Object literal
  • 110 |
  • Variable
  • 111 |
  • Function
  • 112 |
  • Type alias
  • 113 |
  • Type alias with type parameter
  • 114 |
115 |
    116 |
  • Interface
  • 117 |
  • Interface with type parameter
  • 118 |
119 |
    120 |
  • Enumeration
  • 121 |
122 |
    123 |
  • Class
  • 124 |
125 |
126 |
127 |
128 |
129 |

Generated using TypeDoc

130 |
131 |
132 | 133 | 134 | -------------------------------------------------------------------------------- /docs/modules/_lib_ts_kernel32_lib_loader_api_fns_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/ts/kernel32/lib_loader_api_fns" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/ts/kernel32/lib_loader_api_fns"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Interfaces

75 | 78 |
79 |
80 |
81 |
82 |
83 | 102 |
103 |
104 |
105 |
106 |

Legend

107 |
108 |
    109 |
  • Object literal
  • 110 |
  • Variable
  • 111 |
  • Function
  • 112 |
  • Type alias
  • 113 |
  • Type alias with type parameter
  • 114 |
115 |
    116 |
  • Interface
  • 117 |
  • Interface with type parameter
  • 118 |
119 |
    120 |
  • Enumeration
  • 121 |
122 |
    123 |
  • Class
  • 124 |
125 |
126 |
127 |
128 |
129 |

Generated using TypeDoc

130 |
131 |
132 | 133 | 134 | -------------------------------------------------------------------------------- /docs/modules/_lib_ts_kernel32_process_threads_api_fns_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/ts/kernel32/process_threads_api_fns" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/ts/kernel32/process_threads_api_fns"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Interfaces

75 | 78 |
79 |
80 |
81 |
82 |
83 | 102 |
103 |
104 |
105 |
106 |

Legend

107 |
108 |
    109 |
  • Object literal
  • 110 |
  • Variable
  • 111 |
  • Function
  • 112 |
  • Type alias
  • 113 |
  • Type alias with type parameter
  • 114 |
115 |
    116 |
  • Interface
  • 117 |
  • Interface with type parameter
  • 118 |
119 |
    120 |
  • Enumeration
  • 121 |
122 |
    123 |
  • Class
  • 124 |
125 |
126 |
127 |
128 |
129 |

Generated using TypeDoc

130 |
131 |
132 | 133 | 134 | -------------------------------------------------------------------------------- /docs/modules/_lib_ts_kernel32_sys_info_api_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/ts/kernel32/sys_info_api" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/ts/kernel32/sys_info_api"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Interfaces

75 | 78 |
79 |
80 |
81 |
82 |
83 | 102 |
103 |
104 |
105 |
106 |

Legend

107 |
108 |
    109 |
  • Object literal
  • 110 |
  • Variable
  • 111 |
  • Function
  • 112 |
  • Type alias
  • 113 |
  • Type alias with type parameter
  • 114 |
115 |
    116 |
  • Interface
  • 117 |
  • Interface with type parameter
  • 118 |
119 |
    120 |
  • Enumeration
  • 121 |
122 |
    123 |
  • Class
  • 124 |
125 |
126 |
127 |
128 |
129 |

Generated using TypeDoc

130 |
131 |
132 | 133 | 134 | -------------------------------------------------------------------------------- /docs/modules/_lib_ts_ref_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/ts/ref" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/ts/ref"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Interfaces

75 | 79 |
80 |
81 |
82 |
83 |
84 | 106 |
107 |
108 |
109 |
110 |

Legend

111 |
112 |
    113 |
  • Object literal
  • 114 |
  • Variable
  • 115 |
  • Function
  • 116 |
  • Type alias
  • 117 |
  • Type alias with type parameter
  • 118 |
119 |
    120 |
  • Interface
  • 121 |
  • Interface with type parameter
  • 122 |
123 |
    124 |
  • Enumeration
  • 125 |
126 |
    127 |
  • Class
  • 128 |
129 |
130 |
131 |
132 |
133 |

Generated using TypeDoc

134 |
135 |
136 | 137 | 138 | -------------------------------------------------------------------------------- /docs/modules/_lib_ts_user32_guid_def_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/ts/user32/guid_def" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/ts/user32/guid_def"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Type aliases

75 | 79 |
80 |
81 |
82 |
83 |
84 |

Type aliases

85 |
86 | 87 |

GUID

88 |
GUID: Pointer
89 | 94 |
95 |
96 |
        Struct
97 |
98 |
99 |
100 |
101 | 102 |

LPCGUID

103 |
LPCGUID: Pointer
104 | 109 |
110 |
111 |
112 | 134 |
135 |
136 |
137 |
138 |

Legend

139 |
140 |
    141 |
  • Object literal
  • 142 |
  • Variable
  • 143 |
  • Function
  • 144 |
  • Type alias
  • 145 |
  • Type alias with type parameter
  • 146 |
147 |
    148 |
  • Interface
  • 149 |
  • Interface with type parameter
  • 150 |
151 |
    152 |
  • Enumeration
  • 153 |
154 |
    155 |
  • Class
  • 156 |
157 |
158 |
159 |
160 |
161 |

Generated using TypeDoc

162 |
163 |
164 | 165 | 166 | -------------------------------------------------------------------------------- /docs/modules/_lib_ts_user32_win_base_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/ts/user32/win_base" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/ts/user32/win_base"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Type aliases

75 | 79 |
80 |
81 |
82 |
83 |
84 |

Type aliases

85 |
86 | 87 |

LPSECURITY_ATTRIBUTES

88 |
LPSECURITY_ATTRIBUTES: Pointer
89 | 94 |
95 |
96 | 97 |

LPTHREAD_START_ROUTINE

98 |
LPTHREAD_START_ROUTINE: Pointer
99 | 104 |
105 |
106 |
107 | 129 |
130 |
131 |
132 |
133 |

Legend

134 |
135 |
    136 |
  • Object literal
  • 137 |
  • Variable
  • 138 |
  • Function
  • 139 |
  • Type alias
  • 140 |
  • Type alias with type parameter
  • 141 |
142 |
    143 |
  • Interface
  • 144 |
  • Interface with type parameter
  • 145 |
146 |
    147 |
  • Enumeration
  • 148 |
149 |
    150 |
  • Class
  • 151 |
152 |
153 |
154 |
155 |
156 |

Generated using TypeDoc

157 |
158 |
159 | 160 | 161 | -------------------------------------------------------------------------------- /docs/modules/_lib_ts_user32_win_nls_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/ts/user32/win_nls" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/ts/user32/win_nls"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Type aliases

75 | 78 |
79 |
80 |
81 |
82 |
83 |

Type aliases

84 |
85 | 86 |

LCTYPE

87 |
LCTYPE: number
88 | 93 |
94 |
95 |
96 | 115 |
116 |
117 |
118 |
119 |

Legend

120 |
121 |
    122 |
  • Object literal
  • 123 |
  • Variable
  • 124 |
  • Function
  • 125 |
  • Type alias
  • 126 |
  • Type alias with type parameter
  • 127 |
128 |
    129 |
  • Interface
  • 130 |
  • Interface with type parameter
  • 131 |
132 |
    133 |
  • Enumeration
  • 134 |
135 |
    136 |
  • Class
  • 137 |
138 |
139 |
140 |
141 |
142 |

Generated using TypeDoc

143 |
144 |
145 | 146 | 147 | -------------------------------------------------------------------------------- /docs/modules/_lib_ts_user32_win_ternl_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/ts/user32/win_ternl" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/ts/user32/win_ternl"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Type aliases

75 | 78 |
79 |
80 |
81 |
82 |
83 |

Type aliases

84 |
85 | 86 |

UNICODE_STRING

87 |
UNICODE_STRING: string
88 | 93 |
94 |
95 |
96 | 115 |
116 |
117 |
118 |
119 |

Legend

120 |
121 |
    122 |
  • Object literal
  • 123 |
  • Variable
  • 124 |
  • Function
  • 125 |
  • Type alias
  • 126 |
  • Type alias with type parameter
  • 127 |
128 |
    129 |
  • Interface
  • 130 |
  • Interface with type parameter
  • 131 |
132 |
    133 |
  • Enumeration
  • 134 |
135 |
    136 |
  • Class
  • 137 |
138 |
139 |
140 |
141 |
142 |

Generated using TypeDoc

143 |
144 |
145 | 146 | 147 | -------------------------------------------------------------------------------- /docs/modules/_lib_ts_user32_win_user_fns_.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | "lib/ts/user32/win_user_fns" | win-win 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 | 27 |
28 |
29 | Options 30 |
31 |
32 | All 33 |
    34 |
  • Public
  • 35 |
  • Public/Protected
  • 36 |
  • All
  • 37 |
38 |
39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | Menu 48 |
49 |
50 |
51 |
52 |
53 |
54 | 62 |

Module "lib/ts/user32/win_user_fns"

63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |

Index

71 |
72 |
73 |
74 |

Interfaces

75 | 78 |
79 |
80 |
81 |
82 |
83 | 102 |
103 |
104 |
105 |
106 |

Legend

107 |
108 |
    109 |
  • Object literal
  • 110 |
  • Variable
  • 111 |
  • Function
  • 112 |
  • Type alias
  • 113 |
  • Type alias with type parameter
  • 114 |
115 |
    116 |
  • Interface
  • 117 |
  • Interface with type parameter
  • 118 |
119 |
    120 |
  • Enumeration
  • 121 |
122 |
    123 |
  • Class
  • 124 |
125 |
126 |
127 |
128 |
129 |

Generated using TypeDoc

130 |
131 |
132 | 133 | 134 | -------------------------------------------------------------------------------- /example/create-thread.js: -------------------------------------------------------------------------------- 1 | const { Win32ffi, ffi, CPP, L, NULL } = require('../dist'); 2 | 3 | Win32ffi.assign({ 4 | user32Fns: { 5 | demo: [], 6 | }, 7 | }); 8 | 9 | const { CreateThread, MessageBoxW } = new Win32ffi().winFns(); 10 | 11 | const proc = ffi.Callback(CPP.INT, [CPP.PVOID], (...d) => { 12 | MessageBoxW(0, L('The Alert Window From Thread'), null, CPP.MB_OK | CPP.MB_ICONEXCLAMATION); 13 | }); 14 | 15 | const handle = CreateThread(null, 0, proc, NULL, 0, NULL); 16 | 17 | console.log(Object.prototype.toString.call(handle)); 18 | -------------------------------------------------------------------------------- /example/create-window.js: -------------------------------------------------------------------------------- 1 | const { Win32ffi, L, CPP, NULL } = require('../dist'); 2 | 3 | const winFns = new Win32ffi().winFns(); 4 | 5 | const { CreateWindowExW, GetMessageW, TranslateMessage, DispatchMessageW, GetModuleHandleW } = winFns; 6 | const sampleName = L('Sample Window Name\0'); 7 | const sampleText = L('description\0'); 8 | 9 | const WS_OVERLAPPED = 0x00000000; 10 | const WS_CAPTION = 0x00c00000; 11 | const WS_SYSMENU = 0x00080000; 12 | const WS_THICKFRAME = 0x00040000; 13 | const WS_MINIMIZEBOX = 0x00020000; 14 | const WS_MAXIMIZEBOX = 0x00020000; 15 | 16 | const CW_USEDEFAULT = 0x00000000; 17 | 18 | const WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; 19 | 20 | const hInst = GetModuleHandleW(NULL); 21 | 22 | CreateWindowExW( 23 | 0, 24 | sampleName, 25 | sampleText, 26 | WS_OVERLAPPEDWINDOW, 27 | CW_USEDEFAULT, 28 | CW_USEDEFAULT, 29 | CW_USEDEFAULT, 30 | CW_USEDEFAULT, 31 | 0, 32 | 0, 33 | hInst, 34 | NULL 35 | ); 36 | 37 | const msg = new CPP.StructMSG(); 38 | while (GetMessageW(msg.ref(), 0, 0, 0)) { 39 | TranslateMessage(msg.ref()); 40 | DispatchMessageW(msg.ref()); 41 | } 42 | -------------------------------------------------------------------------------- /example/mouse-hook.js: -------------------------------------------------------------------------------- 1 | const { Win32ffi, ffi, CPP, ref, NULL } = require('../dist'); 2 | 3 | const win32ffi = new Win32ffi(); 4 | const { 5 | CallNextHookEx, 6 | WindowFromPoint, 7 | SetWindowsHookExW, 8 | GetMessageW, 9 | DispatchMessageW, 10 | TranslateMessage, 11 | UnhookWindowsHookEx, 12 | } = win32ffi.user32(); 13 | const { GetModuleHandleW } = win32ffi.kernel32(); 14 | 15 | const cb = function (nCode, wParam, lParam) { 16 | const mouse = lParam.deref(); 17 | const pt = mouse.pt; 18 | const { x, y } = pt; 19 | const currentHwnd = WindowFromPoint(mouse.pt); 20 | console.log('x: ' + x, 'y: ' + y, 'point hwnd:' + currentHwnd); 21 | 22 | return CallNextHookEx(0, nCode, wParam, lParam); 23 | }; 24 | 25 | const _createMouseHookProc = ffi.Callback( 26 | CPP.LRESULT, // cxx CALLBACK 27 | [CPP.INT, CPP.WPARAM, ref.refType(CPP.StructMOUSEHOOKSTRUCT)], 28 | cb 29 | ); 30 | 31 | const hInst = GetModuleHandleW(NULL); 32 | 33 | const _mouseHook = SetWindowsHookExW(CPP.WH_MOUSE_LL, _createMouseHookProc, hInst, 0); 34 | const msg = new CPP.StructMSG(); 35 | 36 | while (GetMessageW(msg.ref(), 0, 0, 0)) { 37 | TranslateMessage(msg.ref()); 38 | DispatchMessageW(msg.ref()); 39 | } 40 | 41 | UnhookWindowsHookEx(_mouseHook); 42 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | }; -------------------------------------------------------------------------------- /lib/cpp/comctl32/comm_ctrl_constant.ts: -------------------------------------------------------------------------------- 1 | //comctl32.dll Windows GUI module 2 | 3 | /** 4 | * ListView messages 5 | */ 6 | export const LVM_FIRST = 0x1000; 7 | /** 8 | * TreeView messages 9 | */ 10 | export const TV_FIRST = 0x1100; 11 | /** 12 | * Header messages 13 | */ 14 | export const HDM_FIRST = 0x1200; 15 | /** 16 | * Tab control messages 17 | */ 18 | export const TCM_FIRST = 0x1300; 19 | /** 20 | * Pager control messages 21 | */ 22 | export const PGM_FIRST = 0x1400; 23 | /** 24 | * Common control shared messages 25 | */ 26 | export const CCM_FIRST = 0x2000; 27 | export const CCM_LAST = CCM_FIRST + 0x200; 28 | /** 29 | * lParam is bkColor 30 | */ 31 | export const CCM_SETBKCOLOR = CCM_FIRST + 1; 32 | 33 | export const LVS_ALIGNTOP = 0x0000; 34 | export const LVS_ALIGNLEFT = 0x0800; 35 | export const LVS_ALIGNMASK = 0x0c00; 36 | export const LVS_OWNERDRAWFIXED = 0x0400; 37 | export const LVS_NOCOLUMNHEADER = 0x4000; 38 | export const LVS_NOSORTHEADER = 0x8000; 39 | 40 | export const LVM_SETIMAGELIST = LVM_FIRST + 3; 41 | export const LVM_GETITEMCOUNT = LVM_FIRST + 4; 42 | export const LVM_GETITEMTEXTA = LVM_FIRST + 45; 43 | export const LVM_GETHEADER = LVM_FIRST + 31; 44 | export const LVM_GETITEMTEXTW = LVM_FIRST + 115; 45 | -------------------------------------------------------------------------------- /lib/cpp/comctl32/index.ts: -------------------------------------------------------------------------------- 1 | export * from './comm_ctrl_constant'; -------------------------------------------------------------------------------- /lib/cpp/index.ts: -------------------------------------------------------------------------------- 1 | export * from './user32'; 2 | export * from './kernel32'; 3 | export * from './comctl32'; 4 | -------------------------------------------------------------------------------- /lib/cpp/kernel32/err_handling_api.ts: -------------------------------------------------------------------------------- 1 | import { DWORD } from '../user32/win_def'; 2 | 3 | export const errHandlingApi = { 4 | GetLastError: [DWORD, []], 5 | }; 6 | -------------------------------------------------------------------------------- /lib/cpp/kernel32/index.ts: -------------------------------------------------------------------------------- 1 | import { libloaderApiFns } from './lib_loader_api_fns'; 2 | import { sysInfoApiFns } from './sys_info_api'; 3 | import { processThreadsApiFns } from './process_threads_api_fns'; 4 | import { errHandlingApi } from './err_handling_api'; 5 | 6 | export const kernel32Fns = Object.assign({}, libloaderApiFns, sysInfoApiFns, processThreadsApiFns, errHandlingApi); 7 | 8 | export * from './lib_loader_api_type'; -------------------------------------------------------------------------------- /lib/cpp/kernel32/lib_loader_api_fns.ts: -------------------------------------------------------------------------------- 1 | import { 2 | DLL_DIRECTORY_COOKIE, 3 | ENUMRESLANGPROCA, 4 | ENUMRESLANGPROCW, 5 | ENUMRESNAMEPROCA, 6 | ENUMRESNAMEPROCW, 7 | ENUMRESTYPEPROCA, 8 | ENUMRESTYPEPROCW, 9 | } from './lib_loader_api_type'; 10 | import { PCWSTR, LPCWSTR, LPCSTR, LANGID, VOID, LPSTR, LPWSTR, HANDLE } from '../user32/win_nt'; 11 | import { BOOL, HMODULE, DWORD, INT, HGLOBAL, FARPROC, HRSRC, LPVOID } from '../user32/win_def'; 12 | import { LONG_PTR } from '../user32/base_tsd'; 13 | 14 | export const libloaderApiFns = { 15 | AddDllDirectory: [DLL_DIRECTORY_COOKIE, [PCWSTR]], 16 | DisableThreadLibraryCalls: [BOOL, [HMODULE]], 17 | EnumResourceLanguagesExA: [BOOL, [HMODULE, LPCSTR, LPCSTR, ENUMRESLANGPROCA, LONG_PTR, DWORD, LANGID]], 18 | EnumResourceLanguagesExW: [BOOL, [HMODULE, LPCWSTR, LPCWSTR, ENUMRESLANGPROCW, LONG_PTR, DWORD, LANGID]], 19 | EnumResourceNamesExA: [BOOL, [HMODULE, LPCSTR, ENUMRESNAMEPROCA, LONG_PTR, DWORD, LANGID]], 20 | EnumResourceNamesExW: [BOOL, [HMODULE, LPCWSTR, ENUMRESNAMEPROCW, LONG_PTR, DWORD, LANGID]], 21 | EnumResourceTypesExA: [BOOL, [HMODULE, ENUMRESTYPEPROCA, LONG_PTR, DWORD, LANGID]], 22 | EnumResourceTypesExW: [BOOL, [HMODULE, ENUMRESTYPEPROCW, LONG_PTR, DWORD, LANGID]], 23 | FindStringOrdinal: [INT, [DWORD, LPCWSTR, INT, LPCWSTR, INT, BOOL]], 24 | FreeLibrary: [BOOL, [HMODULE]], 25 | FreeLibraryAndExitThread: [VOID, [HMODULE, DWORD]], 26 | FreeResource: [BOOL, [HGLOBAL]], 27 | GetModuleFileNameA: [DWORD, [HMODULE, LPSTR, DWORD]], 28 | GetModuleFileNameW: [DWORD, [HMODULE, LPWSTR, DWORD]], 29 | GetModuleHandleA: [HMODULE, [LPCSTR]], 30 | GetModuleHandleExA: [BOOL, [DWORD, LPCSTR, HMODULE]], 31 | GetModuleHandleExW: [BOOL, [DWORD, LPCWSTR, HMODULE]], 32 | GetModuleHandleW: [HMODULE, [LPCWSTR]], 33 | GetProcAddress: [FARPROC, [HMODULE, LPCSTR]], 34 | LoadLibraryA: [HMODULE, [LPCSTR]], 35 | LoadLibraryExA: [HMODULE, [LPCSTR, HANDLE, DWORD]], 36 | LoadLibraryExW: [HMODULE, [LPCWSTR, HANDLE, DWORD]], 37 | LoadLibraryW: [HMODULE, [LPCWSTR]], 38 | LoadResource: [HGLOBAL, [HMODULE, HRSRC]], 39 | LockResource: [LPVOID, [HGLOBAL]], 40 | RemoveDllDirectory: [BOOL, [DLL_DIRECTORY_COOKIE]], 41 | SetDefaultDllDirectories: [BOOL, [DWORD]], 42 | SizeofResource: [DWORD, [HMODULE, HRSRC]], 43 | }; 44 | -------------------------------------------------------------------------------- /lib/cpp/kernel32/lib_loader_api_type.ts: -------------------------------------------------------------------------------- 1 | import { PVOID } from '../user32/win_nt'; 2 | 3 | export const DLL_DIRECTORY_COOKIE = PVOID; 4 | 5 | export const ENUMRESLANGPROCA = 'pointer'; 6 | export const ENUMRESLANGPROCW = 'pointer'; 7 | export const ENUMRESNAMEPROCA = 'pointer'; 8 | export const ENUMRESNAMEPROCW = 'pointer'; 9 | export const ENUMRESTYPEPROCA = 'pointer'; 10 | export const ENUMRESTYPEPROCW = 'pointer'; 11 | -------------------------------------------------------------------------------- /lib/cpp/kernel32/process_threads_api_fns.ts: -------------------------------------------------------------------------------- 1 | import { HANDLE, VOID, PHANDLE, PCWSTR } from '../user32/win_nt'; 2 | import { LPSECURITY_ATTRIBUTES, LPTHREAD_START_ROUTINE } from '../user32/win_base'; 3 | import { LPVOID, DWORD, LPDWORD, BOOL, UINT, INT, HRESULT, PULONG } from '../user32/win_def'; 4 | import { SIZE_T } from '../user32/base_tsd'; 5 | 6 | export const processThreadsApiFns = { 7 | // CreateProcessA: [ 8 | // BOOL, 9 | // [ 10 | // LPCSTR, 11 | // LPSTR, 12 | // LPSECURITY_ATTRIBUTES, 13 | // LPSECURITY_ATTRIBUTES, 14 | // BOOL, 15 | // DWORD, 16 | // LPVOID, 17 | // LPCSTR, 18 | // LPSTARTUPINFOA, 19 | // LPPROCESS_INFORMATION, 20 | // ], 21 | // ], 22 | // CreateProcessAsUserA: [BOOL, [HANDLE, LPCSTR, LPSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPCSTR, LPSTARTUPINFOA, LPPROCESS_INFORMATION]], 23 | // CreateProcessAsUserW: [BOOL, [HANDLE, LPCWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPCWSTR, LPSTARTUPINFOW, LPPROCESS_INFORMATION]], 24 | // CreateProcessW: [BOOL, [LPCWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPCWSTR, LPSTARTUPINFOW, LPPROCESS_INFORMATION]], 25 | // CreateRemoteThread: [HANDLE, [HANDLE, LPSECURITY_ATTRIBUTES, SIZE_T, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD]], 26 | // CreateRemoteThreadEx: [HANDLE, [HANDLE, LPSECURITY_ATTRIBUTES, SIZE_T, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPPROC_THREAD_ATTRIBUTE_LIST, LPDWORD]] 27 | // DeleteProcThreadAttributeList: [VOID, [LPPROC_THREAD_ATTRIBUTE_LIST]], 28 | // ExitProcess: [VOID, [UINT]], 29 | // FlushInstructionCache: [BOOL, [HANDLE, LPCVOID, SIZE_T]], 30 | // FlushProcessWriteBuffers: [VOID, [\placeholder]], 31 | // GetCurrentProcess: [HANDLE, [\placeholder]], 32 | // GetCurrentProcessId: [DWORD, [\placeholder]], 33 | // GetCurrentProcessorNumber: [DWORD, [\placeholder]], 34 | // GetCurrentProcessorNumberEx: [VOID, [PPROCESSOR_NUMBER]], 35 | // GetCurrentProcessToken: [HANDLE, [\placeholder]], 36 | // GetCurrentThread: [HANDLE, [\placeholder]], 37 | // GetCurrentThreadEffectiveToken: [HANDLE, [\placeholder]], 38 | // GetCurrentThreadId: [DWORD, [\placeholder]], 39 | // GetCurrentThreadStackLimits: [VOID, [PULONG_PTR, PULONG_PTR]], 40 | // GetCurrentThreadToken: [HANDLE, [\placeholder]], 41 | // GetExitCodeProcess: [BOOL, [HANDLE, LPDWORD]], 42 | // GetExitCodeThread: [BOOL, [HANDLE, LPDWORD]], 43 | // GetPriorityClass: [DWORD, [HANDLE]], 44 | // GetProcessHandleCount: [BOOL, [HANDLE, PDWORD]], 45 | // GetProcessId: [DWORD, [HANDLE]], 46 | // GetProcessIdOfThread: [DWORD, [HANDLE]], 47 | // GetProcessInformation: [BOOL, [HANDLE, PROCESS_INFORMATION_CLASS, LPVOID, DWORD]], 48 | // GetProcessMitigationPolicy: [BOOL, [HANDLE, PROCESS_MITIGATION_POLICY, PVOID, SIZE_T]], 49 | // GetProcessPriorityBoost: [BOOL, [HANDLE, PBOOL]], 50 | // GetProcessShutdownParameters: [BOOL, [LPDWORD, LPDWORD]], 51 | // GetProcessTimes: [BOOL, [HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME]], 52 | // GetProcessVersion: [DWORD, [DWORD]], 53 | // GetStartupInfoW: [VOID, [LPSTARTUPINFOW]], 54 | // GetSystemTimes: [BOOL, [PFILETIME, PFILETIME, PFILETIME]], 55 | // GetThreadContext: [BOOL, [HANDLE, LPCONTEXT]], 56 | // GetThreadDescription: [HRESULT, [HANDLE, PWSTR]], 57 | // GetThreadId: [DWORD, [HANDLE]], 58 | // GetThreadIdealProcessorEx: [BOOL, [HANDLE, PPROCESSOR_NUMBER]], 59 | // GetThreadInformation: [BOOL, [HANDLE, THREAD_INFORMATION_CLASS, LPVOID, DWORD]], 60 | // GetThreadIOPendingFlag: [BOOL, [HANDLE, PBOOL]], 61 | // GetThreadPriority: [INT, [HANDLE]], 62 | // GetThreadPriorityBoost: [BOOL, [HANDLE, PBOOL]], 63 | // GetThreadTimes: [BOOL, [HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME]], 64 | // InitializeProcThreadAttributeList: [BOOL, [LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD, PSIZE_T]], 65 | // IsProcessCritical: [BOOL, [HANDLE, PBOOL]], 66 | // IsProcessorFeaturePresent: [BOOL, [DWORD]], 67 | // OpenProcess: [HANDLE, [DWORD, BOOL, DWORD]], 68 | // OpenProcessToken: [BOOL, [HANDLE, DWORD, PHANDLE]], 69 | // OpenThread: [HANDLE, [DWORD, BOOL, DWORD]], 70 | // OpenThreadToken: [BOOL, [HANDLE, DWORD, BOOL, PHANDLE]], 71 | // ProcessIdToSessionId: [BOOL, [DWORD, DWORD]], 72 | // QueryProcessAffinityUpdateMode: [BOOL, [HANDLE, LPDWORD]], 73 | // QueryProtectedPolicy: [BOOL, [LPCGUID, PULONG_PTR]], 74 | // QueueUserAPC: [DWORD, [PAPCFUNC, HANDLE, ULONG_PTR]], 75 | // ResumeThread: [DWORD, [HANDLE]], 76 | // SetPriorityClass: [BOOL, [HANDLE, DWORD]], 77 | // SetProcessAffinityUpdateMode: [BOOL, [HANDLE, DWORD]], 78 | // SetProcessDynamicEHContinuationTargets: [BOOL, [HANDLE, USHORT, PPROCESS_DYNAMIC_EH_CONTINUATION_TARGET]], 79 | // SetProcessInformation: [BOOL, [HANDLE, PROCESS_INFORMATION_CLASS, LPVOID, DWORD]], 80 | // SetProcessMitigationPolicy: [BOOL, [PROCESS_MITIGATION_POLICY, PVOID, SIZE_T]], 81 | // SetProcessPriorityBoost: [BOOL, [HANDLE, BOOL]], 82 | // SetProcessShutdownParameters: [BOOL, [DWORD, DWORD]], 83 | // SetProtectedPolicy: [BOOL, [LPCGUID, ULONG_PTR, PULONG_PTR]], 84 | // SetThreadContext: [BOOL, [HANDLE, CONST, CONTEXT]], 85 | // SetThreadIdealProcessorEx: [BOOL, [HANDLE, PPROCESSOR_NUMBER, PPROCESSOR_NUMBER]], 86 | // SetThreadInformation: [BOOL, [HANDLE, THREAD_INFORMATION_CLASS, LPVOID, DWORD]], 87 | // TlsAlloc: [DWORD, [\placeholder]], 88 | // UpdateProcThreadAttribute: [BOOL, [LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD_PTR, PVOID, SIZE_T, PVOID, PSIZE_T]], 89 | CreateThread: [HANDLE, [LPSECURITY_ATTRIBUTES, SIZE_T, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD]], 90 | ExitThread: [VOID, [DWORD]], 91 | SetThreadDescription: [HRESULT, [HANDLE, PCWSTR]], 92 | SetThreadIdealProcessor: [DWORD, [HANDLE, DWORD]], 93 | SetThreadPriority: [BOOL, [HANDLE, INT]], 94 | SetThreadPriorityBoost: [BOOL, [HANDLE, BOOL]], 95 | SetThreadStackGuarantee: [BOOL, [PULONG]], 96 | SetThreadToken: [BOOL, [PHANDLE, HANDLE]], 97 | SuspendThread: [DWORD, [HANDLE]], 98 | SwitchToThread: [BOOL, []], 99 | TerminateProcess: [BOOL, [HANDLE, UINT]], 100 | TerminateThread: [BOOL, [HANDLE, DWORD]], 101 | TlsFree: [BOOL, [DWORD]], 102 | TlsGetValue: [LPVOID, [DWORD]], 103 | TlsSetValue: [BOOL, [DWORD, LPVOID]], 104 | }; 105 | -------------------------------------------------------------------------------- /lib/cpp/kernel32/sys_info_api.ts: -------------------------------------------------------------------------------- 1 | import { DWORD } from '../user32/win_def'; 2 | 3 | export const sysInfoApiFns = { 4 | GetTickCount: [DWORD, []], 5 | }; 6 | -------------------------------------------------------------------------------- /lib/cpp/string/index.ts: -------------------------------------------------------------------------------- 1 | export const L = (val: string): Buffer => Buffer.from(val, 'ucs2'); 2 | export const _T = L; 3 | export const _Text_ = L; -------------------------------------------------------------------------------- /lib/cpp/user32/base_tsd.ts: -------------------------------------------------------------------------------- 1 | import { arch } from '../utils'; 2 | import { _UINT_PTR, _LONG_PTR } from './win_common'; 3 | 4 | export const UINT_PTR = _UINT_PTR; 5 | export const PUINT_PTR = ['uint64*', 'uint*'][arch()]; 6 | 7 | export const LONG_PTR = _LONG_PTR; 8 | export const PLONG_PTR = ['int64*', 'long*'][arch()]; 9 | 10 | export const ULONG_PTR = ['uint64', 'ulong'][arch()]; 11 | export const DWORD_PTR = ULONG_PTR; 12 | 13 | export const HALF_PTR = ['int', 'short'][arch()]; 14 | export const PHALF_PTR = ['int*', 'short*'][arch()]; 15 | export const UHALF_PTR = ['uint', 'ushort'][arch()]; 16 | export const PUHALF_PTR = ['uint*', 'ushort*'][arch()]; 17 | 18 | export const PDWORD_PTR = ['uint64*', 'ulong*'][arch()]; 19 | 20 | export const DWORD32 = 'uint'; 21 | export const DWORD64 = 'uint64'; 22 | 23 | export const PDWORD32 = 'uint*'; 24 | export const PDWORD64 = 'uint64*'; 25 | 26 | export const INT8 = 'char'; 27 | export const INT16 = 'short'; 28 | export const INT32 = 'int'; 29 | export const INT64 = 'int64'; 30 | 31 | export const INT_PTR = ['int64', 'int'][arch()]; 32 | export const PINT_PTR = ['int64*', 'int*'][arch()]; 33 | 34 | export const UINT8 = 'uchar'; 35 | export const UINT16 = 'ushort'; 36 | export const UINT32 = 'uint'; 37 | export const UINT64 = 'uint64'; 38 | 39 | export const PINT8 = 'char*'; 40 | export const PINT16 = 'short*'; 41 | export const PINT32 = 'int*'; 42 | export const PINT64 = 'int64*'; 43 | 44 | export const PUINT8 = 'char*'; 45 | export const PUINT16 = 'short*'; 46 | export const PUINT32 = 'int*'; 47 | export const PUINT64 = 'int64*'; 48 | 49 | export const LONG32 = 'int'; 50 | export const LONG64 = 'int64'; 51 | 52 | export const ULONG32 = 'uint'; 53 | export const ULONG64 = 'uint64'; 54 | 55 | export const PLONG32 = 'int*'; 56 | export const PLONG64 = 'int64*'; 57 | 58 | export const POINTER_32 = 'pointer'; 59 | export const POINTER_64 = 'pointer'; 60 | export const POINTER_SIGNED = 'pointer'; 61 | export const POINTER_UNSIGNED = 'pointer'; 62 | 63 | export const PSIZE_T = 'size_t*'; 64 | export const PSSIZE_T = 'size_t*'; 65 | export const SSIZE_T = _LONG_PTR; 66 | export const SIZE_T = ULONG_PTR; 67 | -------------------------------------------------------------------------------- /lib/cpp/user32/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 3 | * 4 | */ 5 | 6 | // Data types https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types 7 | // Api https://docs.microsoft.com/en-us/windows/win32/api/winuser/ 8 | // Basic types https://github.com/libffi/libffi 9 | import { winUserFns } from './win_user_fns'; 10 | 11 | export * from './win_nt'; 12 | export * from './win_def'; 13 | export * from './win_ternl'; 14 | export * from './base_tsd'; 15 | export * from './user_macro_fns'; 16 | export * from './win_user_struct'; 17 | export * from './win_user_constant'; 18 | export * from './win_user_type'; 19 | 20 | export const user32Fns = Object.assign({}, winUserFns); 21 | 22 | /** 23 | * FFI types 24 | * { 25 | * void: { 26 | * size: 0, 27 | * indirection: 1, 28 | * get: [Function: get], 29 | * set: [Function: set], 30 | * name: 'void', 31 | * ffi_type: 32 | * }, 33 | * int8: { 34 | * size: 1, 35 | * indirection: 1, 36 | * get: [Function: get], 37 | * set: [Function: set], 38 | * alignment: 1, 39 | * name: 'int8', 40 | * ffi_type: 41 | * }, 42 | * uint8: { 43 | * size: 1, 44 | * indirection: 1, 45 | * get: [Function: get], 46 | * set: [Function: set], 47 | * alignment: 1, 48 | * name: 'uint8', 49 | * ffi_type: 50 | * }, 51 | * int16: { 52 | * size: 2, 53 | * indirection: 1, 54 | * get: [Function: get], 55 | * set: [Function: set], 56 | * alignment: 2, 57 | * name: 'int16', 58 | * ffi_type: 59 | * }, 60 | * uint16: { 61 | * size: 2, 62 | * indirection: 1, 63 | * get: [Function: get], 64 | * set: [Function: set], 65 | * alignment: 2, 66 | * name: 'uint16', 67 | * ffi_type: 68 | * }, 69 | * int32: { 70 | * size: 4, 71 | * indirection: 1, 72 | * get: [Function: get], 73 | * set: [Function: set], 74 | * alignment: 4, 75 | * name: 'int32', 76 | * ffi_type: 77 | * }, 78 | * uint32: { 79 | * size: 4, 80 | * indirection: 1, 81 | * get: [Function: get], 82 | * set: [Function: set], 83 | * alignment: 4, 84 | * name: 'uint32', 85 | * ffi_type: 86 | * }, 87 | * int64: { 88 | * size: 8, 89 | * indirection: 1, 90 | * get: [Function: get], 91 | * set: [Function: set], 92 | * alignment: 8, 93 | * name: 'int64', 94 | * ffi_type: 95 | * }, 96 | * uint64: { 97 | * size: 8, 98 | * indirection: 1, 99 | * get: [Function: get], 100 | * set: [Function: set], 101 | * alignment: 8, 102 | * name: 'uint64', 103 | * ffi_type: 104 | * }, 105 | * float: { 106 | * size: 4, 107 | * indirection: 1, 108 | * get: [Function: get], 109 | * set: [Function: set], 110 | * alignment: 4, 111 | * name: 'float', 112 | * ffi_type: 113 | * }, 114 | * double: { 115 | * size: 8, 116 | * indirection: 1, 117 | * get: [Function: get], 118 | * set: [Function: set], 119 | * alignment: 8, 120 | * name: 'double', 121 | * ffi_type: 122 | * }, 123 | * Object: { 124 | * size: 24, 125 | * indirection: 1, 126 | * get: [Function: get], 127 | * set: [Function: set], 128 | * alignment: 8, 129 | * name: 'Object', 130 | * ffi_type: 131 | * }, 132 | * CString: { 133 | * size: 8, 134 | * alignment: 8, 135 | * indirection: 1, 136 | * get: [Function: get], 137 | * set: [Function: set], 138 | * name: 'CString', 139 | * ffi_type: 140 | * }, 141 | * bool: { 142 | * alignment: 1, 143 | * get: [Function: get], 144 | * set: [Function: set], 145 | * name: 'bool' 146 | * }, 147 | * byte: { name: 'byte' }, 148 | * char: { 149 | * alignment: 1, 150 | * name: 'char', 151 | * ffi_type: 152 | * }, 153 | * uchar: { 154 | * alignment: 1, 155 | * name: 'uchar', 156 | * ffi_type: 157 | * }, 158 | * short: { 159 | * alignment: 2, 160 | * name: 'short', 161 | * ffi_type: 162 | * }, 163 | * ushort: { 164 | * alignment: 2, 165 | * name: 'ushort', 166 | * ffi_type: 167 | * }, 168 | * int: { 169 | * alignment: 4, 170 | * name: 'int', 171 | * ffi_type: 172 | * }, 173 | * uint: { 174 | * alignment: 4, 175 | * name: 'uint', 176 | * ffi_type: 177 | * }, 178 | * long: { 179 | * alignment: 4, 180 | * name: 'long', 181 | * ffi_type: 182 | * }, 183 | * ulong: { 184 | * alignment: 4, 185 | * name: 'ulong', 186 | * ffi_type: 187 | * }, 188 | * longlong: { 189 | * alignment: 8, 190 | * name: 'longlong', 191 | * ffi_type: 192 | * }, 193 | * ulonglong: { 194 | * alignment: 8, 195 | * name: 'ulonglong', 196 | * ffi_type: 197 | * }, 198 | * size_t: { 199 | * alignment: 8, 200 | * name: 'size_t', 201 | * ffi_type: 202 | * } 203 | * } 204 | */ 205 | -------------------------------------------------------------------------------- /lib/cpp/user32/user_macro_fns.ts: -------------------------------------------------------------------------------- 1 | import { TsWin32Fns, User32Fns } from '../../ts'; 2 | import { iconv } from '../utils'; 3 | 4 | export const MAKELONG = (a: number, b: number): number => (a & 0xfff) | ((b & 0xfff) << 16); 5 | 6 | export const userMacroFns = (fns: TsWin32Fns): any => { 7 | return { 8 | MAKELONG, 9 | CopyCursor: fns.CopyIcon, 10 | MAKELPARAM: MAKELONG, 11 | MAKELRESULT: MAKELONG, 12 | MAKEWPARAM: MAKELONG, 13 | GetMessage: [fns.GetMessageW, fns.GetMessageA][iconv()], 14 | }; 15 | }; 16 | -------------------------------------------------------------------------------- /lib/cpp/user32/win_base.ts: -------------------------------------------------------------------------------- 1 | 2 | export const LPSECURITY_ATTRIBUTES = 'pointer'; 3 | export const LPTHREAD_START_ROUTINE = 'pointer'; -------------------------------------------------------------------------------- /lib/cpp/user32/win_common.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 3 | * All rights reserved. 4 | */ 5 | import { arch } from '../utils'; 6 | 7 | export const _BOOL = 'int'; 8 | 9 | export const _LONG = 'int32'; 10 | 11 | export const _WORD = 'int16'; 12 | export const _DWORD = 'int32'; 13 | export const _PDWORD = 'uint32*'; 14 | 15 | export const _BYTE = 'uchar'; 16 | 17 | /** 18 | * 19 | */ 20 | 21 | export const _DECLARE_HANDLE = ['uint64', 'uint32'][arch()]; 22 | 23 | /** 24 | * win_def 25 | */ 26 | export const _LPVOID = 'void*'; 27 | /** 28 | * base_tsd 29 | */ 30 | export const _LONG_PTR = ['int64', 'long'][arch()]; 31 | export const _UINT_PTR = ['uint64', 'uint'][arch()]; 32 | -------------------------------------------------------------------------------- /lib/cpp/user32/win_def.ts: -------------------------------------------------------------------------------- 1 | import { _LONG, _DECLARE_HANDLE, _WORD, _DWORD, _BYTE, _BOOL, _LPVOID, _LONG_PTR, _UINT_PTR } from './win_common'; 2 | import * as ref from 'ref-napi'; 3 | import StructType = require('ref-struct-di'); 4 | const Struct = StructType(ref); 5 | /** 6 | * short == int16; 7 | * int == int32; 8 | * long == int64 9 | */ 10 | 11 | export const DWORD = _DWORD; 12 | export const WORD = _WORD; 13 | 14 | export const DWORDLONG = 'uint64'; 15 | 16 | export const UCHAR = 'uchar'; 17 | export const PUCHAR = 'uchar*'; 18 | 19 | export const USHORT = 'ushort'; 20 | 21 | export const BOOL = _BOOL; 22 | export const BYTE = _BYTE; 23 | 24 | export const FLOAT = 'float'; 25 | export const PFLOAT = 'float*'; 26 | 27 | //BUGBUG - might want to remove this from minwin 28 | export const ATOM = WORD; 29 | /** 30 | * near: a 16 bit pointer that can address any byte in a 64k segment 31 | * far: a 32 bit pointer that contains a segment and an offset.Note that because segments can 32 | * @see https://stackoverflow.com/questions/3575592/what-are-near-far-and-huge-pointers 33 | */ 34 | export const PBOOL = 'int32*'; 35 | export const LPBOOL = 'int32*'; 36 | export const PBYTE = 'uchar*'; 37 | export const LPBYTE = 'uchar*'; 38 | export const LPINT = 'int*'; 39 | 40 | export const PWORD = 'int16*'; 41 | export const LPWORD = 'int16*'; 42 | export const PDWORD = _DWORD; 43 | export const LPDWORD = 'uint32*'; 44 | export const LPVOID = _LPVOID; 45 | export const LPCVOID = 'void*'; 46 | export const LPCOLORREF = 'int32*'; 47 | 48 | export const INT = 'int'; 49 | export const UINT = 'uint'; 50 | export const PINT = 'int*'; 51 | export const PUINT = 'uint*'; 52 | 53 | export const LPLONG = 'int32*'; 54 | export const ULONG = 'ulong'; 55 | export const PULONG = 'ulong*'; 56 | 57 | export const SPHANDLE = 'void**'; 58 | export const LPHANDLE = 'void**'; 59 | export const HFILE = 'int'; 60 | 61 | /** 62 | * AUTHOR --- sewerganger 63 | * LASTMODIFY --- 2020-07-01T14:28:50.384Z 64 | * BLOCK --- _DECLARE_HANDLE 65 | * DESCRIPTION --- 66 | */ 67 | 68 | export const HLOCAL = _DECLARE_HANDLE; 69 | export const HACCEL = _DECLARE_HANDLE; 70 | export const HBITMAP = _DECLARE_HANDLE; 71 | export const HBRUSH = _DECLARE_HANDLE; 72 | export const HCOLORSPACE = _DECLARE_HANDLE; 73 | export const HCONV = _DECLARE_HANDLE; 74 | export const HCONVLIST = _DECLARE_HANDLE; 75 | export const HICON = _DECLARE_HANDLE; 76 | export const HCURSOR = HICON; 77 | export const HDC = _DECLARE_HANDLE; 78 | export const HDDEDATA = _DECLARE_HANDLE; 79 | export const HDESK = _DECLARE_HANDLE; 80 | export const HDROP = _DECLARE_HANDLE; 81 | export const HDWP = _DECLARE_HANDLE; 82 | export const HENHMETAFILE = _DECLARE_HANDLE; 83 | export const HFONT = _DECLARE_HANDLE; 84 | export const HGDIOBJ = _DECLARE_HANDLE; 85 | export const HGLOBAL = _DECLARE_HANDLE; 86 | export const HHOOK = _DECLARE_HANDLE; 87 | export const HINSTANCE = _DECLARE_HANDLE; 88 | export const HKEY = _DECLARE_HANDLE; 89 | export const HKL = _DECLARE_HANDLE; 90 | export const HMENU = _DECLARE_HANDLE; 91 | export const HMETAFILE = _DECLARE_HANDLE; 92 | export const HMODULE = HINSTANCE; 93 | // export const HMONITOR = ?; 94 | export const HPALETTE = _DECLARE_HANDLE; 95 | export const HPEN = _DECLARE_HANDLE; 96 | export const HRESULT = _LONG; 97 | export const HRGN = _DECLARE_HANDLE; 98 | export const HRSRC = _DECLARE_HANDLE; 99 | export const HSZ = _DECLARE_HANDLE; 100 | export const HWINSTA = _DECLARE_HANDLE; 101 | export const HWND = _DECLARE_HANDLE; 102 | 103 | export const CALLBACK = 'pointer'; 104 | export const WINAPI = 'pointer'; 105 | export const APIENTRY = WINAPI; 106 | 107 | /** 108 | * AUTHOR --- sewerganger 109 | * LASTMODIFY --- 2020-07-01T14:28:22.070Z 110 | * BLOCK --- PROCEDURE; 111 | * DESCRIPTION --- 112 | */ 113 | 114 | export const FARPROC = 'pointer'; 115 | export const NEARPROC = 'pointer'; 116 | export const HOOKPROC = 'pointer'; 117 | 118 | export const COLORREF = DWORD; 119 | 120 | export const LPARAM = _LONG_PTR; 121 | export const WPARAM = _UINT_PTR; 122 | export const LRESULT = _LONG_PTR; 123 | 124 | /** 125 | * 126 | */ 127 | 128 | export const tagSIZE = { 129 | cx: _LONG, 130 | cy: _LONG, 131 | }; 132 | 133 | export const SIZE = Struct(tagSIZE); 134 | 135 | export const tagPOINT = { 136 | x: _LONG, 137 | y: _LONG, 138 | }; 139 | 140 | export const POINT = Struct(tagPOINT); 141 | -------------------------------------------------------------------------------- /lib/cpp/user32/win_gdi.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Han 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | export const DISPLAYCONFIG_DEVICE_INFO_HEADER = 'pointer'; 6 | export const tagDISPLAYCONFIG_DEVICE_INFO_HEADER = { 7 | // type: DISPLAYCONFIG_DEVICE_INFO_TYPE 8 | // UINT32 size, 9 | // LUID adapterId, 10 | // UINT32 id, 11 | }; 12 | 13 | export const PDISPLAY_DEVICEA = 'pointer'; 14 | export const _PDISPLAY_DEVICEA = { 15 | // type: DISPLAYCONFIG_DEVICE_INFO_TYPE 16 | // UINT32 size, 17 | // LUID adapterId, 18 | // UINT32 id, 19 | }; 20 | 21 | export const PDISPLAY_DEVICEW = 'pointer'; 22 | 23 | export const BLENDFUNCTION = 'pointer'; 24 | -------------------------------------------------------------------------------- /lib/cpp/user32/win_nls.ts: -------------------------------------------------------------------------------- 1 | import { _DWORD } from './win_common'; 2 | 3 | export const LCID = _DWORD; 4 | export const LCTYPE = _DWORD; 5 | -------------------------------------------------------------------------------- /lib/cpp/user32/win_nt.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 3 | * All rights reserved. 4 | */ 5 | 6 | import { _LONG, _WORD, _DWORD, _PDWORD, _BYTE } from './win_common'; 7 | 8 | import { arch, iconv } from '../utils'; 9 | 10 | export const TBYTE = ['ushort', 'uchar'][arch()]; 11 | export const PTBYTE = ['ushort*', 'uchar*'][arch()]; 12 | 13 | export const PVOID = 'void*'; 14 | export const HANDLE = 'void *'; 15 | 16 | export const LONG = _LONG; 17 | export const LONGLONG = ['int64', 'double'][arch()]; 18 | export const PLONG = 'long*'; 19 | export const PLONGLONG = ['int64*', 'double*'][arch()]; 20 | export const ULONGLONG = ['uint64', 'double'][arch()]; 21 | 22 | export const CHAR = 'char'; 23 | export const CCHAR = 'char'; 24 | 25 | export const TCHAR = ['ushort', 'char'][arch()]; 26 | export const PTCHAR = ['ushort*', 'char*'][arch()]; 27 | 28 | export const SHORT = 'short'; 29 | export const PSHORT = 'short*'; 30 | 31 | export const VOID = 'void'; 32 | 33 | export const LANGID = _WORD; 34 | export const LCID = _DWORD; 35 | export const LPCSTR = 'char*'; 36 | export const LPCWSTR = 'ushort*'; 37 | export const LPSTR = 'char*'; 38 | export const LPCTSTR = [LPCWSTR, LPCSTR][iconv()]; 39 | export const LPTSTR = [LPCWSTR, LPSTR][iconv()]; 40 | export const LPWSTR = 'ushort*'; 41 | 42 | export const WCHAR = 'ushort'; 43 | export const PWCHAR = 'ushort*'; 44 | export const PCHAR = 'char*'; 45 | export const PSTR = 'char*'; 46 | export const PCSTR = 'char*'; 47 | export const PCWSTR = 'ushort*'; 48 | export const PLCID = _PDWORD; 49 | export const PCTSTR = [LPCWSTR, LPCSTR][iconv()]; 50 | export const PTSTR = [LPWSTR, LPSTR][iconv()]; 51 | 52 | export const PHANDLE = 'void**'; 53 | export const PHKEY = 'void**'; 54 | 55 | export const PDWORDLONG = 'uint64*'; 56 | 57 | export const BOOLEAN = _BYTE; 58 | export const PBOOLEAN = 'uchar*'; 59 | 60 | export const USN = LONGLONG; 61 | 62 | export const ACCESS_MASK = _DWORD; 63 | 64 | export const PSECURITY_DESCRIPTOR = _DWORD; 65 | 66 | export const PSECURITY_INFORMATION = 'uint*'; 67 | // export const USN = LONGLONG; 68 | -------------------------------------------------------------------------------- /lib/cpp/user32/win_ternl.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 3 | * All rights reserved. 4 | */ 5 | 6 | export const UNICODE_STRING = 'CString'; -------------------------------------------------------------------------------- /lib/cpp/user32/win_user_constant.ts: -------------------------------------------------------------------------------- 1 | export const WM_MOUSEFIRST = 0x0200; 2 | export const WM_MOUSEMOVE = 0x0200; 3 | export const WM_LBUTTONDOWN = 0x0201; 4 | export const WM_LBUTTONUP = 0x0202; 5 | export const WM_LBUTTONDBLCLK = 0x0203; 6 | export const WM_RBUTTONDOWN = 0x0204; 7 | export const WM_RBUTTONUP = 0x0205; 8 | export const WM_RBUTTONDBLCLK = 0x0206; 9 | export const WM_MBUTTONDOWN = 0x0207; 10 | export const WM_MBUTTONUP = 0x0208; 11 | export const WM_MBUTTONDBLCLK = 0x0209; 12 | export const WM_MOUSEWHEEL = 0x020a; 13 | 14 | export const WH_KEYBOARD_LL = 13; 15 | export const WH_MOUSE_LL = 14; 16 | 17 | export const SM_CXSCREEN = 0; 18 | export const SM_CYSCREEN = 1; 19 | export const SM_CXVSCROLL = 2; 20 | export const SM_CYHSCROLL = 3; 21 | export const SM_CYCAPTION = 4; 22 | export const SM_CXBORDER = 5; 23 | export const SM_CYBORDER = 6; 24 | export const SM_CXDLGFRAME = 7; 25 | export const SM_CYDLGFRAME = 8; 26 | export const SM_CYVTHUMB = 9; 27 | export const SM_CXHTHUMB = 10; 28 | export const SM_CXICON = 11; 29 | export const SM_CYICON = 12; 30 | export const SM_CXCURSOR = 13; 31 | export const SM_CYCURSOR = 14; 32 | export const SM_CYMENU = 15; 33 | export const SM_CXFULLSCREEN = 16; 34 | export const SM_CYFULLSCREEN = 17; 35 | export const SM_CYKANJIWINDOW = 18; 36 | export const SM_MOUSEPRESENT = 19; 37 | export const SM_CYVSCROLL = 20; 38 | export const SM_CXHSCROLL = 21; 39 | export const SM_DEBUG = 22; 40 | export const SM_SWAPBUTTON = 23; 41 | export const SM_RESERVED1 = 24; 42 | export const SM_RESERVED2 = 25; 43 | export const SM_RESERVED3 = 26; 44 | export const SM_RESERVED4 = 27; 45 | export const SM_CXMIN = 28; 46 | export const SM_CYMIN = 29; 47 | export const SM_CXSIZE = 30; 48 | export const SM_CYSIZE = 31; 49 | export const SM_CXFRAME = 32; 50 | export const SM_CYFRAME = 33; 51 | export const SM_CXMINTRACK = 34; 52 | export const SM_CYMINTRACK = 35; 53 | export const SM_CXDOUBLECLK = 36; 54 | export const SM_CYDOUBLECLK = 37; 55 | export const SM_CXICONSPACING = 38; 56 | export const SM_CYICONSPACING = 39; 57 | export const SM_MENUDROPALIGNMENT = 40; 58 | export const SM_PENWINDOWS = 41; 59 | export const SM_DBCSENABLED = 42; 60 | export const SM_CMOUSEBUTTONS = 43; 61 | 62 | export const SWP_NOSIZE = 0x0001; 63 | export const SWP_NOMOVE = 0x0002; 64 | export const SWP_NOZORDER = 0x0004; 65 | export const SWP_NOREDRAW = 0x0008; 66 | export const SWP_NOACTIVATE = 0x0010; 67 | export const SWP_FRAMECHANGED = 0x0020; /* The frame changed: send WM_NCCALCSIZE */ 68 | export const SWP_SHOWWINDOW = 0x0040; 69 | export const SWP_HIDEWINDOW = 0x0080; 70 | export const SWP_NOCOPYBITS = 0x0100; 71 | export const SWP_NOOWNERZORDER = 0x0200; /* Don't do owner Z ordering */ 72 | export const SWP_NOSENDCHANGING = 0x0400; /* Don't send WM_WINDOWPOSCHANGING */ 73 | 74 | export const SWP_DRAWFRAME = SWP_FRAMECHANGED; 75 | export const SWP_NOREPOSITION = SWP_NOOWNERZORDER; 76 | 77 | /** 78 | * MW_USER WINVER>400 79 | */ 80 | 81 | export const WM_IME_STARTCOMPOSITION = 0x010d; 82 | export const WM_IME_ENDCOMPOSITION = 0x010e; 83 | export const WM_IME_COMPOSITION = 0x010f; 84 | export const WM_IME_KEYLAST = 0x010f; 85 | export const WM_INITDIALOG = 0x0110; 86 | export const WM_COMMAND = 0x0111; 87 | export const WM_SYSCOMMAND = 0x0112; 88 | export const WM_TIMER = 0x0113; 89 | export const WM_HSCROLL = 0x0114; 90 | export const WM_VSCROLL = 0x0115; 91 | export const WM_INITMENU = 0x0116; 92 | export const WM_INITMENUPOPUP = 0x0117; 93 | 94 | /** 95 | * System Menu Command Values 96 | */ 97 | 98 | /* 99 | * System Menu Command Values 100 | */ 101 | export const SC_SIZE = 0xf000; 102 | export const SC_MOVE = 0xf010; 103 | export const SC_MINIMIZE = 0xf020; 104 | export const SC_MAXIMIZE = 0xf030; 105 | export const SC_NEXTWINDOW = 0xf040; 106 | export const SC_PREVWINDOW = 0xf050; 107 | export const SC_CLOSE = 0xf060; 108 | export const SC_VSCROLL = 0xf070; 109 | export const SC_HSCROLL = 0xf080; 110 | export const SC_MOUSEMENU = 0xf090; 111 | export const SC_KEYMENU = 0xf100; 112 | export const SC_ARRANGE = 0xf110; 113 | export const SC_RESTORE = 0xf120; 114 | export const SC_TASKLIST = 0xf130; 115 | export const SC_SCREENSAVE = 0xf140; 116 | export const SC_HOTKEY = 0xf150; 117 | export const SC_DEFAULT = 0xf160; 118 | export const SC_MONITORPOWER = 0xf170; 119 | export const SC_CONTEXTHELP = 0xf180; 120 | export const SC_SEPARATOR = 0xf00f; 121 | 122 | /** 123 | * MessageBox() Flags 124 | */ 125 | 126 | export const MB_OK = 0x00000000; 127 | export const MB_OKCANCEL = 0x00000001; 128 | export const MB_ABORTRETRYIGNORE = 0x00000002; 129 | export const MB_YESNOCANCEL = 0x00000003; 130 | export const MB_YESNO = 0x00000004; 131 | export const MB_RETRYCANCEL = 0x00000005; 132 | export const MB_CANCELTRYCONTINUE = 0x00000006; 133 | 134 | export const MB_ICONHAND = 0x00000010; 135 | export const MB_ICONQUESTION = 0x00000020; 136 | export const MB_ICONEXCLAMATION = 0x00000030; 137 | export const MB_ICONASTERISK = 0x00000040; 138 | 139 | export const MB_USERICON = 0x00000080; 140 | export const MB_ICONWARNING = MB_ICONEXCLAMATION; 141 | export const MB_ICONERROR = MB_ICONHAND; 142 | 143 | export const MB_ICONINFORMATION = MB_ICONASTERISK; 144 | export const MB_ICONSTOP = MB_ICONHAND; 145 | 146 | export const MB_DEFBUTTON1 = 0x00000000; 147 | export const MB_DEFBUTTON2 = 0x00000100; 148 | export const MB_DEFBUTTON3 = 0x00000200; 149 | export const MB_DEFBUTTON4 = 0x00000300; 150 | 151 | export const MB_APPLMODAL = 0x00000000; 152 | export const MB_SYSTEMMODAL = 0x00001000; 153 | export const MB_TASKMODAL = 0x00002000; 154 | export const MB_HELP = 0x00004000; // Help Butto; 155 | 156 | export const MB_NOFOCUS = 0x00008000; 157 | export const MB_SETFOREGROUND = 0x00010000; 158 | export const MB_DEFAULT_DESKTOP_ONLY = 0x00020000; 159 | 160 | // #if(WINVER >= 0x0400) 161 | export const MB_TOPMOST = 0x00040000; 162 | export const MB_RIGHT = 0x00080000; 163 | export const MB_RTLREADING = 0x00100000; 164 | 165 | // #endif /* WINVER >= 0x0400 */ 166 | 167 | // #ifdef _WIN32_WINNT 168 | // #if(_WIN32_WINNT >= 0x0400) 169 | // export const MB_SERVICE_NOTIFICATION = 0x00200000; 170 | // #else 171 | // export const MB_SERVICE_NOTIFICATION = 0x00040000; 172 | // #endif 173 | export const MB_SERVICE_NOTIFICATION_NT3X = 0x00040000; 174 | // #endif 175 | 176 | export const MB_TYPEMASK = 0x0000000f; 177 | export const MB_ICONMASK = 0x000000f0; 178 | export const MB_DEFMASK = 0x00000f00; 179 | export const MB_MODEMASK = 0x00003000; 180 | export const MB_MISCMASK = 0x0000c000; 181 | -------------------------------------------------------------------------------- /lib/cpp/user32/win_user_struct.ts: -------------------------------------------------------------------------------- 1 | import { HWND, UINT, WPARAM, LPARAM, POINT } from './win_def'; 2 | import { DWORD } from './win_def'; 3 | import * as ref from 'ref-napi'; 4 | import StructDi = require('ref-struct-di'); 5 | import { LONG } from './win_nt'; 6 | import { ULONG_PTR } from './base_tsd'; 7 | 8 | const Struct = StructDi(ref); 9 | 10 | /** 11 | * Contains status information for the application - switching(ALT + TAB) window. 12 | * https://docs.microsoft.com/zh-cn/windows/win32/api/winuser/ns-winuser-alttabinfo 13 | */ 14 | 15 | // export const Tag_ALTTABINFO = { 16 | // cbSize: DWORD, 17 | // cItems: INT, 18 | // cColumns: INT, 19 | // cRows: INT, 20 | // iColFocus: INT, 21 | // iRowFocus: INT, 22 | // cxItem: INT, 23 | // cyItem: INT, 24 | // ptStart: POINT 25 | // }; 26 | 27 | export const tagRECT = { 28 | left: LONG, 29 | top: LONG, 30 | right: LONG, 31 | bottom: LONG, 32 | }; 33 | export const RECT = 'pointer'; 34 | export const StructRECT = Struct(tagRECT); 35 | 36 | export const tagMSG = { 37 | hwnd: HWND, 38 | message: UINT, 39 | wParam: WPARAM, 40 | lParam: LPARAM, 41 | time: DWORD, 42 | pt: POINT, 43 | }; 44 | 45 | export const StructMSG = Struct(tagMSG); 46 | export const MSG = 'pointer'; 47 | 48 | export const tagMOUSEHOOKSTRUCT = { 49 | pt: POINT, 50 | hwnd: HWND, 51 | wHitTestCode: UINT, 52 | dwExtraInfo: ULONG_PTR, 53 | }; 54 | export const MOUSEHOOKSTRUCT = 'pointer'; 55 | export const StructMOUSEHOOKSTRUCT = Struct(tagMOUSEHOOKSTRUCT); 56 | 57 | export const tagMOUSEHOOKSTRUCTEX = { 58 | mouseData: DWORD, 59 | ...tagMOUSEHOOKSTRUCT, 60 | }; 61 | 62 | export const MOUSEHOOKSTRUCTEX = 'pointer'; 63 | export const StructMOUSEHOOKSTRUCTEX = Struct(tagMOUSEHOOKSTRUCTEX); 64 | 65 | export const tagKBDLLHOOKSTRUCT = { 66 | vkCode: DWORD, 67 | scanCode: DWORD, 68 | flags: DWORD, 69 | time: DWORD, 70 | dwExtraInfo: ULONG_PTR, 71 | }; 72 | 73 | export const KBDLLHOOKSTRUCT = 'pointer'; 74 | export const StructKBDLLHOOKSTRUCT = Struct(tagKBDLLHOOKSTRUCT); 75 | 76 | export const LPRECT = 'pointer'; 77 | 78 | export const LPCDLGTEMPLATE = 'pointer'; 79 | 80 | export const LPCDLGTEMPLATEW = 'pointer'; 81 | 82 | export const LPCDLGTEMPLATEA = 'pointer'; 83 | 84 | export const PGESTUREINFO = 'pointer'; 85 | 86 | export const LPCMENUITEMINFOA = 'pointer'; 87 | 88 | export const LPCMENUITEMINFOW = 'pointer'; 89 | 90 | export const LPPAINTSTRUCT = 'pointer'; 91 | 92 | export const PBSMINFO = 'pointer'; 93 | 94 | export const LPCRECT = 'pointer'; 95 | 96 | export const LPMSG = 'pointer'; 97 | 98 | export const DEVMODEA = 'pointer'; 99 | 100 | export const DEVMODEW = 'pointer'; 101 | 102 | export const PCHANGEFILTERSTRUCT = 'pointer'; 103 | 104 | export const LPPOINT = 'pointer'; 105 | 106 | export const LPACCEL = 'pointer'; 107 | 108 | export const PICONINFO = 'pointer'; 109 | 110 | export const PRAWINPUT = 'pointer'; 111 | 112 | export const LPTPMPARAMS = 'pointer'; 113 | 114 | export const LPTRACKMOUSEEVENT = 'pointer'; 115 | 116 | export const WINDOWPLACEMENT = 'pointer'; 117 | 118 | export const LPCSCROLLINFO = 'pointer'; 119 | 120 | export const LPCMENUINFO = 'pointer'; 121 | 122 | export const PGESTURECONFIG = 'pointer'; 123 | 124 | export const DISPLAYCONFIG_PATH_INFO = 'pointer'; 125 | 126 | export const LPINPUT = 'pointer'; 127 | 128 | export const PCRAWINPUTDEVICE = 'pointer'; 129 | 130 | export const LPCGUID = 'pointer'; 131 | 132 | export const LPDRAWTEXTPARAMS = 'pointer'; 133 | 134 | export const PAINTSTRUCT = 'pointer'; 135 | 136 | export const TOUCH_HIT_TESTING_INPUT = 'pointer'; 137 | 138 | export const TOUCH_HIT_TESTING_PROXIMITY_EVALUATION = 'pointer'; 139 | 140 | export const PFLASHWINFO = 'pointer'; 141 | 142 | export const PALTTABINFO = 'pointer'; 143 | 144 | export const WNDCLASSA = 'pointer'; 145 | 146 | export const WNDCLASSEXA = 'pointer'; 147 | 148 | export const WNDCLASSEXW = 'pointer'; 149 | 150 | export const WNDCLASSW = 'pointer'; 151 | 152 | export const MSGBOXPARAMSA = 'pointer'; 153 | 154 | export const MSGBOXPARAMSW = 'pointer'; 155 | 156 | export const PWINDOWINFO = 'pointer'; 157 | 158 | export const POINTER_TOUCH_INFO = 'pointer'; 159 | 160 | export const POINTER_TYPE_INFO = 'pointer'; 161 | 162 | export const PTITLEBARINFO = 'pointer'; 163 | 164 | export const PTOUCHINPUT = 'pointer'; 165 | 166 | export const LPSCROLLINFO = 'pointer'; 167 | 168 | export const PSCROLLBARINFO = 'pointer'; 169 | 170 | export const PRAWINPUTDEVICE = 'pointer'; 171 | 172 | export const POINTER_DEVICE_PROPERTY = 'pointer'; 173 | 174 | export const PRAWINPUTDEVICELIST = 'pointer'; 175 | 176 | export const POINTER_PEN_INFO = 'pointer'; 177 | 178 | export const INPUT_TRANSFORM = 'pointer'; 179 | 180 | export const POINTER_INFO = 'pointer'; 181 | 182 | export const POINTER_DEVICE_INFO = 'pointer'; 183 | 184 | export const POINTER_DEVICE_CURSOR_INFO = 'pointer'; 185 | 186 | export const LPMOUSEMOVEPOINT = 'pointer'; 187 | 188 | export const LPMONITORINFO = 'pointer'; 189 | 190 | export const LPMENUITEMINFOA = 'pointer'; 191 | 192 | export const LPMENUITEMINFOW = 'pointer'; 193 | 194 | export const LPMENUINFO = 'pointer'; 195 | 196 | export const INPUT_MESSAGE_SOURCE = 'pointer'; 197 | 198 | export const LPWNDCLASSA = 'pointer'; 199 | 200 | export const LPWNDCLASSEXA = 'pointer'; 201 | 202 | export const LPWNDCLASSEXW = 'pointer'; 203 | 204 | export const LPWNDCLASSW = 'pointer'; 205 | 206 | export const PCOMBOBOXINFO = 'pointer'; 207 | 208 | export const PCURSORINFO = 'pointer'; 209 | 210 | export const PGUITHREADINFO = 'pointer'; 211 | 212 | export const PICONINFOEXA = 'pointer'; 213 | 214 | export const PICONINFOEXW = 'pointer'; 215 | 216 | export const PLASTINPUTINFO = 'pointer'; 217 | 218 | export const PMENUBARINFO = 'pointer'; 219 | -------------------------------------------------------------------------------- /lib/cpp/user32/win_user_type.ts: -------------------------------------------------------------------------------- 1 | import { PVOID, VOID } from './win_nt'; 2 | import { DWORD } from './win_def'; 3 | import { _DECLARE_HANDLE } from './win_common'; 4 | 5 | /** 6 | * Proc 7 | */ 8 | export const WNDPROC = 'pointer'; 9 | export const DLGPROC = 'pointer'; 10 | export const WNDENUMPROC = 'pointer'; 11 | export const DRAWSTATEPROC = 'pointer'; 12 | export const DESKTOPENUMPROCA = 'pointer'; 13 | export const DESKTOPENUMPROCW = 'pointer'; 14 | export const TIMERPROC = 'pointer'; 15 | export const WINEVENTPROC = 'pointer'; 16 | export const WINSTAENUMPROCA = 'pointer'; 17 | export const GRAYSTRINGPROC = 'pointer'; 18 | export const PROPENUMPROCA = 'pointer'; 19 | export const PROPENUMPROCEXA = 'pointer'; 20 | export const PROPENUMPROCEXW = 'pointer'; 21 | export const PROPENUMPROCW = 'pointer'; 22 | export const WINSTAENUMPROCW = 'pointer'; 23 | export const MONITORENUMPROC = 'pointer'; 24 | export const SENDASYNCPROC = 'pointer'; 25 | 26 | export const HGESTUREINFO = _DECLARE_HANDLE; 27 | export const HTOUCHINPUT = _DECLARE_HANDLE; 28 | export const HRAWINPUT = _DECLARE_HANDLE; 29 | export const HSYNTHETICPOINTERDEVICE = _DECLARE_HANDLE; 30 | export const HWINEVENTHOOK = _DECLARE_HANDLE; 31 | export const DPI_AWARENESS_CONTEXT = _DECLARE_HANDLE; 32 | export const HMONITOR = _DECLARE_HANDLE; 33 | 34 | export const HDEVNOTIFY = PVOID; 35 | export const HPOWERNOTIFY = PVOID; 36 | export const MENUTEMPLATEA = VOID; 37 | export const MENUTEMPLATEW = VOID; 38 | 39 | /** 40 | * Enum 41 | */ 42 | export const POINTER_INPUT_TYPE = DWORD; 43 | export const POINTER_FEEDBACK_MODE = DWORD; 44 | export const DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS = 'pointer'; 45 | export const DIALOG_DPI_CHANGE_BEHAVIORS = 'pointer'; 46 | export const ORIENTATION_PREFERENCE = 'pointer'; 47 | export const PAR_STATE = 'pointer'; 48 | export const DPI_AWARENESS = 'pointer'; 49 | export const DPI_HOSTING_BEHAVIOR = 'pointer'; 50 | export const FEEDBACK_TYPE = 'pointer'; 51 | export const DISPLAYCONFIG_TOPOLOGY_ID = 'pointer'; 52 | export const DISPLAYCONFIG_MODE_INFO = 'pointer'; 53 | -------------------------------------------------------------------------------- /lib/cpp/utils.ts: -------------------------------------------------------------------------------- 1 | const _ARCH_ = process.arch; 2 | const _UNICODE_ = process.env.WIN_ICONV; 3 | 4 | /** 5 | * @return {number} x64 = 0 x32 = 1 6 | */ 7 | export const arch = (): number => { 8 | switch (_ARCH_) { 9 | case 'x64': 10 | return 0; 11 | case 'x32': 12 | return 1; 13 | default: 14 | return 0; 15 | } 16 | }; 17 | 18 | /** 19 | * @return {number} unicode = 0 ascii = 1 20 | */ 21 | export const iconv = (): number => { 22 | switch (_UNICODE_) { 23 | case '_UNICODE_': 24 | return 0; 25 | default: 26 | return 1; 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /lib/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2022 WangHan 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import StructType = require('ref-struct-di'); 18 | import { Ref } from './ts/ref'; 19 | import * as missDeclarationRef from 'ref-napi'; 20 | 21 | export * as TS from './ts'; 22 | export * as CPP from './cpp'; 23 | export * from './cpp/string'; 24 | export * from './win32-ffi'; 25 | const ref: Ref = missDeclarationRef as Ref; 26 | const { NULL_POINTER, NULL } = missDeclarationRef; 27 | /** 28 | * @see https://www.npmjs.com/package/ffi-napi 29 | */ 30 | export * as ffi from 'ffi-napi'; 31 | 32 | /** 33 | * @see https://www.npmjs.com/package/ref-struct-di 34 | */ 35 | export { StructType, ref, NULL, NULL_POINTER }; 36 | 37 | export * from './library'; 38 | -------------------------------------------------------------------------------- /lib/library.ts: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 2 | //@ts-nocheck 3 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 4 | //@ts-ignore 5 | 6 | import { ForeignFunction, VariadicForeignFunction } from 'ffi-napi'; 7 | import * as util from 'util'; 8 | import assert from 'assert'; 9 | import * as ref from 'ref-napi'; 10 | import { join } from 'path'; 11 | import { readFileSync } from 'fs'; 12 | 13 | const debug = util.debuglog('win32-ffi:library'); 14 | 15 | let bindings = require('node-gyp-build')(join(require.resolve('ffi-napi'), '../..')); 16 | bindings = bindings.initializeBindings(ref.instance); 17 | 18 | const funcs = bindings.StaticFunctions; 19 | const int = ref.types.int; 20 | const voidPtr = ref.refType(ref.types.void); 21 | const dlopen = ForeignFunction(funcs.dlopen, voidPtr, ['string', int]); 22 | const dlclose = ForeignFunction(funcs.dlclose, int, [voidPtr]); 23 | const dlsym = ForeignFunction(funcs.dlsym, voidPtr, [voidPtr, 'string']); 24 | const dlerror = ForeignFunction(funcs.dlerror, 'string', []); 25 | 26 | /** 27 | * The extension to use on libraries. 28 | * i.e. libm -> libm.so on linux 29 | */ 30 | 31 | const EXT = (SecureLibrary.EXT = { 32 | linux: '.so', 33 | linux2: '.so', 34 | sunos: '.so', 35 | solaris: '.so', 36 | freebsd: '.so', 37 | openbsd: '.so', 38 | darwin: '.dylib', 39 | mac: '.dylib', 40 | win32: '.dll', 41 | } as any)[process.platform]; 42 | 43 | /** 44 | * `SecureDynamicLibrary` loads and fetches function pointers for dynamic libraries 45 | * (.so, .dylib, etc). After the libray's function pointer is acquired, then you 46 | * call `get(symbol)` to retreive a pointer to an exported symbol. You need to 47 | * call `get___()` on the pointer to dereference it into its actual value, or 48 | * turn the pointer into a callable function with `ForeignFunction`. 49 | */ 50 | 51 | export const SecureDynamicLibrary = function (path?: string, mode?: number) { 52 | if (!(this instanceof SecureDynamicLibrary)) { 53 | return new SecureDynamicLibrary(path, mode); 54 | } 55 | debug('new SecureDynamicLibrary()', path, mode); 56 | 57 | if (null == mode) { 58 | mode = SecureDynamicLibrary.FLAGS.RTLD_LAZY; 59 | } 60 | 61 | this._path = path; 62 | this._handle = dlopen(path, mode); 63 | assert(Buffer.isBuffer(this._handle), 'expected a Buffer instance to be returned from `dlopen()`'); 64 | 65 | if (this._handle.isNull()) { 66 | const err = this.error(); 67 | 68 | // THIS CODE IS BASED ON GHC Trac ticket #2615 69 | // http://hackage.haskell.org/trac/ghc/attachment/ticket/2615 70 | 71 | // On some systems (e.g., Gentoo Linux) dynamic files (e.g. libc.so) 72 | // contain linker scripts rather than ELF-format object code. This 73 | // code handles the situation by recognizing the real object code 74 | // file name given in the linker script. 75 | 76 | // If an "invalid ELF header" error occurs, it is assumed that the 77 | // .so file contains a linker script instead of ELF object code. 78 | // In this case, the code looks for the GROUP ( ... ) linker 79 | // directive. If one is found, the first file name inside the 80 | // parentheses is treated as the name of a dynamic library and the 81 | // code attempts to dlopen that file. If this is also unsuccessful, 82 | // an error message is returned. 83 | 84 | // see if the error message is due to an invalid ELF header 85 | let match; 86 | 87 | if ((match = err.match(/^(([^ \t()])+\.so([^ \t:()])*):([ \t])*/))) { 88 | const content = readFileSync(match[1], 'ascii'); 89 | // try to find a GROUP ( ... ) command 90 | if ((match = content.match(/GROUP *\( *(([^ )])+)/))) { 91 | return SecureDynamicLibrary.call(this, match[1], mode); 92 | } 93 | } 94 | 95 | throw new Error('Dynamic Linking Error: ' + err); 96 | } 97 | }; 98 | 99 | /** 100 | * Set the exported flags from "dlfcn.h" 101 | */ 102 | 103 | SecureDynamicLibrary.FLAGS = {} as any; 104 | Object.keys(bindings).forEach(function (k) { 105 | if (!/^RTLD_/.test(k)) return; 106 | const desc = Object.getOwnPropertyDescriptor(bindings, k); 107 | Object.defineProperty(SecureDynamicLibrary.FLAGS, k, desc!); 108 | }); 109 | 110 | /** 111 | * Close this library, returns the result of the dlclose() system function. 112 | */ 113 | 114 | SecureDynamicLibrary.prototype.close = function () { 115 | debug('dlclose()'); 116 | return dlclose(this._handle); 117 | }; 118 | 119 | /** 120 | * Get a symbol from this library, returns a Pointer for (memory address of) the symbol 121 | */ 122 | 123 | SecureDynamicLibrary.prototype.get = function (symbol: string): Buffer { 124 | debug('dlsym()', symbol); 125 | assert.strictEqual('string', typeof symbol); 126 | 127 | const ptr = dlsym(this._handle, symbol); 128 | assert(Buffer.isBuffer(ptr)); 129 | 130 | if (ptr.isNull()) { 131 | return; 132 | } 133 | 134 | ptr.name = symbol; 135 | 136 | return ptr; 137 | }; 138 | 139 | /** 140 | * Returns the result of the dlerror() system function 141 | */ 142 | SecureDynamicLibrary.prototype.error = function error() { 143 | debug('dlerror()'); 144 | return dlerror(); 145 | }; 146 | 147 | /** 148 | * Returns the path originally passed to the constructor 149 | */ 150 | SecureDynamicLibrary.prototype.path = function error() { 151 | return this._path; 152 | }; 153 | 154 | const RTLD_NOW = SecureDynamicLibrary.FLAGS.RTLD_NOW; 155 | 156 | /** 157 | * Provides a friendly abstraction/API on-top of SecureDynamicLibrary and 158 | * ForeignFunction. 159 | */ 160 | 161 | // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types 162 | export function SecureLibrary(libfile: string, funcs: any, lib?: any): any { 163 | debug('creating Library object for %s', libfile); 164 | 165 | if (libfile && typeof libfile === 'string' && libfile.indexOf(EXT) === -1) { 166 | debug('appending library extension to library name'); 167 | libfile += EXT; 168 | } 169 | 170 | if (!lib) { 171 | lib = {}; 172 | } 173 | let dl: any; 174 | if (typeof libfile === 'string' || !libfile) { 175 | dl = new SecureDynamicLibrary(libfile, RTLD_NOW); 176 | } else { 177 | dl = libfile; 178 | } 179 | 180 | for (const func of Object.keys(funcs || {})) { 181 | debug('defining function %s', func); 182 | 183 | const fptr = dl.get(func); 184 | const info = funcs[func]; 185 | 186 | if (!fptr) { 187 | continue; 188 | } 189 | 190 | if (fptr.isNull()) { 191 | throw new Error('Library: "' + dl.path() + '" returned NULL function pointer for "' + func + '"'); 192 | } 193 | 194 | const resultType = info[0]; 195 | const paramTypes = info[1]; 196 | const fopts = info[2]; 197 | const abi = fopts && fopts.abi; 198 | const async = fopts && fopts.async; 199 | const varargs = fopts && fopts.varargs; 200 | 201 | if (varargs) { 202 | lib[func] = VariadicForeignFunction(fptr, resultType, paramTypes, abi); 203 | } else { 204 | const ff = ForeignFunction(fptr, resultType, paramTypes, abi); 205 | lib[func] = async ? ff.async : ff; 206 | } 207 | } 208 | 209 | return lib; 210 | } 211 | -------------------------------------------------------------------------------- /lib/ts/common.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/ban-types */ 2 | /** 3 | * for 64bit 4 | */ 5 | /// 6 | import * as ref from 'ref-napi'; 7 | 8 | export type BigIntString = bigint | string; 9 | export type Value = number | boolean | BigIntString | void | Buffer; 10 | export type Pointer = Buffer; 11 | 12 | export interface TsWin32FnsBasic { 13 | [fnName: string]: (...args: any[]) => Value; 14 | } 15 | 16 | export interface FfiWin32Fns { 17 | [fnName: string]: any[]; 18 | } 19 | 20 | interface _AsyncCallback

{ 21 | (err: Error, res: P): void; 22 | } 23 | 24 | export type TsWin32Fns = { 25 | [P in keyof T]: T[P] & { async: (...args: Array<_AsyncCallback> | Value>) => void }; 26 | }; 27 | 28 | // export type RefStruct = RefBuffer; 29 | // fix struct doesn't have ref 30 | export interface _RefBuffer extends Buffer { 31 | address(): number; 32 | isNull(): boolean; 33 | ref(): any; 34 | deref(): any; 35 | readObject: any; 36 | writeObject: any; 37 | readPointer: any; 38 | writePointer: any; 39 | readCString: any; 40 | writeCString: any; 41 | readInt64BE: any; 42 | writeInt64BE: any; 43 | readUInt64BE: any; 44 | writeUInt64BE: any; 45 | readInt64LE: any; 46 | writeInt64LE: any; 47 | reinterpret: any; 48 | reinterpretUntilZeros: any; 49 | type?: ref.Type; 50 | } 51 | 52 | export interface RefBuffer extends _RefBuffer { 53 | readObject: (offset?: number) => Object; 54 | writeObject: (offset: number, object: Object) => void; 55 | readPointer: (offset?: number, length?: number) => RefBuffer; 56 | writePointer: (offset: number, pointer: RefBuffer) => void; 57 | readCString: (offset?: number) => string; 58 | writeCString: (offset: number, string: string, encoding?: string) => void; 59 | readInt64BE: (offset?: number) => any; 60 | writeInt64BE: (offset: number, input: number) => void; 61 | readUInt64BE: (offset?: number) => any; 62 | writeUInt64BE: (offset: number, input: number) => void; 63 | readInt64LE: (offset?: number) => any; 64 | writeInt64LE: (offset: number, input: number) => void; 65 | reinterpret: (size: number, offset?: number) => RefBuffer; 66 | reinterpretUntilZeros: (size: number, offset?: number) => RefBuffer; 67 | } 68 | 69 | export type RefStruct = RefBuffer & T; 70 | -------------------------------------------------------------------------------- /lib/ts/index.ts: -------------------------------------------------------------------------------- 1 | 2 | export * from './user32'; 3 | export * from './common'; 4 | export * from './kernel32'; 5 | -------------------------------------------------------------------------------- /lib/ts/kernel32/err_handling_api.ts: -------------------------------------------------------------------------------- 1 | import { DWORD } from './../user32/win_def'; 2 | import { TsWin32FnsBasic } from '../common'; 3 | 4 | export interface ErrHandlingApi extends TsWin32FnsBasic { 5 | GetLastError: () => DWORD; 6 | } 7 | -------------------------------------------------------------------------------- /lib/ts/kernel32/index.ts: -------------------------------------------------------------------------------- 1 | import { LibLoaderApiFns } from './lib_loader_api_fns'; 2 | import { SysInfoApiFns } from './sys_info_api'; 3 | import { ProcessThreadsApiFns } from './process_threads_api_fns'; 4 | import { ErrHandlingApi } from './err_handling_api'; 5 | 6 | export * from './lib_loader_api_type'; 7 | 8 | export type Kernel32Fns = LibLoaderApiFns & 9 | SysInfoApiFns & 10 | ProcessThreadsApiFns & 11 | ErrHandlingApi; 12 | -------------------------------------------------------------------------------- /lib/ts/kernel32/lib_loader_api_fns.ts: -------------------------------------------------------------------------------- 1 | import { TsWin32FnsBasic } from '../common'; 2 | 3 | export interface LibLoaderApiFns extends TsWin32FnsBasic { 4 | AddDllDirectory: (NewDirectory: any) => any; 5 | DisableThreadLibraryCalls: (hLibModule: any) => any; 6 | EnumResourceLanguagesExA: ( 7 | hModule: any, 8 | lpType: any, 9 | lpName: any, 10 | lpEnumFunc: any, 11 | lParam: any, 12 | dwFlags: any, 13 | LangId: any 14 | ) => any; 15 | EnumResourceLanguagesExW: ( 16 | hModule: any, 17 | lpType: any, 18 | lpName: any, 19 | lpEnumFunc: any, 20 | lParam: any, 21 | dwFlags: any, 22 | LangId: any 23 | ) => any; 24 | EnumResourceNamesExA: (hModule: any, lpType: any, lpEnumFunc: any, lParam: any, dwFlags: any, LangId: any) => any; 25 | EnumResourceNamesExW: (hModule: any, lpType: any, lpEnumFunc: any, lParam: any, dwFlags: any, LangId: any) => any; 26 | EnumResourceTypesExA: (hModule: any, lpEnumFunc: any, lParam: any, dwFlags: any, LangId: any) => any; 27 | EnumResourceTypesExW: (hModule: any, lpEnumFunc: any, lParam: any, dwFlags: any, LangId: any) => any; 28 | FindStringOrdinal: ( 29 | dwFindStringOrdinalFlags: any, 30 | lpStringSource: any, 31 | cchSource: any, 32 | lpStringValue: any, 33 | cchValue: any, 34 | bIgnoreCase: any 35 | ) => any; 36 | FreeLibrary: (hLibModule: any) => any; 37 | FreeLibraryAndExitThread: (hLibModule: any, dwExitCode: any) => any; 38 | FreeResource: (hResData: any) => any; 39 | GetModuleFileNameA: (hModule: any, lpFilename: any, nSize: any) => any; 40 | GetModuleFileNameW: (hModule: any, lpFilename: any, nSize: any) => any; 41 | GetModuleHandleA: (lpModuleName: any) => any; 42 | GetModuleHandleExA: (dwFlags: any, lpModuleName: any, phModule: any) => any; 43 | GetModuleHandleExW: (dwFlags: any, lpModuleName: any, phModule: any) => any; 44 | GetModuleHandleW: (lpModuleName: any) => any; 45 | GetProcAddress: (hModule: any, lpProcName: any) => any; 46 | LoadLibraryA: (lpLibFileName: any) => any; 47 | LoadLibraryExA: (lpLibFileName: any, hFile: any, dwFlags: any) => any; 48 | LoadLibraryExW: (lpLibFileName: any, hFile: any, dwFlags: any) => any; 49 | LoadLibraryW: (lpLibFileName: any) => any; 50 | LoadResource: (hModule: any, hResInfo: any) => any; 51 | LockResource: (hResData: any) => any; 52 | RemoveDllDirectory: (Cookie: any) => any; 53 | SetDefaultDllDirectories: (DirectoryFlags: any) => any; 54 | SizeofResource: (hModule: any, hResInfo: any) => any; 55 | } 56 | -------------------------------------------------------------------------------- /lib/ts/kernel32/lib_loader_api_type.ts: -------------------------------------------------------------------------------- 1 | import { Pointer } from '../common'; 2 | import { PVOID } from '../user32'; 3 | 4 | export type DLL_DIRECTORY_COOKIE = PVOID; 5 | 6 | export type ENUMRESLANGPROCA = Pointer; 7 | export type ENUMRESLANGPROCW = Pointer; 8 | export type ENUMRESNAMEPROCA = Pointer; 9 | export type ENUMRESNAMEPROCW = Pointer; 10 | export type ENUMRESTYPEPROCA = Pointer; 11 | export type ENUMRESTYPEPROCW = Pointer; 12 | -------------------------------------------------------------------------------- /lib/ts/kernel32/process_threads_api_fns.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | import { BOOL, DWORD, HRESULT, INT, LPDWORD, UINT } from './../user32/win_def'; 3 | 4 | import { TsWin32FnsBasic } from '../common'; 5 | import { LPSECURITY_ATTRIBUTES, LPTHREAD_START_ROUTINE } from '../user32/win_base'; 6 | import { SIZE_T } from '../user32/base_tsd'; 7 | import { LPVOID } from '../user32/win_def'; 8 | import { HANDLE, PCWSTR, PHANDLE, PULONG } from '../user32/win_nt'; 9 | 10 | export interface ProcessThreadsApiFns extends TsWin32FnsBasic { 11 | CreateThread: ( 12 | lpThreadAttributes: LPSECURITY_ATTRIBUTES | null, 13 | dwStackSize: SIZE_T, 14 | lpStartAddress: LPTHREAD_START_ROUTINE, 15 | lpParameter: LPVOID, 16 | dwCreationFlags: DWORD, 17 | lpThreadId: LPDWORD 18 | ) => HANDLE; 19 | ExitThread: (dwExitCode: DWORD) => void; 20 | SetThreadDescription: (hThread: HANDLE, lpThreadDescription: PCWSTR) => HRESULT; 21 | 22 | SetThreadPriority: (hThread: HANDLE, nPriority: INT) => BOOL; 23 | SetThreadPriorityBoost: (hThread: HANDLE, bDisablePriorityBoost: BOOL) => BOOL; 24 | SetThreadStackGuarantee: (StackSizeInBytes: PULONG) => BOOL; 25 | SetThreadToken: (Thread: PHANDLE, Token: HANDLE) => BOOL; 26 | SuspendThread: (hThread: HANDLE) => DWORD; 27 | SwitchToThread: () => BOOL; 28 | TerminateProcess: (hProcess: HANDLE, uExitCode: UINT) => BOOL; 29 | TerminateThread: (hThread: HANDLE, dwExitCode: DWORD) => BOOL; 30 | TlsAlloc: () => DWORD; 31 | TlsFree: (dwTlsIndex: DWORD) => BOOL; 32 | TlsGetValue: (dwTlsIndex: DWORD) => LPVOID; 33 | TlsSetValue: (dwTlsIndex: DWORD, lpTlsValue: LPVOID) => BOOL; 34 | } 35 | -------------------------------------------------------------------------------- /lib/ts/kernel32/sys_info_api.ts: -------------------------------------------------------------------------------- 1 | import { TsWin32FnsBasic } from '../common'; 2 | 3 | export interface SysInfoApiFns extends TsWin32FnsBasic { 4 | GetTickCount: () => any; 5 | } 6 | -------------------------------------------------------------------------------- /lib/ts/user32/base_tsd.ts: -------------------------------------------------------------------------------- 1 | import { Pointer, BigIntString } from '../common'; 2 | 3 | export type UINT_PTR = number | BigIntString; 4 | export type PUINT_PTR = Pointer; 5 | 6 | export type LONG_PTR = number | BigIntString; 7 | export type PLONG_PTR = Pointer; 8 | 9 | export type ULONG_PTR = number | BigIntString; 10 | export type DWORD_PTR = ULONG_PTR; 11 | 12 | export type HALF_PTR = number; 13 | export type PHALF_PTR = Pointer; 14 | export type UHALF_PTR = number; 15 | export type PUHALF_PTR = Pointer; 16 | 17 | export type PDWORD_PTR = Pointer; 18 | 19 | export type DWORD32 = number; 20 | export type DWORD64 = number | BigIntString; 21 | 22 | export type PDWORD32 = Pointer; 23 | export type PDWORD64 = Pointer; 24 | 25 | export type INT8 = number; 26 | export type INT16 = number; 27 | export type INT32 = number; 28 | export type INT64 = number | BigIntString; 29 | 30 | export type INT_PTR = number; 31 | export type PINT_PTR = Pointer; 32 | 33 | export type UINT8 = number; 34 | export type UINT16 = number; 35 | export type UINT32 = number; 36 | export type UINT64 = number | BigIntString; 37 | 38 | export type PINT8 = Pointer; 39 | export type PINT16 = Pointer; 40 | export type PINT32 = Pointer; 41 | export type PINT64 = Pointer; 42 | 43 | export type PUINT8 = Pointer; 44 | export type PUINT16 = Pointer; 45 | export type PUINT32 = Pointer; 46 | export type PUINT64 = Pointer; 47 | 48 | export type LONG32 = Pointer; 49 | export type LONG64 = number | BigIntString; 50 | 51 | export type ULONG32 = Pointer; 52 | export type ULONG64 = number | BigIntString; 53 | 54 | export type PLONG32 = Pointer; 55 | export type PLONG64 = Pointer; 56 | 57 | export type POINTER_32 = Pointer; 58 | export type POINTER_64 = Pointer; 59 | export type POINTER_SIGNED = Pointer; 60 | export type POINTER_UNSIGNED = Pointer; 61 | 62 | export type PSIZE_T = Pointer; 63 | export type PSSIZE_T = Pointer; 64 | export type SSIZE_T = LONG_PTR; 65 | export type SIZE_T = ULONG_PTR; 66 | -------------------------------------------------------------------------------- /lib/ts/user32/guid_def.ts: -------------------------------------------------------------------------------- 1 | import { Pointer } from '../common'; 2 | 3 | export type LPCGUID = Pointer; 4 | export type GUID = Pointer; 5 | -------------------------------------------------------------------------------- /lib/ts/user32/index.ts: -------------------------------------------------------------------------------- 1 | import { WinUserFns } from './win_user_fns'; 2 | export * from './base_tsd'; 3 | export * from './win_def'; 4 | export * from './win_nls'; 5 | export * from './win_nt'; 6 | export * from './win_user_struct'; 7 | export * from './win_user_type'; 8 | export * from './win_gdi'; 9 | export * from './win_base'; 10 | export * from './win_ternl'; 11 | 12 | export type User32Fns = WinUserFns; -------------------------------------------------------------------------------- /lib/ts/user32/win_base.ts: -------------------------------------------------------------------------------- 1 | import { Pointer } from '../common'; 2 | 3 | export type LPSECURITY_ATTRIBUTES = Pointer; 4 | export type LPTHREAD_START_ROUTINE = Pointer; 5 | -------------------------------------------------------------------------------- /lib/ts/user32/win_def.ts: -------------------------------------------------------------------------------- 1 | // import { RefStruct } from '../common'; 2 | import { BigIntString, Pointer } from '../common'; 3 | import { UINT_PTR, LONG_PTR } from './base_tsd'; 4 | import { HANDLE, LONG } from './win_nt'; 5 | 6 | /** 7 | * short == int16; 8 | * int == int32; 9 | * long == int64 10 | */ 11 | 12 | export type DWORD = number; 13 | export type WORD = number; 14 | 15 | export type DWORDLONG = number | BigIntString; 16 | 17 | export type UCHAR = string; 18 | export type PUCHAR = Pointer; 19 | 20 | export type USHORT = number; 21 | 22 | export type BOOL = number; 23 | export type BYTE = string | number; 24 | 25 | export type FLOAT = number; 26 | export type PFLOAT = Pointer; 27 | 28 | export type ATOM = WORD; 29 | /** 30 | * near: a 16 bit pointer that can address any byte in a 64k segment 31 | * far: a 32 bit pointer that contains a segment and an offset.Note that because segments can 32 | * @see {@link https://stackoverflow.com/questions/3575592/what-are-near-far-and-huge-pointers} 33 | */ 34 | export type PBOOL = Pointer; 35 | export type LPBOOL = Pointer; 36 | export type PBYTE = Pointer; 37 | export type LPBYTE = Pointer; 38 | export type LPINT = Pointer; 39 | export type PWORD = Pointer; 40 | export type LPWORD = Pointer; 41 | export type PDWORD = Pointer; 42 | export type LPDWORD = Pointer; 43 | export type LPVOID = Pointer; 44 | export type LPCVOID = Pointer; 45 | export type LPCOLORREF = Pointer; 46 | export type INT = number; 47 | export type UINT = number; 48 | export type PINT = Pointer; 49 | export type PUINT = Pointer; 50 | export type LPLONG = Pointer; 51 | export type ULONG = number; 52 | export type SPHANDLE = Pointer; 53 | export type LPHANDLE = Pointer; 54 | export type HFILE = number; 55 | export type HLOCAL = HANDLE; 56 | export type HACCEL = HANDLE; 57 | export type HBITMAP = HANDLE; 58 | export type HBRUSH = HANDLE; 59 | export type HCOLORSPACE = HANDLE; 60 | export type HCONV = HANDLE; 61 | export type HCONVLIST = HANDLE; 62 | export type HICON = HANDLE; 63 | export type HCURSOR = HICON; 64 | export type HDC = HANDLE; 65 | export type HDDEDATA = HANDLE; 66 | export type HDESK = HANDLE; 67 | export type HDROP = HANDLE; 68 | export type HDWP = HANDLE; 69 | export type HENHMETAFILE = HANDLE; 70 | export type HFONT = HANDLE; 71 | export type HGDIOBJ = HANDLE; 72 | export type HGLOBAL = HANDLE; 73 | export type HHOOK = HANDLE; 74 | export type HINSTANCE = HANDLE; 75 | export type HKEY = HANDLE; 76 | export type HKL = HANDLE; 77 | export type HMENU = HANDLE; 78 | export type HMETAFILE = HANDLE; 79 | export type HMODULE = HINSTANCE; 80 | // export type HMONITOR = ?; 81 | export type HPALETTE = HANDLE; 82 | export type HPEN = HANDLE; 83 | export type HRESULT = LONG; 84 | export type HRGN = HANDLE; 85 | export type HRSRC = HANDLE; 86 | export type HSZ = HANDLE; 87 | export type HWINSTA = HANDLE; 88 | export type HWND = HANDLE; 89 | export type CALLBACK = Pointer; 90 | export type WINAPI = Pointer; 91 | export type APIENTRY = WINAPI; 92 | export type FARPROC = Pointer; 93 | export type NEARPROC = Pointer; 94 | export type HOOKPROC = Pointer; 95 | export type COLORREF = DWORD; 96 | export type LPARAM = LONG_PTR; 97 | export type WPARAM = UINT_PTR; 98 | export type LRESULT = LONG_PTR; 99 | export type LPCRECT = Pointer; 100 | 101 | export type POINT = { 102 | x: LONG; 103 | y: LONG; 104 | }; 105 | export type POINTS = Pointer; 106 | export type SIZE = Pointer; 107 | -------------------------------------------------------------------------------- /lib/ts/user32/win_gdi.ts: -------------------------------------------------------------------------------- 1 | import { Pointer } from '../common'; 2 | 3 | export type PDISPLAY_DEVICEA = Pointer; 4 | export type PDISPLAY_DEVICEW = Pointer; 5 | export type DISPLAYCONFIG_PATH_INFO = Pointer; 6 | export type DISPLAYCONFIG_MODE_INFO = Pointer; 7 | -------------------------------------------------------------------------------- /lib/ts/user32/win_nls.ts: -------------------------------------------------------------------------------- 1 | 2 | export type LCTYPE = number; -------------------------------------------------------------------------------- /lib/ts/user32/win_nt.ts: -------------------------------------------------------------------------------- 1 | import { WORD, DWORD, BYTE, PDWORD } from './win_def'; 2 | import { Pointer, BigIntString } from '../common'; 3 | 4 | export type TBYTE = string | number; 5 | export type PTBYTE = Pointer; 6 | 7 | export type PVOID = Pointer; 8 | export type HANDLE = PVOID | number | BigIntString; 9 | 10 | export type LONG = number; 11 | export type LONGLONG = number; 12 | export type PLONG = Pointer; 13 | export type PLONGLONG = Pointer; 14 | export type ULONGLONG = number; 15 | 16 | export type CHAR = string; 17 | export type CCHAR = string; 18 | 19 | export type TCHAR = string | number; 20 | export type PTCHAR = Pointer; 21 | 22 | export type SHORT = string | number; 23 | export type PSHORT = Pointer; 24 | 25 | export type VOID = void | Pointer | number; 26 | 27 | export type LANGID = WORD; 28 | export type LCID = DWORD; 29 | export type LPCSTR = Pointer; 30 | export type LPCWSTR = Pointer; 31 | export type LPSTR = Pointer; 32 | export type LPCTSTR = Pointer; 33 | export type LPTSTR = Pointer; 34 | export type LPWSTR = Pointer; 35 | 36 | export type WCHAR = string | number; 37 | export type PWCHAR = Pointer; 38 | export type PCHAR = Pointer; 39 | export type PSTR = Pointer; 40 | export type PCSTR = Pointer; 41 | export type PCWSTR = Pointer; 42 | export type PLCID = PDWORD; 43 | export type PCTSTR = Pointer; 44 | export type PTSTR = Pointer; 45 | 46 | export type PHANDLE = Pointer; 47 | export type PHKEY = Pointer; 48 | export type PDWORDLONG = Pointer; 49 | 50 | export type BOOLEAN = BYTE; 51 | export type PBOOLEAN = Pointer; 52 | export type USN = LONGLONG; 53 | export type PULONG = Pointer; 54 | 55 | /** 56 | * 57 | */ 58 | 59 | export type ACCESS_MASK = DWORD; 60 | 61 | export type PSECURITY_INFORMATION = Pointer; 62 | export type PSECURITY_DESCRIPTOR = PVOID; 63 | -------------------------------------------------------------------------------- /lib/ts/user32/win_ternl.ts: -------------------------------------------------------------------------------- 1 | 2 | export type UNICODE_STRING = string; -------------------------------------------------------------------------------- /lib/ts/user32/win_user_struct.ts: -------------------------------------------------------------------------------- 1 | import { Pointer } from '../common'; 2 | import { HWND, UINT, WPARAM, LPARAM, DWORD, POINT } from './win_def'; 3 | import { ULONG_PTR } from './base_tsd'; 4 | 5 | export type LPMSG = Pointer; 6 | export type MSG = { 7 | hwnd: HWND; 8 | message: UINT; 9 | wParam: WPARAM; 10 | lParam: LPARAM; 11 | time: DWORD; 12 | pt: POINT; 13 | }; 14 | 15 | export type MOUSEHOOKSTRUCT = { 16 | pt: POINT; 17 | hwnd: HWND; 18 | wHitTestCode: UINT; 19 | dwExtraInfo: ULONG_PTR; 20 | }; 21 | 22 | export type MOUSEHOOKSTRUCTEX = { 23 | mouseData: DWORD; 24 | }; 25 | 26 | export type KBDLLHOOKSTRUCT = { 27 | vkCode: DWORD; 28 | scanCode: DWORD; 29 | flags: DWORD; 30 | time: DWORD; 31 | dwExtraInfo: ULONG_PTR; 32 | }; 33 | 34 | export type PBSMINFO = Pointer; 35 | 36 | export type RECT = Pointer; 37 | 38 | export type LPRECT = Pointer; 39 | 40 | export type DEVMODEA = Pointer; 41 | 42 | export type DEVMODEW = Pointer; 43 | 44 | export type PCHANGEFILTERSTRUCT = Pointer; 45 | 46 | export type LPPOINT = Pointer; 47 | 48 | export type LPACCEL = Pointer; 49 | 50 | export type DISPLAYCONFIG_DEVICE_INFO_HEADER = Pointer; 51 | 52 | export type PICONINFO = Pointer; 53 | 54 | export type POINTER_DEVICE_INFO = Pointer; 55 | 56 | export type POINTER_DEVICE_CURSOR_INFO = Pointer; 57 | 58 | export type POINTER_DEVICE_PROPERTY = Pointer; 59 | 60 | export type POINTER_INFO = Pointer; 61 | 62 | export type POINTER_PEN_INFO = Pointer; 63 | 64 | export type INPUT_TRANSFORM = Pointer; 65 | 66 | export type POINTER_TOUCH_INFO = Pointer; 67 | 68 | export type LPTRACKMOUSEEVENT = Pointer; 69 | 70 | export type PAINTSTRUCT = Pointer; 71 | 72 | export type PRAWINPUT = Pointer; 73 | 74 | export type LPDRAWTEXTPARAMS = Pointer; 75 | 76 | export type PGESTURECONFIG = Pointer; 77 | 78 | export type PGUITHREADINFO = Pointer; 79 | 80 | export type PICONINFOEXA = Pointer; 81 | 82 | export type PICONINFOEXW = Pointer; 83 | 84 | export type TPMPARAMS = Pointer; 85 | 86 | export type LPTPMPARAMS = Pointer; 87 | 88 | export type POINTER_TYPE_INFO = Pointer; 89 | 90 | export type PWINDOWINFO = Pointer; 91 | 92 | export type TOUCH_HIT_TESTING_INPUT = Pointer; 93 | 94 | export type TOUCH_HIT_TESTING_PROXIMITY_EVALUATION = Pointer; 95 | 96 | export type PFLASHWINFO = Pointer; 97 | 98 | export type PALTTABINFO = Pointer; 99 | 100 | export type INPUT_MESSAGE_SOURCE = Pointer; 101 | 102 | export type LPWNDCLASSA = Pointer; 103 | 104 | export type LPWNDCLASSEXA = Pointer; 105 | 106 | export type LPWNDCLASSEXW = Pointer; 107 | 108 | export type LPWNDCLASSW = Pointer; 109 | 110 | export type PCOMBOBOXINFO = Pointer; 111 | 112 | export type PCURSORINFO = Pointer; 113 | 114 | export type PLASTINPUTINFO = Pointer; 115 | 116 | export type PMENUBARINFO = Pointer; 117 | 118 | export type LPMENUINFO = Pointer; 119 | 120 | export type LPMENUITEMINFOA = Pointer; 121 | export type LPMENUITEMINFOW = Pointer; 122 | 123 | export type LPMONITORINFO = Pointer; 124 | export type LPMOUSEMOVEPOINT = Pointer; 125 | 126 | export type PTITLEBARINFO = Pointer; 127 | 128 | export type PTOUCHINPUT = Pointer; 129 | 130 | export type PRAWINPUTDEVICELIST = Pointer; 131 | export type PRAWINPUTDEVICE = Pointer; 132 | 133 | export type PSCROLLBARINFO = Pointer; 134 | export type LPSCROLLINFO = Pointer; 135 | export type LPCSCROLLINFO = Pointer; 136 | 137 | export type WINDOWPLACEMENT = Pointer; 138 | 139 | export type BLENDFUNCTION = Pointer; 140 | 141 | export type MSGBOXPARAMSA = Pointer; 142 | export type MSGBOXPARAMSW = Pointer; 143 | 144 | export type WNDCLASSA = Pointer; 145 | export type WNDCLASSEXA = Pointer; 146 | export type WNDCLASSEXW = Pointer; 147 | export type WNDCLASSW = Pointer; 148 | 149 | export type RAWINPUTDEVICE = Pointer; 150 | export type PCRAWINPUTDEVICE = Pointer; 151 | 152 | export type LPINPUT = Pointer; 153 | export type LPCMENUINFO = Pointer; 154 | 155 | export type LPCDLGTEMPLATE = Pointer; 156 | export type LPCDLGTEMPLATEW = Pointer; 157 | export type LPCDLGTEMPLATEA = Pointer; 158 | 159 | export type PGESTUREINFO = Pointer; 160 | 161 | export type LPCMENUITEMINFOA = Pointer; 162 | export type LPCMENUITEMINFOW = Pointer; 163 | 164 | export type LPPAINTSTRUCT = Pointer; 165 | -------------------------------------------------------------------------------- /lib/ts/user32/win_user_type.ts: -------------------------------------------------------------------------------- 1 | import { Pointer } from '../common'; 2 | import { HANDLE, PVOID, VOID } from './win_nt'; 3 | import { DWORD } from './win_def'; 4 | 5 | /** 6 | * Proc 7 | */ 8 | export type WNDPROC = Pointer; 9 | export type DLGPROC = Pointer; 10 | export type WNDENUMPROC = Pointer; 11 | export type DRAWSTATEPROC = Pointer; 12 | export type DESKTOPENUMPROCA = Pointer; 13 | export type DESKTOPENUMPROCW = Pointer; 14 | export type TIMERPROC = Pointer; 15 | export type WINEVENTPROC = Pointer; 16 | export type WINSTAENUMPROCA = Pointer; 17 | export type GRAYSTRINGPROC = Pointer; 18 | export type PROPENUMPROCA = Pointer; 19 | export type PROPENUMPROCEXA = Pointer; 20 | export type PROPENUMPROCEXW = Pointer; 21 | export type PROPENUMPROCW = Pointer; 22 | export type WINSTAENUMPROCW = Pointer; 23 | export type MONITORENUMPROC = Pointer; 24 | export type SENDASYNCPROC = Pointer; 25 | 26 | export type HGESTUREINFO = HANDLE; 27 | export type HTOUCHINPUT = HANDLE; 28 | export type HRAWINPUT = HANDLE; 29 | export type HSYNTHETICPOINTERDEVICE = HANDLE; 30 | export type HWINEVENTHOOK = HANDLE; 31 | export type DPI_AWARENESS_CONTEXT = HANDLE; 32 | export type HMONITOR = HANDLE; 33 | 34 | export type HDEVNOTIFY = PVOID; 35 | export type HPOWERNOTIFY = PVOID; 36 | export type MENUTEMPLATEA = VOID; 37 | export type MENUTEMPLATEW = VOID; 38 | 39 | /** 40 | * Enum 41 | */ 42 | export type POINTER_INPUT_TYPE = DWORD; 43 | export type POINTER_FEEDBACK_MODE = DWORD; 44 | export type DIALOG_CONTROL_DPI_CHANGE_BEHAVIORS = Pointer; 45 | export type DIALOG_DPI_CHANGE_BEHAVIORS = Pointer; 46 | export type ORIENTATION_PREFERENCE = Pointer; 47 | export type PAR_STATE = Pointer; 48 | export type DPI_AWARENESS = Pointer; 49 | export type DPI_HOSTING_BEHAVIOR = Pointer; 50 | export type FEEDBACK_TYPE = Pointer; 51 | export type DISPLAYCONFIG_TOPOLOGY_ID = Pointer; 52 | -------------------------------------------------------------------------------- /lib/win32-ffi.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | import { TsWin32Fns, User32Fns, Kernel32Fns, FfiWin32Fns } from './ts'; 3 | import { userMacroFns } from './cpp/user32/user_macro_fns'; 4 | import { user32Fns } from './cpp/user32'; 5 | import { kernel32Fns } from './cpp/kernel32'; 6 | import { SecureLibrary } from './library'; 7 | 8 | interface FFIOptions { 9 | unicode: boolean; 10 | } 11 | 12 | interface WindowsLibs { 13 | user32Fns?: FfiWin32Fns; 14 | kernel32Fns?: FfiWin32Fns; 15 | } 16 | 17 | export type Win32Fns = User32Fns & Kernel32Fns; 18 | 19 | export enum LibraryNames { 20 | user32 = 'User32', 21 | kernel32 = 'Kernel32', 22 | } 23 | 24 | let overrideOptions: WindowsLibs = { 25 | user32Fns: {}, 26 | kernel32Fns: {}, 27 | }; 28 | 29 | const defaultOptions = { 30 | /** 31 | * false ascii 32 | * @see {@link https://docs.microsoft.com/en-us/windows/win32/learnwin32/working-with-strings} 33 | */ 34 | unicode: true, 35 | }; 36 | 37 | export class Win32ffi { 38 | constructor(arg: FFIOptions = defaultOptions) { 39 | !!arg.unicode && (process.env.WIN_ICONV = '_UNICODE_'); 40 | } 41 | /** 42 | * User32 43 | * @template T 44 | * @returns user32 45 | */ 46 | // eslint-disable-next-line @typescript-eslint/ban-types 47 | public user32(): TsWin32Fns { 48 | const fns: TsWin32Fns = SecureLibrary( 49 | LibraryNames.user32, 50 | Object.assign({}, user32Fns as any, overrideOptions.user32Fns) 51 | ); 52 | return Object.assign({}, fns, userMacroFns(fns)); 53 | } 54 | 55 | /** 56 | * Kernel32 57 | * @template T 58 | * @returns kernel32 59 | */ 60 | public kernel32>(): TsWin32Fns { 61 | return SecureLibrary(LibraryNames.kernel32, Object.assign({}, kernel32Fns, overrideOptions.kernel32Fns)); 62 | } 63 | 64 | /** 65 | * win32 Api 66 | * @template T 67 | * @returns fns 68 | */ 69 | public winFns>(): TsWin32Fns { 70 | return Object.assign({}, this.user32(), this.kernel32()) as TsWin32Fns; 71 | } 72 | 73 | /** 74 | * @param opt [WindowsLibs] 75 | */ 76 | static assign(opt: WindowsLibs = overrideOptions): void { 77 | overrideOptions = opt; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "win32-ffi", 3 | "version": "0.0.6-alpha.5", 4 | "description": "Win32 api javascript binding", 5 | "author": "Han ", 6 | "homepage": "https://github.com/deskbtm/win32-ffi/", 7 | "license": "Apache-2.0", 8 | "main": "dist/index.js", 9 | "types": "dist/index.d.ts", 10 | "files": [ 11 | "lib/**", 12 | "dist/**" 13 | ], 14 | "publishConfig": { 15 | "registry": "https://registry.npmjs.org/" 16 | }, 17 | "keywords": [ 18 | "windows", 19 | "ffi", 20 | "electron", 21 | "node", 22 | "win32", 23 | "system" 24 | ], 25 | "engines": { 26 | "node": ">=14" 27 | }, 28 | "repository": { 29 | "type": "git", 30 | "url": "git+https://github.com/deskbtm/win32-ffi.git" 31 | }, 32 | "scripts": { 33 | "build": "rimraf ./dist && tsc -p tsconfig.json", 34 | "start": "rimraf ./dist && tsc -w -p tsconfig.json", 35 | "gen": "node ./scripts/win_cpp_fns_to_ts_generator.js", 36 | "doc": "typedoc ./lib --readme ./README.md", 37 | "lint": "eslint lib --fix --ext \".ts\" ", 38 | "test": "jest" 39 | }, 40 | "bugs": { 41 | "url": "https://github.com/deskbtm/win32-ffi/issues" 42 | }, 43 | "devDependencies": { 44 | "@types/ffi-napi": "^4.0.7", 45 | "@types/jest": "^27.4.1", 46 | "@types/ref-napi": "^3.0.4", 47 | "@types/ref-union-di": "^1.0.3", 48 | "@typescript-eslint/eslint-plugin": "^4.26.1", 49 | "@typescript-eslint/parser": "^4.26.1", 50 | "cheerio": "1.0.0-rc.10", 51 | "eslint": "^7.28.0", 52 | "eslint-plugin-import": "^2.23.4", 53 | "jest": "^27.5.1", 54 | "node-gyp": "^9.0.0", 55 | "request-promise": "^4.2.6", 56 | "rimraf": "^3.0.2", 57 | "ts-jest": "^27.1.4", 58 | "typedoc": "^0.22.13", 59 | "typescript": "^4.3.2" 60 | }, 61 | "dependencies": { 62 | "ffi-napi": "^4.0.3", 63 | "ref-napi": "^3.0.3", 64 | "ref-struct-di": "^1.1.1", 65 | "ref-union-di": "^1.0.1" 66 | } 67 | } -------------------------------------------------------------------------------- /scripts/win_cpp_fns_to_ts_generator.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const cheerio = require('cheerio'); 4 | const request = require('request-promise'); 5 | const fs = require('fs'); 6 | const { resolve, join } = require('path'); 7 | const { promisify } = require('util'); 8 | 9 | const appendFile = promisify(fs.appendFile); 10 | 11 | const chalk = require('chalk'); 12 | // '/winuser', '/libloaderapi' , '/processthreadsapi' 13 | const libList = ['/processthreadsapi', '/winuser', '/libloaderapi']; 14 | const baseUrl = 'https://docs.microsoft.com/'; 15 | 16 | const configure = { baseUrl }; 17 | const rp = request.defaults(configure); 18 | 19 | const createAbortError = () => { 20 | const error = new Error('Delay aborted'); 21 | error.name = 'AbortError'; 22 | return error; 23 | }; 24 | 25 | const createDelay = 26 | ({ clearTimeout: defaultClear, setTimeout: set, willResolve }) => 27 | (ms, { value, signal } = {}) => { 28 | if (signal && signal.aborted) { 29 | return Promise.reject(createAbortError()); 30 | } 31 | 32 | let timeoutId; 33 | let settle; 34 | let rejectFn; 35 | const clear = defaultClear || clearTimeout; 36 | 37 | const signalListener = () => { 38 | clear(timeoutId); 39 | rejectFn(createAbortError()); 40 | }; 41 | 42 | const cleanup = () => { 43 | if (signal) { 44 | signal.removeEventListener('abort', signalListener); 45 | } 46 | }; 47 | 48 | const delayPromise = new Promise((resolve, reject) => { 49 | settle = () => { 50 | cleanup(); 51 | if (willResolve) { 52 | resolve(value); 53 | } else { 54 | reject(value); 55 | } 56 | }; 57 | 58 | rejectFn = reject; 59 | timeoutId = (set || setTimeout)(settle, ms); 60 | }); 61 | 62 | if (signal) { 63 | signal.addEventListener('abort', signalListener, { once: true }); 64 | } 65 | 66 | delayPromise.clear = () => { 67 | clear(timeoutId); 68 | timeoutId = null; 69 | settle(); 70 | }; 71 | 72 | return delayPromise; 73 | }; 74 | 75 | const delay = createDelay({ willResolve: true }); 76 | 77 | // 这里本应该使用自动机来写 78 | var parseCppToTs = (code) => { 79 | const list = code.replace(/\n+/g, '').split(/\s+/g); 80 | let isStartParam = false; 81 | let retTsCode = ''; 82 | let retTsCppCode = ''; 83 | let funcName = ''; 84 | const retType = []; 85 | let paramType = []; 86 | let cppParamType = []; 87 | let tsParamString = ''; 88 | 89 | for (const c of list) { 90 | if (c.endsWith(');')) { 91 | if (c.includes('(')) { 92 | funcName = c.replace(/\(.*\);/g, ''); 93 | } else { 94 | tsParamString += c.replace(');', '') + (paramType.length !== 0 ? ':' + paramType.join('|') : ''); 95 | } 96 | retTsCode = funcName + ':' + `(${tsParamString})=> ${retType.join('|')};`; 97 | retTsCppCode = 98 | cppParamType.length > 0 99 | ? `${funcName}:[${retType.join('')}, [${cppParamType.join(',')}]],` 100 | : `${funcName}:[${retType.join('')},[\\placeholder]],`; 101 | } else if (isStartParam) { 102 | if (c.endsWith(',')) { 103 | if (paramType.length == 0) { 104 | tsParamString += c; 105 | } else { 106 | tsParamString += c.replace(',', '') + ':' + paramType.join('|') + ','; 107 | } 108 | paramType = []; 109 | } else { 110 | paramType.push(c.toUpperCase()); 111 | cppParamType.push(c.toUpperCase()); 112 | } 113 | } else if (c.endsWith('(')) { 114 | isStartParam = true; 115 | funcName = c.replace('(', ''); 116 | } else { 117 | retType.push(c.toUpperCase()); 118 | } 119 | } 120 | return { ts: retTsCode, ffi: retTsCppCode }; 121 | }; 122 | 123 | const extractContent = async (content) => { 124 | const $ = cheerio.load(content); 125 | const cppCode = $('pre').children('code').eq(0).text(); 126 | return parseCppToTs(cppCode); 127 | }; 128 | 129 | const baseDir = resolve(__dirname, `../temp/${new Date().toLocaleDateString().replace(/\//g, '-')}`); 130 | 131 | (async () => { 132 | for await (const lib of libList) { 133 | const intrefaceTemplate = `export interface WinUserFns extends TsWin32FnsBasic {\n`; 134 | const ffiTemplate = `export const ${lib.replace('/', '')}Fns = {\n `; 135 | 136 | const contentsBody = await rp.get('/en-us/windows/win32/api' + lib).catch((err) => console.log(err)); 137 | const $ = cheerio.load(contentsBody); 138 | const trs = $('#functions').next().children('tbody').children('tr'); 139 | 140 | const uid = ((Math.random() + Date.now()) * 0xffffff).toString(36); 141 | 142 | const typePath = join(baseDir, `${lib}.type.${uid}.txt`); 143 | const ffiPath = join(baseDir, `${lib}.ffi.${uid}.txt`); 144 | 145 | await fs.promises.mkdir(baseDir, { recursive: true }); 146 | 147 | await appendFile(typePath, intrefaceTemplate).catch((err) => console.log(err)); 148 | await appendFile(ffiPath, ffiTemplate).catch((err) => console.log(err)); 149 | 150 | for (let index = 0; index < trs.length; index++) { 151 | const tr = trs[index]; 152 | const aLink = $(tr).children('td').eq(0).children('a'); 153 | const href = aLink.attr()['href']; 154 | const detailContent = await rp.get(href).catch((err) => console.log(err)); 155 | const codes = await extractContent(detailContent); 156 | 157 | console.log(chalk.green('Code Generate ----------------')); 158 | console.log(chalk.yellow(`Ts:${codes.ts}`)); 159 | console.log(chalk.green('----------------------------------')); 160 | console.log(chalk.yellow(`FFi:${codes.ffi}`)); 161 | console.log(chalk.green('----------------------------------')); 162 | console.log('\n'); 163 | 164 | await appendFile(typePath, codes.ts + '\n').catch((err) => console.log(err)); 165 | await appendFile(ffiPath, codes.ffi + '\n').catch((err) => console.log(err)); 166 | await delay(1000); 167 | } 168 | 169 | await appendFile(typePath, '}').catch((err) => console.log(err)); 170 | await appendFile(ffiPath, '}').catch((err) => console.log(err)); 171 | } 172 | })(); 173 | 174 | process.once('uncaughtException', () => { 175 | fs.rmSync(baseDir, { recursive: true }); 176 | }); 177 | -------------------------------------------------------------------------------- /tea.yaml: -------------------------------------------------------------------------------- 1 | # https://tea.xyz/what-is-this-file 2 | --- 3 | version: 1.0.0 4 | codeOwners: 5 | - '0x06722c4e5E8e0dE519e387fd571E2e1738F97De8' 6 | quorum: 1 7 | -------------------------------------------------------------------------------- /temp/legacy/libloaderapi.ffi.5n69s0sihf800.txt: -------------------------------------------------------------------------------- 1 | export const libloaderapiFns = { 2 | AddDllDirectory:[DLL_DIRECTORY_COOKIE, [PCWSTR]], 3 | DisableThreadLibraryCalls:[BOOL, [HMODULE]], 4 | EnumResourceLanguagesExA:[BOOL, [HMODULE,LPCSTR,LPCSTR,ENUMRESLANGPROCA,LONG_PTR,DWORD,LANGID]], 5 | EnumResourceLanguagesExW:[BOOL, [HMODULE,LPCWSTR,LPCWSTR,ENUMRESLANGPROCW,LONG_PTR,DWORD,LANGID]], 6 | EnumResourceNamesExA:[BOOL, [HMODULE,LPCSTR,ENUMRESNAMEPROCA,LONG_PTR,DWORD,LANGID]], 7 | EnumResourceNamesExW:[BOOL, [HMODULE,LPCWSTR,ENUMRESNAMEPROCW,LONG_PTR,DWORD,LANGID]], 8 | EnumResourceTypesExA:[BOOL, [HMODULE,ENUMRESTYPEPROCA,LONG_PTR,DWORD,LANGID]], 9 | EnumResourceTypesExW:[BOOL, [HMODULE,ENUMRESTYPEPROCW,LONG_PTR,DWORD,LANGID]], 10 | FindStringOrdinal:[INT, [DWORD,LPCWSTR,INT,LPCWSTR,INT,BOOL]], 11 | FreeLibrary:[BOOL, [HMODULE]], 12 | FreeLibraryAndExitThread:[VOID, [HMODULE,DWORD]], 13 | FreeResource:[BOOL, [HGLOBAL]], 14 | GetModuleFileNameA:[DWORD, [HMODULE,LPSTR,DWORD]], 15 | GetModuleFileNameW:[DWORD, [HMODULE,LPWSTR,DWORD]], 16 | GetModuleHandleA:[HMODULE, [LPCSTR]], 17 | GetModuleHandleExA:[BOOL, [DWORD,LPCSTR,HMODULE]], 18 | GetModuleHandleExW:[BOOL, [DWORD,LPCWSTR,HMODULE]], 19 | GetModuleHandleW:[HMODULE, [LPCWSTR]], 20 | GetProcAddress:[FARPROC, [HMODULE,LPCSTR]], 21 | LoadLibraryA:[HMODULE, [LPCSTR]], 22 | LoadLibraryExA:[HMODULE, [LPCSTR,HANDLE,DWORD]], 23 | LoadLibraryExW:[HMODULE, [LPCWSTR,HANDLE,DWORD]], 24 | LoadLibraryW:[HMODULE, [LPCWSTR]], 25 | LoadResource:[HGLOBAL, [HMODULE,HRSRC]], 26 | LockResource:[LPVOID, [HGLOBAL]], 27 | RemoveDllDirectory:[BOOL, [DLL_DIRECTORY_COOKIE]], 28 | SetDefaultDllDirectories:[BOOL, [DWORD]], 29 | SizeofResource:[DWORD, [HMODULE,HRSRC]], 30 | } -------------------------------------------------------------------------------- /temp/legacy/libloaderapi.type.5n69s0sihf800.txt: -------------------------------------------------------------------------------- 1 | export interface WinUserFns extends TsWin32Fns { 2 | AddDllDirectory:(NewDirectory:PCWSTR)=> DLL_DIRECTORY_COOKIE; 3 | DisableThreadLibraryCalls:(hLibModule:HMODULE)=> BOOL; 4 | EnumResourceLanguagesExA:(hModule:HMODULE,lpType:LPCSTR,lpName:LPCSTR,lpEnumFunc:ENUMRESLANGPROCA,lParam:LONG_PTR,dwFlags:DWORD,LangId:LANGID)=> BOOL; 5 | EnumResourceLanguagesExW:(hModule:HMODULE,lpType:LPCWSTR,lpName:LPCWSTR,lpEnumFunc:ENUMRESLANGPROCW,lParam:LONG_PTR,dwFlags:DWORD,LangId:LANGID)=> BOOL; 6 | EnumResourceNamesExA:(hModule:HMODULE,lpType:LPCSTR,lpEnumFunc:ENUMRESNAMEPROCA,lParam:LONG_PTR,dwFlags:DWORD,LangId:LANGID)=> BOOL; 7 | EnumResourceNamesExW:(hModule:HMODULE,lpType:LPCWSTR,lpEnumFunc:ENUMRESNAMEPROCW,lParam:LONG_PTR,dwFlags:DWORD,LangId:LANGID)=> BOOL; 8 | EnumResourceTypesExA:(hModule:HMODULE,lpEnumFunc:ENUMRESTYPEPROCA,lParam:LONG_PTR,dwFlags:DWORD,LangId:LANGID)=> BOOL; 9 | EnumResourceTypesExW:(hModule:HMODULE,lpEnumFunc:ENUMRESTYPEPROCW,lParam:LONG_PTR,dwFlags:DWORD,LangId:LANGID)=> BOOL; 10 | FindStringOrdinal:(dwFindStringOrdinalFlags:DWORD,lpStringSource:LPCWSTR,cchSource:INT,lpStringValue:LPCWSTR,cchValue:INT,bIgnoreCase:BOOL)=> INT; 11 | FreeLibrary:(hLibModule:HMODULE)=> BOOL; 12 | FreeLibraryAndExitThread:(hLibModule:HMODULE,dwExitCode:DWORD)=> VOID; 13 | FreeResource:(hResData:HGLOBAL)=> BOOL; 14 | GetModuleFileNameA:(hModule:HMODULE,lpFilename:LPSTR,nSize:DWORD)=> DWORD; 15 | GetModuleFileNameW:(hModule:HMODULE,lpFilename:LPWSTR,nSize:DWORD)=> DWORD; 16 | GetModuleHandleA:(lpModuleName:LPCSTR)=> HMODULE; 17 | GetModuleHandleExA:(dwFlags:DWORD,lpModuleName:LPCSTR,*phModule:HMODULE)=> BOOL; 18 | GetModuleHandleExW:(dwFlags:DWORD,lpModuleName:LPCWSTR,*phModule:HMODULE)=> BOOL; 19 | GetModuleHandleW:(lpModuleName:LPCWSTR)=> HMODULE; 20 | GetProcAddress:(hModule:HMODULE,lpProcName:LPCSTR)=> FARPROC; 21 | LoadLibraryA:(lpLibFileName:LPCSTR)=> HMODULE; 22 | LoadLibraryExA:(lpLibFileName:LPCSTR,hFile:HANDLE,dwFlags:DWORD)=> HMODULE; 23 | LoadLibraryExW:(lpLibFileName:LPCWSTR,hFile:HANDLE,dwFlags:DWORD)=> HMODULE; 24 | LoadLibraryW:(lpLibFileName:LPCWSTR)=> HMODULE; 25 | LoadResource:(hModule:HMODULE,hResInfo:HRSRC)=> HGLOBAL; 26 | LockResource:(hResData:HGLOBAL)=> LPVOID; 27 | RemoveDllDirectory:(Cookie:DLL_DIRECTORY_COOKIE)=> BOOL; 28 | SetDefaultDllDirectories:(DirectoryFlags:DWORD)=> BOOL; 29 | SizeofResource:(hModule:HMODULE,hResInfo:HRSRC)=> DWORD; 30 | } -------------------------------------------------------------------------------- /temp/legacy/processthreadsapi.ffi.5n92fwp7u6000.txt: -------------------------------------------------------------------------------- 1 | export const processthreadsapiFns = { 2 | CreateProcessA:[BOOL, [LPCSTR,LPSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,LPVOID,LPCSTR,LPSTARTUPINFOA,LPPROCESS_INFORMATION]], 3 | CreateProcessAsUserA:[BOOL, [HANDLE,LPCSTR,LPSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,LPVOID,LPCSTR,LPSTARTUPINFOA,LPPROCESS_INFORMATION]], 4 | CreateProcessAsUserW:[BOOL, [HANDLE,LPCWSTR,LPWSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,LPVOID,LPCWSTR,LPSTARTUPINFOW,LPPROCESS_INFORMATION]], 5 | CreateProcessW:[BOOL, [LPCWSTR,LPWSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,LPVOID,LPCWSTR,LPSTARTUPINFOW,LPPROCESS_INFORMATION]], 6 | CreateRemoteThread:[HANDLE, [HANDLE,LPSECURITY_ATTRIBUTES,SIZE_T,LPTHREAD_START_ROUTINE,LPVOID,DWORD,LPDWORD]], 7 | CreateRemoteThreadEx:[HANDLE, [HANDLE,LPSECURITY_ATTRIBUTES,SIZE_T,LPTHREAD_START_ROUTINE,LPVOID,DWORD,LPPROC_THREAD_ATTRIBUTE_LIST,LPDWORD]], 8 | CreateThread:[HANDLE, [LPSECURITY_ATTRIBUTES,SIZE_T,LPTHREAD_START_ROUTINE,__DRV_ALIASESMEM,LPVOID,DWORD,LPDWORD]], 9 | DeleteProcThreadAttributeList:[VOID, [LPPROC_THREAD_ATTRIBUTE_LIST]], 10 | ExitProcess:[VOID, [UINT]], 11 | ExitThread:[VOID, [DWORD]], 12 | FlushInstructionCache:[BOOL, [HANDLE,LPCVOID,SIZE_T]], 13 | FlushProcessWriteBuffers:[VOID,[\placeholder]], 14 | GetCurrentProcess:[HANDLE,[\placeholder]], 15 | GetCurrentProcessId:[DWORD,[\placeholder]], 16 | GetCurrentProcessorNumber:[DWORD,[\placeholder]], 17 | GetCurrentProcessorNumberEx:[VOID, [PPROCESSOR_NUMBER]], 18 | GetCurrentProcessToken:[HANDLE,[\placeholder]], 19 | GetCurrentThread:[HANDLE,[\placeholder]], 20 | GetCurrentThreadEffectiveToken:[HANDLE,[\placeholder]], 21 | GetCurrentThreadId:[DWORD,[\placeholder]], 22 | GetCurrentThreadStackLimits:[VOID, [PULONG_PTR,PULONG_PTR]], 23 | GetCurrentThreadToken:[HANDLE,[\placeholder]], 24 | GetExitCodeProcess:[BOOL, [HANDLE,LPDWORD]], 25 | GetExitCodeThread:[BOOL, [HANDLE,LPDWORD]], 26 | GetPriorityClass:[DWORD, [HANDLE]], 27 | GetProcessHandleCount:[BOOL, [HANDLE,PDWORD]], 28 | GetProcessId:[DWORD, [HANDLE]], 29 | GetProcessIdOfThread:[DWORD, [HANDLE]], 30 | GetProcessInformation:[BOOL, [HANDLE,PROCESS_INFORMATION_CLASS,LPVOID,DWORD]], 31 | GetProcessMitigationPolicy:[BOOL, [HANDLE,PROCESS_MITIGATION_POLICY,PVOID,SIZE_T]], 32 | GetProcessPriorityBoost:[BOOL, [HANDLE,PBOOL]], 33 | GetProcessShutdownParameters:[BOOL, [LPDWORD,LPDWORD]], 34 | GetProcessTimes:[BOOL, [HANDLE,LPFILETIME,LPFILETIME,LPFILETIME,LPFILETIME]], 35 | GetProcessVersion:[DWORD, [DWORD]], 36 | GetStartupInfoW:[VOID, [LPSTARTUPINFOW]], 37 | GetSystemTimes:[BOOL, [PFILETIME,PFILETIME,PFILETIME]], 38 | GetThreadContext:[BOOL, [HANDLE,LPCONTEXT]], 39 | GetThreadDescription:[HRESULT, [HANDLE,PWSTR]], 40 | GetThreadId:[DWORD, [HANDLE]], 41 | GetThreadIdealProcessorEx:[BOOL, [HANDLE,PPROCESSOR_NUMBER]], 42 | GetThreadInformation:[BOOL, [HANDLE,THREAD_INFORMATION_CLASS,LPVOID,DWORD]], 43 | GetThreadIOPendingFlag:[BOOL, [HANDLE,PBOOL]], 44 | GetThreadPriority:[INT, [HANDLE]], 45 | GetThreadPriorityBoost:[BOOL, [HANDLE,PBOOL]], 46 | GetThreadTimes:[BOOL, [HANDLE,LPFILETIME,LPFILETIME,LPFILETIME,LPFILETIME]], 47 | InitializeProcThreadAttributeList:[BOOL, [LPPROC_THREAD_ATTRIBUTE_LIST,DWORD,DWORD,PSIZE_T]], 48 | IsProcessCritical:[BOOL, [HANDLE,PBOOL]], 49 | IsProcessorFeaturePresent:[BOOL, [DWORD]], 50 | OpenProcess:[HANDLE, [DWORD,BOOL,DWORD]], 51 | OpenProcessToken:[BOOL, [HANDLE,DWORD,PHANDLE]], 52 | OpenThread:[HANDLE, [DWORD,BOOL,DWORD]], 53 | OpenThreadToken:[BOOL, [HANDLE,DWORD,BOOL,PHANDLE]], 54 | ProcessIdToSessionId:[BOOL, [DWORD,DWORD]], 55 | QueryProcessAffinityUpdateMode:[BOOL, [HANDLE,LPDWORD]], 56 | QueryProtectedPolicy:[BOOL, [LPCGUID,PULONG_PTR]], 57 | QueueUserAPC:[DWORD, [PAPCFUNC,HANDLE,ULONG_PTR]], 58 | ResumeThread:[DWORD, [HANDLE]], 59 | SetPriorityClass:[BOOL, [HANDLE,DWORD]], 60 | SetProcessAffinityUpdateMode:[BOOL, [HANDLE,DWORD]], 61 | SetProcessDynamicEHContinuationTargets:[BOOL, [HANDLE,USHORT,PPROCESS_DYNAMIC_EH_CONTINUATION_TARGET]], 62 | SetProcessInformation:[BOOL, [HANDLE,PROCESS_INFORMATION_CLASS,LPVOID,DWORD]], 63 | SetProcessMitigationPolicy:[BOOL, [PROCESS_MITIGATION_POLICY,PVOID,SIZE_T]], 64 | SetProcessPriorityBoost:[BOOL, [HANDLE,BOOL]], 65 | SetProcessShutdownParameters:[BOOL, [DWORD,DWORD]], 66 | SetProtectedPolicy:[BOOL, [LPCGUID,ULONG_PTR,PULONG_PTR]], 67 | SetThreadContext:[BOOL, [HANDLE,CONST,CONTEXT]], 68 | SetThreadDescription:[HRESULT, [HANDLE,PCWSTR]], 69 | SetThreadIdealProcessor:[DWORD, [HANDLE,DWORD]], 70 | SetThreadIdealProcessorEx:[BOOL, [HANDLE,PPROCESSOR_NUMBER,PPROCESSOR_NUMBER]], 71 | SetThreadInformation:[BOOL, [HANDLE,THREAD_INFORMATION_CLASS,LPVOID,DWORD]], 72 | SetThreadPriority:[BOOL, [HANDLE,INT]], 73 | SetThreadPriorityBoost:[BOOL, [HANDLE,BOOL]], 74 | SetThreadStackGuarantee:[BOOL, [PULONG]], 75 | SetThreadToken:[BOOL, [PHANDLE,HANDLE]], 76 | SuspendThread:[DWORD, [HANDLE]], 77 | SwitchToThread:[BOOL,[\placeholder]], 78 | TerminateProcess:[BOOL, [HANDLE,UINT]], 79 | TerminateThread:[BOOL, [HANDLE,DWORD]], 80 | TlsAlloc:[DWORD,[\placeholder]], 81 | TlsFree:[BOOL, [DWORD]], 82 | TlsGetValue:[LPVOID, [DWORD]], 83 | TlsSetValue:[BOOL, [DWORD,LPVOID]], 84 | UpdateProcThreadAttribute:[BOOL, [LPPROC_THREAD_ATTRIBUTE_LIST,DWORD,DWORD_PTR,PVOID,SIZE_T,PVOID,PSIZE_T]], 85 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES5", 4 | "lib": [ 5 | "esnext" 6 | ], 7 | "declaration": true, 8 | "declarationDir": "./dist/", 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "importsNotUsedAsValues": "preserve", 16 | "module": "commonjs", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": false, 20 | "sourceMap": false, 21 | "baseUrl": ".", 22 | "outDir": "./dist", 23 | "paths": { 24 | "@/*": [ 25 | "lib/*" 26 | ] 27 | } 28 | }, 29 | "exclude": [ 30 | "node_modules", 31 | "temp", 32 | ], 33 | "include": [ 34 | "lib/**/*" 35 | ] 36 | } -------------------------------------------------------------------------------- /typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "out": "docs", 3 | "mode": "modules", 4 | "exclude": [ 5 | "lib/utils", 6 | "lib/**/index.ts", 7 | "lib/win_fns.ts" 8 | ] 9 | } --------------------------------------------------------------------------------