6
|
1 |
Object subclass:#JavaDecompiler
|
18
|
2 |
instanceVariableNames:'code pc javaMethod outStream classToCompileFor'
|
6
|
3 |
classVariableNames:'DecoderTable'
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Java-Support'
|
|
6 |
!
|
|
7 |
|
|
8 |
|
129
|
9 |
!JavaDecompiler class methodsFor:'initialization'!
|
6
|
10 |
|
|
11 |
initialize
|
|
12 |
DecoderTable := #(
|
|
13 |
(nop) "/ 0
|
|
14 |
(aconst_null) "/ 1
|
|
15 |
(iconst_m1) "/ 2
|
|
16 |
(iconst_0) "/ 3
|
|
17 |
(iconst_1) "/ 4
|
|
18 |
(iconst_2) "/ 5
|
|
19 |
(iconst_3) "/ 6
|
|
20 |
(iconst_4) "/ 7
|
|
21 |
(iconst_5) "/ 8
|
|
22 |
(lconst_0) "/ 9
|
|
23 |
|
|
24 |
(lconst_1) "/ 10
|
|
25 |
(fconst_0) "/ 11
|
|
26 |
(fconst_1) "/ 12
|
|
27 |
(fconst_2) "/ 13
|
|
28 |
(dconst_0) "/ 14
|
|
29 |
(dconst_1) "/ 15
|
|
30 |
(bipush signedByte) "/ 16
|
|
31 |
(sipush signedShort) "/ 17
|
|
32 |
(ldc1 constIndexByte) "/ 18
|
|
33 |
(ldc2 constIndexShort) "/ 19
|
|
34 |
|
|
35 |
(ldc2w constIndexShort) "/ 20
|
|
36 |
(iload localIndexByte) "/ 21
|
|
37 |
(lload localIndexByte) "/ 22
|
|
38 |
(fload localIndexByte) "/ 23
|
|
39 |
(dload localIndexByte) "/ 24
|
|
40 |
(aload localIndexByte) "/ 25
|
24
|
41 |
(iload_0) "/ 26
|
6
|
42 |
(iload_1) "/ 27
|
|
43 |
(iload_2) "/ 28
|
|
44 |
(iload_3) "/ 29
|
|
45 |
|
|
46 |
(lload_0) "/ 30
|
|
47 |
(lload_1) "/ 31
|
|
48 |
(lload_2) "/ 32
|
|
49 |
(lload_3) "/ 33
|
|
50 |
(fload_0) "/ 34
|
|
51 |
(fload_1) "/ 35
|
|
52 |
(fload_2) "/ 36
|
|
53 |
(fload_3) "/ 37
|
|
54 |
(dload_0) "/ 38
|
|
55 |
(dload_1) "/ 39
|
|
56 |
|
|
57 |
(dload_2) "/ 40
|
|
58 |
(dload_3) "/ 41
|
|
59 |
(aload_0) "/ 42
|
|
60 |
(aload_1) "/ 43
|
|
61 |
(aload_2) "/ 44
|
|
62 |
(aload_3) "/ 45
|
|
63 |
(iaload) "/ 46
|
|
64 |
(laload) "/ 47
|
|
65 |
(faload) "/ 48
|
|
66 |
(daload) "/ 49
|
|
67 |
|
|
68 |
(aaload) "/ 50
|
|
69 |
(baload) "/ 51
|
|
70 |
(caload) "/ 52
|
|
71 |
(saload) "/ 53
|
|
72 |
(istore localIndexByte) "/ 54
|
|
73 |
(lstore localIndexByte) "/ 55
|
|
74 |
(fstore localIndexByte) "/ 56
|
|
75 |
(dstore localIndexByte) "/ 57
|
|
76 |
(astore localIndexByte) "/ 58
|
|
77 |
(istore_0) "/ 59
|
|
78 |
|
|
79 |
(istore_1) "/ 60
|
|
80 |
(istore_2) "/ 61
|
|
81 |
(istore_3) "/ 62
|
|
82 |
(lstore_0) "/ 63
|
|
83 |
(lstore_1) "/ 64
|
|
84 |
(lstore_2) "/ 65
|
|
85 |
(lstore_3) "/ 66
|
|
86 |
(fstore_0) "/ 67
|
|
87 |
(fstore_1) "/ 68
|
|
88 |
(fstore_2) "/ 69
|
|
89 |
|
|
90 |
(fstore_3) "/ 70
|
|
91 |
(dstore_0) "/ 71
|
|
92 |
(dstore_1) "/ 72
|
|
93 |
(dstore_2) "/ 73
|
|
94 |
(dstore_3) "/ 74
|
|
95 |
(astore_0) "/ 75
|
|
96 |
(astore_1) "/ 76
|
|
97 |
(astore_2) "/ 77
|
|
98 |
(astore_3) "/ 78
|
|
99 |
(iastore) "/ 79
|
|
100 |
|
|
101 |
(lastore) "/ 80
|
|
102 |
(fastore) "/ 81
|
|
103 |
(dastore) "/ 82
|
|
104 |
(aastore) "/ 83
|
|
105 |
(bastore) "/ 84
|
|
106 |
(castore) "/ 85
|
|
107 |
(sastore) "/ 86
|
|
108 |
(pop) "/ 87
|
|
109 |
(pop2) "/ 88
|
|
110 |
(dup) "/ 89
|
|
111 |
|
|
112 |
(dup_x1) "/ 90
|
|
113 |
(dup_x2) "/ 91
|
|
114 |
(dup2) "/ 92
|
|
115 |
(dup2_x1) "/ 93
|
|
116 |
(dup2_x2) "/ 94
|
|
117 |
(swap) "/ 95
|
|
118 |
(iadd) "/ 96
|
|
119 |
(ladd) "/ 97
|
|
120 |
(fadd) "/ 98
|
|
121 |
(dadd) "/ 99
|
|
122 |
|
|
123 |
(isub) "/ 100
|
|
124 |
(lsub) "/ 101
|
|
125 |
(fsub) "/ 102
|
|
126 |
(dsub) "/ 103
|
|
127 |
(imul) "/ 104
|
|
128 |
(lmul) "/ 105
|
|
129 |
(fmul) "/ 106
|
|
130 |
(dmul) "/ 107
|
|
131 |
(idiv) "/ 108
|
|
132 |
(ldiv) "/ 109
|
|
133 |
|
|
134 |
(fdiv) "/ 110
|
|
135 |
(ddiv) "/ 111
|
91
|
136 |
"/ (imod) "/ 112 "/ obsolete
|
|
137 |
(irem) "/ 112
|
|
138 |
"/ (lmod) "/ 113 "/ obsolete
|
|
139 |
(lrem) "/ 113
|
|
140 |
"/ (fmod) "/ 114 "/ obsolete
|
|
141 |
(frem) "/ 114
|
|
142 |
"/ (dmod) "/ 115 "/ obsolete
|
|
143 |
(drem) "/ 115
|
6
|
144 |
(ineg) "/ 116
|
|
145 |
(lneg) "/ 117
|
|
146 |
(fneg) "/ 118
|
|
147 |
(dneg) "/ 119
|
|
148 |
|
|
149 |
(ishl) "/ 120
|
|
150 |
(lshl) "/ 121
|
|
151 |
(ishr) "/ 122
|
|
152 |
(lshr) "/ 123
|
|
153 |
(iushr) "/ 124
|
|
154 |
(lushr) "/ 125
|
|
155 |
(iand) "/ 126
|
|
156 |
(land) "/ 127
|
|
157 |
(ior) "/ 128
|
|
158 |
(lor) "/ 129
|
|
159 |
|
|
160 |
(ixor) "/ 130
|
|
161 |
(lxor) "/ 131
|
39
|
162 |
(iinc localIndexByte signedByte) "/ 132
|
68
|
163 |
(i2l) "/ 133
|
44
|
164 |
(i2f) "/ 134
|
52
|
165 |
(i2d) "/ 135
|
44
|
166 |
(l2i) "/ 136
|
6
|
167 |
(l2f) "/ 137
|
|
168 |
(l2d) "/ 138
|
44
|
169 |
(f2i) "/ 139
|
6
|
170 |
|
|
171 |
(f2l) "/ 140
|
|
172 |
(f2d) "/ 141
|
|
173 |
(d2i) "/ 142
|
|
174 |
(d2l) "/ 143
|
|
175 |
(d2f) "/ 144
|
|
176 |
(int2byte) "/ 145
|
|
177 |
(int2char) "/ 146
|
|
178 |
(int2short) "/ 147
|
|
179 |
(lcmp) "/ 148
|
|
180 |
(fcmpl) "/ 149
|
|
181 |
|
|
182 |
(fcmpg) "/ 150
|
|
183 |
(dcmpl) "/ 151
|
|
184 |
(dcmpg) "/ 152
|
|
185 |
(ifeq signedBranchShort) "/ 153
|
|
186 |
(ifne signedBranchShort) "/ 154
|
|
187 |
(iflt signedBranchShort) "/ 155
|
|
188 |
(ifge signedBranchShort) "/ 156
|
|
189 |
(ifgt signedBranchShort) "/ 157
|
|
190 |
(ifle signedBranchShort) "/ 158
|
|
191 |
(if_icmpeq signedBranchShort) "/ 159
|
|
192 |
|
|
193 |
(if_icmpne signedBranchShort) "/ 160
|
|
194 |
(if_icmplt signedBranchShort) "/ 161
|
|
195 |
(if_icmpge signedBranchShort) "/ 162
|
|
196 |
(if_icmpgt signedBranchShort) "/ 163
|
|
197 |
(if_icmple signedBranchShort) "/ 164
|
|
198 |
(if_acmpeq signedBranchShort) "/ 165
|
|
199 |
(if_acmpne signedBranchShort) "/ 166
|
|
200 |
(goto signedBranchShort) "/ 167
|
|
201 |
(jsr signedBranchShort) "/ 168
|
|
202 |
(ret localIndexByte) "/ 169
|
|
203 |
|
|
204 |
(tableswitch tableSwitchBytes) "/ 170
|
|
205 |
(lookupswitch lookupSwitchBytes) "/ 171
|
|
206 |
(ireturn) "/ 172
|
|
207 |
(lreturn) "/ 173
|
|
208 |
(freturn) "/ 174
|
|
209 |
(dreturn) "/ 175
|
|
210 |
(areturn) "/ 176
|
|
211 |
(return) "/ 177
|
|
212 |
(getstatic constIndexShort) "/ 178
|
|
213 |
(putstatic constIndexShort) "/ 179
|
|
214 |
|
|
215 |
(getfield constIndexShort) "/ 180
|
|
216 |
(putfield constIndexShort) "/ 181
|
|
217 |
(invokevirtual constIndexShort) "/ 182
|
|
218 |
(invokenonvirtual constIndexShort) "/ 183
|
|
219 |
(invokestatic constIndexShort) "/ 184
|
|
220 |
(invokeinterface constIndexShort nargsByte reservedByte) "/ 185
|
|
221 |
(newfromname) "/ 186
|
|
222 |
(new constIndexShort) "/ 187
|
|
223 |
(newarray arrayTypeByte) "/ 188
|
|
224 |
(anewarray constIndexShort) "/ 189
|
|
225 |
|
|
226 |
(arraylength) "/ 190
|
32
|
227 |
(athrow) "/ 191
|
27
|
228 |
(checkcast constIndexShort) "/ 192
|
6
|
229 |
(instanceof constIndexShort) "/ 193
|
|
230 |
(monitorenter) "/ 194
|
|
231 |
(monitorexit) "/ 195
|
68
|
232 |
"/ (verifystack) "/ 196 obsolete (Alpha release)
|
|
233 |
(wide localIndexByte) "/ 196
|
|
234 |
(multianewarray constIndexShort dimensionsByte) "/ 197
|
41
|
235 |
|
68
|
236 |
(ifnull signedBranchShort) "/ 198
|
|
237 |
(ifnonnull signedBranchShort) "/ 199
|
6
|
238 |
|
68
|
239 |
(#'goto_w' signedBranchLong) "/ 200
|
|
240 |
(#'jsr_w' signedBranchShort) "/ 201
|
|
241 |
|
|
242 |
(breakpoint) "/ 202
|
|
243 |
|
6
|
244 |
nil "/ 203
|
|
245 |
nil "/ 204
|
|
246 |
nil "/ 205
|
68
|
247 |
nil "/ 206
|
6
|
248 |
nil "/ 207
|
|
249 |
nil "/ 208
|
68
|
250 |
(#'ret_w' signedBranchShort) "/ 209
|
6
|
251 |
|
|
252 |
nil "/ 210
|
|
253 |
nil "/ 211
|
|
254 |
nil "/ 212
|
|
255 |
nil "/ 213
|
|
256 |
nil "/ 214
|
|
257 |
nil "/ 215
|
|
258 |
nil "/ 216
|
|
259 |
nil "/ 217
|
|
260 |
nil "/ 218
|
|
261 |
nil "/ 219
|
|
262 |
|
|
263 |
nil "/ 220
|
|
264 |
nil "/ 221
|
|
265 |
nil "/ 222
|
|
266 |
nil "/ 223
|
|
267 |
nil "/ 224
|
|
268 |
nil "/ 225
|
|
269 |
nil "/ 226
|
|
270 |
nil "/ 227
|
|
271 |
nil "/ 228
|
|
272 |
nil "/ 229
|
|
273 |
|
|
274 |
nil "/ 230
|
|
275 |
nil "/ 231
|
|
276 |
nil "/ 232
|
|
277 |
nil "/ 233
|
|
278 |
nil "/ 234
|
|
279 |
nil "/ 235
|
|
280 |
nil "/ 236
|
|
281 |
nil "/ 237
|
|
282 |
nil "/ 238
|
|
283 |
nil "/ 239
|
|
284 |
|
|
285 |
nil "/ 240
|
|
286 |
nil "/ 241
|
|
287 |
nil "/ 242
|
|
288 |
nil "/ 243
|
|
289 |
nil "/ 244
|
|
290 |
nil "/ 245
|
|
291 |
nil "/ 246
|
|
292 |
nil "/ 247
|
|
293 |
nil "/ 248
|
|
294 |
nil "/ 249
|
|
295 |
|
|
296 |
nil "/ 250
|
|
297 |
nil "/ 251
|
|
298 |
nil "/ 252
|
|
299 |
nil "/ 253
|
|
300 |
nil "/ 254
|
124
|
301 |
(invokenonvirtual_d constIndexShort) "/ 255 special - dummy invokenonvirtual
|
6
|
302 |
)
|
|
303 |
|
|
304 |
"
|
|
305 |
JavaDecompiler initialize
|
|
306 |
"
|
|
307 |
|
|
308 |
"Modified: 16.4.1996 / 14:56:13 / cg"
|
|
309 |
! !
|
|
310 |
|
129
|
311 |
!JavaDecompiler class methodsFor:'accessing'!
|
27
|
312 |
|
|
313 |
instructionTable
|
|
314 |
^ DecoderTable
|
|
315 |
! !
|
|
316 |
|
161
|
317 |
!JavaDecompiler class methodsFor:'class definition generation'!
|
|
318 |
|
|
319 |
definitionOf:aJavaClass on:s
|
|
320 |
|pckgName needCR fields staticFields superClass
|
|
321 |
interfaces|
|
|
322 |
|
|
323 |
pckgName := aJavaClass package.
|
175
|
324 |
pckgName ~= aJavaClass name ifTrue:[
|
|
325 |
s nextPutAll:'package ' , (pckgName copy replaceAll:$/ by:$.).
|
|
326 |
s nextPutAll:';'; cr; cr.
|
|
327 |
].
|
161
|
328 |
|
|
329 |
needCR := false.
|
|
330 |
aJavaClass isPublic ifTrue:[
|
|
331 |
s nextPutAll:'public '.
|
|
332 |
needCR := true.
|
|
333 |
].
|
|
334 |
aJavaClass isAbstract ifTrue:[
|
|
335 |
s nextPutAll:'abstract '.
|
|
336 |
needCR := true.
|
|
337 |
].
|
|
338 |
aJavaClass isFinal ifTrue:[
|
|
339 |
s nextPutAll:'final '.
|
|
340 |
needCR := true.
|
|
341 |
].
|
|
342 |
|
|
343 |
needCR ifTrue:[
|
|
344 |
s cr
|
|
345 |
].
|
|
346 |
aJavaClass isInterface ifTrue:[
|
|
347 |
s nextPutAll:'interface '.
|
|
348 |
] ifFalse:[
|
|
349 |
s nextPutAll:'class '.
|
|
350 |
].
|
|
351 |
s nextPutAll:aJavaClass name; space.
|
|
352 |
superClass := aJavaClass superclass.
|
|
353 |
|
|
354 |
superClass ~~ (Java at:'java.lang.Object') ifTrue:[
|
|
355 |
s nextPutAll:'extends '.
|
|
356 |
(superClass package ~= 'java/lang'
|
|
357 |
and:[superClass package ~= pckgName]) ifTrue:[
|
|
358 |
s nextPutAll:(superClass displayString); space
|
|
359 |
] ifFalse:[
|
|
360 |
s nextPutAll:(superClass name); space
|
|
361 |
]
|
|
362 |
].
|
|
363 |
|
|
364 |
(interfaces := aJavaClass interfaces) size > 0 ifTrue:[
|
165
|
365 |
(aJavaClass isInterface
|
|
366 |
and:[interfaces size == 1]) ifTrue:[
|
|
367 |
s nextPutAll:'extends '.
|
|
368 |
] ifFalse:[
|
|
369 |
s nextPutAll:'implements '.
|
|
370 |
].
|
161
|
371 |
interfaces keysAndValuesDo:[:nr :if |
|
|
372 |
nr ~~ 1 ifTrue:[
|
|
373 |
s nextPutAll:', '.
|
|
374 |
].
|
|
375 |
(if package ~= 'java/lang'
|
|
376 |
and:[if package ~= pckgName]) ifTrue:[
|
|
377 |
s nextPutAll:(if displayString)
|
|
378 |
] ifFalse:[
|
|
379 |
s nextPutAll:(if name)
|
|
380 |
]
|
|
381 |
].
|
|
382 |
s space.
|
|
383 |
].
|
|
384 |
|
|
385 |
s nextPutAll:'{'; cr.
|
|
386 |
|
|
387 |
needCR := false.
|
|
388 |
staticFields := aJavaClass staticFields.
|
|
389 |
staticFields size > 0 ifTrue:[
|
|
390 |
needCR := true.
|
|
391 |
|
|
392 |
staticFields do:[:aField |
|
|
393 |
|type v|
|
|
394 |
|
|
395 |
s nextPutAll:' '.
|
|
396 |
aField isPublic ifTrue:[
|
|
397 |
s nextPutAll:'public '.
|
|
398 |
] ifFalse:[
|
|
399 |
s nextPutAll:'private '.
|
|
400 |
].
|
|
401 |
s nextPutAll:'static '.
|
|
402 |
aField isFinal ifTrue:[
|
|
403 |
s nextPutAll:'final '.
|
|
404 |
].
|
|
405 |
|
|
406 |
((type := aField type) startsWith:pckgName) ifTrue:[
|
|
407 |
type := type copyFrom:(pckgName size + 1 + 1).
|
|
408 |
] ifFalse:[
|
|
409 |
(type startsWith:'java.lang.') ifTrue:[
|
|
410 |
type := type copyFrom:(11).
|
|
411 |
]
|
|
412 |
].
|
|
413 |
type := type copy replaceAll:$/ with:$..
|
|
414 |
s nextPutAll:type; space;
|
|
415 |
nextPutAll:aField name.
|
|
416 |
|
|
417 |
(v := aField constantValue) notNil ifTrue:[
|
|
418 |
s nextPutAll:' = '; nextPutAll:v displayString.
|
|
419 |
].
|
|
420 |
|
|
421 |
s nextPutAll:';'; cr.
|
|
422 |
needCR := true.
|
|
423 |
].
|
|
424 |
].
|
|
425 |
|
|
426 |
|
|
427 |
fields := aJavaClass fields.
|
|
428 |
fields size > 0 ifTrue:[
|
|
429 |
needCR ifTrue:[
|
|
430 |
s cr
|
|
431 |
].
|
|
432 |
needCR := true.
|
|
433 |
|
|
434 |
fields do:[:aField |
|
|
435 |
|type|
|
|
436 |
|
|
437 |
s nextPutAll:' '.
|
|
438 |
aField isPublic ifTrue:[
|
|
439 |
s nextPutAll:'public '.
|
|
440 |
] ifFalse:[
|
|
441 |
s nextPutAll:'private '.
|
|
442 |
].
|
|
443 |
aField isFinal ifTrue:[
|
|
444 |
s nextPutAll:'final '.
|
|
445 |
].
|
|
446 |
|
|
447 |
((type := aField type) startsWith:pckgName) ifTrue:[
|
|
448 |
type := type copyFrom:(pckgName size + 1 + 1).
|
|
449 |
].
|
|
450 |
type := type copy replaceAll:$/ with:$..
|
|
451 |
s nextPutAll:type; space;
|
|
452 |
nextPutAll:aField name; nextPutAll:';'; cr.
|
|
453 |
].
|
|
454 |
].
|
|
455 |
|
|
456 |
aJavaClass methodDictionary size > 0 ifTrue:[
|
|
457 |
needCR ifTrue:[
|
|
458 |
s cr
|
|
459 |
].
|
|
460 |
needCR := true.
|
|
461 |
|
|
462 |
aJavaClass methodDictionary do:[:aMethod |
|
165
|
463 |
|type nm|
|
161
|
464 |
|
|
465 |
s nextPutAll:' '.
|
|
466 |
aMethod isPublic ifTrue:[
|
|
467 |
s nextPutAll:'public '.
|
|
468 |
] ifFalse:[
|
|
469 |
aMethod isProtected ifTrue:[
|
|
470 |
s nextPutAll:'protected '.
|
|
471 |
] ifFalse:[
|
|
472 |
s nextPutAll:'private '.
|
|
473 |
]
|
|
474 |
].
|
|
475 |
aMethod isFinal ifTrue:[
|
|
476 |
s nextPutAll:'final '.
|
|
477 |
].
|
|
478 |
aMethod isStatic ifTrue:[
|
|
479 |
s nextPutAll:'static '.
|
|
480 |
].
|
|
481 |
aMethod isNative ifTrue:[
|
|
482 |
s nextPutAll:'native '.
|
|
483 |
].
|
|
484 |
aMethod isSynchronized ifTrue:[
|
|
485 |
s nextPutAll:'synchronized '.
|
|
486 |
].
|
|
487 |
|
165
|
488 |
(nm := aMethod name) = '<init>' ifTrue:[
|
|
489 |
nm := aMethod javaClass name.
|
161
|
490 |
].
|
165
|
491 |
s nextPutAll:(aMethod signatureNameFor:nm withArgsIn:aMethod javaClass package).
|
161
|
492 |
|
|
493 |
aMethod exceptionTable size > 0 ifTrue:[
|
165
|
494 |
s nextPutAll:' throws '.
|
161
|
495 |
|
|
496 |
aMethod exceptionTable keysAndValuesDo:[:index :aClassRef |
|
|
497 |
|nm|
|
|
498 |
|
|
499 |
nm := aClassRef fullName.
|
|
500 |
(nm startsWith:pckgName) ifTrue:[
|
|
501 |
nm := nm copyFrom:pckgName size + 2
|
|
502 |
] ifFalse:[
|
|
503 |
(nm startsWith:'java/lang') ifTrue:[
|
|
504 |
nm := nm copyFrom:'java/lang' size + 2.
|
|
505 |
].
|
|
506 |
].
|
|
507 |
index ~~ 1 ifTrue:[
|
|
508 |
s nextPutAll:', '
|
|
509 |
].
|
|
510 |
s nextPutAll:((nm copyFrom:1) replaceAll:$/ with:$.)
|
|
511 |
]
|
|
512 |
].
|
|
513 |
|
|
514 |
s nextPutAll:';'; cr.
|
|
515 |
].
|
|
516 |
].
|
|
517 |
|
|
518 |
s nextPutAll:'}'; cr.
|
|
519 |
|
|
520 |
"Created: 22.3.1997 / 14:29:37 / cg"
|
175
|
521 |
"Modified: 30.7.1997 / 15:27:53 / cg"
|
161
|
522 |
! !
|
|
523 |
|
129
|
524 |
!JavaDecompiler class methodsFor:'decompiling'!
|
6
|
525 |
|
|
526 |
decompile:aJavaMethod
|
18
|
527 |
self decompile:aJavaMethod to:Transcript
|
|
528 |
!
|
|
529 |
|
|
530 |
decompile:aJavaMethod to:aStream
|
|
531 |
self new decompile:aJavaMethod to:aStream
|
6
|
532 |
! !
|
|
533 |
|
|
534 |
!JavaDecompiler methodsFor:'decompiling'!
|
|
535 |
|
18
|
536 |
decompile:aJavaMethod to:aStream
|
27
|
537 |
|who endPC insn spec op|
|
18
|
538 |
|
|
539 |
outStream := aStream.
|
|
540 |
|
|
541 |
who := aJavaMethod who.
|
|
542 |
who notNil ifTrue:[
|
129
|
543 |
classToCompileFor := who methodClass.
|
18
|
544 |
aStream cr.
|
129
|
545 |
"/ aStream showCR:'decompiling ' , classToCompileFor name , '>>' , (who methodSelector) , ':'.
|
61
|
546 |
aStream showCR:'decompiling ' , aJavaMethod displayString , ':'.
|
119
|
547 |
aJavaMethod isStatic ifTrue:[
|
|
548 |
aStream show:'static method'.
|
|
549 |
].
|
|
550 |
aStream cr.
|
18
|
551 |
aStream cr.
|
|
552 |
].
|
6
|
553 |
|
|
554 |
javaMethod := aJavaMethod.
|
|
555 |
code := aJavaMethod javaByteCode.
|
|
556 |
endPC := code size.
|
18
|
557 |
endPC == 0 ifTrue:[
|
19
|
558 |
javaMethod isNative ifTrue:[
|
175
|
559 |
outStream nextPutAll:'// native method'; cr
|
18
|
560 |
] ifFalse:[
|
175
|
561 |
outStream nextPutAll:'{} // no bytecode'; cr
|
18
|
562 |
].
|
|
563 |
^ self
|
|
564 |
].
|
|
565 |
|
6
|
566 |
pc := 1.
|
|
567 |
[pc <= endPC] whileTrue:[
|
|
568 |
insn := code at:pc.
|
|
569 |
pc := pc + 1.
|
|
570 |
spec := DecoderTable at:(insn + 1).
|
27
|
571 |
spec isNil ifTrue:[
|
|
572 |
op := '** invalid opcode: ',insn printString, ' **'
|
|
573 |
] ifFalse:[
|
|
574 |
op := spec at:1
|
|
575 |
].
|
23
|
576 |
outStream
|
|
577 |
show:((pc - 1) printStringPaddedTo:4);
|
|
578 |
show:' ';
|
27
|
579 |
show:op;
|
23
|
580 |
show:' '.
|
|
581 |
|
27
|
582 |
spec notNil ifTrue:[
|
|
583 |
spec from:2 to:spec size do:[:what |
|
|
584 |
self perform:what
|
|
585 |
].
|
6
|
586 |
].
|
18
|
587 |
outStream cr.
|
6
|
588 |
]
|
|
589 |
|
|
590 |
"Created: 16.4.1996 / 14:59:29 / cg"
|
175
|
591 |
"Modified: 30.7.1997 / 16:13:04 / cg"
|
6
|
592 |
! !
|
|
593 |
|
|
594 |
!JavaDecompiler methodsFor:'operand decoding'!
|
|
595 |
|
23
|
596 |
arrayTypeByte
|
|
597 |
|hi low index type|
|
|
598 |
|
|
599 |
index := code at:pc.
|
|
600 |
pc := pc + 1.
|
|
601 |
|
|
602 |
type := #('T_ARRAY' 'invalid' 'invalid' 'T_BOOLEAN'
|
|
603 |
'T_CHAR' 'T_FLOAT' 'T_DOUBLE' 'T_BYTE'
|
|
604 |
'T_INT' 'T_LONG' ) at:index ifAbsent:'invalid'.
|
|
605 |
|
|
606 |
outStream
|
|
607 |
show:index;
|
|
608 |
show:' [';
|
|
609 |
show:type;
|
|
610 |
show:']'
|
|
611 |
|
|
612 |
"Created: 16.4.1996 / 15:00:04 / cg"
|
|
613 |
"Modified: 16.4.1996 / 15:30:55 / cg"
|
|
614 |
!
|
|
615 |
|
|
616 |
constIndexByte
|
126
|
617 |
|index|
|
23
|
618 |
|
|
619 |
index := code at:pc.
|
|
620 |
pc := pc + 1.
|
|
621 |
|
|
622 |
outStream
|
|
623 |
show:index;
|
|
624 |
show:' [';
|
27
|
625 |
show:(javaMethod constantPool at:index ifAbsent:['??']) displayString;
|
|
626 |
show:'] '
|
23
|
627 |
|
|
628 |
"Created: 16.4.1996 / 15:00:04 / cg"
|
|
629 |
"Modified: 16.4.1996 / 15:30:55 / cg"
|
|
630 |
!
|
|
631 |
|
6
|
632 |
constIndexShort
|
126
|
633 |
|index|
|
6
|
634 |
|
24
|
635 |
index := code wordAt:pc MSB:true.
|
|
636 |
pc := pc + 2.
|
6
|
637 |
|
18
|
638 |
outStream
|
6
|
639 |
show:index;
|
|
640 |
show:' [';
|
27
|
641 |
show:(javaMethod constantPool at:index ifAbsent:'???') displayString;
|
|
642 |
show:'] '
|
6
|
643 |
|
|
644 |
"Created: 16.4.1996 / 15:00:04 / cg"
|
|
645 |
"Modified: 16.4.1996 / 15:30:55 / cg"
|
23
|
646 |
!
|
|
647 |
|
27
|
648 |
dimensionsByte
|
108
|
649 |
outStream show:' dims= '.
|
27
|
650 |
self unsignedByte
|
|
651 |
!
|
|
652 |
|
23
|
653 |
localIndexByte
|
|
654 |
|hi low index constants|
|
|
655 |
|
|
656 |
index := code at:pc.
|
|
657 |
pc := pc + 1.
|
|
658 |
|
|
659 |
outStream
|
|
660 |
show:index;
|
39
|
661 |
show:' '
|
23
|
662 |
|
|
663 |
"Created: 16.4.1996 / 15:00:04 / cg"
|
|
664 |
"Modified: 16.4.1996 / 15:30:55 / cg"
|
|
665 |
!
|
|
666 |
|
27
|
667 |
lookupSwitchBytes
|
|
668 |
|defaultOffset delta nPairs match pc0|
|
|
669 |
|
|
670 |
pc0 := pc-1. "/ i.e. the pc of the tableSwitch op
|
|
671 |
|
|
672 |
[(pc-1) \\ 4 ~~ 0] whileTrue:[
|
|
673 |
pc := pc + 1
|
|
674 |
].
|
|
675 |
|
|
676 |
defaultOffset := code signedDoubleWordAt:pc MSB:true.
|
|
677 |
pc := pc + 4.
|
|
678 |
nPairs := code signedDoubleWordAt:pc MSB:true.
|
|
679 |
pc := pc + 4.
|
|
680 |
|
|
681 |
outStream show:'n='; show:nPairs; cr.
|
|
682 |
|
|
683 |
nPairs timesRepeat:[
|
|
684 |
match := code signedDoubleWordAt:pc MSB:true.
|
|
685 |
pc := pc + 4.
|
|
686 |
delta := code signedDoubleWordAt:pc MSB:true.
|
|
687 |
pc := pc + 4.
|
|
688 |
outStream show:' ';
|
|
689 |
show:match;
|
|
690 |
show:' -> ';
|
|
691 |
show:delta;
|
|
692 |
show:' [';
|
|
693 |
show:(pc0 + delta);
|
|
694 |
show:']';
|
|
695 |
cr.
|
|
696 |
].
|
|
697 |
|
|
698 |
outStream show:' ';
|
|
699 |
show:'default';
|
|
700 |
show:' -> ';
|
|
701 |
show:defaultOffset;
|
|
702 |
show:' [';
|
|
703 |
show:(pc0 + defaultOffset);
|
|
704 |
show:']'.
|
|
705 |
!
|
|
706 |
|
|
707 |
nargsByte
|
|
708 |
|byte constants|
|
|
709 |
|
|
710 |
byte := code byteAt:pc.
|
|
711 |
pc := pc + 1.
|
|
712 |
|
|
713 |
outStream
|
|
714 |
show:byte
|
|
715 |
|
|
716 |
"Created: 16.4.1996 / 15:00:04 / cg"
|
|
717 |
"Modified: 16.4.1996 / 15:30:55 / cg"
|
|
718 |
!
|
|
719 |
|
|
720 |
reservedByte
|
|
721 |
|byte constants|
|
|
722 |
|
|
723 |
byte := code byteAt:pc.
|
|
724 |
pc := pc + 1.
|
|
725 |
|
|
726 |
outStream
|
|
727 |
show:byte
|
|
728 |
|
|
729 |
"Created: 16.4.1996 / 15:00:04 / cg"
|
|
730 |
"Modified: 16.4.1996 / 15:30:55 / cg"
|
|
731 |
!
|
|
732 |
|
23
|
733 |
signedBranchShort
|
24
|
734 |
|index constants|
|
23
|
735 |
|
24
|
736 |
index := code signedWordAt:pc MSB:true.
|
23
|
737 |
|
|
738 |
outStream
|
|
739 |
show:index;
|
|
740 |
show:' [';
|
25
|
741 |
show:(pc + index - 1);
|
|
742 |
show:']'.
|
|
743 |
|
|
744 |
pc := pc + 2.
|
23
|
745 |
|
|
746 |
"Created: 16.4.1996 / 15:00:04 / cg"
|
|
747 |
"Modified: 16.4.1996 / 15:30:55 / cg"
|
24
|
748 |
!
|
|
749 |
|
|
750 |
signedByte
|
|
751 |
|byte constants|
|
|
752 |
|
|
753 |
byte := code signedByteAt:pc.
|
|
754 |
pc := pc + 1.
|
|
755 |
|
|
756 |
outStream
|
|
757 |
show:byte
|
|
758 |
|
|
759 |
"Created: 16.4.1996 / 15:00:04 / cg"
|
|
760 |
"Modified: 16.4.1996 / 15:30:55 / cg"
|
|
761 |
!
|
|
762 |
|
|
763 |
signedShort
|
|
764 |
|word constants|
|
|
765 |
|
|
766 |
word := code signedWordAt:pc MSB:true.
|
|
767 |
pc := pc + 2.
|
|
768 |
|
|
769 |
outStream
|
|
770 |
show:word
|
|
771 |
|
|
772 |
"Created: 16.4.1996 / 15:00:04 / cg"
|
|
773 |
"Modified: 16.4.1996 / 15:30:55 / cg"
|
|
774 |
!
|
|
775 |
|
|
776 |
tableSwitchBytes
|
|
777 |
|defaultOffset delta low high pc0|
|
|
778 |
|
|
779 |
pc0 := pc-1. "/ i.e. the pc of the tableSwitch op
|
|
780 |
|
|
781 |
[(pc-1) \\ 4 ~~ 0] whileTrue:[
|
|
782 |
pc := pc + 1
|
|
783 |
].
|
|
784 |
|
|
785 |
defaultOffset := code signedDoubleWordAt:pc MSB:true.
|
|
786 |
pc := pc + 4.
|
|
787 |
low := code signedDoubleWordAt:pc MSB:true.
|
|
788 |
pc := pc + 4.
|
|
789 |
high := code signedDoubleWordAt:pc MSB:true.
|
|
790 |
pc := pc + 4.
|
|
791 |
|
|
792 |
outStream cr.
|
|
793 |
|
|
794 |
low to:high do:[:switchValue |
|
|
795 |
delta := code signedDoubleWordAt:pc MSB:true.
|
|
796 |
pc := pc + 4.
|
|
797 |
outStream show:' ';
|
|
798 |
show:switchValue;
|
|
799 |
show:' -> ';
|
|
800 |
show:delta;
|
|
801 |
show:' [';
|
|
802 |
show:(pc0 + delta);
|
|
803 |
show:']';
|
|
804 |
cr.
|
|
805 |
].
|
|
806 |
|
|
807 |
outStream show:' ';
|
|
808 |
show:'default';
|
|
809 |
show:' -> ';
|
|
810 |
show:defaultOffset;
|
|
811 |
show:' [';
|
|
812 |
show:(pc0 + defaultOffset);
|
|
813 |
show:']'.
|
|
814 |
|
|
815 |
|
27
|
816 |
!
|
|
817 |
|
|
818 |
unsignedByte
|
|
819 |
|byte constants|
|
|
820 |
|
|
821 |
byte := code byteAt:pc.
|
|
822 |
pc := pc + 1.
|
|
823 |
|
|
824 |
outStream
|
|
825 |
show:byte
|
|
826 |
|
|
827 |
"Created: 16.4.1996 / 15:00:04 / cg"
|
|
828 |
"Modified: 16.4.1996 / 15:30:55 / cg"
|
6
|
829 |
! !
|
|
830 |
|
129
|
831 |
!JavaDecompiler class methodsFor:'documentation'!
|
6
|
832 |
|
|
833 |
version
|
175
|
834 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaDecompiler.st,v 1.26 1997/07/30 14:40:09 cg Exp $'
|
6
|
835 |
! !
|
|
836 |
JavaDecompiler initialize!
|