forked from sebastianbiallas/ht
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.h
208 lines (183 loc) · 5.25 KB
/
class.h
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* HT Editor
* class.h
*
* Copyright (C) 2001 Stanley Gambarin <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _CLASS_H
#define _CLASS_H
#include "htformat.h"
#include "stddata.h"
typedef unsigned char u1;
typedef unsigned int u2;
typedef unsigned long u4;
/* flags */
static const u2 jACC_PUBLIC = 0x0001;
static const u2 jACC_PRIVATE = 0x0002;
static const u2 jACC_PROTECTED = 0x0004;
static const u2 jACC_STATIC = 0x0008;
static const u2 jACC_FINAL = 0x0010;
static const u2 jACC_SUPER = 0x0020;
static const u2 jACC_SYNCHRONIZED = 0x0020;
static const u2 jACC_VOLATILE = 0x0040;
static const u2 jACC_TRANSIENT = 0x0080;
static const u2 jACC_NATIVE = 0x0100;
static const u2 jACC_INTERFACE = 0x0200;
static const u2 jACC_ABSTRACT = 0x0400;
static const u2 jACC_STRICT = 0x0800;
static const u2 jACC_JNM = 0x4000;
/* constant pool tags */
static const u1 CONSTANT_Utf8 = 1;
static const u1 CONSTANT_Integer = 3;
static const u1 CONSTANT_Float = 4;
static const u1 CONSTANT_Long = 5;
static const u1 CONSTANT_Double = 6;
static const u1 CONSTANT_Class = 7;
static const u1 CONSTANT_String = 8;
static const u1 CONSTANT_Fieldref = 9;
static const u1 CONSTANT_Methodref = 10;
static const u1 CONSTANT_InterfaceMethodref = 11;
static const u1 CONSTANT_NameAndType = 12;
struct cp_info {
u4 offset;
u1 tag;
union {
char *string;
double dval;
float fval;
sint32 ival;
uint32 llval[2];
} value;
};
static const u2 ATTRIB_ConstantValue = 1;
static const u2 ATTRIB_Code = 2;
static const u2 ATTRIB_Exceptions = 3;
static const u2 ATTRIB_InnerClasses = 4;
static const u2 ATTRIB_Synthetic = 5;
static const u2 ATTRIB_SourceFile = 6;
static const u2 ATTRIB_LineNumberTable = 7;
static const u2 ATTRIB_LocalVariableTable = 8;
static const u2 ATTRIB_Deprecated = 9;
static const u2 ATTRIB_Signature = 10;
struct exception_info {
u2 start_pc;
u2 end_pc;
u2 handler_pc;
u2 catch_type;
};
struct attrib_info {
u4 offset;
u2 tag;
u2 name;
u4 len;
union {
struct {
u2 max_stack;
u2 max_locals;
u4 len;
u4 start;
u2 exctbl_len;
exception_info *exctbl;
} code;
u2 signature;
};
};
/* mf_info */
struct mf_info {
u4 offset;
u2 flags;
char *name;
char *desc;
u2 attribs_count;
attrib_info **attribs;
};
/* classfile */
struct classfile {
u4 offset;
u4 magic;
u2 minor_version;
u2 major_version;
u2 cpool_count;
cp_info **cpool;
u4 coffset;
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 *interfaces;
u4 foffset;
u2 fields_count;
mf_info **fields;
u4 moffset;
u2 methods_count;
mf_info **methods;
u4 aoffset;
u2 attribs_count;
attrib_info **attribs;
};
struct ht_class_shared_data {
Container *methods;
Container *fields;
classfile *file;
Area *valid;
Area *initialized;
int flags;
struct {
char *thisclass;
char *superclass;
Container *interfaces;
} classinfo;
};
extern ht_class_shared_data *class_read(File *);
extern void class_unread(ht_class_shared_data *);
extern attrib_info *attribute_read(Stream *, classfile *);
int token_translate(char *buf, int maxlen, uint32 token, ht_class_shared_data *shared);
void java_demangle(char *result, const char *classname, const char *name, const char *type, int flags);
void java_demangle_field(char *result, const char *name, const char *type, int flags);
char *java_demangle_flags(char *result, int flags);
class cview: public ht_format_group {
public:
void init(Bounds *, File *, format_viewer_if **, ht_format_group *, FileOfs, void *shared);
virtual void done();
};
#define ClassAddress uint32
class ClassMethod: public Object {
public:
const char *name;
const char *type;
ClassAddress start;
uint length;
int flags;
int exctbl_len;
exception_info *exctbl;
ClassMethod(char *name, char *type, ClassAddress start, uint length, int flags,
int exctbl_len, exception_info *exctbl);
virtual int compareTo(const Object *obj) const;
void addsig(const char *s) { type = s; }
};
class ClassField: public Object {
public:
const char *name;
const char *type;
int flags;
ClassField(char *name, char *type, int flags);
void addsig(const char *s) { type = s; }
};
#define DESC_JAVA "java - class file"
#define DESC_JAVA_HEADERS "java/headers"
#define DESC_JAVA_IMAGE "java/image"
extern format_viewer_if htcls_if;
#endif /* _CLASS_H */