Search in sources :

Example 1 with MergePatch

use of com.taobao.android.apatch.MergePatch in project atlas by alibaba.

the class APatchTool method doPatch.

@Override
public PatchFile doPatch() throws Exception {
    APatchFile patchFile = new APatchFile();
    ApatchInput apatchInput = (ApatchInput) input;
    mappingMap = apatchInput.mappingMap;
    if (apatchInput.mappingMap.get(apatchInput.replaceAnnotation) != null) {
        MethodReplaceAnnotation.ANNOTATION = apatchInput.mappingMap.get(apatchInput.replaceAnnotation);
    }
    File patchTmpDir = new File(input.outPutFile.getParentFile(), "apatch-tmp");
    patchTmpDir.mkdirs();
    patchFile.aDiffText = new File(input.outPutFile.getParentFile(), "apatch-diff.txt");
    patchFile.diffJson = new File(input.outPutFile.getParentFile(), "apatch-diff.json");
    FileUtils.deleteQuietly(patchFile.aDiffText);
    patchFile.aDiffText.createNewFile();
    // unzip apk
    File unzipFolder = unzipApk(patchTmpDir);
    final File newApkUnzipFolder = new File(unzipFolder, NEW_APK_UNZIP_NAME);
    final File baseApkUnzipFolder = new File(unzipFolder, BASE_APK_UNZIP_NAME);
    // first generate main bundle patch file
    List<File> aPatches = createBundleAPatch(newApkUnzipFolder, baseApkUnzipFolder, patchTmpDir, apatchInput.andfixMainBundleName, patchFile.aDiffText, patchFile.diffJson);
    // second generate common bundle patch file
    // 
    Collection<File> soFiles = FileUtils.listFiles(newApkUnzipFolder, new String[] { "so" }, true);
    if (input.splitDiffBundle != null) {
        for (Pair<BundleBO, BundleBO> bundle : input.splitDiffBundle) {
            if (bundle.getFirst() == null || bundle.getSecond() == null) {
                continue;
            }
            List<File> aPatchFiles = processBundleFiles(bundle.getSecond().getBundleFile(), bundle.getFirst().getBundleFile(), patchTmpDir, patchFile.aDiffText, patchFile.diffJson);
            if (null != aPatchFiles) {
                for (File aPatchFile : aPatchFiles) {
                    if (null != aPatchFile && aPatchFile.exists()) {
                        aPatches.add(aPatchFile);
                    }
                }
            }
        }
    }
    for (File soFile : soFiles) {
        String relativePath = PathUtils.toRelative(newApkUnzipFolder, soFile.getAbsolutePath());
        if (null != apatchInput.notIncludeFiles && pathMatcher.match(apatchInput.notIncludeFiles, relativePath)) {
            continue;
        }
        File baseSoFile = new File(baseApkUnzipFolder, relativePath);
        if (PatchUtils.isBundleFile(soFile)) {
            // if bundle file
            List<File> aPatchFiles = processBundleFiles(soFile, baseSoFile, patchTmpDir, patchFile.aDiffText, patchFile.diffJson);
            if (null != aPatchFiles) {
                for (File aPatchFile : aPatchFiles) {
                    if (null != aPatchFile && aPatchFile.exists()) {
                        aPatches.add(aPatchFile);
                    }
                }
            }
        }
    }
    if (aPatches.size() <= 0) {
        throw new Exception("No apatch files! No classes modify!");
    }
    // merge apatch file
    File[] aPatchFiles = new File[aPatches.size()];
    aPatchFiles = aPatches.toArray(aPatchFiles);
    File mergePatchFile = null;
    if (null != aPatchFiles && aPatchFiles.length > 1) {
        MergePatch mergePatch = new MergePatch(aPatchFiles, apatchInput.projectArtifactId, patchTmpDir);
        mergePatchFile = mergePatch.doMerge();
    } else if (null != aPatchFiles && aPatchFiles.length == 1) {
        mergePatchFile = aPatchFiles[0];
    }
    if (null != mergePatchFile && mergePatchFile.exists()) {
        FileUtils.moveFile(mergePatchFile, input.outPutFile);
    }
    FileUtils.deleteDirectory(unzipFolder);
    FileUtils.deleteDirectory(patchTmpDir);
    patchFile.patchFile = input.outPutFile;
    return patchFile;
}
Also used : BundleBO(com.taobao.android.tpatch.model.BundleBO) ApatchInput(com.taobao.android.inputs.ApatchInput) APatchFile(com.taobao.android.outputs.APatchFile) File(java.io.File) APatchFile(com.taobao.android.outputs.APatchFile) PatchFile(com.taobao.android.outputs.PatchFile) MergePatch(com.taobao.android.apatch.MergePatch) IOException(java.io.IOException) RecognitionException(org.antlr.runtime.RecognitionException) PatchException(com.taobao.android.differ.dex.PatchException)

