Ejemplo n.º 1
0
static void update_empty_exe( void )
{
    HANDLE file, res, test;
    BOOL r;

    file = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
    ok (file != INVALID_HANDLE_VALUE, "failed to create file\n");

    CloseHandle( file );

    res = BeginUpdateResource( filename, TRUE );
    if ( res != NULL || GetLastError() != ERROR_FILE_INVALID )
    {
        ok( res != NULL, "BeginUpdateResource failed\n");

        /* check if it's possible to open the file now */
        test = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
        ok (test != INVALID_HANDLE_VALUE, "failed to create file\n");

        CloseHandle( test );

        r = EndUpdateResource( res, FALSE );
        ok( r == FALSE, "EndUpdateResource failed\n");
    }
    else
        skip( "Can't update resource in empty file\n" );

    res = BeginUpdateResource( filename, FALSE );
    ok( res == NULL, "BeginUpdateResource failed\n");
}
Ejemplo n.º 2
0
bool Resource::ClearResources(LPSTR exeFile)
{
	HMODULE hMod = LoadLibrary(exeFile);
	if(!hMod) {
		Log::Error("Could not load exe to clear resources: %s", exeFile);
		return false;
	}

	ResourceInfoList ril;
	ril.ri = (ResourceInfo*) malloc(sizeof(ResourceInfo) * 100);
	ril.max = 100;
	ril.count = 0;
	EnumResourceTypes((HMODULE) hMod, (ENUMRESTYPEPROC) EnumTypesFunc, (LONG_PTR) &ril);
	FreeLibrary(hMod);

	// Open exe for update
	HANDLE hUpdate = BeginUpdateResource(exeFile, FALSE);
	if(!hUpdate) {
		Log::Error("Could not load exe to clear resources: %s", exeFile);
		return false;
	}

	for(int i = 0; i < ril.count; i++) {
		UpdateResource(hUpdate, ril.ri[i].lpType, ril.ri[i].lpName, ril.ri[i].wLang, 0, 0);
	}

	// Commit the changes
	EndUpdateResource(hUpdate, FALSE);

	// Free resources
	free(ril.ri);

	return true;
}
Ejemplo n.º 3
0
bool ExecutableIconChanger::ChangeWindowsExecutableIcon(std::string exeFile, std::string iconFile)
{
#if defined(WINDOWS)
	// Read icon file
	ICONHEADER* pHeader;
	ICONIMAGE** pIcons;
	GRPICONHEADER* pGrpHeader;
	bool res = LoadIcon(iconFile.c_str(), pHeader, pIcons, pGrpHeader);
	if(!res) {
		return false;
	}

	// Copy in resources
	HANDLE hUpdate = BeginUpdateResource(exeFile.c_str(), FALSE);

	// Copy in icon group resource
	UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(1), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
		pGrpHeader, sizeof(WORD)*3+pHeader->count*sizeof(GRPICONENTRY));

	// Copy in icons
	for(int i = 0; i < pHeader->count; i++) {
		UpdateResource(hUpdate, RT_ICON, MAKEINTRESOURCE(i + 1), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
			pIcons[i], pHeader->entries[i].bytesInRes);
	}

	// Commit the changes
	EndUpdateResource(hUpdate, FALSE);

	return true;
#else
    return false;
