File: bytecode.h

package info (click to toggle)
jclassinfo 0.19.1-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,176 kB
  • sloc: sh: 8,551; ansic: 6,672; makefile: 199; xml: 93
file content (106 lines) | stat: -rw-r--r-- 3,057 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* libjclass - Library for reading java class files
 * Copyright (C) 2003  Nicos Panayides
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: bytecode.h,v 1.16 2003/10/23 12:41:19 anarxia Exp $
 */

#ifndef __JCLASS_BYTECODE_H__
#define __JCLASS_BYTECODE_H__

#ifdef _cplusplus
  extern "C" {
#endif 

#include <jclass/types.h>
	  
#define OP_LENGTH_UNPREDICTABLE	0x10

typedef enum {
	OP_TYPE_NONE,
	OP_TYPE_BYTE,
	OP_TYPE_UNSIGNED_BYTE,
	OP_TYPE_BYTE_ARRAY_TYPE,
	OP_TYPE_BYTE_CONSTANT_INDEX,
	OP_TYPE_UNSIGNED_BYTE_USELESS,
	OP_TYPE_SHORT,
	OP_TYPE_UNSIGNED_SHORT,
	OP_TYPE_SHORT_OFFSET,
	OP_TYPE_SHORT_CLASS_INDEX,
	OP_TYPE_SHORT_METHOD_INDEX,
	OP_TYPE_SHORT_FIELD_INDEX,
	OP_TYPE_SHORT_CONSTANT_INDEX,
	OP_TYPE_INT,
	OP_TYPE_INT_OFFSET,
	OP_TYPE_INSTRUCTION,
	OP_TYPE_TABLESWITCH,
	OP_TYPE_LOOKUPSWITCH,
	OP_TYPE_ERROR
} OperandType;

typedef enum {
	ARRAY_TYPE_BOOLEAN = 4,
	ARRAY_TYPE_CHAR,
	ARRAY_TYPE_FLOAT,
	ARRAY_TYPE_DOUBLE,
	ARRAY_TYPE_BYTE,
	ARRAY_TYPE_SHORT,
	ARRAY_TYPE_INT,
	ARRAY_TYPE_LONG
} ArrayType;

typedef struct {
	int32_t num_pairs;
	uint32_t default_target;
	int32_t low_value;
	uint32_t* target;
} TableSwitchOperand;

typedef struct {
	int32_t num_pairs;
	uint32_t default_target;
	uint32_t* value;
	uint32_t* target;
} LookupSwitchOperand;

#define MAX_LEGAL_OPCODE 201

const char* jclass_code_instruction_name(uint8_t opcode);
uint8_t jclass_code_instruction_ops(uint8_t opcode);
uint8_t jclass_code_instruction_ops_length(uint8_t opcode);
OperandType jclass_code_instruction_op_type(uint8_t opcode,
											int operand_number,
											int is_wide);

int8_t jclass_code_read_byte(uint8_t* code, uint32_t* pc);
uint8_t jclass_code_read_ubyte(uint8_t* code, uint32_t* pc);
int16_t jclass_code_read_short(uint8_t* code, uint32_t* pc);
uint16_t jclass_code_read_ushort(uint8_t* code, uint32_t* pc);
int32_t jclass_code_read_int(uint8_t* code, uint32_t* pc);
TableSwitchOperand* jclass_code_read_tableswitch(uint8_t* code, uint32_t* pc);
LookupSwitchOperand* jclass_code_read_lookupswitch(uint8_t* code, uint32_t* pc);
void jclass_code_lookupswitch_operand_free(LookupSwitchOperand* operand);
void jclass_code_tableswitch_operand_free(TableSwitchOperand* operand);

#define JCLASS_CODE_ALIGN_PC(pc) (((pc) % 4) ? (((pc) + 4) - ((pc) % 4)) : (pc))

const char* jclass_code_array_name(uint8_t array_number);

#ifdef _cplusplus
  }
#endif 

#endif