Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the Portable Executeable's MZ header by specifing the assembly.
        /// </summary>
        /// <param name="assembly">The assembly to read the mz header</param>
        /// <returns></returns>
        public static MZHeader FromAssembly(LWin32 assembly)
        {
            MZHeader a = new MZHeader();

            a._assembly = assembly;
            return(a);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets the Portable Executeable's MZ header by specifing the assembly.
 /// </summary>
 /// <param name="assembly">The assembly to read the mz header</param>
 /// <returns></returns>
 public static MZHeader FromAssembly(LWin32 assembly)
 {
     MZHeader a = new MZHeader();
     a._assembly = assembly;
     return a;
 }