Represents a symbol imported by a windows assembly image.
        internal static ImageSymbolImport FromReadingContext(ReadingContext context)
        {
            var reader      = context.Reader;
            var application = context.Assembly;

            var optionalHeader = application.NtHeaders.OptionalHeader;

            var import = new ImageSymbolImport(optionalHeader.Magic == OptionalHeaderMagic.Pe32Plus
                ? reader.ReadUInt64()
                : reader.ReadUInt32());

            if (import.Lookup == 0)
            {
                return(import);
            }

            import.IsImportByOrdinal = import.Lookup >> (optionalHeader.Magic == OptionalHeaderMagic.Pe32Plus ? 63 : 31) == 1;

            if (!import.IsImportByOrdinal)
            {
                import.HintName =
                    HintName.FromReadingContext(context.CreateSubContext(application.RvaToFileOffset(import.HintNameRva)));
            }

            return(import);
        }
Exemple #2
0
        /// <summary>
        /// Determines the import address to use for a specific function.
        /// </summary>
        /// <param name="import">The imported symbol to get the address from.</param>
        /// <param name="is32Bit">Specifies whether the address should be a 32-bit or 64-bit address.</param>
        /// <returns></returns>
        public ulong GetSymbolImportAddress(ImageSymbolImport import, bool is32Bit)
        {
            int index = SymbolImports.IndexOf(import);

            if (index == -1)
            {
                throw new ArgumentException("Symbol is not present in the module import.", "import");
            }
            return((ulong)(ImportAddressTableRva + index * (is32Bit ? sizeof(uint) : sizeof(ulong))));
        }
        internal static ImageSymbolImport FromReadingContext(ReadingContext context)
        {
            var reader = context.Reader;
            var application = context.Assembly;

            var optionalHeader = application.NtHeaders.OptionalHeader;

            var import = new ImageSymbolImport(optionalHeader.Magic == OptionalHeaderMagic.Pe32Plus
                ? reader.ReadUInt64()
                : reader.ReadUInt32());

            if (import.Lookup == 0)
                return import;

            import.IsImportByOrdinal = import.Lookup >> (optionalHeader.Magic == OptionalHeaderMagic.Pe32Plus ? 63 : 31) == 1;

            if (!import.IsImportByOrdinal)
                import.HintName =
                    HintName.FromReadingContext(context.CreateSubContext(application.RvaToFileOffset(import.HintNameRva)));

            return import;
        }
 /// <summary>
 /// Determines the import address to use for a specific function.
 /// </summary>
 /// <param name="import">The imported symbol to get the address from.</param>
 /// <param name="is32Bit">Specifies whether the address should be a 32-bit or 64-bit address.</param>
 /// <returns></returns>
 public ulong GetSymbolImportAddress(ImageSymbolImport import, bool is32Bit)
 {
     int index = SymbolImports.IndexOf(import);
     if (index == -1)
         throw new ArgumentException("Symbol is not present in the module import.", "import");
     return (ulong)(ImportAddressTableRva + index * (is32Bit ? sizeof (uint) : sizeof (ulong)));
 }