2014-04-24 2 views
0

내가 특정 클래스에 javap -c Address.class > Address.txt을 실행자바 클래스 상수 풀에서 상수 매핑 목록을 얻는 방법은 무엇입니까?

나는 정수 풀 내가 형태로 풀을 얻을 수있을 것입니다 방법

Compiled from "Address.java" 
public class test.Address extends test.Entity { 
    public test.Address(); 
    Code: 
     0: aload_0  
     1: invokespecial #1     // Method test/DefaultEntity."<init>":()V 
     4: aload_0  
     5: aconst_null 
     6: putfield  #2     // Field io:Ljava/lang/String; 
     9: aload_0  
     10: aconst_null 
     11: putfield  #3     // Field zip4:Ljava/lang/String; 
     14: aload_0  
     15: aconst_null 
     16: putfield  #4     // Field zip:Ljava/lang/String; 
     19: aload_0 

에 대한 지표로 #<NUMBER>과 출력의 무리를 얻을 수 해시 맵? 즉 :

{1 "Method test/DefaultEntity."<init>":()" 
2 "Field io:Ljava/lang/String;"} 
+0

상수 풀 '은 javap -c -verbose YourClass'의 출력의 상단에있다. –

+0

프로그래밍 방식으로 가져 오는 방법이 있습니까? 나는 asm을보고 있지만 그 방법을 찾을 수 없었다. – zcaudate

+0

[BCEL] (https://commons.apache.org/proper/commons-bcel/)을 사용하여 [Constant Pool] (http : // commons .class 파일] (http://docs.oracle.com/javase/specs/jvms/se7/)에서 ".apache.org/proper/commons-bcel/apidocs/org/apache/bcel/classfile/ConstantPool.html" html/jvms-4.html). –

답변

1

ASM, 당신은의 .class 파일을 읽어 ClassReader를 사용하고 정수 풀의 모든 항목을 읽을 수는, getItemCount()와 다양한 읽기 방법을 사용할 수 있습니다.

(def cr (clojure.asm.ClassReader "test.Address")) 
(.getItemCount cr) 
;; etc