@finogeeks2026/finshield-opencode 0.0.0-stage → 0.11.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DESIGN.md +593 -0
- package/LICENSE.rtf +28 -0
- package/README.md +132 -2
- package/THIRD-PARTY-NOTICES.md +3131 -0
- package/bin/node.exe +4 -0
- package/dist/gui-experimental.cjs +96 -0
- package/dist/updater/server.js +1046 -0
- package/install/download-source.json +3 -0
- package/install/runtime.js +60 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/LICENSE.rtf +28 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/README.md +116 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/bin/finsafe_native.dll +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/native-build.json +5 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/README.md +6 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/index.js +12 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/package.json +24 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/win32_x64/koffi.lib +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/win32_x64/koffi.node +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/CHANGELOG.md +1183 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/LICENSE.txt +22 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/README.md +42 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/cnoke.cjs +816 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/benchmarks.md +80 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/callbacks.md +182 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/composites.md +549 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/contribute.md +163 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/index.md +46 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/load.md +191 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/migration.md +256 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/misc.md +76 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/output.md +299 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/pointers.md +385 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/primitives.md +151 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/start.md +110 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/types.md +88 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/unions.md +0 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/values.md +134 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.cjs +1 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.d.ts +389 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.js +2 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/indirect.cjs +1 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/indirect.js +2 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/base.cc +11064 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/base.hh +5951 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/unicode.inc +408 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/package.json +68 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/CMakeLists.txt +249 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/index.cjs +296 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/index.js +281 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/indirect.cjs +295 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/indirect.js +280 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64.cc +1408 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64_asm.S +216 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64_asm.asm +181 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/loong64.cc +5 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/loong64_asm.S +200 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/riscv64.cc +1345 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/riscv64_asm.S +200 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64sysv.cc +1434 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64sysv_asm.S +224 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win.cc +1086 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win_asm.S +162 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win_asm.asm +189 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86.cc +1185 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86_asm.S +217 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86_asm.asm +174 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/call.cc +2094 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/call.hh +179 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/errno.inc +462 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/ffi.cc +3009 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/ffi.hh +461 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/parser.cc +218 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/parser.hh +54 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/primitives.inc +36 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/static.cjs +130 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/static.js +133 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/trampolines.cjs +77 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/type.cc +725 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/type.hh +71 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/util.cc +1040 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/util.hh +493 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.cc +214 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.def +11 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.hh +112 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/win32.cc +198 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/win32.hh +148 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/LICENSE.md +9 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/README.md +95 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi-inl.deprecated.h +186 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi-inl.h +7211 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi.h +3421 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/LICENSE +21 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/README.md +95 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/def/js_native_api.def +125 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/def/node_api.def +157 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/js_native_api.h +591 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/js_native_api_types.h +210 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/node_api.h +265 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/node_api_types.h +58 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/package.json +36 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/release.json +4 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/src/native.js +85 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/src/shell.js +20 -0
- package/node_modules/@finogeeks2026/finsafe-sdk/src/status.js +57 -0
- package/package.json +47 -4
- package/policy/candidate.yaml +347 -0
- package/release.json +4 -0
- package/src/activation.js +2 -0
- package/src/attachment.js +34 -0
- package/src/connector.js +91 -0
- package/src/contract.js +8 -0
- package/src/desktop-contract.js +4 -0
- package/src/desktop.js +25 -0
- package/src/gui.tsx +58 -0
- package/src/host.js +38 -0
- package/src/index.js +12 -0
- package/src/instance-settings.js +27 -0
- package/src/known-folders.js +22 -0
- package/src/management.js +17 -0
- package/src/preparation.js +18 -0
- package/src/presentation.js +153 -0
- package/src/settings.js +18 -0
- package/ui/feedback.cjs +45 -0
- package/ui/page.cjs +225 -0
- package/ui/state.cjs +44 -0
- package/updater/bootstrap.js +41 -0
- package/updater/common/activation.js +81 -0
- package/updater/common/coordinator.js +329 -0
- package/updater/common/download.js +57 -0
- package/updater/common/index.js +12 -0
- package/updater/common/package.js +53 -0
- package/updater/common/protocol.js +38 -0
- package/updater/common/transport.js +65 -0
- package/updater/coordinator.js +2 -0
- package/updater/launch.js +40 -0
- package/updater/management.js +9 -0
- package/updater/native.js +18 -0
- package/updater/operations.js +45 -0
- package/updater/protocol.js +1 -0
- package/updater/server.js +100 -0
- package/updater/transport.js +10 -0
- package/updater/windows-launch-reader.js +40 -0
- package/updater/windows-launch.js +96 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Number types
|
|
2
|
+
|
|
3
|
+
While the C standard allows for variation in the size of most integer types, Koffi enforces the same definition for most primitive types, listed below:
|
|
4
|
+
|
|
5
|
+
C type | JS type | Bytes | Signedness | Note
|
|
6
|
+
----------------------------- | ---------------- | ----- | ---------- | ---------------------------
|
|
7
|
+
void | Undefined | 0 | | Only valid as a return type
|
|
8
|
+
int8, int8_t | Number (integer) | 1 | Signed |
|
|
9
|
+
uint8, uint8_t | Number (integer) | 1 | Unsigned |
|
|
10
|
+
char | Number (integer) | 1 | Signed |
|
|
11
|
+
uchar, unsigned char | Number (integer) | 1 | Unsigned |
|
|
12
|
+
char16, char16_t | Number (integer) | 2 | Signed |
|
|
13
|
+
int16, int16_t | Number (integer) | 2 | Signed |
|
|
14
|
+
uint16, uint16_t | Number (integer) | 2 | Unsigned |
|
|
15
|
+
short | Number (integer) | 2 | Signed |
|
|
16
|
+
ushort, unsigned short | Number (integer) | 2 | Unsigned |
|
|
17
|
+
char32, char32_t | Number (integer) | 4 | Signed |
|
|
18
|
+
int32, int32_t | Number (integer) | 4 | Signed |
|
|
19
|
+
uint32, uint32_t | Number (integer) | 4 | Unsigned |
|
|
20
|
+
int | Number (integer) | 4 | Signed |
|
|
21
|
+
uint, unsigned int | Number (integer) | 4 | Unsigned |
|
|
22
|
+
int64, int64_t | Number (integer) | 8 | Signed |
|
|
23
|
+
uint64, uint64_t | Number (integer) | 8 | Unsigned |
|
|
24
|
+
longlong, long long | Number (integer) | 8 | Signed |
|
|
25
|
+
ulonglong, unsigned long long | Number (integer) | 8 | Unsigned |
|
|
26
|
+
float32 | Number (float) | 4 | |
|
|
27
|
+
float64 | Number (float) | 8 | |
|
|
28
|
+
float | Number (float) | 4 | |
|
|
29
|
+
double | Number (float) | 8 | |
|
|
30
|
+
|
|
31
|
+
Koffi also accepts BigInt values when converting from JS to C integers. If the value exceeds the range of the C type, Koffi will convert the number to an undefined value. In the reverse direction, BigInt values are automatically used when needed for big 64-bit integers.
|
|
32
|
+
|
|
33
|
+
Koffi defines a few more types that can change size depending on the OS and the architecture:
|
|
34
|
+
|
|
35
|
+
C type | JS type | Signedness | Note
|
|
36
|
+
---------------- | ---------------- | ----------- | ------------------------------------------------
|
|
37
|
+
bool | Boolean | | Usually one byte
|
|
38
|
+
long | Number (integer) | Signed | 4 or 8 bytes depending on platform (LP64, LLP64)
|
|
39
|
+
ulong | Number (integer) | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
|
|
40
|
+
unsigned long | Number (integer) | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
|
|
41
|
+
intptr | Number (integer) | Signed | 4 or 8 bytes depending on register width
|
|
42
|
+
intptr_t | Number (integer) | Signed | 4 or 8 bytes depending on register width
|
|
43
|
+
uintptr | Number (integer) | Unsigned | 4 or 8 bytes depending on register width
|
|
44
|
+
uintptr_t | Number (integer) | Unsigned | 4 or 8 bytes depending on register width
|
|
45
|
+
wchar_t | Number (integer) | | 2 bytes on Windows, 4 bytes Linux, macOS and BSD
|
|
46
|
+
|
|
47
|
+
Primitive types can be specified by name (in a string) or through `koffi.types`:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
// These two lines do the same:
|
|
51
|
+
let struct1 = koffi.struct({ dummy: 'long' });
|
|
52
|
+
let struct2 = koffi.struct({ dummy: koffi.types.long });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
# String types
|
|
56
|
+
|
|
57
|
+
Koffi can convert JS strings to and from UTF-8, UTF-16 or UTF-32.
|
|
58
|
+
|
|
59
|
+
Type name | Aliases | JS type | Conversion / encoding
|
|
60
|
+
------------------------------ | --------------- | ------- | ---------------------
|
|
61
|
+
const char \*, char \* | str, string | String | UTF-8
|
|
62
|
+
const char16_t \*, char16_t \* | str16, string16 | String | UTF-16
|
|
63
|
+
const char32_t \*, char32_t \* | str32, string32 | String | UTF-32
|
|
64
|
+
|
|
65
|
+
Koffi also supports wide strings (`wchar_t *` or `wstring`), which use:
|
|
66
|
+
|
|
67
|
+
- UTF-16 on Windows (where wchar_t is 2 bytes)
|
|
68
|
+
- UTF-32 on other platforms (where wchar_t is 4 bytes)
|
|
69
|
+
|
|
70
|
+
# Enum types
|
|
71
|
+
|
|
72
|
+
*New in Koffi 3.0*
|
|
73
|
+
|
|
74
|
+
C enumeration values are stored as integers. The underlying integer type is implementation-defined but Koffi tries to match usual platform behavior.
|
|
75
|
+
|
|
76
|
+
On POSIX platforms, Koffi follows the following rules:
|
|
77
|
+
|
|
78
|
+
- If no negative value exists: `unsigned int` by default, `uint64_t` if needed
|
|
79
|
+
- If any negative value exists: `int` by default, `int64_t` if needed
|
|
80
|
+
|
|
81
|
+
On Windows, things are simpler, and `int` is used all the time. Koffi will throw an error if any enumeration value does not fit in a 32-bit integer.
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
// For OpenResult, the underlying type will be unsigned int on POSIX, int on Windows
|
|
85
|
+
const OpenResult = koffi.enumeration('OpenResult', {
|
|
86
|
+
Success: 0,
|
|
87
|
+
MissingFile: 1,
|
|
88
|
+
AccessDenied: 2,
|
|
89
|
+
OtherError: 3
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// For RelativePosition, the underlying type will be int everywhere
|
|
93
|
+
const RelativePosition = koffi.enumeration('RelativePosition', {
|
|
94
|
+
Left: -1,
|
|
95
|
+
Center: 0,
|
|
96
|
+
Right: 1
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// For IntLimits, the underlying type will be int64_t on POSIX, and fail on Windows
|
|
100
|
+
const Int64Limits = koffi.enumeration('Int64Limits', {
|
|
101
|
+
Min: -9223372036854775808n,
|
|
102
|
+
Max: 9223372036854775807n
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
> [!WARNING]
|
|
107
|
+
> This behavior may not match your compiler:
|
|
108
|
+
>
|
|
109
|
+
> - On POSIX platforms, GCC and Clang will use a short integer type if `-fshort-enums` is specified and the enumeration values fit in `short` or `unsigned short`.
|
|
110
|
+
> - On Windows, MSVC (and Clang) always use `int` even if some values do not fit, which matches what Koffi does... unless the compiler flag `/Zc:enumTypes` is set, maybe.
|
|
111
|
+
>
|
|
112
|
+
> Use an explicit type specifier to work around these problems, as shown below.
|
|
113
|
+
|
|
114
|
+
You can access the constants in `values` member of the type object.
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
console.log(OpenResult.values.MissingFile); // Prints 1
|
|
118
|
+
console.log(RelativePosition.values.Left); // Prints -1
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
You can specify the storage type explicitly as the last argument: `koffi.enumeration(name, values, type)`.
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
// This one explictly uses int64_t as the underlying type, despite the fact that the values fit inside an int.
|
|
125
|
+
const ExplicitEnum = koffi.enumeration('ExplicitEnum', {
|
|
126
|
+
Zero: 0,
|
|
127
|
+
One: 1,
|
|
128
|
+
Two: 2
|
|
129
|
+
}, 'int64_t');
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
# Endian-sensitive integers
|
|
133
|
+
|
|
134
|
+
Koffi defines a bunch of endian-sensitive types, which can be used when dealing with binary data (network payloads, binary file formats, etc.).
|
|
135
|
+
|
|
136
|
+
C type | Bytes | Signedness | Endianness
|
|
137
|
+
---------------------- | ----- | ---------- | -------------
|
|
138
|
+
int16_le, int16_le_t | 2 | Signed | Little Endian
|
|
139
|
+
int16_be, int16_be_t | 2 | Signed | Big Endian
|
|
140
|
+
uint16_le, uint16_le_t | 2 | Unsigned | Little Endian
|
|
141
|
+
uint16_be, uint16_be_t | 2 | Unsigned | Big Endian
|
|
142
|
+
int32_le, int32_le_t | 4 | Signed | Little Endian
|
|
143
|
+
int32_be, int32_be_t | 4 | Signed | Big Endian
|
|
144
|
+
uint32_le, uint32_le_t | 4 | Unsigned | Little Endian
|
|
145
|
+
uint32_be, uint32_be_t | 4 | Unsigned | Big Endian
|
|
146
|
+
int64_le, int64_le_t | 8 | Signed | Little Endian
|
|
147
|
+
int64_be, int64_be_t | 8 | Signed | Big Endian
|
|
148
|
+
uint64_le, uint64_le_t | 8 | Unsigned | Little Endian
|
|
149
|
+
uint64_be, uint64_be_t | 8 | Unsigned | Big Endian
|
|
150
|
+
|
|
151
|
+
You can find an example that uses these types to [extract information from a PNG header](pointers#handling-void-pointers) with transparent endian conversion.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Install Koffi
|
|
2
|
+
|
|
3
|
+
You can install Koffi with npm:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install koffi
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Once you have installed Koffi, you can start by loading it:
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
// ES6 modules
|
|
13
|
+
import koffi from 'koffi';
|
|
14
|
+
|
|
15
|
+
// CommonJS syntax
|
|
16
|
+
const koffi = require('koffi');
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
> [!NOTE]
|
|
20
|
+
> Follow the [build instructions](contribute#build-from-source) if you want to build the native Koffi code yourself, to fix something or simply to study the code.
|
|
21
|
+
|
|
22
|
+
# Simple examples
|
|
23
|
+
|
|
24
|
+
Below you can find two examples:
|
|
25
|
+
|
|
26
|
+
* The first one runs on Linux. The functions are declared with the C-like prototype language.
|
|
27
|
+
* The second one runs on Windows, and uses the node-ffi like syntax to declare functions.
|
|
28
|
+
|
|
29
|
+
## For Linux
|
|
30
|
+
|
|
31
|
+
This is a small example for Linux systems, which uses `gettimeofday()`, `localtime_r()` and `printf()` to print the current time.
|
|
32
|
+
|
|
33
|
+
It illustrates the use of output parameters.
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import koffi from 'koffi';
|
|
37
|
+
// CJS: const koffi = require('koffi');
|
|
38
|
+
|
|
39
|
+
// Load the shared library
|
|
40
|
+
const lib = koffi.load('libc.so.6');
|
|
41
|
+
|
|
42
|
+
// Declare struct types
|
|
43
|
+
const timeval = koffi.struct('timeval', {
|
|
44
|
+
tv_sec: 'unsigned int',
|
|
45
|
+
tv_usec: 'unsigned int'
|
|
46
|
+
});
|
|
47
|
+
const timezone = koffi.struct('timezone', {
|
|
48
|
+
tz_minuteswest: 'int',
|
|
49
|
+
tz_dsttime: 'int'
|
|
50
|
+
});
|
|
51
|
+
const time_t = koffi.struct('time_t', { value: 'int64_t' });
|
|
52
|
+
const tm = koffi.struct('tm', {
|
|
53
|
+
tm_sec: 'int',
|
|
54
|
+
tm_min: 'int',
|
|
55
|
+
tm_hour: 'int',
|
|
56
|
+
tmay: 'int',
|
|
57
|
+
tm_mon: 'int',
|
|
58
|
+
tm_year: 'int',
|
|
59
|
+
tm_wday: 'int',
|
|
60
|
+
tm_yday: 'int',
|
|
61
|
+
tm_isdst: 'int'
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Find functions
|
|
65
|
+
const gettimeofday = lib.func('int gettimeofday(_Out_ timeval *tv, _Out_ timezone *tz)');
|
|
66
|
+
const localtime_r = lib.func('tm *localtime_r(const time_t *timeval, _Out_ tm *result)');
|
|
67
|
+
const printf = lib.func('int printf(const char *format, ...)');
|
|
68
|
+
|
|
69
|
+
// Get local time
|
|
70
|
+
let tv = {};
|
|
71
|
+
let now = {};
|
|
72
|
+
gettimeofday(tv, null);
|
|
73
|
+
localtime_r({ value: tv.tv_sec }, now);
|
|
74
|
+
|
|
75
|
+
// And format it with printf (variadic function)
|
|
76
|
+
printf('Hello World!\n');
|
|
77
|
+
printf('Local time: %02d:%02d:%02d\n', 'int', now.tm_hour, 'int', now.tm_min, 'int', now.tm_sec);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## For Windows
|
|
81
|
+
|
|
82
|
+
This is a small example targeting the Win32 API, using `MessageBox()` to show a *Hello World!* message to the user.
|
|
83
|
+
|
|
84
|
+
It illustrates the use of the x86 stdcall calling convention, and the use of UTF-8 and UTF-16 string arguments.
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
import koffi from 'koffi';
|
|
88
|
+
// CJS: const koffi = require('koffi');
|
|
89
|
+
|
|
90
|
+
// Load the shared library
|
|
91
|
+
const lib = koffi.load('user32.dll');
|
|
92
|
+
|
|
93
|
+
// Declare constants
|
|
94
|
+
const MB_OK = 0x0;
|
|
95
|
+
const MB_YESNO = 0x4;
|
|
96
|
+
const MB_ICONQUESTION = 0x20;
|
|
97
|
+
const MB_ICONINFORMATION = 0x40;
|
|
98
|
+
const IDOK = 1;
|
|
99
|
+
const IDYES = 6;
|
|
100
|
+
const IDNO = 7;
|
|
101
|
+
|
|
102
|
+
// Find functions
|
|
103
|
+
const MessageBoxA = lib.func('__stdcall', 'MessageBoxA', 'int', ['void *', 'str', 'str', 'uint']);
|
|
104
|
+
const MessageBoxW = lib.func('__stdcall', 'MessageBoxW', 'int', ['void *', 'str16', 'str16', 'uint']);
|
|
105
|
+
|
|
106
|
+
let ret = MessageBoxA(null, 'Do you want another message box?', 'Koffi', MB_YESNO | MB_ICONQUESTION);
|
|
107
|
+
|
|
108
|
+
if (ret == IDYES)
|
|
109
|
+
MessageBoxW(null, 'Hello World!', 'Koffi', MB_ICONINFORMATION);
|
|
110
|
+
```
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Type specifiers
|
|
2
|
+
|
|
3
|
+
*Changed in Koffi 3.0*
|
|
4
|
+
|
|
5
|
+
> [!NOTE]
|
|
6
|
+
> In Koffi 2.0, types were External values, you had to use `koffi.introspect()` to get type information. In Koffi 3.0, this information is directly available in type objects, and this function is deprecated.
|
|
7
|
+
>
|
|
8
|
+
> Consult the [migration guide](migration) for more information.
|
|
9
|
+
|
|
10
|
+
You can use strings or type objects to give type information to Koffi (when declaring functions, structs, and so on). Use `koffi.type(spec)` to resolve all accepted type values (strings and type objects) to type objects.
|
|
11
|
+
|
|
12
|
+
You can inspect the type object for information: name, primitive, size, alignment, members (record types), reference type (array, pointer), length (array), arguments and return type (prototypes).
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
const FoobarType = koffi.struct('FoobarType', {
|
|
16
|
+
a: 'int',
|
|
17
|
+
b: 'char *',
|
|
18
|
+
c: 'double'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
console.log(FoobarType);
|
|
22
|
+
|
|
23
|
+
// Expected result on 64-bit machines:
|
|
24
|
+
// {
|
|
25
|
+
// name: 'FoobarType',
|
|
26
|
+
// primitive: 'Record',
|
|
27
|
+
// size: 24,
|
|
28
|
+
// alignment: 8,
|
|
29
|
+
// disposable: false,
|
|
30
|
+
// members: {
|
|
31
|
+
// a: { name: 'a', type: [Type], offset: 0 },
|
|
32
|
+
// b: { name: 'b', type: [Type], offset: 8 },
|
|
33
|
+
// c: { name: 'c', type: [Type], offset: 16 }
|
|
34
|
+
// }
|
|
35
|
+
// }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Koffi also exposes a few more utility functions to get a subset of this information:
|
|
39
|
+
|
|
40
|
+
- `koffi.sizeof(type)` to get the size of a type
|
|
41
|
+
- `koffi.alignof(type)` to get the alignment of a type
|
|
42
|
+
- `koffi.offsetof(type, member_name)` to get the offset of a record member
|
|
43
|
+
- `koffi.type(type)` to get the resolved type object from a type string
|
|
44
|
+
|
|
45
|
+
Just like before, you can refer to primitive types by their name or through `koffi.types`:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
// These two lines do the same:
|
|
49
|
+
console.log(koffi.sizeof('long'));
|
|
50
|
+
console.log(koffi.sizeof(koffi.types.long));
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
# Aliases
|
|
54
|
+
|
|
55
|
+
You can alias a type with `koffi.alias(name, type)`. Aliased types are completely equivalent.
|
|
56
|
+
|
|
57
|
+
# Circular references
|
|
58
|
+
|
|
59
|
+
In some cases, composite types can point to each other and thus depend on each other. This can also happen when a function takes a pointer to a struct that also contains a function pointer.
|
|
60
|
+
|
|
61
|
+
To deal with this, you can create an opaque type and redefine it later to a concrete struct or union type, as shown below.
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
const Type1 = koffi.opaque('Type1');
|
|
65
|
+
|
|
66
|
+
const Type2 = koffi.struct('Type2', {
|
|
67
|
+
ptr: 'Type1 *',
|
|
68
|
+
i: 'int'
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Redefine Type1 to a concrete type
|
|
72
|
+
koffi.struct(Type1, {
|
|
73
|
+
ptr: 'Type2 *',
|
|
74
|
+
f: 'float'
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
> [!NOTE]
|
|
79
|
+
> You must use a proper type object when you redefine the type. If you only have the name, use `koffi.type()` to get a type object from a type string.
|
|
80
|
+
>
|
|
81
|
+
> ```js
|
|
82
|
+
> const MyType = koffi.opaque('MyType');
|
|
83
|
+
>
|
|
84
|
+
> // This does not work, you must use the MyType object and not a type string
|
|
85
|
+
> koffi.struct('MyType', {
|
|
86
|
+
> ptr: 'Type2 *',
|
|
87
|
+
> f: 'float'
|
|
88
|
+
> });
|
|
File without changes
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Decode to JS values
|
|
2
|
+
|
|
3
|
+
## Decode numbers
|
|
4
|
+
|
|
5
|
+
*New in Koffi 3.1.0*
|
|
6
|
+
|
|
7
|
+
Use these functions to decode numeric values from a pointer. These functions match the [number types](primitives#number-types) of Koffi:
|
|
8
|
+
|
|
9
|
+
Type | Function | Result
|
|
10
|
+
--------- | ---------------------------- | ------------------------------------
|
|
11
|
+
char | `koffi.decode.char(ptr)` | Number
|
|
12
|
+
uchar | `koffi.decode.uchar(ptr)` | Number
|
|
13
|
+
short | `koffi.decode.short(ptr)` | Number
|
|
14
|
+
ushort | `koffi.decode.ushort(ptr)` | Number
|
|
15
|
+
int | `koffi.decode.int(ptr)` | Number
|
|
16
|
+
uint | `koffi.decode.uint(ptr)` | Number
|
|
17
|
+
long | `koffi.decode.long(ptr)` | Number or BigInt (on LP64 platforms)
|
|
18
|
+
ulong | `koffi.decode.ulong(ptr)` | Number or BigInt (on LP64 platforms)
|
|
19
|
+
longlong | `koffi.decode.longlong(ptr)` | Number or BigInt
|
|
20
|
+
ulonglong | `koffi.decode.ulonglong(ptr)`| Number or BigInt
|
|
21
|
+
int8 | `koffi.decode.int8(ptr)` | Number
|
|
22
|
+
uint8 | `koffi.decode.uint8(ptr)` | Number
|
|
23
|
+
int16 | `koffi.decode.int16(ptr)` | Number
|
|
24
|
+
uint16 | `koffi.decode.uint16(ptr)` | Number
|
|
25
|
+
int32 | `koffi.decode.int32(ptr)` | Number
|
|
26
|
+
uint32 | `koffi.decode.uint32(ptr)` | Number
|
|
27
|
+
int64 | `koffi.decode.int64(ptr)` | Number or BigInt
|
|
28
|
+
uint64 | `koffi.decode.uint64(ptr)` | Number or BigInt
|
|
29
|
+
float | `koffi.decode.float(ptr)` | Number
|
|
30
|
+
double | `koffi.decode.double(ptr)` | Number
|
|
31
|
+
|
|
32
|
+
You can also decode [endian-sensitive integers](primitives#endian-sensitive-integers) with these functions:
|
|
33
|
+
|
|
34
|
+
Type | Function | Endianness | Result
|
|
35
|
+
--------- | ---------------------------- | ------------- | ----------------
|
|
36
|
+
int16_le | `koffi.decode.int16le(ptr)` | Little Endian | Number
|
|
37
|
+
uint16_le | `koffi.decode.uint16le(ptr)` | Little Endian | Number
|
|
38
|
+
int32_le | `koffi.decode.int32le(ptr)` | Little Endian | Number
|
|
39
|
+
uint32_le | `koffi.decode.uint32le(ptr)` | Little Endian | Number
|
|
40
|
+
int64_le | `koffi.decode.int64le(ptr)` | Little Endian | Number or BigInt
|
|
41
|
+
uint64_le | `koffi.decode.uint64le(ptr)` | Little Endian | Number or BigInt
|
|
42
|
+
int16_be | `koffi.decode.int16be(ptr)` | Big Endian | Number
|
|
43
|
+
uint16_be | `koffi.decode.uint16be(ptr)` | Big Endian | Number
|
|
44
|
+
int32_be | `koffi.decode.int32be(ptr)` | Big Endian | Number
|
|
45
|
+
uint32_be | `koffi.decode.uint32be(ptr)` | Big Endian | Number
|
|
46
|
+
int64_be | `koffi.decode.int64be(ptr)` | Big Endian | Number or BigInt
|
|
47
|
+
uint64_be | `koffi.decode.uint64be(ptr)` | Big Endian | Number or BigInt
|
|
48
|
+
|
|
49
|
+
## Decode strings
|
|
50
|
+
|
|
51
|
+
You can also decode strings, NUL-terminated or with an explicit length:
|
|
52
|
+
|
|
53
|
+
Type | Function | Conversion/encoding
|
|
54
|
+
-------- | ------------------------------------ | -------------------------------------
|
|
55
|
+
string | `koffi.decode.string(ptr)` | UTF-8 (NUL-terminated)
|
|
56
|
+
string | `koffi.decode.string(ptr, length)` | UTF-8 (explicit length)
|
|
57
|
+
string16 | `koffi.decode.string16(ptr)` | UTF-16 (NUL-terminated)
|
|
58
|
+
string16 | `koffi.decode.string16(ptr, length)` | UTF-16 (explicit length)
|
|
59
|
+
string32 | `koffi.decode.string32(ptr)` | UTF-32 (NUL-terminated)
|
|
60
|
+
string32 | `koffi.decode.string32(ptr, length)` | UTF-32 (explicit length)
|
|
61
|
+
wstring | `koffi.decode.wstring(ptr)` | UTF-16 or UTF-32 (platform-dependent)
|
|
62
|
+
wstring | `koffi.decode.wstring(ptr, length)` | UTF-16 or UTF-32 (platform-dependent)
|
|
63
|
+
|
|
64
|
+
## Generic decode function
|
|
65
|
+
|
|
66
|
+
Use `koffi.decode()` to decode the data pointed to by a pointer (represented by a BigInt value).
|
|
67
|
+
|
|
68
|
+
Some arguments are optional and this function can be called in several ways:
|
|
69
|
+
|
|
70
|
+
- `koffi.decode(ptr, type)`: no offset
|
|
71
|
+
- `koffi.decode(ptr, offset, type)`: explicit offset to add to the pointer before decoding
|
|
72
|
+
|
|
73
|
+
By default, Koffi expects NUL terminated strings when decoding them. See below if you need to specify the string length.
|
|
74
|
+
|
|
75
|
+
The following example illustrates how to decode an integer and a C string variable.
|
|
76
|
+
|
|
77
|
+
```c
|
|
78
|
+
int my_int = 42;
|
|
79
|
+
const char *my_string = "foobar";
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
const my_int = lib.symbol('my_int');
|
|
84
|
+
const my_string = lib.symbol('my_string');
|
|
85
|
+
|
|
86
|
+
console.log(koffi.decode(my_int, 'int')) // Prints 42
|
|
87
|
+
console.log(koffi.decode(my_string, 'const char *')) // Prints "foobar"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
There is also an optional ending `length` argument that you can use in two cases:
|
|
91
|
+
|
|
92
|
+
- Use it to give the number of bytes to decode in non-NUL terminated strings: `koffi.decode(ptr, 'char *', 5)`
|
|
93
|
+
- Decode consecutive values into an array. For example, here is how you can decode an array with 3 float values: `koffi.decode(ptr, 'float', 3)`. This is equivalent to `koffi.decode(ptr, koffi.array('float', 3))`.
|
|
94
|
+
|
|
95
|
+
The example below will decode the symbol `my_string` defined above but only the first three bytes.
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
// Only decode 3 bytes from the C string my_string
|
|
99
|
+
console.log(koffi.decode(my_string, 'const char *', 3)) // Prints "foo"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
# Encode to C memory
|
|
103
|
+
|
|
104
|
+
Use `koffi.encode()` to encode JS values into C symbols or pointers, which are represented by BigInt numbers.
|
|
105
|
+
|
|
106
|
+
Some arguments are optional and this function can be called in several ways:
|
|
107
|
+
|
|
108
|
+
- `koffi.encode(ptr, type, value)`: no offset
|
|
109
|
+
- `koffi.encode(ptr, offset, type, value)`: explicit offset to add to the pointer before encoding
|
|
110
|
+
|
|
111
|
+
We'll reuse the examples shown above and change the variable values with `koffi.encode()`.
|
|
112
|
+
|
|
113
|
+
```c
|
|
114
|
+
int my_int = 42;
|
|
115
|
+
const char *my_string = NULL;
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
const my_int = lib.symbol('my_int');
|
|
120
|
+
const my_string = lib.symbol('my_string');
|
|
121
|
+
|
|
122
|
+
console.log(koffi.decode(my_int, 'int')) // Prints 42
|
|
123
|
+
console.log(koffi.decode(my_string, 'const char *')) // Prints null
|
|
124
|
+
|
|
125
|
+
koffi.encode(my_int, 'int', -1);
|
|
126
|
+
koffi.encode(my_string, 'const char *', 'Hello World!');
|
|
127
|
+
|
|
128
|
+
console.log(koffi.decode(my_int, 'int')) // Prints -1
|
|
129
|
+
console.log(koffi.decode(my_string, 'const char *')) // Prints "Hello World!"
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
When encoding strings (either directly or embedded in arrays or structs), the memory will be bound to the raw pointer value and managed by Koffi. You can assign to the same string again and again without any leak or risk of use-after-free.
|
|
133
|
+
|
|
134
|
+
There is also an optional ending `length` argument that you can use to encode an array. For example, here is how you can encode an array with 3 float values: `koffi.encode(symbol, 'float', [1, 2, 3], 3)`. This is equivalent to `koffi.encode(symbol, koffi.array('float', 3), [1, 2, 3])`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("./src/koffi/index.cjs");
|