/// <summary>Get all relocations blocks from directory</summary> /// <returns>Relocation blocks</returns> public IEnumerator <RelocationBlock> GetEnumerator() { if (!IsEmpty) { UInt32 position = base.Directory.VirtualAddress; UInt32 end = position + base.Directory.Size; UInt32 sizeOfBaseRelocation = (UInt32)Marshal.SizeOf(typeof(WinNT.IMAGE_BASE_RELOCATION)); while (position < end) { WinNT.IMAGE_BASE_RELOCATION block = base.Parent.Header.PtrToStructure <WinNT.IMAGE_BASE_RELOCATION>(position); RelocationSection[] sections = new RelocationSection[block.TypeOffest]; for (UInt32 loop = 0; loop < block.TypeOffest; loop++) { UInt32 sectionPosition = position + sizeOfBaseRelocation + sizeof(UInt16) * loop; sections[loop] = new RelocationSection(base.Parent.Header.PtrToStructure <UInt16>(sectionPosition)); } //UInt16 section = base.Info.Header.PtrToStructure<UInt16>(position); yield return(new RelocationBlock(block, sections)); position += block.SizeOfBlock; } } }
/// <summary>Create instance of relocation block info</summary> /// <param name="block">Relocation block</param> /// <param name="sections">Array of sections</param> public RelocationBlock(WinNT.IMAGE_BASE_RELOCATION block, RelocationSection[] sections) { this._block = block; this._sections = sections; }