use of com.googlecode.d2j.visitors.DexFileVisitor in project dex2jar by pxb1988.
the class SmaliCmd method doCommandLine.
@Override
protected void doCommandLine() throws Exception {
if (showVersionThenExits) {
System.out.println("smali 1.4.2p (https://sourceforge.net/p/dex2jar)");
System.out.println("Copyright (c) 2009-2013 Panxiaobo (pxb1988@gmail.com)");
System.out.println("Apache license (http://www.apache.org/licenses/LICENSE-2.0)");
return;
}
if (!readSmaliFromStdin && remainingArgs.length < 1) {
System.err.println("ERRPR: no file to process");
return;
}
if (output == null) {
output = new File("out.dex").toPath();
}
Smali smali = new Smali();
DexFileWriter fw = new DexFileWriter();
DexFileVisitor fv = new DexFileVisitor(fw) {
@Override
public void visitEnd() {
// intercept the call to super
}
};
if (readSmaliFromStdin) {
smali.smaliFile("<stdin>", System.in, fv);
System.err.println("smali <stdin> -> " + output);
}
for (String s : remainingArgs) {
Path file = new File(s).toPath();
if (!Files.exists(file)) {
System.err.println("skip " + file + ", it is not a dir or a file");
} else {
System.err.println("smali " + s + " -> " + output);
smali.smali(file, fv);
}
}
fw.visitEnd();
byte[] data = fw.toByteArray();
Files.write(output, data);
}
use of com.googlecode.d2j.visitors.DexFileVisitor in project dex2jar by pxb1988.
the class DexWeaverCmd method doCommandLine.
@Override
protected void doCommandLine() throws Exception {
if (remainingArgs.length == 0) {
throw new HelpException("no odex");
}
final Map<String, Method> map = new HashMap<>();
for (String ln : Files.readAllLines(config, StandardCharsets.UTF_8)) {
if (ln.startsWith("#") || ln.length() == 0) {
continue;
}
String[] x = ln.split("=");
map.put(x[0], parseMethod(x[1]));
}
DexFileWriter out = new DexFileWriter();
DexFileVisitor fv = new DexFileVisitor(out) {
@Override
public DexClassVisitor visit(int access_flags, String className, String superClass, String[] interfaceNames) {
DexClassVisitor dcv = super.visit(access_flags, className, superClass, interfaceNames);
if (dcv != null) {
return new DexClassVisitor(dcv) {
@Override
public DexMethodVisitor visitMethod(int accessFlags, Method method) {
DexMethodVisitor dmv = super.visitMethod(accessFlags, method);
if (dmv != null) {
return new DexMethodVisitor(dmv) {
@Override
public DexCodeVisitor visitCode() {
DexCodeVisitor code = super.visitCode();
if (code != null) {
return new DexCodeVisitor(code) {
@Override
public void visitMethodStmt(Op op, int[] args, Method method) {
Method replaceTo = map.get(method.toString());
if (replaceTo != null) {
switch(op) {
case INVOKE_DIRECT:
case INVOKE_INTERFACE:
case INVOKE_STATIC:
case INVOKE_SUPER:
case INVOKE_VIRTUAL:
super.visitMethodStmt(Op.INVOKE_STATIC, args, replaceTo);
break;
case INVOKE_DIRECT_RANGE:
case INVOKE_INTERFACE_RANGE:
case INVOKE_STATIC_RANGE:
case INVOKE_SUPER_RANGE:
case INVOKE_VIRTUAL_RANGE:
super.visitMethodStmt(Op.INVOKE_STATIC_RANGE, args, replaceTo);
break;
default:
}
} else {
super.visitMethodStmt(op, args, method);
}
}
};
}
return code;
}
};
}
return dmv;
}
};
}
return dcv;
}
@Override
public void visitEnd() {
}
};
for (String f : remainingArgs) {
byte[] data = ZipUtil.readDex(new File(f).toPath());
DexFileReader r = new DexFileReader(data);
r.accept(fv);
}
if (stub != null) {
byte[] data = ZipUtil.readDex(stub);
DexFileReader r = new DexFileReader(data);
r.accept(new DexFileVisitor(out) {
@Override
public void visitEnd() {
}
});
}
out.visitEnd();
byte[] data = out.toByteArray();
Files.write(output, data);
}
Aggregations