VBoxGuestInstallHelper.cpp revision 69635e74efb7b4a3c97269b3268d4354cebb36d0
/* $Id$ */
/** @file
* VBoxGuestInstallHelper - Various helper routines for Windows guest installer.
*/
/*
* Copyright (C) 2011-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <windows.h>
#include <atlconv.h>
#include <stdlib.h>
#include <tchar.h>
#include <strsafe.h>
#include "exdll.h"
#include <iprt/initterm.h>
#include <iprt/localipc.h>
/* Required structures/defines of VBoxTray. */
#include "../../VBoxTray/VBoxTrayMsg.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/**
* @todo Clean up this DLL, use more IPRT in here!
*/
/**
* Pops (gets) a value from the internal NSIS stack.
* Since the supplied popstring() method easily can cause buffer
* overflows, use vboxPopString() instead!
*
* @return HRESULT
* @param pszDest Pointer to pre-allocated string to store result.
* @param cchDest Size (in characters) of pre-allocated string.
*/
{
if (!g_stacktop || !*g_stacktop)
else
{
if (pStack)
{
{
}
}
else
}
return hr;
}
{
if (!g_stacktop || !*g_stacktop)
else
{
if (pStack)
{
}
}
return hr;
}
{
{
else
"FormatMessage failed! Error = %ld", GetLastError());
}
else
}
/**
* Connects to VBoxTray IPC under the behalf of the user running
* in the current thread context.
*
* @return IPRT status code.
* @param phSession Where to store the IPC session.
*/
{
int rc = VINF_SUCCESS;
if (!fRc)
if (RT_SUCCESS(rc))
{
char *pszUserName;
if (RT_SUCCESS(rc))
{
char szPipeName[255];
{
}
else
rc = VERR_NO_MEMORY;
}
}
return rc;
}
{
if (pwString)
}
{
if (!pwString)
else
{
{
}
else
{
}
}
return hr;
}
/**
* Loads a system DLL.
*
* @returns Module handle or NULL
* @param pszName The DLL name.
*/
{
return NULL;
return LoadLibraryA(szPath);
}
/**
* Disables the Windows File Protection for a specified file
* using an undocumented SFC API call. Don't try this at home!
*
* @param hwndParent Window handle of parent.
* @param string_size Size of variable string.
* @param variables The actual variable string.
* @param stacktop Pointer to a pointer to the current stack.
*/
{
EXDLL_INIT();
{
{
if (g_pfnSfcFileException == NULL)
{
/* If we didn't get the proc address with the call above, try it harder with
* the (zero based) index of the function list. */
if (g_pfnSfcFileException == NULL)
}
}
else
{
{
}
}
if (hSFC)
}
}
/**
* Retrieves a file's architecture (x86 or amd64).
*
* @param hwndParent Window handle of parent.
* @param string_size Size of variable string.
* @param variables The actual variable string.
* @param stacktop Pointer to a pointer to the current stack.
*/
{
EXDLL_INIT();
{
if (pFh)
{
/* Assume the file is invalid. */
/* Do some basic validation. */
/* Check for "MZ" header (DOS stub). */
{
/* Seek to 0x3C to get the PE offset. */
{
/* Read actual offset of PE signature. */
{
/* ... and seek to it. */
{
/* Validate PE signature. */
{
}
}
}
}
}
/* Validation successful? */
{
/** @todo When we need to do more stuff here, we probably should
* mmap the file w/ a struct so that we easily could access
* all the fixed size stuff. Later. */
/* Jump to machine type (first entry, 2 bytes):
* Use absolute PE offset retrieved above. */
{
{
switch (wMachineType)
{
case 0x14C: /* Intel 86 */
pushstring("x86");
break;
case 0x8664: /* AMD64 / x64 */
pushstring("amd64");
break;
default:
break;
}
}
else
}
else
}
}
else
}
}
/**
* Retrieves a file's vendor.
*
* @param hwndParent Window handle of parent.
* @param string_size Size of variable string.
* @param variables The actual variable string.
* @param stacktop Pointer to a pointer to the current stack.
*/
{
EXDLL_INIT();
{
if (dwInfoSize)
{
if (pFileInfo)
{
{
{
{
}
else
}
else
}
}
else
}
else
}
}
/**
* Shows a balloon message using VBoxTray's notification area in the
* Windows task bar.
*
* @param hwndParent Window handle of parent.
* @param string_size Size of variable string.
* @param variables The actual variable string.
* @param stacktop Pointer to a pointer to the current stack.
*/
{
EXDLL_INIT();
char szMsg[256];
char szTitle[128];
/** @todo Do we need to restore the stack on failure? */
{
RTR3InitDll(0);
if (pIpcMsg)
{
/* Stuff in the strings. */
/* Pop off the values in reverse order from the stack. */
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
}
if (RT_FAILURE(rc))
}
}
else
}
/* Push simple return value on stack. */
}
{
return TRUE;
}