void Engine::read_socket(DataInputStream & network_in) { if( BIO_pending(bioIn) > 64*1024 ) // Enough for 4 ssl packets return; Data data; if( network_in.read(data) == 0 ) return; wLog("sock.read: %d", data.getSize()); int len = BIO_write(bioIn, data.getData(), data.getSize()); // Consumes everything by docs wLog("BIO_write: %d", len); }
void Engine::read_app() { if( !waiting_to_app_data.empty() ) return; Data tmp(16384); // SSL_pending has a bug that returns 0 until you call SSL_read wLog("before SSL_read"); int len = SSL_read(ssl, tmp.lock(), tmp.getSize()); int err = SSL_get_error(ssl, len); wLog("SSL_read: %d %d", len, err); if( len <= 0 ) return; waiting_to_app_data = Data(tmp, 0, len); }
int Engine::write(Data & data) // Write application data { if( data.empty() ) // SSL_write undefined behaviour when writing 0 return 0; int write = SSL_write(ssl, data.getData(), data.getSize()); wLog("SSL_write: %d", write); if( write <= 0 ) return 0; data = Data(data, write, data.getSize() - write); return write; }
void Engine::write_socket(DataOutputStream & network_out) { while(true) { if( waiting_to_socket_data.empty() ) { int cbPending = int(BIO_ctrl_pending(bioOut)); if( cbPending == 0 ) break; waiting_to_socket_data = Data(cbPending); int len = BIO_read(bioOut, waiting_to_socket_data.lock(), waiting_to_socket_data.getSize()); wLog("BIO_read: %d", len); waiting_to_socket_data = Data(waiting_to_socket_data, 0, len); } int slen = network_out.write(waiting_to_socket_data); wLog("sock.write: %d", slen); if( !waiting_to_socket_data.empty() ) break; } }
//Called after StarCraft is completely loaded extern "C" __declspec(dllexport) bool ApplyPatch(HANDLE hProcess, DWORD dwProcessID) { wchar_t msgtemp[255]; wchar_t dll[MAX_PATH]; GetFullPathNameW(WDETECTOR, MAX_PATH, dll, NULL); wLog(LOG_INFO, L"~Logging started~"); //Get SeDebugPrivilege if (SetDebugPrivilege(TRUE) == true) { wLog(LOG_INFO, L"Obtained SeDebugPrivilege"); } else { wLog(LOG_ERROR, L"Unable to obtain SeDebugPrivilege"); return false; } //Inject wDetector.w if (CreateRemoteThreadInject(dwProcessID, dll) == true) { swprintf_s(msgtemp, sizeof(msgtemp), L"Injected %ls into %d", dll, dwProcessID); wLog(LOG_INFO, msgtemp); } else { swprintf_s(msgtemp, sizeof(msgtemp), L"Could not inject %ls into %d", dll, dwProcessID); wLog(LOG_ERROR, msgtemp); return false; } //Kill wLauncher.exe std::thread wLauncher(KillProc, processInfo.hProcess); //Wait for wDetector.w std::this_thread::sleep_for(std::chrono::milliseconds(250)); //Get base address of wDetector.w module uint32_t wDetectorBaseAddress = 0; if (FindModuleBaseAddress(WDETECTOR, wDetectorBaseAddress) == true) { swprintf_s(msgtemp, sizeof(msgtemp), L"wDetector's base address is %d", wDetectorBaseAddress); wLog(LOG_INFO, msgtemp); } else { wLog(LOG_ERROR, L"Could not get wDetector's base address!"); return false; } //Wait for wLauncher to be killed wLauncher.join(); //Patch wDetector int8_t activate = { 0x12 }; WriteProcessMemory(hProcess, (LPVOID)(wDetectorBaseAddress + (uint32_t)0x5AD94), &activate, sizeof(activate), NULL); wLog(LOG_INFO, L"wDetector activated!"); std::array<uint32_t, 17> offset = { 0x429E4, //Refresh game message 0x43CB4, //toggle automatic refresh - enable 0x43CAC, //toggle automatic refresh - disable 0x41B8C, //ago 0x41B84, //min 0x41B88, //sec 0x41AB0, 0x418D3, //mission briefing 0x43DB3, //time off 0x43DA3, //time on 0x43CBD, //toggle automatic refresh 0x4297D, //Automatic game refresh disable -msg after 3 mins 0x4299F, //3 minutes passed) -msg after 3 mins 0x429C7, //F5 - seconds until refreshing. 0x41C0B, //English 0x42755, //"Conflict" (no null terminator) 0x444CC //"has banned you. (Host hack)" }; std::array<std::string, 17> vals = { "Refreshing", //<wDetector 3.35 - Refreshing> "enabled", //toggle automatic refresh "disable", //toggle automatic refresh "ago", "min", "sec", " min %u sec", "Players Ready", //mission briefing "Time off", "Time on", "Automatic refresh %s", //toggle automatic refresh "Automatic game refresh disable", //msg after 3 mins "3 minutes passed)", //msg after 3 mins " seconds until refreshing.", //F5 "English", /*16*/ "Conflict", "has banned you. (Host hack)" }; std::array<char, 17> terminator = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*16*/ 0x20, 0x00 }; { char buff[50] = ""; int a = 0; for (std::size_t i{ 0 }; i < offset.size(); ++i) { if (terminator.at(i) == 0x00) { a = 1; } else { vals.at(i) += terminator.at(i); //append to end of C++ string a = 0; //don't leave room for null terminator } strcpy_s(buff, sizeof(buff), vals.at(i).c_str()); //vals.size() does not have a null terminator WriteProcessMemory(hProcess, (LPVOID)(wDetectorBaseAddress + offset.at(i)), buff, vals.at(i).size() + a, NULL); } } wLog(LOG_INFO, L"wDetector translated"); return true; }