@jshookmcp/jshook 0.1.5 → 0.1.6

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.
Files changed (81) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +72 -40
  3. package/README.zh.md +77 -40
  4. package/dist/constants.d.ts +1 -0
  5. package/dist/constants.js +13 -1
  6. package/dist/modules/analyzer/IntelligentAnalyzer.js +19 -11
  7. package/dist/modules/browser/BrowserModeManager.d.ts +5 -0
  8. package/dist/modules/browser/BrowserModeManager.js +96 -10
  9. package/dist/modules/browser/CamoufoxBrowserManager.d.ts +4 -0
  10. package/dist/modules/browser/CamoufoxBrowserManager.js +64 -3
  11. package/dist/modules/browser/TabRegistry.js +3 -2
  12. package/dist/modules/browser/UnifiedBrowserManager.d.ts +5 -0
  13. package/dist/modules/browser/UnifiedBrowserManager.js +62 -9
  14. package/dist/modules/captcha/AICaptchaDetector.js +185 -185
  15. package/dist/modules/debugger/DebuggerSessionManager.d.ts +4 -0
  16. package/dist/modules/debugger/DebuggerSessionManager.js +29 -19
  17. package/dist/modules/debugger/ScriptManager.impl.class.d.ts +4 -0
  18. package/dist/modules/debugger/ScriptManager.impl.class.js +46 -21
  19. package/dist/modules/emulator/EnvironmentEmulator.js +2 -2
  20. package/dist/modules/monitor/NetworkMonitor.impl.d.ts +1 -0
  21. package/dist/modules/monitor/NetworkMonitor.impl.js +22 -15
  22. package/dist/modules/monitor/PerformanceMonitor.js +64 -32
  23. package/dist/modules/process/LinuxProcessManager.d.ts +3 -1
  24. package/dist/modules/process/LinuxProcessManager.js +7 -3
  25. package/dist/modules/process/MacProcessManager.d.ts +3 -1
  26. package/dist/modules/process/MacProcessManager.js +32 -28
  27. package/dist/modules/process/ProcessManager.impl.d.ts +5 -1
  28. package/dist/modules/process/ProcessManager.impl.js +54 -13
  29. package/dist/modules/process/index.d.ts +3 -1
  30. package/dist/modules/process/index.js +2 -2
  31. package/dist/modules/process/memory/AuditTrail.d.ts +25 -0
  32. package/dist/modules/process/memory/AuditTrail.js +44 -0
  33. package/dist/modules/process/memory/availability.js +49 -49
  34. package/dist/modules/process/memory/injector.js +185 -185
  35. package/dist/modules/process/memory/linux/mapsParser.d.ts +16 -0
  36. package/dist/modules/process/memory/linux/mapsParser.js +28 -0
  37. package/dist/modules/process/memory/reader.js +50 -50
  38. package/dist/modules/process/memory/regions.enumerate.js +45 -1
  39. package/dist/modules/process/memory/regions.protection.js +48 -2
  40. package/dist/modules/process/memory/scanner.d.ts +4 -1
  41. package/dist/modules/process/memory/scanner.js +383 -182
  42. package/dist/modules/process/memory/writer.js +54 -54
  43. package/dist/native/NativeMemoryManager.impl.d.ts +4 -0
  44. package/dist/native/NativeMemoryManager.impl.js +72 -24
  45. package/dist/native/NativeMemoryManager.utils.d.ts +1 -0
  46. package/dist/native/NativeMemoryManager.utils.js +44 -1
  47. package/dist/native/scripts/linux/enum-windows.sh +12 -12
  48. package/dist/native/scripts/macos/enum-windows.applescript +22 -22
  49. package/dist/native/scripts/windows/enum-windows-by-class.ps1 +51 -51
  50. package/dist/native/scripts/windows/enum-windows.ps1 +44 -44
  51. package/dist/native/scripts/windows/inject-dll.ps1 +21 -21
  52. package/dist/server/MCPServer.search.d.ts +3 -0
  53. package/dist/server/MCPServer.search.js +21 -2
  54. package/dist/server/ToolCallContextGuard.d.ts +2 -0
  55. package/dist/server/ToolCallContextGuard.js +29 -14
  56. package/dist/server/ToolSearch.js +11 -5
  57. package/dist/server/domains/browser/definitions.tools.page-core.js +53 -53
  58. package/dist/server/domains/browser/definitions.tools.runtime.js +40 -40
  59. package/dist/server/domains/browser/definitions.tools.security.js +76 -76
  60. package/dist/server/domains/browser/handlers/tab-workflow.js +6 -4
  61. package/dist/server/domains/maintenance/handlers.extensions.js +46 -26
  62. package/dist/server/domains/process/definitions.js +20 -7
  63. package/dist/server/domains/process/handlers.impl.core.runtime.base.d.ts +35 -0
  64. package/dist/server/domains/process/handlers.impl.core.runtime.base.js +107 -1
  65. package/dist/server/domains/process/handlers.impl.core.runtime.inject.js +111 -2
  66. package/dist/server/domains/process/handlers.impl.core.runtime.memory.d.ts +9 -0
  67. package/dist/server/domains/process/handlers.impl.core.runtime.memory.js +282 -31
  68. package/dist/server/domains/process/manifest.js +1 -0
  69. package/dist/server/domains/transform/handlers.impl.transform-base.js +102 -102
  70. package/dist/server/domains/workflow/handlers.impl.workflow-api.js +14 -4
  71. package/dist/server/domains/workflow/handlers.impl.workflow-base.js +51 -51
  72. package/dist/server/registry/discovery.js +17 -12
  73. package/dist/server/registry/index.js +10 -2
  74. package/dist/utils/TokenBudgetManager.d.ts +1 -0
  75. package/dist/utils/TokenBudgetManager.js +22 -0
  76. package/package.json +5 -1
  77. package/src/native/scripts/linux/enum-windows.sh +12 -12
  78. package/src/native/scripts/macos/enum-windows.applescript +22 -22
  79. package/src/native/scripts/windows/enum-windows-by-class.ps1 +51 -51
  80. package/src/native/scripts/windows/enum-windows.ps1 +44 -44
  81. package/src/native/scripts/windows/inject-dll.ps1 +21 -21
