Merge pull request #1 from Starystars67/unix-tcp-fix

Unix tcp fix merge into master
This commit is contained in:
Anonymous275 2020-11-06 17:21:35 +02:00 committed by GitHub
commit 7c2871f1b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View File

@ -7,14 +7,18 @@
#include <WS2tcpip.h>
#include <filesystem>
#include "Startup.h"
#include <algorithm>
#include "Logger.h"
#include <iostream>
#include <sstream>
#include <cstring>
#include <fstream>
#include <string>
#include <thread>
#include <vector>
namespace fs = std::experimental::filesystem;
std::string ListOfMods;
std::vector<std::string> Split(const std::string& String,const std::string& delimiter){
@ -30,12 +34,12 @@ std::vector<std::string> Split(const std::string& String,const std::string& deli
return Val;
}
void STCPSend(SOCKET socket,const std::string&Data){
void STCPSendRaw(SOCKET socket,const std::vector<char>& Data){
if(socket == -1){
Terminate = true;
return;
}
int BytesSent = send(socket, Data.c_str(), int(Data.length())+1, 0);
int BytesSent = send(socket, Data.data(), int(Data.size()), 0);
if (BytesSent == 0){
debug(Sec("(TCP) Connection closing..."));
Terminate = true;
@ -49,6 +53,9 @@ void STCPSend(SOCKET socket,const std::string&Data){
}
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
void STCPSend(SOCKET socket,const std::string&Data){
STCPSendRaw(socket,std::vector<char>(Data.begin(),Data.end()));
}
std::pair<char*,size_t> STCPRecv(SOCKET socket){
char buf[64000];
int len = 64000;
@ -112,6 +119,15 @@ void Check(Hold* S){
}
}
}
std::vector<char> PrependSize(const std::string& str) {
uint32_t Size = htonl(uint32_t(str.size()) + 1);
std::vector<char> result;
// +1 for \0, +4 for the size
result.resize(str.size() + 1 + 4);
memcpy(result.data(), &Size, 4);
memcpy(result.data() + 4, str.data(), str.size() + 1);
return result;
}
std::string HandShake(SOCKET Sock,Hold*S,RSA*LKey){
S->TCPSock = Sock;
std::thread Timeout(Check,S);
@ -121,7 +137,7 @@ std::string HandShake(SOCKET Sock,Hold*S,RSA*LKey){
std::string msg(Res.first,Res.second);
Parse(msg);
if(N != 0 && E != 0) {
STCPSend(Sock,GenerateM(LKey));
STCPSendRaw(Sock,PrependSize(GenerateM(LKey)));
Res = STCPRecv(Sock);
msg = std::string(Res.first,Res.second);
if(RSA_D(msg,LKey->d,LKey->n) != "HC"){
@ -138,8 +154,8 @@ std::string HandShake(SOCKET Sock,Hold*S,RSA*LKey){
}
msg = RSA_E("NR" + GetDName() + ":" + GetDID(),E,N);
if(!msg.empty()) {
STCPSend(Sock,msg);
STCPSend(Sock, RSA_E("VC" + GetVer(),E,N));
STCPSendRaw(Sock, PrependSize(msg));
STCPSendRaw(Sock, PrependSize(RSA_E("VC" + GetVer(),E,N)));
Res = STCPRecv(Sock);
msg = Res.first;
}

View File

@ -10,7 +10,6 @@
#include <filesystem>
#include <iostream>
#include "Logger.h"
#include <urlmon.h>
#include <thread>
extern int TraceBack;
@ -25,7 +24,7 @@ std::string GetVer(){
return r;
}
std::string GetPatch(){
static std::string r = Sec(".6");
static std::string r = Sec(".7");
return r;
}
void ReLaunch(int argc,char*args[]){