static void process_image (MonoImage *image, gboolean all) { int i; const MonoTableInfo *t; MonoClass *klass; MonoMethod *entry; guint32 eptoken; if (verbose) g_print ("#processing image: %s\n", mono_image_get_name (image)); eptoken = mono_image_get_entry_point (image); if (eptoken) { entry = mono_get_method (image, eptoken, NULL); add_types_from_method (entry); } /* we always add the <Module> type */ klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | 1); handle_type (klass, all? TYPE_ALL: TYPE_BASIC); if (all) { t = mono_image_get_table_info (image, MONO_TABLE_TYPEDEF); for (i = 1; i < mono_table_info_get_rows (t); ++i) { klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | (i + 1)); handle_type (klass, all? TYPE_ALL: TYPE_BASIC); } } }
void CPipeServer::EnumClassesInImage() { int i; void *image=(void *)ReadQword(); void *tdef=mono_image_get_table_info (image, MONO_TABLE_TYPEDEF); int tdefcount=mono_table_info_get_rows(tdef); WriteDword(tdefcount); for (i = 0; i < tdefcount; i++) { void *c = mono_class_get(image, MONO_TOKEN_TYPE_DEF | i+1); char *name=mono_class_get_name(c); WriteQword((UINT_PTR)c); WriteWord(strlen(name)); Write(name, strlen(name)); name=mono_class_get_namespace(c); WriteWord(strlen(name)); Write(name, strlen(name)); } }
GDMonoClass *GDMonoAssembly::get_object_derived_class(const StringName &p_class) { GDMonoClass *match = NULL; if (gdobject_class_cache_updated) { Map<StringName, GDMonoClass *>::Element *result = gdobject_class_cache.find(p_class); if (result) match = result->get(); } else { List<GDMonoClass *> nested_classes; int rows = mono_image_get_table_rows(image, MONO_TABLE_TYPEDEF); for (int i = 1; i < rows; i++) { MonoClass *mono_class = mono_class_get(image, (i + 1) | MONO_TOKEN_TYPE_DEF); if (!mono_class_is_assignable_from(CACHED_CLASS_RAW(GodotObject), mono_class)) continue; GDMonoClass *current = get_class(mono_class); if (!current) continue; nested_classes.push_back(current); if (!match && current->get_name() == p_class) match = current; while (!nested_classes.empty()) { GDMonoClass *current_nested = nested_classes.front()->get(); nested_classes.pop_back(); void *iter = NULL; while (true) { MonoClass *raw_nested = mono_class_get_nested_types(current_nested->get_raw(), &iter); if (!raw_nested) break; GDMonoClass *nested_class = get_class(raw_nested); if (nested_class) { gdobject_class_cache.insert(nested_class->get_name(), nested_class); nested_classes.push_back(nested_class); } } } gdobject_class_cache.insert(current->get_name(), current); } gdobject_class_cache_updated = true; } return match; }
/** * mono_exception_from_token_two_strings: * * Same as mono_exception_from_name_two_strings, but lookup the exception class using * IMAGE and TOKEN. */ MonoException * mono_exception_from_token_two_strings (MonoImage *image, guint32 token, MonoString *a1, MonoString *a2) { MonoClass *klass = mono_class_get (image, token); return create_exception_two_strings (klass, a1, a2); }
const Vector<MonoClass*>& MonoAssembly::getAllClasses() const { if(mHaveCachedClassList) return mCachedClassList; mCachedClassList.clear(); Stack<MonoClass*> todo; int numRows = mono_image_get_table_rows (mMonoImage, MONO_TABLE_TYPEDEF); for(int i = 1; i < numRows; i++) // Skip Module { ::MonoClass* monoClass = mono_class_get (mMonoImage, (i + 1) | MONO_TOKEN_TYPE_DEF); String ns; String type; MonoUtil::getClassName(monoClass, ns, type); MonoClass* curClass = getClass(ns, type); if (curClass != nullptr) { // Get nested types if it has any todo.push(curClass); while (!todo.empty()) { MonoClass* curNestedClass = todo.top(); todo.pop(); void* iter = nullptr; do { ::MonoClass* rawNestedClass = rawNestedClass = mono_class_get_nested_types(curNestedClass->_getInternalClass(), &iter); if (rawNestedClass == nullptr) break; String nestedType = curNestedClass->getTypeName() + "+" + mono_class_get_name(rawNestedClass); MonoClass* nestedClass = getClass(ns, nestedType, rawNestedClass); if (nestedClass != nullptr) { mCachedClassList.push_back(nestedClass); todo.push(nestedClass); } } while (true); } mCachedClassList.push_back(curClass); } } mHaveCachedClassList = true; return mCachedClassList; }
/** * mono_exception_from_token: * @image: the Mono image where to look for the class * @token: The type token of the class * * Creates an exception of the type given by @token. * * Returns: the initialized exception instance. */ MonoException * mono_exception_from_token (MonoImage *image, guint32 token) { MonoClass *klass; MonoObject *o; klass = mono_class_get (image, token); o = mono_object_new (mono_domain_get (), klass); g_assert (o != NULL); mono_runtime_object_init (o); return (MonoException *)o; }
gboolean ml_is_api_dll(MonoImage *image) { MonoClass *klass; int i, total; total = mono_image_get_table_rows (image, MONO_TABLE_TYPEDEF); for (i = 1; i <= total; ++i) { klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | i); if (strcmp(mono_class_get_name(klass), "Debug") == 0) if (strcmp(mono_class_get_namespace(klass), "Purple") == 0) { ml_set_api_image(image); return TRUE; } } return FALSE; }
MonoClass* ml_find_plugin_class(MonoImage *image) { MonoClass *klass, *pklass = NULL; int i, total; total = mono_image_get_table_rows (image, MONO_TABLE_TYPEDEF); for (i = 1; i <= total; ++i) { klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | i); pklass = mono_class_get_parent(klass); if (pklass) { if (strcmp("Plugin", mono_class_get_name(pklass)) == 0) return klass; } } return NULL; }
static void add_types_from_method (MonoMethod *method) { const MonoOpcode *opcode; MonoMethodHeader *header; const unsigned char *ip, *il_code_end; gpointer val = NULL, oldkey = NULL; int i, n; guint32 token; MonoClass *klass; MonoClassField *field; MonoCustomAttrInfo* cattrs; MonoType** locals; gpointer exc_iter; MonoExceptionClause clause; if (g_hash_table_lookup_extended (method_table, method, &oldkey, &val)) return; g_hash_table_insert (method_table, method, NULL); g_assert (method->klass); if (verbose > 1) g_print ("#processing method: %s\n", mono_method_full_name (method, TRUE)); mono_class_init (method->klass); cattrs = mono_custom_attrs_from_method (method); handle_cattrs (cattrs); add_type (method->klass); add_types_from_signature (mono_method_signature (method)); for (i = 0; i < mono_method_signature (method)->param_count + 1; ++i) { cattrs = mono_custom_attrs_from_param (method, i); handle_cattrs (cattrs); } if (method->flags & METHOD_ATTRIBUTE_VIRTUAL) virtual_methods = g_list_prepend (virtual_methods, method); /* if no IL code to parse, return */ if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME)) return; if (method->flags & (METHOD_ATTRIBUTE_PINVOKE_IMPL | METHOD_ATTRIBUTE_ABSTRACT)) return; header = mono_method_get_header (method); locals = mono_method_header_get_locals (header, &n, NULL); for (i = 0; i < n; ++i) { klass = mono_class_from_mono_type (locals [i]); add_type (klass); } for (exc_iter = NULL; mono_method_header_get_clauses (header, method, &exc_iter, &clause);) { if (clause.flags == MONO_EXCEPTION_CLAUSE_NONE) add_type (clause.data.catch_class); } ip = mono_method_header_get_code (header, &n, NULL); il_code_end = ip + n; while (ip < il_code_end) { if (verbose > 2) g_print ("#%s", mono_disasm_code_one (NULL, method, ip, NULL)); if (*ip == 0xfe) { ++ip; i = *ip + 256; } else { i = *ip; } opcode = &mono_opcodes [i]; switch (opcode->argument) { case MonoInlineNone: ip++; break; case MonoInlineType: token = read32 (ip + 1); add_type (mono_class_get (method->klass->image, token)); ip += 5; break; case MonoInlineField: { token = read32 (ip + 1); field = mono_field_from_token (method->klass->image, token, &klass, NULL); add_field (field); add_type (klass); ip += 5; break; } case MonoInlineTok: case MonoInlineSig: /* FIXME */ case MonoInlineString: case MonoShortInlineR: case MonoInlineBrTarget: case MonoInlineI: ip += 5; break; case MonoInlineVar: ip += 3; break; case MonoShortInlineVar: case MonoShortInlineI: case MonoShortInlineBrTarget: ip += 2; break; case MonoInlineSwitch: ++ip; n = read32 (ip); ip += 4; ip += 4 * n; break; case MonoInlineI8: case MonoInlineR: ip += 9; break; case MonoInlineMethod: { MonoMethod *cm = mono_get_method (method->klass->image, read32 (ip + 1), NULL); add_type (cm->klass); add_types_from_method (cm); } ip += 5; break; default: g_assert_not_reached (); } } }