Пример #1
0
        private void ParseCoffFile()
        {
            // Output console message
            Console.WriteLine("Parsing the input object file, {0}.", fileName);

            // Parse the COFF header
            try
            {
                hdr = CoffFile.ParseCOFFHeader(binFile);
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
                return;
            }

            // Set section count
            sectionCount = hdr.c_shnum;
            symbolCount  = hdr.c_symnum;

            // Set Table File Addresses
            symbolTableFileAddr = (Int64)hdr.c_psymtable;
            stringTableFileAddr = (Int64)(symbolTableFileAddr + (symbolTableEntrySize * symbolCount));

            // Set endianness
            endian = hdr.c_endian;
            Debug.DebugMSG("Endianness: " + endian.ToString());

            binFile.Seek(0, SeekOrigin.Begin);
            EndianBinaryReader ebr = new EndianBinaryReader(binFile, hdr.c_endian);

            headerRef["numBootSections"] = (UInt32)0;

            // Read the optional COFF header
            if (hdr.c_ehsize != 0)
            {
                ebr.BaseStream.Seek(COFFHeaderSize, SeekOrigin.Begin);
                headerRef["optMagicNumber"] = (UInt32)ebr.ReadUInt16();
                Debug.DebugMSG("optMagicNumber: " + ((UInt32)headerRef["optMagicNumber"]).ToString("X4"));

                headerRef["optVersionStamp"] = (UInt32)ebr.ReadUInt16();
                Debug.DebugMSG("optVersionStamp: " + ((UInt32)headerRef["optVersionStamp"]).ToString("X4"));

                headerRef["optExeSize"] = ebr.ReadUInt32();
                Debug.DebugMSG("optExeSize: " + ((UInt32)headerRef["optExeSize"]).ToString("X8"));

                headerRef["optInitSize"] = ebr.ReadUInt32();
                Debug.DebugMSG("optInitSize: " + ((UInt32)headerRef["optInitSize"]).ToString("X8"));

                headerRef["optUninitSize"] = ebr.ReadUInt32();
                Debug.DebugMSG("optUninitSize: " + ((UInt32)headerRef["optUninitSize"]).ToString("X8"));

                entryPoint = (UInt64)ebr.ReadUInt32();
                headerRef["optEntryPoint"] = (UInt32)entryPoint;
                Debug.DebugMSG("optEntryPoint: " + ((UInt32)headerRef["optEntryPoint"]).ToString("X8"));

                headerRef["optExeAddr"] = ebr.ReadUInt32();
                Debug.DebugMSG("optExeAddr: " + ((UInt32)headerRef["optExeAddr"]).ToString("X8"));

                headerRef["optInitAddr"] = ebr.ReadUInt32();
                Debug.DebugMSG("optInitAddr: " + ((UInt32)headerRef["optInitAddr"]).ToString("X8"));
            }

            // Read the section headers
            ParseSectionHdrs();

            // Parse the symbol table
            ParseSymbolTable();
        } // end ParseCOFFFile()
Пример #2
0
        private void ParseCoffFile()
        {
            // Output console message
              Console.WriteLine("Parsing the input object file, {0}.", fileName);

              // Parse the COFF header
              try
              {
            hdr = CoffFile.ParseCOFFHeader(binFile);
              }
              catch (Exception e)
              {
            Console.Write(e.Message);
            return;
              }

              // Set section count
              sectionCount = hdr.c_shnum;
              symbolCount  = hdr.c_symnum;

              // Set Table File Addresses
              symbolTableFileAddr = (Int64) hdr.c_psymtable;
              stringTableFileAddr = (Int64) (symbolTableFileAddr + (symbolTableEntrySize * symbolCount));

              // Set endianness
              endian = hdr.c_endian;
              Debug.DebugMSG("Endianness: " + endian.ToString());

              binFile.Seek(0, SeekOrigin.Begin);
              EndianBinaryReader ebr = new EndianBinaryReader(binFile, hdr.c_endian);

              headerRef["numBootSections"] = (UInt32)0;

              // Read the optional COFF header
              if (hdr.c_ehsize != 0)
              {
            ebr.BaseStream.Seek(COFFHeaderSize,SeekOrigin.Begin);
            headerRef["optMagicNumber"] = (UInt32) ebr.ReadUInt16();
            Debug.DebugMSG("optMagicNumber: " + ((UInt32)headerRef["optMagicNumber"]).ToString("X4"));

            headerRef["optVersionStamp"] = (UInt32)ebr.ReadUInt16();
            Debug.DebugMSG("optVersionStamp: " + ((UInt32)headerRef["optVersionStamp"]).ToString("X4"));

            headerRef["optExeSize"] = ebr.ReadUInt32();
            Debug.DebugMSG("optExeSize: " + ((UInt32)headerRef["optExeSize"]).ToString("X8"));

            headerRef["optInitSize"] = ebr.ReadUInt32();
            Debug.DebugMSG("optInitSize: " + ((UInt32)headerRef["optInitSize"]).ToString("X8"));

            headerRef["optUninitSize"] = ebr.ReadUInt32();
            Debug.DebugMSG("optUninitSize: " + ((UInt32)headerRef["optUninitSize"]).ToString("X8"));

            entryPoint = (UInt64) ebr.ReadUInt32();
            headerRef["optEntryPoint"] = (UInt32) entryPoint;
            Debug.DebugMSG("optEntryPoint: " + ((UInt32)headerRef["optEntryPoint"]).ToString("X8"));

            headerRef["optExeAddr"] = ebr.ReadUInt32();
            Debug.DebugMSG("optExeAddr: " + ((UInt32)headerRef["optExeAddr"]).ToString("X8"));

            headerRef["optInitAddr"] = ebr.ReadUInt32();
            Debug.DebugMSG("optInitAddr: " + ((UInt32)headerRef["optInitAddr"]).ToString("X8"));
              }

              // Read the section headers
              ParseSectionHdrs();

              // Parse the symbol table
              ParseSymbolTable();
        }