private IRelocationDirectoryInfo CreateDirectoryInfoFromList(
            List <RelocationTypeOffset> relocationTypeOffetList, ICode code,
            IImageBaseRelocationSerializer imageBaseRelocationSerializer,
            IRelocationDirectoryInfoFactory relocationDirecroryInfoFactory)
        {
            var relocationInfo = code.CodeInMemoryLayout.RelocationDirectoryInfo;

            //the relocation directory might grow up to twice. the obfuscation algorithm might add jump instruction for each existing
            //jump instruction which doubles the number of addresses
            var newBufferSize = relocationInfo.RelocationDirectorySize * 2;

            byte[] buffer = new byte[newBufferSize];

            List <IMAGE_BASE_RELOCATION> imageBaseRelocationList = new List <IMAGE_BASE_RELOCATION>();
            //contains reloction offset list of virtual addresses from 0 to 999 after performing
            //virtual address%1000
            IMAGE_BASE_RELOCATION relocations0To999;
            ulong bufferIndex = 0;
            int   listIndex   = 0;

            while (listIndex < relocationTypeOffetList.Count)
            {
                relocations0To999 = CreateRelocationsFrom0To999(relocationTypeOffetList,
                                                                ref listIndex, buffer, ref bufferIndex, imageBaseRelocationSerializer);
                imageBaseRelocationList.Add(relocations0To999);
            }

            List <RelocationTypeOffsetItem> newCodeAddressesInData = GetNewAddressesInData(code);

            return(relocationDirecroryInfoFactory.Create(imageBaseRelocationList.ToArray(),
                                                         (uint)bufferIndex, buffer, 0, newCodeAddressesInData));
        }
 public RelocationDirectoryFromNewCode(IImageBaseRelocationSerializer imageBaseRelcationSerializer,
                                       IRelocationDirectoryInfoFactory relocationDirectoryInfoFactory)
 {
     m_ImageBaseRelocationSerializer = imageBaseRelcationSerializer ??
                                       throw new ArgumentNullException(nameof(imageBaseRelcationSerializer));
     m_relocationDirectoryInfoFactory = relocationDirectoryInfoFactory ??
                                        throw new ArgumentNullException(nameof(relocationDirectoryInfoFactory));
 }