bool EnforceFilter( bool bEnforce )
{
	DWORD ErrCode = 0;

	
	// Obtain the address of SetUnhandledExceptionFilter 

	HMODULE hLib = GetModuleHandle( _T("kernel32.dll") );

	if( hLib == NULL )
	{
		ErrCode = GetLastError();
		_ASSERTE( !_T("GetModuleHandle(kernel32.dll) failed.") );
		return false;
	}

	BYTE* pTarget = (BYTE*)GetProcAddress( hLib, "SetUnhandledExceptionFilter" );

	if( pTarget == 0 )
	{
		ErrCode = GetLastError();
		_ASSERTE( !_T("GetProcAddress(SetUnhandledExceptionFilter) failed.") );
		return false;
	}

	if( IsBadReadPtr( pTarget, sizeof(OriginalBytes) ) )
	{
		_ASSERTE( !_T("Target is unreadable.") );
		return false;
	}


	if( bEnforce )
	{
		// Save the original contents of SetUnhandledExceptionFilter 

		memcpy( OriginalBytes, pTarget, sizeof(OriginalBytes) );


		// Patch SetUnhandledExceptionFilter 

		if( !WriteMemory( pTarget, PatchBytes, sizeof(PatchBytes) ) )
			return false;

	}
	else
	{
		// Restore the original behavior of SetUnhandledExceptionFilter 

		if( !WriteMemory( pTarget, OriginalBytes, sizeof(OriginalBytes) ) )
			return false;

	}


	// Success 

	return true;

}
Exemplo n.º 2
0
void NoDamageText(bool toggle)
{
	if (toggle)
	{
		WriteMemory(NoDamageText_Addy, 7, 0xC2, 0x58, 0x00, 0x90, 0x90, 0x90, 0x90);
	}
	else
	{
		WriteMemory(NoDamageText_Addy, 7, 0x6A, 0xFF, 0x68, 0x08, 0x95, 0x68, 0x01);
	}
}
Exemplo n.º 3
0
// CPU Hacks
void NoBackground(bool toggle)
{
	if (toggle)
	{
		WriteMemory(NoBackground_Addy, 5, 0x90, 0x90, 0x90, 0x90, 0x90);
	}
	else
	{
		WriteMemory(NoBackground_Addy, 5, 0x8B, 0x75, 0x04, 0x3B, 0xF7);
	}
}
Exemplo n.º 4
0
// Char Hacks
void StanceHack(bool toggle)
{
	if (toggle) 
	{
		WriteMemory(StanceHack_Addy, 1, 0x00);
	}
	else 
	{
		WriteMemory(StanceHack_Addy, 1, 0x01);
	}
}
Exemplo n.º 5
0
VOID
SetDepthLookaside (
    IN ULONG Address,
    IN PUCHAR Name,
    IN ULONG Depth
    )

/*++

Routine Description:

    Set the depth of a specific lookaside list.

Arguments:

    Address - Gives the address of the lookaside list to reset

    Name - Gives an optional name of to print in case of errors

    Depth - Supplies the depth to set the lookaside list to

Return Value:

    None

--*/

