Example #1
0
// TODO: I should probably move all initalization inside the thread
// We should minimize the amount of work done in DLL_PROCESS_ATTACH as per
// http://blogs.msdn.com/b/oleglv/archive/2003/10/24/56141.aspx
static BOOL ProcessAttach()
{
    lf("memtrace.dll: ProcessAttach()");
    if (!OpenPipe()) {
        lf("memtrace.dll: couldn't open pipe");
        return FALSE;
    } else {
        lf("memtrace.dll: opened pipe");
    }

    gHeap = HeapCreate(0, 0, 0);
    if (!gHeap) {
        lf("memtrace.dll: failed to create heap");
        return FALSE;
    }

    InitializeCriticalSection(&gMemMutex);
    gSendThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (!gSendThreadEvent) {
        lf("memtrace.dll: couldn't create gSendThreadEvent");
        return FALSE;
    }
    gSendThread = CreateThread(NULL, 0, DataSendThreadProc, NULL, 0, 0);
    if (!gSendThread) {
        lf("memtrace.dll: couldn't create gSendThread");
        return FALSE;
    }
    InstallHooks();
    return TRUE;
}
Example #2
0
BOOL __stdcall DllMain ( HINSTANCE hInstance, DWORD dwReason, void* pReserved )
{
	switch ( dwReason )
	{
		case DLL_PROCESS_ATTACH:
		{
            InstallHooks ();
			break;
		}
	}
	return TRUE;
}
Example #3
0
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{

    if(!Installed){
		 Installed=true;
		 InstallHooks();
	}

	return TRUE;
}
Example #4
0
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{

    if(!Installed){
		 Installed=true;
		 if(InstallHooks()==0) return FALSE;
		 atexit(Closing);
	}

	return TRUE;
}
Example #5
0
void CMemLeakDetector::Enable()
{
	if(m_HooksEnabled)
		return;

#if defined(PLATFORM_WINDOWS)
	m_OldHook = _CrtSetAllocHook(CrtAllocHook);
#else
#if defined(_DEBUG)
	SaveHooks();
	InstallHooks();
#endif
#endif
	m_HooksEnabled = true;
}
Example #6
0
extern "C" __declspec(dllexport) int __cdecl OverlayHelperProcessMain(unsigned int magic, HANDLE parent) {
	int retval = 0;

	if (GetOverlayMagicVersion() != magic) {
		return OVERLAY_HELPER_ERROR_DLL_MAGIC_MISMATCH;
	}

	HANDLE pcheckHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) OverlayHelperProcessParentDeathThread,
	                                   reinterpret_cast<void *>(parent), 0, NULL);
	if (pcheckHandle == 0) {
		return OVERLAY_HELPER_ERROR_DLL_PDEATH_THREAD_ERROR;
	}

	PrepareD3D9();
	PrepareDXGI();

	InstallHooks();

	while (1) {
		MSG msg;
		BOOL ret;

		ret = GetMessage(&msg, NULL, 0, 0);

		// The ret variable is set to 0 on WM_QUIT,
		// and -1 on error.
		if (ret == 0) {
			retval = 0;
			break;
		} else if (ret == -1) {
			retval = -1001;
			break;
		}

		if (msg.message == WM_CLOSE) {
			retval = 0;
			break;
		}

		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	RemoveHooks();

	return retval;
}
void FLiveEditorListenServer::StartupModule()
{
#if !UE_BUILD_SHIPPING
	//FLiveEditorListenServer does nothing in the Editor
	if ( GIsEditor )
	{
		return;
	}

	TransactionHistory = new FLiveEditorTransactionHistory();

	Listener = new FTcpListener( DEFAULT_LISTEN_ENDPOINT );
	Listener->OnConnectionAccepted().BindRaw(this, &FLiveEditorListenServer::HandleListenerConnectionAccepted);

	InstallHooks();
#endif
}
Example #8
0
void CMemLeakDetector::FreeHook(void* p_MemPtr, const void* p_Caller)
{
	// Restore all old hooks
	RestoreHooks();

	// Call recursively
	free(p_MemPtr);

	// Save underlying hooks
	SaveHooks();

	// might call free, so protect it too.
	if(p_MemPtr)
		g_MemLeakDetector.RemoveAllocInfo((uintx)p_MemPtr);
	
	// install our own hooks
	InstallHooks();
}
Example #9
0
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:	
		MessageBox(HWND_DESKTOP, "Thread injection complete", "Yee!", MB_OK);
		InstallHooks();
		break;

	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
