示例#1
0
 internal override void Write(PEWriter output, bool fatFormat)
 {
     if (Diag.DiagOn)
     {
         Console.WriteLine("writing exception details");
     }
     for (int i = 0; i < handlers.Count; i++)
     {
         if (Diag.DiagOn)
         {
             Console.WriteLine("Except block " + i);
         }
         HandlerBlock handler = handlers[i];
         flags = handler.GetFlag();
         if (Diag.DiagOn)
         {
             Console.WriteLine("flags = " + flags);
         }
         if (fatFormat)
         {
             output.Write((uint)flags);
         }
         else
         {
             output.Write(flags);
         }
         base.Write(output, fatFormat);
         handler.Write(output, fatFormat);
     }
 }
示例#2
0
        internal virtual void Write(PEWriter output, bool fatFormat)
        {
            Contract.Requires(output != null);
            if (fatFormat)
            {
                output.Write(start.GetLabelOffset());
            }
            else
            {
                output.Write((short)start.GetLabelOffset());
            }
            uint len = end.GetLabelOffset() - start.GetLabelOffset();

            if (Diag.DiagOn)
            {
                Console.WriteLine("block start = " + start.GetLabelOffset() + "  len = " + len);
            }
            if (fatFormat)
            {
                output.Write(len);
            }
            else
            {
                output.Write((byte)len);
            }
        }
示例#3
0
 internal sealed override void Write(PEWriter output)
 {
     output.Write((short)0);
     output.StringsIndex(nameIx);
     output.GUIDIndex(mvidIx);
     output.GUIDIndex(0);
     output.GUIDIndex(0);
 }
示例#4
0
 internal sealed override void Write(PEWriter output)
 {
     output.Write(flags);
     output.Write(0);
     output.StringsIndex(nameIx);
     output.StringsIndex(nameSpaceIx);
     output.WriteCodedIndex(CIx.Implementation, implementation);
 }
示例#5
0
 internal void WriteByteCodes(PEWriter output)
 {
     foreach (CILInstructions byteCode in byteCodes)
     {
         byteCode.Write(output);
     }
     for (int i = 0; i < byteCodePadding; i++)
     {
         output.Write((byte)0);
     }
 }
示例#6
0
 internal override void Write(PEWriter output)
 {
     output.Write(index);
     output.Write(flags);
     output.WriteCodedIndex(CIx.TypeOrMethodDef, parent);
     output.StringsIndex(nameIx);
     if (extraField)
     {
         output.Write(kind);
     }
 }
示例#7
0
 internal sealed override void Write(PEWriter output)
 {
     output.Write(major);
     output.Write(minor);
     output.Write(build);
     output.Write(revision);
     output.Write(flags);
     output.BlobIndex(keyIx);
     output.StringsIndex(nameIx);
     output.StringsIndex(cultIx);
     output.BlobIndex(hashIx);
 }
示例#8
0
 internal sealed override void Write(PEWriter output)
 {
     //Console.WriteLine("Writing assembly element with nameIx of " + nameIx + " at file offset " + output.Seek(0,SeekOrigin.Current));
     output.Write((uint)hashAlgId);
     output.Write(majorVer);
     output.Write(minorVer);
     output.Write(buildNo);
     output.Write(revisionNo);
     output.Write(flags);
     output.BlobIndex(keyIx);
     output.StringsIndex(nameIx);
     output.StringsIndex(cultIx);
 }
示例#9
0
 internal void WriteResources(PEWriter output)
 {
     if (resources == null)
     {
         return;
     }
     foreach (object res in resources)
     {
         byte[] resBytes = (byte[])res;
         output.Write((uint)resBytes.Length);
         output.Write(resBytes);
     }
 }