{
    NPAGED_LOOKASIDE_LIST Lookaside;
    ULONG Results;

    //
    //  Read the lookaside list from memory
    //

    if (!ReadMemory( (ULONG)Address, &Lookaside, sizeof(NPAGED_LOOKASIDE_LIST), &Results ) ||
        (Results < sizeof(NPAGED_LOOKASIDE_LIST))) {

        dprintf("Can't read lookaside \"%s\" at 0x%08lx\n", Name, Address);
    }

    //
    //  Set the depth
    //

    Lookaside.L.Depth = (USHORT)Depth;

    //
    //  Write it back out
    //

    if (!WriteMemory( (ULONG)Address, &Lookaside, sizeof(NPAGED_LOOKASIDE_LIST), &Results ) ||
        (Results < sizeof(NPAGED_LOOKASIDE_LIST))) {

        dprintf("Can't write lookaside \"%s\" at 0x%08lx\n", Name, Address);
    }


    return;
}
Exemplo n.º 6
0
void FifoPlayer::WriteFramePart(u32 dataStart, u32 dataEnd, u32 &nextMemUpdate, const FifoFrameInfo &frame, const AnalyzedFrameInfo &info)
{
	u8 *data = frame.fifoData;

	while (nextMemUpdate < frame.memoryUpdates.size() && dataStart < dataEnd)
	{
		const MemoryUpdate &memUpdate = info.memoryUpdates[nextMemUpdate];

		if (memUpdate.fifoPosition < dataEnd)
		{
			if (dataStart < memUpdate.fifoPosition)
			{
				WriteFifo(data, dataStart, memUpdate.fifoPosition);
				dataStart = memUpdate.fifoPosition;
			}

			WriteMemory(memUpdate);

			++nextMemUpdate;
		}
		else
		{
			WriteFifo(data, dataStart, dataEnd);
			dataStart = dataEnd;
		}
	}

	if (dataStart < dataEnd)
		WriteFifo(data, dataStart, dataEnd);
}
Exemplo n.º 7
0
DWORD
TraceBpHandler(
    PPROCESS_INFO       ThisProcess,
    PTHREAD_INFO        ThisThread,
    PEXCEPTION_RECORD   ExceptionRecord,
    PBREAKPOINT_INFO    BreakpointInfo
    )
{
    CONTEXT Context;
#ifdef _M_IX86
    if (BreakpointInfo->Flags & BPF_TRACE) {
        CurrContext.EFlags &= ~0x100;
        SetRegContext( ThisThread->hThread, &CurrContext );
    }
#endif

    if (BreakpointInfo->LastBp) {
        WriteMemory(
            ThisProcess->hProcess,
            (PVOID) BreakpointInfo->LastBp->Address,
            &BpInstr,
            BpSize
            );
        BreakpointInfo->LastBp = NULL;
    }

    //
    // clear the trace breakpoint
    //
    ClearBreakpoint( ThisProcess, BreakpointInfo );

    //
    // print the registers
    //
    if (PrintRegistersFlag) {
        PrintRegisters();
    }

    //
    // print the code
    //
    PrintOneInstruction( ThisProcess->hProcess, (ULONG)ExceptionRecord->ExceptionAddress );

    //
    // enter the debugger
    //
    ULONG ContinueStatus = ConsoleDebugger(
        ThisThread->hProcess,
        ThisThread->hThread,
        ExceptionRecord,
        FALSE,
        BreakpointInfo->Command
        );

    //
    // continue the debuggee
    //
    return ContinueStatus;
}
Exemplo n.º 8
0
 int RedirectFunc(const char *name1, T* name2)
 {
   map <string, void *> :: iterator it = IATAddress.find(name1);
   if (it == IATAddress.end()) return 0;
   int org = *(int *)IATAddress[name1];
   WriteMemory(it->second, &name2, sizeof(name2));
   return org;
 }
Exemplo n.º 9
0
DWORD SetRange(const LPVOID dwAddress, const USHORT wCount, const BYTE btValue)
{
	BYTE * lpBuf	= new BYTE[wCount];
	// ----
	memset(lpBuf, btValue, wCount);
	// ----
	return WriteMemory( dwAddress, (LPVOID) lpBuf, wCount);
}
Exemplo n.º 10
0
	void CAttributeItem::SetSelect(const int index)
	{
		m_lstCandidata.SetSelect(index);

		// 写入内存中
		WriteMemory();

		m_bChanged = true;
	}
Exemplo n.º 11
0
DWORD SetOp(const LPVOID dwEnterFunction, const LPVOID dwJMPAddress, const BYTE cmd)
{
	BYTE btBuf[5];
	DWORD dwShift	= (ULONG_PTR)dwJMPAddress - (ULONG_PTR)dwEnterFunction - 5;
	// ----
	btBuf[0]		= cmd;
	memcpy( (LPVOID) & btBuf[1], (LPVOID) & dwShift, sizeof(ULONG_PTR));
	// ----
	return WriteMemory(dwEnterFunction, (LPVOID) btBuf, sizeof(btBuf));
}
Exemplo n.º 12
0
 bool restore_cpp_handler()
 {
     if(!saved_handler_instructions)
         return false;
     else
     {
         void *loc = __CxxFrameHandler;
         return WriteMemory(loc, cpp_handler_instructions, 
                        sizeof(cpp_handler_instructions));
     }
 }
Exemplo n.º 13
0
trap_retval ReqWrite_mem( void )
{
    write_mem_req       *acc;
    write_mem_ret       *ret;
                                                                          _DBG1(( "WriteMem" ));
    acc = GetInPtr( 0 );
    ret = GetOutPtr( 0 );
    ret->len = WriteMemory( &acc->mem_addr, GetInPtr( sizeof(*acc) ),
                            GetTotalSize() - sizeof(*acc) );
    return( sizeof( *ret ) );
}
Exemplo n.º 14
0
DWORD SetJa(const LPVOID dwEnterFunction, const LPVOID dwJMPAddress)
{
	BYTE btBuf[6];
	DWORD dwShift	= (ULONG_PTR)dwJMPAddress - (ULONG_PTR)dwEnterFunction - 6;
	// ----
	btBuf[0]	= 0x0F;
	btBuf[1]	= 0x87;
	memcpy( (LPVOID) & btBuf[2], (LPVOID) & dwShift, sizeof(ULONG_PTR));
	// ----
	return WriteMemory(dwEnterFunction, (LPVOID) btBuf, sizeof(btBuf));
}
Exemplo n.º 15
0
unsigned ReqWrite_mem( void )
/***************************/
{
    write_mem_req       *acc;
    write_mem_ret       *ret;

    acc = GetInPtr( 0 );
    ret = GetOutPtr( 0 );
    ret->len = WriteMemory( &acc->mem_addr, GetInPtr( sizeof( *acc ) ), GetTotalSize() - sizeof( *acc ) );
    return( sizeof( *ret ) );
}
Exemplo n.º 16
0
trap_retval ReqClear_break( void )
{
    clear_break_req     *acc;
    opcode_type         brk_opcode;

    acc = GetInPtr( 0 );
    brk_opcode = acc->old;
    WriteMemory( &acc->break_addr, &brk_opcode, sizeof( brk_opcode ) );
    _DBG1(( "AccRestoreBreak" ));
    return( 0 );
}
Exemplo n.º 17
0
void CFPSOverrider::OnBnClickedcmdsetfps()
{
	// When cmdsetfps is clicked do this:
	CWnd* txtsetfps = GetDlgItem(txtSetFPS);
	txtsetfps->GetWindowText(strFPSValue); //Get value from the text file
	intFPSValue = atoi(strFPSValue);  //Convert Value from String to Int
	FPSValue = CheckFPSRange(intFPSValue); //Check if its between 30 and 120
	if(FPSValue != 0){
		WriteMemory( "SWGANH.exe" ); //Write memory to .exe
	}
}
Exemplo n.º 18
0
void CChildView::OnButtonZero()
{
	CMemory mem;
	for (UINT i = 0; i < Selected.size(); i++)
	{
		DWORD s = Selected[i].object->GetMemorySize();
		DWORD_PTR a = Selected[i].Address;
		mem.SetSize(s);
		ZeroMemory(mem.pMemory, s);
		WriteMemory((LPVOID)a, mem.pMemory, s);
	}
}
Exemplo n.º 19
0
DWORD SetHook(const LPVOID dwMyFuncOffset, const LPVOID dwJmpOffset, const BYTE cmd)
{
	BYTE btBuf[5];
	// ----
	DWORD dwShift	= (ULONG_PTR)dwMyFuncOffset - ( (ULONG_PTR)dwJmpOffset + 5 );
	// ----
	btBuf[0] = cmd;
	// ----
	memcpy( (LPVOID) & btBuf[1], (LPVOID) & dwShift, sizeof(ULONG_PTR));
	// ----
	return WriteMemory(dwJmpOffset, (LPVOID) btBuf, sizeof(btBuf));
}
Exemplo n.º 20
0
unsigned ReqClear_break( void )
/*****************************/
{
    byte            ch;
    clear_break_req *acc;

    _DBG( "AccClearBreak\r\n" );
    acc = GetInPtr( 0 );
    ch = acc->old;
    WriteMemory( &acc->break_addr, &ch, 1 );
    return( 0 );
}
Exemplo n.º 21
0
int r2k__write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
#if __WINDOWS__
	//eprintf("writing to: 0x%"PFMT64x" len: %x\n",io->off, count);
	return WriteKernelMemory (io->off, buf, count);
#elif defined (__linux__) && !defined (__GNU__)
	switch (r2k_struct.beid) {
	case 0:
		return WriteMemory (io, fd, IOCTL_WRITE_KERNEL_MEMORY, r2k_struct.pid, io->off, buf, count);
	case 1:
		return WriteMemory (io, fd, IOCTL_WRITE_PROCESS_ADDR, r2k_struct.pid, io->off, buf, count);
	case 2:
		return WriteMemory (io, fd, IOCTL_WRITE_PHYSICAL_ADDR, r2k_struct.pid, io->off, buf, count);
	default:
		io->cb_printf ("ERROR: Undefined beid in r2k__write.\n");
		return -1;
	}
#else
	io->cb_printf ("TODO: r2k not implemented for this plataform.\n");
	return -1;
#endif
}
Exemplo n.º 22
0
trap_retval ReqClear_break( void )
/*****************************/
{
    opcode_type     brk_opcode;
    clear_break_req *acc;

    _DBG( "AccClearBreak\r\n" );
    acc = GetInPtr( 0 );
    brk_opcode = acc->old;
    WriteMemory( &acc->break_addr, &brk_opcode, sizeof( brk_opcode ) );
    return( 0 );
}
Exemplo n.º 23
0
void FifoPlayer::WriteAllMemoryUpdates()
{
	_assert_(m_File);

	for (int frameNum = 0; frameNum < m_File->GetFrameCount(); ++frameNum)
	{
		const FifoFrameInfo &frame = m_File->GetFrame(frameNum);
		for (unsigned int i = 0; i < frame.memoryUpdates.size(); ++i)
		{
			WriteMemory(frame.memoryUpdates[i]);
		}
	}
}
Exemplo n.º 24
0
void FifoPlayer::WriteAllMemoryUpdates()
{
	_assert_(m_File);

	for (u32 frameNum = 0; frameNum < m_File->GetFrameCount(); ++frameNum)
	{
		const FifoFrameInfo &frame = m_File->GetFrame(frameNum);
		for (auto& update : frame.memoryUpdates)
		{
			WriteMemory(update);
		}
	}
}
Exemplo n.º 25
0
unsigned ReqWrite_mem()
{
    write_mem_req       *acc;
    write_mem_ret       *ret;

    _DBG1(( "WriteMem\n" ));
    acc = GetInPtr( 0 );
    ret = GetOutPtr( 0 );
    ret->len = WriteMemory( (addr48_ptr *)&acc->mem_addr,
                            GetInPtr( sizeof(*acc) ),
                            GetTotalSize() - sizeof(*acc) );
    return( sizeof( *ret ) );
}
Exemplo n.º 26
0
	void DllHook::UpdateThunk(IMAGE_THUNK_DATA*pThunk,bool bInstall) const
	{
		if (hModule)
		{
			const dword_map& mpLookup = (bInstall?mpModuleToRedirect:mpRedirectToModule);
			while (pThunk->u1.Function)
			{
				dword_map::const_iterator it = mpLookup.find(pThunk->u1.Function);
				if (it != mpLookup.end())
					WriteMemory(&(pThunk->u1.Function),it->second);
				++pThunk;
			}
		}
	}
Exemplo n.º 27
0
unsigned ReqSet_break( void )
/***************************/
{
    byte            ch;
    set_break_req   *acc;
    set_break_ret   *ret;

    _DBG( "AccSetBreak\r\n" );
    acc = GetInPtr( 0 );
    ret = GetOutPtr( 0 );
    ReadMemory( &acc->break_addr, &ch, 1 );
    ret->old = ch;
    ch = 0xCC;
    WriteMemory( &acc->break_addr, &ch, 1 );
    return( sizeof( *ret ) );
}
Exemplo n.º 28
0
void CChildView::OnButtonSwap()
{
	CMemory mem;
	for (UINT i = 0; i < Selected.size(); i++)
	{
		DWORD s = Selected[i].object->GetMemorySize();
		DWORD_PTR a = Selected[i].Address;
		mem.SetSize(s);

		ReadMemory((LPVOID)a, mem.pMemory, s);

		std::reverse(mem.pMemory, mem.pMemory + s);

		WriteMemory((LPVOID)a, mem.pMemory, s);
	}
}
Exemplo n.º 29
0
trap_retval ReqSet_break( void )
/******************************/
{
    opcode_type     brk_opcode;
    set_break_req   *acc;
    set_break_ret   *ret;

    _DBG( "AccSetBreak\r\n" );
    acc = GetInPtr( 0 );
    ret = GetOutPtr( 0 );
    ReadMemory( &acc->break_addr, &brk_opcode, sizeof( brk_opcode ) );
    ret->old = brk_opcode;
    brk_opcode = BRKPOINT;
    WriteMemory( &acc->break_addr, &brk_opcode, sizeof( brk_opcode ) );
    return( sizeof( *ret ) );
}
Exemplo n.º 30
0
void CChildView::OnButtonRandom()
{
	CMemory mem;
	srand(GetTickCount());
	for (UINT i = 0; i < Selected.size(); i++)
	{
		DWORD s = Selected[i].object->GetMemorySize();
		DWORD_PTR a = Selected[i].Address;
		mem.SetSize(s);

		for (UINT r = 0; r < s; r++)
			mem.pMemory[r] = rand();

		WriteMemory((LPVOID)a, mem.pMemory, s);
	}

}