forked from Squirrel/Squirrel.Windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteZipToSetup.cpp
More file actions
65 lines (51 loc) · 1.45 KB
/
WriteZipToSetup.cpp
File metadata and controls
65 lines (51 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// WriteZipToSetup.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int wmain(int argc, wchar_t* argv[])
{
if (argc != 3) {
goto fail;
}
wprintf(L"Setup: %s, Zip: %s\n", argv[1], argv[2]);
// Read the entire zip file into memory, yolo
HANDLE hFile = CreateFile(argv[2], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
printf("Can't open Zip file\n");
return -1;
}
BY_HANDLE_FILE_INFORMATION fileInfo;
if (!GetFileInformationByHandle(hFile, &fileInfo)) {
goto fail;
}
BYTE* pBuf = new BYTE[fileInfo.nFileSizeLow + 0x1000];
BYTE* pCurrent = pBuf;
DWORD dwBytesRead;
printf("Starting to read in Zip file!\n");
do {
if (!ReadFile(hFile, pCurrent, 0x1000, &dwBytesRead, NULL)) {
printf("Failed to read file! 0x%p\n", GetLastError());
goto fail;
}
pCurrent += dwBytesRead;
} while (dwBytesRead > 0);
printf("Updating Resource!\n");
HANDLE hRes = BeginUpdateResource(argv[1], false);
if (!hRes) {
printf("Couldn't open setup.exe for writing\n");
goto fail;
}
if (!UpdateResource(hRes, L"DATA", (LPCWSTR)131, 0x0409, pBuf, fileInfo.nFileSizeLow)) {
printf("Failed to update resource\n");
goto fail;
}
printf("Finished!\n");
if (!EndUpdateResource(hRes, false)) {
printf("Failed to update resource\n");
goto fail;
}
printf("It worked!\n");
return 0;
fail:
printf("Usage: WriteZipToSetup [Setup.exe template] [Zip File]\n");
return -1;
}