Esempio n. 1
0
 private static void openObjFile(String file_name, out ObjectFile obj_file)
 {
     if (ElfFile.IsElfFile(file_name))
         obj_file = new ElfFile(file_name);
     else if (CoffFile.IsCoffFile(file_name))
         obj_file = new CoffFile(file_name);
     else
         throw new Exception("File " + file_name + " is not a valid object file.");
 }
Esempio n. 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();
        } // end ParseCOFFFile()
Esempio n. 3
0
        public virtual retType InsertAISObjectFile( String fileName )
        {
            Debug.DebugMSG("Inserting Object File, fileName = " + fileName);
              // Since no load address is provided, we can assume ObjectFile is ElfFile or CoffFile
              if (File.Exists(fileName))
              {
            // Parse the object file
            ObjectFile file;
            if (ElfFile.IsElfFile(fileName))
            {
              file = new ElfFile(fileName);
            }
            else if (CoffFile.IsCoffFile(fileName))
            {
              file = new CoffFile(fileName);
            }
            else
            {
              Console.WriteLine("ERROR: Not a valid object file.");
              return retType.FAIL;
            }

            if (file != null)
            {
              // Load the object file contents
              AISObjectFileLoad(this,file);
              file.Close();
            }
            else
            {
              Console.WriteLine("ERROR: Parsing the input file {0} failed!",fileName);
            }
              }
              else
              {
            Console.WriteLine("WARNING: File {0} does not exist. Ignoring insert command.",fileName);
              }

              return retType.SUCCESS;
        }