readTable


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@288 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent dad8dc308d
commit 32cb2027e5
  1. 78
      jode/jode/obfuscator/MethodIdentifier.java

@ -22,6 +22,7 @@ import jode.bytecode.*;
import java.io.*; import java.io.*;
import java.util.Vector; import java.util.Vector;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable;
public class MethodIdentifier extends Identifier implements Opcodes { public class MethodIdentifier extends Identifier implements Opcodes {
ClassIdentifier clazz; ClassIdentifier clazz;
@ -36,6 +37,22 @@ public class MethodIdentifier extends Identifier implements Opcodes {
super(info.getName()); super(info.getName());
this.clazz = clazz; this.clazz = clazz;
this.info = info; this.info = info;
AttributeInfo codeattr = info.findAttribute("Code");
AttributeInfo exceptionsattr = info.findAttribute("Exceptions");
try {
if (codeattr != null) {
DataInputStream stream = new DataInputStream
(new ByteArrayInputStream(codeattr.getContents()));
codeinfo = new CodeInfo();
codeinfo.read(clazz.info.getConstantPool(), stream);
}
if (exceptionsattr != null)
readExceptions(exceptionsattr);
} catch (IOException ex) {
ex.printStackTrace();
}
} }
/** /**
@ -194,7 +211,6 @@ public class MethodIdentifier extends Identifier implements Opcodes {
for (int i=0; i< count; i++) { for (int i=0; i< count; i++) {
exceptions[i] exceptions[i]
= cp.getClassName(input.readUnsignedShort()).replace('/','.'); = cp.getClassName(input.readUnsignedShort()).replace('/','.');
clazz.bundle.reachableIdentifier(exceptions[i], false);
} }
} }
@ -213,29 +229,27 @@ public class MethodIdentifier extends Identifier implements Opcodes {
index = type.indexOf('L', end); index = type.indexOf('L', end);
} }
AttributeInfo codeattr = info.findAttribute("Code"); if (codeinfo != null) {
AttributeInfo exceptionsattr = info.findAttribute("Exceptions"); try {
try {
if (codeattr != null) {
DataInputStream stream = new DataInputStream
(new ByteArrayInputStream(codeattr.getContents()));
codeinfo = new CodeInfo();
codeinfo.read(clazz.info.getConstantPool(), stream);
analyzeCode(); analyzeCode();
} catch (IOException ex) {
ex.printStackTrace();
System.exit(0);
} }
if (exceptionsattr != null)
readExceptions(exceptionsattr);
} catch (IOException ex) {
ex.printStackTrace();
} }
if (exceptions != null) {
for (int i=0; i< exceptions.length; i++)
clazz.bundle.reachableIdentifier(exceptions[i], false);
}
}
public void readTable(Hashtable table) {
setAlias((String) table.get(getFullName() + "." + getType()));
} }
public void writeTable(PrintWriter out) throws IOException { public void writeTable(Hashtable table) {
if (getName() != getAlias()) table.put(getFullAlias()
out.println("" + getFullAlias() + "." + clazz.bundle.getTypeAlias(getType()), getName());
+ "." + clazz.bundle.getTypeAlias(getType())
+ " = " + getName());
} }
public Identifier getParent() { public Identifier getParent() {
@ -401,7 +415,8 @@ public class MethodIdentifier extends Identifier implements Opcodes {
names[0] = ci.getFullAlias(); names[0] = ci.getFullAlias();
Identifier fi = ci.getIdentifier(names[1], names[2]); Identifier fi = ci.getIdentifier(names[1], names[2]);
if (fi instanceof FieldIdentifier) { if (fi instanceof FieldIdentifier) {
if (!((FieldIdentifier)fi).isReachable()) { if (Obfuscator.shouldStrip
&& !((FieldIdentifier)fi).isReachable()) {
if (opcode != opc_putfield if (opcode != opc_putfield
&& opcode != opc_putstatic) && opcode != opc_putstatic)
throw new jode.AssertError throw new jode.AssertError
@ -511,13 +526,17 @@ public class MethodIdentifier extends Identifier implements Opcodes {
output.writeShort(handlers[i]); output.writeShort(handlers[i]);
output.writeShort(handlers[i+1]); output.writeShort(handlers[i+1]);
output.writeShort(handlers[i+2]); output.writeShort(handlers[i+2]);
String clName if (handlers[i+3] == 0)
= cp.getClassName(handlers[i+3]).replace('/','.'); output.writeShort(0);
ClassIdentifier ci = (ClassIdentifier) else {
clazz.bundle.getIdentifier(clName); String clName
if (ci != null) = cp.getClassName(handlers[i+3]).replace('/','.');
clName = ci.getFullAlias(); ClassIdentifier ci = (ClassIdentifier)
output.writeShort(gcp.putClassRef(clName)); clazz.bundle.getIdentifier(clName);
if (ci != null)
clName = ci.getFullAlias();
output.writeShort(gcp.putClassRef(clName));
}
} }
output.writeShort(0); // No Attributes; output.writeShort(0); // No Attributes;
output.close(); output.close();
@ -544,6 +563,7 @@ public class MethodIdentifier extends Identifier implements Opcodes {
case opc_ldc: { case opc_ldc: {
int index = stream.readUnsignedByte(); int index = stream.readUnsignedByte();
gcp.copyConstant(cp, index); gcp.copyConstant(cp, index);
addr += 2;
break; break;
} }
@ -588,6 +608,7 @@ public class MethodIdentifier extends Identifier implements Opcodes {
addr+=2; addr+=2;
break; break;
case opc_sipush: case opc_sipush:
case opc_ldc_w:
case opc_ldc2_w: case opc_ldc2_w:
case opc_iinc: case opc_iinc:
case opc_ifnull: case opc_ifnonnull: case opc_ifnull: case opc_ifnonnull:
@ -634,7 +655,7 @@ public class MethodIdentifier extends Identifier implements Opcodes {
public void fillConstantPool(GrowableConstantPool gcp) { public void fillConstantPool(GrowableConstantPool gcp) {
nameIndex = gcp.putUTF(getAlias()); nameIndex = gcp.putUTF(getAlias());
descriptorIndex = gcp.putUTF(clazz.bundle.getTypeAlias(getType())); descriptorIndex = gcp.putUTF(clazz.bundle.getTypeAlias(getType()));
AttributeInfo codeattr = info.findAttribute("Code");
codeIndex = 0; codeIndex = 0;
if (codeinfo != null) { if (codeinfo != null) {
transformCode(gcp); transformCode(gcp);
@ -679,4 +700,3 @@ public class MethodIdentifier extends Identifier implements Opcodes {
} }
} }
} }

Loading…
Cancel
Save