1 module monox
is aliced
;
4 import std
.string
: fromStringz
;
11 // ////////////////////////////////////////////////////////////////////////// //
12 extern(C
) nothrow @nogc {
13 enum RTLD_LAZY
= 0x00001; // POSIX
14 extern void* __libc_dlopen_mode (const(char)* name
, int mode
);
15 extern void* __libc_dlsym (void* soh
, const(char)* name
);
16 extern int __libc_dlclose (void* soh
);
20 // ////////////////////////////////////////////////////////////////////////// //
23 alias uintptr_t
= uint;
26 // ////////////////////////////////////////////////////////////////////////// //
27 // original source: blob.h in the mono sourcecode
28 // Encoding for type signatures used in the Metadata
29 alias MonoTypeEnum
= uint;
30 enum /*MonoTypeEnum*/ : uint {
31 MONO_TYPE_END
= 0x00, // End of List
32 MONO_TYPE_VOID
= 0x01,
33 MONO_TYPE_BOOLEAN
= 0x02,
34 MONO_TYPE_CHAR
= 0x03,
45 MONO_TYPE_STRING
= 0x0e,
46 MONO_TYPE_PTR
= 0x0f, // arg: <type> token
47 MONO_TYPE_BYREF
= 0x10, // arg: <type> token
48 MONO_TYPE_VALUETYPE
= 0x11, // arg: <type> token
49 MONO_TYPE_CLASS
= 0x12, // arg: <type> token
50 MONO_TYPE_VAR
= 0x13, // number
51 MONO_TYPE_ARRAY
= 0x14, // type, rank, boundsCount, bound1, loCount, lo1
52 MONO_TYPE_GENERICINST
= 0x15, // <type> <type-arg-count> <type-1> \x{2026} <type-n>
53 MONO_TYPE_TYPEDBYREF
= 0x16,
56 MONO_TYPE_FNPTR
= 0x1b, // arg: full method signature
57 MONO_TYPE_OBJECT
= 0x1c,
58 MONO_TYPE_SZARRAY
= 0x1d, // 0-based one-dim-array
59 MONO_TYPE_MVAR
= 0x1e, // number
60 MONO_TYPE_CMOD_REQD
= 0x1f, // arg: typedef or typeref token
61 MONO_TYPE_CMOD_OPT
= 0x20, // optional arg: typedef or typref token
62 MONO_TYPE_INTERNAL
= 0x21, // CLR internal type
64 MONO_TYPE_MODIFIER
= 0x40, // Or with the following types
65 MONO_TYPE_SENTINEL
= 0x41, // Sentinel for varargs method signature
66 MONO_TYPE_PINNED
= 0x45, // Local var that points to pinned object
68 MONO_TYPE_ENUM
= 0x55, // an enumeration
71 alias MonoMetaTableEnum
= uint;
72 enum /*MonoMetaTableEnum*/ : uint {
76 MONO_TABLE_FIELD_POINTER
,
78 MONO_TABLE_METHOD_POINTER
,
80 MONO_TABLE_PARAM_POINTER
,
82 MONO_TABLE_INTERFACEIMPL
,
83 MONO_TABLE_MEMBERREF
, // 0xa
85 MONO_TABLE_CUSTOMATTRIBUTE
,
86 MONO_TABLE_FIELDMARSHAL
,
87 MONO_TABLE_DECLSECURITY
,
88 MONO_TABLE_CLASSLAYOUT
,
89 MONO_TABLE_FIELDLAYOUT
, // 0x10
90 MONO_TABLE_STANDALONESIG
,
92 MONO_TABLE_EVENT_POINTER
,
94 MONO_TABLE_PROPERTYMAP
,
95 MONO_TABLE_PROPERTY_POINTER
,
97 MONO_TABLE_METHODSEMANTICS
,
98 MONO_TABLE_METHODIMPL
,
99 MONO_TABLE_MODULEREF
, // 0x1a
105 MONO_TABLE_ASSEMBLY
, // 0x20
106 MONO_TABLE_ASSEMBLYPROCESSOR
,
107 MONO_TABLE_ASSEMBLYOS
,
108 MONO_TABLE_ASSEMBLYREF
,
109 MONO_TABLE_ASSEMBLYREFPROCESSOR
,
110 MONO_TABLE_ASSEMBLYREFOS
,
112 MONO_TABLE_EXPORTEDTYPE
,
113 MONO_TABLE_MANIFESTRESOURCE
,
114 MONO_TABLE_NESTEDCLASS
,
115 MONO_TABLE_GENERICPARAM
, // 0x2a
116 MONO_TABLE_METHODSPEC
,
117 MONO_TABLE_GENERICPARAMCONSTRAINT
,
123 MONO_TYPEDEF_NAMESPACE
,
124 MONO_TYPEDEF_EXTENDS
,
125 MONO_TYPEDEF_FIELD_LIST
,
126 MONO_TYPEDEF_METHOD_LIST
,
132 MONO_METHOD_IMPLFLAGS
,
135 MONO_METHOD_SIGNATURE
,
136 MONO_METHOD_PARAMLIST
,
140 alias MonoTokenType
= uint;
141 enum /*MonoTokenType*/ : uint {
142 MONO_TOKEN_MODULE
= 0x00000000,
143 MONO_TOKEN_TYPE_REF
= 0x01000000,
144 MONO_TOKEN_TYPE_DEF
= 0x02000000,
145 MONO_TOKEN_FIELD_DEF
= 0x04000000,
146 MONO_TOKEN_METHOD_DEF
= 0x06000000,
147 MONO_TOKEN_PARAM_DEF
= 0x08000000,
148 MONO_TOKEN_INTERFACE_IMPL
= 0x09000000,
149 MONO_TOKEN_MEMBER_REF
= 0x0a000000,
150 MONO_TOKEN_CUSTOM_ATTRIBUTE
= 0x0c000000,
151 MONO_TOKEN_PERMISSION
= 0x0e000000,
152 MONO_TOKEN_SIGNATURE
= 0x11000000,
153 MONO_TOKEN_EVENT
= 0x14000000,
154 MONO_TOKEN_PROPERTY
= 0x17000000,
155 MONO_TOKEN_MODULE_REF
= 0x1a000000,
156 MONO_TOKEN_TYPE_SPEC
= 0x1b000000,
157 MONO_TOKEN_ASSEMBLY
= 0x20000000,
158 MONO_TOKEN_ASSEMBLY_REF
= 0x23000000,
159 MONO_TOKEN_FILE
= 0x26000000,
160 MONO_TOKEN_EXPORTED_TYPE
= 0x27000000,
161 MONO_TOKEN_MANIFEST_RESOURCE
= 0x28000000,
162 MONO_TOKEN_GENERIC_PARAM
= 0x2a000000,
163 MONO_TOKEN_METHOD_SPEC
= 0x2b000000,
165 // These do not match metadata tables directly
166 MONO_TOKEN_STRING
= 0x70000000,
167 MONO_TOKEN_NAME
= 0x71000000,
168 MONO_TOKEN_BASE_TYPE
= 0x72000000,
172 // ////////////////////////////////////////////////////////////////////////// //
173 alias MonoDomainFunc
= extern(C
) void function (void* domain
, void* user_data
) nothrow @nogc;
174 alias GFunc
= extern(C
) void function (void* data
, void* user_data
) nothrow @nogc;
176 alias G_FREE
= extern(C
) void function (void* ptr
) nothrow @nogc;
178 alias MONO_GET_ROOT_DOMAIN
= extern(C
) void* function () nothrow @nogc;
179 alias MONO_THREAD_ATTACH
= extern(C
) void* function (void* domain
) nothrow @nogc;
180 alias MONO_THREAD_DETACH
= extern(C
) void function (void* monothread
) nothrow @nogc;
181 alias MONO_OBJECT_GET_CLASS
= extern(C
) void* function (void* object
) nothrow @nogc;
183 alias MONO_DOMAIN_FOREACH
= extern(C
) void function (MonoDomainFunc func
, void* user_data
) nothrow /*@nogc*/;
185 alias MONO_DOMAIN_SET
= extern(C
) int function (void* domain
, BOOL force
) nothrow @nogc;
186 alias MONO_ASSEMBLY_FOREACH
= extern(C
) int function (GFunc func
, void* user_data
) nothrow /*@nogc*/;
187 alias MONO_ASSEMBLY_GET_IMAGE
= extern(C
) void* function (void* assembly
) nothrow @nogc;
188 alias MONO_ASSEMBLY_OPEN
= extern(C
) void* function (void* fname
, int* status
) nothrow @nogc;
189 alias MONO_IMAGE_GET_ASSEMBLY
= extern(C
) void* function (void* image
) nothrow @nogc;
190 alias MONO_IMAGE_GET_NAME
= extern(C
) char* function (void* image
) nothrow @nogc;
191 alias MONO_IMAGE_OPEN
= extern(C
) void* function (const(char)* fname
, int* status
) nothrow @nogc;
193 alias MONO_IMAGE_GET_TABLE_INFO
= extern(C
) void* function (void* image
, int table_id
) nothrow @nogc;
194 alias MONO_TABLE_INFO_GET_ROWS
= extern(C
) int function (void* tableinfo
) nothrow @nogc;
195 alias MONO_METADATA_DECODE_ROW_COL
= extern(C
) int function (void* tableinfo
, int idx
, uint col
) nothrow @nogc;
196 alias MONO_METADATA_STRING_HEAP
= extern(C
) ubyte* function (void* image
, UINT32 index
) nothrow @nogc; //???
198 alias MONO_CLASS_FROM_NAME_CASE
= extern(C
) void* function (void* image
, const(char)* name_space
, const(char)* name
) nothrow @nogc;
199 alias MONO_CLASS_GET_NAME
= extern(C
) char* function (void* klass
) nothrow @nogc;
200 alias MONO_CLASS_GET_NAMESPACE
= extern(C
) char* function (void* klass
) nothrow @nogc; // returns namespace name
201 alias MONO_CLASS_GET
= extern(C
) void* function (void* image
, UINT32 tokenindex
) nothrow @nogc;
202 alias MONO_CLASS_GET_METHODS
= extern(C
) void* function (void* klass
, void* iter
) nothrow @nogc;
203 alias MONO_CLASS_GET_METHOD_FROM_NAME
= extern(C
) void* function (void* klass
, const(char)* methodname
, int paramcount
) nothrow @nogc;
204 alias MONO_CLASS_GET_FIELDS
= extern(C
) void* function (void* klass
, void* iter
) nothrow @nogc;
205 alias MONO_CLASS_GET_PARENT
= extern(C
) void* function (void* klass
) nothrow @nogc;
206 alias MONO_CLASS_VTABLE
= extern(C
) void* function (void* domain
, void* klass
) nothrow @nogc;
207 alias MONO_CLASS_FROM_MONO_TYPE
= extern(C
) void* function (void* type
) nothrow @nogc;
208 alias MONO_CLASS_GET_ELEMENT_CLASS
= extern(C
) void* function (void* klass
) nothrow @nogc;
210 alias MONO_CLASS_NUM_FIELDS
= extern(C
) int function (void* klass
) nothrow @nogc;
211 alias MONO_CLASS_NUM_METHODS
= extern(C
) int function (void* klass
) nothrow @nogc;
213 alias MONO_FIELD_GET_NAME
= extern(C
) char* function (void* field
) nothrow @nogc; // should be g_free'd
214 alias MONO_FIELD_GET_TYPE
= extern(C
) void* function (void* field
) nothrow @nogc;
215 alias MONO_FIELD_GET_PARENT
= extern(C
) void* function (void* field
) nothrow @nogc;
216 alias MONO_FIELD_GET_OFFSET
= extern(C
) int function (void* field
) nothrow @nogc;
218 alias MONO_TYPE_GET_NAME
= extern(C
) char* function (void* type
) nothrow @nogc;
219 alias MONO_TYPE_GET_TYPE
= extern(C
) int function (void* type
) nothrow @nogc;
220 alias MONO_TYPE_GET_NAME_FULL
= extern(C
) char* function (void* type
, int format
) nothrow @nogc;
221 alias MONO_FIELD_GET_FLAGS
= extern(C
) int function (void* type
) nothrow @nogc;
223 alias MONO_METHOD_GET_NAME
= extern(C
) char* function (void* method
) nothrow @nogc;
224 alias MONO_COMPILE_METHOD
= extern(C
) void* function (void* method
) nothrow @nogc;
225 alias MONO_FREE_METHOD
= extern(C
) void function (void* method
) nothrow @nogc;
227 alias MONO_JIT_INFO_TABLE_FIND
= extern(C
) void* function (void* domain
, void* addr
) nothrow @nogc;
229 alias MONO_JIT_INFO_GET_METHOD
= extern(C
) void* function (void* jitinfo
) nothrow @nogc;
230 alias MONO_JIT_INFO_GET_CODE_START
= extern(C
) void* function (void* jitinfo
) nothrow @nogc;
231 alias MONO_JIT_INFO_GET_CODE_SIZE
= extern(C
) int function (void* jitinfo
) nothrow @nogc;
233 alias MONO_METHOD_GET_HEADER
= extern(C
) void* function (void* method
) nothrow @nogc;
234 alias MONO_METHOD_GET_CLASS
= extern(C
) void* function (void* method
) nothrow @nogc;
235 alias MONO_METHOD_SIG
= extern(C
) void* function (void* method
) nothrow @nogc;
236 alias MONO_METHOD_GET_PARAM_NAMES
= extern(C
) void* function (void* method
, const(char)** names
) nothrow @nogc;
238 alias MONO_METHOD_HEADER_GET_CODE
= extern(C
) void* function (void* methodheader
, UINT32
*code_size
, UINT32
*max_stack
) nothrow @nogc;
239 alias MONO_DISASM_CODE
= extern(C
) char* function (void* dishelper
, void* method
, void* ip
, void* end
) nothrow @nogc;
241 alias MONO_SIGNATURE_GET_DESC
= extern(C
) char* function (void* signature
, int include_namespace
) nothrow @nogc;
242 alias MONO_SIGNATURE_GET_PARAM_COUNT
= extern(C
) int function (void* signature
) nothrow @nogc;
243 alias MONO_SIGNATURE_GET_RETURN_TYPE
= extern(C
) void* function (void* signature
) nothrow @nogc;
245 alias MONO_IMAGE_RVA_MAP
= extern(C
) void* function (void* image
, UINT32 addr
) nothrow @nogc;
246 alias MONO_VTABLE_GET_STATIC_FIELD_DATA
= extern(C
) void* function (void* vtable
) nothrow @nogc;
248 alias MONO_METHOD_DESC_NEW
= extern(C
) void* function (const(char)* name
, int include_namespace
) nothrow @nogc;
249 alias MONO_METHOD_DESC_FROM_METHOD
= extern(C
) void* function (void* method
) nothrow @nogc;
250 alias MONO_METHOD_DESC_FREE
= extern(C
) void function (void* desc
) nothrow @nogc;
252 alias MONO_ASSEMBLY_NAME_NEW
= extern(C
) void* function (const(char)* name
) nothrow @nogc;
253 alias MONO_ASSEMBLY_LOADED
= extern(C
) void* function (void* aname
) nothrow @nogc;
254 alias MONO_IMAGE_LOADED
= extern(C
) void* function (void* aname
) nothrow @nogc;
256 alias MONO_STRING_NEW
= extern(C
) void* function (void* domain
, const(char)* text
) nothrow @nogc;
257 alias MONO_STRING_TO_UTF8
= extern(C
) char* function (void*) nothrow @nogc;
258 alias MONO_ARRAY_NEW
= extern(C
) void* function (void* domain
, void* eclass
, uintptr_t n
) nothrow @nogc;
259 alias MONO_OBJECT_TO_STRING
= extern(C
) void* function (void* object
, void* *exc
) nothrow @nogc;
260 alias MONO_FREE
= extern(C
) void function (void*) nothrow @nogc;
262 alias MONO_METHOD_DESC_SEARCH_IN_IMAGE
= extern(C
) void* function (void* desc
, void* image
) nothrow @nogc;
263 alias MONO_RUNTIME_INVOKE
= extern(C
) void* function (void* method
, void* obj
, void* *params
, void* *exc
) nothrow @nogc;
264 alias MONO_RUNTIME_INVOKE_ARRAY
= extern(C
) void* function (void* method
, void* obj
, void* params
, void* *exc
) nothrow @nogc;
265 alias MONO_VALUE_BOX
= extern(C
) void* function (void* domain
, void* klass
, void* val
) nothrow @nogc;
266 alias MONO_OBJECT_UNBOX
= extern(C
) void* function (void* obj
) nothrow @nogc;
267 alias MONO_CLASS_GET_TYPE
= extern(C
) void* function (void* klass
) nothrow @nogc;
270 // ////////////////////////////////////////////////////////////////////////// //
274 __gshared
void* hmono
;
275 __gshared
void* mono_selfthread
;
277 @MonoAPI G_FREE g_free
;
278 @MonoAPI __gshared MONO_GET_ROOT_DOMAIN mono_get_root_domain
;
279 @MonoAPI __gshared MONO_THREAD_ATTACH mono_thread_attach
;
280 @MonoAPI __gshared MONO_THREAD_DETACH mono_thread_detach
;
281 @MonoAPI __gshared MONO_OBJECT_GET_CLASS mono_object_get_class
;
282 @MonoAPI __gshared MONO_CLASS_GET_NAME mono_class_get_name
;
283 @MonoAPI __gshared MONO_CLASS_GET_NAMESPACE mono_class_get_namespace
;
284 @MonoAPI __gshared MONO_CLASS_GET_PARENT mono_class_get_parent
;
285 @MonoAPI __gshared MONO_CLASS_VTABLE mono_class_vtable
;
286 @MonoAPI __gshared MONO_CLASS_FROM_MONO_TYPE mono_class_from_mono_type
;
288 @MonoAPI __gshared MONO_DOMAIN_FOREACH mono_domain_foreach
;
289 @MonoAPI __gshared MONO_DOMAIN_SET mono_domain_set
;
290 @MonoAPI __gshared MONO_ASSEMBLY_FOREACH mono_assembly_foreach
;
291 @MonoAPI __gshared MONO_ASSEMBLY_GET_IMAGE mono_assembly_get_image
;
292 @MonoAPI __gshared MONO_IMAGE_GET_ASSEMBLY mono_image_get_assembly
;
293 @MonoAPI __gshared MONO_ASSEMBLY_OPEN mono_assembly_open
;
295 @MonoAPI __gshared MONO_IMAGE_GET_NAME mono_image_get_name
;
296 @MonoAPI __gshared MONO_IMAGE_GET_TABLE_INFO mono_image_get_table_info
;
297 @MonoAPI __gshared MONO_IMAGE_RVA_MAP mono_image_rva_map
;
298 @MonoAPI __gshared MONO_IMAGE_OPEN mono_image_open
;
299 @MonoAPI __gshared MONO_IMAGE_LOADED mono_image_loaded
;
301 @MonoAPI __gshared MONO_TABLE_INFO_GET_ROWS mono_table_info_get_rows
;
302 @MonoAPI __gshared MONO_METADATA_DECODE_ROW_COL mono_metadata_decode_row_col
;
303 @MonoAPI __gshared MONO_METADATA_STRING_HEAP mono_metadata_string_heap
;
304 @MonoAPI __gshared MONO_CLASS_GET mono_class_get
;
305 @MonoAPI __gshared MONO_CLASS_FROM_NAME_CASE mono_class_from_name_case
;
307 @MonoAPI __gshared MONO_CLASS_NUM_FIELDS mono_class_num_fields
;
308 @MonoAPI __gshared MONO_CLASS_GET_FIELDS mono_class_get_fields
;
310 @MonoAPI __gshared MONO_CLASS_NUM_METHODS mono_class_num_methods
;
311 @MonoAPI __gshared MONO_CLASS_GET_METHODS mono_class_get_methods
;
313 @MonoAPI __gshared MONO_CLASS_GET_METHOD_FROM_NAME mono_class_get_method_from_name
;
314 @MonoAPI __gshared MONO_CLASS_GET_ELEMENT_CLASS mono_class_get_element_class
;
317 @MonoAPI __gshared MONO_FIELD_GET_NAME mono_field_get_name
;
318 @MonoAPI __gshared MONO_FIELD_GET_TYPE mono_field_get_type
;
319 @MonoAPI __gshared MONO_FIELD_GET_PARENT mono_field_get_parent
;
320 @MonoAPI __gshared MONO_FIELD_GET_OFFSET mono_field_get_offset
;
322 @MonoAPI __gshared MONO_TYPE_GET_NAME mono_type_get_name
;
323 @MonoAPI __gshared MONO_TYPE_GET_TYPE mono_type_get_type
;
324 @MonoAPI __gshared MONO_TYPE_GET_NAME_FULL mono_type_get_name_full
;
325 @MonoAPI __gshared MONO_FIELD_GET_FLAGS mono_field_get_flags
;
327 @MonoAPI __gshared MONO_METHOD_GET_NAME mono_method_get_name
;
328 @MonoAPI __gshared MONO_METHOD_GET_HEADER mono_method_get_header
;
329 @MonoAPI __gshared MONO_METHOD_GET_CLASS mono_method_get_class
;
330 @MonoAPI __gshared MONO_METHOD_SIG mono_method_signature
;
331 @MonoAPI __gshared MONO_METHOD_GET_PARAM_NAMES mono_method_get_param_names
;
333 @MonoAPI __gshared MONO_SIGNATURE_GET_DESC mono_signature_get_desc
;
334 @MonoAPI __gshared MONO_SIGNATURE_GET_PARAM_COUNT mono_signature_get_param_count
;
335 @MonoAPI __gshared MONO_SIGNATURE_GET_RETURN_TYPE mono_signature_get_return_type
;
338 @MonoAPI __gshared MONO_COMPILE_METHOD mono_compile_method
;
339 @MonoAPI __gshared MONO_FREE_METHOD mono_free_method
;
341 @MonoAPI __gshared MONO_JIT_INFO_TABLE_FIND mono_jit_info_table_find
;
342 @MonoAPI __gshared MONO_JIT_INFO_GET_METHOD mono_jit_info_get_method
;
343 @MonoAPI __gshared MONO_JIT_INFO_GET_CODE_START mono_jit_info_get_code_start
;
344 @MonoAPI __gshared MONO_JIT_INFO_GET_CODE_SIZE mono_jit_info_get_code_size
;
346 @MonoAPI __gshared MONO_METHOD_HEADER_GET_CODE mono_method_header_get_code
;
347 @MonoAPI __gshared MONO_DISASM_CODE mono_disasm_code
;
349 @MonoAPI __gshared MONO_VTABLE_GET_STATIC_FIELD_DATA mono_vtable_get_static_field_data
;
351 @MonoAPI __gshared MONO_METHOD_DESC_NEW mono_method_desc_new
;
352 @MonoAPI __gshared MONO_METHOD_DESC_FROM_METHOD mono_method_desc_from_method
;
353 @MonoAPI __gshared MONO_METHOD_DESC_FREE mono_method_desc_free
;
354 @MonoAPI @Optional __gshared MONO_ASSEMBLY_NAME_NEW mono_assembly_name_new
;
355 @MonoAPI __gshared MONO_ASSEMBLY_LOADED mono_assembly_loaded
;
357 @MonoAPI __gshared MONO_STRING_NEW mono_string_new
;
358 @MonoAPI __gshared MONO_STRING_TO_UTF8 mono_string_to_utf8
;
359 @MonoAPI __gshared MONO_ARRAY_NEW mono_array_new
;
360 @MonoAPI @Optional __gshared MONO_OBJECT_TO_STRING mono_object_to_string
;
361 @MonoAPI @Optional __gshared MONO_FREE mono_free
; //???
362 @MonoAPI __gshared MONO_VALUE_BOX mono_value_box
;
363 @MonoAPI __gshared MONO_OBJECT_UNBOX mono_object_unbox
;
364 @MonoAPI __gshared MONO_CLASS_GET_TYPE mono_class_get_type
;
366 @MonoAPI __gshared MONO_METHOD_DESC_SEARCH_IN_IMAGE mono_method_desc_search_in_image
;
367 @MonoAPI __gshared MONO_RUNTIME_INVOKE mono_runtime_invoke
;
369 __gshared
int attached
= 0;
372 // ////////////////////////////////////////////////////////////////////////// //
373 __gshared
void* k32h
;
374 extern(Windows
) __gshared
void* function (const(char)* name
) nothrow @nogc LoadLibA
;
375 extern(Windows
) __gshared
void* function (void* hmod
, const(char)* name
) nothrow @nogc GetProcAddr
;
378 string
getKernelDllName () {
379 import core
.sys
.posix
.unistd
: getpid
;
380 import core
.stdc
.stdio
: FILE
, fopen
, fclose
, snprintf
, fgets
;
381 import core
.stdc
.string
: strstr
;
386 int pid
= cast(int)getpid();
387 snprintf(filename
.ptr
, filename
.length
, "/proc/%d/maps", pid
);
388 fp
= fopen(filename
.ptr
, "r");
389 if (fp
is null) return null;
390 while (fgets(line
.ptr
, 850, fp
) !is null) {
391 import std
.string
: fromStringz
;
392 auto ln
= line
.ptr
.fromStringz
;
393 while (ln
.length
&& ln
[$-1] <= ' ') ln
= ln
[0..$-1];
394 if (ln
.length
== 0 || ln
.ptr
[0] <= ' ') continue;
396 foreach (immutable _
; 0..5) {
397 while (ln
.length
> 0 && ln
.ptr
[0] > ' ') ln
= ln
[1..$];
398 while (ln
.length
> 0 && ln
.ptr
[0] <= ' ') ln
= ln
[1..$];
400 if (ln
.length
== 0) continue;
402 int pos
= cast(int)ln
.length
;
403 while (pos
> 0 && ln
.ptr
[pos
-1] != '/') --pos
;
405 if (ln
== "kernel32.dll.so") {
406 // add zero (it is safe, we always has room for it)
407 savedln
.ptr
[savedln
.length
] = 0;
408 auto dp
= new char[](savedln
.length
+1);
409 dp
[] = savedln
.ptr
[0..savedln
.length
+1];
410 return cast(string
)(dp
[0..$-1]); // zero is there, but not included in length
418 // ////////////////////////////////////////////////////////////////////////// //
419 public void loadWineAPI () {
420 import core
.stdc
.stdio
: stderr
, fprintf
;
422 auto k32name
= getKernelDllName();
423 if (k32name
.length
== 0) { fprintf(stderr
, "MSG: not a WINE process!\n"); return; }
424 fprintf(stderr
, "MSG: kernel: [%s]\n", k32name
.ptr
);
426 k32h
= __libc_dlopen_mode(k32name
.ptr
, 1); // lazy
427 if (k32h
is null) { fprintf(stderr
, "MSG: FUCK0 (no kernel32.dll)\n"); return; }
429 *cast(void**)&LoadLibA
= __libc_dlsym(k32h
, "LoadLibraryA");
430 if (LoadLibA
is null) { fprintf(stderr
, "MSG: FUCK1 (no LoadLibraryA)\n"); k32h
= null; return; }
432 *cast(void**)&GetProcAddr
= __libc_dlsym(k32h
, "GetProcAddress");
433 if (GetProcAddr
is null) { fprintf(stderr
, "MSG: FUCK2 (no GetProcAddress)\n"); k32h
= null; return; }
435 fprintf(stderr
, "MSG: WINE API loaded\n");
438 public @property bool isWineAPILoaded () nothrow @trusted @nogc { return (k32h
!is null); }
441 // ////////////////////////////////////////////////////////////////////////// //
442 public void loadMonoAPI () {
443 import core
.stdc
.stdio
: stderr
, fprintf
;
446 if (!isWineAPILoaded
) {
447 fprintf(stderr
, "MSG: no WINE API was found\n");
452 if (attached
!= 0) return;
454 hmono
= LoadLibA("mono.dll");
456 fprintf(stderr
, "MSG: no mono API was found\n");
462 foreach (string memname
; __traits(allMembers
, mixin(__MODULE__
))) {
463 static if (is(typeof(__traits(getMember
, mixin(__MODULE__
), memname
)))) {
464 alias mem
= Identity
!(__traits(getMember
, mixin(__MODULE__
), memname
));
465 static if (is(typeof(&mem
)) && hasUDA
!(mem
, MonoAPI
)) {
466 //pragma(msg, memname);
467 mixin("*cast(void**)&"~memname
~" = GetProcAddr(hmono, "~memname
.stringof
~");");
468 static if (hasUDA
!(mem
, Optional
)) {
469 mixin("if ("~memname
~` is null) { import core.stdc.stdio : stderr, fprintf; fprintf(stderr, "MSG: mono API '%s' not found!\n", `~memname
.stringof
~".ptr); }");
471 mixin("if ("~memname
~` is null) { import core.stdc.stdio : stderr, fprintf; fprintf(stderr, "MSG: mono API '%s' not found (FATAL)!\n", `~memname
.stringof
~".ptr); }");
472 mixin("if ("~memname
~" is null) attached = -1;");
477 if (attached
== 1) mono_selfthread
= mono_thread_attach(mono_get_root_domain());
480 public @property bool isMonoAPILoaded () nothrow @trusted @nogc { return (attached
== 1); }
483 // ////////////////////////////////////////////////////////////////////////// //
484 public string
getAssemblyNameEP (uint asmid
) {
485 auto image
= mono_assembly_get_image(cast(void*)asmid
);
486 if (image
is null) return "<none>";
487 auto imgname
= mono_image_get_name(image
);
488 if (imgname
is null) return "<none>";
489 scope(exit
) g_free(imgname
);
490 return imgname
.fromStringz
.idup
;
494 // ////////////////////////////////////////////////////////////////////////// //
495 extern(C
) void assemblyEnumerator (void* assembly
, void* userptr
) nothrow {
496 auto image
= mono_assembly_get_image(assembly
);
497 if (image
is null) return;
498 auto imgname
= mono_image_get_name(image
);
499 if (imgname
is null) return;
500 scope(exit
) g_free(imgname
);
501 AssemblyInfo
[]* arr
= cast(AssemblyInfo
[]*)userptr
;
503 (*arr
) ~= AssemblyInfo(cast(uint)assembly
, imgname
.fromStringz
.idup
);
504 } catch (Exception
) {}
507 public AssemblyInfo
[] enumAssembliesEP () {
509 mono_assembly_foreach(cast(GFunc
)&assemblyEnumerator
, &arr
);
514 // ////////////////////////////////////////////////////////////////////////// //
515 void collectAssemblyClasses (uint asmid
, ref NCClassInfo
[] clist
) {
516 auto image
= mono_assembly_get_image(cast(void*)asmid
);
517 if (image
is null) return;
518 //auto imgname = mono_image_get_name(image);
519 //if (imgname is null) return;
520 //scope(exit) g_free(imgname);
521 //auto imgnamestr = imgname.fromStringz.idup;
522 auto tdef
= mono_image_get_table_info(image
, MONO_TABLE_TYPEDEF
);
523 if (tdef
is null) return;
524 auto tdefcount
= mono_table_info_get_rows(tdef
);
525 foreach (immutable int i
; 0..tdefcount
) {
526 auto c
= mono_class_get(image
, MONO_TOKEN_TYPE_DEF|i
+1);
527 auto name
= mono_class_get_name(c
);
528 if (name
is null) continue;
529 scope(exit
) g_free(name
);
530 auto nspace
= mono_class_get_namespace(c
);
531 scope(exit
) if (nspace
!is null) g_free(nspace
);
532 clist
~= NCClassInfo(cast(uint)c
, asmid
, name
.fromStringz
.idup
, nspace
.fromStringz
.idup
);
536 extern(C
) void assemblyEnumeratorForClassList (void* assembly
, void* userptr
) nothrow {
537 auto image
= mono_assembly_get_image(assembly
);
538 if (image
is null) return;
539 NCClassInfo
[]* arr
= cast(NCClassInfo
[]*)userptr
;
541 collectAssemblyClasses(cast(uint)assembly
, *arr
);
542 } catch (Exception
) {}
545 public NCClassInfo
[] getClassListEP (uint asmid
=0) {
548 mono_assembly_foreach(cast(GFunc
)&assemblyEnumeratorForClassList
, &arr
);
550 collectAssemblyClasses(asmid
, arr
);
556 // ////////////////////////////////////////////////////////////////////////// //
557 public FieldInfo
[] getClassFieldsEP (uint clsid
) {
558 void* c
= cast(void*)clsid
;
559 auto cname
= mono_class_get_name(c
);
560 if (cname
is null) return null;
561 scope(exit
) g_free(cname
);
565 auto field
= mono_class_get_fields(c
, &iter
);
566 if (field
is null) break;
567 auto fieldtype
= mono_field_get_type(field
);
568 auto name
= mono_field_get_name(field
);
569 if (name
is null) continue;
570 scope(exit
) g_free(name
);
571 auto tname
= mono_type_get_name(fieldtype
);
572 if (tname
is null) continue;
573 scope(exit
) g_free(tname
);
575 fi
.type
= mono_type_get_type(fieldtype
);
576 fi
.ofs
= mono_field_get_offset(field
);
577 fi
.flags
= mono_field_get_flags(field
);
578 fi
.name
= name
.fromStringz
.idup
;
579 fi
.typename
= tname
.fromStringz
.idup
;
581 WriteQword((UINT_PTR)mono_field_get_parent(field));
582 WriteDword(mono_field_get_flags(field));