Begin code generator.
This commit is contained in:
28
vuln.c
28
vuln.c
@@ -9,9 +9,9 @@
|
|||||||
|
|
||||||
#define MAX_PROGRAM_LEN 0x1000
|
#define MAX_PROGRAM_LEN 0x1000
|
||||||
|
|
||||||
typedef enum Opcode : uint8_t { COUNT_OPCODES } Opcode;
|
typedef enum Opcode : uint8_t { ADD = 1, SHIFT = 2, MOV = 3, COUNT_OPCODES } Opcode;
|
||||||
|
|
||||||
typedef enum Register : uint8_t { COUNT_REGISTERS } Register;
|
typedef enum Register : uint8_t { A = 0, B = 1, C = 2, D = 3, E = 4, F = 5, COUNT_REGISTERS } Register;
|
||||||
|
|
||||||
typedef struct Instruction {
|
typedef struct Instruction {
|
||||||
Opcode opcode;
|
Opcode opcode;
|
||||||
@@ -20,7 +20,6 @@ typedef struct Instruction {
|
|||||||
|
|
||||||
typedef int (*exec_func_t)();
|
typedef int (*exec_func_t)();
|
||||||
|
|
||||||
|
|
||||||
static __attribute__((unused)) bool premium_activated = false;
|
static __attribute__((unused)) bool premium_activated = false;
|
||||||
|
|
||||||
size_t get_size_t(size_t limit) {
|
size_t get_size_t(size_t limit) {
|
||||||
@@ -91,9 +90,26 @@ void exec_code(uint8_t *code) {
|
|||||||
_exit(res);
|
_exit(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gen_code(uint8_t *code, Instruction *program) {
|
void write_instr(uint8_t *code, size_t offset, const uint8_t *instr, size_t instr_len) {
|
||||||
(void)code;
|
for (size_t i = 0; i < instr_len; ++i) {
|
||||||
(void)program;
|
code[offset + i] = instr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gen_code(uint8_t *code, Instruction *program, size_t program_len) {
|
||||||
|
Register cur_reg;
|
||||||
|
size_t acc;
|
||||||
|
for (size_t pc = 0; pc < program_len; ++pc) {
|
||||||
|
switch (program[pc].opcode) {
|
||||||
|
case ADD:
|
||||||
|
if (program[pc].reg == cur_reg) {
|
||||||
|
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
puts("Found invalid instruction!");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_jit(Instruction *program, size_t len) {
|
int run_jit(Instruction *program, size_t len) {
|
||||||
|
|||||||
Reference in New Issue
Block a user