This repository has been archived by the owner on Sep 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathex4_to_mq4_auto.c
136 lines (104 loc) · 3.19 KB
/
ex4_to_mq4_auto.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <shlobj.h>
#include <objbase.h>
#include <objidl.h>
#include <olectlid.h>
#include <tchar.h>
#include <wchar.h>
#include "scit/scit.h"
#define null NULL
#define true 1
#define false 0
#define APP_NAME "ex4_to_mq4_auto"
//L"D:\\prj\\cl workspace\\ex4_to_mq4_auto\\Debug\\Foo.ex4"
#define WND_NAME "EX4-TO-MQ4 Decompiler (https://purebeam.biz)"
#define EXE_NAME "ex4_to_mq4.exe"
//#define WND_NAME "NotePAD"
//#define EXE_NAME "notepad.exe"
typedef UINT WINAPI DragQueryFileW_t(HDROP,UINT,LPWSTR,UINT);
DragQueryFileW_t *oldDragQueryFileW;
wchar_t tmpWcBuff[1024];
HWND WINAPI _FindWindow(LPCTSTR lpClassName, LPCTSTR lpWindowName)
{
HWND hWnd;
hWnd = FindWindow(lpClassName, null);
if (hWnd) {
return hWnd;
}
hWnd = FindWindow(null, lpWindowName);
if (hWnd) {
return hWnd;
}
return 0;
}
/*
* http://msdn.microsoft.com/en-us/library/windows/desktop/bb776408(v=vs.85).aspx
*/
UINT WINAPI myDragQueryFileW(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch) {
if (iFile == -1) {
return 1;
}
if ((int)hDrop == 123 && iFile == 0) {
wcsncpy(lpszFile, tmpWcBuff, cch);
return wcslen(tmpWcBuff);
}
return oldDragQueryFileW(hDrop, iFile, lpszFile, cch);
}
int main(int argc, char **argv)
{
ScitInjectedProcessDescriptor_t ipd;
PROCESS_INFORMATION pi;
STARTUPINFO si;
HWND hWnd = 0;
char tmpBuff[1024];
DWORD dwTargetTmpWcBuff;
SIZE_T stWritten;
int i;
if (argc <= 1) {
memset(tmpBuff, 0, sizeof(tmpBuff));
snprintf(tmpBuff, sizeof(tmpBuff), "Usage: %s <ex4 file> [...]", argv[0]);
MessageBox(0, tmpBuff, APP_NAME, 0);
return 1;
}
hWnd = _FindWindow(WND_NAME, WND_NAME);
if (!hWnd) {
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
if (!CreateProcess(EXE_NAME, null, null, null, false, 0, null, null, &si, &pi)) {
memset(tmpBuff, 0, sizeof(tmpBuff));
snprintf(tmpBuff, sizeof(tmpBuff), "Unable to run %s", EXE_NAME);
MessageBox(0, tmpBuff, APP_NAME, 0);
return 1;
}
do {
if (!hWnd) {
hWnd = _FindWindow(WND_NAME, WND_NAME);
if (hWnd) {
break;
}
}
} while (WaitForSingleObject(pi.hProcess, 0));
}
ipd = scitInjectLocalModule(pi.dwProcessId, TRUE, FALSE);
if (ipd.bOk) {
ipd = scitRemoteHookAPI(ipd, "shell32.dll", "DragQueryFileW", (FARPROC)myDragQueryFileW, (FARPROC*)&oldDragQueryFileW, FALSE);
}
//calculate tmpWcBuff in remote process
dwTargetTmpWcBuff = (DWORD)tmpWcBuff - (DWORD)ipd.hModule + (DWORD)ipd.hInjectedModule;
for (i = 1; i < argc; i++) {
//get fullpath of target file
memset(tmpBuff, 0, sizeof(tmpBuff));
GetFullPathName(argv[i], sizeof(tmpBuff), tmpBuff, null);
//copy to local buffer as unicode string
mbstowcs(tmpWcBuff, tmpBuff, 1024);
//write file pathname to remote process and send WM_DROPFILES message
WriteProcessMemory(pi.hProcess, (LPVOID)dwTargetTmpWcBuff, tmpWcBuff, sizeof(tmpWcBuff), &stWritten);
SendMessage(hWnd, WM_DROPFILES, 123, 0);
}
//wait until process terminate
// do {
// } while (WaitForSingleObject(pi.hProcess, 1));
TerminateProcess(pi.hProcess, 0);
return 0;
}