VBoxGuestInstallHelper.cpp revision c7814cf6e1240a519cbec0441e033d0e2470ed00
/* $Id$ */
/** @file
* VBoxGuestInstallHelper - Various helper routines for Windows guest installer.
*/
/*
* Copyright (C) 2011-2012 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"
/* Required structures/defines of VBoxTray. */
#include "../../VBoxTray/VBoxTrayMsg.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/**
* 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)
{
{
}
}
}
return hr;
}
{
if (!g_stacktop || !*g_stacktop)
else
{
if (pStack)
{
}
}
return hr;
}
{
{
else
"FormatMessage failed! Error = %ld", GetLastError());
}
else
}
{
if (pwString)
}
{
if (!pwString)
else
{
{
}
else
{
}
}
return hr;
}
static HANDLE vboxIPCConnect(void)
{
while (1)
{
GENERIC_READ | /* Read and write access. */
0, /* No sharing. */
NULL, /* Default security attributes. */
OPEN_EXISTING, /* Opens existing pipe. */
0, /* Default attributes. */
NULL); /* No template file. */
/* Break if the pipe handle is valid. */
if (hPipe != INVALID_HANDLE_VALUE)
break;
/* Exit if an error other than ERROR_PIPE_BUSY occurs. */
if (GetLastError() != ERROR_PIPE_BUSY)
return NULL;
/* All pipe instances are busy, so wait for 20 seconds. */
return NULL;
}
/* The pipe connected; change to message-read mode. */
&dwMode, /* New pipe mode. */
NULL, /* Don't set maximum bytes. */
NULL); /* Don't set maximum time. */
if (!fSuccess)
return NULL;
return hPipe;
}
{
}
{
return hr;
}
/**
* 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();
{
if (hPipe)
{
}
}
/* Push simple return value on stack. */
}
{
return TRUE;
}