Re: [PATCH v46 0/2] MR10295: Fix ImageGetDigestStream
eric pouech (@epo) commented about dlls/imagehlp/integrity.c:
- */ - nt_hdr->OptionalHeader.SizeOfInitializedData = 0; - nt_hdr->OptionalHeader.SizeOfImage = 0; - nt_hdr->OptionalHeader.CheckSum = 0; - size = sizeof(nt_hdr->Signature) + sizeof(nt_hdr->FileHeader) + - nt_hdr->FileHeader.SizeOfOptionalHeader; + NumberOfRvaAndSizes = nthdr32->OptionalHeader.NumberOfRvaAndSizes; + DataDirectory = nthdr32->OptionalHeader.DataDirectory; + if( nthdr32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC ) + { + nthdr64 = (IMAGE_NT_HEADERS64 *)nthdr32; + NumberOfRvaAndSizes = nthdr64->OptionalHeader.NumberOfRvaAndSizes; + DataDirectory = nthdr64->OptionalHeader.DataDirectory; + /* NOTE: Fields up to SizeOfStackCommit are the same size/offset, except for ImageBase */ + } + memcpy(DataDirBackup, DataDirectory, sizeof(DataDirBackup)); it looks a bit ackward to save ntheader+section headers, modify the memory of mapping, then restore the saved bits in the mapping
it would be more straightforward to keep mapping as is, and allocate a buffer for tempering ntheader + section headers and pass pointer into this buffer in the callback this is how native behaves BTW this would save one memcpy and avoids dirty:ing the mapping which results with COW of the modified pages -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10295#note_137581
participants (1)
-
eric pouech (@epo)