public ImportExportTableReader(NTHeader header)
 {
     this.header = header;
     image = header._assembly._peImage;
     LoadExports();
     LoadImports();
 }
Beispiel #2
0
 public ImportExportTableReader(NTHeader header)
 {
     this.header = header;
     image       = header._assembly._peImage;
     LoadExports();
     LoadImports();
 }
Beispiel #3
0
        /// <summary>
        /// Loads an assembly from a specific file using the specific reading parameters.
        /// </summary>
        /// <param name="file">The file to read.</param>
        /// <param name="arguments">The reading parameters to use.</param>
        /// <returns></returns>
        /// <exception cref="System.BadImageFormatException"></exception>
        public static LWin32 LoadFile(string file, ReadingParameters arguments)
        {
            try
            {
                LWin32 a = new LWin32();
                a._path            = file;
                a.ReadingArguments = arguments;
                a._peImage         = PeImage.LoadFromAssembly(a);

                a._headerReader = PeHeaderReader.FromAssembly(a);
                a._ntHeader     = NTHeader.FromAssembly(a);
                a._mzHeader     = MZHeader.FromAssembly(a);
                a._headerReader.LoadData(arguments.IgnoreDataDirectoryAmount);


                if (!arguments.OnlyManaged)
                {
                    a._importExportTableReader = new ImportExportTableReader(a._ntHeader);
                    a._resourcesReader         = new ResourcesReader(a._ntHeader);
                }


                a._netHeader = NETHeader.FromAssembly(a);
                a._peImage.SetOffset(a._ntHeader.OptionalHeader.HeaderSize);
                return(a);
            }
            catch (Exception ex)
            {
                if (ex is AccessViolationException || ex is FileNotFoundException)
                {
                    throw;
                }
                throw new BadImageFormatException("The file is not a valid Portable Executable File.", ex);
            }
        }
Beispiel #4
0
 internal NETHeaderReader(NTHeader header, NETHeader parent)
 {
     this.parent = parent;
     header._assembly._netHeader = parent;
     image = header._assembly._peImage;
     this.ntHeader = header;
 }
Beispiel #5
0
 internal NETHeaderReader(NTHeader header, NETHeader parent)
 {
     this.parent = parent;
     header._assembly._netHeader = parent;
     image         = header._assembly._peImage;
     this.ntHeader = header;
 }
Beispiel #6
0
        /// <summary>
        /// Gets the Portable Executeable's NT header by specifing the assembly.
        /// </summary>
        /// <param name="assembly">The assembly to read the nt header</param>
        /// <returns></returns>
        public static NTHeader FromAssembly(LWin32 assembly)
        {
            NTHeader a = new NTHeader();

            a._assembly = assembly;
            a._file     = assembly._path;
            a._header   = assembly._headerReader;
            a._fheader  = FileHeader.FromAssembly(assembly);
            return(a);
        }
Beispiel #7
0
 internal ResourcesReader(NTHeader header)
 {
     this.header       = header;
     this.image        = header._assembly._peImage;
     resourceDirectory = header.OptionalHeader.DataDirectories[(int)DataDirectoryName.Resource];
     if (header._assembly._peImage.TrySetOffset(resourceDirectory.TargetOffset.FileOffset))
     {
         stream = header._assembly._peImage.ReadStream((int)resourceDirectory.Size);
         reader = new BinaryReader(stream);
         ReadRootDirectory();
     }
 }
Beispiel #8
0
 internal ResourcesReader(NTHeader header)
 {
     this.header = header;
     this.image = header._assembly._peImage;
     resourceDirectory = header.OptionalHeader.DataDirectories[(int)DataDirectoryName.Resource];
     if (header._assembly._peImage.TrySetOffset(resourceDirectory.TargetOffset.FileOffset))
     {
         stream = header._assembly._peImage.ReadStream((int)resourceDirectory.Size);
         reader = new BinaryReader(stream);
         ReadRootDirectory();
     }
 }
Beispiel #9
0
 /// <summary>
 /// Gets the Portable Executeable's NT header by specifing the assembly.
 /// </summary>
 /// <param name="assembly">The assembly to read the nt header</param>
 /// <returns></returns>
 public static NTHeader FromAssembly(LWin32 assembly)
 {
     NTHeader a = new NTHeader();
     a._assembly = assembly;
     a._file = assembly._path;
     a._header = assembly._headerReader;
     a._fheader = FileHeader.FromAssembly(assembly);
     return a;
 }