Ejemplo n.º 1
0
PVIRTUALCHANNELENTRY freerdp_load_dynamic_addin(LPCSTR pszFileName,
        LPCSTR pszPath, LPCSTR pszEntryName)
{
	LPSTR pszAddinInstallPath = freerdp_get_dynamic_addin_install_path();
	PVIRTUALCHANNELENTRY entry = NULL;
	BOOL bHasExt = TRUE;
	PCSTR pszExt;
	size_t cchExt = 0;
	HINSTANCE library = NULL;
	size_t cchFileName;
	size_t cchFilePath;
	LPSTR pszAddinFile = NULL;
	LPSTR pszFilePath = NULL;
	LPSTR pszRelativeFilePath = NULL;
	size_t cchAddinFile;
	size_t cchAddinInstallPath;

	if (!pszFileName || !pszEntryName)
		goto fail;

	cchFileName = strlen(pszFileName);

	/* Get file name with prefix and extension */
	if (FAILED(PathCchFindExtensionA(pszFileName, cchFileName + 1, &pszExt)))
	{
		pszExt = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
		cchExt = strlen(pszExt);
		bHasExt = FALSE;
	}

	if (bHasExt)
	{
		pszAddinFile = _strdup(pszFileName);

		if (!pszAddinFile)
			goto fail;
	}
	else
	{
		cchAddinFile = cchFileName + cchExt + 2 + sizeof(FREERDP_SHARED_LIBRARY_PREFIX);
		pszAddinFile = (LPSTR) malloc(cchAddinFile + 1);

		if (!pszAddinFile)
			goto fail;

		sprintf_s(pszAddinFile, cchAddinFile, FREERDP_SHARED_LIBRARY_PREFIX"%s%s",
		          pszFileName, pszExt);
	}
	cchAddinFile = strlen(pszAddinFile);

	/* If a path is provided prefix the library name with it. */
	if (pszPath)
	{
		size_t relPathLen = strlen(pszPath) + cchAddinFile + 1;
		pszRelativeFilePath = calloc(relPathLen, sizeof(CHAR));
		if (!pszRelativeFilePath)
			goto fail;
		sprintf_s(pszRelativeFilePath, relPathLen, "%s", pszRelativeFilePath);
		NativePathCchAppendA(pszRelativeFilePath, relPathLen, pszAddinFile);
	}
	else
		pszRelativeFilePath = _strdup(pszAddinFile);

	if (!pszRelativeFilePath)
		goto fail;

	/* If a system prefix path is provided try these locations too. */
	if (pszAddinInstallPath)
	{
		cchAddinInstallPath = strlen(pszAddinInstallPath);
		cchFilePath = cchAddinInstallPath + cchFileName + 32;
		pszFilePath = (LPSTR) malloc(cchFilePath + 1);

		if (!pszFilePath)
			goto fail;

		CopyMemory(pszFilePath, pszAddinInstallPath, cchAddinInstallPath);
		pszFilePath[cchAddinInstallPath] = '\0';
		NativePathCchAppendA((LPSTR) pszFilePath, cchFilePath + 1, pszRelativeFilePath);
	}
	else
		pszFilePath = _strdup(pszRelativeFilePath);

	library = LoadLibraryA(pszFilePath);

	if (!library)
		goto fail;

	entry = (PVIRTUALCHANNELENTRY)GetProcAddress(library, pszEntryName);

fail:
	free(pszRelativeFilePath);
	free(pszAddinFile);
	free(pszFilePath);
	free(pszAddinInstallPath);
	if (!entry && library)
		FreeLibrary(library);
	return entry;
}
Ejemplo n.º 2
0
void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszEntryName)
{
	void* entry;
	BOOL bHasExt;
	PCSTR pszExt;
	size_t cchExt;
	HINSTANCE library;
	size_t cchFileName;
	LPSTR pszFilePath;
	size_t cchFilePath;
	LPSTR pszAddinFile;
	size_t cchAddinFile;
	LPSTR pszAddinInstallPath;
	size_t cchAddinInstallPath;

	entry = NULL;
	cchExt = 0;
	bHasExt = TRUE;
	cchFileName = strlen(pszFileName);

	if (PathCchFindExtensionA(pszFileName, cchFileName + 1, &pszExt) != S_OK)
	{
		pszExt = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
		cchExt = strlen(pszExt);
		bHasExt = FALSE;
	}

	pszAddinInstallPath = freerdp_get_dynamic_addin_install_path();
	cchAddinInstallPath = strlen(pszAddinInstallPath);

	cchFilePath = cchAddinInstallPath + cchFileName + 32;
	pszFilePath = (LPSTR) malloc(cchFilePath + 1);

	if (bHasExt)
	{
		pszAddinFile = _strdup(pszFileName);
		cchAddinFile = strlen(pszAddinFile);
	}
	else
	{
		cchAddinFile = cchFileName + cchExt + 2;
		pszAddinFile = (LPSTR) malloc(cchAddinFile + 1);
		sprintf_s(pszAddinFile, cchAddinFile, "%s%s", pszFileName, pszExt);
		cchAddinFile = strlen(pszAddinFile);
	}

	CopyMemory(pszFilePath, pszAddinInstallPath, cchAddinInstallPath);
	pszFilePath[cchAddinInstallPath] = '\0';

	NativePathCchAppendA((LPSTR) pszFilePath, cchFilePath + 1, pszAddinFile);

	library = LoadLibraryA(pszFilePath);

	free(pszAddinInstallPath);
	free(pszAddinFile);
	free(pszFilePath);

	if (!library)
		return NULL;

	entry = GetProcAddress(library, pszEntryName);

	if (entry)
		return entry;

	FreeLibrary(library);
	return entry;
}
Ejemplo n.º 3
0
int TestPathCchFindExtension(int argc, char* argv[])
{
	PCSTR pszExt;
	PCSTR pszTmp;
	HRESULT hr;

	/* Test invalid args */

	hr = PathCchFindExtensionA(NULL, sizeof(testPathExtension), &pszExt);
	if (SUCCEEDED(hr))
	{
		printf("PathCchFindExtensionA unexpectedly succeeded with pszPath = NULL. result: 0x%08X\n", (ULONG)hr);
		return -1;
	}

	hr = PathCchFindExtensionA(testPathExtension, 0, &pszExt);
	if (SUCCEEDED(hr))
	{
		printf("PathCchFindExtensionA unexpectedly succeeded with cchPath = 0. result: 0x%08X\n", (ULONG)hr);
		return -1;
	}

	hr = PathCchFindExtensionA(testPathExtension, sizeof(testPathExtension), NULL);
	if (SUCCEEDED(hr))
	{
		printf("PathCchFindExtensionA unexpectedly succeeded with ppszExt = NULL. result: 0x%08X\n", (ULONG)hr);
		return -1;
	}


	/* Test missing null-termination of pszPath */

	hr = PathCchFindExtensionA("c:\\45.789", 9, &pszExt); /* nb: correct would be 10 */
	if (SUCCEEDED(hr))
	{
		printf("PathCchFindExtensionA unexpectedly succeeded with unterminated pszPath. result: 0x%08X\n", (ULONG)hr);
		return -1;
	}


	/* Test passing of an empty terminated string (must succeed) */

	pszExt = NULL;
	pszTmp = "";
	hr = PathCchFindExtensionA(pszTmp, 1, &pszExt);
	if (hr != S_OK)
	{
		printf("PathCchFindExtensionA failed with an empty terminated string. result: 0x%08X\n", (ULONG)hr);
		return -1;
	}
	/* pszExt must point to the strings terminating 0 now */
	if (pszExt != pszTmp)
	{
		printf("PathCchFindExtensionA failed with an empty terminated string:  pszExt pointer mismatch\n");
		return -1;
	}


	/* Test a path without file extension (must succeed) */

	pszExt = NULL;
	pszTmp = "c:\\4.678\\";
	hr = PathCchFindExtensionA(pszTmp, 10, &pszExt);
	if (hr != S_OK)
	{
		printf("PathCchFindExtensionA failed with a directory path. result: 0x%08X\n", (ULONG)hr);
		return -1;
	}
	/* The extension must not have been found and pszExt must point to the
	 * strings terminating NULL now */
	if (pszExt != &pszTmp[9])
	{
		printf("PathCchFindExtensionA failed with a directory path: pszExt pointer mismatch\n");
		return -1;
	}


	/* Non-special tests */

	pszExt = NULL;
	if (PathCchFindExtensionA(testPathExtension, sizeof(testPathExtension), &pszExt) != S_OK)
	{
		printf("PathCchFindExtensionA failure: expected S_OK\n");
		return -1;
	}

	if (!pszExt || strcmp(pszExt, ".exe"))
	{
		printf("PathCchFindExtensionA failure: unexpected extension\n");
		return -1;
	}

	printf("Extension: %s\n", pszExt);

	return 0;
}