/*
 * beacon.h -- Full Beacon API header for BOF development
 * Step 03: Complete API surface with data parsing, output, formatting,
 *          and the DLL import convention.
 *
 * This header declares ALL functions a BOF can call. The functions
 * themselves are NOT defined here -- they are external symbols that
 * the COFF loader resolves at load time, either from its internal
 * compatibility layer or via LoadLibraryA/GetProcAddress.
 */

#ifndef BEACON_H_
#define BEACON_H_

#include <windows.h>

/* ================================================================
 * Callback type constants
 * Controls how the output is categorized by the operator console.
 * ================================================================ */
#define CALLBACK_OUTPUT      0x00
#define CALLBACK_OUTPUT_OEM  0x1e
#define CALLBACK_ERROR       0x0d
#define CALLBACK_OUTPUT_UTF8 0x20

/* ================================================================
 * datap -- Cursor-based argument parser
 *
 * Arguments arrive as a packed byte buffer. This struct tracks
 * the current read position as you extract typed values.
 * ================================================================ */
typedef struct {
    char* original;   /* pointer to buffer start                    */
    char* buffer;     /* current read cursor (advances on extract)  */
    int   length;     /* remaining bytes from cursor to end         */
    int   size;       /* total parseable region size                */
} datap;

/* ================================================================
 * formatp -- Output buffer builder
 *
 * Identical layout to datap but used for WRITING output
 * incrementally rather than reading input.
 * ================================================================ */
typedef struct {
    char* original;   /* allocated buffer base                      */
    char* buffer;     /* current write cursor                       */
    int   length;     /* bytes written so far                       */
    int   size;       /* total allocated capacity                   */
} formatp;

/* ================================================================
 * Data Parsing API
 * ================================================================ */
DECLSPEC_IMPORT void  BeaconDataParse(datap* parser, char* buffer, int size);
DECLSPEC_IMPORT int   BeaconDataInt(datap* parser);
DECLSPEC_IMPORT short BeaconDataShort(datap* parser);
DECLSPEC_IMPORT int   BeaconDataLength(datap* parser);
DECLSPEC_IMPORT char* BeaconDataExtract(datap* parser, int* size);

/* ================================================================
 * Output API
 * ================================================================ */
DECLSPEC_IMPORT void BeaconPrintf(int type, char* fmt, ...);
DECLSPEC_IMPORT void BeaconOutput(int type, char* data, int len);

/* ================================================================
 * Format Buffer API
 * ================================================================ */
DECLSPEC_IMPORT void  BeaconFormatAlloc(formatp* format, int maxsz);
DECLSPEC_IMPORT void  BeaconFormatReset(formatp* format);
DECLSPEC_IMPORT void  BeaconFormatFree(formatp* format);
DECLSPEC_IMPORT void  BeaconFormatAppend(formatp* format, char* text, int len);
DECLSPEC_IMPORT void  BeaconFormatPrintf(formatp* format, char* fmt, ...);
DECLSPEC_IMPORT char* BeaconFormatToString(formatp* format, int* size);
DECLSPEC_IMPORT void  BeaconFormatInt(formatp* format, int value);

/* ================================================================
 * Token / Process API (stubs in standalone loaders)
 * ================================================================ */
DECLSPEC_IMPORT void  BeaconUseToken(HANDLE token);
DECLSPEC_IMPORT void  BeaconRevertToken(void);
DECLSPEC_IMPORT BOOL  BeaconIsAdmin(void);
DECLSPEC_IMPORT void  BeaconGetSpawnTo(BOOL x86, char* buffer, int length);
DECLSPEC_IMPORT BOOL  BeaconSpawnTemporaryProcess(BOOL x86, BOOL ignoreToken,
                          STARTUPINFOA* si, PROCESS_INFORMATION* pi);
DECLSPEC_IMPORT void  BeaconInjectProcess(HANDLE hProc, int pid,
                          char* payload, int p_len, int offset,
                          char* arg, int a_len);
DECLSPEC_IMPORT void  BeaconInjectTemporaryProcess(PROCESS_INFORMATION* pi,
                          char* payload, int p_len, int offset,
                          char* arg, int a_len);
DECLSPEC_IMPORT void  BeaconCleanupProcess(PROCESS_INFORMATION* pi);

/* ================================================================
 * Utility
 * ================================================================ */
DECLSPEC_IMPORT BOOL toWideChar(char* src, wchar_t* dst, int max);

#endif /* BEACON_H_ */
