4 #define VM_STANDARDFILTERS
11 #define VM_MEMSIZE 0x40000
12 #define VM_MEMMASK (VM_MEMSIZE-1)
13 #define VM_GLOBALMEMADDR 0x3C000
14 #define VM_GLOBALMEMSIZE 0x2000
15 #define VM_FIXEDGLOBALSIZE 64
19 VM_MOV, VM_CMP, VM_ADD, VM_SUB, VM_JZ, VM_JNZ, VM_INC, VM_DEC,
20 VM_JMP, VM_XOR, VM_AND, VM_OR, VM_TEST, VM_JS, VM_JNS, VM_JB,
21 VM_JBE, VM_JA, VM_JAE, VM_PUSH, VM_POP, VM_CALL, VM_RET, VM_NOT,
22 VM_SHL, VM_SHR, VM_SAR, VM_NEG, VM_PUSHA,VM_POPA, VM_PUSHF,VM_POPF,
23 VM_MOVZX,VM_MOVSX,VM_XCHG, VM_MUL, VM_DIV, VM_ADC, VM_SBB, VM_PRINT,
26 VM_MOVB, VM_MOVD, VM_CMPB, VM_CMPD,
28 VM_ADDB, VM_ADDD, VM_SUBB, VM_SUBD, VM_INCB, VM_INCD, VM_DECB, VM_DECD,
35 enum VM_StandardFilters {
36 VMSF_NONE, VMSF_E8, VMSF_E8E9, VMSF_ITANIUM, VMSF_RGB, VMSF_AUDIO,
37 VMSF_DELTA, VMSF_UPCASE
40 enum VM_Flags {VM_FC=1,VM_FZ=2,VM_FS=0x80000000};
42 enum VM_OpType {VM_OPREG,VM_OPINT,VM_OPREGMEM,VM_OPNONE};
44 struct VM_PreparedOperand
52 struct VM_PreparedCommand
56 VM_PreparedOperand Op1,Op2;
60 struct VM_PreparedProgram
62 VM_PreparedProgram() {AltCmd=NULL;}
64 Array<VM_PreparedCommand> Cmd;
65 VM_PreparedCommand *AltCmd;
68 Array<byte> GlobalData;
69 Array<byte> StaticData;
73 unsigned int FilteredDataSize;
76 class RarVM:private BitInput
79 inline uint GetValue(bool ByteMode,uint *Addr);
80 inline void SetValue(bool ByteMode,uint *Addr,uint Value);
81 inline uint* GetOperand(VM_PreparedOperand *CmdOp);
82 void PrintState(uint IP);
83 void DecodeArg(VM_PreparedOperand &Op,bool ByteMode);
85 void Optimize(VM_PreparedProgram *Prg);
87 bool ExecuteCode(VM_PreparedCommand *PreparedCode,int CodeSize);
88 #ifdef VM_STANDARDFILTERS
89 VM_StandardFilters IsStandardFilter(byte *Code,int CodeSize);
90 void ExecuteStandardFilter(VM_StandardFilters FilterType);
91 unsigned int FilterItanium_GetBits(byte *Data,int BitPos,int BitCount);
92 void FilterItanium_SetBits(byte *Data,unsigned int BitField,int BitPos,
103 void Prepare(byte *Code,int CodeSize,VM_PreparedProgram *Prg);
104 void Execute(VM_PreparedProgram *Prg);
105 void SetValue(uint *Addr,uint Value);
106 void SetMemory(unsigned int Pos,byte *Data,unsigned int DataSize);
107 static uint ReadData(BitInput &Inp);