Example #10
0
bool CFilmSound::Start(wchar_t const * fileName, double dTargetTime, float fUseVolume, wchar_t const * extraFileName, double extraTime)
{
	InstallHooks(); // make sure hooks are installed

	if (!g_FilmSound_Capturing)
	{
		// only start when idle

		g_FilmSound_TimeRounding = FS_TR_FLOOR;
		
		// init time:
		g_TargetTime = dTargetTime;
		g_CurrentTime = 0.0;

		// set volume:
		g_Volume = fUseVolume;

		// retrive sound info structure (since we need the samples per second value == shm->Valve_speed):
		volatile dma_HL_t *shm=*(dma_HL_t **)HL_ADDR_GET(shm);

		if(!(_pWaveFile=_fBeginWave(fileName, shm->Valve_speed))) // we use Quake speed since we capture the internal mixer
			return false; // on fail return false

		m_pWaveFileExtra = 0;
		if(0 < extraTime)
		{
			m_ExtraTime = extraTime;

			if(!(m_pWaveFileExtra = _fBeginWave(extraFileName, shm->Valve_speed)))
			{
				_fEndWave(_pWaveFile);
				return false;
			}
		}

		g_FilmSound_Capturing = true; // switch to filming mode

		return true;
	}

	return false;
}
Example #11
0
void* CMemLeakDetector::MallocHook(size_t p_Size, const void* p_Caller)
{
	void *result;
	
	// Restore all old hooks
	RestoreHooks();
	
	// Call recursively
	result = malloc(p_Size);
	
	// Save underlying hooks
	SaveHooks();

	// might call malloc, so protect it too.
	if(result)
		g_MemLeakDetector.TrackAllocInfo((uintx)result, (uintx)p_Size);

	// Install our own hooks
	InstallHooks();

	return result;
}
void c_Loop(char* version, boolean useDoubleclick, boolean checkUpdates, boolean launchPoEBool){
	VERSION = version;
	UseDoubleclick = useDoubleclick;
	CheckForUpdates = checkUpdates;
	LaunchPoE = launchPoEBool;
	PoEHandle = NULL;
	if(LaunchPoE && FindProcessId("PathOfExile.exe") == 0 && !UpdateLoading){
		launchPoE();
	}
	//Initialize Variables
	//ExitCalled = FALSE;
	hInstance = GetModuleHandle(NULL);
	CtrlPressed = FALSE;
	//Install Hooks
	InstallHooks();
	//c_LoadFilters();
	//CreateCustomMenu();	//Created automatically when needed
	ShowTrayIcon();
    MSG msg = {0};
	if(PoEHandle != NULL){
		SetTimer(NULL, 1, 1000, NULL);
	}
    while (GetMessage(&msg, NULL, 0, 0) != 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
		if (PoEHandle != NULL){
			DWORD dwExitCode;
			GetExitCodeProcess(PoEHandle,&dwExitCode);
			if(dwExitCode != STILL_ACTIVE) {
				Exit();
			}
		}		
    }
	Exit();
	
}
//
// The entrypoint.
//
// We create a console window that prints anything
// sent to stdout and then install our hooks.
// After that, we create an invisible window and
// sit in a message pumping loop until the user
// presses their Escape key.
//
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
	if( false == CreateConsole( ) )
		return 1;

	if( false == InstallHooks() )
	{
		FreeConsole( );
		return 1;
	}

	//
	// Create a plain Win32 window we don't even show.
	// A wndproc needs to be running for our hooks not
	// to interfere with normal system operation.
	//

	const wchar_t class_name[] = L"whatever";
	WNDCLASSEX wc;
	MSG msg;

	wc.cbSize        = sizeof( WNDCLASSEX );
	wc.lpszClassName = class_name;
	wc.lpfnWndProc   = WndProc;
	wc.hInstance     = hInstance;
	wc.cbClsExtra    = NULL;
	wc.cbWndExtra    = NULL;
	wc.style         = NULL;
	wc.hIconSm       = NULL;
	wc.hIcon         = NULL;
	wc.hCursor       = NULL;
	wc.hbrBackground = NULL;
	wc.lpszMenuName  = NULL;

	if( NULL == RegisterClassEx( &wc ) )
	{
		wchar_t error[64];
		_snwprintf_s( error, sizeof error, L"Failed to register window class. Error code: %u", GetLastError( ) );
		MessageBox( NULL, error, L"Error", MB_ICONEXCLAMATION | MB_OK );
		return 1;
	}

	hwnd = CreateWindowEx( NULL, class_name, class_name, NULL,
		CW_USEDEFAULT, CW_USEDEFAULT, 320, 240, NULL, NULL, hInstance, NULL);

	if( NULL == hwnd )
	{
		wchar_t error[64];
		_snwprintf_s( error, sizeof error, L"Failed to create window. Error code: %u", GetLastError( ) );
		MessageBox( NULL, error, L"Error", MB_ICONEXCLAMATION | MB_OK );
		return 1;
	}

	while( GetMessage( &msg, NULL, NULL, NULL ) > 0 )
	{
		TranslateMessage( &msg );
		DispatchMessage( &msg );
	}

	return msg.wParam;
}
Example #14
0
void FLiveEditor::StartupModule()
{
    FLiveEditorManager::Get().Initialize();
    InstallHooks();
}
Example #15
0
void main(int argc, char **argv){
	
	DWORD l;
	OFSTRUCT o;
	WSADATA WsaDat;	
	int addbpx=0;

	system("cls");
	printf("\n");

	STDOUT = GetStdHandle(STD_OUTPUT_HANDLE);
	STDIN  = GetStdHandle(STD_INPUT_HANDLE);
	SetConsoleMode(STDIN, !ENABLE_LINE_INPUT ); //turn off line input (step mode needs)

	if(argc < 2) usage();
	if(strstr(argv[1],"?") > 0 ) usage();
	if(strstr(argv[1],"-h") > 0 ) usage();

	for(int i=2; i<argc; i++){
		if(strstr(argv[i],"/addbpx") > 0 ) addbpx=1;
		if(strstr(argv[i],"/redir") > 0 )  redirect=1;
		if(strstr(argv[i],"/nonet") > 0 )  nonet=1;
		if(strstr(argv[i],"/nofilt") > 0 ) nofilt=1;
		if(strstr(argv[i],"/dump") > 0 )   autoDump=1;
		if(strstr(argv[i],"/step") > 0 )   stepMode=1; //might still have some side effects 
	}

	char* filename = argv[1];
	HANDLE h =  (HANDLE)OpenFile(filename, &o , OF_READ);
	
	if(h == INVALID_HANDLE_VALUE ){
		printf("Could not open file %s\n\n", filename);
		return;
	}

	strcpy(sc_file,argv[1]);
	bufsz = GetFileSize(h,NULL);
	
	if( bufsz == INVALID_FILE_SIZE){
		printf("Could not get filesize\n\n");
		CloseHandle(h);
		return;
	}
	
	if( bufsz > 2000){
		printf("What in the world are you loading..to big..nay i say!\n");
		CloseHandle(h);
		return;
	}

	if(addbpx){
		printf("Adding Breakpoint to beginning of shellcode buffer\n");
		bufsz++;
	}

	buf = (char*)malloc(bufsz);
	printf("Loading Shellcode into memory\n");

	if(addbpx){
		buf[0]= (unsigned char)0xCC;
		ReadFile(h, &buf[1]  , (bufsz-1) ,&l,0);
	}else{
		ReadFile(h, buf  , bufsz ,&l,0);
	}

	CloseHandle(h);

	printf("Starting up winsock\n");
	
	if ( WSAStartup(MAKEWORD(1,1), &WsaDat) !=0  ){  
		printf("Sorry WSAStartup failed exiting.."); 
		return;
	}

	printf("Installing Hooks\n" ) ;
	InstallHooks();

	msg("Executing Buffer...\n\n"); //we are hooked now only use safe display fx
	msg("_ret_____API_________________\n",0x02);

	_asm jmp buf

	//we wont ever get down here..


}