public VirtualMachine build(String smaliPath) throws IOException { return build(smaliPath, SmaliParser.DEFAULT_API_LEVEL); }
public VirtualMachine build(String smaliPath, int outputAPILevel) throws IOException { return build(smaliPath, outputAPILevel, DEFAULT_MAX_ADDRESS_VISITS, DEFAULT_MAX_CALL_DEPTH, DEFAULT_MAX_METHOD_VISITS, DEFAULT_MAX_EXECUTION_TIME); }
public VirtualMachine build(String smaliPath, int outputAPILevel, int maxAddressVisits, int maxCallDepth, int maxMethodVisits, int maxExecutionTime) throws IOException { return build(new File(smaliPath), outputAPILevel, maxAddressVisits, maxCallDepth, maxMethodVisits, maxExecutionTime); } }
public static void main(String[] args) throws Exception { // The SMALI_PATH directory is populated using dumpSmali.sh and contains converted code from org.cf.demosmali. // You can use a link to a DEX, APK, or directory with Smali files. VirtualMachineFactory vmFactory = new VirtualMachineFactory(); vm = vmFactory.build(SMALI_PATH); // The smali code contains System.out.println()s used for debugging, but smalivm won't execute this method // because it's not white listed because it affects state outside of the VM. Also, smalivm doesn't have a // "screen" to send output. This hooks those method calls with our own implementation to actually print stuff. MethodEmulator .addMethod("Ljava/io/PrintStream;->println(Ljava/lang/String;)V", java_io_PrintStream_println.class); // Execute demo smali's main() method vm.execute("Lorg/cf/demosmali/Main;->main([Ljava/lang/String;)V"); executePrintParameter(42); executeParameterLogicWithUnknownParameter(); executeParameterLogicWithKnownParameter(10); }
public void run(String[] args) throws IOException, UnhandledVirtualException { opts = getOptions(args); setLogLevel(opts); log.info("Options:\n{}", opts.toString()); RuntimeStats stats = new RuntimeStats(); stats.begin(); vm = vmFactory.build( opts.getInFile(), opts.getOutputAPILevel(), opts.getMaxAddressVisits(), opts.getMaxCallDepth(), opts.getMaxMethodVisits(), opts.getMaxExecutionTime() ); ClassManager classManager = vm.getClassManager(); Map<String, Collection<VirtualMethod>> targetClassNameToMethods = collectTargetClassNameToMethods(classManager, opts); stats.startClasses(targetClassNameToMethods.keySet()); for (Map.Entry<String, Collection<VirtualMethod>> entry : targetClassNameToMethods.entrySet()) { stats.incrementCurrentClassIndex(); String className = entry.getKey(); Collection<VirtualMethod> methods = entry.getValue(); System.out.println("[" + stats.getCurrentClassIndex() + " / " + stats.getTotalClasses() + "] Processing top level class " + className); executeMethods(methods, classManager, stats); } stats.end(); System.out.println("Simplification complete:\n" + stats.getStats()); System.out.println(Optimizer.getTotalOptimizationCounts()); System.out.println("Writing output to " + opts.getOutFile()); classManager.getDexBuilder().writeTo(new FileDataStore(opts.getOutDexFile())); if (opts.isZip()) { Files.copy(opts.getInFile().toPath(), opts.getOutFile().toPath(), StandardCopyOption.REPLACE_EXISTING); updateZip(opts.getOutFile(), opts.getOutDexFile(), "classes.dex"); } }
/** * Create a new {@link VirtualMachine} for testing. Since this is heavily used, it tries to avoid the main cost of creating a {@link * VirtualMachine} by reusing the same {@link ClassManager} by default. If {@code reloadClasses} is true, a new {@link ClassManager} is created * and all classes are loaded again. This is necessary if method implementations are modified. For example, Simplify optimization strategy tests * modify method implementation and in order for each test to have the true method implementations, many of those tests set {@code reloadClasses} * to {@code true}. * * @param reloadClasses if true, rebuild {@link ClassManager}, otherwise reuse existing * @return {@link VirtualMachine} for tests */ public static VirtualMachine spawnVM(boolean reloadClasses) { if ((null == classManager) || reloadClasses) { try { classManager = new ClassManagerFactory().build(TEST_CLASS_PATH, getDexBuilder()); } catch (IOException e) { throw new RuntimeException("Exception building class manager for " + TEST_CLASS_PATH, e); } } return new VirtualMachineFactory().build(classManager); }
e1.printStackTrace(); stats.incrementFailedMethodCount(); vm = vmFactory.build( classManager, opts.getMaxAddressVisits(), opts.getMaxCallDepth(), opts.getMaxMethodVisits(), opts.getMaxExecutionTime() stats.incrementFailedMethodCount(); vm = vmFactory .build(classManager, opts.getMaxAddressVisits(), opts.getMaxCallDepth(), opts.getMaxMethodVisits(), opts.getMaxExecutionTime()); break;