Commit 9a83f3f7 authored by Julian Kranz's avatar Julian Kranz
Browse files

X86 Tester

- X86 Generator
parent 1c7ab7e9
......@@ -32,3 +32,7 @@ specifications/x86/c/cli-gdrr
jgdrr/.classpath
jgdrr/bin/
x86-tester/x86-generator/.cproject
x86-tester/x86-generator/.project
x86-tester/x86-generator/Debug/
/*
* generator.h
*
* Created on: Apr 29, 2013
* Author: jucs
*/
#ifndef GENERATOR_H_
#define GENERATOR_H_
#include <stdlib.h>
#include <stdint.h>
typedef size_t (generator_function_t)(uint8_t **buffer, size_t offset, size_t size);
struct generator {
generator_function_t *generate;
};
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);
#endif /* GENERATOR_H_ */
/*
* opcodes.h
*
* Created on: Apr 29, 2013
* Author: jucs
*/
#ifndef OPCODES_H_
#define OPCODES_H_
#include <stdint.h>
struct opcode_table {
size_t *offsets;
size_t offsets_length;
uint8_t *opcodes;
};
extern struct opcode_table *opcodes_opcode_table_build();
extern struct opcode_table opcodes_opcode_table_free(struct opcode_table *table);
#endif /* OPCODES_H_ */
/*
* util.h
*
* Created on: Apr 29, 2013
* Author: jucs
*/
#ifndef UTIL_H_
#define UTIL_H_
#include <stdlib.h>
#include <stdint.h>
size_t util_append_byte(uint8_t **buffer, size_t offset, size_t *size, uint8_t byte);
#endif /* UTIL_H_ */
/*
* generator.c
*
* Created on: Apr 29, 2013
* Author: jucs
*/
#include <stdlib.h>
#include <stdio.h>
#include <generator.h>
#include <util.h>
struct generator *generator_init(generator_function_t *generate) {
struct generator *generator = (struct generator*)malloc(sizeof(struct generator));
generator->generate = generate;
return generator;
}
size_t generator_x86_prefixes_generate(uint8_t **buffer, size_t offset, size_t *size) {
while(rand() > RAND_MAX/2) {
int discr = rand()%4;
switch(discr) {
case 0: {
offset = util_append_byte(buffer, offset, size, 0x66);
break;
}
case 1: {
offset = util_append_byte(buffer, offset, size, 0x67);
break;
}
case 2: {
offset = util_append_byte(buffer, offset, size, 0xf2);
break;
}
case 3: {
offset = util_append_byte(buffer, offset, size, 0xf3);
break;
}
}
}
return offset;
}
void generator_free(struct generator *generator) {
}
/*
* opcodes.c
*
* Created on: Apr 29, 2013
* Author: jucs
*/
extern struct opcode_table *opcodes_opcode_table_build() {
}
extern struct opcode_table opcodes_opcode_table_free(struct opcode_table *table) {
}
/*
* util.c
*
* Created on: Apr 29, 2013
* Author: jucs
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
size_t util_append_byte(uint8_t **buffer, size_t offset, size_t *size, uint8_t byte) {
if(offset + 1 > *size) {
*size *= 2;
*buffer = (uint8_t*)realloc(*buffer, *size);
}
(*buffer)[offset++] = byte;
return offset;
}
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