Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/exploits/CVE-2010-0232/common/ResourceLoader.c
Views: 11784
/*!1* @file ResourceLoader.c2* @brief Helper functions for loading embedded resources.3*/4#include <Windows.h>5#include "common.h"67/*!8* @brief Load a resource from the given module as a raw array of bytes.9* @param hModule Handle to the module containing the resource.10* @param uResourceId ID of the resource to load.11* @param lpType The type of resource being loaded.12* @param pBuffer Pointer to the buffer that will receive the loaded resource.13* @param pBufferSize Pointer to the variable that will receive the size of \c pBuffer.14* @returns Indication of success or failure.15*/16DWORD resource_extract_raw(HMODULE hModule, UINT uResourceId, LPCSTR lpType, LPBYTE* pBuffer, LPDWORD pBufferSize)17{18DWORD dwResult = FALSE;19DWORD dwResourceSize = 0;20LPBYTE pResource = NULL;21HRSRC hResource = NULL;22HGLOBAL hResData = NULL;23LPVOID lpResData = NULL;2425*pBuffer = NULL;26*pBufferSize = 0;2728do29{30if ((hResource = FindResourceA(hModule, MAKEINTRESOURCEA(uResourceId), lpType)) == NULL) {31dwResult = GetLastError();32dprintf("[RES] Unable to find resource %d type %s", uResourceId, lpType);33break;34}3536if ((dwResourceSize = SizeofResource(hModule, hResource)) == 0) {37dwResult = GetLastError();38dprintf("[RES] Unable to find resource size for %d type %s", uResourceId, lpType);39break;40}4142if ((pResource = (LPBYTE)malloc(dwResourceSize)) == NULL) {43dwResult = ERROR_NOT_ENOUGH_MEMORY;44dprintf("[RES] Unable to allocate memory for resource %d type %s size %u", uResourceId, lpType, dwResourceSize);45break;46}4748if ((hResData = LoadResource(hModule, hResource)) == NULL) {49dwResult = GetLastError();50dprintf("[RES] Unable to load resource for %d type %s", uResourceId, lpType);51break;52}5354if ((lpResData = LockResource(hResData)) == NULL) {55dwResult = GetLastError();56dprintf("[RES] Unable to lock resource for %d type %s", uResourceId, lpType);57break;58}5960memcpy_s(pResource, dwResourceSize, lpResData, dwResourceSize);6162// Locked resource don't need to be unlocked. If we get here, we've won!63dwResult = ERROR_SUCCESS;64*pBuffer = lpResData;65*pBufferSize = dwResourceSize;6667} while (0);6869if (dwResult != ERROR_SUCCESS && pResource != NULL) {70free(pResource);71}7273return dwResult;74}7576/*!77* @brief Free up memory that was allocated when loading the resource.78* @param lpBuffer Pointer to the allocated buffer.79* @returns \c ERROR_SUCCESS80*/81DWORD resource_destroy(LPBYTE lpBuffer)82{83if (lpBuffer != NULL)84{85free(lpBuffer);86}87return ERROR_SUCCESS;88}8990