示例#10
0
        internal void WriteTildeStream(PEWriter output)
        {
            long startTilde = output.Seek(0, SeekOrigin.Current);

            //Console.WriteLine("Starting tilde output at offset " + Hex.Long(startTilde));
            output.Write((uint)0);                 // Reserved
            output.Write(output.verInfo.tsMajVer); // MajorVersion
            output.Write(output.verInfo.tsMinVer); // MinorVersion
            output.Write(heapSizes);
            output.Write((byte)1);                 // Reserved
            output.Write(valid);
            output.Write(sorted);
            for (int i = 0; i < NumMetaDataTables; i++)
            {
                if (tables[i] != null)
                {
                    uint count = (uint)tables[i].Count;
                    output.Write(count);
                }
            }
            long tabStart = output.Seek(0, SeekOrigin.Current);

            //Console.WriteLine("Starting metaData tables at " + tabStart);
            for (int i = 0; i < NumMetaDataTables; i++)
            {
                if (tables[i] != null)
                {
                    //Console.WriteLine("Starting metaData table " + i + " at " + (output.Seek(0,SeekOrigin.Current) - startTilde));
                    ArrayList table = tables[i];
                    foreach (object tbl in table)
                    {
                        ((MetaDataElement)tbl).Write(output);
                    }
                }
            }
            // reset the typespec flags
            if (tables[(int)MDTable.TypeSpec] != null)
            {
                ArrayList typeSpecTable = tables[(int)MDTable.TypeSpec];
                foreach (object tbl in typeSpecTable)
                {
                    ((Type)tbl).typeSpecAdded = false;
                }
            }
            //Console.WriteLine("Writing padding at " + output.Seek(0,SeekOrigin.Current));
            for (int i = 0; i < tildePadding; i++)
            {
                output.Write((byte)0);
            }
        }
示例#11
0
 internal void InitMetaDataOut(PEWriter file)
 {
     // tilde = new MetaDataStream(tildeNameArray,false,0);
     this.output = file;
     streams     = new MetaDataStream[5];
     strings     = new MetaDataStream(MetaData.stringsNameArray, new UTF8Encoding(), true);
     us          = new MetaDataStream(MetaData.usNameArray, new UnicodeEncoding(), true);
     guid        = new MetaDataStream(MetaData.guidNameArray, false);
     blob        = new MetaDataStream(MetaData.blobNameArray, new UnicodeEncoding(), true);
     streams[1]  = strings;
     streams[2]  = us;
     streams[3]  = guid;
     streams[4]  = blob;
 }
示例#12
0
 internal sealed override void Write(PEWriter output)
 {
     if (code == null)
     {
         output.Write(0);
     }
     else
     {
         output.WriteCodeRVA(textOffset);
     }
     output.Write(implFlags);
     output.Write(methFlags);
     output.StringsIndex(nameIx);
     output.BlobIndex(sigIx);
     output.WriteIndex(MDTable.Param, parIx);
 }
示例#13
0
 internal sealed override void Write(PEWriter output)
 {
     if (varArgParent != null)
     {
         output.WriteCodedIndex(CIx.MemberRefParent, varArgParent);
     }
     else if (parent is ConstructedTypeSpec)
     {
         output.WriteCodedIndex(CIx.MemberRefParent, ((ConstructedTypeSpec)parent).Spec);
     }
     else
     {
         output.WriteCodedIndex(CIx.MemberRefParent, parent);
     }
     output.StringsIndex(nameIx);
     output.BlobIndex(sigIx);
 }
示例#14
0
 internal void WriteMetaData(PEWriter output)
 {
     this.output = output;
     if (Diag.DiagOn)
     {
         mdStart = output.Seek(0, SeekOrigin.Current);
         Console.WriteLine("Writing metaData at " + Hex.Long(mdStart));
     }
     output.Write(MetaDataSignature);
     output.Write(output.verInfo.mdMajVer);
     output.Write(output.verInfo.mdMinVer);
     output.Write(0);                                         // Reserved
     output.Write(output.verInfo.netVerString.Length);
     output.Write(output.verInfo.netVerString.ToCharArray()); // version string is already zero padded
     output.Write((short)0);                                  // Flags, reserved
     output.Write((ushort)numStreams);
     // write tilde header
     output.Write(tildeStart);
     output.Write(tildeTide + tildePadding);
     output.Write(tildeNameArray);
     for (int i = 1; i < numStreams; i++)
     {
         if (Diag.DiagOn)
         {
             Console.WriteLine("Stream " + new String(streams[i].name) + " should start at " + Hex.Long(streams[i].Start + mdStart));
         }
         streams[i].WriteHeader(output);
     }
     if (Diag.DiagOn)
     {
         Console.Write("Writing tilde stream at " + Hex.Long(output.Seek(0, SeekOrigin.Current)));
         Console.WriteLine(" should be at " + Hex.Long(tildeStart + mdStart));
     }
     WriteTildeStream(output);
     for (int i = 1; i < numStreams; i++)
     {
         if (Diag.DiagOn)
         {
             Console.WriteLine("Writing stream " + new String(streams[i].name) + " at " + Hex.Long(output.Seek(0, SeekOrigin.Current)));
         }
         streams[i].Write(output);
     }
     //Console.WriteLine("Finished Writing metaData at " + output.Seek(0,SeekOrigin.Current));
 }
