📄 ollymachine.cpp
字号:
VM.Execute();
}
else if (2 == nDoWhat) // compile & link
{
char szFileNameBin[MAX_PATH];
CString strOutMsg;
char *pDest = NULL;
ShowMsg(
"Compile success!\n"
"Now you have to specify the target filename!\n\n"
"Press enter to continue..."
);
nRetCode = GetFileName(2, szFileNameBin, szFileName);
OM_PROCESS_ERROR(nRetCode);
nRetCode = PathFileExists(szFileNameBin);
if (nRetCode)
{
strOutMsg = "File \"";
strOutMsg += szFileNameBin;
strOutMsg += "\" already exists!\nAre you sure to overwrite it?";
nRetCode = MessageBox(
g_hWndMain,
strOutMsg,
g_szPluginName,
MB_ICONQUESTION | MB_YESNO
);
if (IDYES != nRetCode)
goto Exit0;
}
pDest = strrchr(szFileNameBin, '.');
if (NULL == pDest)
{
strcat(szFileNameBin, ".omb");
}
nRetCode = Linker(
unCodeSize,
ucCode,
unDataSize,
cData,
strlen(szFileNameBin) + 1,
szFileNameBin
);
OM_PROCESS_ERROR(nRetCode);
strOutMsg = "Compile & Link Success!\n\nFile saved as: \"";
strOutMsg += szFileNameBin;
strOutMsg += "\"";
ShowMsg(strOutMsg);
}
nRetResult = 1;
Exit0:
if (cData)
{
free(cData);
cData = NULL;
}
if (ucCode)
{
free(ucCode);
ucCode = NULL;
}
return nRetResult;
}
static int Compile()
{
return ProcessFile(2);
}
static int Run()
{
return ProcessFile(1);
}
static int CmpSysTimeData(const FILETIME *f1, const FILETIME *f2)
{
ASSERT(f1);
ASSERT(f2);
if (f1->dwHighDateTime > f2->dwHighDateTime)
return 1;
else if (f1->dwHighDateTime < f2->dwHighDateTime)
return -1;
else if(f1->dwLowDateTime > f2->dwLowDateTime)
return 1;
else if(f1->dwLowDateTime < f2->dwLowDateTime)
return -1;
else
return 0;
}
static CString GetScriptIniFilePath(void)
{
char szIniPathFileName[MAX_PATH];
CString strIniFile;
strcpy(szIniPathFileName, g_szIniFilePathName);
strcpy(&szIniPathFileName[strlen(szIniPathFileName) - 3], "ini");
strIniFile = szIniPathFileName;
return strIniFile;
}
static void SaveAllRecentFileToIni(void)
{
char szKey[MAX_PATH];
char szKeyTime[MAX_PATH];
char szFile[MAX_PATH];
CString strIniName = GetScriptIniFilePath();
RECENTFILE *pMark;
int i;
char *szRS = "RecentScript";
for (i = 0; i < NUM_OF_RECENT_FILE; ++i)
{
pMark = (RECENTFILE *)Findsorteddata(&(g_windowRecentFile.data), i);
szFile[0] = 0;
szKeyTime[0] = 0;
if (NULL != pMark)
{
strcpy(szFile, pMark->szFileName);
sprintf(
szKeyTime,
"%x-%x",
pMark->runtime.dwLowDateTime,
pMark->runtime.dwHighDateTime
);
}
sprintf(szKey, "File%02i", i);
WritePrivateProfileString(szRS, szKey, szFile, strIniName);
sprintf(szKey, "Time%02i", i);
WritePrivateProfileString(szRS, szKey, szKeyTime, strIniName);
}
}
static void ReadAllRecentFileFormIni(void)
{
char szKey[MAX_PATH];
char szKeyTime[MAX_PATH];
char szFile[MAX_PATH];
CString strDefault;
CString strIniName = GetScriptIniFilePath();
RECENTFILE mark;
char *szRS = "RecentScript";
int nIndex = 0;
int i;
for (i = 0;i < NUM_OF_RECENT_FILE; ++i)
{
sprintf(szKey, "File%02i", i);
GetPrivateProfileString(
szRS,
szKey,
strDefault,
szFile,
MAX_PATH,
strIniName
);
sprintf(szKey,"Time%02i",i);
GetPrivateProfileString(
szRS,
szKey,
strDefault,
szKeyTime,
MAX_PATH,
strIniName
);
if ((0 != szFile[0]) && (0 != szKeyTime[0]))
{
char *cTemp;
strcpy(mark.szFileName,szFile);
mark.index = nIndex;
mark.size = 1;
mark.type = 0;
CString strTime = szKeyTime;
int nPos = strTime.ReverseFind('-');
strTime = strTime.Mid(nPos + 1,strTime.GetLength() - nPos - 1);
szKeyTime[nPos] = 0;
mark.runtime.dwLowDateTime = strtol(szKeyTime, &cTemp, 16);
mark.runtime.dwHighDateTime = strtol(strTime, &cTemp, 16);
Addsorteddata(&(g_windowRecentFile.data), &mark);
++nIndex;
}
}
}
// To sort sorted data by some criterium, one must supply sort function that
// returns -1 if first element is less than second, 1 if first element is
// greater and 0 if elements are equal according to criterium sort. Usually
// this criterium is the zero-based index of the column in window.
static int RecentFileSortFunc(
/* [in] */ const RECENTFILE *f1,
/* [in] */ const RECENTFILE *f2,
/* [in] */ const int sort
)
{
ASSERT(f1);
ASSERT(f2);
int i = 0;
if (0 == sort)
i = strcmp(f1->szFileName, f2->szFileName);
// If elements are equal or sorting is by the first column, sort by index.
if (0 == i)
i = CmpSysTimeData(&f1->runtime, &f2->runtime);
return i;
}
// Display every line information
static int GetRecentFileText(
char *s,
char *mask,
int *select,
t_sortheader *ph,
int column
)
{
int n;
RECENTFILE *pb = (RECENTFILE *)ph;
switch (column)
{
case 0: //file name
{
CString szFileName = pb->szFileName;
int nPos = szFileName.ReverseFind('\\');
CString str = szFileName.Mid(
nPos + 1,
szFileName.GetLength() - nPos - 1
);
n = sprintf(s, "%s", str);
}
break;
case 1: //run time
{
SYSTEMTIME sysTime;
FileTimeToSystemTime(&pb->runtime, &sysTime);
n = sprintf(
s,
"%i/%i/%i %i:%02i:%02i",
sysTime.wYear,
sysTime.wMonth,
sysTime.wDay,
sysTime.wHour,
sysTime.wMinute,
sysTime.wSecond
);
}
break;
case 2: //path name
n = sprintf(s,"%s",pb->szFileName);
break;
default:
n = 0;
break;
}
return n;
}
static void CreateRecentFileWindow(void)
{
if (0 == g_windowRecentFile.bar.nbar)
{
// Bar still uninitialized.
g_windowRecentFile.bar.name[0] = "Recent Scripts"; // index
g_windowRecentFile.bar.defdx[0] = 30;
g_windowRecentFile.bar.mode[0] = 0; // can be sorted
g_windowRecentFile.bar.name[1] = "Last Visited Time";
g_windowRecentFile.bar.defdx[1] = 20;
g_windowRecentFile.bar.mode[1] = 0;
g_windowRecentFile.bar.name[2] = "Full Path"; // File Full Path
g_windowRecentFile.bar.defdx[2] = 256;
g_windowRecentFile.bar.mode[2] = BAR_NOSORT; // can't be sorted
g_windowRecentFile.bar.nbar = 3;
g_windowRecentFile.mode =
TABLE_COPYMENU | TABLE_SORTMENU | TABLE_APPMENU | TABLE_SAVEPOS;
g_windowRecentFile.drawfunc = GetRecentFileText;
};
// If window already exists, Quicktablewindow() does not create new window,
// but restores and brings to top existing. This is the simplest way,
// Newtablewindow() is more flexible but more complicated. I do not
// recommend custom (plugin-drawn) windows without very important reasons
// to do this.
Quicktablewindow(
&g_windowRecentFile,
15,
4,
g_szOllyMachineClass,
g_OM_RecentFiles
);
Selectandscroll(&g_windowRecentFile, 0, 2);
}
// This function receives possible keyboard shortcuts from standard OllyDbg
// windows. If it recognizes shortcut, it must process it and return 1,
// otherwise it returns 0.
extc int _export cdecl ODBG_Pluginshortcut(
int origin,
int ctrl,
int alt,
int shift,
int key,
void *item
)
{
if (
(1 == alt) &&
(key == 'r' || key == 'R')
)
{
CreateRecentFileWindow();
return 1;
}
return 0; // Shortcut not recognized
}
extc void _export cdecl RunOMFile(const char *szFileName)
{
ProcessFile(1, szFileName);
}
// use the last one to replace the deleted blank
void ReSortOtherData(const ulong ulIndex)
{
RECENTFILE *pMark1;
pMark1 = (RECENTFILE *)Findsorteddata(&(g_windowRecentFile.data), ulIndex);
if (NULL != pMark1)
return;
for (ulong i = NUM_OF_RECENT_FILE - 1; i > ulIndex; --i)
{
RECENTFILE *pMark = (RECENTFILE *)Findsorteddata(
&(g_windowRecentFile.data),
i
);
if (NULL != pMark)
{
RECENTFILE mark = *pMark;
mark.index = i;
Deletesorteddata(&(g_windowRecentFile.data), i);
Addsorteddata(&(g_windowRecentFile.data), &mark);
}
}
}
LRESULT CALLBACK OllyMachineWndProc(
HWND hw,
UINT msg,
WPARAM wp,
LPARAM lp
)
{
int i;
int shiftkey;
int controlkey;
HMENU menu;
RECENTFILE *pb;
switch (msg)
{
// Standard messages. You can process them, but - unless absolutely sure -
// always pass them to Tablefunction().
case WM_DESTROY:
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_LBUTTONDBLCLK:
case WM_LBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONDBLCLK:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -