/*
 * beacon_compatibility.h -- Beacon API compatibility layer declarations
 * Step 03: Struct typedefs, callback constants, and function prototypes
 *          for the standalone Beacon API implementation.
 *
 * This header is included by the LOADER (not the BOF).
 * It declares the functions that the loader implements to satisfy
 * the BOF's Beacon API calls.
 */

#ifndef BEACON_COMPATIBILITY_H_
#define BEACON_COMPATIBILITY_H_

#include <windows.h>
#include <stdint.h>

/* ================================================================
 * Callback type constants (same as in beacon.h)
 * ================================================================ */
#define CALLBACK_OUTPUT      0x00
#define CALLBACK_OUTPUT_OEM  0x1e
#define CALLBACK_ERROR       0x0d
#define CALLBACK_OUTPUT_UTF8 0x20

/* ================================================================
 * Data structures (same as in beacon.h)
 * ================================================================ */
typedef struct {
    char* original;
    char* buffer;
    int   length;
    int   size;
} datap;

typedef struct {
    char* original;
    char* buffer;
    int   length;
    int   size;
} formatp;

/* ================================================================
 * InternalFunctions table
 *
 * 30-slot array mapping Beacon API function names to pointers.
 * Each entry is: { "FunctionName", function_pointer }
 * process_symbol() looks up names in this table during relocation.
 * ================================================================ */
extern unsigned char* InternalFunctions[30][2];

/* ================================================================
 * Beacon API function prototypes (implemented in beacon_compatibility.c)
 * ================================================================ */

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

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

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

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

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

/* Output retrieval (standalone loader only) */
char* BeaconGetOutputData(int* outsize);

#endif /* BEACON_COMPATIBILITY_H_ */
