Commit b3bcf84e authored by Julian Kranz's avatar Julian Kranz
Browse files

X86 Tester

- X86 Generator
parent 271b1088
......@@ -10,16 +10,43 @@
#include <stdlib.h>
#include <stdint.h>
#include <opcodes.h>
typedef size_t (generator_function_t)(uint8_t **buffer, size_t offset, size_t size);
typedef size_t (generator_function_t)(uint8_t **buffer, size_t offset,
size_t size);
struct generator {
enum generator_type {
GENERATOR_TYPE_PREFIXES,
GENERATOR_TYPE_OPCODE,
GENERATOR_TYPE_MODRM,
GENERATOR_TYPE_IMMEDIATE,
GENERATOR_TYPE_REX,
GENERATOR_TYPE_VEX
};
struct generator {
void *data;
generator_function_t *generate;
};
struct generator_opcodes_data {
struct opcode_table *table;
};
extern struct generator *generator_init(generator_function_t *generate);
extern size_t generator_x86_prefixes_generate(uint8_t **buffer, size_t offset, size_t *size);
extern void generator_free(struct generator *generator);
extern size_t generator_x86_prefixes_generate(uint8_t **buffer, size_t offset,
size_t *size);
extern size_t generator_x86_opcode_generate(uint8_t **buffer, size_t offset,
size_t *size);
extern size_t generator_x86_modrm_generate(uint8_t **buffer, size_t offset,
size_t *size);
extern size_t generator_x86_immediate_generate(uint8_t **buffer, size_t offset,
size_t *size);
extern size_t generator_x86_rex_generate(uint8_t **buffer, size_t offset,
size_t *size);
extern size_t generator_x86_vex_generate(uint8_t **buffer, size_t offset,
size_t *size);
#endif /* GENERATOR_H_ */
/*
* generator_tree.h
*
* Created on: 30.04.2013
* Author: jucs
*/
#ifndef GENERATOR_TREE_H_
#define GENERATOR_TREE_H_
#include <stdlib.h>
#include <generator.h>
enum generator_tree_node_type {
GENERATOR_TREE_NODE_TYPE_BRANCH, GENERATOR_TREE_NODE_TYPE_GENERATOR
};
struct generator_tree_node;
struct generator_tree_wbranch {
struct generator_tree_node *node;
uint8_t weight;
};
struct generator_tree_node {
enum generator_tree_node_type type;
union {
struct {
struct generator_tree_wbranch *branches;
size_t branches_length;
};
struct {
struct generator *generator;
struct generator_tree_node *next;
};
};
};
extern struct generator_tree_node *generator_tree_generator_build(
struct generator *generator, struct generator_tree_node *child);
extern struct generator_tree_node *generator_tree_branch(size_t branches_length,
...);
#endif /* GENERATOR_TREE_H_ */
/*
* generator_tree.c
*
* Created on: 30.04.2013
* Author: jucs
*/
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <generator_tree.h>
struct generator_tree_node *generator_tree_generator_build(
struct generator *generator, struct generator_tree_node *child) {
struct generator_tree_node *node = (struct generator_tree_node *)malloc(
sizeof(struct generator_tree_node));
node->type = GENERATOR_TREE_NODE_TYPE_GENERATOR;
node->generator = generator;
node->next = child;
return node;
}
struct generator_tree_node *generator_tree_branch(size_t branches_length, ...) {
struct generator_tree_node *node = (struct generator_tree_node *)malloc(
sizeof(struct generator_tree_node));
node->type = GENERATOR_TREE_NODE_TYPE_BRANCH;
node->branches_length = branches_length;
node->branches = (struct generator_tree_wbranch*)malloc(
branches_length * sizeof(struct generator_tree_wbranch));
va_list a_list;
va_start(a_list, branches_length);
for(int i = 0; i < branches_length; ++i) {
struct generator_tree_node *node =
va_arg(a_list, struct generator_tree_node *);
uint8_t weight = va_arg(a_list, uint8_t);
node->branches[i].node = node;
node->branches[i].weight = weight;
}
va_end(a_list);
return node;
}
......@@ -3114,5 +3114,9 @@ extern struct opcode_table *opcodes_opcode_table_build() {
}
extern void opcodes_opcode_table_free(struct opcode_table *table) {
if(table) {
free(table->offsets);
free(table->opcodes);
free(table);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment