Does "love.exe" get the "zip" offset by parsing the PE file structure?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
2Ha
Prole
Posts: 3
Joined: Fri Sep 20, 2019 3:01 am

Does "love.exe" get the "zip" offset by parsing the PE file structure?

Post by 2Ha »

Does "love.exe" get the "zip" offset by parsing the PE file structure?
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;
}
Is Love2d the same way? Or is it simpler?
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Does "love.exe" get the "zip" offset by parsing the PE file structure?

Post by zorg »

executable files have headers, so the important stuff is at the start of the file.
zip archives have footers, meaning the important stuff is at the very end of the file.
So...:
[EXE header][EXE data][ZIP data][ZIP footer]

I would say that yeah, it probably needs to parse the file structure found in the footer, otherwise it would literally not be able to read anything from them; i'm just saying it's not hard finding the literal end of the file. :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3549
Joined: Sun Oct 18, 2015 2:58 pm

Re: Does "love.exe" get the "zip" offset by parsing the PE file structure?

Post by pgimeno »

Indeed, LÖVE is completely agnostic about the executable headers of any particular operating system it runs on. It reads the ZIP footer. Fused executables work with Linux ELF too, for example.
2Ha
Prole
Posts: 3
Joined: Fri Sep 20, 2019 3:01 am

Re: Does "love.exe" get the "zip" offset by parsing the PE file structure?

Post by 2Ha »

Thanks to everyone, I am currently adding knowledge about the zip structure.
Post Reply

Who is online

Users browsing this forum: No registered users and 93 guests