Example 2 with MergePatch

use of com.taobao.android.apatch.MergePatch in project atlas by alibaba.

the class APatchTool method doPatch.

/**
     * 生成patch文件
     *
     * @param outPatchFile
     * @param projectArtifactId
     */
public void doPatch(File outPatchFile, String projectArtifactId) throws Exception {
    isApatch = true;
    if (mappingMap.get(replaceAnnotation) != null) {
        MethodReplaceAnnotation.ANNOTATION = mappingMap.get(replaceAnnotation);
    }
    File patchTmpDir = new File(outPatchFile.getParentFile(), "apatch-tmp");
    patchTmpDir.mkdirs();
    File adiffFile = new File(outPatchFile.getParentFile(), "apatch-diff.txt");
    File adiffJsonFile = new File(outPatchFile.getParentFile(), "apatch-diff.json");
    FileUtils.deleteQuietly(adiffFile);
    adiffFile.createNewFile();
    // 解压apk
    File unzipFolder = unzipApk(patchTmpDir);
    final File newApkUnzipFolder = new File(unzipFolder, NEW_APK_UNZIP_NAME);
    final File baseApkUnzipFolder = new File(unzipFolder, BASE_APK_UNZIP_NAME);
    // 生成主bundle的tpatch文件
    List<File> aPatches = createBundleAPatch(newApkUnzipFolder, baseApkUnzipFolder, patchTmpDir, andfixMainBundleName, adiffFile, adiffJsonFile);
    // 生成bundle的tpatch文件
    // 判断主bundle的so和awb的插件
    Collection<File> soFiles = FileUtils.listFiles(newApkUnzipFolder, new String[] { "so" }, true);
    for (File soFile : soFiles) {
        String relativePath = PathUtils.toRelative(newApkUnzipFolder, soFile.getAbsolutePath());
        if (null != notIncludeFiles && pathMatcher.match(notIncludeFiles, relativePath)) {
            continue;
        }
        File baseSoFile = new File(baseApkUnzipFolder, relativePath);
        if (PatchUtils.isBundleFile(soFile)) {
            // 如果是bundle文件
            List<File> aPatchFiles = processBundleFiles(soFile, baseSoFile, patchTmpDir, adiffFile, adiffJsonFile);
            if (null != aPatchFiles) {
                for (File aPatchFile : aPatchFiles) {
                    if (null != aPatchFile && aPatchFile.exists()) {
                        aPatches.add(aPatchFile);
                    }
                }
            }
        }
    }
    if (aPatches.size() <= 0) {
        throw new Exception("No apatch files! No classes modify!");
    }
    // 合并aPatch文件
    // 4. 合并apatch文件
    File[] aPatchFiles = new File[aPatches.size()];
    aPatchFiles = aPatches.toArray(aPatchFiles);
    File mergePatchFile = null;
    if (null != aPatchFiles && aPatchFiles.length > 1) {
        MergePatch mergePatch = new MergePatch(aPatchFiles, projectArtifactId, patchTmpDir);
        mergePatchFile = mergePatch.doMerge();
    } else if (null != aPatchFiles && aPatchFiles.length == 1) {
        mergePatchFile = aPatchFiles[0];
    }
    if (null != mergePatchFile && mergePatchFile.exists()) {
        FileUtils.moveFile(mergePatchFile, outPatchFile);
    }
    FileUtils.deleteDirectory(unzipFolder);
    FileUtils.deleteDirectory(patchTmpDir);
}
Also used : File(java.io.File) MergePatch(com.taobao.android.apatch.MergePatch) IOException(java.io.IOException) RecognitionException(org.antlr.runtime.RecognitionException) PatchException(com.taobao.android.differ.dex.PatchException)

Example 3 with MergePatch

use of com.taobao.android.apatch.MergePatch in project atlas by alibaba.

the class FastPatchTool method doPatch.

public void doPatch() throws IOException, PatchException, RecognitionException {
    MappingReader mappingReader = null;
    MappingProcessor mappingProcessor = null;
    if (outDir == null || !outDir.exists()) {
        return;
    }
    outPatchFile = new File(outDir, "apatch-unsigned.apatch");
    if (mappingFile != null && mappingFile.exists()) {
        mappingReader = new MappingReader(mappingFile);
        mappingProcessor = new MappingProcessorImpl(superClassMap);
        mappingReader.pump(mappingProcessor);
        mappingProcessor.updateMethod();
        mappingProcessor.updateFieldType();
    }
    for (FastPatchObject fastPatchObject : patchObjects) {
        Set<ClassDef> classes = new HashSet<ClassDef>();
        Map<ClassDef, List<Method>> patchClassDefs = new HashMap<ClassDef, List<Method>>();
        Set<ClassDef> addedClasses = new HashSet<ClassDef>();
        Map<ClassDef, List<Method>> newClassDef = new HashMap<ClassDef, List<Method>>();
        ArrayList<Method> methods = new ArrayList<Method>();
        for (File dexFile : fastPatchObject.DexFiles) {
            DexFile dFile = DexFileFactory.loadDexFile(dexFile.getAbsolutePath(), 19, true);
            classes.addAll(dFile.getClasses());
        }
        final Set<ClassDef> newClasses = new HashSet<ClassDef>();
        for (ClassDef classDef : classes) {
            String type = classDef.getType();
            if (fastPatchObject.addedClass.contains(SmaliUtils.getDalvikClassName(type))) {
                System.out.println("patch added class:" + type);
                addedClasses.add(classDef);
                continue;
            }
            for (Map.Entry<String, List<String>> entry : fastPatchObject.modifyClasses.entrySet()) {
                if (entry.getKey().equals(SmaliUtils.getDalvikClassName(type))) {
                    ArrayList<Method> newMethods = new ArrayList<Method>();
                    for (Method method : classDef.getMethods()) {
                        System.err.println(getMethodFullName(method));
                        if (entry.getValue().contains(getMethodFullName(method))) {
                            newMethods.add(method);
                        }
                    }
                    patchClassDefs.put(classDef, newMethods);
                    break;
                }
            }
        }
        if (patchClassDefs.size() == 0 && addedClasses.size() == 0) {
            continue;
        }
        if (mappingFile != null && mappingFile.exists()) {
            //第一步先将prepareclass混淆掉
            for (String className : fastPatchObject.prepareClasses) {
                ApkPatch.prepareClasses.add(mappingProcessor.getNewClassName(className).className);
            }
            //将replaceanatation混淆掉
            MethodReplaceAnnotation.ANNOTATION = DefineUtils.getDefineClassName(mappingProcessor.getNewClassName(DefineUtils.getDalvikClassName("Lcom/alipay/euler/andfix/annotation/MethodReplace;")).className, false);
            //将dex代码混淆掉
            InsTructionsReIClassDef insTructionsReDef = new InsTructionsReIClassDef(new MappingClassProcessor(mappingProcessor));
            for (ClassDef c : classes) {
                if (patchClassDefs.containsKey(c)) {
                    for (Method method : c.getMethods()) {
                        if (patchClassDefs.get(c).contains(method)) {
                            methods.add(insTructionsReDef.reMethod(method));
                        }
                    }
                    newClassDef.put(insTructionsReDef.reClassDef(c), methods);
                } else if (addedClasses.contains(c)) {
                    newClassDef.put(insTructionsReDef.reClassDef(c), new ArrayList<Method>());
                }
                if (c.getType().contains("/R$")) {
                    continue;
                }
                newClasses.add(insTructionsReDef.reClassDef(c));
            }
        } else {
            ApkPatch.prepareClasses.addAll(fastPatchObject.prepareClasses);
        }
        File patchDexFile = new File(outDir, "patch.dex");
        for (ClassDef classDef : newClassDef.keySet()) {
            System.out.println("modify class:" + classDef.getType());
        }
        if (newClassDef.size() > 0) {
            DexFileFactory.writeDexFile(patchDexFile.getAbsolutePath(), new ImmutableDexFile(newClassDef.keySet()));
        } else if (patchClassDefs.size() > 0) {
            DexFileFactory.writeDexFile(patchDexFile.getAbsolutePath(), new ImmutableDexFile(patchClassDefs.keySet()));
        }
        File tempDexFile = new File(outDir, "temp.dex");
        if (newClasses.size() > 0) {
            DexFileFactory.writeDexFile(tempDexFile.getAbsolutePath(), new DexFile() {

                @Nonnull
                @Override
                public Set<? extends ClassDef> getClasses() {
                    return new AbstractSet<ClassDef>() {

                        @Nonnull
                        @Override
                        public Iterator<ClassDef> iterator() {
                            return newClasses.iterator();
                        }

                        @Override
                        public int size() {
                            return newClasses.size();
                        }
                    };
                }
            });
        } else if (classes.size() > 0) {
            DexFileFactory.writeDexFile(tempDexFile.getAbsolutePath(), new ImmutableDexFile(classes));
        }
        SmaliDiffUtils.scanClasses(new File(outDir, "smali2"), Lists.newArrayList(tempDexFile));
        DexFile patchDex = DexFileFactory.loadDexFile(patchDexFile.getAbsolutePath(), 19, true);
        DexFile tempDex = DexFileFactory.loadDexFile(tempDexFile.getAbsolutePath(), 19, true);
        Set<? extends ClassDef> patchClasses = patchDex.getClasses();
        DexDiffInfo dexDiffInfo = new DexDiffInfo();
        for (ClassDef patchClassDef : patchClasses) {
            String type = patchClassDef.getType();
            if (fastPatchObject.addedClass.contains(SmaliUtils.getDalvikClassName(type))) {
                dexDiffInfo.getAddedClasses().add((DexBackedClassDef) patchClassDef);
                dexDiffInfo.addManifestAddClass(type);
                continue;
            }
            for (Method method : patchClassDef.getMethods()) {
                List<? extends CharSequence> parameters = method.getParameterTypes();
                if (methods.size() > 0) {
                    for (Method modifyMethod : methods) {
                        List<? extends CharSequence> modifyParameters = modifyMethod.getParameterTypes();
                        if (parameters.size() != modifyParameters.size() || !isEqualObj(parameters, modifyParameters)) {
                            continue;
                        }
                        if (modifyMethod.getName().equals(method.getName()))
                            dexDiffInfo.addModifiedMethods((DexBackedMethod) method);
                    }
                } else if (patchClassDefs.size() > 0) {
                    for (ClassDef classDef : patchClassDefs.keySet()) {
                        if (classDef.getType().equals(patchClassDef.getType())) {
                            List<Method> methodList = patchClassDefs.get(classDef);
                            for (Method method1 : methodList) {
                                if (method1.getName().equals(method.getName())) {
                                    dexDiffInfo.addModifiedMethods((DexBackedMethod) method);
                                }
                            }
                        }
                    }
                }
            }
        }
        FastBuild fastBuild = new FastBuild(fastPatchObject.bundleName, new File(outDir, bundleName));
        fastBuild.setClasses(tempDex.getClasses());
        fastBuild.setDiffInfo(dexDiffInfo);
        new AndFixFilterImpl(dexDiffInfo).filterDex();
        dexDiffInfo.update();
        APatchTool.isApatch = true;
        File adiffFile = new File(outDir, "apatch-diff.txt");
        File adiffJsonFile = new File(outDir, "apatch-diff.json");
        dexDiffInfo.writeToFile(fastPatchObject.bundleName, adiffFile, adiffJsonFile);
        try {
            File patchJarFile = fastBuild.dopatch();
            patchJarFiles.add(patchJarFile);
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        } catch (UnrecoverableEntryException e) {
            e.printStackTrace();
        }
    }
    File[] aPatchFiles = new File[patchJarFiles.size()];
    aPatchFiles = patchJarFiles.toArray(aPatchFiles);
    File mergePatchFile = null;
    if (null != aPatchFiles && aPatchFiles.length > 1) {
        MergePatch mergePatch = new MergePatch(aPatchFiles, "com_taobao_android", outDir);
        mergePatchFile = mergePatch.doMerge();
    } else if (null != aPatchFiles && aPatchFiles.length == 1) {
        mergePatchFile = aPatchFiles[0];
    }
    if (null != mergePatchFile && mergePatchFile.exists()) {
        FileUtils.moveFile(mergePatchFile, outPatchFile);
    }
}
Also used : DexBackedMethod(org.jf.dexlib2.dexbacked.DexBackedMethod) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef) InsTructionsReIClassDef(com.taobao.android.repatch.InsTructionsReIClassDef) ClassDef(org.jf.dexlib2.iface.ClassDef) MappingReader(com.taobao.android.repatch.mapping.MappingReader) UnrecoverableEntryException(java.security.UnrecoverableEntryException) Nonnull(javax.annotation.Nonnull) AndFixFilterImpl(com.taobao.android.apatch.AndFixFilterImpl) MappingClassProcessor(com.taobao.android.repatch.processor.MappingClassProcessor) Method(org.jf.dexlib2.iface.Method) DexBackedMethod(org.jf.dexlib2.dexbacked.DexBackedMethod) KeyStoreException(java.security.KeyStoreException) FastBuild(com.taobao.android.apatch.FastBuild) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) DexFile(org.jf.dexlib2.iface.DexFile) DexDiffInfo(com.taobao.android.object.DexDiffInfo) FastPatchObject(com.taobao.android.repatch.FastPatchObject) MappingProcessor(com.taobao.android.repatch.mapping.MappingProcessor) MappingProcessorImpl(com.taobao.android.repatch.mapping.MappingProcessorImpl) InsTructionsReIClassDef(com.taobao.android.repatch.InsTructionsReIClassDef) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) File(java.io.File) DexFile(org.jf.dexlib2.iface.DexFile) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) MergePatch(com.taobao.android.apatch.MergePatch)

