2015-08-21 07:04:50 +00:00
|
|
|
/* Unicorn Emulator Engine */
|
|
|
|
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2015 */
|
|
|
|
|
2018-02-24 06:23:15 +00:00
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "cpu.h"
|
2015-08-21 07:04:50 +00:00
|
|
|
#include "hw/boards.h"
|
|
|
|
#include "hw/i386/pc.h"
|
2016-03-02 03:43:02 +00:00
|
|
|
#include "sysemu/cpus.h"
|
2015-08-21 07:04:50 +00:00
|
|
|
#include "unicorn.h"
|
|
|
|
#include "tcg.h"
|
|
|
|
#include "unicorn_common.h"
|
2016-02-05 03:09:41 +00:00
|
|
|
#include <unicorn/x86.h> /* needed for uc_x86_mmr */
|
2016-03-02 03:43:02 +00:00
|
|
|
#include "uc_priv.h"
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2018-03-04 02:42:43 +00:00
|
|
|
static void cpu_get_fp80(uint64_t *pmant, uint16_t *pexp, floatx80 f)
|
|
|
|
{
|
|
|
|
CPU_LDoubleU temp;
|
|
|
|
|
|
|
|
temp.d = f;
|
|
|
|
*pmant = temp.l.lower;
|
|
|
|
*pexp = temp.l.upper;
|
|
|
|
}
|
|
|
|
|
|
|
|
static floatx80 cpu_set_fp80(uint64_t mant, uint16_t upper)
|
|
|
|
{
|
|
|
|
CPU_LDoubleU temp;
|
|
|
|
|
|
|
|
temp.l.upper = upper;
|
|
|
|
temp.l.lower = mant;
|
|
|
|
return temp.d;
|
|
|
|
}
|
|
|
|
|
2017-02-09 15:49:54 +00:00
|
|
|
#define X86_NON_CS_FLAGS (DESC_P_MASK | DESC_S_MASK | DESC_W_MASK | DESC_A_MASK)
|
2017-02-08 01:37:41 +00:00
|
|
|
static void load_seg_16_helper(CPUX86State *env, int seg, uint32_t selector)
|
|
|
|
{
|
2017-02-09 15:49:54 +00:00
|
|
|
cpu_x86_load_seg_cache(env, seg, selector, (selector << 4), 0xffff, X86_NON_CS_FLAGS);
|
2017-02-08 01:37:41 +00:00
|
|
|
}
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2017-02-24 13:37:19 +00:00
|
|
|
|
|
|
|
extern void helper_wrmsr(CPUX86State *env);
|
|
|
|
extern void helper_rdmsr(CPUX86State *env);
|
|
|
|
|
2016-08-20 11:14:07 +00:00
|
|
|
const int X86_REGS_STORAGE_SIZE = offsetof(CPUX86State, tlb_table);
|
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
static void x86_set_pc(struct uc_struct *uc, uint64_t address)
|
|
|
|
{
|
2018-03-07 15:33:21 +00:00
|
|
|
CPUX86State *state = uc->cpu->env_ptr;
|
|
|
|
|
|
|
|
state->eip = address;
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void x86_release(void *ctx);
|
|
|
|
|
|
|
|
void x86_release(void *ctx)
|
|
|
|
{
|
|
|
|
TCGContext *s = (TCGContext *) ctx;
|
|
|
|
|
2016-01-10 15:34:36 +00:00
|
|
|
release_common(ctx);
|
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
// arch specific
|
2016-12-21 14:28:36 +00:00
|
|
|
g_free(s->tb_ctx.tbs);
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
2015-08-26 11:06:12 +00:00
|
|
|
void x86_reg_reset(struct uc_struct *uc)
|
2015-08-21 07:04:50 +00:00
|
|
|
{
|
2016-09-23 14:38:21 +00:00
|
|
|
CPUArchState *env = uc->cpu->env_ptr;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2015-09-01 16:16:45 +00:00
|
|
|
env->features[FEAT_1_EDX] = CPUID_CX8 | CPUID_CMOV | CPUID_SSE2 | CPUID_FXSR | CPUID_SSE | CPUID_CLFLUSH;
|
|
|
|
env->features[FEAT_1_ECX] = CPUID_EXT_SSSE3 | CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_AES;
|
|
|
|
env->features[FEAT_8000_0001_EDX] = CPUID_EXT2_3DNOW | CPUID_EXT2_RDTSCP;
|
|
|
|
env->features[FEAT_8000_0001_ECX] = CPUID_EXT3_LAHF_LM | CPUID_EXT3_ABM | CPUID_EXT3_SKINIT | CPUID_EXT3_CR8LEG;
|
|
|
|
env->features[FEAT_7_0_EBX] = CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX | CPUID_7_0_EBX_SMAP;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
memset(env->regs, 0, sizeof(env->regs));
|
|
|
|
memset(env->segs, 0, sizeof(env->segs));
|
|
|
|
memset(env->cr, 0, sizeof(env->cr));
|
|
|
|
|
|
|
|
memset(&env->ldt, 0, sizeof(env->ldt));
|
|
|
|
memset(&env->gdt, 0, sizeof(env->gdt));
|
|
|
|
memset(&env->tr, 0, sizeof(env->tr));
|
|
|
|
memset(&env->idt, 0, sizeof(env->idt));
|
|
|
|
|
|
|
|
env->eip = 0;
|
|
|
|
env->eflags = 0;
|
2015-11-05 12:26:39 +00:00
|
|
|
env->eflags0 = 0;
|
2017-09-15 15:18:38 +00:00
|
|
|
env->cc_op = CC_OP_EFLAGS;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
env->fpstt = 0; /* top of stack index */
|
|
|
|
env->fpus = 0;
|
|
|
|
env->fpuc = 0;
|
|
|
|
memset(env->fptags, 0, sizeof(env->fptags)); /* 0 = valid, 1 = empty */
|
|
|
|
|
|
|
|
env->mxcsr = 0;
|
|
|
|
memset(env->xmm_regs, 0, sizeof(env->xmm_regs));
|
|
|
|
memset(&env->xmm_t0, 0, sizeof(env->xmm_t0));
|
|
|
|
memset(&env->mmx_t0, 0, sizeof(env->mmx_t0));
|
|
|
|
|
|
|
|
memset(env->opmask_regs, 0, sizeof(env->opmask_regs));
|
|
|
|
|
|
|
|
/* sysenter registers */
|
|
|
|
env->sysenter_cs = 0;
|
|
|
|
env->sysenter_esp = 0;
|
|
|
|
env->sysenter_eip = 0;
|
|
|
|
env->efer = 0;
|
|
|
|
env->star = 0;
|
|
|
|
|
|
|
|
env->vm_hsave = 0;
|
|
|
|
|
|
|
|
env->tsc = 0;
|
|
|
|
env->tsc_adjust = 0;
|
|
|
|
env->tsc_deadline = 0;
|
|
|
|
|
|
|
|
env->mcg_status = 0;
|
|
|
|
env->msr_ia32_misc_enable = 0;
|
|
|
|
env->msr_ia32_feature_control = 0;
|
|
|
|
|
|
|
|
env->msr_fixed_ctr_ctrl = 0;
|
|
|
|
env->msr_global_ctrl = 0;
|
|
|
|
env->msr_global_status = 0;
|
|
|
|
env->msr_global_ovf_ctrl = 0;
|
|
|
|
memset(env->msr_fixed_counters, 0, sizeof(env->msr_fixed_counters));
|
|
|
|
memset(env->msr_gp_counters, 0, sizeof(env->msr_gp_counters));
|
|
|
|
memset(env->msr_gp_evtsel, 0, sizeof(env->msr_gp_evtsel));
|
|
|
|
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
env->lstar = 0;
|
|
|
|
env->cstar = 0;
|
|
|
|
env->fmask = 0;
|
|
|
|
env->kernelgsbase = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO: reset other registers in CPUX86State qemu/target-i386/cpu.h
|
|
|
|
|
|
|
|
// properly initialize internal setup for each mode
|
|
|
|
switch(uc->mode) {
|
|
|
|
default:
|
|
|
|
break;
|
2015-08-25 16:39:46 +00:00
|
|
|
case UC_MODE_16:
|
|
|
|
env->hflags = 0;
|
|
|
|
env->cr[0] = 0;
|
2017-02-09 15:49:54 +00:00
|
|
|
//undo the damage done by the memset of env->segs above
|
|
|
|
//for R_CS, not quite the same as x86_cpu_reset
|
|
|
|
cpu_x86_load_seg_cache(env, R_CS, 0, 0, 0xffff,
|
|
|
|
DESC_P_MASK | DESC_S_MASK | DESC_CS_MASK |
|
|
|
|
DESC_R_MASK | DESC_A_MASK);
|
|
|
|
//remainder yields same state as x86_cpu_reset
|
|
|
|
load_seg_16_helper(env, R_DS, 0);
|
|
|
|
load_seg_16_helper(env, R_ES, 0);
|
|
|
|
load_seg_16_helper(env, R_SS, 0);
|
|
|
|
load_seg_16_helper(env, R_FS, 0);
|
|
|
|
load_seg_16_helper(env, R_GS, 0);
|
|
|
|
|
2015-08-25 16:39:46 +00:00
|
|
|
break;
|
2015-08-21 07:04:50 +00:00
|
|
|
case UC_MODE_32:
|
2015-08-23 02:41:14 +00:00
|
|
|
env->hflags |= HF_CS32_MASK | HF_SS32_MASK | HF_OSFXSR_MASK;
|
2015-12-25 03:55:15 +00:00
|
|
|
cpu_x86_update_cr0(env, CR0_PE_MASK); // protected mode
|
2015-08-21 07:04:50 +00:00
|
|
|
break;
|
|
|
|
case UC_MODE_64:
|
2015-08-23 02:41:14 +00:00
|
|
|
env->hflags |= HF_CS32_MASK | HF_SS32_MASK | HF_CS64_MASK | HF_LMA_MASK | HF_OSFXSR_MASK;
|
2015-08-21 07:04:50 +00:00
|
|
|
env->hflags &= ~(HF_ADDSEG_MASK);
|
2015-12-25 03:55:15 +00:00
|
|
|
cpu_x86_update_cr0(env, CR0_PE_MASK); // protected mode
|
2015-08-21 07:04:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-24 13:37:19 +00:00
|
|
|
static int x86_msr_read(struct uc_struct *uc, uc_x86_msr *msr)
|
|
|
|
{
|
|
|
|
CPUX86State *env = (CPUX86State *)uc->cpu->env_ptr;
|
|
|
|
uint64_t ecx = env->regs[R_ECX];
|
|
|
|
uint64_t eax = env->regs[R_EAX];
|
|
|
|
uint64_t edx = env->regs[R_EDX];
|
|
|
|
|
|
|
|
env->regs[R_ECX] = msr->rid;
|
|
|
|
helper_rdmsr(env);
|
|
|
|
|
|
|
|
msr->value = ((uint32_t)env->regs[R_EAX]) |
|
2017-05-13 17:16:17 +00:00
|
|
|
((uint64_t)((uint32_t)env->regs[R_EDX]) << 32);
|
2017-02-24 13:37:19 +00:00
|
|
|
|
|
|
|
env->regs[R_EAX] = eax;
|
|
|
|
env->regs[R_ECX] = ecx;
|
|
|
|
env->regs[R_EDX] = edx;
|
|
|
|
|
|
|
|
/* The implementation doesn't throw exception or return an error if there is one, so
|
|
|
|
* we will return 0. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int x86_msr_write(struct uc_struct *uc, uc_x86_msr *msr)
|
|
|
|
{
|
|
|
|
CPUX86State *env = (CPUX86State *)uc->cpu->env_ptr;
|
|
|
|
uint64_t ecx = env->regs[R_ECX];
|
|
|
|
uint64_t eax = env->regs[R_EAX];
|
|
|
|
uint64_t edx = env->regs[R_EDX];
|
|
|
|
|
|
|
|
env->regs[R_ECX] = msr->rid;
|
|
|
|
env->regs[R_EAX] = (unsigned int)msr->value;
|
|
|
|
env->regs[R_EDX] = (unsigned int)(msr->value >> 32);
|
|
|
|
helper_wrmsr(env);
|
|
|
|
|
|
|
|
env->regs[R_ECX] = ecx;
|
|
|
|
env->regs[R_EAX] = eax;
|
|
|
|
env->regs[R_EDX] = edx;
|
|
|
|
|
|
|
|
/* The implementation doesn't throw exception or return an error if there is one, so
|
|
|
|
* we will return 0. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-04 15:25:30 +00:00
|
|
|
int x86_reg_read(struct uc_struct *uc, unsigned int *regs, void **vals, int count)
|
2015-08-21 07:04:50 +00:00
|
|
|
{
|
2016-09-23 14:38:21 +00:00
|
|
|
CPUState *mycpu = uc->cpu;
|
2018-03-07 15:33:21 +00:00
|
|
|
CPUX86State *state = &X86_CPU(uc, mycpu)->env;
|
2016-04-04 15:25:30 +00:00
|
|
|
int i;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2016-04-04 15:25:30 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
unsigned int regid = regs[i];
|
|
|
|
void *value = vals[i];
|
|
|
|
switch(regid) {
|
|
|
|
default:
|
|
|
|
break;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_FP0:
|
|
|
|
case UC_X86_REG_FP1:
|
|
|
|
case UC_X86_REG_FP2:
|
|
|
|
case UC_X86_REG_FP3:
|
|
|
|
case UC_X86_REG_FP4:
|
|
|
|
case UC_X86_REG_FP5:
|
|
|
|
case UC_X86_REG_FP6:
|
|
|
|
case UC_X86_REG_FP7:
|
2016-04-04 15:25:30 +00:00
|
|
|
{
|
2018-03-07 15:33:21 +00:00
|
|
|
floatx80 reg = state->fpregs[regid - UC_X86_REG_FP0].d;
|
2017-01-19 11:50:28 +00:00
|
|
|
cpu_get_fp80(value, (uint16_t*)((char*)value+sizeof(uint64_t)), reg);
|
2016-04-04 15:25:30 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case UC_X86_REG_FPSW:
|
|
|
|
{
|
2018-03-07 15:33:21 +00:00
|
|
|
uint16_t fpus = state->fpus;
|
2016-04-04 15:25:30 +00:00
|
|
|
fpus = fpus & ~0x3800;
|
2018-03-07 15:33:21 +00:00
|
|
|
fpus |= (state->fpstt & 0x7) << 11;
|
2016-04-04 15:25:30 +00:00
|
|
|
*(uint16_t*) value = fpus;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case UC_X86_REG_FPCW:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(uint16_t*) value = state->fpuc;
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
case UC_X86_REG_FPTAG:
|
|
|
|
{
|
|
|
|
#define EXPD(fp) (fp.l.upper & 0x7fff)
|
|
|
|
#define MANTD(fp) (fp.l.lower)
|
|
|
|
#define MAXEXPD 0x7fff
|
|
|
|
int fptag, exp, i;
|
|
|
|
uint64_t mant;
|
|
|
|
CPU_LDoubleU tmp;
|
|
|
|
fptag = 0;
|
|
|
|
for (i = 7; i >= 0; i--) {
|
|
|
|
fptag <<= 2;
|
2018-03-07 15:33:21 +00:00
|
|
|
if (state->fptags[i]) {
|
2016-04-04 15:25:30 +00:00
|
|
|
fptag |= 3;
|
|
|
|
} else {
|
2018-03-07 15:33:21 +00:00
|
|
|
tmp.d = state->fpregs[i].d;
|
2016-04-04 15:25:30 +00:00
|
|
|
exp = EXPD(tmp);
|
|
|
|
mant = MANTD(tmp);
|
|
|
|
if (exp == 0 && mant == 0) {
|
|
|
|
/* zero */
|
|
|
|
fptag |= 1;
|
|
|
|
} else if (exp == 0 || exp == MAXEXPD
|
|
|
|
|| (mant & (1LL << 63)) == 0) {
|
|
|
|
/* NaNs, infinity, denormal */
|
|
|
|
fptag |= 2;
|
|
|
|
}
|
2016-03-09 22:14:33 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-04 15:25:30 +00:00
|
|
|
*(uint16_t*) value = fptag;
|
2016-03-09 22:14:33 +00:00
|
|
|
}
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_XMM0:
|
|
|
|
case UC_X86_REG_XMM1:
|
|
|
|
case UC_X86_REG_XMM2:
|
|
|
|
case UC_X86_REG_XMM3:
|
|
|
|
case UC_X86_REG_XMM4:
|
|
|
|
case UC_X86_REG_XMM5:
|
|
|
|
case UC_X86_REG_XMM6:
|
|
|
|
case UC_X86_REG_XMM7:
|
2016-06-29 10:56:53 +00:00
|
|
|
{
|
|
|
|
float64 *dst = (float64*)value;
|
2018-03-07 15:33:21 +00:00
|
|
|
ZMMReg *reg = &state->xmm_regs[regid - UC_X86_REG_XMM0];
|
2018-02-19 04:53:11 +00:00
|
|
|
dst[0] = reg->ZMM_D(0);
|
|
|
|
dst[1] = reg->ZMM_D(1);
|
2016-06-29 10:56:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-05-05 01:02:58 +00:00
|
|
|
case UC_X86_REG_YMM0:
|
|
|
|
case UC_X86_REG_YMM1:
|
|
|
|
case UC_X86_REG_YMM2:
|
|
|
|
case UC_X86_REG_YMM3:
|
|
|
|
case UC_X86_REG_YMM4:
|
|
|
|
case UC_X86_REG_YMM5:
|
|
|
|
case UC_X86_REG_YMM6:
|
|
|
|
case UC_X86_REG_YMM7:
|
|
|
|
{
|
|
|
|
float64 *dst = (float64*)value;
|
2018-03-07 15:33:21 +00:00
|
|
|
ZMMReg *reg = &state->xmm_regs[regid - UC_X86_REG_XMM0];
|
2018-02-19 04:53:11 +00:00
|
|
|
dst[0] = reg->ZMM_D(0);
|
|
|
|
dst[1] = reg->ZMM_D(1);
|
|
|
|
dst[2] = reg->ZMM_D(2);
|
|
|
|
dst[3] = reg->ZMM_D(3);
|
2017-05-05 01:02:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-04-04 15:25:30 +00:00
|
|
|
}
|
2016-03-09 21:07:38 +00:00
|
|
|
|
2016-04-04 15:25:30 +00:00
|
|
|
switch(uc->mode) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case UC_MODE_16:
|
|
|
|
switch(regid) {
|
|
|
|
default: break;
|
|
|
|
case UC_X86_REG_ES:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = state->segs[R_ES].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
case UC_X86_REG_SS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = state->segs[R_SS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
case UC_X86_REG_DS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = state->segs[R_DS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
case UC_X86_REG_FS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = state->segs[R_FS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
case UC_X86_REG_GS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = state->segs[R_GS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// fall-thru
|
|
|
|
case UC_MODE_32:
|
|
|
|
switch(regid) {
|
|
|
|
default:
|
|
|
|
break;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_CR0:
|
|
|
|
case UC_X86_REG_CR1:
|
|
|
|
case UC_X86_REG_CR2:
|
|
|
|
case UC_X86_REG_CR3:
|
|
|
|
case UC_X86_REG_CR4:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = state->cr[regid - UC_X86_REG_CR0];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_DR0:
|
|
|
|
case UC_X86_REG_DR1:
|
|
|
|
case UC_X86_REG_DR2:
|
|
|
|
case UC_X86_REG_DR3:
|
|
|
|
case UC_X86_REG_DR4:
|
|
|
|
case UC_X86_REG_DR5:
|
|
|
|
case UC_X86_REG_DR6:
|
|
|
|
case UC_X86_REG_DR7:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = state->dr[regid - UC_X86_REG_DR0];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EFLAGS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = cpu_compute_eflags(state);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EAX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = state->regs[R_EAX];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_EAX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AH:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_H(state->regs[R_EAX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_EAX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EBX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = state->regs[R_EBX];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_EBX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BH:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_H(state->regs[R_EBX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_EBX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ECX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = state->regs[R_ECX];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_ECX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CH:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_H(state->regs[R_ECX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_ECX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EDX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = state->regs[R_EDX];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_EDX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DH:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_H(state->regs[R_EDX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_EDX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ESP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = state->regs[R_ESP];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_ESP]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EBP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = state->regs[R_EBP];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_EBP]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ESI:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = state->regs[R_ESI];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SI:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_ESI]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EDI:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = state->regs[R_EDI];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DI:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_EDI]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EIP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = state->eip;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_IP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->eip);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_CS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_DS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_SS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ES:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_ES].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_FS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_FS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_GS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_GS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_IDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
((uc_x86_mmr *)value)->limit = (uint16_t)state->idt.limit;
|
|
|
|
((uc_x86_mmr *)value)->base = (uint32_t)state->idt.base;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_GDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
((uc_x86_mmr *)value)->limit = (uint16_t)state->gdt.limit;
|
|
|
|
((uc_x86_mmr *)value)->base = (uint32_t)state->gdt.base;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_LDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
((uc_x86_mmr *)value)->limit = state->ldt.limit;
|
|
|
|
((uc_x86_mmr *)value)->base = (uint32_t)state->ldt.base;
|
|
|
|
((uc_x86_mmr *)value)->selector = (uint16_t)state->ldt.selector;
|
|
|
|
((uc_x86_mmr *)value)->flags = state->ldt.flags;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_TR:
|
2018-03-07 15:33:21 +00:00
|
|
|
((uc_x86_mmr *)value)->limit = state->tr.limit;
|
|
|
|
((uc_x86_mmr *)value)->base = (uint32_t)state->tr.base;
|
|
|
|
((uc_x86_mmr *)value)->selector = (uint16_t)state->tr.selector;
|
|
|
|
((uc_x86_mmr *)value)->flags = state->tr.flags;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
2017-02-24 13:37:19 +00:00
|
|
|
case UC_X86_REG_MSR:
|
|
|
|
x86_msr_read(uc, (uc_x86_msr *)value);
|
|
|
|
break;
|
2016-04-04 15:25:30 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
#ifdef TARGET_X86_64
|
2016-04-04 15:25:30 +00:00
|
|
|
case UC_MODE_64:
|
|
|
|
switch(regid) {
|
|
|
|
default:
|
|
|
|
break;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_CR0:
|
|
|
|
case UC_X86_REG_CR1:
|
|
|
|
case UC_X86_REG_CR2:
|
|
|
|
case UC_X86_REG_CR3:
|
|
|
|
case UC_X86_REG_CR4:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int64_t *)value = state->cr[regid - UC_X86_REG_CR0];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_DR0:
|
|
|
|
case UC_X86_REG_DR1:
|
|
|
|
case UC_X86_REG_DR2:
|
|
|
|
case UC_X86_REG_DR3:
|
|
|
|
case UC_X86_REG_DR4:
|
|
|
|
case UC_X86_REG_DR5:
|
|
|
|
case UC_X86_REG_DR6:
|
|
|
|
case UC_X86_REG_DR7:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int64_t *)value = state->dr[regid - UC_X86_REG_DR0];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EFLAGS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int64_t *)value = cpu_compute_eflags(state);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RAX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(uint64_t *)value = state->regs[R_EAX];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EAX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[R_EAX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_EAX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AH:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_H(state->regs[R_EAX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_EAX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RBX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(uint64_t *)value = state->regs[R_EBX];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EBX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[R_EBX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_EBX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BH:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_H(state->regs[R_EBX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_EBX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RCX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(uint64_t *)value = state->regs[R_ECX];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ECX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[R_ECX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_ECX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CH:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_H(state->regs[R_ECX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_ECX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RDX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(uint64_t *)value = state->regs[R_EDX];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EDX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[R_EDX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DX:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_EDX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DH:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_H(state->regs[R_EDX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_EDX]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RSP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(uint64_t *)value = state->regs[R_ESP];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ESP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[R_ESP]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_ESP]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SPL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_ESP]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RBP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(uint64_t *)value = state->regs[R_EBP];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EBP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[R_EBP]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_EBP]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BPL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_EBP]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RSI:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(uint64_t *)value = state->regs[R_ESI];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ESI:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[R_ESI]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SI:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_ESI]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SIL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_ESI]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RDI:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(uint64_t *)value = state->regs[R_EDI];
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EDI:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[R_EDI]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DI:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[R_EDI]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DIL:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[R_EDI]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RIP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(uint64_t *)value = state->eip;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EIP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->eip);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_IP:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->eip);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_CS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_DS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_SS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ES:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_ES].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_FS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_FS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_GS:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = (uint16_t)state->segs[R_GS].selector;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R8:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int64_t *)value = READ_QWORD(state->regs[8]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R8D:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[8]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R8W:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[8]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R8B:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[8]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R9:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int64_t *)value = READ_QWORD(state->regs[9]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R9D:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[9]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R9W:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[9]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R9B:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[9]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R10:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int64_t *)value = READ_QWORD(state->regs[10]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R10D:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[10]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R10W:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[10]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R10B:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[10]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R11:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int64_t *)value = READ_QWORD(state->regs[11]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R11D:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[11]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R11W:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[11]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R11B:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[11]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R12:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int64_t *)value = READ_QWORD(state->regs[12]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R12D:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[12]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R12W:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[12]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R12B:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[12]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R13:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int64_t *)value = READ_QWORD(state->regs[13]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R13D:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[13]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R13W:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[13]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R13B:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[13]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R14:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int64_t *)value = READ_QWORD(state->regs[14]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R14D:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[14]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R14W:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[14]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R14B:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[14]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R15:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int64_t *)value = READ_QWORD(state->regs[15]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R15D:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int32_t *)value = READ_DWORD(state->regs[15]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R15W:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int16_t *)value = READ_WORD(state->regs[15]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R15B:
|
2018-03-07 15:33:21 +00:00
|
|
|
*(int8_t *)value = READ_BYTE_L(state->regs[15]);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_IDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
((uc_x86_mmr *)value)->limit = (uint16_t)state->idt.limit;
|
|
|
|
((uc_x86_mmr *)value)->base = state->idt.base;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_GDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
((uc_x86_mmr *)value)->limit = (uint16_t)state->gdt.limit;
|
|
|
|
((uc_x86_mmr *)value)->base = state->gdt.base;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_LDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
((uc_x86_mmr *)value)->limit = state->ldt.limit;
|
|
|
|
((uc_x86_mmr *)value)->base = state->ldt.base;
|
|
|
|
((uc_x86_mmr *)value)->selector = (uint16_t)state->ldt.selector;
|
|
|
|
((uc_x86_mmr *)value)->flags = state->ldt.flags;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_TR:
|
2018-03-07 15:33:21 +00:00
|
|
|
((uc_x86_mmr *)value)->limit = state->tr.limit;
|
|
|
|
((uc_x86_mmr *)value)->base = state->tr.base;
|
|
|
|
((uc_x86_mmr *)value)->selector = (uint16_t)state->tr.selector;
|
|
|
|
((uc_x86_mmr *)value)->flags = state->tr.flags;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
2017-02-24 13:37:19 +00:00
|
|
|
case UC_X86_REG_MSR:
|
|
|
|
x86_msr_read(uc, (uc_x86_msr *)value);
|
|
|
|
break;
|
2016-04-04 15:25:30 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-08-21 07:04:50 +00:00
|
|
|
#endif
|
2016-04-04 15:25:30 +00:00
|
|
|
}
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-04 15:25:30 +00:00
|
|
|
int x86_reg_write(struct uc_struct *uc, unsigned int *regs, void *const *vals, int count)
|
2015-08-21 07:04:50 +00:00
|
|
|
{
|
2016-09-23 14:38:21 +00:00
|
|
|
CPUState *mycpu = uc->cpu;
|
2018-03-07 15:33:21 +00:00
|
|
|
CPUX86State *state = &X86_CPU(uc, mycpu)->env;
|
2016-04-04 15:25:30 +00:00
|
|
|
int i;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2016-04-04 15:25:30 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
unsigned int regid = regs[i];
|
|
|
|
const void *value = vals[i];
|
|
|
|
switch(regid) {
|
|
|
|
default:
|
|
|
|
break;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_FP0:
|
|
|
|
case UC_X86_REG_FP1:
|
|
|
|
case UC_X86_REG_FP2:
|
|
|
|
case UC_X86_REG_FP3:
|
|
|
|
case UC_X86_REG_FP4:
|
|
|
|
case UC_X86_REG_FP5:
|
|
|
|
case UC_X86_REG_FP6:
|
|
|
|
case UC_X86_REG_FP7:
|
2016-04-04 15:25:30 +00:00
|
|
|
{
|
|
|
|
uint64_t mant = *(uint64_t*) value;
|
2017-01-19 11:50:28 +00:00
|
|
|
uint16_t upper = *(uint16_t*) ((char*)value + sizeof(uint64_t));
|
2018-03-07 15:33:21 +00:00
|
|
|
state->fpregs[regid - UC_X86_REG_FP0].d = cpu_set_fp80(mant, upper);
|
2016-04-04 15:25:30 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case UC_X86_REG_FPSW:
|
|
|
|
{
|
|
|
|
uint16_t fpus = *(uint16_t*) value;
|
2018-03-07 15:33:21 +00:00
|
|
|
state->fpus = fpus & ~0x3800;
|
|
|
|
state->fpstt = (fpus >> 11) & 0x7;
|
2016-03-09 22:14:33 +00:00
|
|
|
}
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
case UC_X86_REG_FPCW:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->fpuc = *(uint16_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
case UC_X86_REG_FPTAG:
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint16_t fptag = *(uint16_t*) value;
|
|
|
|
for (i = 0; i < 8; i++) {
|
2018-03-07 15:33:21 +00:00
|
|
|
state->fptags[i] = ((fptag & 3) == 3);
|
2016-04-04 15:25:30 +00:00
|
|
|
fptag >>= 2;
|
|
|
|
}
|
2016-03-20 10:15:41 +00:00
|
|
|
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_XMM0:
|
|
|
|
case UC_X86_REG_XMM1:
|
|
|
|
case UC_X86_REG_XMM2:
|
|
|
|
case UC_X86_REG_XMM3:
|
|
|
|
case UC_X86_REG_XMM4:
|
|
|
|
case UC_X86_REG_XMM5:
|
|
|
|
case UC_X86_REG_XMM6:
|
|
|
|
case UC_X86_REG_XMM7:
|
2016-06-29 10:56:53 +00:00
|
|
|
{
|
|
|
|
float64 *src = (float64*)value;
|
2018-03-07 15:33:21 +00:00
|
|
|
ZMMReg *reg = &state->xmm_regs[regid - UC_X86_REG_XMM0];
|
2018-02-19 04:53:11 +00:00
|
|
|
reg->ZMM_D(0) = src[0];
|
|
|
|
reg->ZMM_D(1) = src[1];
|
2016-06-29 10:56:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-05-05 01:02:58 +00:00
|
|
|
case UC_X86_REG_YMM0:
|
|
|
|
case UC_X86_REG_YMM1:
|
|
|
|
case UC_X86_REG_YMM2:
|
|
|
|
case UC_X86_REG_YMM3:
|
|
|
|
case UC_X86_REG_YMM4:
|
|
|
|
case UC_X86_REG_YMM5:
|
|
|
|
case UC_X86_REG_YMM6:
|
|
|
|
case UC_X86_REG_YMM7:
|
|
|
|
{
|
|
|
|
float64 *src = (float64*)value;
|
2018-03-07 15:33:21 +00:00
|
|
|
ZMMReg *reg = &state->xmm_regs[regid - UC_X86_REG_XMM0];
|
2018-02-19 04:53:11 +00:00
|
|
|
reg->ZMM_D(4) = src[0];
|
|
|
|
reg->ZMM_D(5) = src[1];
|
|
|
|
reg->ZMM_D(6) = src[2];
|
|
|
|
reg->ZMM_D(7) = src[3];
|
2017-05-05 01:02:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-04-04 15:25:30 +00:00
|
|
|
}
|
2016-03-09 21:07:38 +00:00
|
|
|
|
2016-04-04 15:25:30 +00:00
|
|
|
switch(uc->mode) {
|
|
|
|
default:
|
|
|
|
break;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2016-04-04 15:25:30 +00:00
|
|
|
case UC_MODE_16:
|
|
|
|
switch(regid) {
|
|
|
|
default: break;
|
|
|
|
case UC_X86_REG_ES:
|
2018-03-07 15:33:21 +00:00
|
|
|
load_seg_16_helper(state, R_ES, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
case UC_X86_REG_SS:
|
2018-03-07 15:33:21 +00:00
|
|
|
load_seg_16_helper(state, R_SS, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
case UC_X86_REG_DS:
|
2018-03-07 15:33:21 +00:00
|
|
|
load_seg_16_helper(state, R_DS, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
case UC_X86_REG_FS:
|
2018-03-07 15:33:21 +00:00
|
|
|
load_seg_16_helper(state, R_FS, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
case UC_X86_REG_GS:
|
2018-03-07 15:33:21 +00:00
|
|
|
load_seg_16_helper(state, R_GS, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// fall-thru
|
|
|
|
case UC_MODE_32:
|
|
|
|
switch(regid) {
|
|
|
|
default:
|
|
|
|
break;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_CR0:
|
|
|
|
case UC_X86_REG_CR1:
|
|
|
|
case UC_X86_REG_CR2:
|
|
|
|
case UC_X86_REG_CR3:
|
|
|
|
case UC_X86_REG_CR4:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->cr[regid - UC_X86_REG_CR0] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_DR0:
|
|
|
|
case UC_X86_REG_DR1:
|
|
|
|
case UC_X86_REG_DR2:
|
|
|
|
case UC_X86_REG_DR3:
|
|
|
|
case UC_X86_REG_DR4:
|
|
|
|
case UC_X86_REG_DR5:
|
|
|
|
case UC_X86_REG_DR6:
|
|
|
|
case UC_X86_REG_DR7:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->dr[regid - UC_X86_REG_DR0] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EFLAGS:
|
2018-03-07 15:33:21 +00:00
|
|
|
cpu_load_eflags(state, *(uint32_t *)value, -1);
|
|
|
|
state->eflags0 = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EAX:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_EAX] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_EAX], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AH:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_H(state->regs[R_EAX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_EAX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EBX:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_EBX] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_EBX], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BH:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_H(state->regs[R_EBX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_EBX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ECX:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_ECX] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_ECX], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CH:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_H(state->regs[R_ECX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_ECX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EDX:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_EDX] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_EDX], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DH:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_H(state->regs[R_EDX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_EDX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ESP:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_ESP] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SP:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_ESP], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EBP:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_EBP] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BP:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_EBP], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ESI:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_ESI] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SI:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_ESI], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EDI:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_EDI] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DI:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_EDI], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EIP:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->eip = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
// force to quit execution and flush TB
|
|
|
|
uc->quit_request = true;
|
|
|
|
uc_emu_stop(uc);
|
|
|
|
break;
|
|
|
|
case UC_X86_REG_IP:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->eip, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
// force to quit execution and flush TB
|
|
|
|
uc->quit_request = true;
|
|
|
|
uc_emu_stop(uc);
|
|
|
|
break;
|
|
|
|
case UC_X86_REG_CS:
|
2018-03-07 15:33:21 +00:00
|
|
|
cpu_x86_load_seg(state, R_CS, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DS:
|
2018-03-07 15:33:21 +00:00
|
|
|
cpu_x86_load_seg(state, R_DS, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SS:
|
2018-03-07 15:33:21 +00:00
|
|
|
cpu_x86_load_seg(state, R_SS, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ES:
|
2018-03-07 15:33:21 +00:00
|
|
|
cpu_x86_load_seg(state, R_ES, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_FS:
|
2018-03-07 15:33:21 +00:00
|
|
|
cpu_x86_load_seg(state, R_FS, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_GS:
|
2018-03-07 15:33:21 +00:00
|
|
|
cpu_x86_load_seg(state, R_GS, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_IDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->idt.limit = (uint16_t)((uc_x86_mmr *)value)->limit;
|
|
|
|
state->idt.base = (uint32_t)((uc_x86_mmr *)value)->base;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_GDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->gdt.limit = (uint16_t)((uc_x86_mmr *)value)->limit;
|
|
|
|
state->gdt.base = (uint32_t)((uc_x86_mmr *)value)->base;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_LDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->ldt.limit = ((uc_x86_mmr *)value)->limit;
|
|
|
|
state->ldt.base = (uint32_t)((uc_x86_mmr *)value)->base;
|
|
|
|
state->ldt.selector = (uint16_t)((uc_x86_mmr *)value)->selector;
|
|
|
|
state->ldt.flags = ((uc_x86_mmr *)value)->flags;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_TR:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->tr.limit = ((uc_x86_mmr *)value)->limit;
|
|
|
|
state->tr.base = (uint32_t)((uc_x86_mmr *)value)->base;
|
|
|
|
state->tr.selector = (uint16_t)((uc_x86_mmr *)value)->selector;
|
|
|
|
state->tr.flags = ((uc_x86_mmr *)value)->flags;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
2017-02-24 13:37:19 +00:00
|
|
|
case UC_X86_REG_MSR:
|
|
|
|
x86_msr_write(uc, (uc_x86_msr *)value);
|
|
|
|
break;
|
2016-04-04 15:25:30 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
#ifdef TARGET_X86_64
|
2016-04-04 15:25:30 +00:00
|
|
|
case UC_MODE_64:
|
|
|
|
switch(regid) {
|
|
|
|
default:
|
|
|
|
break;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_CR0:
|
|
|
|
case UC_X86_REG_CR1:
|
|
|
|
case UC_X86_REG_CR2:
|
|
|
|
case UC_X86_REG_CR3:
|
|
|
|
case UC_X86_REG_CR4:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->cr[regid - UC_X86_REG_CR0] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
2017-01-21 01:28:22 +00:00
|
|
|
case UC_X86_REG_DR0:
|
|
|
|
case UC_X86_REG_DR1:
|
|
|
|
case UC_X86_REG_DR2:
|
|
|
|
case UC_X86_REG_DR3:
|
|
|
|
case UC_X86_REG_DR4:
|
|
|
|
case UC_X86_REG_DR5:
|
|
|
|
case UC_X86_REG_DR6:
|
|
|
|
case UC_X86_REG_DR7:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->dr[regid - UC_X86_REG_DR0] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EFLAGS:
|
2018-03-07 15:33:21 +00:00
|
|
|
cpu_load_eflags(state, *(uint64_t *)value, -1);
|
|
|
|
state->eflags0 = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RAX:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_EAX] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EAX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[R_EAX], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_EAX], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AH:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_H(state->regs[R_EAX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_AL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_EAX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RBX:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_EBX] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EBX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[R_EBX], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_EBX], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BH:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_H(state->regs[R_EBX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_EBX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RCX:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_ECX] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ECX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[R_ECX], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_ECX], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CH:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_H(state->regs[R_ECX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_CL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_ECX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RDX:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_EDX] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EDX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[R_EDX], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DX:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_EDX], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DH:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_H(state->regs[R_EDX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_EDX], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RSP:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_ESP] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ESP:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[R_ESP], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SP:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_ESP], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SPL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_ESP], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RBP:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_EBP] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EBP:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[R_EBP], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BP:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_EBP], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_BPL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_EBP], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RSI:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_ESI] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ESI:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[R_ESI], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SI:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_ESI], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SIL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_ESI], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RDI:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[R_EDI] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_EDI:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[R_EDI], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DI:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[R_EDI], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DIL:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[R_EDI], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_RIP:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->eip = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
// force to quit execution and flush TB
|
|
|
|
uc->quit_request = true;
|
|
|
|
uc_emu_stop(uc);
|
|
|
|
break;
|
|
|
|
case UC_X86_REG_EIP:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->eip, *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
// force to quit execution and flush TB
|
|
|
|
uc->quit_request = true;
|
|
|
|
uc_emu_stop(uc);
|
|
|
|
break;
|
|
|
|
case UC_X86_REG_IP:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->eip, *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
// force to quit execution and flush TB
|
|
|
|
uc->quit_request = true;
|
|
|
|
uc_emu_stop(uc);
|
|
|
|
break;
|
|
|
|
case UC_X86_REG_CS:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->segs[R_CS].selector = *(uint16_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_DS:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->segs[R_DS].selector = *(uint16_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_SS:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->segs[R_SS].selector = *(uint16_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_ES:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->segs[R_ES].selector = *(uint16_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_FS:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->segs[R_FS].selector = *(uint16_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_GS:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->segs[R_GS].selector = *(uint16_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R8:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[8] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R8D:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[8], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R8W:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[8], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R8B:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[8], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R9:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[9] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R9D:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[9], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R9W:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[9], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R9B:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[9], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R10:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[10] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R10D:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[10], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R10W:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[10], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R10B:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[10], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R11:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[11] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R11D:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[11], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R11W:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[11], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R11B:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[11], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R12:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[12] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R12D:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[12], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R12W:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[12], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R12B:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[12], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R13:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[13] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R13D:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[13], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R13W:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[13], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R13B:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[13], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R14:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[14] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R14D:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[14], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R14W:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[14], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R14B:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[14], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R15:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->regs[15] = *(uint64_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R15D:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_DWORD(state->regs[15], *(uint32_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R15W:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_WORD(state->regs[15], *(uint16_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_R15B:
|
2018-03-07 15:33:21 +00:00
|
|
|
WRITE_BYTE_L(state->regs[15], *(uint8_t *)value);
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_IDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->idt.limit = (uint16_t)((uc_x86_mmr *)value)->limit;
|
|
|
|
state->idt.base = ((uc_x86_mmr *)value)->base;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_GDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->gdt.limit = (uint16_t)((uc_x86_mmr *)value)->limit;
|
|
|
|
state->gdt.base = ((uc_x86_mmr *)value)->base;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_LDTR:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->ldt.limit = ((uc_x86_mmr *)value)->limit;
|
|
|
|
state->ldt.base = ((uc_x86_mmr *)value)->base;
|
|
|
|
state->ldt.selector = (uint16_t)((uc_x86_mmr *)value)->selector;
|
|
|
|
state->ldt.flags = ((uc_x86_mmr *)value)->flags;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
|
|
|
case UC_X86_REG_TR:
|
2018-03-07 15:33:21 +00:00
|
|
|
state->tr.limit = ((uc_x86_mmr *)value)->limit;
|
|
|
|
state->tr.base = ((uc_x86_mmr *)value)->base;
|
|
|
|
state->tr.selector = (uint16_t)((uc_x86_mmr *)value)->selector;
|
|
|
|
state->tr.flags = ((uc_x86_mmr *)value)->flags;
|
2016-04-04 15:25:30 +00:00
|
|
|
break;
|
2017-02-24 13:37:19 +00:00
|
|
|
case UC_X86_REG_MSR:
|
|
|
|
x86_msr_write(uc, (uc_x86_msr *)value);
|
|
|
|
break;
|
2016-04-04 15:25:30 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-08-21 07:04:50 +00:00
|
|
|
#endif
|
2016-04-04 15:25:30 +00:00
|
|
|
}
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-19 11:50:28 +00:00
|
|
|
DEFAULT_VISIBILITY
|
2015-08-21 07:04:50 +00:00
|
|
|
int x86_uc_machine_init(struct uc_struct *uc)
|
|
|
|
{
|
|
|
|
return machine_initialize(uc);
|
|
|
|
}
|
|
|
|
|
2015-08-24 16:02:31 +00:00
|
|
|
static bool x86_stop_interrupt(int intno)
|
|
|
|
{
|
|
|
|
switch(intno) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
case EXCP06_ILLOP:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-13 17:16:17 +00:00
|
|
|
static bool x86_insn_hook_validate(uint32_t insn_enum)
|
|
|
|
{
|
2018-09-03 11:50:31 +00:00
|
|
|
//for x86 we can only hook IN, OUT, SYSCALL, and SYSENTER
|
2017-05-13 17:16:17 +00:00
|
|
|
if (insn_enum != UC_X86_INS_IN
|
|
|
|
&& insn_enum != UC_X86_INS_OUT
|
2018-09-03 11:50:31 +00:00
|
|
|
&& insn_enum != UC_X86_INS_SYSCALL
|
|
|
|
&& insn_enum != UC_X86_INS_SYSENTER) {
|
2017-05-13 17:16:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-09 19:12:03 +00:00
|
|
|
void pc_machine_init_v2_2(struct uc_struct *uc);
|
|
|
|
|
2017-01-19 11:50:28 +00:00
|
|
|
DEFAULT_VISIBILITY
|
2015-08-21 07:04:50 +00:00
|
|
|
void x86_uc_init(struct uc_struct* uc)
|
|
|
|
{
|
|
|
|
apic_register_types(uc);
|
|
|
|
apic_common_register_types(uc);
|
|
|
|
register_accel_types(uc);
|
|
|
|
pc_machine_register_types(uc);
|
|
|
|
x86_cpu_register_types(uc);
|
2018-03-09 19:12:03 +00:00
|
|
|
pc_machine_init_v2_2(uc); // pc_piix
|
2015-08-21 07:04:50 +00:00
|
|
|
uc->reg_read = x86_reg_read;
|
|
|
|
uc->reg_write = x86_reg_write;
|
|
|
|
uc->reg_reset = x86_reg_reset;
|
|
|
|
uc->release = x86_release;
|
|
|
|
uc->set_pc = x86_set_pc;
|
2015-08-24 16:02:31 +00:00
|
|
|
uc->stop_interrupt = x86_stop_interrupt;
|
2017-05-13 17:16:17 +00:00
|
|
|
uc->insn_hook_validate = x86_insn_hook_validate;
|
2015-08-21 07:04:50 +00:00
|
|
|
uc_common_init(uc);
|
|
|
|
}
|
2017-02-24 13:37:19 +00:00
|
|
|
|
|
|
|
/* vim: set ts=4 sts=4 sw=4 et: */
|