Christian Collberg (collberg@cs.arizona.edu)
This is a very simple algorithm that adds a constant string containing
a watermark to a classfile. It embeds a string
sm$watermark=WATERMARK
in the constant pool of the
application. WATERMARK
is the string to be embedded.
Embedding
To embed the watermark we pick one of the user's classes at random and
adds the appropriate string:
String jarInput = props.getProperty("WM_Embed_JarInput"); String jarOutput = props.getProperty("WM_Embed_JarOutput"); String watermark = props.getProperty("WM_Encode_Watermark"); sandmark.util.ClassFileCollection cfc = new sandmark.util.ClassFileCollection(jarInput); java.util.Iterator classes = cfc.classes(); String className = (String) classes.next(); org.apache.bcel.classfile.JavaClass origClass = cfc.getClass(className); org.apache.bcel.generic.ClassGen cg = new org.apache.bcel.generic.ClassGen(origClass); org.apache.bcel.generic.ConstantPoolGen cp = cg.getConstantPool(); int stringIndex = cp.addString("sm$watermark" + "=" + watermark); org.apache.bcel.classfile.JavaClass newClass = cg.getJavaClass(); cfc.addClass(newClass); cfc.saveJar(jarOutput);
Recognition
During recognition we go through every class in the watermarked jar-file
looking for a string in the constant pool that starts with
sm$watermark
:
String jarInput = props.getProperty("WM_Recognize_JarInput"); sandmark.util.ClassFileCollection cfc = new sandmark.util.ClassFileCollection(jarInput); java.util.Iterator classes = cfc.classes(); while (classes.hasNext()) { String className = (String) classes.next(); org.apache.bcel.classfile.JavaClass clazz = cfc.getClass(className); org.apache.bcel.classfile.ConstantPool cp = clazz.getConstantPool(); for (int i=0; iExample
For example, if
SWM_ConstantString_Ident
is set tosm$watermark
and the watermark is the value123456
, we will add the identifiersm$watermark=123456
to the constant pool of a random class in the user's application.Configuration
SWM_ConstantString_Ident
: The prefix of the string in which we hide the watermark.References