-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDlgFinders.cpp
More file actions
181 lines (152 loc) · 4.07 KB
/
Copy pathDlgFinders.cpp
File metadata and controls
181 lines (152 loc) · 4.07 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "stdafx.h"
#include "Init.h"
#include "DlgFinders.h"
#include "DlgMain.h"
bool fIsDll;
CListBox FindersBox;
DWORD dwOEPFinderResult;
IMPLEMENT_DYNAMIC(CDlgFinders,CDialog)
CDlgFinders::CDlgFinders(bool n_fIsDll):CDialog(CDlgFinders::IDD,NULL)
{
fIsDll=n_fIsDll;
}
CDlgFinders::~CDlgFinders()
{
UnloadOEPFinders();
}
void CDlgFinders::DoDataExchange(CDataExchange *pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX,IDC_OEPFINDERSBOX,FindersBox);
}
BEGIN_MESSAGE_MAP(CDlgFinders,CDialog)
ON_LBN_DBLCLK(IDC_OEPFINDERSBOX,OnLbnDblclkOepfindersbox)
END_MESSAGE_MAP()
const TCHAR szOEPPluginSearch[]=_T("\\OEPFinders\\*.dll");
const TCHAR szOEPPluginDir[]=_T("\\OEPFinders\\");
const char szGetOEP[]="GetOEPNow";
const char szGetDllOEP[]="GetDllOEPNow";
const char szOEPGetNamePluginFn[]="ShortFinderName";
typedef DWORD (__stdcall *StartFinder)(const BYTE*);
typedef const BYTE *(__stdcall *GetFinderName)();
struct FINDER_INFO
{
HMODULE hModule;
StartFinder StartFunc;
bool fUnicode;
};
std::vector<FINDER_INFO> OEPFinders;
void LoadOEPFinders(HWND hWnd)
{
TCHAR cBuff[MAX_PATH]={_T('\0')};
WIN32_FIND_DATA Find={0};
HANDLE hFind;
GetModuleFileName(NULL,cBuff,_countof(cBuff));
PathToDir(cBuff);
_tcscat_s(cBuff,szOEPPluginSearch);
hFind=FindFirstFile(cBuff,&Find);
if(hFind!=INVALID_HANDLE_VALUE)
{
do ProcessOEPFinder(Find.cFileName);
while(FindNextFile(hFind,&Find));
FindClose(hFind);
}
EnableWindow(hWnd,OEPFinders.empty() ? FALSE : TRUE);
}
void ProcessOEPFinder(TCHAR *szDllName)
{
StartFinder pFn;
GetFinderName pFnGetName;
HMODULE hModule;
TCHAR cBuff[MAX_PATH]={_T('\0')};
GetModuleFileName(NULL,cBuff,_countof(cBuff));
PathToDir(cBuff);
_tcscat_s(cBuff,szOEPPluginDir);
_tcscat_s(cBuff,szDllName);
hModule=LoadLibrary(cBuff);
if(hModule==NULL)
return;
if(fIsDll)
pFn=(StartFinder)GetProcAddress(hModule,szGetDllOEP);
else
pFn=(StartFinder)GetProcAddress(hModule,szGetOEP);
pFnGetName=(GetFinderName)GetProcAddress(hModule,szOEPGetNamePluginFn);
if(pFn!=NULL && pFnGetName!=NULL)
{
FINDER_INFO FinderInfo;
FinderInfo.hModule=hModule;
FinderInfo.StartFunc=pFn;
FinderInfo.fUnicode=pFnGetName()[1]==0;
OEPFinders.push_back(FinderInfo);
TCHAR *szName;
if(FinderInfo.fUnicode)
{
size_t nLength=wcslen((WCHAR*)pFnGetName())+2;
szName=new TCHAR[nLength];
#ifdef UNICODE
_stprintf_s(szName,nLength,_T("%ls"),pFnGetName());
#else
_stprintf_s(szName,nLength,_T("%ls*"),pFnGetName());
#endif
}
else
{
size_t nLength=strlen((char*)pFnGetName())+2;
szName=new TCHAR[nLength];
#ifdef UNICODE
_stprintf_s(szName,nLength,_T("%hs*"),pFnGetName());
#else
_stprintf_s(szName,nLength,_T("%hs"),pFnGetName());
#endif
}
FindersBox.AddString(szName);
delete[] szName;
}
}
void UnloadOEPFinders()
{
for(size_t i=0;i!=OEPFinders.size();++i)
FreeLibrary(OEPFinders[i].hModule);
OEPFinders.clear();
}
BOOL CDlgFinders::OnInitDialog()
{
CDialog::OnInitDialog();
CString sTemp;
GetWindowText(sTemp); sTemp=pDlgMain->LocalizeString(sTemp,true); SetWindowText(sTemp);
LoadOEPFinders(GetSafeHwnd());
FindersBox.SetCurSel(0);
FindersBox.SelectString(-1,_T("ForceOEP"));
if(pDlgMain->Option.fAlwaysOnTop)
SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
return TRUE;
}
void CDlgFinders::OnLbnDblclkOepfindersbox()
{
size_t nLength=pDlgMain->InitData.sVictimFile.length()+1;
BYTE *szName;
if(OEPFinders[FindersBox.GetCurSel()].fUnicode)
{
szName=(BYTE*)new WCHAR[nLength];
#ifdef UNICODE
swprintf_s((WCHAR*)szName,nLength,L"%ls",pDlgMain->InitData.sVictimFile.c_str());
#else
swprintf_s((WCHAR*)szName,nLength,L"%hs",pDlgMain->InitData.sVictimFile.c_str());
#endif
}
else
{
szName=(BYTE*)new char[nLength];
#ifdef UNICODE
sprintf_s((char*)szName,nLength,"%ls",pDlgMain->InitData.sVictimFile.c_str());
#else
sprintf_s((char*)szName,nLength,"%hs",pDlgMain->InitData.sVictimFile.c_str());
#endif
}
dwOEPFinderResult=OEPFinders[FindersBox.GetCurSel()].StartFunc(szName);
delete[] szName;
pDlgMain->UpdateData(TRUE);
pDlgMain->sOEPbox.Format(_T("%08X"),dwOEPFinderResult);
pDlgMain->UpdateData(FALSE);
OnOK();
}