feat: add test main

This commit is contained in:
2026-05-12 19:13:46 -03:00
parent ffc02e65be
commit 9c96b73d28
+85
View File
@@ -0,0 +1,85 @@
#include "configurator.h"
#include "cout-sink.h"
#include <tinymitm/proxy.h>
#include <tinymitm/ssl.h>
#include <seallib/log.h>
#include <memory>
#include <thread>
#include <chrono>
bool running = true;
TinyMITMProxy* proxy;
ProxyConfigurator* conf;
#ifdef _WIN32
#define _AMD64_
#include <consoleapi.h>
#include <processenv.h>
#include <cassert>
// 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<ConOutSink>());
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;
}