working verifier

This commit is contained in:
Chris Forbes
2010-03-19 22:40:33 +13:00
parent 85d62ee260
commit b68e14655f
2 changed files with 23 additions and 4 deletions

View File

@@ -29,11 +29,26 @@ namespace OpenRA.FileFormats
public static class Verifier public static class Verifier
{ {
static readonly string[] AllowedPatterns = { static readonly string[] AllowedPatterns = {
/* todo */ "System.Collections.Generic.*",
}; "System.Linq.*",
"OpenRA.*",
"System.Collections.*",
"System.Func*",
"System.String:*",
"System.IDisposable:*",
"System.Action*",
"System.Object:*",
"System.Math:*",
"System.Predicate*",
"System.NotSupportedException:.ctor",
"System.Threading.Thread:get_CurrentThread",
"System.Threading.Thread:get_ManagedThreadId",
};
public static bool IsSafe(string filename, List<string> failures) public static bool IsSafe(string filename, List<string> failures)
{ {
Log.Write("Start verification: {0}", filename);
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (s, a) => Assembly.ReflectionOnlyLoad(a.Name); AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (s, a) => Assembly.ReflectionOnlyLoad(a.Name);
var flags = BindingFlags.Instance | BindingFlags.Static | var flags = BindingFlags.Instance | BindingFlags.Static |
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly; BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
@@ -53,13 +68,13 @@ namespace OpenRA.FileFormats
.SelectMany(x => x.GetMembers(flags)) .SelectMany(x => x.GetMembers(flags))
.SelectMany(x => FunctionsUsedBy(x)) .SelectMany(x => FunctionsUsedBy(x))
.Where(x => x.DeclaringType.Assembly != assembly) .Where(x => x.DeclaringType.Assembly != assembly)
.Select(x => string.Format("{0}:{1}", x.DeclaringType.FullName, x)) .Select(x => string.Format("{0}:{1}", x.DeclaringType.FullName, x.Name))
.OrderBy(x => x) .OrderBy(x => x)
.Distinct()) .Distinct())
if (!IsAllowed(fn)) if (!IsAllowed(fn))
failures.Add("Unsafe function: {0}".F(fn)); failures.Add("Unsafe function: {0}".F(fn));
return failures.Count > 0; return failures.Count == 0;
} }
static bool IsAllowed(string fn) static bool IsAllowed(string fn)
@@ -74,6 +89,8 @@ namespace OpenRA.FileFormats
if (fn == p) return true; if (fn == p) return true;
} }
Log.Write(fn);
return false; return false;
} }

View File

@@ -87,6 +87,8 @@ namespace OpenRA
Log.Write("Assembly `{0}` cannot be verified. Failures:", a); Log.Write("Assembly `{0}` cannot be verified. Failures:", a);
foreach (var f in failures) foreach (var f in failures)
Log.Write("\t{0}", f); Log.Write("\t{0}", f);
throw new InvalidOperationException("Failed verification. See the log for further details.");
} }
} }