// Token: 0x06000D5E RID: 3422 RVA: 0x0005B33C File Offset: 0x0005953C private static bool ValidateAssembly(ModInfo.AssemblyInfo info, out ModAssembly mAssembly) { List <Assembly> list = new List <Assembly>(); if (!AssemblyScanner.Scan(info, list)) { mAssembly = null; return(false); } mAssembly = new ModAssembly(info, list); if (info.Mod.Assemblies.Any((ModAssembly a) => a.Info.Path == info.Path)) { MLog.Error("The same assmbly is listed in the manifest more than once!"); mAssembly = null; return(false); } return(true); }
// Token: 0x06000D6C RID: 3436 RVA: 0x0005BEC0 File Offset: 0x0005A0C0 private static bool IsForbidden(MethodReference method) { return(AssemblyScanner.IsForbiddenMethod(method.DeclaringType.Namespace, method.DeclaringType.Name, method.Name)); }
// Token: 0x06000D6A RID: 3434 RVA: 0x0005BB54 File Offset: 0x00059D54 private bool ScanType(TypeDefinition type) { foreach (FieldDefinition fieldDefinition in type.Fields) { if (AssemblyScanner.IsForbidden(fieldDefinition.FieldType)) { this.LogError(fieldDefinition, fieldDefinition.FieldType); return(false); } } foreach (MethodDefinition methodDefinition in type.Methods) { if (methodDefinition.HasPInvokeInfo) { this.LogError("You are not allowed to use PInvoke!"); return(false); } if (methodDefinition.HasBody) { foreach (VariableDefinition variableDefinition in methodDefinition.Body.Variables) { if (AssemblyScanner.IsForbidden(variableDefinition.VariableType)) { this.LogError(methodDefinition, variableDefinition.VariableType); return(false); } } foreach (Instruction instruction in methodDefinition.Body.Instructions) { if (instruction.OpCode == OpCodes.Ldfld) { FieldReference fieldReference = (FieldReference)instruction.Operand; if (AssemblyScanner.IsForbidden(fieldReference.FieldType)) { this.LogError(methodDefinition, fieldReference.FieldType); return(false); } } else if (instruction.OpCode == OpCodes.Call || instruction.OpCode == OpCodes.Callvirt || instruction.OpCode == OpCodes.Calli || instruction.OpCode == OpCodes.Newobj) { MethodReference methodReference = (MethodReference)instruction.Operand; if (AssemblyScanner.IsForbidden(methodReference)) { this.LogError(methodDefinition, methodReference); return(false); } } else if (instruction.OpCode == OpCodes.Newarr) { TypeReference typeReference = (TypeReference)instruction.Operand; if (AssemblyScanner.IsForbidden(typeReference)) { this.LogError(methodDefinition, typeReference); return(false); } } } } } foreach (TypeDefinition type2 in type.NestedTypes) { if (!this.ScanType(type2)) { return(false); } } return(true); }
// Token: 0x06000D6B RID: 3435 RVA: 0x0005BEAC File Offset: 0x0005A0AC private static bool IsForbidden(TypeReference type) { return(AssemblyScanner.IsForbiddenType(type.Namespace, type.Name)); }
// Token: 0x06000D69 RID: 3433 RVA: 0x0005B7EC File Offset: 0x000599EC public static bool Scan(ModInfo.AssemblyInfo info, List <Assembly> additionalRefs) { if (BesiegeLogFilter.logDev) { Console.WriteLine("[AssemblyScanner] Scanning {0}.", new object[] { info.Path }); } bool result; try { AssemblyScanner assemblyScanner = new AssemblyScanner(); assemblyScanner.CurrentlyScanning = info; AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(info.Path); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); if (BesiegeLogFilter.logDev) { string format = "[AssemblyScanner] Got loaded assembly list:\n{0}."; object[] array = new object[1]; array[0] = string.Join("\n", (from a in assemblies select a.FullName + "(" + a.CodeBase + ")").ToArray <string>()); Debug.LogFormat(format, array); } foreach (ModuleDefinition moduleDefinition in assemblyDefinition.Modules) { AssemblyNameReference reference; foreach (AssemblyNameReference reference2 in moduleDefinition.AssemblyReferences) { reference = reference2; if (BesiegeLogFilter.logDev) { Debug.LogFormat("[AssemblyScanner] Checking if reference {0} is loaded.", new object[] { reference.FullName }); } if (assemblies.Any((Assembly a) => a.GetName().Name == reference.Name)) { if (BesiegeLogFilter.logDev) { Debug.LogFormat("[AssemblyScanner] Found matching loaded assembly!", new object[0]); } } else { if (BesiegeLogFilter.logDev) { Debug.LogFormat("[AssemblyScanner] Did not find matching loaded assembly!", new object[0]); } Assembly assembly; try { assembly = Assembly.ReflectionOnlyLoad(reference.FullName); } catch (FileNotFoundException) { string text = Path.Combine(new FileInfo(info.Path).DirectoryName, reference.Name + ".dll"); if (!File.Exists(text)) { continue; } assembly = Assembly.ReflectionOnlyLoadFrom(text); } additionalRefs.Add(assembly); ModInfo.AssemblyInfo info2 = new ModInfo.AssemblyInfo { Path = assembly.Location }; if (!AssemblyScanner.Scan(info2, additionalRefs)) { MLog.Error("Referenced assembly did not validate: " + reference.Name); MLog.Error("Not loading " + assemblyDefinition.Name); return(false); } } } foreach (TypeDefinition type in moduleDefinition.Types) { if (!assemblyScanner.ScanType(type)) { return(false); } } } result = true; } catch (Exception exception) { Debug.LogError("Error scanning assembly, not loading!"); Debug.LogException(exception); result = false; } return(result); }