示例#15
0
        internal void WriteCodedIndex(CIx code, MetaDataElement elem, PEWriter output)
        {
            uint ix = 0;

            if (elem != null)
            {
                ix = (elem.Row << CIxShiftMap[(uint)code]) | elem.GetCodedIx(code);
                // Console.WriteLine("coded index = " + ix + " row = " + elem.Row);
                //} else {
                // Console.WriteLine("elem for coded index is null");
            }
            if (lgeCIx[(uint)code])
            {
                output.Write(ix);
            }
            else
            {
                output.Write((ushort)ix);
            }
        }
示例#16
0
        /// <summary>
        /// Write out the PEFile (the "bake" function)
        /// </summary>
        /// <param name="debug">include debug information</param>
        public void WritePEFile(bool writePDB)
        {
            if (outStream == null)
            {
                if (outputDir != null)
                {
                    if (!outputDir.EndsWith("\\"))
                    {
                        fileName = outputDir + "\\" + fileName;
                    }
                    else
                    {
                        fileName = outputDir + fileName;
                    }
                }
                output = new PEWriter(versionInfo, fileName, metaData, writePDB);
            }
            else
            {
                // Check to make sure we have not been asked to write a PDB
                if (writePDB)
                {
                    throw new Exception("You can not write PDB data when writing to a stream.  Please try writing to a file instead.");
                }

                output = new PEWriter(versionInfo, outStream, metaData);
            }

            BuildMetaData();

            // If the application is roundtripping an input PE-file with
            // unmanaged resources, then this.unmanagedResourceRoot != null.
            if (this.unmanagedResourceRoot != null)
            {
                output.AddUnmanagedResourceDirectory(this.unmanagedResourceRoot);
            }

            output.MakeFile(versionInfo);
        }
示例#17
0
 internal void WriteTildeStream(PEWriter output)
 {
     long startTilde = output.Seek(0, SeekOrigin.Current);
     //Console.WriteLine("Starting tilde output at offset " + Hex.Long(startTilde));
     output.Write((uint)0); // Reserved
     output.Write(output.verInfo.tsMajVer); // MajorVersion
     output.Write(output.verInfo.tsMinVer); // MinorVersion
     output.Write(heapSizes);
     output.Write((byte)1); // Reserved
     output.Write(valid);
     output.Write(sorted);
     for (int i = 0; i < NumMetaDataTables; i++)
     {
         if (tables[i] != null)
         {
             uint count = (uint)tables[i].Count;
             output.Write(count);
         }
     }
     long tabStart = output.Seek(0, SeekOrigin.Current);
     //Console.WriteLine("Starting metaData tables at " + tabStart);
     for (int i = 0; i < NumMetaDataTables; i++)
     {
         if (tables[i] != null)
         {
             //Console.WriteLine("Starting metaData table " + i + " at " + (output.Seek(0,SeekOrigin.Current) - startTilde));
             ArrayList table = tables[i];
             foreach (object tbl in table)
             {
                 ((MetaDataElement)tbl).Write(output);
             }
         }
     }
     // reset the typespec flags
     if (tables[(int)MDTable.TypeSpec] != null)
     {
         ArrayList typeSpecTable = tables[(int)MDTable.TypeSpec];
         foreach (object tbl in typeSpecTable)
         {
             ((Type)tbl).typeSpecAdded = false;
         }
     }
     //Console.WriteLine("Writing padding at " + output.Seek(0,SeekOrigin.Current));
     for (int i = 0; i < tildePadding; i++) output.Write((byte)0);
 }
