Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/byakugan/detours/disasm.cpp
Views: 11779
//////////////////////////////////////////////////////////////////////////////1//2// Detours Disassembler (disasm.cpp of detours.lib)3//4// Microsoft Research Detours Package, Version 2.1.5//6// Copyright (c) Microsoft Corporation. All rights reserved.7//89#include <windows.h>10#include <limits.h>1112// #define DETOUR_DEBUG 113#define DETOURS_INTERNAL1415#include "detours.h"1617#if !defined(DETOURS_X86) && !defined(DETOURS_X64) && !defined(DETOURS_IA64)18#error Must define one of DETOURS_X86, DETOURS_X64, or DETOURS_IA6419#endif2021#undef ASSERT22#define ASSERT(x)2324//////////////////////////////////////////////////////////////////////////////25//26// Function:27// DetourCopyInstructionEx(PVOID pDst,28// PVOID pSrc,29// PVOID *ppTarget,30// LONG *plExtra)31// Purpose:32// Copy a single instruction from pSrc to pDst.33//34// Arguments:35// pDst:36// Destination address for the instruction. May be NULL in which37// case DetourCopyInstruction is used to measure an instruction.38// If not NULL then the source instruction is copied to the39// destination instruction and any relative arguments are adjusted.40// pSrc:41// Source address of the instruction.42// ppTarget:43// Out parameter for any target instruction address pointed to by44// the instruction. For example, a branch or a jump insruction has45// a target, but a load or store instruction doesn't. A target is46// another instruction that may be executed as a result of this47// instruction. ppTarget may be NULL.48// plExtra:49// Out parameter for the number of extra bytes needed by the50// instruction to reach the target. For example, lExtra = 3 if the51// instruction had an 8-bit relative offset, but needs a 32-bit52// relative offset.53//54// Returns:55// Returns the address of the next instruction (following in the source)56// instruction. By subtracting pSrc from the return value, the caller57// can determinte the size of the instruction copied.58//59// Comments:60// By following the pTarget, the caller can follow alternate61// instruction streams. However, it is not always possible to determine62// the target based on static analysis. For example, the destination of63// a jump relative to a register cannot be determined from just the64// instruction stream. The output value, pTarget, can have any of the65// following outputs:66// DETOUR_INSTRUCTION_TARGET_NONE:67// The instruction has no targets.68// DETOUR_INSTRUCTION_TARGET_DYNAMIC:69// The instruction has a non-deterministic (dynamic) target.70// (i.e. the jump is to an address held in a register.)71// Address: The instruction has the specified target.72//73// When copying instructions, DetourCopyInstruction insures that any74// targets remain constant. It does so by adjusting any IP relative75// offsets.76//7778PVOID WINAPI DetourCopyInstruction(PVOID pDst, PVOID pSrc, PVOID *ppTarget)79{80return DetourCopyInstructionEx(pDst, pSrc, ppTarget, NULL);81}8283//////////////////////////////////////////////////// X86 and X64 Disassembler.84//85// Includes full support for all x86 chips prior to the Pentium III.86//87#if defined(DETOURS_X64) || defined(DETOURS_X86)8889class CDetourDis90{91public:92CDetourDis(PBYTE *ppbTarget, LONG *plExtra);9394PBYTE CopyInstruction(PBYTE pbDst, PBYTE pbSrc);95static BOOL SanityCheckSystem();9697public:98struct COPYENTRY;99typedef const COPYENTRY * REFCOPYENTRY;100101typedef PBYTE (CDetourDis::* COPYFUNC)(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc);102103enum {104DYNAMIC = 0x1u,105ADDRESS = 0x2u,106NOENLARGE = 0x4u,107RAX = 0x8u,108109SIB = 0x10u,110RIP = 0x20u,111NOTSIB = 0x0fu,112};113struct COPYENTRY114{115ULONG nOpcode : 8; // Opcode116ULONG nFixedSize : 4; // Fixed size of opcode117ULONG nFixedSize16 : 4; // Fixed size when 16 bit operand118ULONG nModOffset : 4; // Offset to mod/rm byte (0=none)119LONG nRelOffset : 4; // Offset to relative target.120LONG nTargetBack : 4; // Offset back to absolute or rip target121ULONG nFlagBits : 4; // Flags for DYNAMIC, etc.122COPYFUNC pfCopy; // Function pointer.123};124125protected:126// These macros define common uses of nFixedSize..pfCopy.127#define ENTRY_CopyBytes1 1, 1, 0, 0, 0, 0, &CDetourDis::CopyBytes128#define ENTRY_CopyBytes1Dynamic 1, 1, 0, 0, 0, DYNAMIC, &CDetourDis::CopyBytes129#define ENTRY_CopyBytes2 2, 2, 0, 0, 0, 0, &CDetourDis::CopyBytes130#define ENTRY_CopyBytes2Jump 2, 2, 0, 1, 0, 0, &CDetourDis::CopyBytes131#define ENTRY_CopyBytes2CantJump 2, 2, 0, 1, 0, NOENLARGE, &CDetourDis::CopyBytes132#define ENTRY_CopyBytes2Dynamic 2, 2, 0, 0, 0, DYNAMIC, &CDetourDis::CopyBytes133#define ENTRY_CopyBytes3 3, 3, 0, 0, 0, 0, &CDetourDis::CopyBytes134#define ENTRY_CopyBytes3Dynamic 3, 3, 0, 0, 0, DYNAMIC, &CDetourDis::CopyBytes135#define ENTRY_CopyBytes3Or5 5, 3, 0, 0, 0, 0, &CDetourDis::CopyBytes136#define ENTRY_CopyBytes3Or5Rax 5, 3, 0, 0, 0, RAX, &CDetourDis::CopyBytes137#define ENTRY_CopyBytes3Or5Target 5, 3, 0, 1, 0, 0, &CDetourDis::CopyBytes138#define ENTRY_CopyBytes5Or7Dynamic 7, 5, 0, 0, 0, DYNAMIC, &CDetourDis::CopyBytes139#define ENTRY_CopyBytes3Or5Address 5, 3, 0, 0, 0, ADDRESS, &CDetourDis::CopyBytes140#define ENTRY_CopyBytes4 4, 4, 0, 0, 0, 0, &CDetourDis::CopyBytes141#define ENTRY_CopyBytes5 5, 5, 0, 0, 0, 0, &CDetourDis::CopyBytes142#define ENTRY_CopyBytes7 7, 7, 0, 0, 0, 0, &CDetourDis::CopyBytes143#define ENTRY_CopyBytes2Mod 2, 2, 1, 0, 0, 0, &CDetourDis::CopyBytes144#define ENTRY_CopyBytes2Mod1 3, 3, 1, 0, 1, 0, &CDetourDis::CopyBytes145#define ENTRY_CopyBytes2ModOperand 6, 4, 1, 0, 4, 0, &CDetourDis::CopyBytes146#define ENTRY_CopyBytes3Mod 3, 3, 2, 0, 0, 0, &CDetourDis::CopyBytes147#define ENTRY_CopyBytesPrefix 1, 1, 0, 0, 0, 0, &CDetourDis::CopyBytesPrefix148#define ENTRY_CopyBytesRax 1, 1, 0, 0, 0, 0, &CDetourDis::CopyBytesRax149#define ENTRY_Copy0F 1, 1, 0, 0, 0, 0, &CDetourDis::Copy0F150#define ENTRY_Copy66 1, 1, 0, 0, 0, 0, &CDetourDis::Copy66151#define ENTRY_Copy67 1, 1, 0, 0, 0, 0, &CDetourDis::Copy67152#define ENTRY_CopyF6 0, 0, 0, 0, 0, 0, &CDetourDis::CopyF6153#define ENTRY_CopyF7 0, 0, 0, 0, 0, 0, &CDetourDis::CopyF7154#define ENTRY_CopyFF 0, 0, 0, 0, 0, 0, &CDetourDis::CopyFF155#define ENTRY_Invalid 1, 1, 0, 0, 0, 0, &CDetourDis::Invalid156#define ENTRY_End 0, 0, 0, 0, 0, 0, NULL157158PBYTE CopyBytes(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc);159PBYTE CopyBytesPrefix(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc);160PBYTE CopyBytesRax(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc);161162PBYTE Invalid(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc);163164PBYTE AdjustTarget(PBYTE pbDst, PBYTE pbSrc, LONG cbOp,165LONG cbTargetOffset, LONG cbTargetSize);166167protected:168PBYTE Copy0F(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc);169PBYTE Copy66(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc);170PBYTE Copy67(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc);171PBYTE CopyF6(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc);172PBYTE CopyF7(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc);173PBYTE CopyFF(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc);174175protected:176static const COPYENTRY s_rceCopyTable[257];177static const COPYENTRY s_rceCopyTable0F[257];178static const BYTE s_rbModRm[256];179180protected:181BOOL m_bOperandOverride;182BOOL m_bAddressOverride;183BOOL m_bRaxOverride;184185PBYTE * m_ppbTarget;186LONG * m_plExtra;187188LONG m_lScratchExtra;189PBYTE m_pbScratchTarget;190BYTE m_rbScratchDst[64];191};192193PVOID WINAPI DetourCopyInstructionEx(PVOID pDst,194PVOID pSrc,195PVOID *ppTarget,196LONG *plExtra)197{198CDetourDis oDetourDisasm((PBYTE*)ppTarget, plExtra);199return oDetourDisasm.CopyInstruction((PBYTE)pDst, (PBYTE)pSrc);200}201202/////////////////////////////////////////////////////////// Disassembler Code.203//204CDetourDis::CDetourDis(PBYTE *ppbTarget, LONG *plExtra)205{206m_bOperandOverride = FALSE;207m_bAddressOverride = FALSE;208m_bRaxOverride = FALSE;209210m_ppbTarget = ppbTarget ? ppbTarget : &m_pbScratchTarget;211m_plExtra = plExtra ? plExtra : &m_lScratchExtra;212213*m_ppbTarget = (PBYTE)DETOUR_INSTRUCTION_TARGET_NONE;214*m_plExtra = 0;215}216217PBYTE CDetourDis::CopyInstruction(PBYTE pbDst, PBYTE pbSrc)218{219// Configure scratch areas if real areas are not available.220if (NULL == pbDst) {221pbDst = m_rbScratchDst;222}223if (NULL == pbSrc) {224// We can't copy a non-existent instruction.225SetLastError(ERROR_INVALID_DATA);226return NULL;227}228229// Figure out how big the instruction is, do the appropriate copy,230// and figure out what the target of the instruction is if any.231//232REFCOPYENTRY pEntry = &s_rceCopyTable[pbSrc[0]];233return (this->*pEntry->pfCopy)(pEntry, pbDst, pbSrc);234}235236PBYTE CDetourDis::CopyBytes(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc)237{238#ifdef DETOURS_X64239#error Feature not supported in this release.240241242243244#else245LONG nBytesFixed = (pEntry->nFlagBits & ADDRESS)246? (m_bAddressOverride ? pEntry->nFixedSize16 : pEntry->nFixedSize)247: (m_bOperandOverride ? pEntry->nFixedSize16 : pEntry->nFixedSize);248#endif249250LONG nBytes = nBytesFixed;251LONG nRelOffset = pEntry->nRelOffset;252LONG cbTarget = nBytes - nRelOffset;253if (pEntry->nModOffset > 0) {254BYTE bModRm = pbSrc[pEntry->nModOffset];255BYTE bFlags = s_rbModRm[bModRm];256257nBytes += bFlags & NOTSIB;258259if (bFlags & SIB) {260BYTE bSib = pbSrc[pEntry->nModOffset + 1];261262if ((bSib & 0x07) == 0x05) {263if ((bModRm & 0xc0) == 0x00) {264nBytes += 4;265}266else if ((bModRm & 0xc0) == 0x40) {267nBytes += 1;268}269else if ((bModRm & 0xc0) == 0x80) {270nBytes += 4;271}272}273cbTarget = nBytes - nRelOffset;274}275else if (bFlags & RIP) {276#ifdef DETOURS_X64277#error Feature not supported in this release.278279280#endif281}282}283CopyMemory(pbDst, pbSrc, nBytes);284285if (nRelOffset) {286*m_ppbTarget = AdjustTarget(pbDst, pbSrc, nBytesFixed, nRelOffset, cbTarget);287#ifdef DETOURS_X64288#error Feature not supported in this release.289290291292#endif293}294if (pEntry->nFlagBits & NOENLARGE) {295*m_plExtra = -*m_plExtra;296}297if (pEntry->nFlagBits & DYNAMIC) {298*m_ppbTarget = (PBYTE)DETOUR_INSTRUCTION_TARGET_DYNAMIC;299}300return pbSrc + nBytes;301}302303PBYTE CDetourDis::CopyBytesPrefix(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc)304{305CopyBytes(pEntry, pbDst, pbSrc);306307pEntry = &s_rceCopyTable[pbSrc[1]];308return (this->*pEntry->pfCopy)(pEntry, pbDst + 1, pbSrc + 1);309}310311PBYTE CDetourDis::CopyBytesRax(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc)312{313CopyBytes(pEntry, pbDst, pbSrc);314315if (*pbSrc & 0x8) {316m_bRaxOverride = TRUE;317}318319pEntry = &s_rceCopyTable[pbSrc[1]];320return (this->*pEntry->pfCopy)(pEntry, pbDst + 1, pbSrc + 1);321}322323PBYTE CDetourDis::AdjustTarget(PBYTE pbDst, PBYTE pbSrc, LONG cbOp,324LONG cbTargetOffset, LONG cbTargetSize)325{326PBYTE pbTarget = NULL;327PVOID pvTargetAddr = &pbDst[cbTargetOffset];328LONG_PTR nOldOffset = 0;329330switch (cbTargetSize) {331case 1:332nOldOffset = (LONG_PTR)*(CHAR*&)pvTargetAddr;333break;334case 2:335nOldOffset = (LONG_PTR)*(SHORT*&)pvTargetAddr;336break;337case 4:338nOldOffset = (LONG_PTR)*(LONG*&)pvTargetAddr;339break;340case 8:341nOldOffset = (LONG_PTR)*(LONG_PTR*&)pvTargetAddr;342break;343default:344ASSERT(!"cbTargetSize is invalid.");345break;346}347348pbTarget = pbSrc + cbOp + nOldOffset;349LONG_PTR nNewOffset = nOldOffset - (pbDst - pbSrc);350351switch (cbTargetSize) {352case 1:353*(CHAR*&)pvTargetAddr = (CHAR)nNewOffset;354if (nNewOffset < SCHAR_MIN || nNewOffset > SCHAR_MAX) {355*m_plExtra = sizeof(ULONG_PTR) - 1;356}357break;358case 2:359*(SHORT*&)pvTargetAddr = (SHORT)nNewOffset;360if (nNewOffset < SHRT_MIN || nNewOffset > SHRT_MAX) {361*m_plExtra = sizeof(ULONG_PTR) - 2;362}363break;364case 4:365*(LONG*&)pvTargetAddr = (LONG)nNewOffset;366if (nNewOffset < LONG_MIN || nNewOffset > LONG_MAX) {367*m_plExtra = sizeof(ULONG_PTR) - 4;368}369break;370case 8:371*(LONG_PTR*&)pvTargetAddr = (LONG_PTR)nNewOffset;372break;373}374ASSERT(pbDst + cbOp + nNewOffset == pbTarget);375return pbTarget;376}377378PBYTE CDetourDis::Invalid(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc)379{380(void)pbDst;381(void)pEntry;382ASSERT(!"Invalid Instruction");383return pbSrc + 1;384}385386////////////////////////////////////////////////////// Individual Bytes Codes.387//388PBYTE CDetourDis::Copy0F(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc)389{390CopyBytes(pEntry, pbDst, pbSrc);391392pEntry = &s_rceCopyTable0F[pbSrc[1]];393return (this->*pEntry->pfCopy)(pEntry, pbDst + 1, pbSrc + 1);394}395396PBYTE CDetourDis::Copy66(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc)397{ // Operand-size override prefix398m_bOperandOverride = TRUE;399return CopyBytesPrefix(pEntry, pbDst, pbSrc);400}401402PBYTE CDetourDis::Copy67(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc)403{ // Address size override prefix404m_bAddressOverride = TRUE;405return CopyBytesPrefix(pEntry, pbDst, pbSrc);406}407408PBYTE CDetourDis::CopyF6(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc)409{410(void)pEntry;411412// TEST BYTE /0413if (0x00 == (0x38 & pbSrc[1])) { // reg(bits 543) of ModR/M == 0414const COPYENTRY ce = { 0xf6, ENTRY_CopyBytes2Mod1 };415return (this->*ce.pfCopy)(&ce, pbDst, pbSrc);416}417// DIV /6418// IDIV /7419// IMUL /5420// MUL /4421// NEG /3422// NOT /2423424const COPYENTRY ce = { 0xf6, ENTRY_CopyBytes2Mod };425return (this->*ce.pfCopy)(&ce, pbDst, pbSrc);426}427428PBYTE CDetourDis::CopyF7(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc)429{430(void)pEntry;431432// TEST WORD /0433if (0x00 == (0x38 & pbSrc[1])) { // reg(bits 543) of ModR/M == 0434const COPYENTRY ce = { 0xf7, ENTRY_CopyBytes2ModOperand };435return (this->*ce.pfCopy)(&ce, pbDst, pbSrc);436}437438// DIV /6439// IDIV /7440// IMUL /5441// MUL /4442// NEG /3443// NOT /2444const COPYENTRY ce = { 0xf7, ENTRY_CopyBytes2Mod };445return (this->*ce.pfCopy)(&ce, pbDst, pbSrc);446}447448PBYTE CDetourDis::CopyFF(REFCOPYENTRY pEntry, PBYTE pbDst, PBYTE pbSrc)449{ // CALL /2450// CALL /3451// INC /0452// JMP /4453// JMP /5454// PUSH /6455(void)pEntry;456457if (0x15 == pbSrc[1] || 0x25 == pbSrc[1]) { // CALL [], JMP []458#ifdef DETOURS_X64459#error Feature not supported in this release.460461462#else463PBYTE *ppbTarget = *(PBYTE**)&pbSrc[2];464*m_ppbTarget = *ppbTarget;465#endif466}467else if (0x10 == (0x38 & pbSrc[1]) || // CALL /2 --> reg(bits 543) of ModR/M == 0104680x18 == (0x38 & pbSrc[1]) || // CALL /3 --> reg(bits 543) of ModR/M == 0114690x20 == (0x38 & pbSrc[1]) || // JMP /4 --> reg(bits 543) of ModR/M == 1004700x28 == (0x38 & pbSrc[1]) // JMP /5 --> reg(bits 543) of ModR/M == 101471) {472*m_ppbTarget = (PBYTE)DETOUR_INSTRUCTION_TARGET_DYNAMIC;473}474const COPYENTRY ce = { 0xff, ENTRY_CopyBytes2Mod };475return (this->*ce.pfCopy)(&ce, pbDst, pbSrc);476}477478///////////////////////////////////////////////////////// Disassembler Tables.479//480const BYTE CDetourDis::s_rbModRm[256] = {4810,0,0,0, SIB|1,RIP|4,0,0, 0,0,0,0, SIB|1,RIP|4,0,0, // 0x4820,0,0,0, SIB|1,RIP|4,0,0, 0,0,0,0, SIB|1,RIP|4,0,0, // 1x4830,0,0,0, SIB|1,RIP|4,0,0, 0,0,0,0, SIB|1,RIP|4,0,0, // 2x4840,0,0,0, SIB|1,RIP|4,0,0, 0,0,0,0, SIB|1,RIP|4,0,0, // 3x4851,1,1,1, 2,1,1,1, 1,1,1,1, 2,1,1,1, // 4x4861,1,1,1, 2,1,1,1, 1,1,1,1, 2,1,1,1, // 5x4871,1,1,1, 2,1,1,1, 1,1,1,1, 2,1,1,1, // 6x4881,1,1,1, 2,1,1,1, 1,1,1,1, 2,1,1,1, // 7x4894,4,4,4, 5,4,4,4, 4,4,4,4, 5,4,4,4, // 8x4904,4,4,4, 5,4,4,4, 4,4,4,4, 5,4,4,4, // 9x4914,4,4,4, 5,4,4,4, 4,4,4,4, 5,4,4,4, // Ax4924,4,4,4, 5,4,4,4, 4,4,4,4, 5,4,4,4, // Bx4930,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // Cx4940,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // Dx4950,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // Ex4960,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 // Fx497};498499const CDetourDis::COPYENTRY CDetourDis::s_rceCopyTable[257] =500{501{ 0x00, ENTRY_CopyBytes2Mod }, // ADD /r502{ 0x01, ENTRY_CopyBytes2Mod }, // ADD /r503{ 0x02, ENTRY_CopyBytes2Mod }, // ADD /r504{ 0x03, ENTRY_CopyBytes2Mod }, // ADD /r505{ 0x04, ENTRY_CopyBytes2 }, // ADD ib506{ 0x05, ENTRY_CopyBytes3Or5 }, // ADD iw507{ 0x06, ENTRY_CopyBytes1 }, // PUSH508{ 0x07, ENTRY_CopyBytes1 }, // POP509{ 0x08, ENTRY_CopyBytes2Mod }, // OR /r510{ 0x09, ENTRY_CopyBytes2Mod }, // OR /r511{ 0x0A, ENTRY_CopyBytes2Mod }, // OR /r512{ 0x0B, ENTRY_CopyBytes2Mod }, // OR /r513{ 0x0C, ENTRY_CopyBytes2 }, // OR ib514{ 0x0D, ENTRY_CopyBytes3Or5 }, // OR iw515{ 0x0E, ENTRY_CopyBytes1 }, // PUSH516{ 0x0F, ENTRY_Copy0F }, // Extension Ops517{ 0x10, ENTRY_CopyBytes2Mod }, // ADC /r518{ 0x11, ENTRY_CopyBytes2Mod }, // ADC /r519{ 0x12, ENTRY_CopyBytes2Mod }, // ADC /r520{ 0x13, ENTRY_CopyBytes2Mod }, // ADC /r521{ 0x14, ENTRY_CopyBytes2 }, // ADC ib522{ 0x15, ENTRY_CopyBytes3Or5 }, // ADC id523{ 0x16, ENTRY_CopyBytes1 }, // PUSH524{ 0x17, ENTRY_CopyBytes1 }, // POP525{ 0x18, ENTRY_CopyBytes2Mod }, // SBB /r526{ 0x19, ENTRY_CopyBytes2Mod }, // SBB /r527{ 0x1A, ENTRY_CopyBytes2Mod }, // SBB /r528{ 0x1B, ENTRY_CopyBytes2Mod }, // SBB /r529{ 0x1C, ENTRY_CopyBytes2 }, // SBB ib530{ 0x1D, ENTRY_CopyBytes3Or5 }, // SBB id531{ 0x1E, ENTRY_CopyBytes1 }, // PUSH532{ 0x1F, ENTRY_CopyBytes1 }, // POP533{ 0x20, ENTRY_CopyBytes2Mod }, // AND /r534{ 0x21, ENTRY_CopyBytes2Mod }, // AND /r535{ 0x22, ENTRY_CopyBytes2Mod }, // AND /r536{ 0x23, ENTRY_CopyBytes2Mod }, // AND /r537{ 0x24, ENTRY_CopyBytes2 }, // AND ib538{ 0x25, ENTRY_CopyBytes3Or5 }, // AND id539{ 0x26, ENTRY_CopyBytesPrefix }, // ES prefix540{ 0x27, ENTRY_CopyBytes1 }, // DAA541{ 0x28, ENTRY_CopyBytes2Mod }, // SUB /r542{ 0x29, ENTRY_CopyBytes2Mod }, // SUB /r543{ 0x2A, ENTRY_CopyBytes2Mod }, // SUB /r544{ 0x2B, ENTRY_CopyBytes2Mod }, // SUB /r545{ 0x2C, ENTRY_CopyBytes2 }, // SUB ib546{ 0x2D, ENTRY_CopyBytes3Or5 }, // SUB id547{ 0x2E, ENTRY_CopyBytesPrefix }, // CS prefix548{ 0x2F, ENTRY_CopyBytes1 }, // DAS549{ 0x30, ENTRY_CopyBytes2Mod }, // XOR /r550{ 0x31, ENTRY_CopyBytes2Mod }, // XOR /r551{ 0x32, ENTRY_CopyBytes2Mod }, // XOR /r552{ 0x33, ENTRY_CopyBytes2Mod }, // XOR /r553{ 0x34, ENTRY_CopyBytes2 }, // XOR ib554{ 0x35, ENTRY_CopyBytes3Or5 }, // XOR id555{ 0x36, ENTRY_CopyBytesPrefix }, // SS prefix556{ 0x37, ENTRY_CopyBytes1 }, // AAA557{ 0x38, ENTRY_CopyBytes2Mod }, // CMP /r558{ 0x39, ENTRY_CopyBytes2Mod }, // CMP /r559{ 0x3A, ENTRY_CopyBytes2Mod }, // CMP /r560{ 0x3B, ENTRY_CopyBytes2Mod }, // CMP /r561{ 0x3C, ENTRY_CopyBytes2 }, // CMP ib562{ 0x3D, ENTRY_CopyBytes3Or5 }, // CMP id563{ 0x3E, ENTRY_CopyBytesPrefix }, // DS prefix564{ 0x3F, ENTRY_CopyBytes1 }, // AAS565#ifdef DETOURS_X64 // For Rax Prefix566#error Feature not supported in this release.567568569570571572573574575576577578579580581582#else583{ 0x40, ENTRY_CopyBytes1 }, // INC584{ 0x41, ENTRY_CopyBytes1 }, // INC585{ 0x42, ENTRY_CopyBytes1 }, // INC586{ 0x43, ENTRY_CopyBytes1 }, // INC587{ 0x44, ENTRY_CopyBytes1 }, // INC588{ 0x45, ENTRY_CopyBytes1 }, // INC589{ 0x46, ENTRY_CopyBytes1 }, // INC590{ 0x47, ENTRY_CopyBytes1 }, // INC591{ 0x48, ENTRY_CopyBytes1 }, // DEC592{ 0x49, ENTRY_CopyBytes1 }, // DEC593{ 0x4A, ENTRY_CopyBytes1 }, // DEC594{ 0x4B, ENTRY_CopyBytes1 }, // DEC595{ 0x4C, ENTRY_CopyBytes1 }, // DEC596{ 0x4D, ENTRY_CopyBytes1 }, // DEC597{ 0x4E, ENTRY_CopyBytes1 }, // DEC598{ 0x4F, ENTRY_CopyBytes1 }, // DEC599#endif600{ 0x50, ENTRY_CopyBytes1 }, // PUSH601{ 0x51, ENTRY_CopyBytes1 }, // PUSH602{ 0x52, ENTRY_CopyBytes1 }, // PUSH603{ 0x53, ENTRY_CopyBytes1 }, // PUSH604{ 0x54, ENTRY_CopyBytes1 }, // PUSH605{ 0x55, ENTRY_CopyBytes1 }, // PUSH606{ 0x56, ENTRY_CopyBytes1 }, // PUSH607{ 0x57, ENTRY_CopyBytes1 }, // PUSH608{ 0x58, ENTRY_CopyBytes1 }, // POP609{ 0x59, ENTRY_CopyBytes1 }, // POP610{ 0x5A, ENTRY_CopyBytes1 }, // POP611{ 0x5B, ENTRY_CopyBytes1 }, // POP612{ 0x5C, ENTRY_CopyBytes1 }, // POP613{ 0x5D, ENTRY_CopyBytes1 }, // POP614{ 0x5E, ENTRY_CopyBytes1 }, // POP615{ 0x5F, ENTRY_CopyBytes1 }, // POP616{ 0x60, ENTRY_CopyBytes1 }, // PUSHAD617{ 0x61, ENTRY_CopyBytes1 }, // POPAD618{ 0x62, ENTRY_CopyBytes2Mod }, // BOUND /r619{ 0x63, ENTRY_CopyBytes2Mod }, // ARPL /r620{ 0x64, ENTRY_CopyBytesPrefix }, // FS prefix621{ 0x65, ENTRY_CopyBytesPrefix }, // GS prefix622{ 0x66, ENTRY_Copy66 }, // Operand Prefix623{ 0x67, ENTRY_Copy67 }, // Address Prefix624{ 0x68, ENTRY_CopyBytes3Or5 }, // PUSH625{ 0x69, ENTRY_CopyBytes2ModOperand }, //626{ 0x6A, ENTRY_CopyBytes2 }, // PUSH627{ 0x6B, ENTRY_CopyBytes2Mod1 }, // IMUL /r ib628{ 0x6C, ENTRY_CopyBytes1 }, // INS629{ 0x6D, ENTRY_CopyBytes1 }, // INS630{ 0x6E, ENTRY_CopyBytes1 }, // OUTS/OUTSB631{ 0x6F, ENTRY_CopyBytes1 }, // OUTS/OUTSW632{ 0x70, ENTRY_CopyBytes2Jump }, // JO633{ 0x71, ENTRY_CopyBytes2Jump }, // JNO634{ 0x72, ENTRY_CopyBytes2Jump }, // JB/JC/JNAE635{ 0x73, ENTRY_CopyBytes2Jump }, // JAE/JNB/JNC636{ 0x74, ENTRY_CopyBytes2Jump }, // JE/JZ637{ 0x75, ENTRY_CopyBytes2Jump }, // JNE/JNZ638{ 0x76, ENTRY_CopyBytes2Jump }, // JBE/JNA639{ 0x77, ENTRY_CopyBytes2Jump }, // JA/JNBE640{ 0x78, ENTRY_CopyBytes2Jump }, // JS641{ 0x79, ENTRY_CopyBytes2Jump }, // JNS642{ 0x7A, ENTRY_CopyBytes2Jump }, // JP/JPE643{ 0x7B, ENTRY_CopyBytes2Jump }, // JNP/JPO644{ 0x7C, ENTRY_CopyBytes2Jump }, // JL/JNGE645{ 0x7D, ENTRY_CopyBytes2Jump }, // JGE/JNL646{ 0x7E, ENTRY_CopyBytes2Jump }, // JLE/JNG647{ 0x7F, ENTRY_CopyBytes2Jump }, // JG/JNLE648{ 0x80, ENTRY_CopyBytes2Mod1 }, // ADC/2 ib, etc.s649{ 0x81, ENTRY_CopyBytes2ModOperand }, //650{ 0x82, ENTRY_CopyBytes2 }, // MOV al,x651{ 0x83, ENTRY_CopyBytes2Mod1 }, // ADC/2 ib, etc.652{ 0x84, ENTRY_CopyBytes2Mod }, // TEST /r653{ 0x85, ENTRY_CopyBytes2Mod }, // TEST /r654{ 0x86, ENTRY_CopyBytes2Mod }, // XCHG /r @todo655{ 0x87, ENTRY_CopyBytes2Mod }, // XCHG /r @todo656{ 0x88, ENTRY_CopyBytes2Mod }, // MOV /r657{ 0x89, ENTRY_CopyBytes2Mod }, // MOV /r658{ 0x8A, ENTRY_CopyBytes2Mod }, // MOV /r659{ 0x8B, ENTRY_CopyBytes2Mod }, // MOV /r660{ 0x8C, ENTRY_CopyBytes2Mod }, // MOV /r661{ 0x8D, ENTRY_CopyBytes2Mod }, // LEA /r662{ 0x8E, ENTRY_CopyBytes2Mod }, // MOV /r663{ 0x8F, ENTRY_CopyBytes2Mod }, // POP /0664{ 0x90, ENTRY_CopyBytes1 }, // NOP665{ 0x91, ENTRY_CopyBytes1 }, // XCHG666{ 0x92, ENTRY_CopyBytes1 }, // XCHG667{ 0x93, ENTRY_CopyBytes1 }, // XCHG668{ 0x94, ENTRY_CopyBytes1 }, // XCHG669{ 0x95, ENTRY_CopyBytes1 }, // XCHG670{ 0x96, ENTRY_CopyBytes1 }, // XCHG671{ 0x97, ENTRY_CopyBytes1 }, // XCHG672{ 0x98, ENTRY_CopyBytes1 }, // CWDE673{ 0x99, ENTRY_CopyBytes1 }, // CDQ674{ 0x9A, ENTRY_CopyBytes5Or7Dynamic }, // CALL cp675{ 0x9B, ENTRY_CopyBytes1 }, // WAIT/FWAIT676{ 0x9C, ENTRY_CopyBytes1 }, // PUSHFD677{ 0x9D, ENTRY_CopyBytes1 }, // POPFD678{ 0x9E, ENTRY_CopyBytes1 }, // SAHF679{ 0x9F, ENTRY_CopyBytes1 }, // LAHF680{ 0xA0, ENTRY_CopyBytes3Or5Address }, // MOV681{ 0xA1, ENTRY_CopyBytes3Or5Address }, // MOV682{ 0xA2, ENTRY_CopyBytes3Or5Address }, // MOV683{ 0xA3, ENTRY_CopyBytes3Or5Address }, // MOV684{ 0xA4, ENTRY_CopyBytes1 }, // MOVS685{ 0xA5, ENTRY_CopyBytes1 }, // MOVS/MOVSD686{ 0xA6, ENTRY_CopyBytes1 }, // CMPS/CMPSB687{ 0xA7, ENTRY_CopyBytes1 }, // CMPS/CMPSW688{ 0xA8, ENTRY_CopyBytes2 }, // TEST689{ 0xA9, ENTRY_CopyBytes3Or5 }, // TEST690{ 0xAA, ENTRY_CopyBytes1 }, // STOS/STOSB691{ 0xAB, ENTRY_CopyBytes1 }, // STOS/STOSW692{ 0xAC, ENTRY_CopyBytes1 }, // LODS/LODSB693{ 0xAD, ENTRY_CopyBytes1 }, // LODS/LODSW694{ 0xAE, ENTRY_CopyBytes1 }, // SCAS/SCASB695{ 0xAF, ENTRY_CopyBytes1 }, // SCAS/SCASD696{ 0xB0, ENTRY_CopyBytes2 }, // MOV B0+rb697{ 0xB1, ENTRY_CopyBytes2 }, // MOV B0+rb698{ 0xB2, ENTRY_CopyBytes2 }, // MOV B0+rb699{ 0xB3, ENTRY_CopyBytes2 }, // MOV B0+rb700{ 0xB4, ENTRY_CopyBytes2 }, // MOV B0+rb701{ 0xB5, ENTRY_CopyBytes2 }, // MOV B0+rb702{ 0xB6, ENTRY_CopyBytes2 }, // MOV B0+rb703{ 0xB7, ENTRY_CopyBytes2 }, // MOV B0+rb704{ 0xB8, ENTRY_CopyBytes3Or5Rax }, // MOV B8+rb705{ 0xB9, ENTRY_CopyBytes3Or5 }, // MOV B8+rb706{ 0xBA, ENTRY_CopyBytes3Or5 }, // MOV B8+rb707{ 0xBB, ENTRY_CopyBytes3Or5 }, // MOV B8+rb708{ 0xBC, ENTRY_CopyBytes3Or5 }, // MOV B8+rb709{ 0xBD, ENTRY_CopyBytes3Or5 }, // MOV B8+rb710{ 0xBE, ENTRY_CopyBytes3Or5 }, // MOV B8+rb711{ 0xBF, ENTRY_CopyBytes3Or5 }, // MOV B8+rb712{ 0xC0, ENTRY_CopyBytes2Mod1 }, // RCL/2 ib, etc.713{ 0xC1, ENTRY_CopyBytes2Mod1 }, // RCL/2 ib, etc.714{ 0xC2, ENTRY_CopyBytes3 }, // RET715{ 0xC3, ENTRY_CopyBytes1 }, // RET716{ 0xC4, ENTRY_CopyBytes2Mod }, // LES717{ 0xC5, ENTRY_CopyBytes2Mod }, // LDS718{ 0xC6, ENTRY_CopyBytes2Mod1 }, // MOV719{ 0xC7, ENTRY_CopyBytes2ModOperand }, // MOV720{ 0xC8, ENTRY_CopyBytes4 }, // ENTER721{ 0xC9, ENTRY_CopyBytes1 }, // LEAVE722{ 0xCA, ENTRY_CopyBytes3Dynamic }, // RET723{ 0xCB, ENTRY_CopyBytes1Dynamic }, // RET724{ 0xCC, ENTRY_CopyBytes1Dynamic }, // INT 3725{ 0xCD, ENTRY_CopyBytes2Dynamic }, // INT ib726{ 0xCE, ENTRY_CopyBytes1Dynamic }, // INTO727{ 0xCF, ENTRY_CopyBytes1Dynamic }, // IRET728{ 0xD0, ENTRY_CopyBytes2Mod }, // RCL/2, etc.729{ 0xD1, ENTRY_CopyBytes2Mod }, // RCL/2, etc.730{ 0xD2, ENTRY_CopyBytes2Mod }, // RCL/2, etc.731{ 0xD3, ENTRY_CopyBytes2Mod }, // RCL/2, etc.732{ 0xD4, ENTRY_CopyBytes2 }, // AAM733{ 0xD5, ENTRY_CopyBytes2 }, // AAD734{ 0xD6, ENTRY_Invalid }, //735{ 0xD7, ENTRY_CopyBytes1 }, // XLAT/XLATB736{ 0xD8, ENTRY_CopyBytes2Mod }, // FADD, etc.737{ 0xD9, ENTRY_CopyBytes2Mod }, // F2XM1, etc.738{ 0xDA, ENTRY_CopyBytes2Mod }, // FLADD, etc.739{ 0xDB, ENTRY_CopyBytes2Mod }, // FCLEX, etc.740{ 0xDC, ENTRY_CopyBytes2Mod }, // FADD/0, etc.741{ 0xDD, ENTRY_CopyBytes2Mod }, // FFREE, etc.742{ 0xDE, ENTRY_CopyBytes2Mod }, // FADDP, etc.743{ 0xDF, ENTRY_CopyBytes2Mod }, // FBLD/4, etc.744{ 0xE0, ENTRY_CopyBytes2CantJump }, // LOOPNE cb745{ 0xE1, ENTRY_CopyBytes2CantJump }, // LOOPE cb746{ 0xE2, ENTRY_CopyBytes2CantJump }, // LOOP cb747{ 0xE3, ENTRY_CopyBytes2Jump }, // JCXZ/JECXZ748{ 0xE4, ENTRY_CopyBytes2 }, // IN ib749{ 0xE5, ENTRY_CopyBytes2 }, // IN id750{ 0xE6, ENTRY_CopyBytes2 }, // OUT ib751{ 0xE7, ENTRY_CopyBytes2 }, // OUT ib752{ 0xE8, ENTRY_CopyBytes3Or5Target }, // CALL cd753{ 0xE9, ENTRY_CopyBytes3Or5Target }, // JMP cd754{ 0xEA, ENTRY_CopyBytes5Or7Dynamic }, // JMP cp755{ 0xEB, ENTRY_CopyBytes2Jump }, // JMP cb756{ 0xEC, ENTRY_CopyBytes1 }, // IN ib757{ 0xED, ENTRY_CopyBytes1 }, // IN id758{ 0xEE, ENTRY_CopyBytes1 }, // OUT759{ 0xEF, ENTRY_CopyBytes1 }, // OUT760{ 0xF0, ENTRY_CopyBytesPrefix }, // LOCK prefix761{ 0xF1, ENTRY_Invalid }, //762{ 0xF2, ENTRY_CopyBytesPrefix }, // REPNE prefix763{ 0xF3, ENTRY_CopyBytesPrefix }, // REPE prefix764{ 0xF4, ENTRY_CopyBytes1 }, // HLT765{ 0xF5, ENTRY_CopyBytes1 }, // CMC766{ 0xF6, ENTRY_CopyF6 }, // TEST/0, DIV/6767{ 0xF7, ENTRY_CopyF7 }, // TEST/0, DIV/6768{ 0xF8, ENTRY_CopyBytes1 }, // CLC769{ 0xF9, ENTRY_CopyBytes1 }, // STC770{ 0xFA, ENTRY_CopyBytes1 }, // CLI771{ 0xFB, ENTRY_CopyBytes1 }, // STI772{ 0xFC, ENTRY_CopyBytes1 }, // CLD773{ 0xFD, ENTRY_CopyBytes1 }, // STD774{ 0xFE, ENTRY_CopyBytes2Mod }, // DEC/1,INC/0775{ 0xFF, ENTRY_CopyFF }, // CALL/2776{ 0, ENTRY_End },777};778779const CDetourDis::COPYENTRY CDetourDis::s_rceCopyTable0F[257] =780{781{ 0x00, ENTRY_CopyBytes2Mod }, // LLDT/2, etc.782{ 0x01, ENTRY_CopyBytes2Mod }, // INVLPG/7, etc.783{ 0x02, ENTRY_CopyBytes2Mod }, // LAR/r784{ 0x03, ENTRY_CopyBytes2Mod }, // LSL/r785{ 0x04, ENTRY_Invalid }, // _04786{ 0x05, ENTRY_Invalid }, // _05787{ 0x06, ENTRY_CopyBytes2 }, // CLTS788{ 0x07, ENTRY_Invalid }, // _07789{ 0x08, ENTRY_CopyBytes2 }, // INVD790{ 0x09, ENTRY_CopyBytes2 }, // WBINVD791{ 0x0A, ENTRY_Invalid }, // _0A792{ 0x0B, ENTRY_CopyBytes2 }, // UD2793{ 0x0C, ENTRY_Invalid }, // _0C794{ 0x0D, ENTRY_CopyBytes2Mod }, // PREFETCH795{ 0x0E, ENTRY_CopyBytes2 }, // FEMMS796{ 0x0F, ENTRY_CopyBytes3Mod }, // 3DNow Opcodes797{ 0x10, ENTRY_CopyBytes2Mod }, // MOVSS MOVUPD MOVSD798{ 0x11, ENTRY_CopyBytes2Mod }, // MOVSS MOVUPD MOVSD799{ 0x12, ENTRY_CopyBytes2Mod }, // MOVLPD800{ 0x13, ENTRY_CopyBytes2Mod }, // MOVLPD801{ 0x14, ENTRY_CopyBytes2Mod }, // UNPCKLPD802{ 0x15, ENTRY_CopyBytes2Mod }, // UNPCKHPD803{ 0x16, ENTRY_CopyBytes2Mod }, // MOVHPD804{ 0x17, ENTRY_CopyBytes2Mod }, // MOVHPD805{ 0x18, ENTRY_CopyBytes2Mod }, // PREFETCHINTA...806{ 0x19, ENTRY_Invalid }, // _19807{ 0x1A, ENTRY_Invalid }, // _1A808{ 0x1B, ENTRY_Invalid }, // _1B809{ 0x1C, ENTRY_Invalid }, // _1C810{ 0x1D, ENTRY_Invalid }, // _1D811{ 0x1E, ENTRY_Invalid }, // _1E812{ 0x1F, ENTRY_Invalid }, // _1F813{ 0x20, ENTRY_CopyBytes2Mod }, // MOV/r814{ 0x21, ENTRY_CopyBytes2Mod }, // MOV/r815{ 0x22, ENTRY_CopyBytes2Mod }, // MOV/r816{ 0x23, ENTRY_CopyBytes2Mod }, // MOV/r817{ 0x24, ENTRY_Invalid }, // _24818{ 0x25, ENTRY_Invalid }, // _25819{ 0x26, ENTRY_Invalid }, // _26820{ 0x27, ENTRY_Invalid }, // _27821{ 0x28, ENTRY_CopyBytes2Mod }, // MOVAPS MOVAPD822{ 0x29, ENTRY_CopyBytes2Mod }, // MOVAPS MOVAPD823{ 0x2A, ENTRY_CopyBytes2Mod }, // CVPI2PS &824{ 0x2B, ENTRY_CopyBytes2Mod }, // MOVNTPS MOVNTPD825{ 0x2C, ENTRY_CopyBytes2Mod }, // CVTTPS2PI &826{ 0x2D, ENTRY_CopyBytes2Mod }, // CVTPS2PI &827{ 0x2E, ENTRY_CopyBytes2Mod }, // UCOMISS UCOMISD828{ 0x2F, ENTRY_CopyBytes2Mod }, // COMISS COMISD829{ 0x30, ENTRY_CopyBytes2 }, // WRMSR830{ 0x31, ENTRY_CopyBytes2 }, // RDTSC831{ 0x32, ENTRY_CopyBytes2 }, // RDMSR832{ 0x33, ENTRY_CopyBytes2 }, // RDPMC833{ 0x34, ENTRY_CopyBytes2 }, // SYSENTER834{ 0x35, ENTRY_CopyBytes2 }, // SYSEXIT835{ 0x36, ENTRY_Invalid }, // _36836{ 0x37, ENTRY_Invalid }, // _37837{ 0x38, ENTRY_Invalid }, // _38838{ 0x39, ENTRY_Invalid }, // _39839{ 0x3A, ENTRY_Invalid }, // _3A840{ 0x3B, ENTRY_Invalid }, // _3B841{ 0x3C, ENTRY_Invalid }, // _3C842{ 0x3D, ENTRY_Invalid }, // _3D843{ 0x3E, ENTRY_Invalid }, // _3E844{ 0x3F, ENTRY_Invalid }, // _3F845{ 0x40, ENTRY_CopyBytes2Mod }, // CMOVO (0F 40)846{ 0x41, ENTRY_CopyBytes2Mod }, // CMOVNO (0F 41)847{ 0x42, ENTRY_CopyBytes2Mod }, // CMOVB & CMOVNE (0F 42)848{ 0x43, ENTRY_CopyBytes2Mod }, // CMOVAE & CMOVNB (0F 43)849{ 0x44, ENTRY_CopyBytes2Mod }, // CMOVE & CMOVZ (0F 44)850{ 0x45, ENTRY_CopyBytes2Mod }, // CMOVNE & CMOVNZ (0F 45)851{ 0x46, ENTRY_CopyBytes2Mod }, // CMOVBE & CMOVNA (0F 46)852{ 0x47, ENTRY_CopyBytes2Mod }, // CMOVA & CMOVNBE (0F 47)853{ 0x48, ENTRY_CopyBytes2Mod }, // CMOVS (0F 48)854{ 0x49, ENTRY_CopyBytes2Mod }, // CMOVNS (0F 49)855{ 0x4A, ENTRY_CopyBytes2Mod }, // CMOVP & CMOVPE (0F 4A)856{ 0x4B, ENTRY_CopyBytes2Mod }, // CMOVNP & CMOVPO (0F 4B)857{ 0x4C, ENTRY_CopyBytes2Mod }, // CMOVL & CMOVNGE (0F 4C)858{ 0x4D, ENTRY_CopyBytes2Mod }, // CMOVGE & CMOVNL (0F 4D)859{ 0x4E, ENTRY_CopyBytes2Mod }, // CMOVLE & CMOVNG (0F 4E)860{ 0x4F, ENTRY_CopyBytes2Mod }, // CMOVG & CMOVNLE (0F 4F)861{ 0x50, ENTRY_CopyBytes2Mod }, // MOVMSKPD MOVMSKPD862{ 0x51, ENTRY_CopyBytes2Mod }, // SQRTPS &863{ 0x52, ENTRY_CopyBytes2Mod }, // RSQRTTS RSQRTPS864{ 0x53, ENTRY_CopyBytes2Mod }, // RCPPS RCPSS865{ 0x54, ENTRY_CopyBytes2Mod }, // ANDPS ANDPD866{ 0x55, ENTRY_CopyBytes2Mod }, // ANDNPS ANDNPD867{ 0x56, ENTRY_CopyBytes2Mod }, // ORPS ORPD868{ 0x57, ENTRY_CopyBytes2Mod }, // XORPS XORPD869{ 0x58, ENTRY_CopyBytes2Mod }, // ADDPS &870{ 0x59, ENTRY_CopyBytes2Mod }, // MULPS &871{ 0x5A, ENTRY_CopyBytes2Mod }, // CVTPS2PD &872{ 0x5B, ENTRY_CopyBytes2Mod }, // CVTDQ2PS &873{ 0x5C, ENTRY_CopyBytes2Mod }, // SUBPS &874{ 0x5D, ENTRY_CopyBytes2Mod }, // MINPS &875{ 0x5E, ENTRY_CopyBytes2Mod }, // DIVPS &876{ 0x5F, ENTRY_CopyBytes2Mod }, // MASPS &877{ 0x60, ENTRY_CopyBytes2Mod }, // PUNPCKLBW/r878{ 0x61, ENTRY_CopyBytes2Mod }, // PUNPCKLWD/r879{ 0x62, ENTRY_CopyBytes2Mod }, // PUNPCKLWD/r880{ 0x63, ENTRY_CopyBytes2Mod }, // PACKSSWB/r881{ 0x64, ENTRY_CopyBytes2Mod }, // PCMPGTB/r882{ 0x65, ENTRY_CopyBytes2Mod }, // PCMPGTW/r883{ 0x66, ENTRY_CopyBytes2Mod }, // PCMPGTD/r884{ 0x67, ENTRY_CopyBytes2Mod }, // PACKUSWB/r885{ 0x68, ENTRY_CopyBytes2Mod }, // PUNPCKHBW/r886{ 0x69, ENTRY_CopyBytes2Mod }, // PUNPCKHWD/r887{ 0x6A, ENTRY_CopyBytes2Mod }, // PUNPCKHDQ/r888{ 0x6B, ENTRY_CopyBytes2Mod }, // PACKSSDW/r889{ 0x6C, ENTRY_CopyBytes2Mod }, // PUNPCKLQDQ890{ 0x6D, ENTRY_CopyBytes2Mod }, // PUNPCKHQDQ891{ 0x6E, ENTRY_CopyBytes2Mod }, // MOVD/r892{ 0x6F, ENTRY_CopyBytes2Mod }, // MOV/r893{ 0x70, ENTRY_CopyBytes2Mod1 }, // PSHUFW/r ib894{ 0x71, ENTRY_CopyBytes2Mod1 }, // PSLLW/6 ib,PSRAW/4 ib,PSRLW/2 ib895{ 0x72, ENTRY_CopyBytes2Mod1 }, // PSLLD/6 ib,PSRAD/4 ib,PSRLD/2 ib896{ 0x73, ENTRY_CopyBytes2Mod1 }, // PSLLQ/6 ib,PSRLQ/2 ib897{ 0x74, ENTRY_CopyBytes2Mod }, // PCMPEQB/r898{ 0x75, ENTRY_CopyBytes2Mod }, // PCMPEQW/r899{ 0x76, ENTRY_CopyBytes2Mod }, // PCMPEQD/r900{ 0x77, ENTRY_CopyBytes2 }, // EMMS901{ 0x78, ENTRY_Invalid }, // _78902{ 0x79, ENTRY_Invalid }, // _79903{ 0x7A, ENTRY_Invalid }, // _7A904{ 0x7B, ENTRY_Invalid }, // _7B905{ 0x7C, ENTRY_Invalid }, // _7C906{ 0x7D, ENTRY_Invalid }, // _7D907{ 0x7E, ENTRY_CopyBytes2Mod }, // MOVD/r908{ 0x7F, ENTRY_CopyBytes2Mod }, // MOV/r909{ 0x80, ENTRY_CopyBytes3Or5Target }, // JO910{ 0x81, ENTRY_CopyBytes3Or5Target }, // JNO911{ 0x82, ENTRY_CopyBytes3Or5Target }, // JB,JC,JNAE912{ 0x83, ENTRY_CopyBytes3Or5Target }, // JAE,JNB,JNC913{ 0x84, ENTRY_CopyBytes3Or5Target }, // JE,JZ,JZ914{ 0x85, ENTRY_CopyBytes3Or5Target }, // JNE,JNZ915{ 0x86, ENTRY_CopyBytes3Or5Target }, // JBE,JNA916{ 0x87, ENTRY_CopyBytes3Or5Target }, // JA,JNBE917{ 0x88, ENTRY_CopyBytes3Or5Target }, // JS918{ 0x89, ENTRY_CopyBytes3Or5Target }, // JNS919{ 0x8A, ENTRY_CopyBytes3Or5Target }, // JP,JPE920{ 0x8B, ENTRY_CopyBytes3Or5Target }, // JNP,JPO921{ 0x8C, ENTRY_CopyBytes3Or5Target }, // JL,NGE922{ 0x8D, ENTRY_CopyBytes3Or5Target }, // JGE,JNL923{ 0x8E, ENTRY_CopyBytes3Or5Target }, // JLE,JNG924{ 0x8F, ENTRY_CopyBytes3Or5Target }, // JG,JNLE925{ 0x90, ENTRY_CopyBytes2Mod }, // CMOVO (0F 40)926{ 0x91, ENTRY_CopyBytes2Mod }, // CMOVNO (0F 41)927{ 0x92, ENTRY_CopyBytes2Mod }, // CMOVB & CMOVC & CMOVNAE (0F 42)928{ 0x93, ENTRY_CopyBytes2Mod }, // CMOVAE & CMOVNB & CMOVNC (0F 43)929{ 0x94, ENTRY_CopyBytes2Mod }, // CMOVE & CMOVZ (0F 44)930{ 0x95, ENTRY_CopyBytes2Mod }, // CMOVNE & CMOVNZ (0F 45)931{ 0x96, ENTRY_CopyBytes2Mod }, // CMOVBE & CMOVNA (0F 46)932{ 0x97, ENTRY_CopyBytes2Mod }, // CMOVA & CMOVNBE (0F 47)933{ 0x98, ENTRY_CopyBytes2Mod }, // CMOVS (0F 48)934{ 0x99, ENTRY_CopyBytes2Mod }, // CMOVNS (0F 49)935{ 0x9A, ENTRY_CopyBytes2Mod }, // CMOVP & CMOVPE (0F 4A)936{ 0x9B, ENTRY_CopyBytes2Mod }, // CMOVNP & CMOVPO (0F 4B)937{ 0x9C, ENTRY_CopyBytes2Mod }, // CMOVL & CMOVNGE (0F 4C)938{ 0x9D, ENTRY_CopyBytes2Mod }, // CMOVGE & CMOVNL (0F 4D)939{ 0x9E, ENTRY_CopyBytes2Mod }, // CMOVLE & CMOVNG (0F 4E)940{ 0x9F, ENTRY_CopyBytes2Mod }, // CMOVG & CMOVNLE (0F 4F)941{ 0xA0, ENTRY_CopyBytes2 }, // PUSH942{ 0xA1, ENTRY_CopyBytes2 }, // POP943{ 0xA2, ENTRY_CopyBytes2 }, // CPUID944{ 0xA3, ENTRY_CopyBytes2Mod }, // BT (0F A3)945{ 0xA4, ENTRY_CopyBytes2Mod1 }, // SHLD946{ 0xA5, ENTRY_CopyBytes2Mod }, // SHLD947{ 0xA6, ENTRY_Invalid }, // _A6948{ 0xA7, ENTRY_Invalid }, // _A7949{ 0xA8, ENTRY_CopyBytes2 }, // PUSH950{ 0xA9, ENTRY_CopyBytes2 }, // POP951{ 0xAA, ENTRY_CopyBytes2 }, // RSM952{ 0xAB, ENTRY_CopyBytes2Mod }, // BTS (0F AB)953{ 0xAC, ENTRY_CopyBytes2Mod1 }, // SHRD954{ 0xAD, ENTRY_CopyBytes2Mod }, // SHRD955{ 0xAE, ENTRY_CopyBytes2Mod }, // FXRSTOR/1,FXSAVE/0956{ 0xAF, ENTRY_CopyBytes2Mod }, // IMUL (0F AF)957{ 0xB0, ENTRY_CopyBytes2Mod }, // CMPXCHG (0F B0)958{ 0xB1, ENTRY_CopyBytes2Mod }, // CMPXCHG (0F B1)959{ 0xB2, ENTRY_CopyBytes2Mod }, // LSS/r960{ 0xB3, ENTRY_CopyBytes2Mod }, // BTR (0F B3)961{ 0xB4, ENTRY_CopyBytes2Mod }, // LFS/r962{ 0xB5, ENTRY_CopyBytes2Mod }, // LGS/r963{ 0xB6, ENTRY_CopyBytes2Mod }, // MOVZX/r964{ 0xB7, ENTRY_CopyBytes2Mod }, // MOVZX/r965{ 0xB8, ENTRY_Invalid }, // _B8966{ 0xB9, ENTRY_Invalid }, // _B9967{ 0xBA, ENTRY_CopyBytes2Mod1 }, // BT & BTC & BTR & BTS (0F BA)968{ 0xBB, ENTRY_CopyBytes2Mod }, // BTC (0F BB)969{ 0xBC, ENTRY_CopyBytes2Mod }, // BSF (0F BC)970{ 0xBD, ENTRY_CopyBytes2Mod }, // BSR (0F BD)971{ 0xBE, ENTRY_CopyBytes2Mod }, // MOVSX/r972{ 0xBF, ENTRY_CopyBytes2Mod }, // MOVSX/r973{ 0xC0, ENTRY_CopyBytes2Mod }, // XADD/r974{ 0xC1, ENTRY_CopyBytes2Mod }, // XADD/r975{ 0xC2, ENTRY_CopyBytes2Mod }, // CMPPS &976{ 0xC3, ENTRY_CopyBytes2Mod }, // MOVNTI977{ 0xC4, ENTRY_CopyBytes2Mod1 }, // PINSRW /r ib978{ 0xC5, ENTRY_CopyBytes2Mod1 }, // PEXTRW /r ib979{ 0xC6, ENTRY_CopyBytes2Mod1 }, // SHUFPS & SHUFPD980{ 0xC7, ENTRY_CopyBytes2Mod }, // CMPXCHG8B (0F C7)981{ 0xC8, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd982{ 0xC9, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd983{ 0xCA, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd984{ 0xCB, ENTRY_CopyBytes2 }, //CVTPD2PI BSWAP 0F C8 + rd985{ 0xCC, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd986{ 0xCD, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd987{ 0xCE, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd988{ 0xCF, ENTRY_CopyBytes2 }, // BSWAP 0F C8 + rd989{ 0xD0, ENTRY_Invalid }, // _D0990{ 0xD1, ENTRY_CopyBytes2Mod }, // PSRLW/r991{ 0xD2, ENTRY_CopyBytes2Mod }, // PSRLD/r992{ 0xD3, ENTRY_CopyBytes2Mod }, // PSRLQ/r993{ 0xD4, ENTRY_CopyBytes2Mod }, // PADDQ994{ 0xD5, ENTRY_CopyBytes2Mod }, // PMULLW/r995{ 0xD6, ENTRY_CopyBytes2Mod }, // MOVDQ2Q / MOVQ2DQ996{ 0xD7, ENTRY_CopyBytes2Mod }, // PMOVMSKB/r997{ 0xD8, ENTRY_CopyBytes2Mod }, // PSUBUSB/r998{ 0xD9, ENTRY_CopyBytes2Mod }, // PSUBUSW/r999{ 0xDA, ENTRY_CopyBytes2Mod }, // PMINUB/r1000{ 0xDB, ENTRY_CopyBytes2Mod }, // PAND/r1001{ 0xDC, ENTRY_CopyBytes2Mod }, // PADDUSB/r1002{ 0xDD, ENTRY_CopyBytes2Mod }, // PADDUSW/r1003{ 0xDE, ENTRY_CopyBytes2Mod }, // PMAXUB/r1004{ 0xDF, ENTRY_CopyBytes2Mod }, // PANDN/r1005{ 0xE0, ENTRY_CopyBytes2Mod }, // PAVGB1006{ 0xE1, ENTRY_CopyBytes2Mod }, // PSRAW/r1007{ 0xE2, ENTRY_CopyBytes2Mod }, // PSRAD/r1008{ 0xE3, ENTRY_CopyBytes2Mod }, // PAVGW1009{ 0xE4, ENTRY_CopyBytes2Mod }, // PMULHUW/r1010{ 0xE5, ENTRY_CopyBytes2Mod }, // PMULHW/r1011{ 0xE6, ENTRY_CopyBytes2Mod }, // CTDQ2PD &1012{ 0xE7, ENTRY_CopyBytes2Mod }, // MOVNTQ1013{ 0xE8, ENTRY_CopyBytes2Mod }, // PSUBB/r1014{ 0xE9, ENTRY_CopyBytes2Mod }, // PSUBW/r1015{ 0xEA, ENTRY_CopyBytes2Mod }, // PMINSW/r1016{ 0xEB, ENTRY_CopyBytes2Mod }, // POR/r1017{ 0xEC, ENTRY_CopyBytes2Mod }, // PADDSB/r1018{ 0xED, ENTRY_CopyBytes2Mod }, // PADDSW/r1019{ 0xEE, ENTRY_CopyBytes2Mod }, // PMAXSW /r1020{ 0xEF, ENTRY_CopyBytes2Mod }, // PXOR/r1021{ 0xF0, ENTRY_Invalid }, // _F01022{ 0xF1, ENTRY_CopyBytes2Mod }, // PSLLW/r1023{ 0xF2, ENTRY_CopyBytes2Mod }, // PSLLD/r1024{ 0xF3, ENTRY_CopyBytes2Mod }, // PSLLQ/r1025{ 0xF4, ENTRY_CopyBytes2Mod }, // PMULUDQ/r1026{ 0xF5, ENTRY_CopyBytes2Mod }, // PMADDWD/r1027{ 0xF6, ENTRY_CopyBytes2Mod }, // PSADBW/r1028{ 0xF7, ENTRY_CopyBytes2Mod }, // MASKMOVQ1029{ 0xF8, ENTRY_CopyBytes2Mod }, // PSUBB/r1030{ 0xF9, ENTRY_CopyBytes2Mod }, // PSUBW/r1031{ 0xFA, ENTRY_CopyBytes2Mod }, // PSUBD/r1032{ 0xFB, ENTRY_CopyBytes2Mod }, // FSUBQ/r1033{ 0xFC, ENTRY_CopyBytes2Mod }, // PADDB/r1034{ 0xFD, ENTRY_CopyBytes2Mod }, // PADDW/r1035{ 0xFE, ENTRY_CopyBytes2Mod }, // PADDD/r1036{ 0xFF, ENTRY_Invalid }, // _FF1037{ 0, ENTRY_End },1038};10391040BOOL CDetourDis::SanityCheckSystem()1041{1042ULONG n = 0;1043for (; n < 256; n++) {1044REFCOPYENTRY pEntry = &s_rceCopyTable[n];10451046if (n != pEntry->nOpcode) {1047ASSERT(n == pEntry->nOpcode);1048return FALSE;1049}1050}1051if (s_rceCopyTable[256].pfCopy != NULL) {1052ASSERT(!"Missing end marker.");1053return FALSE;1054}10551056for (n = 0; n < 256; n++) {1057REFCOPYENTRY pEntry = &s_rceCopyTable0F[n];10581059if (n != pEntry->nOpcode) {1060ASSERT(n == pEntry->nOpcode);1061return FALSE;1062}1063}1064if (s_rceCopyTable0F[256].pfCopy != NULL) {1065ASSERT(!"Missing end marker.");1066return FALSE;1067}10681069return TRUE;1070}1071#endif // defined(DETOURS_X64) || defined(DETOURS_X86)10721073/////////////////////////////////////////////////////////// IA64 Disassembler.1074//1075#ifdef DETOURS_IA641076#error Feature not supported in this release.107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595#endif // DETOURS_IA6415961597//1598///////////////////////////////////////////////////////////////// End of File.159916001601