4
* Copyright (C) 2005 trog@uncon.org
6
* This code is based on the work of Alexander L. Roshal
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
33
#define MIN(a,b) ((a < b) ? a : b)
36
#define RARVM_MEMSIZE 0x40000
37
#define RARVM_MEMMASK (RARVM_MEMSIZE-1)
39
#define VM_GLOBALMEMADDR 0x3C000
40
#define VM_GLOBALMEMSIZE 0x2000
41
#define VM_FIXEDGLOBALSIZE 64
43
typedef enum rarvm_commands
45
VM_MOV, VM_CMP, VM_ADD, VM_SUB, VM_JZ, VM_JNZ, VM_INC, VM_DEC,
46
VM_JMP, VM_XOR, VM_AND, VM_OR, VM_TEST, VM_JS, VM_JNS, VM_JB,
47
VM_JBE, VM_JA, VM_JAE, VM_PUSH, VM_POP, VM_CALL, VM_RET, VM_NOT,
48
VM_SHL, VM_SHR, VM_SAR, VM_NEG, VM_PUSHA,VM_POPA, VM_PUSHF,VM_POPF,
49
VM_MOVZX,VM_MOVSX,VM_XCHG, VM_MUL, VM_DIV, VM_ADC, VM_SBB, VM_PRINT,
50
VM_MOVB, VM_MOVD, VM_CMPB, VM_CMPD, VM_ADDB, VM_ADDD, VM_SUBB, VM_SUBD,
51
VM_INCB, VM_INCD, VM_DECB, VM_DECD, VM_NEGB, VM_NEGD, VM_STANDARD
54
typedef enum rarvm_standard_filters {
55
VMSF_NONE, VMSF_E8, VMSF_E8E9, VMSF_ITANIUM, VMSF_RGB, VMSF_AUDIO,
56
VMSF_DELTA, VMSF_UPCASE
57
} rarvm_standard_filters_t;
72
struct rarvm_prepared_operand {
73
enum rarvm_op_type type;
79
struct rarvm_prepared_command {
80
rarvm_commands_t op_code;
82
struct rarvm_prepared_operand op1, op2;
85
struct rarvm_prepared_program {
87
struct rarvm_prepared_command *alt_cmd;
89
unsigned char *global_data;
90
unsigned char *static_data;
91
long global_size, static_size;
92
unsigned int init_r[7];
93
uint8_t *filtered_data;
94
unsigned int filtered_data_size;
97
typedef struct rarvm_input_tag {
98
unsigned char *in_buf;
104
typedef struct rarvm_data_tag {
110
unsigned int rarvm_getbits(rarvm_input_t *rarvm_input);
111
void rarvm_addbits(rarvm_input_t *rarvm_input, int bits);
112
int rarvm_init(rarvm_data_t *rarvm_data);
113
void rarvm_free(rarvm_data_t *rarvm_data);
114
int rarvm_prepare(rarvm_data_t *rarvm_data, rarvm_input_t *rarvm_input, unsigned char *code,
115
int code_size, struct rarvm_prepared_program *prg);
116
void rarvm_set_memory(rarvm_data_t *rarvm_data, unsigned int pos, uint8_t *data, unsigned int data_size);
117
int rarvm_execute(rarvm_data_t *rarvm_data, struct rarvm_prepared_program *prg);
118
void rarvm_set_value(int byte_mode, unsigned int *addr, unsigned int value);
119
unsigned int rarvm_read_data(rarvm_input_t *rarvm_input);
120
uint32_t rar_crc(uint32_t start_crc, void *addr, uint32_t size);