fix: dll path do not work on Linux/UNIX systems
This commit is contained in:
5 files changed
+34
-6
No files matched your search
@@ -8,6 +8,7 @@ CMakePresets.json
|
||||
*.obj
|
||||
*.exe
|
||||
*.so
|
||||
!native/snowluma-linux-x64.so
|
||||
*.dylib
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -37,11 +37,21 @@ function loadNativeAddon(addonPath: string): NativeHookAddon {
|
||||
return mod.exports as unknown as NativeHookAddon;
|
||||
}
|
||||
|
||||
function platformBinaryName(ext: 'node' | 'dll'): string {
|
||||
type HookBinaryExt = 'node' | 'dll' | 'so';
|
||||
|
||||
function platformBinaryName(ext: HookBinaryExt): string {
|
||||
if (process.platform === 'win32' && process.arch === 'x64') return `snowluma-win32-x64.${ext}`;
|
||||
return `snowluma-${process.platform}-${process.arch}.${ext}`;
|
||||
}
|
||||
|
||||
function platformInjectableExt(): 'dll' | 'so' {
|
||||
return process.platform === 'win32' ? 'dll' : 'so';
|
||||
}
|
||||
|
||||
function defaultProcessName(): string {
|
||||
return process.platform === 'win32' ? 'QQ.exe' : 'qq';
|
||||
}
|
||||
|
||||
function nativeSearchDirs(): string[] {
|
||||
// Several layouts must be supported:
|
||||
// 1. Released zip (flattened dist/): __dirname=<extracted>/, native at <extracted>/native
|
||||
@@ -56,7 +66,7 @@ function nativeSearchDirs(): string[] {
|
||||
];
|
||||
}
|
||||
|
||||
export function resolveHookNativePath(ext: 'node' | 'dll'): string | null {
|
||||
export function resolveHookNativePath(ext: HookBinaryExt): string | null {
|
||||
const fileName = platformBinaryName(ext);
|
||||
for (const dir of nativeSearchDirs()) {
|
||||
const fullPath = path.join(dir, fileName);
|
||||
@@ -92,7 +102,7 @@ export function listHookProcesses(): HookProcessBaseInfo[] {
|
||||
return [...new Set(addon.getAllMainProcess())]
|
||||
.filter(pid => Number.isInteger(pid) && pid > 0)
|
||||
.sort((a, b) => a - b)
|
||||
.map(pid => ({ pid, name: 'QQ.exe', path: '' }));
|
||||
.map(pid => ({ pid, name: defaultProcessName(), path: '' }));
|
||||
}
|
||||
|
||||
export function injectHookProcess(pid: number): HookInjectResult {
|
||||
@@ -100,9 +110,10 @@ export function injectHookProcess(pid: number): HookInjectResult {
|
||||
if (!addon) {
|
||||
throw new Error(getNativeHookLoadError() ?? 'hook native addon is not available');
|
||||
}
|
||||
const dllPath = resolveHookNativePath('dll');
|
||||
const injectableExt = platformInjectableExt();
|
||||
const dllPath = resolveHookNativePath(injectableExt);
|
||||
if (!dllPath) {
|
||||
throw new Error(`No hook DLL found for ${process.platform}-${process.arch}`);
|
||||
throw new Error(`No hook ${injectableExt} found for ${process.platform}-${process.arch}`);
|
||||
}
|
||||
return { method: 'loadModuleManual', handle: addon.loadModuleManual(pid, dllPath) };
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import net from 'net';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
export const PIPE_MAGIC = 0x31504851;
|
||||
@@ -81,8 +83,22 @@ interface PendingAck {
|
||||
wantReply: boolean;
|
||||
}
|
||||
|
||||
function linuxRuntimeDir(): string {
|
||||
const explicit = process.env.SNOWLUMA_HOOK_RUNTIME_DIR;
|
||||
if (explicit && explicit.length > 0) return explicit;
|
||||
const xdg = process.env.XDG_RUNTIME_DIR;
|
||||
if (xdg && xdg.length > 0) return xdg;
|
||||
// Mirrors hook_stub.cpp runtime_dir() fallback.
|
||||
// process.geteuid is POSIX-only; cast to allow non-Linux type checks.
|
||||
const uid = typeof process.geteuid === 'function' ? process.geteuid() : os.userInfo().uid;
|
||||
return `/tmp/snowluma-${uid}`;
|
||||
}
|
||||
|
||||
function mojoPipeName(pid: number, suffix: string): string {
|
||||
return `\\\\.\\pipe\\mojo.${pid}.${suffix}`;
|
||||
if (process.platform === 'win32') {
|
||||
return `\\\\.\\pipe\\mojo.${pid}.${suffix}`;
|
||||
}
|
||||
return path.join(linuxRuntimeDir(), `mojo.${pid}.${suffix}`);
|
||||
}
|
||||
|
||||
function toBuffer(body: Buffer | Uint8Array | string | null | undefined): Buffer {
|
||||
|
||||
Reference in new issue
Block a user