示例#18
0
 internal void WriteMetaData(PEWriter output)
 {
     this.output = output;
     if (Diag.DiagOn)
     {
         mdStart = output.Seek(0, SeekOrigin.Current);
         Console.WriteLine("Writing metaData at " + Hex.Long(mdStart));
     }
     output.Write(MetaDataSignature);
     output.Write(output.verInfo.mdMajVer);
     output.Write(output.verInfo.mdMinVer);
     output.Write(0);         // Reserved
     output.Write(output.verInfo.netVerString.Length);
     output.Write(output.verInfo.netVerString.ToCharArray());   // version string is already zero padded
     output.Write((short)0);  // Flags, reserved
     output.Write((ushort)numStreams);
     // write tilde header
     output.Write(tildeStart);
     output.Write(tildeTide + tildePadding);
     output.Write(tildeNameArray);
     for (int i = 1; i < numStreams; i++)
     {
         if (Diag.DiagOn)
             Console.WriteLine("Stream " + new String(streams[i].name) + " should start at " + Hex.Long(streams[i].Start + mdStart));
         streams[i].WriteHeader(output);
     }
     if (Diag.DiagOn)
     {
         Console.Write("Writing tilde stream at " + Hex.Long(output.Seek(0, SeekOrigin.Current)));
         Console.WriteLine(" should be at " + Hex.Long(tildeStart + mdStart));
     }
     WriteTildeStream(output);
     for (int i = 1; i < numStreams; i++)
     {
         if (Diag.DiagOn)
             Console.WriteLine("Writing stream " + new String(streams[i].name) + " at " + Hex.Long(output.Seek(0, SeekOrigin.Current)));
         streams[i].Write(output);
     }
     //Console.WriteLine("Finished Writing metaData at " + output.Seek(0,SeekOrigin.Current));
 }
示例#19
0
 internal void WriteByteCodes(PEWriter output)
 {
     foreach (CILInstructions byteCode in byteCodes)
     {
         byteCode.Write(output);
     }
     for (int i = 0; i < byteCodePadding; i++)
     {
         output.Write((byte)0);
     }
 }
示例#20
0
 internal override sealed void Write(PEWriter output)
 {
     output.WriteCodedIndex(CIx.MemberRefParent, parent);
     output.StringsIndex(nameIx);
     output.BlobIndex(sigIx);
 }
示例#21
0
 internal override sealed void Write(PEWriter output)
 {
     base.Write(output);
       output.Write(theType.Token());
 }
示例#22
0
 internal sealed override void Write(PEWriter output)
 {
     output.WriteCodedIndex(CIx.HasFieldMarshal, field);
     output.BlobIndex(ntIx);
 }
示例#23
0
 internal override void Write(PEWriter output, bool fatFormat)
 {
     if (Diag.DiagOn) Console.WriteLine("writing exception details");
     for (int i = 0; i < handlers.Count; i++)
     {
         if (Diag.DiagOn) Console.WriteLine("Except block " + i);
         HandlerBlock handler = handlers[i];
         flags = handler.GetFlag();
         if (Diag.DiagOn) Console.WriteLine("flags = " + flags);
         if (fatFormat) output.Write((uint)flags);
         else output.Write(flags);
         base.Write(output, fatFormat);
         handler.Write(output, fatFormat);
     }
 }
示例#24
0
 internal sealed override void Write(PEWriter output)
 {
     output.BlobIndex(sigIx);
 }
示例#25
0
 internal sealed override void Write(PEWriter output)
 {
     output.StringsIndex(nameIx);
 }
示例#26
0
 internal sealed override void Write(PEWriter output)
 {
     output.Write(packSize);
     output.Write(classSize);
     output.WriteIndex(MDTable.TypeDef, parent.Row);
 }
示例#27
0
 internal virtual void Write(PEWriter output)
 {
     Contract.Requires(output != null);
 }
示例#28
0
 internal override sealed void Write(PEWriter output)
 {
     base.Write(output);
       if (byteNum)
     output.Write((byte)val);
       else
     output.Write((ushort)val);
 }
示例#29
0
 internal override sealed void Write(PEWriter output)
 {
     base.Write(output);
       output.Write(signature.Token());
 }
示例#30
0
 internal override sealed void Write(PEWriter output)
 {
     base.Write(output);
       output.Write(USHeapIndex | strIndex);
 }
示例#31
0
 internal override void Write(PEWriter output, bool fatFormat)
 {
     base.Write(output, fatFormat);
     output.Write((int)0);
 }
