Esempio n. 1
0
static int adjbkpt(struct ps_prochandle *P, int wow)
{
    CONTEXT ct;
#if __amd64__
    WOW64_CONTEXT ct32;

    if (wow) {
        ZeroMemory(&ct32, sizeof(PWOW64_CONTEXT));
        ct32.ContextFlags = CONTEXT_CONTROL;
        if (Wow64GetThreadContext(P->thandle, &ct32) == 0) {
            return -1;
        }
        ct32.Eip--;
        if (Wow64SetThreadContext(P->thandle, &ct32) == 0) {
            return -1;
        }
        return 0;
    }
#endif
    ZeroMemory(&ct, sizeof(CONTEXT));
    ct.ContextFlags = CONTEXT_CONTROL;

    if (GetThreadContext(P->thandle, &ct) == 0) {
        return -1;
    }
#if __i386__
    ct.Eip--;
#else
    ct.Rip--;
#endif
    if (SetThreadContext(P->thandle, &ct) == 0) {
        return -1;
    }
    return 0;
}
Esempio n. 2
0
void Pdb::WriteContext(HANDLE hThread, Context& context)
{
	DR_LOG("WriteContext");
#ifdef CPU_64
	if(win64) {
		CONTEXT ctx;
		memcpy(&ctx, &context.context64, sizeof(CONTEXT));
		ctx.ContextFlags = CONTEXT_CONTROL;
		if(!SetThreadContext(hThread, &ctx))
			Error("SetThreadContext failed");
	}
	else {
		WOW64_CONTEXT ctx;
		memcpy(&ctx, &context.context32, sizeof(WOW64_CONTEXT));
		ctx.ContextFlags = CONTEXT_CONTROL;
		if(!Wow64SetThreadContext(hThread, &ctx))
			Error("Wow64SetThreadContext failed");
	}
#else
	CONTEXT ctx;
	memcpy(&ctx, &context.context32, sizeof(WOW64_CONTEXT));
	ctx.ContextFlags = CONTEXT_CONTROL;
	if(!SetThreadContext(hThread, &ctx))
		Error("SetThreadContext failed");
#endif
}
Esempio n. 3
0
File: debug.c Progetto: Disar/Kha
HL_API bool hl_debug_write_register( int pid, int thread, int reg, void *value, bool is64 ) {
#	if defined(HL_WIN)
#	ifdef HL_64
	if( !is64 ) {
		WOW64_CONTEXT c;
		c.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
		if( !Wow64GetThreadContext(OpenTID(thread),&c) )
			return false;
		if( reg == 3 )
			c.EFlags = (int)(int_val)value;
		else
			*GetContextReg32(&c,reg) = (DWORD)(int_val)value;
		return (bool)Wow64SetThreadContext(OpenTID(thread),&c);
	}
#	else
	if( is64 ) return false;
#	endif
	CONTEXT c;
	c.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
	if( !GetThreadContext(OpenTID(thread),&c) )
		return false;
	if( reg == 3 )
		c.EFlags = (int)(int_val)value;
	else
		*GetContextReg(&c,reg) = (REGDATA)value;
	return (bool)SetThreadContext(OpenTID(thread),&c);
#	elif defined(USE_PTRACE)
	return ptrace(PTRACE_POKEUSER,thread,get_reg(reg),value) >= 0;
#	else
	return false;
#	endif
}
Esempio n. 4
0
/*
 * MySetThreadContext - set the context for a specific thread
 */
BOOL MySetThreadContext( thread_info *ti, MYCONTEXT *pc )
{
#ifdef WOW
    if( ( ti->is_wow || ti->is_dos ) && UseVDMStuff ) {
#if defined( MD_x86 )
        VDMCONTEXT      vc;
        /*
         * VDMCONTEXT and CONTEXT are the same on an x86 machine.
         * If we were ever to try to port this to NT running on a RISC,
         * they would be different, and this memcpy would be total crap.
         */
        memcpy( &vc, pc, sizeof( MYCONTEXT ) );
        vc.ContextFlags = VDMCONTEXT_TO_USE;
        return( pVDMSetThreadContext( &DebugEvent, &vc ) );
#elif defined( MD_axp ) | defined( MD_ppc )
        return( FALSE );
#else
        #error MySetThreadContext not configured
#endif
    } else {
        pc->ContextFlags = MYCONTEXT_TO_USE;
        return( SetThreadContext( ti->thread_handle, pc ) );
    }
#else
#if 1
    pc->ContextFlags = MYCONTEXT_TO_USE;
#if defined( MD_x64 )
    return( Wow64SetThreadContext( ti->thread_handle, pc ) );
#else
    return( SetThreadContext( ti->thread_handle, pc ) );
#endif
#else
#if defined( MD_x64 )
    if( ti->is_wow ) {
        pc->ContextFlags = WOW64CONTEXT_TO_USE;
        return( Wow64SetThreadContext( ti->thread_handle, pc ) );
    }
#endif
    pc->ContextFlags = MYCONTEXT_TO_USE;
    return( SetThreadContext( ti->thread_handle, pc ) );
#endif
#endif
}