because of the need to implement a certain software watermarking technique I have to manipulate the exception table.
(Link to the paper that describes the technique:http://profs.sci.univr.it/~giaco/download/Watermarking-Obfuscation/self-validating%20brench%20watermarking.pdf
(Section "Extension to Java Bytecode")
So far I could manually add the exception table entry with Javassist:
MethodInfo minfo = (MethodInfo) aclasscf.getMethods().get(0);
CodeAttribute ca = minfo.getCodeAttribute();
ExceptionTable et = ca.getExceptionTable();
System.out.println("exception table size: "+ et.size());
But the problem is that I can't run the file anymore. Simply running it with the java command results in "Stack map does not match the one at exception handler 40". After some research this seems to
be a problem with java 7 and a stricter verifier. I read several times that java -XX:-UseSplitVerifier should be used instead.
This really fixed the stackmap error, but then another error appeared: "java.lang.VerifyError: (class: AClass, method: <init> signature: ()V) Inconsistent stack height 0 != 1". Are there any further steps required
to insert a new exception in the exception table?
Additional info: Later I want to remove gotos (in this case the goto at line 27) and add a function call instead. When this function finishes it will throw a exception and propagate it back to the caller (which will be at line 27). Then the program should go on as if nothing happend, that is also the reason why the target of the exception is the same as the target of the goto (40).
Here is the bytecode:
1: invokespecial #8 // Method java/lang/Object."<init>":()V
6: goto 19
9: getstatic #10 // Field java/lang/System.out:Ljava/io/PrintStream;
13: invokevirtual #16 // Method java/io/PrintStream.println:(I)V
16: iinc 1, 1
20: bipush 20
22: if_icmplt 9
27: goto 40
30: getstatic #10 // Field java/lang/System.out:Ljava/io/PrintStream;
34: invokevirtual #16 // Method java/io/PrintStream.println:(I)V
37: iinc 1, 1
41: bipush 20
43: if_icmplt 30
from to target type
27 30 40 any