PATMGuest.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/** @file
*
* PATMGuest - Guest OS Patching Manager (non-generic)
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_PATM
#include "PATMInternal.h"
#include <VBox/disopcode.h>
#include <string.h>
/*
* ntdll!KiFastSystemCall:
* 7c90eb8b 8bd4 mov edx,esp
* 7c90eb8d 0f34 sysenter
* 7c90eb8f 90 nop
* 7c90eb90 90 nop
* 7c90eb91 90 nop
* 7c90eb92 90 nop
* 7c90eb93 90 nop
* ntdll!KiFastSystemCallRet:
* 7c90eb94 c3 ret
*
* ntdll!KiIntSystemCall:
* 7c90eba5 8d542408 lea edx,[esp+0x8]
* 7c90eba9 cd2e int 2e
* 7c90ebab c3 ret
*
*/
/*
* D0101B6C: pushf [9C]
* D0101B6D: push CS [0E]
* D0101B6E: push ESI [56]
* D0101B6F: cli [FA]
*/
/**
* Check Windows XP sysenter heuristics and install patch
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param pInstrGC GC Instruction pointer for sysenter
* @param pPatchRec Patch structure
*
*/
{
int rc, i;
/* Guest OS specific patch; check heuristics first */
/* check the epilog of KiFastSystemCall */
if ( VBOX_FAILURE(rc)
{
return VERR_PATCHING_REFUSED;
}
/* Now search for KiIntSystemCall */
for (i=0;i<64;i++)
{
if(VBOX_FAILURE(rc))
{
break;
}
{
lpfnKiIntSystemCall = pInstrGC + i;
/* Found it! */
break;
}
}
if (i == 64)
{
Log(("KiIntSystemCall not found!!\n"));
return VERR_PATCHING_REFUSED;
}
{
Log(("KiFastSystemCall and KiIntSystemCall not in the same page!!\n"));
return VERR_PATCHING_REFUSED;
}
// make a copy of the guest code bytes that will be overwritten
/* Now we simply jump from the fast version to the 'old and slow' system call */
uTemp[0] = 0xE9;
if (VBOX_FAILURE(rc))
{
return VERR_PATCHING_REFUSED;
}
#ifdef DEBUG
Log(("Sysenter Patch code ----------------------------------------------------------\n"));
Log(("Sysenter Patch code ends -----------------------------------------------------\n"));
#endif
return VINF_SUCCESS;
}
/**
* Patch OpenBSD interrupt handler prefix
*
* @returns VBox status code.
* @param pVM The VM to operate on
* @param pCpu Disassembly state of instruction.
* @param pInstrGC GC Instruction pointer for instruction
* @param pInstrHC GC Instruction pointer for instruction
* @param pPatchRec Patch structure
*
*/
int PATMPatchOpenBSDHandlerPrefix(PVM pVM, PDISCPUSTATE pCpu, RTGCPTR pInstrGC, uint8_t *pInstrHC, PPATMPATCHREC pPatchRec)
{
int rc;
/* Guest OS specific patch; check heuristics first */
{
return VERR_PATCHING_REFUSED;
}
/* Found it; patch the pushf block (including push cs) */
}
/**
* Install guest OS specific patch
*
* @returns VBox status code.
* @param pVM The VM to operate on
* @param pCpu Disassembly state of instruction.
* @param pInstrGC GC Instruction pointer for instruction
* @param pInstrHC GC Instruction pointer for instruction
* @param pCallerGC GC address of caller; CODE32_UNKNOWN_CALLER if unknown
* @param pPatchRec Patch structure
*
*/
int PATMInstallGuestSpecificPatch(PVM pVM, PDISCPUSTATE pCpu, RTGCPTR pInstrGC, uint8_t *pInstrHC, PPATMPATCHREC pPatchRec)
{
int rc;
/** @todo might have to check if the patch crosses a page boundary. Currently not necessary, but that might change in the future!! */
{
case OP_SYSENTER:
if (VBOX_FAILURE(rc))
{
return VERR_PATCHING_REFUSED;
}
return VINF_SUCCESS;
case OP_PUSHF:
/* OpenBSD guest specific patch for the following code block:
*
* pushf
* push cs <- dangerous because of DPL 0 tests
* push esi
* cli
*/
default:
return VERR_PATCHING_REFUSED;
}
return VERR_PATCHING_REFUSED;
}