Example 4 with MergePatch

use of com.taobao.android.apatch.MergePatch in project atlas by alibaba.

the class FastPatchTool method doPatch.

public void doPatch() throws IOException, PatchException, RecognitionException {
    MappingReader mappingReader = null;
    MappingProcessor mappingProcessor = null;
    if (outDir == null || !outDir.exists()) {
        return;
    }
    outPatchFile = new File(outDir, "apatch-unsigned.apatch");
    if (mappingFile != null && mappingFile.exists()) {
        mappingReader = new MappingReader(mappingFile);
        mappingProcessor = new MappingProcessorImpl(superClassMap);
        mappingReader.pump(mappingProcessor);
        mappingProcessor.updateMethod();
        mappingProcessor.updateFieldType();
    }
    for (FastPatchObject fastPatchObject : patchObjects) {
        Set<ClassDef> classes = new HashSet<ClassDef>();
        Map<ClassDef, List<Method>> patchClassDefs = new HashMap<ClassDef, List<Method>>();
        Set<ClassDef> addedClasses = new HashSet<ClassDef>();
        Map<ClassDef, List<Method>> newClassDef = new HashMap<ClassDef, List<Method>>();
        ArrayList<Method> methods = new ArrayList<Method>();
        for (File dexFile : fastPatchObject.DexFiles) {
            DexFile dFile = DexFileFactory.loadDexFile(dexFile.getAbsolutePath(), Opcodes.getDefault());
            classes.addAll(dFile.getClasses());
        }
        final Set<ClassDef> newClasses = new HashSet<ClassDef>();
        for (ClassDef classDef : classes) {
            String type = classDef.getType();
            if (fastPatchObject.addedClass.contains(SmaliUtils.getDalvikClassName(type))) {
                System.out.println("patch added class:" + type);
                addedClasses.add(classDef);
                continue;
            }
            for (Map.Entry<String, List<String>> entry : fastPatchObject.modifyClasses.entrySet()) {
                if (entry.getKey().equals(SmaliUtils.getDalvikClassName(type))) {
                    ArrayList<Method> newMethods = new ArrayList<Method>();
                    for (Method method : classDef.getMethods()) {
                        System.err.println(getMethodFullName(method));
                        if (entry.getValue().contains(getMethodFullName(method))) {
                            newMethods.add(method);
                        }
                    }
                    patchClassDefs.put(classDef, newMethods);
                    break;
                }
            }
        }
        if (patchClassDefs.size() == 0 && addedClasses.size() == 0) {
            continue;
        }
        if (mappingFile != null && mappingFile.exists()) {
            // 第一步先将prepareclass混淆掉
            for (String className : fastPatchObject.prepareClasses) {
                ApkPatch.prepareClasses.add(mappingProcessor.getNewClassName(className).className);
            }
            // 将replaceanatation混淆掉
            MethodReplaceAnnotation.ANNOTATION = DefineUtils.getDefineClassName(mappingProcessor.getNewClassName(DefineUtils.getDalvikClassName("Lcom/alipay/euler/andfix/annotation/MethodReplace;")).className, false);
            // 将dex代码混淆掉
            InsTructionsReIClassDef insTructionsReDef = new InsTructionsReIClassDef(new MappingClassProcessor(mappingProcessor));
            for (ClassDef c : classes) {
                if (patchClassDefs.containsKey(c)) {
                    for (Method method : c.getMethods()) {
                        if (patchClassDefs.get(c).contains(method)) {
                            methods.add(insTructionsReDef.reMethod(method));
                        }
                    }
                    newClassDef.put(insTructionsReDef.reClassDef(c), methods);
                } else if (addedClasses.contains(c)) {
                    newClassDef.put(insTructionsReDef.reClassDef(c), new ArrayList<Method>());
                }
                if (c.getType().contains("/R$")) {
                    continue;
                }
                newClasses.add(insTructionsReDef.reClassDef(c));
            }
        } else {
            ApkPatch.prepareClasses.addAll(fastPatchObject.prepareClasses);
        }
        File patchDexFile = new File(outDir, "patch.dex");
        for (ClassDef classDef : newClassDef.keySet()) {
            System.out.println("modify class:" + classDef.getType());
        }
        if (newClassDef.size() > 0) {
            DexFileFactory.writeDexFile(patchDexFile.getAbsolutePath(), new ImmutableDexFile(Opcodes.getDefault(), newClassDef.keySet()));
        } else if (patchClassDefs.size() > 0) {
            DexFileFactory.writeDexFile(patchDexFile.getAbsolutePath(), new ImmutableDexFile(Opcodes.getDefault(), patchClassDefs.keySet()));
        }
        File tempDexFile = new File(outDir, "temp.dex");
        if (newClasses.size() > 0) {
            DexFileFactory.writeDexFile(tempDexFile.getAbsolutePath(), new DexFile() {

                @Nonnull
                @Override
                public Set<? extends ClassDef> getClasses() {
                    return new AbstractSet<ClassDef>() {

                        @Nonnull
                        @Override
                        public Iterator<ClassDef> iterator() {
                            return newClasses.iterator();
                        }

                        @Override
                        public int size() {
                            return newClasses.size();
                        }
                    };
                }

                @Nonnull
                @Override
                public Opcodes getOpcodes() {
                    return Opcodes.getDefault();
                }
            });
        } else if (classes.size() > 0) {
            DexFileFactory.writeDexFile(tempDexFile.getAbsolutePath(), new ImmutableDexFile(Opcodes.getDefault(), classes));
        }
        SmaliDiffUtils.scanClasses(new File(outDir, "smali2"), Lists.newArrayList(tempDexFile));
        DexFile patchDex = DexFileFactory.loadDexFile(patchDexFile.getAbsolutePath(), Opcodes.getDefault());
        DexFile tempDex = DexFileFactory.loadDexFile(tempDexFile.getAbsolutePath(), Opcodes.getDefault());
        Set<? extends ClassDef> patchClasses = patchDex.getClasses();
        DexDiffInfo dexDiffInfo = new DexDiffInfo();
        for (ClassDef patchClassDef : patchClasses) {
            String type = patchClassDef.getType();
            if (fastPatchObject.addedClass.contains(SmaliUtils.getDalvikClassName(type))) {
                dexDiffInfo.getAddedClasses().add((DexBackedClassDef) patchClassDef);
                dexDiffInfo.addManifestAddClass(type);
                continue;
            }
            for (Method method : patchClassDef.getMethods()) {
                List<? extends CharSequence> parameters = method.getParameterTypes();
                if (methods.size() > 0) {
                    for (Method modifyMethod : methods) {
                        List<? extends CharSequence> modifyParameters = modifyMethod.getParameterTypes();
                        if (parameters.size() != modifyParameters.size() || !isEqualObj(parameters, modifyParameters)) {
                            continue;
                        }
                        if (modifyMethod.getName().equals(method.getName()))
                            dexDiffInfo.addModifiedMethods((DexBackedMethod) method);
                    }
                } else if (patchClassDefs.size() > 0) {
                    for (ClassDef classDef : patchClassDefs.keySet()) {
                        if (classDef.getType().equals(patchClassDef.getType())) {
                            List<Method> methodList = patchClassDefs.get(classDef);
                            for (Method method1 : methodList) {
                                if (method1.getName().equals(method.getName())) {
                                    dexDiffInfo.addModifiedMethods((DexBackedMethod) method);
                                }
                            }
                        }
                    }
                }
            }
        }
        FastBuild fastBuild = new FastBuild(fastPatchObject.bundleName, new File(outDir, bundleName));
        fastBuild.setClasses(tempDex.getClasses());
        fastBuild.setDiffInfo(dexDiffInfo);
        new AndFixFilterImpl(dexDiffInfo).filterDex();
        dexDiffInfo.update();
        File adiffFile = new File(outDir, "apatch-diff.txt");
        File adiffJsonFile = new File(outDir, "apatch-diff.json");
        dexDiffInfo.writeToFile(fastPatchObject.bundleName, adiffFile, adiffJsonFile);
        try {
            File patchJarFile = fastBuild.dopatch();
            patchJarFiles.add(patchJarFile);
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        } catch (UnrecoverableEntryException e) {
            e.printStackTrace();
        }
    }
    File[] aPatchFiles = new File[patchJarFiles.size()];
    aPatchFiles = patchJarFiles.toArray(aPatchFiles);
    File mergePatchFile = null;
    if (null != aPatchFiles && aPatchFiles.length > 1) {
        MergePatch mergePatch = new MergePatch(aPatchFiles, "com_taobao_android", outDir);
        mergePatchFile = mergePatch.doMerge();
    } else if (null != aPatchFiles && aPatchFiles.length == 1) {
        mergePatchFile = aPatchFiles[0];
    }
    if (null != mergePatchFile && mergePatchFile.exists()) {
        FileUtils.moveFile(mergePatchFile, outPatchFile);
    }
}
Also used : DexBackedMethod(org.jf.dexlib2.dexbacked.DexBackedMethod) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef) InsTructionsReIClassDef(com.taobao.android.repatch.InsTructionsReIClassDef) ClassDef(org.jf.dexlib2.iface.ClassDef) MappingReader(com.taobao.android.repatch.mapping.MappingReader) Opcodes(org.jf.dexlib2.Opcodes) UnrecoverableEntryException(java.security.UnrecoverableEntryException) Nonnull(javax.annotation.Nonnull) AndFixFilterImpl(com.taobao.android.apatch.AndFixFilterImpl) MappingClassProcessor(com.taobao.android.repatch.processor.MappingClassProcessor) Method(org.jf.dexlib2.iface.Method) DexBackedMethod(org.jf.dexlib2.dexbacked.DexBackedMethod) KeyStoreException(java.security.KeyStoreException) FastBuild(com.taobao.android.apatch.FastBuild) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) DexFile(org.jf.dexlib2.iface.DexFile) DexDiffInfo(com.taobao.android.object.DexDiffInfo) FastPatchObject(com.taobao.android.repatch.FastPatchObject) MappingProcessor(com.taobao.android.repatch.mapping.MappingProcessor) MappingProcessorImpl(com.taobao.android.repatch.mapping.MappingProcessorImpl) InsTructionsReIClassDef(com.taobao.android.repatch.InsTructionsReIClassDef) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) File(java.io.File) DexFile(org.jf.dexlib2.iface.DexFile) ImmutableDexFile(org.jf.dexlib2.immutable.ImmutableDexFile) MergePatch(com.taobao.android.apatch.MergePatch)

