| 1 | // Runner.cpp : �A�v���P�[�V�����̃G���g�� �|�C���g��`���܂��B
|
|---|
| 2 | //
|
|---|
| 3 | #include "StdAfx.h"
|
|---|
| 4 | #include "Common.h"
|
|---|
| 5 |
|
|---|
| 6 | namespace SleipnirGoogleSuggest {
|
|---|
| 7 | namespace Hook {
|
|---|
| 8 | extern bool CALLBACK AttachFromOtherProcess(DWORD SleipnirThreadId);
|
|---|
| 9 | }
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | int APIENTRY _tWinMain(HINSTANCE hInstance,
|
|---|
| 13 | HINSTANCE hPrevInstance,
|
|---|
| 14 | LPTSTR lpCmdLine,
|
|---|
| 15 | int nCmdShow)
|
|---|
| 16 | {
|
|---|
| 17 | UNREFERENCED_PARAMETER(hInstance);
|
|---|
| 18 | UNREFERENCED_PARAMETER(hPrevInstance);
|
|---|
| 19 |
|
|---|
| 20 | using namespace SleipnirGoogleSuggest;
|
|---|
| 21 |
|
|---|
| 22 | Debug("hello world");
|
|---|
| 23 |
|
|---|
| 24 | if (!GetSearchBarEdit()) {
|
|---|
| 25 | // �悭���镶����`�F�b�N�����Ƃ�
|
|---|
| 26 | Debug("CreateProcess()");
|
|---|
| 27 |
|
|---|
| 28 | TCHAR s[MAX_PATH];
|
|---|
| 29 | GetModuleFileName(GetModuleHandle(NULL),s,MAX_PATH);
|
|---|
| 30 | PathRemoveFileSpec(s);
|
|---|
| 31 | PathAppend(s, _T("Sleipnir.exe"));
|
|---|
| 32 |
|
|---|
| 33 | if (!PathFileExists(s)) {
|
|---|
| 34 | Debug("Sleipnir.exe not found");
|
|---|
| 35 | return 1;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | // �v�j���̋@��
|
|---|
| 39 | STARTUPINFO startupInfo;
|
|---|
| 40 | PROCESS_INFORMATION processInfo;
|
|---|
| 41 |
|
|---|
| 42 | memset(&startupInfo,0,sizeof(startupInfo));
|
|---|
| 43 | startupInfo.cb=sizeof(startupInfo);
|
|---|
| 44 | startupInfo.wShowWindow = nCmdShow;
|
|---|
| 45 |
|
|---|
| 46 | if (!CreateProcess(
|
|---|
| 47 | s,
|
|---|
| 48 | lpCmdLine,
|
|---|
| 49 | NULL,
|
|---|
| 50 | NULL,
|
|---|
| 51 | FALSE,
|
|---|
| 52 | 0,
|
|---|
| 53 | NULL,
|
|---|
| 54 | NULL,
|
|---|
| 55 | &startupInfo,
|
|---|
| 56 | &processInfo
|
|---|
| 57 | )) {
|
|---|
| 58 | Debug("!CreateProcess()");
|
|---|
| 59 | return 1;
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|
| 62 | {
|
|---|
| 63 | // �t�b�N�������b�N�X������ő҂� |
|---|
| 64 | HWND hWnd = NULL;
|
|---|
| 65 | for (int loop=0; loop<50; loop++) {
|
|---|
| 66 | Sleep(1000);
|
|---|
| 67 | hWnd = GetSearchBarEdit();
|
|---|
| 68 | if (hWnd) {
|
|---|
| 69 | break;
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 | if (!hWnd) {
|
|---|
| 73 | Debug("searchbarnotfound");
|
|---|
| 74 | return 1;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | DWORD tid = GetWindowThreadProcessId(hWnd,NULL);
|
|---|
| 78 | Hook::AttachFromOtherProcess(tid);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | return 0;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|