#include "configurator.h" #include "cout-sink.h" #include #include #include #include #include #include bool running = true; TinyMITMProxy* proxy; ProxyConfigurator* conf; #ifdef _WIN32 #define _AMD64_ #include #include #include // from: WinBase.h #define STD_OUTPUT_HANDLE ((DWORD) - 11) BOOL WINAPI consoleHandler(DWORD dwType) { if (dwType == CTRL_C_EVENT || dwType == CTRL_CLOSE_EVENT || dwType == CTRL_LOGOFF_EVENT || dwType == CTRL_SHUTDOWN_EVENT) { if (conf) conf->clearProxy(); running = false; exit(0); } return FALSE; } void createAndSetupConsole() { FILE* pstdout = stdout; AllocConsole(); freopen_s(&pstdout, "CONOUT$", "w", stdout); assert(pstdout != nullptr); DWORD conMode = 0; GetConsoleMode(pstdout, &conMode); conMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; SetConsoleMode(pstdout, conMode); SetConsoleCtrlHandler(consoleHandler, TRUE); } #endif int main() { #ifdef _WIN32 createAndSetupConsole(); #endif seallib::Logger mainLog("Main"); mainLog.addSink(std::make_shared()); mainLog.info("init"); mainLog.info("creating proxy"); TinyMITMConfig proxyConfig; proxy = new TinyMITMProxy(proxyConfig); mainLog.info("creating configurator"); conf = new ProxyConfigurator(); mainLog.info("setting proxy addr"); conf->setProxy("127.0.0.1", 44444); mainLog.info("starting proxy"); proxy->init(); while (running) std::this_thread::sleep_for(std::chrono::milliseconds(100)); return 0; }