bool GDMonoField::has_attribute(GDMonoClass *p_attr_class) { ERR_FAIL_NULL_V(p_attr_class, false); if (!attrs_fetched) fetch_attributes(); if (!attributes) return false; return mono_custom_attrs_has_attr(attributes, p_attr_class->get_raw()); }
bool GDMonoClass::has_attribute(GDMonoClass *p_attr_class) { #ifdef DEBUG_ENABLED ERR_FAIL_NULL_V(p_attr_class, false); #endif if (!attrs_fetched) fetch_attributes(); if (!attributes) return false; return mono_custom_attrs_has_attr(attributes, p_attr_class->get_mono_ptr()); }
bool MonoMethod::hasAttribute(MonoClass* monoClass) const { // TODO - Consider caching custom attributes or just initializing them all at load MonoCustomAttrInfo* attrInfo = mono_custom_attrs_from_method(mMethod); if (attrInfo == nullptr) return false; bool hasAttr = mono_custom_attrs_has_attr(attrInfo, monoClass->_getInternalClass()) != 0; mono_custom_attrs_free(attrInfo); return hasAttr; }
/* * Ensure that the restrictions for partially trusted code are satisfied. * * @domain The current application domain * @caller The method calling * @callee The called method * return value: TRUE if a security violation is detected, FALSE otherwise. * * If callee's assembly is strongnamed and doesn't have an * [AllowPartiallyTrustedCallers] attribute then we must enforce a LinkDemand * for FullTrust on all public/protected methods on public class. * * Note: APTC is only effective on stongnamed assemblies. */ static gboolean mono_declsec_linkdemand_aptc (MonoDomain *domain, MonoMethod *caller, MonoMethod *callee) { MonoSecurityManager* secman = NULL; MonoAssembly *assembly; guint32 size = 0; InterlockedIncrement (&mono_jit_stats.cas_linkdemand_aptc); /* A - Applicable only if we're calling into *another* assembly */ if (caller->klass->image == callee->klass->image) return FALSE; /* B - Applicable if we're calling a public/protected method from a public class */ if (!(callee->klass->flags & TYPE_ATTRIBUTE_PUBLIC) || !(callee->flags & FIELD_ATTRIBUTE_PUBLIC)) return FALSE; /* C - Applicable if the callee's assembly is strongnamed */ if ((mono_image_get_public_key (callee->klass->image, &size) == NULL) || (size < MONO_ECMA_KEY_LENGTH)) return FALSE; /* D - the callee's assembly must have [AllowPartiallyTrustedCallers] */ assembly = mono_image_get_assembly (callee->klass->image); if (!MONO_SECMAN_FLAG_INIT (assembly->aptc)) { MonoCustomAttrInfo* cinfo = mono_custom_attrs_from_assembly (assembly); gboolean result = FALSE; secman = mono_security_manager_get_methods (); if (secman && cinfo) { /* look for AllowPartiallyTrustedCallersAttribute */ result = mono_custom_attrs_has_attr (cinfo, secman->allowpartiallytrustedcallers); } if (cinfo) mono_custom_attrs_free (cinfo); MONO_SECMAN_FLAG_SET_VALUE (assembly->aptc, result); } if (MONO_SECMAN_FLAG_GET_VALUE (assembly->aptc)) return FALSE; /* E - the caller's assembly must have full trust permissions */ assembly = mono_image_get_assembly (caller->klass->image); if (mono_declsec_is_assembly_fulltrust (domain, assembly)) return FALSE; /* g_warning ("FAILURE *** JIT LinkDemand APTC check *** %s.%s calls into %s.%s", caller->klass->name, caller->name, callee->klass->name, callee->name); */ return TRUE; /* i.e. throw new SecurityException(); */ }
bool MonoField::hasAttribute(MonoClass* monoClass) { // TODO - Consider caching custom attributes or just initializing them all at load ::MonoClass* parentClass = mono_field_get_parent(mField); MonoCustomAttrInfo* attrInfo = mono_custom_attrs_from_field(parentClass, mField); if(attrInfo == nullptr) return false; bool hasAttr = mono_custom_attrs_has_attr(attrInfo, monoClass->_getInternalClass()) != 0; mono_custom_attrs_free(attrInfo); return hasAttr; }