Beispiel #1
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];
             for (int j=0; j < table.Count; j++) {
                 ((MetaDataElement)table[j]).Write(output);
             }
         }
     }
     // reset the typespec flags
     if (tables[(int)MDTable.TypeSpec] != null) {
         ArrayList typeSpecTable = tables[(int)MDTable.TypeSpec];
         for (int i=0; i < typeSpecTable.Count; i++) {
             ((TypeSpec)typeSpecTable[i]).typeSpecAdded = false;
         }
     }
     //Console.WriteLine("Writing padding at " + output.Seek(0,SeekOrigin.Current));
     for (int i=0; i < tildePadding; i++) output.Write((byte)0);
 }
Beispiel #2
0
        internal void Write(PEWriter output)
        {
            if (Diag.DiagOn) Console.WriteLine("Writing header flags = " + Hex.Short(headerFlags));
            if (tinyFormat) {
                if (Diag.DiagOn) Console.WriteLine("Writing tiny code");
                output.Write((byte)headerFlags);
            } else {
                if (Diag.DiagOn) Console.WriteLine("Writing fat code");
                output.Write(headerFlags);
                output.Write((ushort)maxStack);
                output.Write(offset);
                output.Write(localSigIx);
            }
            if (Diag.DiagOn) {
                Console.WriteLine(Hex.Int(tide) + " CIL instructions");
                Console.WriteLine("starting instructions at " + output.Seek(0,SeekOrigin.Current));
            }

            // Added to enable PDB generation
            if (output.pdbWriter != null) {

                // Open the method
                output.pdbWriter.OpenMethod((int)thisMeth.Token());

                // Check if this is the entry point method
                if (thisMeth.HasEntryPoint()) output.pdbWriter.SetEntryPoint((int)thisMeth.Token());
            }

            // Write out each memember of the buffer
            for (int i=0; i < tide; i++) {
                buffer[i].Write(output);
            }

            // Added to enable PDB generation
            if (output.pdbWriter != null && tide > 0) {
                output.pdbWriter.CloseMethod();
            }
            if (Diag.DiagOn) Console.WriteLine("ending instructions at " + output.Seek(0,SeekOrigin.Current));
            for (int i=0; i < paddingNeeded; i++) { output.Write((byte)0); }
            if (exceptions != null) {
                // Console.WriteLine("Writing exceptions");
                // Console.WriteLine("header = " + Hex.Short(exceptHeader) + " exceptSize = " + Hex.Int(exceptSize));
                output.Write(exceptHeader);
                output.Write3Bytes((uint)exceptSize);
                for (int i=0; i < exceptions.Count; i++) {
                    TryBlock tryBlock = (TryBlock)exceptions[i];
                    tryBlock.Write(output,fatExceptionFormat);
                }
            }
        }
Beispiel #3
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));
 }