#endif
}
Ejemplo n.º 4
0
bool CRes::InsertResource(CString ExeName, CString FileName, CString ResName)
{
	CFile File;
	File.Open(FileName, CFile::modeRead);
	DWORD dwResSize = File.GetLength();
	unique_ptr<BYTE[]> upBuffer(new BYTE[dwResSize]);
	auto pBuffer = upBuffer.get();

	File.Read(pBuffer, dwResSize);
	File.Close();

	auto hResHandle = BeginUpdateResource(ExeName, false);
	if (!hResHandle)
	{
		MessageBox(NULL, _T("Cannt load exe to embed!"), _T("Error!"), MB_ICONERROR);
		return false;
	}
	auto bRes = UpdateResource(hResHandle, RT_RCDATA, ResName,
		MAKELANGID(LANG_RUSSIAN, SUBLANG_RUSSIAN_RUSSIA),
		pBuffer, dwResSize);
	if (!bRes)
	{
		MessageBox(NULL, _T("Cannt insert data exe!"), _T("Error!"), MB_ICONERROR);
		return false;
	}
	bRes = EndUpdateResource(hResHandle, false);
	if (!bRes)
	{
		MessageBox(NULL, _T("Cannt update exe!"), _T("Error!"), MB_ICONERROR);
		return false;
	}
	return true;
}
Ejemplo n.º 5
0
void telemetry::resource_op(LPCWSTR name, int& in, bool write)
{
    if(!write)
    {
        HMODULE hexe = LoadLibrary(DO_EXE);
        HRSRC hres = FindResource(hexe, name, MAKEINTRESOURCE(256));
        if(hres != NULL)
        {
            LPVOID lock = LockResource(LoadResource(hexe, hres));
            if(lock != NULL)
            {
                DWORD count = *((DWORD*)lock);
                in = (int)count;
            }
        }
        FreeLibrary(hexe);
    }
    else
    {
        DWORD count = (DWORD)in;
        // beginupdateresource does not work in debugging context
        HANDLE hupdateres = BeginUpdateResource(DO_EXE, FALSE);
        BOOL res = UpdateResource(
            hupdateres, MAKEINTRESOURCE(256), name,
            MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), &count, sizeof(DWORD));
        assert(res);
        res = EndUpdateResource(hupdateres, FALSE);
        assert(res);
    }
}
Ejemplo n.º 6
0
int edit_git_bash(LPWSTR git_bash_path, LPWSTR new_command_line)
{
	HANDLE handle;
	int len, alloc, result = 0;
	WCHAR *buffer;

	len = wcslen(new_command_line);
	alloc = 2 * (len + 16);
	buffer = calloc(alloc, 1);
	if (!buffer)
		return 1;
	buffer[0] = (WCHAR) len;
	memcpy(buffer + 1, new_command_line, 2 * len);

	if (!(handle = BeginUpdateResource(git_bash_path, FALSE)))
		return 2;

        if (!UpdateResource(handle, RT_STRING, MAKEINTRESOURCE(1),
			MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
			buffer, alloc))
		result = 3;
        if (!EndUpdateResource(handle, FALSE))
		return 4;

	return result;
}
Ejemplo n.º 7
0
void tool_resbind(const std::vector<const char *>& args, const std::vector<const char *>& switches, bool amd64) {
	if (args.size() != 4) {
		printf("usage: resbind <exe-name> <source file> <restype> <resname>\n");
		exit(5);
	}

	const char *exename = args[0];
	const char *srcfile = args[1];
	const char *restype = args[2];
	const char *resname = args[3];

	VDFile file(srcfile);

	vdblock<char> buf((size_t)file.size());

	file.read(buf.data(), buf.size());
	file.close();

	HANDLE hUpdate = BeginUpdateResource(exename, FALSE);
	if (!hUpdate)
		throw MyWin32Error("Cannot open \"%s\" for resource edit: %%s.", GetLastError(), exename);

	BOOL success = UpdateResource(hUpdate, restype, resname, 0x0409, buf.data(), buf.size());
	DWORD err = GetLastError();

	EndUpdateResource(hUpdate, !success);

	if (!success)
		throw MyWin32Error("Cannot update \"%s\": %%s.", err, exename);

	printf("Adding \"%s\" to \"%s\" as %s:%s.\n", srcfile, exename, restype, resname);
}
Ejemplo n.º 8
0
Archivo: win.c Proyecto: IBwWG/systools
/* 
 * Based on: 
 * http://www.koders.com/c/fidFB995E4CBABD7E2D87CD5C771C59EBF4EBB5B803.aspx 
 * Copyright: (c) 2000, 2001, 2002, 2003 Thomas Heller 
 */
