Ejemplo n.º 1
0
static int windows_reg_read (RDebug *dbg, int type, ut8 *buf, int size) {
	int showfpu = false;
	int pid = dbg->pid;
	int tid = dbg->tid;

	if (type < -1) {
		showfpu = true; // hack for debugging
		type = -type;
	}

	HANDLE thread = w32_open_thread (pid, tid);
	CONTEXT ctx __attribute__ ((aligned (16)));
	ctx.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
	if (!GetThreadContext (thread, &ctx)) {
		eprintf ("GetThreadContext: %x\n", (int)GetLastError ());
		CloseHandle(thread);
		return false;
	}
	CloseHandle(thread);
	if (type==R_REG_TYPE_FPU || type==R_REG_TYPE_MMX || type==R_REG_TYPE_XMM) {
	#if __MINGW64__
		eprintf ("TODO: r_debug_native_reg_read fpu/mmx/xmm\n");
	#else
		int i;
		if (showfpu) {
			eprintf ("cwd = 0x%08x  ; control   ", (ut32)ctx.FloatSave.ControlWord);
			eprintf ("swd = 0x%08x  ; status\n", (ut32)ctx.FloatSave.StatusWord);
			eprintf ("twd = 0x%08x ", (ut32)ctx.FloatSave.TagWord);
			eprintf ("eof = 0x%08x\n", (ut32)ctx.FloatSave.ErrorOffset);
			eprintf ("ese = 0x%08x\n", (ut32)ctx.FloatSave.ErrorSelector);
			eprintf ("dof = 0x%08x\n", (ut32)ctx.FloatSave.DataOffset);
			eprintf ("dse = 0x%08x\n", (ut32)ctx.FloatSave.DataSelector);
			eprintf ("mxcr = 0x%08x\n", (ut32)ctx.ExtendedRegisters[24]);
			for (i=0; i<8; i++) {
				ut32 *a = (ut32*) &(ctx.ExtendedRegisters[10*16]);
				a = a + (i * 4);
				eprintf ("xmm%d = %08x %08x %08x %08x  ",i
						, (int)a[0], (int)a[1], (int)a[2], (int)a[3] );
				ut64 *b = (ut64 *)&ctx.FloatSave.RegisterArea[i*10];
				eprintf ("st%d = %lg (0x%08"PFMT64x")\n", i,
					(double)*((double*)&ctx.FloatSave.RegisterArea[i*10]), *b);
			}
		}
	#endif
	}
	if (sizeof(CONTEXT) < size)
		size = sizeof(CONTEXT);

	memcpy (buf, &ctx, size);
	return size;
// XXX this must be defined somewhere else

}
Ejemplo n.º 2
0
static int windows_reg_write (RDebug *dbg, int type, const ut8* buf, int size) {
	BOOL ret = false;
	HANDLE thread;
	CONTEXT ctx __attribute__((aligned (16)));
	thread = w32_open_thread (dbg->pid, dbg->tid);
	ctx.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
	GetThreadContext (thread, &ctx);
	if (type == R_REG_TYPE_DRX || type == R_REG_TYPE_GPR || type == R_REG_TYPE_SEG) {
		if (sizeof(CONTEXT) < size)
			size = sizeof(CONTEXT);
		memcpy (&ctx, buf, size);
		ret = SetThreadContext (thread, &ctx)? true: false;
	}
	CloseHandle (thread);
	return ret;
}
Ejemplo n.º 3
0
static int r_debug_native_reg_write (RDebug *dbg, int type, const ut8* buf, int size) {

	// XXX use switch or so
	if (type == R_REG_TYPE_DRX) {
#if __i386__ || __x86_64__
#if __KFBSD__
		return (0 == ptrace (PT_SETDBREGS, dbg->pid,
			(caddr_t)buf, sizeof (struct dbreg)));
#elif __linux__
		return linux_reg_write (dbg, type, buf, size);
#elif __APPLE__
		if (1) return false; //disable until fixed ?? know why this
		return xnu_reg_write (dbg, type, buf, size);
#else
		//eprintf ("TODO: No support for write DRX registers\n");
		#if __WINDOWS__
		int tid = dbg->tid;
		int pid = dbg->pid;
		BOOL ret;
		HANDLE thread;
		CONTEXT ctx __attribute__((aligned (16)));
		memcpy (&ctx, buf, sizeof (CONTEXT));
		ctx.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
		thread = w32_open_thread (pid, tid);
		ret=SetThreadContext (thread, &ctx)? true: false;
		CloseHandle(thread);
		return ret;
		#endif
		return false;
#endif
#else // i386/x86-64
		return false;
#endif
	} else
	if (type == R_REG_TYPE_GPR) {
#if __WINDOWS__ && !__CYGWIN__
		BOOL ret;
		CONTEXT ctx __attribute__((aligned (16)));
		memcpy (&ctx, buf, sizeof (CONTEXT));
		ctx.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
	//	eprintf ("EFLAGS =%x\n", ctx.EFlags);
		HANDLE thread = w32_open_thread (dbg->pid, dbg->tid);
		ret = SetThreadContext (thread, &ctx)? true: false;
		CloseHandle (thread);
		return ret;
#elif __linux__
		return linux_reg_write (dbg, type, buf, size);
#elif __sun || __NetBSD__ || __KFBSD__ || __OpenBSD__
		int ret = ptrace (PTRACE_SETREGS, dbg->pid,
			(void*)(size_t)buf, sizeof (R_DEBUG_REG_T));
		if (sizeof (R_DEBUG_REG_T) < size)
			size = sizeof (R_DEBUG_REG_T);
		return (ret != 0) ? false: true;
#elif __APPLE__
		return xnu_reg_write (dbg, type, buf, size);
#else
#warning r_debug_native_reg_write not implemented
#endif
	} //else eprintf ("TODO: reg_write_non-gpr (%d)\n", type);
	return false;
}