~ubuntu-branches/ubuntu/feisty/clamav/feisty-backports

« back to all changes in this revision

Viewing changes to libclamav/unrar/unrarvm.h

  • Committer: Bazaar Package Importer
  • Author(s): SpecialK
  • Date: 2008-01-04 11:25:36 UTC
  • mfrom: (19.2.4 hardy)
  • Revision ID: james.westby@ubuntu.com-20080104112536-b23litkqiv48cm9o
Tags: 0.92~dfsg-2~feisty1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Extract RAR archives
3
 
 *
4
 
 *  Copyright (C) 2005 trog@uncon.org
5
 
 *
6
 
 *  This code is based on the work of Alexander L. Roshal
7
 
 *
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.
12
 
 *
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.
17
 
 *
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,
21
 
 *  MA 02110-1301, USA.
22
 
 */
23
 
 
24
 
#ifndef _RAR_VM_
25
 
#define _RAR_VM_
26
 
 
27
 
#include "cltypes.h"
28
 
#include "unrarcmd.h"
29
 
 
30
 
#define FALSE (0)
31
 
#define TRUE (1)
32
 
#ifndef MIN
33
 
#define MIN(a,b) ((a < b) ? a : b)
34
 
#endif
35
 
 
36
 
#define RARVM_MEMSIZE   0x40000
37
 
#define RARVM_MEMMASK   (RARVM_MEMSIZE-1)
38
 
 
39
 
#define VM_GLOBALMEMADDR            0x3C000
40
 
#define VM_GLOBALMEMSIZE             0x2000
41
 
#define VM_FIXEDGLOBALSIZE               64
42
 
 
43
 
typedef enum rarvm_commands
44
 
{
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
52
 
} rarvm_commands_t;
53
 
 
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;
58
 
 
59
 
enum VM_Flags {
60
 
        VM_FC=1,
61
 
        VM_FZ=2,
62
 
        VM_FS=0x80000000
63
 
};
64
 
 
65
 
enum rarvm_op_type {
66
 
        VM_OPREG,
67
 
        VM_OPINT,
68
 
        VM_OPREGMEM,
69
 
        VM_OPNONE
70
 
};
71
 
 
72
 
struct rarvm_prepared_operand {
73
 
        enum rarvm_op_type type;
74
 
        unsigned int data;
75
 
        unsigned int base;
76
 
        unsigned int *addr;
77
 
};
78
 
 
79
 
struct rarvm_prepared_command {
80
 
        rarvm_commands_t op_code;
81
 
        int byte_mode;
82
 
        struct rarvm_prepared_operand op1, op2;
83
 
};
84
 
 
85
 
struct rarvm_prepared_program {
86
 
        rar_cmd_array_t cmd;
87
 
        struct rarvm_prepared_command *alt_cmd;
88
 
        int cmd_count;
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;
95
 
};
96
 
 
97
 
typedef struct rarvm_input_tag {
98
 
        unsigned char *in_buf;
99
 
        int buf_size;
100
 
        int in_addr;
101
 
        int in_bit;
102
 
} rarvm_input_t;
103
 
 
104
 
typedef struct rarvm_data_tag {
105
 
        uint8_t *mem;
106
 
        unsigned int R[8];
107
 
        unsigned int Flags;
108
 
} rarvm_data_t;
109
 
 
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);
121
 
#endif