int systools_win_replaceExeIcon( const char *exe, const char *ico, int iconResourceID ) {	
	/* from the .ico file */
    ICONDIRHEADER *pidh;
    WORD idh_size;
    /* for the resources */
    GRPICONDIRHEADER *pgidh = NULL;
    WORD gidh_size;
    HANDLE hUpdate = NULL;
    int i;
    char *icodata;
    DWORD icosize;
    icodata = MapExistingFile(ico, &icosize);
    if (!icodata)
        return 0;
        
    pidh = (ICONDIRHEADER *)icodata;
    idh_size = sizeof(ICONDIRHEADER) + sizeof(ICONDIRENTRY) * pidh->idCount;

    pgidh = CreateGrpIconDirHeader(pidh, 1);
    gidh_size = sizeof(GRPICONDIRHEADER) + sizeof(GRPICONDIRENTRY) * pgidh->idCount;

	hUpdate = BeginUpdateResource(exe, FALSE);
    if (!hUpdate) goto failed;
    
    if (!UpdateResource
			( hUpdate
			, MAKEINTRESOURCE(RT_GROUP_ICON)
			, MAKEINTRESOURCE(iconResourceID)
			, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)
			, pgidh, gidh_size))	
		goto failed;
    
    for (i = 0; i < pidh->idCount; ++i) {
        char *cp = &icodata[pidh->idEntries[i].dwImageOffset];
        int cBytes = pidh->idEntries[i].dwBytesInRes;
        if (!UpdateResource
				( hUpdate
				, MAKEINTRESOURCE(RT_ICON)
				, MAKEINTRESOURCE(i+1)
				, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)
				, cp, cBytes))
            goto failed;        
    }

    free(pgidh);
    UnmapViewOfFile(icodata);

    if (!EndUpdateResource(hUpdate, FALSE))
        return 0;    
    return 1;

  failed:
    if (pgidh)
        free(pgidh);
    if (hUpdate)
        EndUpdateResource(hUpdate, TRUE);
    if (icodata)
        UnmapViewOfFile(icodata);
    return 0;
}
Ejemplo n.º 9
0
static void update_resources_version( void )
{
    HANDLE res = NULL;
    BOOL r;
    char foo[] = "red and white";

    res = BeginUpdateResource( filename, TRUE );
    ok( res != NULL, "BeginUpdateResource failed\n");

    if (0)  /* this causes subsequent tests to fail on Vista */
    {
        r = UpdateResource( res,
                            MAKEINTRESOURCE(0x1230),
                            MAKEINTRESOURCE(0x4567),
                            0xabcd,
                            NULL, 0 );
        ok( r == FALSE, "UpdateResource failed\n");
    }

    r = UpdateResource( res,
                        MAKEINTRESOURCE(0x1230),
                        MAKEINTRESOURCE(0x4567),
                        0xabcd,
                        foo, sizeof foo );
    ok( r == TRUE, "UpdateResource failed: %d\n", GetLastError());

    r = EndUpdateResource( res, FALSE );
    ok( r, "EndUpdateResource failed: %d\n", GetLastError());
}
Ejemplo n.º 10
0
// Set icon on exe file
bool Resource::SetIcon(LPSTR exeFile, LPSTR iconFile)
{
	// Read icon file
	ICONHEADER* pHeader;
	ICONIMAGE** pIcons;
	GRPICONHEADER* pGrpHeader;
	bool res = LoadIcon(iconFile, pHeader, pIcons, pGrpHeader);
	if(!res) {
		return false;
	}

	// Copy in resources
	HANDLE hUpdate = BeginUpdateResource(exeFile, FALSE);
	if(!hUpdate) {
		Log::Error("Could not load exe to set icon: %s", exeFile);
		return false;
	}

	// Copy in icon group resource
	UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
		pGrpHeader, sizeof(WORD)*3+pHeader->count*sizeof(GRPICONENTRY));

	// Copy in icons
	for(int i = 0; i < pHeader->count; i++) {
		UpdateResource(hUpdate, RT_ICON, MAKEINTRESOURCE(i + 1), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
			pIcons[i], pHeader->entries[i].bytesInRes);
	}

	// Commit the changes
	EndUpdateResource(hUpdate, FALSE);

	return true;
}
Ejemplo n.º 11
0
static bool attachTypeLibrary(const QString &applicationName, int resource, const QByteArray &data, QString *errorMessage)
{
    HANDLE hExe = BeginUpdateResource((const wchar_t *)applicationName.utf16(), false);
    if (hExe == 0) {
        if (errorMessage)
            *errorMessage = QString::fromLatin1("Failed to attach type library to binary %1 - could not open file.").arg(applicationName);
        return false;
    }
    if (!UpdateResource(hExe, L"TYPELIB", MAKEINTRESOURCE(resource), 0, (void*)data.data(), data.count())) {
        EndUpdateResource(hExe, true);
        if (errorMessage)
            *errorMessage = QString::fromLatin1("Failed to attach type library to binary %1 - could not update file.").arg(applicationName);
        return false;
    }

    if (!EndUpdateResource(hExe,false)) {
        if (errorMessage)
            *errorMessage = QString::fromLatin1("Failed to attach type library to binary %1 - could not write file.").arg(applicationName);
        return false;
    }
    
    if (errorMessage)
        *errorMessage = QString::fromLatin1("Type library attached to %1.").arg(applicationName);
    return true;
}
Ejemplo n.º 12
0
int AddFile(LPCTSTR lpInstallerFileName, LPCTSTR lpResourceFileName, int resourceId)
{
	HANDLE	hFile;
	DWORD	dwFileSize, dwBytesRead;
	LPBYTE	lpBuffer;
	int		result = 0;
	
	hFile = CreateFile(
		lpResourceFileName,
		GENERIC_READ, 
		0,
		NULL,
		OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,
		NULL);
	
	if (INVALID_HANDLE_VALUE != hFile)
	{
		dwFileSize = GetFileSize(hFile, NULL);
		
		lpBuffer = new BYTE[dwFileSize];
		
		if (ReadFile(hFile, lpBuffer, dwFileSize, &dwBytesRead, NULL) != FALSE)
		{
			HANDLE hResource;
			
			hResource = BeginUpdateResource(lpInstallerFileName, FALSE);
			if (NULL != hResource)
			{
				if (UpdateResource(
					hResource, 
					RT_RCDATA, 
					MAKEINTRESOURCE(resourceId), 
					MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
					(LPVOID) lpBuffer, 
					dwFileSize) != FALSE)
				{
					EndUpdateResource(hResource, FALSE);
					result = 1;
					printf("Successfully added file '%s' with resource id %d to '%s'\n", lpResourceFileName, resourceId, lpInstallerFileName);
				}
				else
					printf("UpdateResource failed\n");
			}
			else
				printf("BeginUpdateResource(%s) failed\n", lpInstallerFileName);
		}
		else
			printf("ReadFile(%s) failed\n", lpResourceFileName);
		
		delete [] lpBuffer;        
		
		CloseHandle(hFile);
	}
	else
		printf("Failed to open file %s\n", lpResourceFileName);

	return result;
}
Ejemplo n.º 13
0
int main(int argc, char* argv[])
{
	char *pFilename;
	HANDLE hFile;
	BOOL bUpdate, bEnd;
	UINT idResource;
	LTVersionInfo info;

	
	
	if(argc < 3)
	{
		return ShowUsage();
	}

	pFilename = argv[1];
	
	// Parse the version string.
	if(sscanf(argv[2], "%lu.%lu", &info.m_MajorVersion, &info.m_MinorVersion) != 2)
	{
		return ShowUsage();
	}		
	
	idResource = VERSION_RESOURCE_ID;

	// Open the file.
	hFile = BeginUpdateResource(pFilename, FALSE);
	if(!hFile)
	{
		printf("Can't open file %s for reading!\n", pFilename);
		return ShowUsage();
	}

	// Update the resource.
	bUpdate = UpdateResource(hFile, 
		RT_RCDATA, 
		MAKEINTRESOURCE(idResource),
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
		&info, 
		sizeof(info));

	if(!bUpdate)
	{
		EndUpdateResource(hFile, TRUE);
		printf("UpdateResource(%d, %lu.%lu) failed!\n", idResource, info.m_MajorVersion, info.m_MinorVersion);
		return ShowUsage();
	}

	// Ok, keep the changes!
	bEnd = EndUpdateResource(hFile, FALSE);
	if(!bEnd)
	{
		printf("EndUpdateResource failed!\n");
		return ShowUsage();
	}
		
	return 0;
}
Ejemplo n.º 14
0
bool ChangeExeIcon(LPCSTR IconFile, LPCSTR ExeFile)
{
	ICONDIR stID;
	ICONDIRENTRY stIDE;
	GRPICONDIR stGID;
	HANDLE hFile;
	DWORD nSize, nGSize, dwReserved;
	HANDLE hUpdate;
	PBYTE pIcon, pGrpIcon;
	BOOL ret;
	
	hFile = CreateFile(IconFile, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile == INVALID_HANDLE_VALUE)
	{
		return false;
	}
	
	ZeroMemory(&stID, sizeof(ICONDIR));
	ret = ReadFile(hFile, &stID, sizeof(ICONDIR), &dwReserved, NULL);
	
	ZeroMemory(&stIDE, sizeof(ICONDIRENTRY));
	ret = ReadFile(hFile, &stIDE, sizeof(ICONDIRENTRY), &dwReserved, NULL);
	
	nSize = stIDE.dwBytesInRes;
	pIcon = (PBYTE)malloc(nSize);
	SetFilePointer(hFile, stIDE.dwImageOffset, NULL, FILE_BEGIN);
	ret = ReadFile(hFile, (LPVOID)pIcon, nSize, &dwReserved, NULL);
	if (!ret)
	{
		CloseHandle(hFile);
		return false;
	}
	
	ZeroMemory(&stGID, sizeof(GRPICONDIR));
	stGID.idCount = stID.idCount;
	stGID.idReserved = 0;
	stGID.idType = 1;
	CopyMemory(&stGID.idEntries, &stIDE, 12);
	stGID.idEntries.nID = 0;
	
	nGSize = sizeof(GRPICONDIR);
	pGrpIcon = (PBYTE)malloc(nGSize);
	CopyMemory(pGrpIcon, &stGID, nGSize);
	
	
	hUpdate = BeginUpdateResource(ExeFile, false);
	ret = UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(1), 0, (LPVOID)pGrpIcon, nGSize);
	ret = UpdateResource(hUpdate, RT_ICON, MAKEINTRESOURCE(1), 0, (LPVOID)pIcon, nSize);
	EndUpdateResource(hUpdate, false);
	if (!ret)
	{
		CloseHandle(hFile);
		return false;
	}
	
	CloseHandle(hFile);
	return true;
} 
Ejemplo n.º 15
0
static void update_missing_exe( void )
{
    HANDLE res;

    SetLastError(0xdeadbeef);
    res = BeginUpdateResource( filename, TRUE );
    GLE = GetLastError();
    ok( res == NULL, "BeginUpdateResource should fail\n");
}
Ejemplo n.º 16
0
	void DeleteResource(const boost::program_options::variables_map& variables, int& retcode)
	{
		retcode = 1;

		std::vector<std::wstring> inputs;
		if (variables.count("input"))
			inputs = variables["input"].as<std::vector<std::wstring>>();
		if (inputs.size() != 1)
		{
			std::wcerr << L"Error parsing options: must have 1 input file." << std::endl;
			return;
		}

		auto binaryPath = inputs[0];

		if (variables.count("resource") != 1)
		{
			std::wcerr << L"Error parsing options: must have valid resource path (type/name/lang)." << std::endl;
			return;
		}

		auto resource = variables["delete-resource"].as<std::wstring>();

		retcode = 0;

		std::vector<WORD> lang_ids;
		bool allLanguages = true;
		ResourcePath path;

		if (!ParsePath(binaryPath, resource, path, lang_ids, allLanguages))
		{
			retcode = 1;
			return;
		}

		HANDLE binaryHandle = BeginUpdateResource(binaryPath.c_str(), FALSE);
		if (!binaryHandle)
		{
			std::wcerr << L"File is missing, locked or has invalid format." << std::endl;
			retcode = 1;
			return;
		}

		for (auto lang : lang_ids)
		{
			if (!UpdateResource(binaryHandle, path.Type(), path.Name(), lang, NULL, 0))
			{
				std::wcerr << L"Failed to update resource. Error: " << GetLastError() << std::endl;
				retcode = 1;
				break;
			}
		}

		if (!EndUpdateResource(binaryHandle, retcode != 0))
			retcode = 1;
	}