@@ -5,60 +5,60 @@ import { execAsync, executePowerShellScript, } from '../../process/memory/types.
5
5
  async function writeMemoryWindows(pid, address, data) {
6
6
  try {
7
7
  const hexData = data.toString('hex').toUpperCase();
8
- const psScript = `
9
- Add-Type @"
10
- using System;
11
- using System.Runtime.InteropServices;
12
- using System.ComponentModel;
13
-
14
- public class MemoryWriter {
15
- [DllImport("kernel32.dll", SetLastError = true)]
16
- public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
17
-
18
- [DllImport("kernel32.dll", SetLastError = true)]
19
- public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr addr, byte[] buffer, int size, out int written);
20
-
21
- [DllImport("kernel32.dll", SetLastError = true)]
22
- public static extern bool CloseHandle(IntPtr handle);
23
-
24
- const int PROCESS_VM_WRITE = 0x0020;
25
- const int PROCESS_VM_OPERATION = 0x0008;
26
-
27
- public static int WriteMemory(int pid, long address, string hexData) {
28
- IntPtr hProcess = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, false, pid);
29
- if (hProcess == IntPtr.Zero) {
30
- int error = Marshal.GetLastWin32Error();
31
- throw new Win32Exception(error, "Failed to open process. Run as Administrator.");
32
- }
33
-
34
- try {
35
- byte[] buffer = new byte[hexData.Length / 2];
36
- for (int i = 0; i < hexData.Length; i += 2) {
37
- buffer[i / 2] = Convert.ToByte(hexData.Substring(i, 2), 16);
38
- }
39
-
40
- int bytesWritten;
41
- bool success = WriteProcessMemory(hProcess, (IntPtr)address, buffer, buffer.Length, out bytesWritten);
42
-
43
- if (!success) {
44
- int error = Marshal.GetLastWin32Error();
45
- throw new Win32Exception(error, "Failed to write memory");
46
- }
47
-
48
- return bytesWritten;
49
- } finally {
50
- CloseHandle(hProcess);
51
- }
52
- }
53
- }
54
- "@
55
-
56
- try {
57
- $bytesWritten = [MemoryWriter]::WriteMemory(${pid}, ${address}, "${hexData}")
58
- @{ success = $true; bytesWritten = $bytesWritten } | ConvertTo-Json -Compress
59
- } catch {
60
- @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
61
- }
8
+ const psScript = `
9
+ Add-Type @"
10
+ using System;
11
+ using System.Runtime.InteropServices;
12
+ using System.ComponentModel;
13
+
14
+ public class MemoryWriter {
15
+ [DllImport("kernel32.dll", SetLastError = true)]
16
+ public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
17
+
18
+ [DllImport("kernel32.dll", SetLastError = true)]
19
+ public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr addr, byte[] buffer, int size, out int written);
20
+
21
+ [DllImport("kernel32.dll", SetLastError = true)]
22
+ public static extern bool CloseHandle(IntPtr handle);
23
+
24
+ const int PROCESS_VM_WRITE = 0x0020;
25
+ const int PROCESS_VM_OPERATION = 0x0008;
26
+
27
+ public static int WriteMemory(int pid, long address, string hexData) {
28
+ IntPtr hProcess = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, false, pid);
29
+ if (hProcess == IntPtr.Zero) {
30
+ int error = Marshal.GetLastWin32Error();
31
+ throw new Win32Exception(error, "Failed to open process. Run as Administrator.");
32
+ }
33
+
34
+ try {
35
+ byte[] buffer = new byte[hexData.Length / 2];
36
+ for (int i = 0; i < hexData.Length; i += 2) {
37
+ buffer[i / 2] = Convert.ToByte(hexData.Substring(i, 2), 16);
38
+ }
39
+
40
+ int bytesWritten;
41
+ bool success = WriteProcessMemory(hProcess, (IntPtr)address, buffer, buffer.Length, out bytesWritten);
42
+
43
+ if (!success) {
44
+ int error = Marshal.GetLastWin32Error();
45
+ throw new Win32Exception(error, "Failed to write memory");
46
+ }
47
+
48
+ return bytesWritten;
49
+ } finally {
50
+ CloseHandle(hProcess);
51
+ }
52
+ }
53
+ }
54
+ "@
55
+
56
+ try {
57
+ $bytesWritten = [MemoryWriter]::WriteMemory(${pid}, ${address}, "${hexData}")
58
+ @{ success = $true; bytesWritten = $bytesWritten } | ConvertTo-Json -Compress
59
+ } catch {
60
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
61
+ }
62
62
  `;
63
63
  const { stdout } = await executePowerShellScript(psScript, { maxBuffer: 1024 * 1024 });
64
64
  const _trimmed = stdout.trim();
@@ -1,5 +1,9 @@
1
1
  import type { MemoryRegion, ModuleInfo, NativeMemoryReadResult, NativeMemoryScanResult, NativeMemoryWriteResult } from './NativeMemoryManager.types.js';
2
2
  export type { MemoryRegion, ModuleInfo, NativeMemoryReadResult, NativeMemoryScanResult, NativeMemoryWriteResult, } from './NativeMemoryManager.types.js';
3
+ export declare function scanRegionInChunks(region: {
4
+ baseAddress: bigint;
5
+ regionSize: number;
6
+ }, patternBytes: number[], mask: number[], readChunk: (address: bigint, size: number) => Buffer<ArrayBufferLike>, chunkSize?: number): bigint[];
3
7
  export declare class NativeMemoryManager {
4
8
  checkAvailability(): Promise<{
5
9
  available: boolean;
@@ -1,10 +1,38 @@
1
1
  import { logger } from '../utils/logger.js';
2
2
  import { exec } from 'node:child_process';
3
3
  import { promisify } from 'node:util';
4
+ import { cpuLimit } from '../utils/concurrency.js';
4
5
  import { PAGE, MEM, openProcessForMemory, CloseHandle, ReadProcessMemory, WriteProcessMemory, VirtualQueryEx, VirtualProtectEx, VirtualAllocEx, CreateRemoteThread, GetModuleHandle, GetProcAddress, NtQueryInformationProcess, EnumProcessModules, GetModuleBaseName, GetModuleInformation, } from './Win32API.js';
5
6
  import { findPatternInBuffer, getProtectionString, getStateString, getTypeString, isExecutable, isReadable, isWritable, parsePattern, } from './NativeMemoryManager.utils.js';
6
7
  import { checkNativeMemoryAvailability } from './NativeMemoryManager.availability.js';
7
8
  const execAsync = promisify(exec);
9
+ const SCAN_CHUNK_SIZE = 16 * 1024 * 1024;
10
+ export function scanRegionInChunks(region, patternBytes, mask, readChunk, chunkSize = SCAN_CHUNK_SIZE) {
11
+ if (patternBytes.length === 0 || region.regionSize < patternBytes.length || chunkSize <= 0) {
12
+ return [];
13
+ }
14
+ const overlap = Math.max(patternBytes.length - 1, 0);
15
+ let carryOver = Buffer.alloc(0);
16
+ const matches = [];
17
+ for (let chunkOffset = 0; chunkOffset < region.regionSize; chunkOffset += chunkSize) {
18
+ const readSize = Math.min(chunkSize, region.regionSize - chunkOffset);
19
+ const chunkAddress = region.baseAddress + BigInt(chunkOffset);
20
+ const chunk = readChunk(chunkAddress, readSize);
21
+ const scanBuffer = carryOver.length > 0 ? Buffer.concat([carryOver, chunk]) : chunk;
22
+ const chunkMatches = findPatternInBuffer(scanBuffer, patternBytes, mask);
23
+ for (const matchOffset of chunkMatches) {
24
+ const regionOffset = chunkOffset + matchOffset - carryOver.length;
25
+ matches.push(region.baseAddress + BigInt(regionOffset));
26
+ }
27
+ if (overlap === 0 || chunkOffset + readSize >= region.regionSize) {
28
+ carryOver = Buffer.alloc(0);
29
+ continue;
30
+ }
31
+ const carrySize = Math.min(overlap, scanBuffer.length);
32
+ carryOver = scanBuffer.subarray(scanBuffer.length - carrySize);
33
+ }
34
+ return matches;
35
+ }
8
36
  export class NativeMemoryManager {
9
37
  async checkAvailability() {
10
38
  return checkNativeMemoryAvailability(execAsync);
@@ -156,45 +184,65 @@ export class NativeMemoryManager {
156
184
  if (patternBytes.length === 0) {
157
185
  return { success: false, addresses: [], error: 'Invalid pattern' };
158
186
  }
159
- const handle = openProcessForMemory(pid, false);
160
- const addresses = [];
161
187
  const maxResults = 10000;
188
+ const readableRegions = [];
189
+ const handle = openProcessForMemory(pid, false);
162
190
  try {
163
191
  let address = 0n;
164
192
  const maxAddress = BigInt('0x7FFFFFFF0000');
165
- while (address < maxAddress && addresses.length < maxResults) {
193
+ while (address < maxAddress) {
166
194
  const { success, info } = VirtualQueryEx(handle, address);
167
195
  if (!success || info.RegionSize === 0n) {
168
196
  break;
169
197
  }
170
- if (isReadable(info) && Number(info.RegionSize) > 0 && Number(info.RegionSize) < 1024 * 1024 * 1024) {
171
- try {
172
- const regionBuffer = ReadProcessMemory(handle, info.BaseAddress, Number(info.RegionSize));
173
- const matches = findPatternInBuffer(regionBuffer, patternBytes, mask);
174
- for (const offset of matches) {
175
- const foundAddr = info.BaseAddress + BigInt(offset);
176
- addresses.push(`0x${foundAddr.toString(16).toUpperCase()}`);
177
- if (addresses.length >= maxResults)
178
- break;
179
- }
180
- }
181
- catch {
182
- }
198
+ if (isReadable(info) &&
199
+ info.RegionSize > 0n &&
200
+ info.RegionSize <= BigInt(Number.MAX_SAFE_INTEGER)) {
201
+ readableRegions.push({
202
+ baseAddress: info.BaseAddress,
203
+ regionSize: Number(info.RegionSize),
204
+ });
183
205
  }
184
206
  address = info.BaseAddress + info.RegionSize;
185
207
  }
186
- return {
187
- success: true,
188
- addresses,
189
- stats: {
190
- patternLength: patternBytes.length,
191
- resultsFound: addresses.length,
192
- },
193
- };
194
208
  }
195
209
  finally {
196
210
  CloseHandle(handle);
197
211
  }
212
+ const regionMatches = await Promise.all(readableRegions.map(region => cpuLimit(async () => {
213
+ const scanHandle = openProcessForMemory(pid, false);
214
+ try {
215
+ try {
216
+ return scanRegionInChunks(region, patternBytes, mask, (address, size) => ReadProcessMemory(scanHandle, address, size));
217
+ }
218
+ catch {
219
+ return [];
220
+ }
221
+ }
222
+ finally {
223
+ CloseHandle(scanHandle);
224
+ }
225
+ })));
226
+ const addresses = [];
227
+ for (const matches of regionMatches) {
228
+ for (const foundAddr of matches) {
229
+ addresses.push(`0x${foundAddr.toString(16).toUpperCase()}`);
230
+ if (addresses.length >= maxResults) {
231
+ break;
232
+ }
233
+ }
234
+ if (addresses.length >= maxResults) {
235
+ break;
236
+ }
237
+ }
238
+ return {
239
+ success: true,
240
+ addresses,
241
+ stats: {
242
+ patternLength: patternBytes.length,
243
+ resultsFound: addresses.length,
244
+ },
245
+ };
198
246
  }
199
247
  catch (error) {
200
248
  logger.error('Native memory scan failed', {
@@ -1,5 +1,6 @@
1
1
  import { type MemoryBasicInfo } from './Win32API.js';
2
2
  import type { NativePatternType } from './NativeMemoryManager.types.js';
3
+ export declare function isKoffiAvailable(): boolean;
3
4
  export declare function parsePattern(pattern: string, patternType: NativePatternType): {
4
5
  patternBytes: number[];
5
6
  mask: number[];
@@ -1,4 +1,7 @@
1
- import { PAGE, MEM, MEM_TYPE } from './Win32API.js';
1
+ import { PAGE, MEM, MEM_TYPE, isKoffiAvailable as isWin32KoffiAvailable, } from './Win32API.js';
2
+ export function isKoffiAvailable() {
3
+ return isWin32KoffiAvailable();
4
+ }
2
5
  export function parsePattern(pattern, patternType) {
3
6
  const patternBytes = [];
4
7
  const mask = [];
@@ -67,7 +70,47 @@ export function parsePattern(pattern, patternType) {
67
70
  }
68
71
  return { patternBytes, mask };
69
72
  }
73
+ function findExactPatternBMH(buffer, pattern) {
74
+ const matches = [];
75
+ const patternLength = pattern.length;
76
+ if (patternLength === 0 || buffer.length < patternLength) {
77
+ return matches;
78
+ }
79
+ const lastIndex = patternLength - 1;
80
+ const skipTable = new Uint32Array(256);
81
+ skipTable.fill(patternLength);
82
+ for (let i = 0; i < lastIndex; i++) {
83
+ const patternByte = pattern[i];
84
+ if (patternByte !== undefined) {
85
+ skipTable[patternByte] = lastIndex - i;
86
+ }
87
+ }
88
+ let offset = 0;
89
+ while (offset <= buffer.length - patternLength) {
90
+ let patternIndex = lastIndex;
91
+ while (patternIndex >= 0 && buffer[offset + patternIndex] === pattern[patternIndex]) {
92
+ patternIndex--;
93
+ }
94
+ if (patternIndex < 0) {
95
+ matches.push(offset);
96
+ offset += 1;
97
+ continue;
98
+ }
99
+ const skipByte = buffer[offset + lastIndex];
100
+ if (skipByte === undefined) {
101
+ break;
102
+ }
103
+ offset += skipTable[skipByte] ?? patternLength;
104
+ }
105
+ return matches;
106
+ }
70
107
  export function findPatternInBuffer(buffer, pattern, mask) {
108
+ if (pattern.length === 0) {
109
+ return [];
110
+ }
111
+ if (mask.every(value => value === 1)) {
112
+ return findExactPatternBMH(buffer, pattern);
113
+ }
71
114
  const matches = [];
72
115
  for (let i = 0; i <= buffer.length - pattern.length; i++) {
73
116
  let found = true;
@@ -1,12 +1,12 @@
1
- #!/bin/bash
2
- # enum-windows.sh
3
- # Linux window enumeration script (placeholder)
4
-
5
- TARGET_PID=$1
6
-
7
- # Use xdotool or wmctrl for window enumeration
8
- # This is a placeholder for future implementation
9
-
10
- if command -v xdotool &> /dev/null; then
11
- xdotool search --pid "$TARGET_PID" --name "" get-window-name
12
- fi
1
+ #!/bin/bash
2
+ # enum-windows.sh
3
+ # Linux window enumeration script (placeholder)
4
+
5
+ TARGET_PID=$1
6
+
7
+ # Use xdotool or wmctrl for window enumeration
8
+ # This is a placeholder for future implementation
9
+
10
+ if command -v xdotool &> /dev/null; then
11
+ xdotool search --pid "$TARGET_PID" --name "" get-window-name
12
+ fi
@@ -1,22 +1,22 @@
1
- -- enum-windows.applescript
2
- -- macOS window enumeration script (placeholder)
3
-
4
- param TargetPid
5
-
6
- -- AppleScript implementation for window enumeration
7
- -- This is a placeholder for future implementation
8
-
9
- tell application "System Events"
10
- set windowList to {}
11
- repeat with proc in (every process whose unix id is TargetPid)
12
- repeat with win in windows of proc
13
- set end of windowList to {¬
14
- title: name of win, ¬
15
- position: position of win, ¬
16
- size: size of win ¬
17
- }
18
- end repeat
19
- end repeat
20
- end tell
21
-
22
- return windowList
1
+ -- enum-windows.applescript
2
+ -- macOS window enumeration script (placeholder)
3
+
4
+ param TargetPid
5
+
6
+ -- AppleScript implementation for window enumeration
7
+ -- This is a placeholder for future implementation
8
+
9
+ tell application "System Events"
10
+ set windowList to {}
11
+ repeat with proc in (every process whose unix id is TargetPid)
12
+ repeat with win in windows of proc
13
+ set end of windowList to {¬
14
+ title: name of win, ¬
15
+ position: position of win, ¬
16
+ size: size of win ¬
17
+ }
18
+ end repeat
19
+ end repeat
20
+ end tell
21
+
22
+ return windowList
@@ -1,51 +1,51 @@
1
- param(
2
- [string]$ClassPattern
3
- )
4
-
5
- Add-Type @"
6
- using System;
7
- using System.Runtime.InteropServices;
8
- public class Win32 {
9
- [DllImport("user32.dll")] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childAfter, string className, string title);
10
- [DllImport("user32.dll")] public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int pid);
11
- [DllImport("user32.dll")] public static extern int GetWindowText(IntPtr hWnd, System.Text.StringBuilder text, int count);
12
- [DllImport("user32.dll")] public static extern int GetClassName(IntPtr hWnd, System.Text.StringBuilder className, int maxCount);
13
- }
14
- "@
15
-
16
- $windows = @()
17
- $hwnd = [IntPtr]::Zero
18
- while ($true) {
19
- $hwnd = [Win32]::FindWindowEx([IntPtr]::Zero, $hwnd, $null, $null)
20
- if ($hwnd -eq [IntPtr]::Zero) { break }
21
-
22
- $className = New-Object System.Text.StringBuilder 256
23
- [Win32]::GetClassName($hwnd, $className, 256) | Out-Null
24
- $classNameStr = $className.ToString()
25
-
26
- # Support wildcard pattern matching
27
- $isMatch = $false
28
- if ($ClassPattern -eq $classNameStr) {
29
- $isMatch = $true
30
- } elseif ($ClassPattern.Contains('*')) {
31
- # Convert wildcard pattern to regex
32
- $regexPattern = [regex]::Escape($ClassPattern).Replace('\*', '.*')
33
- if ($classNameStr -match $regexPattern) {
34
- $isMatch = $true
35
- }
36
- }
37
-
38
- if ($isMatch) {
39
- $windowPid = 0
40
- [Win32]::GetWindowThreadProcessId($hwnd, [ref]$windowPid) | Out-Null
41
- $title = New-Object System.Text.StringBuilder 256
42
- [Win32]::GetWindowText($hwnd, $title, 256) | Out-Null
43
- $windows += @{
44
- Handle = $hwnd.ToString()
45
- Title = $title.ToString()
46
- ClassName = $classNameStr
47
- ProcessId = $windowPid
48
- }
49
- }
50
- }
51
- $windows | ConvertTo-Json -Compress
1
+ param(
2
+ [string]$ClassPattern
3
+ )
4
+
5
+ Add-Type @"
6
+ using System;
7
+ using System.Runtime.InteropServices;
8
+ public class Win32 {
9
+ [DllImport("user32.dll")] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childAfter, string className, string title);
10
+ [DllImport("user32.dll")] public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int pid);
11
+ [DllImport("user32.dll")] public static extern int GetWindowText(IntPtr hWnd, System.Text.StringBuilder text, int count);
12
+ [DllImport("user32.dll")] public static extern int GetClassName(IntPtr hWnd, System.Text.StringBuilder className, int maxCount);
13
+ }
14
+ "@
15
+
16
+ $windows = @()
17
+ $hwnd = [IntPtr]::Zero
18
+ while ($true) {
19
+ $hwnd = [Win32]::FindWindowEx([IntPtr]::Zero, $hwnd, $null, $null)
20
+ if ($hwnd -eq [IntPtr]::Zero) { break }
21
+
22
+ $className = New-Object System.Text.StringBuilder 256
23
+ [Win32]::GetClassName($hwnd, $className, 256) | Out-Null
24
+ $classNameStr = $className.ToString()
25
+
26
+ # Support wildcard pattern matching
27
+ $isMatch = $false
28
+ if ($ClassPattern -eq $classNameStr) {
29
+ $isMatch = $true
30
+ } elseif ($ClassPattern.Contains('*')) {
31
+ # Convert wildcard pattern to regex
32
+ $regexPattern = [regex]::Escape($ClassPattern).Replace('\*', '.*')
33
+ if ($classNameStr -match $regexPattern) {
34
+ $isMatch = $true
35
+ }
36
+ }
37
+
38
+ if ($isMatch) {
39
+ $windowPid = 0
40
+ [Win32]::GetWindowThreadProcessId($hwnd, [ref]$windowPid) | Out-Null
41
+ $title = New-Object System.Text.StringBuilder 256
42
+ [Win32]::GetWindowText($hwnd, $title, 256) | Out-Null
43
+ $windows += @{
44
+ Handle = $hwnd.ToString()
45
+ Title = $title.ToString()
46
+ ClassName = $classNameStr
47
+ ProcessId = $windowPid
48
+ }
49
+ }
50
+ }
51
+ $windows | ConvertTo-Json -Compress
@@ -1,44 +1,44 @@
1
- param(
2
- [int]$TargetPid
3
- )
4
-
5
- Add-Type @"
6
- using System;
7
- using System.Runtime.InteropServices;
8
- public class Win32 {
9
- [DllImport("user32.dll")] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childAfter, string className, string title);
10
- [DllImport("user32.dll")] public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int pid);
11
- [DllImport("user32.dll")] public static extern int GetWindowText(IntPtr hWnd, System.Text.StringBuilder text, int count);
12
- [DllImport("user32.dll")] public static extern int GetClassName(IntPtr hWnd, System.Text.StringBuilder className, int maxCount);
13
- [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
14
- [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left, Top, Right, Bottom; }
15
- }
16
- "@
17
-
18
- $windows = @()
19
- $hwnd = [IntPtr]::Zero
20
- while ($true) {
21
- $hwnd = [Win32]::FindWindowEx([IntPtr]::Zero, $hwnd, $null, $null)
22
- if ($hwnd -eq [IntPtr]::Zero) { break }
23
- $windowPid = 0
24
- [Win32]::GetWindowThreadProcessId($hwnd, [ref]$windowPid) | Out-Null
25
- if ($windowPid -eq $TargetPid) {
26
- $title = New-Object System.Text.StringBuilder 256
27
- $className = New-Object System.Text.StringBuilder 256
28
- [Win32]::GetWindowText($hwnd, $title, 256) | Out-Null
29
- [Win32]::GetClassName($hwnd, $className, 256) | Out-Null
30
- $rect = New-Object Win32+RECT
31
- [Win32]::GetWindowRect($hwnd, [ref]$rect) | Out-Null
32
- $windows += @{
33
- Handle = $hwnd.ToString()
34
- Title = $title.ToString()
35
- ClassName = $className.ToString()
36
- ProcessId = $windowPid
37
- Left = $rect.Left
38
- Top = $rect.Top
39
- Right = $rect.Right
40
- Bottom = $rect.Bottom
41
- }
42
- }
43
- }
44
- $windows | ConvertTo-Json -Compress
1
+ param(
2
+ [int]$TargetPid
3
+ )
4
+
5
+ Add-Type @"
6
+ using System;
7
+ using System.Runtime.InteropServices;
8
+ public class Win32 {
9
+ [DllImport("user32.dll")] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childAfter, string className, string title);
10
+ [DllImport("user32.dll")] public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int pid);
11
+ [DllImport("user32.dll")] public static extern int GetWindowText(IntPtr hWnd, System.Text.StringBuilder text, int count);
12
+ [DllImport("user32.dll")] public static extern int GetClassName(IntPtr hWnd, System.Text.StringBuilder className, int maxCount);
13
+ [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
14
+ [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left, Top, Right, Bottom; }
15
+ }
16
+ "@
17
+
18
+ $windows = @()
19
+ $hwnd = [IntPtr]::Zero
20
+ while ($true) {
21
+ $hwnd = [Win32]::FindWindowEx([IntPtr]::Zero, $hwnd, $null, $null)
22
+ if ($hwnd -eq [IntPtr]::Zero) { break }
23
+ $windowPid = 0
24
+ [Win32]::GetWindowThreadProcessId($hwnd, [ref]$windowPid) | Out-Null
25
+ if ($windowPid -eq $TargetPid) {
26
+ $title = New-Object System.Text.StringBuilder 256
27
+ $className = New-Object System.Text.StringBuilder 256
28
+ [Win32]::GetWindowText($hwnd, $title, 256) | Out-Null
29
+ [Win32]::GetClassName($hwnd, $className, 256) | Out-Null
30
+ $rect = New-Object Win32+RECT
31
+ [Win32]::GetWindowRect($hwnd, [ref]$rect) | Out-Null
32
+ $windows += @{
33
+ Handle = $hwnd.ToString()
34
+ Title = $title.ToString()
35
+ ClassName = $className.ToString()
36
+ ProcessId = $windowPid
37
+ Left = $rect.Left
38
+ Top = $rect.Top
39
+ Right = $rect.Right
40
+ Bottom = $rect.Bottom
41
+ }
42
+ }
43
+ }
44
+ $windows | ConvertTo-Json -Compress
@@ -1,21 +1,21 @@
1
- param(
2
- [int]$TargetPid,
3
- [string]$DllPath
4
- )
5
-
6
- Add-Type @"
7
- using System;
8
- using System.Runtime.InteropServices;
9
- public class Injector {
10
- [DllImport("kernel32.dll")] public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
11
- [DllImport("kernel32.dll")] public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr addr, int size, int alloc, int protect);
12
- [DllImport("kernel32.dll")] public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr addr, byte[] buffer, int size, out int written);
13
- [DllImport("kernel32.dll")] public static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr attr, int stack, IntPtr start, IntPtr param, int flags, out int threadId);
14
- [DllImport("kernel32.dll")] public static extern IntPtr GetModuleHandle(string name);
15
- [DllImport("kernel32.dll")] public static extern IntPtr GetProcAddress(IntPtr hModule, string name);
16
- [DllImport("kernel32.dll")] public static extern bool CloseHandle(IntPtr handle);
17
- }
18
- "@
19
-
20
- # Injection requires elevated privileges and is disabled for safety
21
- Write-Output "DLL injection is disabled for safety in this implementation. PID: $TargetPid, DLL: $DllPath"
1
+ param(
2
+ [int]$TargetPid,
3
+ [string]$DllPath
4
+ )
5
+
6
+ Add-Type @"
7
+ using System;
8
+ using System.Runtime.InteropServices;
9
+ public class Injector {
10
+ [DllImport("kernel32.dll")] public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
11
+ [DllImport("kernel32.dll")] public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr addr, int size, int alloc, int protect);
12
+ [DllImport("kernel32.dll")] public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr addr, byte[] buffer, int size, out int written);
13
+ [DllImport("kernel32.dll")] public static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr attr, int stack, IntPtr start, IntPtr param, int flags, out int threadId);
14
+ [DllImport("kernel32.dll")] public static extern IntPtr GetModuleHandle(string name);
15
+ [DllImport("kernel32.dll")] public static extern IntPtr GetProcAddress(IntPtr hModule, string name);
16
+ [DllImport("kernel32.dll")] public static extern bool CloseHandle(IntPtr handle);
17
+ }
18
+ "@
19
+
20
+ # Injection requires elevated privileges and is disabled for safety
21
+ Write-Output "DLL injection is disabled for safety in this implementation. PID: $TargetPid, DLL: $DllPath"
@@ -1,2 +1,5 @@
1
1
  import type { MCPServerContext } from './MCPServer.context.js';
2
+ import { ToolSearchEngine } from './ToolSearch.js';
3
+ export declare function buildSearchSignature(ctx: MCPServerContext): string;
4
+ export declare function getSearchEngine(ctx: MCPServerContext): ToolSearchEngine;
2
5
  export declare function registerSearchMetaTools(ctx: MCPServerContext): void;