mirror of
https://github.com/youssefnoob003/SindriKit
synced 2026-07-07 21:57:09 +00:00
aea2eb6cfb
- Implement complete cross-process injection engine via snd_inj_ctx_t - Track explicit remote_entry_point for safe thread hijacking and PE execution - Refactor standalone syscall resolvers into a unified pipeline (scan/sort) - Perfect status code system by purging generic fallbacks in favor of highly-specific, domain-aware error codes - Fix minor pointer validation and parsing bugs in the reflective loader
191 lines
6.0 KiB
C
191 lines
6.0 KiB
C
#ifndef SND_COMMON_STATUS_H
|
|
#define SND_COMMON_STATUS_H
|
|
|
|
#if SND_DEBUG
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#endif
|
|
|
|
#include <sindri/common/macros.h>
|
|
|
|
SND_BEGIN_EXTERN_C
|
|
|
|
// Maximum length for error context strings (including null terminator)
|
|
#define SND_MAX_CTX_LEN 128
|
|
#define SND_FAILED(x) (x.code != SND_SUCCESS)
|
|
#define SND_SUCCEEDED(x) (x.code == SND_SUCCESS)
|
|
|
|
typedef enum _SND_STATUS_CODE {
|
|
SND_SUCCESS = 0,
|
|
SND_ERROR_GENERIC = -1,
|
|
SND_STATUS_NULL_POINTER = -2,
|
|
SND_STATUS_INTEGER_OVERFLOW = -3,
|
|
SND_STATUS_UNSUPPORTED = -4,
|
|
SND_STATUS_NOT_INITIALIZED = -5,
|
|
SND_STATUS_BUFFER_TOO_SMALL = -6,
|
|
|
|
// Core Engine Execution Errors
|
|
SND_STATUS_TOO_MANY_ARGUMENTS = 0x50,
|
|
SND_STATUS_NTDLL_NOT_INITIALIZED,
|
|
SND_STATUS_RESOLVER_NOT_INITIALIZED,
|
|
SND_STATUS_OM_NOT_INITIALIZED,
|
|
SND_STATUS_PIPELINE_EXHAUSTED,
|
|
|
|
// Command-line argument errors
|
|
SND_STATUS_MISSING_COMMAND_LINE_ARGS = 0x100,
|
|
SND_STATUS_INVALID_COMMAND_LINE_ARG,
|
|
|
|
// File / input errors
|
|
SND_STATUS_INVALID_PATH = 0x200,
|
|
SND_STATUS_FILE_CREATE_FAILED,
|
|
SND_STATUS_FILE_SIZE_QUERY_FAILED,
|
|
SND_STATUS_FILE_TOO_LARGE,
|
|
SND_STATUS_FILE_TOO_SMALL,
|
|
SND_STATUS_ALLOC_FAILED,
|
|
SND_STATUS_FILE_READ_FAILED,
|
|
|
|
// PE parsing / validation errors
|
|
SND_STATUS_DOS_HEADER_TRUNCATED = 0x300,
|
|
SND_STATUS_INVALID_DOS_SIGNATURE,
|
|
SND_STATUS_NT_HEADERS_TRUNCATED,
|
|
SND_STATUS_INVALID_NT_SIGNATURE,
|
|
SND_STATUS_INVALID_NT_HEADER_OFFSET,
|
|
SND_STATUS_UNSUPPORTED_OPTIONAL_HEADER_MAGIC,
|
|
SND_STATUS_INVALID_SECTION_COUNT,
|
|
SND_STATUS_SECTION_TABLE_OVERFLOW,
|
|
SND_STATUS_INVALID_SECTION_TABLE,
|
|
SND_STATUS_ARCH_MISMATCH,
|
|
SND_STATUS_ENTRY_POINT_NOT_FOUND,
|
|
SND_STATUS_INVALID_IMPORT_TABLE_SIZE,
|
|
SND_STATUS_INVALID_FILE_OFFSET,
|
|
SND_STATUS_DIRECTORY_NOT_FOUND,
|
|
SND_STATUS_CORRUPTED_STATE,
|
|
SND_STATUS_IMAGE_NOT_MAPPED,
|
|
|
|
// Reflective loading errors
|
|
SND_STATUS_SECTION_COPY_FAILED = 0x400,
|
|
SND_STATUS_RELOCATION_DIRECTORY_INVALID,
|
|
SND_STATUS_RELOCATION_PATCH_OUT_OF_RANGE,
|
|
SND_STATUS_RELOCATION_TYPE_UNSUPPORTED,
|
|
SND_STATUS_IMPORT_DIRECTORY_INVALID,
|
|
SND_STATUS_IMPORT_DLL_LOAD_FAILED,
|
|
SND_STATUS_IMPORT_THUNK_INVALID,
|
|
SND_STATUS_IMPORT_SYMBOL_RESOLVE_FAILED,
|
|
SND_STATUS_PROTECTION_UPDATE_FAILED,
|
|
SND_STATUS_DLL_INITIALIZATION_FAILED,
|
|
SND_STATUS_EXPORT_DIRECTORY_INVALID,
|
|
SND_STATUS_EXPORT_NOT_FOUND,
|
|
SND_STATUS_EXPORT_FORWARDER_UNSUPPORTED,
|
|
SND_STATUS_MISSING_DLL_EXPORT_NAME,
|
|
SND_STATUS_INVALID_STAGE_SEQUENCE,
|
|
SND_FAILED_TO_EXECUTE,
|
|
SND_STATUS_LOCAL_EXECUTION_BLOCKED,
|
|
|
|
// Syscall resolution errors
|
|
SND_STATUS_SSN_NOT_FOUND = 0x500,
|
|
|
|
// PEB
|
|
SND_STATUS_PEB_MODULE_NOT_FOUND = 0x600,
|
|
SND_STATUS_PEB_PROCESS_PARAMETERS_NOT_FOUND,
|
|
|
|
// OS errors
|
|
SND_STATUS_MODULE_NOT_FOUND = 0x800,
|
|
SND_STATUS_SECTION_OPEN_FAILED,
|
|
SND_STATUS_SECTION_MAP_FAILED,
|
|
SND_STATUS_HANDLE_CLOSE_FAILED,
|
|
SND_STATUS_PROCESS_OPEN_FAILED,
|
|
SND_STATUS_VIRTUAL_ALLOC_FAILED,
|
|
SND_STATUS_VIRTUAL_WRITE_FAILED,
|
|
SND_STATUS_VIRTUAL_PROTECT_FAILED,
|
|
SND_STATUS_THREAD_CREATE_FAILED,
|
|
SND_STATUS_VIRTUAL_FREE_FAILED,
|
|
|
|
// Remote process errors
|
|
SND_STATUS_ACCESS_DENIED = 0x900,
|
|
SND_STATUS_INVALID_PAYLOAD,
|
|
SND_STATUS_INVALID_INJECTION_TARGET,
|
|
} snd_status_code_t;
|
|
|
|
typedef struct _SND_STATUS {
|
|
snd_status_code_t code;
|
|
int os_error;
|
|
#if SND_DEBUG
|
|
const char *file;
|
|
int line;
|
|
char context[SND_MAX_CTX_LEN];
|
|
#endif
|
|
} snd_status_t;
|
|
|
|
#if SND_DEBUG
|
|
|
|
static inline snd_status_t _snd_make_err(snd_status_code_t code, int os_error, const char *file, int line,
|
|
const char *fmt, ...) {
|
|
snd_status_t status = {code, os_error, file, line};
|
|
|
|
if (fmt != NULL) {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
vsnprintf(status.context, SND_MAX_CTX_LEN, fmt, args);
|
|
va_end(args);
|
|
} else {
|
|
status.context[0] = '\0';
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
static inline snd_status_t _snd_make_success() {
|
|
snd_status_t status = {SND_SUCCESS, 0, NULL, 0, {0}};
|
|
|
|
return status;
|
|
}
|
|
|
|
#define SND_OK _snd_make_success()
|
|
#define SND_ERR(c) _snd_make_err(c, 0, __FILE__, __LINE__, NULL)
|
|
#define SND_ERR_CTX(c, ...) _snd_make_err(c, 0, __FILE__, __LINE__, __VA_ARGS__)
|
|
#define SND_ERR_W32(code) _snd_make_err(code, GetLastError(), __FILE__, __LINE__, NULL)
|
|
#define SND_ERR_W32_CTX(code, ...) _snd_make_err(code, GetLastError(), __FILE__, __LINE__, __VA_ARGS__)
|
|
#define SND_ERR_NT(code, nt_status) _snd_make_err(code, nt_status, __FILE__, __LINE__, NULL)
|
|
#define SND_ERR_NT_CTX(code, nt_status, ...) _snd_make_err(code, nt_status, __FILE__, __LINE__, __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
static inline snd_status_t _snd_make_success() {
|
|
snd_status_t status = {SND_SUCCESS, 0};
|
|
|
|
return status;
|
|
}
|
|
|
|
static inline snd_status_t _snd_make_err(snd_status_code_t code, int os_error) {
|
|
snd_status_t status = {code, os_error};
|
|
|
|
return status;
|
|
}
|
|
|
|
#define SND_OK _snd_make_success()
|
|
#define SND_ERR(code) _snd_make_err(code, 0)
|
|
#define SND_ERR_CTX(code, ...) _snd_make_err(code, 0)
|
|
#define SND_ERR_W32(code) _snd_make_err(code, GetLastError())
|
|
#define SND_ERR_W32_CTX(code, ...) _snd_make_err(code, GetLastError())
|
|
#define SND_ERR_NT(code, nt_status) _snd_make_err(code, nt_status)
|
|
#define SND_ERR_NT_CTX(code, nt_status, ...) _snd_make_err(code, nt_status)
|
|
|
|
#endif
|
|
|
|
/**
|
|
* @brief Converts a status structure into a human-readable string.
|
|
* @param status The status object to evaluate.
|
|
* @return Null-terminated string describing the status code.
|
|
*/
|
|
const char *snd_status_to_string(snd_status_t status);
|
|
|
|
/**
|
|
* @brief Prints a status structure, including context if available, to stderr.
|
|
* @param status The status object to print.
|
|
*/
|
|
void snd_status_print(snd_status_t status);
|
|
|
|
SND_END_EXTERN_C
|
|
|
|
#endif // SND_COMMON_STATUS_H
|