Ejemplo n.º 1
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.º 2
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.º 3
0
static int FBALocaliseWriteTemplate(TCHAR* pszTemplate)
{
	FILE* fp = _tfopen(pszTemplate, _T("wt"));
	if (fp == NULL) {
		return 1;
	}

	_ftprintf(fp, _T("// translation template for FB Alpha\n\n"));
	_ftprintf(fp, _T("version 0x%06X\n\n"), nBurnVer);

	_ftprintf(fp, _T("// codepage 1252\n\n"));

	EnumResourceTypes(NULL, (ENUMRESTYPEPROC)FBALocaliseEnumResTypeProc, (LONG_PTR)fp);

	fclose(fp);

	return 0;
}
Ejemplo n.º 4
0
void tool_resextract(const std::vector<const char *>& args, const std::vector<const char *>& switches, bool amd64) {
	if (args.size() != 2) {
		printf("usage: resextract <exe-name> <output file>\n");
		exit(5);
	}

	const char *exename = args[0];
	const char *outfile = args[1];

	VDTextOutputFile out(VDTextAToW(outfile).c_str());

	HMODULE hmod = LoadLibraryEx(exename, NULL, LOAD_LIBRARY_AS_DATAFILE);

	if (!hmod)
		throw MyWin32Error("Cannot load executable module \"%s\": %%s", GetLastError(), exename);

	EnumResourceTypes(hmod, EnumResTypesCB, (LONG_PTR)&out);

	FreeLibrary(hmod);
}
Ejemplo n.º 5
0
// ----------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
	ctkCommandLineParser commandLine;
	commandLine.setArgumentPrefix("--", "-");

	commandLine.beginGroup(QString("Option"));
	commandLine.addArgument("help", "h", QVariant::Bool,
		"Display available command line arguments.");
	commandLine.addArgument("list-resources", "l", QVariant::String,
		"List all resources of an executable or library.");
	commandLine.addArgument("add-resource-bitmap", "", QVariant::StringList,
		"Add resource using the provided <path/to/exec/or/lib> <resourceName> and <path/to/resource>");
	commandLine.addArgument("update-resource-ico", "", QVariant::StringList,
		"Add resource using the provided <path/to/exec/or/lib> <resourceName> and <path/to/resource>");
	commandLine.addArgument("delete-resource", "", QVariant::StringList,
		"Delete resource using the provided <path/to/exec/or/lib> <resourceType> <resourceName>");
	commandLine.endGroup();

	bool ok;
	QHash<QString, QVariant> parsedArgs = commandLine.parseArguments(argc, argv, &ok);
	if (!ok)
		{
		QTextStream(stdout, QIODevice::WriteOnly) << "Error parsing arguments : " << commandLine.errorString() << "\n";
		return EXIT_FAILURE;
		}

	if(parsedArgs.contains("help") || parsedArgs.contains("h"))
		{
		QTextStream(stdout, QIODevice::WriteOnly) << commandLine.helpText() << "\n";
		return EXIT_SUCCESS;
		}

	char* exePath;
	HMODULE hExe;       // handle to existing .EXE file

	if(parsedArgs.contains("list-resources") || parsedArgs.contains("l"))
		{
		// Load the .EXE file that contains the dialog box you want to copy.
		exePath =
			(char*) malloc(strlen(parsedArgs.value("list-resources").toString().toStdString().c_str()) * sizeof(char));
		strcpy(exePath, parsedArgs.value("list-resources").toString().toStdString().c_str());
		hExe = loadLibraryEx(TEXT(exePath), NULL, LOAD_LIBRARY_AS_IMAGE_RESOURCE);

		// List all resources
		EnumResourceTypes(hExe, (ENUMRESTYPEPROC)EnumTypesFunc, 0);

		for (int i = 0; i < resources::Resources.size() ; ++i)
			{
			QTextStream(stdout, QIODevice::WriteOnly) << "Type : " << resources::Resources.at(i).Type <<  " -- " << resources::types[resources::Resources.at(i).Type.toInt()] << "\n";
			QTextStream(stdout, QIODevice::WriteOnly) << "\tName : " << resources::Resources.at(i).Name << "\n";
			QTextStream(stdout, QIODevice::WriteOnly) << "\t\tLang : " << resources::Resources.at(i).Lang << "\n";
			}

		// Clean up.
		if (!FreeLibrary(hExe))
			{
			QTextStream(stdout, QIODevice::WriteOnly) << "Could not free executable : " << exePath << "\n";
			return EXIT_FAILURE;
			}
		}

	else if(parsedArgs.contains("delete-resource"))
		{
		QStringList arguments = parsedArgs.value("delete-resource").toStringList();
		exePath = (char*) malloc(strlen(arguments.at(0).toStdString().c_str()) * sizeof(char));
		strcpy(exePath, arguments.at(0).toStdString().c_str());
		hExe = loadLibraryEx(TEXT(exePath), NULL, LOAD_LIBRARY_AS_IMAGE_RESOURCE);

		// List all resources
		EnumResourceTypes(hExe, (ENUMRESTYPEPROC)EnumTypesFunc, 0);
		FreeLibrary(hExe);

		bool resultat = removeResource(arguments.at(0), arguments.at(1), arguments.at(2));
		if(!resultat)
			{
			return EXIT_FAILURE;
			}
		}

	else if(parsedArgs.contains("add-resource-bitmap"))
		{
		QStringList arguments = parsedArgs.value("add-resource-bitmap").toStringList();

		bool result = addResourceBITMAP(arguments.at(0), arguments.at(1), arguments.at(2));
		if(!result)
			{
			QTextStream(stdout, QIODevice::WriteOnly) << "Resource bitmap couldn't be added.\n";
			return EXIT_FAILURE;
			}
		QTextStream(stdout, QIODevice::WriteOnly) << "Resource bitmap added.\n";
		return EXIT_SUCCESS;
		}

	else if(parsedArgs.contains("update-resource-ico"))
		{
		QStringList arguments = parsedArgs.value("update-resource-ico").toStringList();

		bool result = updateResourceICO(arguments.at(0), arguments.at(1), arguments.at(2));
		if(!result)
			{
			QTextStream(stdout, QIODevice::WriteOnly) << "Resource ico couldn't be updated.\n";
			return EXIT_FAILURE;
			}
		QTextStream(stdout, QIODevice::WriteOnly) << "Resource ico updated.\n";
		return EXIT_SUCCESS;
		}

  return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
