| [Home] [Kuri] [Sysad] [Internet?] [Blog] [Java] [Windows] [Download] [Profile] [Flash] [+] |
import java.io.IOException;
import de.fub.bytecode.classfile.*;
public class dump {
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Usage: (java) dump inputclass");
System.exit(1);
}
try {
ClassParser parser = new ClassParser(args[0]);
JavaClass jclass = parser.parse();
System.out.println(jclass);
} catch(IOException e) {
e.printStackTrace();
}
}
}
|
また、コンスタントプールを表示させるには、以下のようにします。
import java.io.IOException;
import de.fub.bytecode.classfile.*;
public class cp {
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Usage: (java) cp inputclass");
System.exit(1);
}
try {
ClassParser parser = new ClassParser(args[0]);
JavaClass jclass = parser.parse();
ConstantPool cp = jclass.getConstantPool();
int len = cp.getLength();
for(int i=1; i<len; i++) {
System.out.println(i + " : " + cp.getConstant(i));
}
} catch(IOException e) {
e.printStackTrace();
}
}
}
|
import java.io.IOException;
import de.fub.bytecode.Constants;
import de.fub.bytecode.classfile.*;
public class strip implements Constants {
public static Attribute[] stripAttributes(Attribute[] attr) {
boolean[] res = new boolean[attr.length];
int total=0, i=0;
/* search unnecessary attributes */
for(int j=0; j<attr.length; j++) {
byte tag = attr[j].getTag();
res[j] = (tag != ATTR_SOURCE_FILE&&tag != ATTR_LINE_NUMBER_TABLE);
if(res[j]) total++;
}
/* remake and return attributes */
Attribute[] ret = new Attribute[total];
for(int j=0; j<attr.length; j++) {
if(res[j]) {
ret[i++] = attr[j];
}
}
return ret;
}
public static void main(String[] args) {
try {
if (args.length != 2) {
System.err.println("Usage: (java) strip inputclass outputclass");
System.exit(1);
}
/* strip class attributes */
ClassParser parser = new ClassParser(args[0]);
JavaClass jclass = parser.parse();
Attribute[] attr = jclass.getAttributes();
jclass.setAttributes(stripAttributes(attr));
/* strip code attributes */
Method[] meth = jclass.getMethods();
for(int i=0; i<meth.length; i++) {
Code code = meth[i].getCode();
attr = code.getAttributes();
code.setAttributes(stripAttributes(attr));
}
/* dump stripped class */
jclass.dump(args[1]);
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
|
|
| [Home] [Kuri] [Sysad] [Internet?] [Blog] [Java] [Windows] [Download] [Profile] [Flash] [-] | |
| usu@usupi.org | Last modified : Wed Jun 6 14:34:44 2001 |