|
@@ -8,8 +8,12 @@ import org.objectweb.asm.commons.AdviceAdapter;
|
|
|
|
|
|
public class ProtectionInjector extends ClassVisitor {
|
|
|
|
|
|
+ private String superName;
|
|
|
+
|
|
|
private final Project project;
|
|
|
|
|
|
+ private boolean isOnCreateExist = false;
|
|
|
+
|
|
|
public ProtectionInjector(ClassVisitor cv, Project project) {
|
|
|
super(Opcodes.ASM9, cv);
|
|
|
this.project = project;
|
|
@@ -18,6 +22,7 @@ public class ProtectionInjector extends ClassVisitor {
|
|
|
@Override
|
|
|
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
|
|
String[] newInterfaces = append(interfaces, "io/nexilis/ui/Callback");
|
|
|
+ this.superName = superName;
|
|
|
super.visit(version, access, name, signature, superName, newInterfaces);
|
|
|
}
|
|
|
|
|
@@ -32,6 +37,7 @@ public class ProtectionInjector extends ClassVisitor {
|
|
|
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
|
|
MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions);
|
|
|
if ("onCreate".equals(name) && "(Landroid/os/Bundle;)V".equals(descriptor)) {
|
|
|
+ isOnCreateExist = true;
|
|
|
return new InjectDetectionLibraryMethodVisitor(api, mv, access, name, descriptor, project);
|
|
|
}
|
|
|
return mv;
|
|
@@ -54,17 +60,37 @@ public class ProtectionInjector extends ClassVisitor {
|
|
|
@Override
|
|
|
protected void onMethodExit(int opcode) {
|
|
|
super.onMethodExit(opcode);
|
|
|
- mv.visitLdcInsn(project != null ? (project.getProperties().get("nexilis.appId") == null ? "" : project.getProperties().get("nexilis.appId")) : "");
|
|
|
- mv.visitLdcInsn(project != null ? (project.getProperties().get("nexilis.account") == null ? "" : project.getProperties().get("nexilis.account")) : "");
|
|
|
- mv.visitVarInsn(ALOAD, 0);
|
|
|
- mv.visitLdcInsn(project != null ? (project.getProperties().get("nexilis.floatingMode") == null ? 0 : project.getProperties().get("nexilis.floatingMode")) : 0);
|
|
|
- mv.visitVarInsn(ALOAD, 0);
|
|
|
- mv.visitMethodInsn(INVOKESTATIC, "io/nexilis/ui/API", "connect", "(Ljava/lang/String;Ljava/lang/String;Landroid/app/Activity;ILio/nexilis/ui/Callback;)V", false);
|
|
|
+ injectConnect(mv, project);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static void injectConnect(MethodVisitor mv, Project project) {
|
|
|
+ mv.visitLdcInsn(project != null ? (project.getProperties().get("nexilis.appId") == null ? "" : project.getProperties().get("nexilis.appId")) : "");
|
|
|
+ mv.visitLdcInsn(project != null ? (project.getProperties().get("nexilis.account") == null ? "" : project.getProperties().get("nexilis.account")) : "");
|
|
|
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
|
|
|
+ mv.visitLdcInsn(project != null ? (project.getProperties().get("nexilis.floatingMode") == null ? 0 : Integer.parseInt(String.valueOf(project.getProperties().get("nexilis.floatingMode")))) : 0);
|
|
|
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
|
|
|
+ mv.visitMethodInsn(Opcodes.INVOKESTATIC, "io/nexilis/ui/API", "connect", "(Ljava/lang/String;Ljava/lang/String;Landroid/app/Activity;ILio/nexilis/ui/Callback;)V", false);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void visitEnd() {
|
|
|
+ if (!isOnCreateExist) {
|
|
|
+ MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "onCreate", "(Landroid/os/Bundle;)V", null, null);
|
|
|
+ if (mv != null) {
|
|
|
+ mv.visitCode();
|
|
|
+
|
|
|
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
|
|
|
+ mv.visitVarInsn(Opcodes.ALOAD, 1);
|
|
|
+ mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "onCreate", "(Landroid/os/Bundle;)V", false);
|
|
|
+
|
|
|
+ injectConnect(mv, project);
|
|
|
+
|
|
|
+ mv.visitInsn(Opcodes.RETURN);
|
|
|
+ mv.visitMaxs(1, 1);
|
|
|
+ mv.visitEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "onSuccess", "(Ljava/lang/String;)V", null, null);
|
|
|
if (mv != null) {
|
|
|
mv.visitCode();
|