[misc] add arbitrary buffer allocation to GetResource()

* If duplicate is TRUE and len is non-zero, then a buffer of len size,
  padded with zeroes, is allocated for the resource.
This commit is contained in:
Pete Batard 2020-02-19 12:41:13 +00:00
parent 841b79f45d
commit b8579c04da
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
6 changed files with 27 additions and 12 deletions

View File

@ -2,7 +2,7 @@
* Rufus: The Reliable USB Formatting Utility
* DOS boot file extraction, from the FAT12 floppy image in diskcopy.dll
* (MS WinME DOS) or from the embedded FreeDOS resource files
* Copyright © 2011-2017 Pete Batard <pete@akeo.ie>
* Copyright © 2011-2020 Pete Batard <pete@akeo.ie>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -317,6 +317,7 @@ static BOOL ExtractMSDOS(const char* path)
goto out;
}
DiskImageSize = 0;
DiskImage = (BYTE*)GetResource(hDLL, MAKEINTRESOURCEA(1), "BINFILE", "disk image", &DiskImageSize, TRUE);
if (DiskImage == NULL)
goto out;

View File

@ -1633,6 +1633,7 @@ static void InitDialog(HWND hDlg)
uprintf(APPLICATION_NAME " " APPLICATION_ARCH " v%d.%d.%d%s%s", rufus_version[0], rufus_version[1], rufus_version[2],
IsAlphaOrBeta(), (ini_file != NULL)?"(Portable)":"");
for (i=0; i<ARRAYSIZE(resource); i++) {
len = 0;
buf = (char*)GetResource(hMainInstance, resource[i], _RT_RCDATA, "ldlinux_sys", &len, TRUE);
if (buf == NULL) {
uprintf("Warning: could not read embedded Syslinux v%d version", i+4);

View File

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.9.1616"
CAPTION "Rufus 3.9.1617"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -394,8 +394,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,9,1616,0
PRODUCTVERSION 3,9,1616,0
FILEVERSION 3,9,1617,0
PRODUCTVERSION 3,9,1617,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -413,13 +413,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.9.1616"
VALUE "FileVersion", "3.9.1617"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.9.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.9.1616"
VALUE "ProductVersion", "3.9.1617"
END
END
BLOCK "VarFileInfo"

View File

@ -549,10 +549,17 @@ out:
return ret;
}
/*
* Get a resource from the RC. If needed that resource can be duplicated.
* If duplicate is true and len is non-zero, the a zeroed buffer of 'len'
* size is allocated for the resource. Else the buffer is allocate for
* the resource size.
*/
unsigned char* GetResource(HMODULE module, char* name, char* type, const char* desc, DWORD* len, BOOL duplicate)
{
HGLOBAL res_handle;
HRSRC res;
DWORD res_len;
unsigned char* p = NULL;
res = FindResourceA(module, name, type);
@ -565,18 +572,23 @@ unsigned char* GetResource(HMODULE module, char* name, char* type, const char* d
uprintf("Could not load resource '%s': %s\n", desc, WindowsErrorString());
goto out;
}
*len = SizeofResource(module, res);
res_len = SizeofResource(module, res);
if (duplicate) {
p = (unsigned char*)malloc(*len);
if (*len == 0)
*len = res_len;
p = (unsigned char*)calloc(*len, 1);
if (p == NULL) {
uprintf("Coult not allocate resource '%s'\n", desc);
uprintf("Could not allocate resource '%s'\n", desc);
goto out;
}
memcpy(p, LockResource(res_handle), *len);
memcpy(p, LockResource(res_handle), res_len);
if (res_len < *len)
uprintf("Warning: Resource '%s' was truncated by %d bytes!\n", desc, *len - res_len);
} else {
p = (unsigned char*)LockResource(res_handle);
}
*len = res_len;
out:
return p;

View File

@ -1856,7 +1856,7 @@ LPCDLGTEMPLATE GetDialogTemplate(int Dialog_ID)
int i;
const char thai_id[] = "th-TH";
size_t len;
DWORD size;
DWORD size = 0;
DWORD* dwBuf;
WCHAR* wBuf;
LPCDLGTEMPLATE rcTemplate = (LPCDLGTEMPLATE) GetResource(hMainInstance, MAKEINTRESOURCEA(Dialog_ID),

View File

@ -2,7 +2,7 @@
*
* Copyright 2003 Lars Munch Christensen - All Rights Reserved
* Copyright 1998-2008 H. Peter Anvin - All Rights Reserved
* Copyright 2012-2018 Pete Batard
* Copyright 2012-2020 Pete Batard
*
* Based on the Linux installer program for SYSLINUX by H. Peter Anvin
*
@ -185,6 +185,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system)
} else {
for (i=0; i<2; i++) {
static_sprintf(tmp, "%s.%s", ldlinux, ldlinux_ext[i]);
syslinux_ldlinux_len[i] = 0;
syslinux_ldlinux[i] = GetResource(hMainInstance, resource[use_v5?1:0][i],
_RT_RCDATA, tmp, &syslinux_ldlinux_len[i], TRUE);
if (syslinux_ldlinux[i] == NULL)