mirror of https://github.com/x64dbg/TitanEngine
small bugfix
This commit is contained in:
parent
f2123991bd
commit
12ae6dcb9d
|
|
@ -47,162 +47,168 @@ INT_PTR CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
{
|
|
||||||
//set icon
|
|
||||||
HICON hIconLarge = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE);
|
|
||||||
SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIconLarge);
|
|
||||||
HICON hIconSmall = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, LR_DEFAULTSIZE);
|
|
||||||
SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall);
|
|
||||||
|
|
||||||
//initialize variables
|
|
||||||
hLogBox = GetDlgItem(hWnd, IDC_LOG);
|
|
||||||
hRunBtn = GetDlgItem(hWnd, IDC_RUN);
|
|
||||||
int i = GetModuleFileName(hInst, FileNameIni, _countof(FileNameIni));
|
|
||||||
while(FileNameIni[i] != TCHAR('\\') && i)
|
|
||||||
i--;
|
|
||||||
if(i)
|
|
||||||
{
|
{
|
||||||
int len = lstrlen(FileNameIni);
|
//set icon
|
||||||
while(FileNameIni[i] != TCHAR('.') && i < len)
|
HICON hIconLarge = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE);
|
||||||
i++;
|
SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIconLarge);
|
||||||
if(i+1 < len)
|
HICON hIconSmall = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, LR_DEFAULTSIZE);
|
||||||
FileNameIni[i] = TCHAR('\0');
|
SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall);
|
||||||
}
|
|
||||||
lstrcat(FileNameIni, _T(".ini"));
|
|
||||||
CreateDummyUnicodeFile(FileNameIni);
|
|
||||||
|
|
||||||
//restore last files
|
//initialize variables
|
||||||
SettingGet(_T("Target"), FileNameTarget, _countof(FileNameTarget));
|
hLogBox = GetDlgItem(hWnd, IDC_LOG);
|
||||||
if(lstrlen(FileNameTarget))
|
hRunBtn = GetDlgItem(hWnd, IDC_RUN);
|
||||||
SetDlgItemText(hWnd, IDC_TARGETPATH, FileNameTarget);
|
int i = GetModuleFileName(hInst, FileNameIni, _countof(FileNameIni));
|
||||||
SettingGet(_T("Script"), FileNameScript, _countof(FileNameScript));
|
while(FileNameIni[i] != TCHAR('\\') && i)
|
||||||
if(lstrlen(FileNameScript))
|
i--;
|
||||||
SetDlgItemText(hWnd, IDC_SCRIPTPATH, FileNameScript);
|
if(i)
|
||||||
|
{
|
||||||
|
int len = lstrlen(FileNameIni);
|
||||||
|
while(FileNameIni[i] != TCHAR('.') && i < len)
|
||||||
|
i++;
|
||||||
|
if(i+1 < len)
|
||||||
|
FileNameIni[i] = TCHAR('\0');
|
||||||
|
}
|
||||||
|
lstrcat(FileNameIni, _T(".ini"));
|
||||||
|
CreateDummyUnicodeFile(FileNameIni);
|
||||||
|
|
||||||
//make sure TitanScript is available
|
//restore last files
|
||||||
if ( !ExtensionManagerIsPluginLoaded( "TitanScript" ) || !ExtensionManagerIsPluginEnabled( "TitanScript" ) )
|
SettingGet(_T("Target"), FileNameTarget, _countof(FileNameTarget));
|
||||||
{
|
if(lstrlen(FileNameTarget))
|
||||||
AddLogMessageW(L"TitanScript failed to load", TS_LOG_ERROR);
|
SetDlgItemText(hWnd, IDC_TARGETPATH, FileNameTarget);
|
||||||
|
SettingGet(_T("Script"), FileNameScript, _countof(FileNameScript));
|
||||||
|
if(lstrlen(FileNameScript))
|
||||||
|
SetDlgItemText(hWnd, IDC_SCRIPTPATH, FileNameScript);
|
||||||
|
|
||||||
|
//make sure TitanScript is available
|
||||||
|
if ( !ExtensionManagerIsPluginLoaded( "TitanScript" ) || !ExtensionManagerIsPluginEnabled( "TitanScript" ) )
|
||||||
|
{
|
||||||
|
AddLogMessageW(L"TitanScript failed to load", TS_LOG_ERROR);
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
AddLogMessageW(L"Ensure plugins\\x64\\TitanScript.dll exists !", TS_LOG_ERROR);
|
AddLogMessageW(L"Ensure plugins\\x64\\TitanScript.dll exists !", TS_LOG_ERROR);
|
||||||
#else
|
#else
|
||||||
AddLogMessageW(L"Ensure plugins\\x86\\TitanScript.dll exists !", TS_LOG_ERROR);
|
AddLogMessageW(L"Ensure plugins\\x86\\TitanScript.dll exists !", TS_LOG_ERROR);
|
||||||
#endif //_WIN64
|
#endif //_WIN64
|
||||||
EnableWindow(GetDlgItem(hWnd, IDC_RUN ), FALSE);
|
EnableWindow(GetDlgItem(hWnd, IDC_RUN ), FALSE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
load_file = GetTSFunctionPointer( LoadFileW );
|
load_file = GetTSFunctionPointer( LoadFileW );
|
||||||
exec = GetTSFunctionPointer( ExecuteWithTitanMistW );
|
exec = GetTSFunctionPointer( ExecuteWithTitanMistW );
|
||||||
set_log_callback = GetTSFunctionPointer( SetLogCallback );
|
set_log_callback = GetTSFunctionPointer( SetLogCallback );
|
||||||
set_log_callback(&AddLogMessage);
|
set_log_callback(&AddLogMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
{
|
|
||||||
switch (LOWORD(wParam))
|
|
||||||
{
|
{
|
||||||
case IDC_BROWSETARGET:
|
switch (LOWORD(wParam))
|
||||||
{
|
|
||||||
if(GetFileDialog(FileNameTarget))
|
|
||||||
{
|
{
|
||||||
SetDlgItemText(hWnd, IDC_TARGETPATH, FileNameTarget);
|
case IDC_BROWSETARGET:
|
||||||
SettingSet(_T("Target"), FileNameTarget);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IDC_BROWSESCRIPT:
|
|
||||||
{
|
|
||||||
if(GetFileDialog(FileNameScript))
|
|
||||||
{
|
|
||||||
SetDlgItemText(hWnd, IDC_SCRIPTPATH, FileNameScript);
|
|
||||||
SettingSet(_T("Script"), FileNameScript);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IDC_RUN:
|
|
||||||
{
|
|
||||||
if(!bRunning)
|
|
||||||
CreateThread(0, 0, TitanScriptExecThread, 0, 0, 0);
|
|
||||||
else
|
|
||||||
StopDebug();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IDC_COPY: {
|
|
||||||
//get lines
|
|
||||||
LRESULT cnt = SendMessageW(hLogBox, LB_GETCOUNT, 0, 0);
|
|
||||||
|
|
||||||
if (cnt != 0 && cnt != LB_ERR)
|
|
||||||
{
|
|
||||||
WCHAR * copy = 0;
|
|
||||||
int copyLength = 0;
|
|
||||||
|
|
||||||
for(LRESULT i=0; i<cnt; i++) {
|
|
||||||
LRESULT stringLength = SendMessageW(hLogBox, LB_GETTEXTLEN, i, 0);
|
|
||||||
copyLength += stringLength + 1 + 2;
|
|
||||||
|
|
||||||
copy = (WCHAR *)realloc(copy, copyLength * sizeof(WCHAR));
|
|
||||||
if (copy)
|
|
||||||
{
|
|
||||||
copy[copyLength - stringLength - 1 - 2] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
WCHAR * buf = (WCHAR *)calloc(stringLength + 1, sizeof(WCHAR));
|
|
||||||
|
|
||||||
if (buf && (SendMessageW(hLogBox, LB_GETTEXT, i, (LPARAM)buf) != LB_ERR))
|
|
||||||
{
|
|
||||||
wcscat(copy, buf);
|
|
||||||
wcscat(copy, L"\r\n");
|
|
||||||
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//copy to clipboard
|
|
||||||
HGLOBAL clipbuffer;
|
|
||||||
WCHAR* buffer;
|
|
||||||
clipbuffer = GlobalAlloc(GMEM_MOVEABLE, (wcslen(copy) + 1) * sizeof(WCHAR));
|
|
||||||
if (clipbuffer)
|
|
||||||
{
|
{
|
||||||
buffer = (TCHAR*)GlobalLock(clipbuffer);
|
if(GetFileDialog(FileNameTarget))
|
||||||
wcscpy(buffer, copy);
|
{
|
||||||
GlobalUnlock(clipbuffer);
|
SetDlgItemText(hWnd, IDC_TARGETPATH, FileNameTarget);
|
||||||
OpenClipboard(NULL);
|
SettingSet(_T("Target"), FileNameTarget);
|
||||||
EmptyClipboard();
|
}
|
||||||
UINT format;
|
break;
|
||||||
|
}
|
||||||
|
case IDC_BROWSESCRIPT:
|
||||||
|
{
|
||||||
|
if(GetFileDialog(FileNameScript))
|
||||||
|
{
|
||||||
|
SetDlgItemText(hWnd, IDC_SCRIPTPATH, FileNameScript);
|
||||||
|
SettingSet(_T("Script"), FileNameScript);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case IDC_RUN:
|
||||||
|
{
|
||||||
|
if(!bRunning)
|
||||||
|
CreateThread(0, 0, TitanScriptExecThread, 0, 0, 0);
|
||||||
|
else
|
||||||
|
StopDebug();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case IDC_COPY: {
|
||||||
|
//get lines
|
||||||
|
LRESULT cnt = SendMessageW(hLogBox, LB_GETCOUNT, 0, 0);
|
||||||
|
|
||||||
|
if (cnt != 0 && cnt != LB_ERR)
|
||||||
|
{
|
||||||
|
WCHAR * copy = (WCHAR *)calloc(1, sizeof(WCHAR));
|
||||||
|
int copyLength = 1;
|
||||||
|
|
||||||
|
for(LRESULT i=0; i<cnt; i++) {
|
||||||
|
LRESULT stringLength = SendMessageW(hLogBox, LB_GETTEXTLEN, i, 0);
|
||||||
|
copyLength += stringLength + 2;
|
||||||
|
|
||||||
|
copy = (WCHAR *)realloc(copy, copyLength * sizeof(WCHAR));
|
||||||
|
if (copy)
|
||||||
|
{
|
||||||
|
copy[copyLength - stringLength - 2] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
WCHAR * buf = (WCHAR *)calloc(stringLength + 1, sizeof(WCHAR));
|
||||||
|
|
||||||
|
if (buf && (SendMessageW(hLogBox, LB_GETTEXT, i, (LPARAM)buf) != LB_ERR))
|
||||||
|
{
|
||||||
|
wcscat(copy, buf);
|
||||||
|
wcscat(copy, L"\r\n");
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//copy to clipboard
|
||||||
|
HGLOBAL clipbuffer;
|
||||||
|
WCHAR* buffer;
|
||||||
|
clipbuffer = GlobalAlloc(GMEM_MOVEABLE, (wcslen(copy) + 1) * sizeof(WCHAR));
|
||||||
|
if (clipbuffer)
|
||||||
|
{
|
||||||
|
buffer = (TCHAR*)GlobalLock(clipbuffer);
|
||||||
|
wcscpy(buffer, copy);
|
||||||
|
GlobalUnlock(clipbuffer);
|
||||||
|
OpenClipboard(NULL);
|
||||||
|
EmptyClipboard();
|
||||||
|
UINT format;
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
format = CF_UNICODETEXT;
|
format = CF_UNICODETEXT;
|
||||||
#else
|
#else
|
||||||
format = CF_OEMTEXT;
|
format = CF_OEMTEXT;
|
||||||
#endif
|
#endif
|
||||||
SetClipboardData(format, clipbuffer);
|
SetClipboardData(format, clipbuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseClipboard();
|
||||||
|
|
||||||
|
free(copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseClipboard();
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
{
|
{
|
||||||
EndDialog(hWnd, NULL);
|
EndDialog(hWnd, NULL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
return false;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue