Owen Rudge orudge@codeweavers.com writes:
- sd = &nt_hdr.OptionalHeader.DataDirectory[IMAGE_FILE_SECURITY_DIRECTORY];
- sd->Size = dwSize;
- sd->VirtualAddress = dwOfs;
- TRACE("size = %x addr = %x\n", sd->Size, sd->VirtualAddress);
- /* write the header back again */
- count = SetFilePointer(handle, dos_hdr.e_lfanew, NULL, FILE_BEGIN);
- if (count == INVALID_SET_FILE_POINTER)
return FALSE;
- count = 0;
- r = WriteFile(handle, &nt_hdr, sizeof nt_hdr, &count, NULL);
The virtual address is not necessarily the same as the disk offset. Also you should check the various header sizes and magic numbers. The existing code is broken in that respect too, but as long as it was only reading it wasn't a big problem. Once we start modifying the file it needs to be much more robust.
The virtual address is not necessarily the same as the disk offset.
Actually, it seems that the security directory is one of the few places where a disk offset is intentionally used. Trying to compensate for the virtual address results in failure in this case.
I have been amending the code to make it more robust however, and shall submit a revised version tomorrow.