/// <summary> /// Adds new method to IL code stream and metadata. /// </summary> /// <param name="method">Interface describing method.</param> public void AddMethod(IMethod method) { uint RVA = (uint)dIL.Count + 4; MethodDefinition targtMet, emittedMehtod; targtMet = Manager.MetadataManager.FindMethod(Manager.ResourceManager.NewAssembly, Manager.ResourceManager.NewAssemblyName, method); if (targtMet == null) { throw new TranslatingException("Method " + method.ToString() + " could not be found in emitted module"); } MethodTranslator translator = new MethodTranslator(this); MethodDescriptor log = translator.TranslateNewMethod(targtMet, out emittedMehtod); Manager.MetadataManager.OldEmitter.CorMetaDataEmit.SetRVA(log.destToken, RVA); TypeDefinition typeDef = Manager.MetadataManager.FindTypeDefinition(Manager.ResourceManager.OldAssembly, Manager.ResourceManager.CurrentModule.Name, method.DeclaringType.FullyQualifiedName); if (typeDef != null) { typeDef.Methods.Add(emittedMehtod); } Manager.ResourceManager.CurrentModule.RemoveFromLoadedTypes(targtMet.DeclaringType.FullName); dIL.AddRange(log.codeIL); if (SymbolWriter != null) { List <SequencePoint> points = SymbolWriter.EmitMethod(log.destToken, log.srcToken); NewMethodsSequencePoints.Add(targtMet.MetadataToken.ToUInt32(), points); } }
/// <summary> /// Change IL code and metadata for property. /// </summary> /// <param name="property">Interaface with info abour property.</param> /// <param name="isGetter">Determines whether it is getter method for property.</param> public void ChangeProperty(IProperty property, bool isGetter) { // Method RVA is offset to start of byte buffer uint RVA = (uint)dIL.Count + 4; PropertyDefinition targtProp, targtPropOld; MethodDefinition targtMet, targtMetOld; // Find appropriete new version of method in new assembly. targtProp = Manager.MetadataManager.FindProperty(Manager.ResourceManager.NewAssembly, Manager.ResourceManager.NewAssemblyName, property); if (targtProp == null) { new TranslatingException("Property " + property.ToString() + " could not be found in emitted module"); } // Find appropriete original version of method in running assembly. targtPropOld = Manager.MetadataManager.FindProperty(Manager.ResourceManager.OldAssembly, Manager.ResourceManager.CurrentModule.Name, property); if (targtPropOld == null) { new TranslatingException("Property " + property.ToString() + " could not be found in debugged module"); } targtMet = (isGetter ? targtProp.GetMethod : targtProp.SetMethod); targtMetOld = (isGetter ? targtPropOld.GetMethod : targtPropOld.SetMethod); SequencePointRemapper remapper = genSequencePointRemapper(targtMetOld, targtMet); // Translate tokens in methods IL code. MethodTranslator translator = new MethodTranslator(this); Dictionary <int, int> placeholder; MethodDescriptor log = translator.TranslateMethod(targtMet, targtMetOld, remapper, out placeholder); log.newRva = RVA; // Set method RVA. Manager.MetadataManager.OldEmitter.CorMetaDataEmit.SetRVA(targtMetOld.MetadataToken.ToUInt32(), RVA); // Store methods IL to buffer dIL.AddRange(log.codeIL); if (SymbolWriter != null) { SymbolWriter.EmitMethod(log.destToken, log.srcToken, placeholder); } }
public static void Draw() { if (IsShowing) { RenderingDevice.SpriteBatch.Begin(); RenderingDevice.SpriteBatch.Draw(Program.Game.Loader.EmptyTex, edgeDrawZone, edgeColor); RenderingDevice.SpriteBatch.Draw(Program.Game.Loader.EmptyTex, internalDrawZone, internalColor); internalBox.Draw(currentText); if (Input.ControlScheme == ControlScheme.Keyboard) { SymbolWriter.WriteKeyboardIcon(Keys.E, symbolPos, true); } if (Input.ControlScheme == ControlScheme.XboxController) { SymbolWriter.WriteXboxIcon(Buttons.X, symbolPos, true); } RenderingDevice.SpriteBatch.End(); } }
/// <summary> /// Write out the scopes and the locals to the PDB file. /// </summary> /// <param name="symWriter">The symbol writer for this file.</param> /// <param name="scope">The scope to write out.</param> private void WriteScopeAndLocals(SymbolWriter symWriter, Scope scope) { // Open the scope symWriter.OpenScope(scope.OffsetStart); // Add each local variable foreach (LocalBinding lb in scope.Locals) { symWriter.DefineLocalVariable2( lb.Name, 0, lb.Token.GetToken(), 1, lb.Index, 0, 0, lb.OffsetStart, lb.OffsetEnd ); } // Add each constants /* For now don't add constants. Doesn't work. AKB 09-01-2007 foreach (ConstantBinding cb in scope.Constants) { symWriter.DefineConstant( cb.Name, cb.Value, cb.GetSig() ); } */ // Add any child scopes foreach (Scope childScope in scope.ChildScopes) WriteScopeAndLocals(symWriter, childScope); // Close the scope symWriter.CloseScope(scope.OffsetEnd); }
/// <summary> /// Write the PDB file to disk. /// </summary> public void WritePDBFile() { // Create the new Symbol Writer SymbolWriter symWriter = new SymbolWriter(PEFilename, PDBFilename); // Add each of the source documents foreach (Document doc in _docWriters) { doc._docWriter = symWriter.DefineDocument( doc._file, doc._docLanguage, doc._langVendor, doc._docType ); } // Set the entry point if it exists if (entryPoint.GetToken() != 0) symWriter.SetUserEntryPoint(entryPoint.GetToken()); // Loop through and add each method foreach (Method meth in methods) { symWriter.OpenMethod(meth.Token.GetToken()); // Write the scope and the locals if (meth.Scope != null) WriteScopeAndLocals(symWriter, meth.Scope); // Add each of the sequence points foreach (Document sourceDoc in meth.SequencePointList.Keys) { SequencePointList spList = (SequencePointList)meth.SequencePointList[sourceDoc]; symWriter.DefineSequencePoints(sourceDoc._docWriter, (uint[])spList.offsets.ToArray(typeof(uint)), (uint[])spList.lines.ToArray(typeof(uint)), (uint[])spList.cols.ToArray(typeof(uint)), (uint[])spList.endLines.ToArray(typeof(uint)), (uint[])spList.endCols.ToArray(typeof(uint))); } symWriter.CloseMethod(); } // Get the debug info debugInfo = symWriter.GetDebugInfo(); // Close the PDB file symWriter.Close(); }