<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
- <dependency>\r
- <groupId>asm</groupId>\r
- <artifactId>asm-all</artifactId>\r
- <version>2.2.3</version>\r
- <scope>compile</scope>\r
- </dependency>\r
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm-all</artifactId>
+ <version>2.2.3</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}</outputDirectory>
+ <includeScope>runtime</includeScope>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import jp.sourceforge.stigmata.BirthmarkContext;
import jp.sourceforge.stigmata.birthmarks.AbstractBirthmarkPreprocessor;
public void preprocess(ClassFileArchive[] targets, BirthmarkContext context){
Map<Integer, Integer> targetMap = new HashMap<Integer, Integer>();
- int classCount = readOpcodes(targets, targetMap);
+ int classCount = 0;
+ for(ClassFileArchive archive: targets){
+ classCount += readOpcodes(archive, targetMap);
+ }
Map<Integer, Integer> weights = new HashMap<Integer, Integer>();
for(Map.Entry<Integer, Integer> entry: targetMap.entrySet()){
c = count;
}
- weights.put(opcode, (int)Math.log(classCount / c));
+ weights.put(opcode, (int)Math.round(Math.log(classCount / c)));
}
context.putProperty("birthmarks.wsp.weights", weights);
}
- private int readOpcodes(ClassFileArchive[] targets, Map<Integer, Integer> targetMap){
+ private int readOpcodes(ClassFileArchive archive, Map<Integer, Integer> targetMap){
int count = 0;
- for(ClassFileArchive archive: targets){
- for(ClassFileEntry entry: archive){
- count++;
- final List<Opcode> opcodes = new ArrayList<Opcode>();
- try{
- InputStream in = entry.getLocation().openStream();
+ for(ClassFileEntry entry: archive){
+ count++;
+ final List<Opcode> opcodes = new ArrayList<Opcode>();
+ try{
+ InputStream in = entry.getLocation().openStream();
- ClassReader reader = new ClassReader(in);
- ClassWriter writer = new ClassWriter(false);
- ClassAdapter opcodeExtractVisitor = new ClassAdapter(writer){
- @Override
- public MethodVisitor visitMethod(int arg0, String arg1, String arg2, String arg3, String[] arg4){
- OpcodeExtractionMethodVisitor visitor =
- new OpcodeExtractionMethodVisitor(super.visitMethod(arg0, arg1, arg2, arg3, arg4), opcodes);
- return visitor;
- }
- };
- reader.accept(opcodeExtractVisitor, false);
+ ClassReader reader = new ClassReader(in);
+ ClassWriter writer = new ClassWriter(false);
+ ClassAdapter opcodeExtractVisitor = new ClassAdapter(writer){
+ @Override
+ public MethodVisitor visitMethod(int arg0, String arg1, String arg2, String arg3, String[] arg4){
+ OpcodeExtractionMethodVisitor visitor =
+ new OpcodeExtractionMethodVisitor(super.visitMethod(arg0, arg1, arg2, arg3, arg4), opcodes);
+ return visitor;
+ }
+ };
+ reader.accept(opcodeExtractVisitor, false);
- for(Opcode opcode: opcodes){
- if(opcode.getCategory() != Opcode.Category.TARGETER){
- Integer i = targetMap.get(opcode.getOpcode());
- if(i == null){
- i = 0;
- }
- i = i + 1;
- targetMap.put(opcode.getOpcode(), i);
- }
+ Set<Integer> set = new HashSet<Integer>();
+ for(Opcode opcode: opcodes){
+ if(opcode.getCategory() != Opcode.Category.TARGETER){
+ set.add(opcode.getOpcode());
}
+ }
- } catch(IOException e){
+ for(Integer i: set){
+ Integer v = targetMap.get(i);
+ if(v == null){
+ v = 0;
+ }
+ v = v + 1;
+ targetMap.put(i, v);
}
+ } catch(IOException e){
}
}
return count;