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.