Aggregations

MergePatch (com.taobao.android.apatch.MergePatch)4 File (java.io.File)4 AndFixFilterImpl (com.taobao.android.apatch.AndFixFilterImpl)2 FastBuild (com.taobao.android.apatch.FastBuild)2 PatchException (com.taobao.android.differ.dex.PatchException)2 DexDiffInfo (com.taobao.android.object.DexDiffInfo)2 FastPatchObject (com.taobao.android.repatch.FastPatchObject)2 InsTructionsReIClassDef (com.taobao.android.repatch.InsTructionsReIClassDef)2 MappingProcessor (com.taobao.android.repatch.mapping.MappingProcessor)2 MappingProcessorImpl (com.taobao.android.repatch.mapping.MappingProcessorImpl)2 MappingReader (com.taobao.android.repatch.mapping.MappingReader)2 MappingClassProcessor (com.taobao.android.repatch.processor.MappingClassProcessor)2 IOException (java.io.IOException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableEntryException (java.security.UnrecoverableEntryException)2 CertificateException (java.security.cert.CertificateException)2 Nonnull (javax.annotation.Nonnull)2 RecognitionException (org.antlr.runtime.RecognitionException)2 DexBackedClassDef (org.jf.dexlib2.dexbacked.DexBackedClassDef)2