示例#32
0
 internal sealed override void Write(PEWriter output)
 {
     output.WriteCodedIndex(CIx.MemberRefParent, parent);
     output.StringsIndex(nameIx);
     output.BlobIndex(sigIx);
 }
示例#33
0
 internal override void Write(PEWriter output, bool fatFormat)
 {
     base.Write(output, fatFormat);
     output.Write(exceptType.Token());
 }
示例#34
0
 internal override sealed void Write(PEWriter output)
 {
     output.Write(flags);
     output.StringsIndex(nameIx);
     output.BlobIndex(sigIx);
 }
示例#35
0
 internal sealed override void Write(PEWriter output)
 {
     output.Write(flags);
     output.StringsIndex(nameIx);
     output.BlobIndex(sigIx);
 }
示例#36
0
 internal override sealed void Write(PEWriter output)
 {
     base.Write(output);
       output.Write(numCases);
       for (int i = 0; i < numCases; i++) {
     int target = (int)cases[i].GetLabelOffset() - (int)(offset + size);
     output.Write(target);
       }
 }
示例#37
0
 internal sealed override void Write(PEWriter output)
 {
     output.WriteDataRVA(data.DataOffset);
     output.WriteIndex(MDTable.Field, field.Row);
 }
示例#38
0
 internal override sealed void Write(PEWriter output)
 {
     if (varArgParent != null)
         output.WriteCodedIndex(CIx.MemberRefParent, varArgParent);
     else if (parent is ConstructedTypeSpec)
         output.WriteCodedIndex(CIx.MemberRefParent, ((ConstructedTypeSpec)parent).Spec);
     else
         output.WriteCodedIndex(CIx.MemberRefParent, parent);
     output.StringsIndex(nameIx);
     output.BlobIndex(sigIx);
 }
示例#39
0
 internal override sealed void Write(PEWriter output)
 {
     output.Write(offset);
     output.WriteIndex(MDTable.Field, field.Row);
 }
示例#40
0
 internal override sealed void Write(PEWriter output)
 {
     if (code == null) output.Write(0);
     else output.WriteCodeRVA(textOffset);
     output.Write(implFlags);
     output.Write(methFlags);
     output.StringsIndex(nameIx);
     output.BlobIndex(sigIx);
     output.WriteIndex(MDTable.Param, parIx);
 }
示例#41
0
 internal void InitMetaDataOut(PEWriter file)
 {
     // tilde = new MetaDataStream(tildeNameArray,false,0);
     this.output = file;
     streams = new MetaDataStream[5];
     strings = new MetaDataStream(MetaData.stringsNameArray, new UTF8Encoding(), true);
     us = new MetaDataStream(MetaData.usNameArray, new UnicodeEncoding(), true);
     guid = new MetaDataStream(MetaData.guidNameArray, false);
     blob = new MetaDataStream(MetaData.blobNameArray, new UnicodeEncoding(), true);
     streams[1] = strings;
     streams[2] = us;
     streams[3] = guid;
     streams[4] = blob;
 }
示例#42
0
 internal override sealed void Write(PEWriter output)
 {
     output.Write((short)0);
     output.StringsIndex(nameIx);
     output.GUIDIndex(mvidIx);
     output.GUIDIndex(0);
     output.GUIDIndex(0);
 }
示例#43
0
 internal void WriteCodedIndex(CIx code, MetaDataElement elem, PEWriter output)
 {
     uint ix = 0;
     if (elem != null)
     {
         ix = (elem.Row << CIxShiftMap[(uint)code]) | elem.GetCodedIx(code);
         // Console.WriteLine("coded index = " + ix + " row = " + elem.Row);
         //} else {
         // Console.WriteLine("elem for coded index is null");
     }
     if (lgeCIx[(uint)code])
         output.Write(ix);
     else
         output.Write((ushort)ix);
 }
示例#44
0
 internal override sealed void Write(PEWriter output)
 {
     //Console.WriteLine("Writing the blob index for a TypeSpec");
     output.BlobIndex(sigIx);
 }
示例#45
0
 internal void WriteResources(PEWriter output)
 {
     if (resources == null) return;
     foreach (object res in resources)
     {
         byte[] resBytes = (byte[])res;
         output.Write((uint)resBytes.Length);
         output.Write(resBytes);
     }
 }
