static void Run(AssemblyHolder holder, string[] cmdLine) { try { EvaluationStack stack = new EvaluationStack(); stack.Push(new ObjectReferenceValue(cmdLine)); ParameterValues paramVals = stack.Perform_CallMethod(holder.Assembly.EntryPoint,false); Exception exc; IntVisitor.InterpretMethod(holder,holder.EntryPoint,paramVals,out exc,""); if (exc != null) { Console.WriteLine( "-------------------------\n"+ "CIL interpreter catched unhandled exception:\n"+ exc ); } Console.WriteLine("-------------------------\nPress Enter..."); Console.ReadLine(); } catch (ConvertionException) { Console.WriteLine("Conversion to CFG failed !"); } }
public AnnotatedAssemblyHolder(AssemblyHolder sourceHolder, WhiteList whiteList) : base(sourceHolder) { this.aMethods = new Hashtable(); this.GraphProcessor = new GraphProcessor(); this.WhiteList = whiteList; foreach (MethodBase method in this.SourceHolder.getMethods()) if (method.IsDefined(typeof(SpecializeAttribute), false)) ControllingVisitor.AddAnnotatedMethodUser(this.AnnotateMethod(this.GetAnnotatedMethod(method))); this.GraphProcessor.Process(); }
static void Main(string[] args) { Console.WriteLine("Prototype CIL interpreter\n-------------------------"); if (args.Length == 0) { Console.WriteLine("usage: TestInt <assembly name> <command line>"); } else { try { Assembly assembly = Assembly.LoadFrom(args[0]); AssemblyHolder holder = new AssemblyHolder(assembly); if (holder.EntryPoint == null) Console.WriteLine("Assembly \""+args[0]+"\" has no entry point !"); else { try { string[] cmdLine = new string[args.Length-1]; for (int i = 1; i < args.Length; i++) cmdLine[i-1] = args[i]; Run(holder,cmdLine); } catch (FileNotFoundException e) { Console.WriteLine("Assembly module "+e.FileName+"was not found !"); } } } catch (FileNotFoundException) { Console.WriteLine("File \""+args[0]+"\" was not found !"); } catch (BadImageFormatException) { Console.WriteLine("File \""+args[0]+"\" has invalid format !"); } catch (SecurityException) { Console.WriteLine("Security error while opening file \""+args[0]+"\" !"); } catch (FileLoadException) { Console.WriteLine("File \""+args[0]+"\" was found but cannot be loaded !"); } } }
protected ModifiedAssemblyHolder(AssemblyHolder sourceHolder) { this.sourceHolder = sourceHolder; }
static void Evaluate() { WhiteList whiteList = new WhiteList(); whiteList.AddFromXml("wlist.xml"); if (showProgress) Console.WriteLine("White list reading - OK"); Assembly assembly = Assembly.LoadFrom(sourceAssemblyName); AssemblyHolder srcHolder = new AssemblyHolder(assembly); if (showProgress) Console.WriteLine("Source assembly reading - OK"); if (showSourceCFG) { Console.WriteLine("\nSource CFG:\n----------\n"); Console.Write(srcHolder); } markTime(); AnnotatedAssemblyHolder btaHolder = new AnnotatedAssemblyHolder(srcHolder, whiteList); btaTime = getSpan(); if (showProgress) Console.WriteLine("Assembly annotation - OK"); if (showAnnotatedCFG) { Console.WriteLine("\nAnnotated CFG:\n-------------\n"); Console.Write(btaHolder.ToString("CSharp",ReflectionFormatter.formatter,new string[] { Annotation.BTTypeOption, Annotation.MethodBTTypeOption })); } markTime(); ResidualAssemblyHolder resHolder = new ResidualAssemblyHolder(btaHolder); specTime = getSpan(); if (showProgress) Console.WriteLine("Assembly specialization - OK"); if (showResidualCFG) { Console.WriteLine("\nResidual CFG:\n-------------\n"); Console.Write(resHolder.ToString("CSharp",ReflectionFormatter.formatter)); } if (enablePostprocessing) { markTime(); resHolder.Optimize(); pprocTime = getSpan(); if (showProgress) Console.WriteLine("Assembly postprocessing - OK"); if (showPostprocessedCFG) { Console.WriteLine("\nPostprocessed CFG:\n-----------------\n"); Console.Write(resHolder.ToString("CSharp",ReflectionFormatter.formatter)); } } Exporter.Export(resHolder, targetAssemblyName); if (showProgress) Console.WriteLine("Assembly export - OK"); if (enableClock) { Console.WriteLine("Timings:"); Console.WriteLine(" BTA - " + btaTime); Console.WriteLine(" Specializer - " + specTime); if (enablePostprocessing) Console.WriteLine(" Postprocessing - " + pprocTime); } }