bool Resource::ListResources(LPSTR exeFile)
{
	HMODULE hMod = LoadLibrary(exeFile);
	if(!hMod) {
		Log::Error("Could not load exe to list 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);

	for(int i = 0; i < ril.count; i++) {
		LPCTSTR lpType = ril.ri[i].lpType;
		LPCTSTR lpName = ril.ri[i].lpName;
		if(lpType == RT_GROUP_ICON) {
			printf("Group Icon\t%04x\n", lpName);
		} else if(lpType == RT_ICON) {
			printf("Icon      \t%04x\n", lpName);
		} else if(lpType == RT_JAR_FILE) {
			HRSRC h = FindResource(hMod, lpName, lpType);
			HGLOBAL hg = LoadResource(hMod, h);
			PBYTE pb = (PBYTE) LockResource(hg);
			DWORD* pd = (DWORD*) pb;
			if(*pd == JAR_RES_MAGIC) {
				printf("JAR File  \t%s\n", &pb[4]);
			} else {
				printf("Unknown   \t%04x, %04x\n", lpType, lpName);
			}
		} else if(lpType == RT_INI_FILE) {
			printf("INI File\n");
		} else if(lpType == RT_SPLASH_FILE) {
			printf("Splash File\n");
		} else if(lpType == RT_ACCELERATOR) {
			printf("Accelerator\t%04x\n", lpName);
		} else if(lpType == RT_ANICURSOR) {
			printf("Ani Cursor\t%04x\n", lpName);
		} else if(lpType == RT_ANIICON) {
			printf("Ani Icon\t%04x\n", lpName);
		} else if(lpType == RT_BITMAP) {
			printf("Bitmap\t%04x\n", lpName);
		} else if(lpType == RT_CURSOR) {
			printf("Cursor\t%04x\n", lpName);
		} else if(lpType == RT_DIALOG) {
			printf("Dialog\t%04x\n", lpName);
		} else if(lpType == RT_DLGINCLUDE) {
			printf("Dialog Include\t%04x\n", lpName);
		} else if(lpType == RT_FONT) {
			printf("Font\t%04x\n", lpName);
		} else if(lpType == RT_FONTDIR) {
			printf("Font Dir\t%04x\n", lpName);
		} else if(lpType == RT_HTML) {
			printf("HTML\t\t%s\n", lpName);
		} else if(lpType == RT_GROUP_CURSOR) {
			printf("Group Cursor\t%04x\n", lpName);
		} else if(lpType == RT_MANIFEST) {
			printf("Manifest\t%04x\n", lpName);
		} else if(lpType == RT_MENU) {
			printf("Menu\t%04x\n", lpName);
		} else if(lpType == RT_MESSAGETABLE) {
			printf("Message Table\t%04x\n", lpName);
		} else if(lpType == RT_PLUGPLAY) {
			printf("Plug Play\t%04x\n", lpName);
		} else if(lpType == RT_RCDATA) {
			printf("RC Data\t%04x\n", lpName);
		} else if(lpType == RT_STRING) {
			printf("String\t%04x\n", lpName);
		} else if(lpType == RT_VERSION) {
			printf("Version\t%04x\n", lpName);
		} else if(lpType == RT_VXD) {
			printf("VXD\t%04x\n", lpName);
		} else {
			printf("Unknown   \t%04x, %04x\n", lpType, lpName);
		}
	}

	free(ril.ri);
	FreeLibrary(hMod);

	return true;
}
Ejemplo n.º 7
0
int main(char* argv[], int argc)
{
	HMODULE hExe;        // handle to .EXE file
	TCHAR szBuffer[80];  // print buffer for info file
	DWORD cbWritten;     // number of bytes written to resource info file
	size_t cbString;     // length of string in szBuffer
	HRESULT hResult;

	// Load the .EXE whose resources you want to list.
	hExe = LoadLibrary(TEXT("f:\\Program\ Files\\Tencent\\QQMusic\\QQMusic.exe"));
	if (hExe == NULL)
	{
		// Add code to fail as securely as possible.
		return;
	}

	// Create a file to contain the resource info.
	g_hFile = CreateFile(TEXT("resinfo.txt"),   // name of file
			GENERIC_READ | GENERIC_WRITE,      // access mode
			0,                                 // share mode
			(LPSECURITY_ATTRIBUTES) NULL,      // default security
			CREATE_ALWAYS,                     // create flags
			FILE_ATTRIBUTE_NORMAL,             // file attributes
			(HANDLE) NULL);                    // no template
	if (g_hFile == INVALID_HANDLE_VALUE)
	{
		//ErrorHandler(TEXT("Could not open file."));
		return;
	}

	// Find all of the loaded file's resources.
	hResult = StringCchPrintf(szBuffer, sizeof(szBuffer)/sizeof(TCHAR),
			TEXT("The file contains the following resources:\r\n\r\n"));
	if (FAILED(hResult))
	{
		// Add code to fail as securely as possible.
		return;
	}

	hResult = StringCchLength(szBuffer, sizeof(szBuffer)/sizeof(TCHAR), &cbString);
	if (FAILED(hResult))
	{
		// Add code to fail as securely as possible.
		return;
	}

	WriteFile(g_hFile,       // file to hold resource info
			szBuffer,            // what to write to the file
			(DWORD) cbString,    // number of bytes in szBuffer
			&cbWritten,          // number of bytes written
			NULL);               // no overlapped I/O

	EnumResourceTypes(hExe,              // module handle
			(ENUMRESTYPEPROC)EnumTypesFunc,  // callback function
			0);                              // extra parameter

	// Unload the executable file whose resources were
	// enumerated and close the file created to contain
	// the resource information.
	FreeLibrary(hExe);
	CloseHandle(g_hFile);
}