-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmain_common.c
169 lines (137 loc) · 4.59 KB
/
main_common.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
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
#include "stdafx.h"
#include "main_common.h"
#include "plugin.h"
#include "raedit.h"
#include "assembler_dlg.h"
#include "resource.h"
HINSTANCE hDllInst;
OPTIONS options;
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hinstDLL);
hDllInst = hinstDLL;
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
TCHAR *PluginInit(HINSTANCE hInst)
{
INITCOMMONCONTROLSEX icex;
TCHAR *pError;
// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icex);
// For drag'n'drop support
if(FAILED(OleInitialize(NULL)))
return _T("OleInitialize() failed");
// Install RAEdit control
InstallRAEdit(hInst, FALSE);
// Init stuff
pError = AssemblerInit();
if(pError)
{
UnInstallRAEdit();
return pError;
}
// Load options
MyGetintfromini(hInst, _T("disasm_rva"), &options.disasm_rva, 0, 0, 1);
MyGetintfromini(hInst, _T("disasm_rva_reloconly"), &options.disasm_rva_reloconly, 0, 0, 1);
MyGetintfromini(hInst, _T("disasm_label"), &options.disasm_label, 0, 0, 1);
MyGetintfromini(hInst, _T("disasm_extjmp"), &options.disasm_extjmp, 0, 0, 1);
MyGetintfromini(hInst, _T("disasm_hex"), &options.disasm_hex, 0, 4, 0);
MyGetintfromini(hInst, _T("disasm_labelgen"), &options.disasm_labelgen, 0, 2, 0);
MyGetintfromini(hInst, _T("asm_comments"), &options.asm_comments, 0, 0, 1);
MyGetintfromini(hInst, _T("asm_labels"), &options.asm_labels, 0, 0, 1);
MyGetintfromini(hInst, _T("edit_savepos"), &options.edit_savepos, 0, 0, 1);
MyGetintfromini(hInst, _T("edit_tabwidth"), &options.edit_tabwidth, 0, 2, 1);
return NULL;
}
void PluginExit()
{
AssemblerExit();
UnInstallRAEdit();
OleUninitialize();
}
BOOL OpenHelp(HWND hWnd, HINSTANCE hInst)
{
TCHAR szFilePath[MAX_PATH];
DWORD dwPathLen;
dwPathLen = GetModuleFileName(hInst, szFilePath, MAX_PATH);
if(dwPathLen == 0)
return FALSE;
do
{
dwPathLen--;
if(dwPathLen == 0)
return FALSE;
}
while(szFilePath[dwPathLen] != _T('\\'));
dwPathLen++;
szFilePath[dwPathLen] = _T('\0');
dwPathLen += sizeof("multiasm.chm") - 1;
if(dwPathLen > MAX_PATH - 1)
return FALSE;
lstrcat(szFilePath, _T("multiasm.chm"));
return !((int)(UINT_PTR)ShellExecute(hWnd, NULL, szFilePath, NULL, NULL, SW_SHOWNORMAL) <= 32);
}
#if !(defined(TARGET_ODBG) || defined(TARGET_IMMDBG) || defined(TARGET_ODBG2))
void OpenUrl(HWND hWnd, PCWSTR url) {
if((INT_PTR)ShellExecuteW(hWnd, L"open", url, NULL, NULL, SW_SHOWNORMAL) <= 32) {
MessageBox(hWnd, _T("Failed to open link"), NULL, MB_ICONHAND);
}
}
HRESULT CALLBACK AboutMessageBoxCallback(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LONG_PTR lpRefData) {
switch(msg) {
case TDN_HYPERLINK_CLICKED:
OpenUrl(hwnd, (PCWSTR)lParam);
break;
}
return S_OK;
}
#endif // !(defined(TARGET_ODBG) || defined(TARGET_IMMDBG) || defined(TARGET_ODBG2))
int AboutMessageBox(HWND hWnd, HINSTANCE hInst)
{
// OllyDbg doesn't use visual styles, so TaskDialogIndirect isn't available.
#if defined(TARGET_ODBG) || defined(TARGET_IMMDBG) || defined(TARGET_ODBG2)
PCWSTR content =
DEF_PLUGINNAME _T(" v") DEF_VERSION _T("\n")
_T("By m417z (Ramen Software)\n")
_T("\n")
_T("Source code:\n")
_T("https://github.com/m417z/Multiline-Ultimate-Assembler");
MSGBOXPARAMS mbpMsgBoxParams;
ZeroMemory(&mbpMsgBoxParams, sizeof(MSGBOXPARAMS));
mbpMsgBoxParams.cbSize = sizeof(MSGBOXPARAMS);
mbpMsgBoxParams.hwndOwner = hWnd;
mbpMsgBoxParams.hInstance = hInst;
mbpMsgBoxParams.lpszText = content;
mbpMsgBoxParams.lpszCaption = _T("About");
mbpMsgBoxParams.dwStyle = MB_USERICON;
mbpMsgBoxParams.lpszIcon = MAKEINTRESOURCE(IDI_MAIN);
return MessageBoxIndirect(&mbpMsgBoxParams);
#else
PCWSTR content =
DEF_PLUGINNAME L" v" DEF_VERSION L"\n"
L"By m417z (<A HREF=\"https://ramensoftware.com/\">Ramen Software</A>)\n"
L"\n"
L"Source code:\n"
L"<A HREF=\"https://github.com/m417z/Multiline-Ultimate-Assembler\">https://github.com/m417z/Multiline-Ultimate-Assembler</a>";
TASKDIALOGCONFIG taskDialogConfig;
ZeroMemory(&taskDialogConfig, sizeof(TASKDIALOGCONFIG));
taskDialogConfig.cbSize = sizeof(taskDialogConfig);
taskDialogConfig.hwndParent = hWnd;
taskDialogConfig.hInstance = hInst;
taskDialogConfig.dwFlags = TDF_ENABLE_HYPERLINKS | TDF_ALLOW_DIALOG_CANCELLATION;
taskDialogConfig.pszWindowTitle = L"About";
taskDialogConfig.pszMainIcon = MAKEINTRESOURCEW(IDI_MAIN);
taskDialogConfig.pszContent = content;
taskDialogConfig.pfCallback = AboutMessageBoxCallback;
return TaskDialogIndirect(&taskDialogConfig, NULL, NULL, NULL);
#endif
}