Specifies reading arguments that are being used to read a win32 assembly.
        /// <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 Win32Assembly LoadFile(string file, ReadingParameters arguments)
        {
            try
            {
                Win32Assembly a = new Win32Assembly();


                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.disassembler            = new x86Disassembler(a);
                    a.assembler               = new x86Assembler(a);
                    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);
            }
        }
Example #2
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 Win32Assembly LoadFile(string file, ReadingParameters arguments)
        {
            try
            {
                Win32Assembly a = new Win32Assembly();

                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.disassembler = new x86Disassembler(a);
                    a.assembler = new x86Assembler(a);
                    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);
            }
        }