Does "love.exe" get the "zip" offset by parsing the PE file structure?
Posted: Sat Sep 21, 2019 7:27 am
Does "love.exe" get the "zip" offset by parsing the PE file structure?
A file like "love.exe+a.zip".
I find this demo.
Is Love2d the same way? Or is it simpler?
A file like "love.exe+a.zip".
I find this demo.
Code: Select all
#include <windows.h>
#include <stdio.h>
DWORD GetPEFileRealSize(LPCTSTR lpszFile)
{
DWORD dwSize = 0;
int i = 0;
HANDLE hFile = CreateFile(lpszFile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
LPBYTE lpBuffer = (LPBYTE)MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
PIMAGE_DOS_HEADER pImgDosHeader = (PIMAGE_DOS_HEADER)lpBuffer;
PIMAGE_NT_HEADERS32 pImgNtHeaders = (PIMAGE_NT_HEADERS32) (lpBuffer + pImgDosHeader->e_lfanew);
PIMAGE_SECTION_HEADER pImgSecHeader = (PIMAGE_SECTION_HEADER) (pImgNtHeaders + 1);
DWORD al = pImgNtHeaders->OptionalHeader.FileAlignment;
dwSize = pImgDosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS32) + pImgNtHeaders->FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER);
if (dwSize%al)
dwSize = (dwSize / al) * al + al;
for (i = 0; i < pImgNtHeaders->FileHeader.NumberOfSections; i++)
dwSize += pImgSecHeader[i].SizeOfRawData;
UnmapViewOfFile(lpBuffer);
CloseHandle(hMap);
CloseHandle(hFile);
}
return dwSize;
}
int main(int argc, char *argv[])
{
printf("%x\n", GetPEFileRealSize(argv[0]));
return 0;
}