Beispiel #1
0
        private PEReader([NotNull] PEFile pefile, [NotNull] System.IO.FileStream file, bool refs, bool skipBody)
            :
            base(new MemoryStream(new BinaryReader(file).ReadBytes(System.Convert.ToInt32(file.Length))))
        {
            Contract.Requires(pefile != null);
            Contract.Requires(file != null);
            this.skipBody = skipBody;
            thisScope = pefile;
            refsOnly = refs;
            verInfo.fromExisting = true;
            try
            {
                ReadDOSHeader();
            }
            catch (PEFileException)
            {
                Console.WriteLine("Bad DOS header");
                return;
            }
            ReadFileHeader();
            ReadSectionHeaders();
            ReadCLIHeader();
            ReadMetaData();
            if (refsOnly)
                this.ReadMetaDataTableRefs();
            else
            {
                this.ReadMetaDataTables();
                pefile.metaDataTables = new MetaDataTables(tables);
                this.SaveUnmanagedResources();
            }
            file.Close();

            if (thisScope != null)
            {
                thisScope.buffer = this;
                if (pefile != null)
                {
                    pefile.versionInfo = verInfo;
                }
            }
            strings = null;
            userstring = null;
            blob = null;
            guid = null;
        }
Beispiel #2
0
 private void SetThisScope()
 {
     if (refsOnly)
         thisScope = Module.ReadModuleRef(this);
     else
         ((PEFile)thisScope).Read(this);
     tables[(int)MDTable.Module][0] = thisScope;
     if (tableLengths[(int)MDTable.Assembly] > 0)
     {
         SetElementPosition(MDTable.Assembly, 1);
         if (refsOnly)
         {
             ModuleRef thisMod = (ModuleRef)thisScope;
             thisScope = Assembly.ReadAssemblyRef(this);
             //if ((thisMod != null) && (thisMod.ismscorlib) && (thisScope != null)) {
             //  ((AssemblyRef)thisScope).CopyVersionInfoToMSCorLib();
             //  thisScope = MSCorLib.mscorlib;
             //}
             tables[(int)MDTable.Assembly][0] = thisScope;
         }
         else
         {
             Assembly.Read(this, tables[(int)MDTable.Assembly], (PEFile)thisScope);
             ((PEFile)thisScope).SetThisAssembly((Assembly)tables[(int)MDTable.Assembly][0]);
         }
     }
 }