Added sbpl_compiler_wrapper

This commit is contained in:
Karmaz95
2024-07-09 18:21:39 +02:00
parent 8b02698095
commit 51b994cc7b
4 changed files with 3091 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ Each article directory contains three subdirectories:
* ☑ [VI. AMFI](https://karol-mazurek.medium.com/snake-apple-vi-amfi-31c48fb92d33?sk=v2%2F8116bf86-e0a7-42be-ada9-5348447c01fd)
* ☑ [VII. Antivirus](https://karol-mazurek.medium.com/snake-apple-vii-antivirus-0a57acc10185?sk=v2%2F2c46d7ac-4435-41e6-bbda-2acb4eb78c76)
* ☐ [VIII. Sandbox]()
* ☑ [SBPL Compilator](https://karol-mazurek.medium.com/sbpl-compilator-c05f5304d057?sk=v2%2F4ae3bf90-ff12-4fea-b0fc-0f2ef60d7b93)
* ☐ [IX. TCC]()
* ☐ [X. NU]()
* ☑ [Kernel Debugging Setup on MacOS](https://karol-mazurek.medium.com/kernel-debugging-setup-on-macos-07dd8c86cdb6?sk=v2%2F782bf539-a057-4f14-bbe7-f8e1ace26701)

View File

@@ -0,0 +1,44 @@
// clang -o sbpl_compiler_wrapper sbpl_compiler_wrapper.c -lsandbox
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Define a struct to hold the compiled sandbox profile
struct compiled_sbp {
int64_t field_0; // unknown, maybe type?
void * data; // pointer to the compiled sandbox profile
size_t size; // size of the compiled sandbox profile
};
// Declare the sandbox_compile_file function
struct compiled_sbp *sandbox_compile_file(const char *inputPath, __int64_t a2, char **error_msg);
int main(int argc, char *argv[]) {
if (argc < 3) {
fprintf(stderr, "Usage: %s input_sb output_bin\n", argv[0]);
return 1;
}
// Get the full path of the input file so we skip the sandbox_compile_file relative path check
char *inputPath = realpath(argv[1], NULL);
if (!inputPath) {
perror("Failed to resolve input file path");
return 1;
}
const char *outputPath = argv[2];
// Declare variables to store the compiled sandbox profile and error message
char *error_msg = NULL;
struct compiled_sbp *compiled_file = NULL;
// Call sandbox_compile_file
compiled_file = sandbox_compile_file(inputPath, 0, &error_msg);
// Write result (bytecode) to output file
FILE *outputFile = fopen(outputPath, "wb");
if (!outputFile) {
perror("Failed to open output file");
return 1;
}
size_t bytesWritten = fwrite(compiled_file->data, 1, compiled_file->size, outputFile);
if (bytesWritten != compiled_file->size) {
fprintf(stderr, "Failed to write all bytecode to output file\n");
}
fclose(outputFile);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1 +1 @@
../VII. Antivirus/python/CrimsonUroboros.py
../VIII. Sandbox/python/CrimsonUroboros.py