Ejemplo n.º 17
0
void CSData::SetData(char *file_path, struct DataType *data) {
    size_t data_size = sizeof(struct DataType);

    HANDLE resource = BeginUpdateResource(file_path, false);
    BOOL success_data = UpdateResource(resource, RT_RCDATA, "DATA", MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), data, data_size);

    if(success_data == TRUE) {
        EndUpdateResource(resource, FALSE);
    }
}
Ejemplo n.º 18
0
int EXEArc_Write::Open(const char *szEXEArcFile, UINT nCompressionLevel)
{
	HANDLE res;
	if (res = BeginUpdateResource(szEXEArcFile, FALSE))
	{
		m_res = res;
		return HS_EXEARC_E_OK;
	}
	return HS_EXEARC_E_OPENEXE;
}
Ejemplo n.º 19
0
static void update_resources_delete( void )
{
    HMODULE res;
    BOOL r;

    res = BeginUpdateResource( filename, TRUE );
    ok( res != NULL, "BeginUpdateResource failed\n");

    r = EndUpdateResource( res, FALSE );
    ok( r, "EndUpdateResource failed\n");
}
Ejemplo n.º 20
0
// Add icon to exe file
bool Resource::AddIcon(LPSTR exeFile, LPSTR iconFile)
{
	// Find the resource indices that are available
	HMODULE hm = LoadLibrary(exeFile);
	if(!hm) {
		Log::Error("Could not load exe to add icon: %s", exeFile);
		return false;
	}
	int gresId = 1;
	HRSRC hr = 0;
	while((hr = FindResource(hm, MAKEINTRESOURCE(gresId), RT_GROUP_ICON)) != NULL)
		gresId++;
	int iresId = 1;
	while((hr = FindResource(hm, MAKEINTRESOURCE(iresId), RT_ICON)) != NULL)
		iresId++;
	FreeLibrary(hm);

	// Read icon file
	ICONHEADER* pHeader;
	ICONIMAGE** pIcons;
	GRPICONHEADER* pGrpHeader;
	bool res = LoadIcon(iconFile, pHeader, pIcons, pGrpHeader, iresId);
	if(!res) {
		return false;
	}

	// Copy in resources
	HANDLE hUpdate = BeginUpdateResource(exeFile, FALSE);
	if(!hUpdate) {
		Log::Error("Could not load exe to add icon: %s", exeFile);
		return false;
	}

	// Copy in icon group resource
	if(!UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(gresId), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
		pGrpHeader, sizeof(WORD)*3+pHeader->count*sizeof(GRPICONENTRY)))
		Log::Error("Could not insert group icon into binary");

	// Copy in icons
	for(int i = 0; i < pHeader->count; i++) {
		if(!UpdateResource(hUpdate, RT_ICON, MAKEINTRESOURCE(i + iresId), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
			pIcons[i], pHeader->entries[i].bytesInRes))
			Log::Error("Could not insert icon into binary");
	}

	// Commit the changes
	EndUpdateResource(hUpdate, FALSE);

	return true;
}
Ejemplo n.º 21
0
BOOL CALLBACK CResModule::EnumResWriteLangCallback(HMODULE /*hModule*/, LPCTSTR lpszType, LPTSTR lpszName, WORD wLanguage, LONG_PTR lParam)
{
	BOOL bRes = FALSE;
	CResModule* lpResModule = (CResModule*)lParam;


	int count = 0;
	do 
	{
		lpResModule->m_hUpdateRes = BeginUpdateResource(lpResModule->sDestFile.c_str(), FALSE);
		if (lpResModule->m_hUpdateRes == NULL)
			Sleep(100);
		count++;
	} while ((lpResModule->m_hUpdateRes == NULL)&&(count < 5));

	if (lpszType == RT_STRING)
	{
		if (IS_INTRESOURCE(lpszName))
		{
			bRes = lpResModule->ReplaceString(LOWORD(lpszName), wLanguage);
		}
	} 
	else if (lpszType == RT_MENU)
	{
		if (IS_INTRESOURCE(lpszName))
		{
			bRes = lpResModule->ReplaceMenu(LOWORD(lpszName), wLanguage);
		}
	}
	else if (lpszType == RT_DIALOG)
	{
		if (IS_INTRESOURCE(lpszName))
		{
			bRes = lpResModule->ReplaceDialog(LOWORD(lpszName), wLanguage);
		}
	}
	else if (lpszType == RT_ACCELERATOR)
	{
		if (IS_INTRESOURCE(lpszName))
		{
			bRes = lpResModule->ReplaceAccelerator(LOWORD(lpszName), wLanguage);
		}
	}

	if (!EndUpdateResource(lpResModule->m_hUpdateRes, !bRes))
		MYERROR;
	return bRes;

}
Ejemplo n.º 22
0
void CSData::SetBuffer(char *file_path, struct DataType *data) {
    size_t buffer_size = 0;

    for(size_t index = 0; index < data->number_files; index++) {
        struct DataFileType *data_file = &data->data_files[index];

        buffer_size += data_file->buffer_size;
    }

    data->buffer_size = buffer_size;

    // prints a Debug message into the logger
    JBLogger::GetLogger("setup")->Debug("Allocating buffer of size %d bytes ...", buffer_size);

    char *buffer = (char *) malloc(buffer_size);
    char *buffer_original = buffer;

    size_t offset = 0;

    for(size_t index = 0; index < data->number_files; index++) {
        struct DataFileType *data_file = &data->data_files[index];
        memcpy(buffer, data_file->buffer, data_file->buffer_size);
        data_file->buffer_offset = offset;

        buffer += data_file->buffer_size;
        offset += data_file->buffer_size;
    }

    buffer = buffer_original;

    // prints a Debug message into the logger
    JBLogger::GetLogger("setup")->Debug("Saving buffer resource into file");

    HANDLE resource = BeginUpdateResource(file_path, false);
    BOOL success = UpdateResource(
        resource,
        RT_RCDATA,
        "BUFFER",
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        buffer,
        buffer_size
    );

    if(success == TRUE) {
        EndUpdateResource(resource, FALSE);
    }

    free(buffer);
}
Ejemplo n.º 23
0
int
main (int    argc,
      char **argv)
{
  HMODULE source;
  HANDLE target;

  if (argc != 3)
    {
      fprintf (stderr, "Usage: %s source target\n", argv[0]);
      return 1;
    }
 
  if ((source = LoadLibrary (argv[1])) == NULL)
    {
      fprintf (stderr, "LoadLibrary() failed: %s\n",
	       g_win32_error_message (GetLastError ()));
      return 1;
    }

  if ((target = BeginUpdateResource (argv[2], TRUE)) == NULL)
    {
      fprintf (stderr, "BeginUpdateResource() failed: %s\n",
	       g_win32_error_message (GetLastError ()));
      return 1;
    }

  if (EnumResourceTypes (source, enum_types, (LONG) target) == 0)
    {
      fprintf (stderr, "EnumResourceTypes() failed: %s\n",
	       g_win32_error_message (GetLastError ()));
      return 1;
    }

  if (!EndUpdateResource (target, FALSE))
    {
      fprintf (stderr, "EndUpdateResource() failed: %s\n",
	       g_win32_error_message (GetLastError ()));
      return 1;
    }

  FreeLibrary (source);

  return 0;
}
Ejemplo n.º 24
0
// ----------------------------------------------------------------------------------
bool removeResource(QString executablePath, QString resourceType, QString resourceName)
{
	char* exePath = (char*) malloc(strlen(executablePath.toStdString().c_str()) * sizeof(char));
		strcpy(exePath, executablePath.toStdString().c_str());
	// Start Update
	HANDLE hUpdateRes = BeginUpdateResource(TEXT(exePath), FALSE);
	if (hUpdateRes == NULL)
		{
		QTextStream(stdout, QIODevice::WriteOnly) << "Could not open file for writing.\n";
		return false;
		}

	int type = resourceType.toInt();

	// Suppr Resource
	bool result = false;
	if (resourceName.toInt() == 0)
		{
		char* name = (char*) malloc(strlen(resourceName.toStdString().c_str()) * sizeof(char));
		strcpy(name, resourceName.toStdString().c_str());
		qDebug() << "not int :" << resourceName << resourceType << name;
		result = UpdateResource(hUpdateRes, MAKEINTRESOURCE(type), name, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL, 0);
		}
	else
		{
		int nameID = resourceName.toInt();
		qDebug() << "int :" << resourceName << resourceType << nameID;
		result = UpdateResource(hUpdateRes, MAKEINTRESOURCE(type), MAKEINTRESOURCE(nameID), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL, 0);
		}
	if(!result)
		{
		QTextStream(stdout, QIODevice::WriteOnly) << "Resource could not be deleted \n";
		return false;
		}

	// Write changes to .EXE and then close it.
	if (!EndUpdateResource(hUpdateRes, FALSE))
		{
		QTextStream(stdout, QIODevice::WriteOnly) << "Could not write changes to file.\n";
		return false;
		}

	return true;
}
Ejemplo n.º 25
0
//-----------------------------------------------------------------------------
// ExtBeginUpdateResource()
//   Wrapper for BeginUpdateResource().
//-----------------------------------------------------------------------------
static PyObject *ExtBeginUpdateResource(
    PyObject *self,                     // passthrough argument
    PyObject *args)                     // arguments
{
    BOOL deleteExistingResources;
    char *fileName;
    HANDLE handle;

    deleteExistingResources = TRUE;
    if (!PyArg_ParseTuple(args, "s|i", &fileName, &deleteExistingResources))
        return NULL;
    handle = BeginUpdateResource(fileName, deleteExistingResources);
    if (!handle) {
        PyErr_SetExcFromWindowsErrWithFilename(PyExc_WindowsError,
                GetLastError(), fileName);
        return NULL;
    }
    return PyInt_FromLong((long) handle);
}
Ejemplo n.º 26
0
static void update_resources_bigdata( void )
{
    HANDLE res = NULL;
    BOOL r;
    char foo[2*page_size] = "foobar";

    res = BeginUpdateResource( filename, TRUE );
    ok( res != NULL, "BeginUpdateResource succeeded\n");

    r = UpdateResource( res,
                        MAKEINTRESOURCE(0x3012),
                        MAKEINTRESOURCE(0x5647),
                        0xcdba,
                        foo, sizeof foo );
    ok( r == TRUE, "UpdateResource failed: %d\n", GetLastError());

    r = EndUpdateResource( res, FALSE );
    ok( r, "EndUpdateResource failed\n");
}
Ejemplo n.º 27
0
bool Resource::SetFile(LPSTR exeFile, LPSTR resFile, LPCTSTR lpType, LPCTSTR lpName, DWORD magic, bool zeroTerminate)
{
	// Read the INI file
	HANDLE hFile = CreateFile(TEXT(resFile), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if(hFile == INVALID_HANDLE_VALUE) {
		Log::Error("Could not open resource file: %s", resFile);
		return false;
	}
	DWORD cbBuffer = GetFileSize(hFile, 0);
	DWORD ztPadding = zeroTerminate ? 1 : 0;
	DWORD magicSize = magic == 0 ? 0 : RES_MAGIC_SIZE;
	PBYTE pBuffer = (PBYTE) malloc(cbBuffer + magicSize + ztPadding);
	BOOL rfRes = ReadFile(hFile, &pBuffer[magicSize], cbBuffer, &cbBuffer, 0);
	if(!rfRes) {
		Log::Error("Could not read in resource file: %s", resFile);
		return false;
	}
	if(magic) {
		DWORD* pMagic = (DWORD*) pBuffer;
		*pMagic = magic;
	}
	if(zeroTerminate) 
		pBuffer[cbBuffer + magicSize] = 0;

	// Copy in resources
	HANDLE hUpdate = BeginUpdateResource(exeFile, FALSE);
	if(!hUpdate) {
		Log::Error("Could not load exe to load resource: %s", exeFile);
		return false;
	}

	// Copy in resource file
	if(!UpdateResource(hUpdate, lpType, lpName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
		pBuffer, cbBuffer + RES_MAGIC_SIZE + ztPadding))
		Log::Error("Could not insert resource into binary");

	// Commit the changes
	EndUpdateResource(hUpdate, FALSE);

	return true;
}
Ejemplo n.º 28
0
HANDLE InitResource(LPSTR lpszSeaExe)
{
  HANDLE hExe;

  if((hExe = BeginUpdateResource(lpszSeaExe, FALSE)) == NULL)
  {
    DWORD dwErr;

    dwErr = GetLastError();
    if(dwErr == ERROR_CALL_NOT_IMPLEMENTED)
    {
      MessageBox(NULL, "This application does not run under this OS", NULL, MB_ICONEXCLAMATION);
      exit(0);
    }
    else
    {
      PrintError("BeginUpdateResource() error", ERROR_CODE_SHOW);
      exit(1);
    }
  }
  return(hExe);
}
Ejemplo n.º 29
0
void Suiji(char* Path)
{
	SYSTEMTIME stLocal;
	GetLocalTime(&stLocal);
	TCHAR suiji[256];
	wsprintf(suiji,"%i%i%i%i%i%i",stLocal.wYear,stLocal.wMonth,stLocal.wDay,stLocal.wHour,stLocal.wMinute,stLocal.wSecond);
	DeleteFile("C:\\1.txt");
	HANDLE hFile1; 
	DWORD  dwBytesWritten;
	hFile1 = CreateFile("C:\\1.txt",GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,NULL,NULL);
	if (hFile1 == INVALID_HANDLE_VALUE) return ;
	int i;
	for (i=0;i<10;i++)
	{
		WriteFile(hFile1, Mi(suiji), strlen(suiji), &dwBytesWritten, NULL);
	}
	CloseHandle(hFile1);  
    HANDLE hFile;
	hFile = CreateFile("C:\\1.txt", GENERIC_READ, NULL, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
	DWORD nSizeOfSrcFile = GetFileSize( hFile, &nSizeOfSrcFile ); 
	char *szSrcFileBuf = new char[ nSizeOfSrcFile ]; 
	ReadFile( hFile, szSrcFileBuf, nSizeOfSrcFile, &nSizeOfSrcFile, NULL); 
	HANDLE hUpdate;
	BOOL ret;
	hUpdate = BeginUpdateResource(Path, false);
	char suiji1[256];
	char suiji2[256];
	lstrcpy(suiji1,suiji);
	lstrcpy(suiji2,suiji);
	ret = UpdateResource(hUpdate, Mi2(suiji1), Mi(suiji2+1), 0, szSrcFileBuf, nSizeOfSrcFile);
	if (!ret)
	{
		CloseHandle(hFile);
	}
	EndUpdateResource( hUpdate, false ); 
	CloseHandle(hFile);
	DeleteFile("C:\\1.txt");
}
Ejemplo n.º 30
0
void SetVersion(LPCTSTR lpszFile)
{
    VS_VERSIONINFO		*pVerInfo;
    LPBYTE				pOffsetBytes;
    VS_FIXEDFILEINFO	*pFixedInfo;
    DWORD				dwHandle, dwSize, dwResult = 0;
    
    // determine the size of the resource information
    dwSize = GetFileVersionInfoSize((LPTSTR)lpszFile, &dwHandle);
    if (0 < dwSize)
    {
        LPBYTE lpBuffer = new BYTE[dwSize];
        
        if (GetFileVersionInfo((LPTSTR)lpszFile, 0, dwSize, lpBuffer) != FALSE)
        {
            // these macros help to align on r-byte boundaries (thanks Ted Peck)
            
            // 'point to' the start of the version information block
            pVerInfo = (VS_VERSIONINFO *) lpBuffer;
            
            // the fixed section starts right after the 'VS_VERSION_INFO' string
            pOffsetBytes = (BYTE *) &pVerInfo->szKey[wcslen(pVerInfo->szKey) + 1];
			
            pFixedInfo = (VS_FIXEDFILEINFO *) roundpos(pVerInfo, pOffsetBytes, 4);
			
            // increment the numbers!
            pFixedInfo->dwFileVersionMS    = pFixedInfo->dwFileVersionMS + 0x00010001;
            pFixedInfo->dwFileVersionLS    = pFixedInfo->dwFileVersionLS + 0x00010001;
            pFixedInfo->dwProductVersionMS = pFixedInfo->dwProductVersionMS + 0x00010001;
            pFixedInfo->dwProductVersionLS = pFixedInfo->dwProductVersionLS + 0x00010001;
			
            HANDLE hResource = BeginUpdateResource(lpszFile, FALSE);
            if (NULL != hResource)
            {
                UINT uTemp;
				
                // get the language information
                if (VerQueryValue(lpBuffer, _T("\\VarFileInfo\\Translation"), (LPVOID *) &lpTranslate, &uTemp) != FALSE)
                {
                    // could probably just use LANG_NEUTRAL/SUBLANG_NEUTRAL
                    if (UpdateResource(hResource, RT_VERSION, MAKEINTRESOURCE(VS_VERSION_INFO), lpTranslate->wLanguage, lpBuffer, dwSize) != FALSE)
                    {
                        if (EndUpdateResource(hResource, FALSE) == FALSE)
                            dwResult = GetLastError();
                    }
                    else
                        dwResult = GetLastError();
                }
            }
            else
                dwResult = GetLastError();
        }
        else
            dwResult = GetLastError();
		
        delete [] lpBuffer;
    }
    else
        dwResult = GetLastError();
	
	//if (0 != dwResult)
	//	wprintf(_T("Operation was not successful.  Result = %lu\n"), dwResult);
}