-
-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathdump.dart
More file actions
87 lines (73 loc) · 2.06 KB
/
dump.dart
File metadata and controls
87 lines (73 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Retrieves the exported symbols from kernel32.
import 'dart:ffi';
import 'dart:io' show exit;
import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';
final _exportedSymbols = <String, int>{};
/// Callback called once for each enumerated symbol by SymEnumSymbols.
int _enumSymbolProc(Pointer<SYMBOL_INFO> pSymInfo, int size, Pointer ctx) {
// Only include symbols from the export table
if (pSymInfo.ref.Flags & SYMFLAG_EXPORT == SYMFLAG_EXPORT) {
final SYMBOL_INFO(:Address, :Name) = pSymInfo.ref;
_exportedSymbols[Name] = Address;
}
return TRUE; // Keep enumerating.
}
Map<String, int> getExports(HANDLE hProcess, String module) {
if (!SymInitialize(hProcess, null, false).value) {
print('SymInitialize failed.');
exit(1);
}
final imageName = module.toPcwstr();
final baseOfDll = SymLoadModuleEx(
hProcess,
null,
imageName,
null,
0,
0,
null,
null,
).value;
free(imageName);
if (baseOfDll == 0) {
print('SymLoadModuleEx failed.');
SymCleanup(hProcess);
exit(1);
}
final callback = NativeCallable<PSYM_ENUMERATESYMBOLS_CALLBACK>.isolateLocal(
_enumSymbolProc,
exceptionalReturn: 0,
);
final mask = '*'.toPcwstr();
if (!SymEnumSymbols(
hProcess,
baseOfDll,
mask,
callback.nativeFunction,
null,
).value) {
print('SymEnumSymbols failed.');
}
free(mask);
callback.close();
SymCleanup(hProcess);
return _exportedSymbols;
}
/// Test which processor architecture Windows is running
bool isWindowsOnArm(HANDLE hProcess) => using((arena) {
final pProcessMachine = arena<USHORT>();
final pNativeMachine = arena<USHORT>();
IsWow64Process2(hProcess, pProcessMachine, pNativeMachine);
return pNativeMachine.value == IMAGE_FILE_MACHINE_ARM64;
});
void main() {
final hProcess = GetCurrentProcess();
final kernel32 = isWindowsOnArm(hProcess)
? r'c:\windows\SysArm32\kernel32.dll'
: r'c:\windows\system32\kernel32.dll';
getExports(
hProcess,
kernel32,
).forEach((name, address) => print('[${address.toHexString()}] $name'));
}