示例#46
0
 internal override void Write(PEWriter output)
 {
     output.WriteCodedIndex(CIx.MethodDefOrRef, methParent);
     output.BlobIndex(instIx);
 }
示例#47
0
 internal sealed override void Write(PEWriter output)
 {
     output.WriteCodedIndex(CIx.HasFieldMarshal, field);
     output.BlobIndex(ntIx);
 }
示例#48
0
        /// <summary>
        /// Write this instruction to the PDB file.
        /// </summary>
        /// <param name="output">The PEWriter being used to write the PE and PDB files.</param>
        internal override void Write(PEWriter output)
        {
            if (output.pdbWriter != null) {
            output.pdbWriter.OpenScope((int)offset);
            _scope.WriteLocals(output.pdbWriter);
            /* Constants do not work. AKB 2007-02-03
             * _scope.WriteConstants(output.pdbWriter);
             */

              }
        }
示例#49
0
 internal override void Write(PEWriter output)
 {
     output.WriteCodedIndex(CIx.MethodDefOrRef, methParent);
     output.BlobIndex(instIx);
 }
示例#50
0
 internal sealed override void Write(PEWriter output)
 {
     //Console.WriteLine("Writing the blob index for a TypeSpec");
     output.BlobIndex(sigIx);
 }
示例#51
0
 internal override sealed void Write(PEWriter output)
 {
     //Console.WriteLine("Writing assembly element with nameIx of " + nameIx + " at file offset " + output.Seek(0,SeekOrigin.Current));
     output.Write((uint)hashAlgId);
     output.Write(majorVer);
     output.Write(minorVer);
     output.Write(buildNo);
     output.Write(revisionNo);
     output.Write(flags);
     output.BlobIndex(keyIx);
     output.StringsIndex(nameIx);
     output.StringsIndex(cultIx);
 }
示例#52
0
 internal override sealed void Write(PEWriter output)
 {
     output.Write(packSize);
     output.Write(classSize);
     output.WriteIndex(MDTable.TypeDef, parent.Row);
 }
示例#53
0
 internal override sealed void Write(PEWriter output)
 {
     output.Write(flags);
     output.StringsIndex(nameIx);
     output.StringsIndex(nameSpaceIx);
     //if (superType != null)
     // Console.WriteLine("getting coded index for superType of " + name + " = " + superType.GetCodedIx(CIx.TypeDefOrRef));
     output.WriteCodedIndex(CIx.TypeDefOrRef, superType);
     output.WriteIndex(MDTable.Field, fieldIx);
     output.WriteIndex(MDTable.Method, methodIx);
 }
示例#54
0
 internal override void Write(PEWriter output, bool fatFormat)
 {
     base.Write(output, fatFormat);
     output.Write(exceptType.Token());
 }
示例#55
0
 internal sealed override void Write(PEWriter output)
 {
     output.Write(flags);
     output.StringsIndex(nameIx);
     output.WriteCodedIndex(CIx.TypeDefOrRef, eventType);
 }
示例#56
0
 internal override void Write(PEWriter output, bool fatFormat)
 {
     base.Write(output, fatFormat);
     output.Write((int)0);
 }
示例#57
0
 internal override void Write(PEWriter output, bool fatFormat)
 {
     base.Write(output, fatFormat);
     output.Write(filterLabel.GetLabelOffset());
 }
示例#58
0
 internal virtual void Write(PEWriter output, bool fatFormat)
 {
     Contract.Requires(output != null);
     if (fatFormat) output.Write(start.GetLabelOffset());
     else output.Write((short)start.GetLabelOffset());
     uint len = end.GetLabelOffset() - start.GetLabelOffset();
     if (Diag.DiagOn) Console.WriteLine("block start = " + start.GetLabelOffset() + "  len = " + len);
     if (fatFormat) output.Write(len);
     else output.Write((byte)len);
 }
示例#59
0
 internal override void Write(PEWriter output, bool fatFormat)
 {
     base.Write(output, fatFormat);
     output.Write(filterLabel.GetLabelOffset());
 }
示例#60
0
 internal sealed override void Write(PEWriter output)
 {
     output.WriteCodedIndex(CIx.ResolutionScope, parent);
     output.StringsIndex(nameIx);
     output.StringsIndex(nameSpaceIx);
 }