示例#1
0
        internal DataDirectory(PortableExecutableImage image, DataDirectories dataDirs, DataDirectoryType dirType, IMAGE_DATA_DIRECTORY dataDirectory, ulong imageBase)
        {
            _image       = image;
            _type        = dirType;
            _header      = dataDirectory;
            _imageBase   = imageBase;
            _sectionName = new Lazy <string>(DoGetSectionName);
            _section     = new Lazy <Section>(DoGetSection);

            Directories = dataDirs;
        }
示例#2
0
        private static void DataDirectory_Exists(string fileName, DataDirectoryType type, bool expectedValue)
        {
            var file = TestingUtils.GetFileFromResources(fileName);

            using (var image = PortableExecutableImage.FromStream(file))
            {
                var value = image.NTHeaders.DataDirectories.ExistsAndNotEmpty(type);

                value.Should().Be(expectedValue);
            }
        }
 public DataDirectoryEntry this[DataDirectoryType idx]
 {
     get
     {
         return(Items[(int)idx]);
     }
     set
     {
         Items[(int)idx] = value;
     }
 }
        /// <summary>
        /// 获得目录
        /// </summary>
        /// <param name="type"></param>
        /// <param name="appendix"></param>
        /// <returns></returns>
        public static string GetDirectory(DataDirectoryType type, string appendix)
        {
            switch (type)
            {
            case DataDirectoryType.Global:
                return(GlobalDataDirectory + "\\" + (appendix == null ? string.Empty : appendix));

            case DataDirectoryType.User:
                return(UserDataDirectory + "\\" + (appendix == null ? string.Empty : appendix));

            default:
                throw new ArgumentException("Invalid DataDirectory Type1");
            }
        }
示例#5
0
        public bool ExistsAndNotEmpty(DataDirectoryType directoryType)
        {
            if (!_directories.ContainsKey(directoryType))
            {
                return(false);
            }

            var dataDirectory = _directories[directoryType];

            if (DataDirectory.IsNullOrEmpty(dataDirectory))
            {
                return(false);
            }

            return(true);
        }
示例#6
0
文件: PELoader.cs 项目: cosim/PETools
        public void LoadDataDirectories()
        {
            DataDirectories = new Dictionary <DataDirectoryType, DataDirectory>(DataDirectoryHeaders.Length);
            for (int i = 0; i < DataDirectoryHeaders.Length; i++)
            {
                var ddh = DataDirectoryHeaders[i];
                if (ddh.Size == 0)
                {
                    continue;
                }

                var begin   = ddh.VirtualAddress;
                var end     = begin + ddh.Size;
                var section = SectionFromVirtualAddressRange(begin, end);

                DataDirectoryType type = (DataDirectoryType)i;
                DataDirectories[type] = new DataDirectory {
                    Type    = type,
                    Offset  = ddh.VirtualAddress - section.VirtualAddress,
                    Section = section,
                    Size    = ddh.Size
                };
            }
        }
 /// <summary>
 /// 获得目录
 /// </summary>
 /// <param name="type"></param>
 /// <param name="appendix"></param>
 /// <returns></returns>
 public static string GetDirectory(DataDirectoryType type, string appendix)
 {
     switch (type)
     {
         case DataDirectoryType.Global:
             return GlobalDataDirectory + "\\" + (appendix == null ? string.Empty : appendix);
         case DataDirectoryType.User:
             return UserDataDirectory + "\\" + (appendix == null ? string.Empty : appendix);
         default:
             throw new ArgumentException("Invalid DataDirectory Type1");
     }
 }
示例#8
0
 public Directory(string name, uint addr, uint size)
 {
     this._type       = (DataDirectoryType)Enum.Parse(typeof(DataDirectoryType), name);
     this.VirtualAddr = addr;
     this.VirtualSize = size;
 }
示例#9
0
 public Directory(DataDirectoryType type, uint addr, uint size)
 {
     this._type       = type;
     this.VirtualAddr = addr;
     this.VirtualSize = size;
 }
示例#10
0
 public Directory(ImageDataDirectory dir, DataDirectoryType type)
     : this(type, dir.VirtualAddress, dir.Size)
 {
     this._directory = dir;
 }
示例#11
0
 public bool Exists(DataDirectoryType directoryType)
 {
     return(_directories.ContainsKey(directoryType));
 }
示例#12
0
 public DataDirectory this[DataDirectoryType directoryType] => (_directories.ContainsKey(directoryType) ? _directories[directoryType] : null);
 internal DataDirectoryEntry(DataDirectoryType type, uint adr, uint s)
 {
     Type    = type;
     Address = adr;
     Size    = s;
 }
 int FindDataDirectoryOffset(DataDirectoryType type)
 {
     var rva = (uint)_dataDirectories[(int)type].RVA;
     return FindRvaOffset(rva);
 }
示例#15
0
 public DataDirectory DataDirectory(DataDirectoryType type) => DataDirectory((int)type);