Search in sources :

Example 1 with Configuration

use of com.tencent.mm.resourceproguard.Configuration in project AndResGuard by shwenzhang.

the class ARSCDecoder method readEntry.

/**
     * 需要防止由于某些非常恶心的白名单,导致出现重复id
     *
     * @throws IOException
     * @throws AndrolibException
     */
private void readEntry() throws IOException, AndrolibException {
    mIn.skipBytes(2);
    short flags = mIn.readShort();
    int specNamesId = mIn.readInt();
    if (mPkg.isCanProguard()) {
        //混效过,或者已经添加到白名单的都不需要再处理了
        if (!mProguardBuilder.isReplaced(mCurEntryID) && !mProguardBuilder.isInWhiteList(mCurEntryID)) {
            Configuration config = mApkDecoder.getConfig();
            boolean isWhiteList = false;
            if (config.mUseWhiteList) {
                //判断是否走whitelist
                HashMap<String, HashMap<String, HashSet<Pattern>>> whiteList = config.mWhiteList;
                String packName = mPkg.getName();
                if (whiteList.containsKey(packName)) {
                    HashMap<String, HashSet<Pattern>> typeMaps = whiteList.get(packName);
                    String typeName = mType.getName();
                    if (typeMaps.containsKey(typeName)) {
                        String specName = mSpecNames.get(specNamesId).toString();
                        HashSet<Pattern> patterns = typeMaps.get(typeName);
                        for (Iterator<Pattern> it = patterns.iterator(); it.hasNext(); ) {
                            Pattern p = it.next();
                            if (p.matcher(specName).matches()) {
                                mPkg.putSpecNamesReplace(mResId, specName);
                                mPkg.putSpecNamesblock(specName);
                                mProguardBuilder.setInWhiteList(mCurEntryID, true);
                                mType.putSpecProguardName(specName);
                                isWhiteList = true;
                                break;
                            }
                        }
                    }
                }
            }
            String replaceString = null;
            if (!isWhiteList) {
                boolean keepMapping = false;
                if (config.mUseKeepMapping) {
                    HashMap<String, HashMap<String, HashMap<String, String>>> resMapping = config.mOldResMapping;
                    String packName = mPkg.getName();
                    if (resMapping.containsKey(packName)) {
                        HashMap<String, HashMap<String, String>> typeMaps = resMapping.get(packName);
                        String typeName = mType.getName();
                        if (typeMaps.containsKey(typeName)) {
                            //这里面的东东已经提前去掉,请放心使用
                            HashMap<String, String> proguard = typeMaps.get(typeName);
                            String specName = mSpecNames.get(specNamesId).toString();
                            if (proguard.containsKey(specName)) {
                                keepMapping = true;
                                replaceString = proguard.get(specName);
                            }
                        }
                    }
                }
                if (!keepMapping) {
                    replaceString = mProguardBuilder.getReplaceString();
                }
                mProguardBuilder.setInReplaceList(mCurEntryID, true);
                if (replaceString == null) {
                    throw new AndrolibException("readEntry replaceString == null");
                }
                generalResIDMapping(mPkg.getName(), mType.getName(), mSpecNames.get(specNamesId).toString(), replaceString);
                mPkg.putSpecNamesReplace(mResId, replaceString);
                mPkg.putSpecNamesblock(replaceString);
                mType.putSpecProguardName(replaceString);
            }
        }
    }
    boolean readDirect;
    if ((flags & ENTRY_FLAG_COMPLEX) == 0) {
        readDirect = true;
        readValue(readDirect, specNamesId);
    } else {
        readDirect = false;
        readComplexEntry(readDirect, specNamesId);
    }
}
Also used : Pattern(java.util.regex.Pattern) Configuration(com.tencent.mm.resourceproguard.Configuration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AndrolibException(com.tencent.mm.androlib.AndrolibException) HashSet(java.util.HashSet)

Example 2 with Configuration

use of com.tencent.mm.resourceproguard.Configuration in project AndResGuard by shwenzhang.

the class CliMain method loadConfigFromXml.

private void loadConfigFromXml(File configFile, File signatureFile, File mappingFile, String keypass, String storealias, String storepass) {
    if (configFile == null) {
        configFile = new File(mRunningLocation + File.separator + TypedValue.CONFIG_FILE);
        if (!configFile.exists()) {
            System.err.printf("the config file %s does not exit", configFile.getAbsolutePath());
            printUsage(System.err);
            System.exit(ERRNO_USAGE);
        }
    }
    try {
        config = new Configuration(configFile, m7zipPath, mZipalignPath);
        //需要检查命令行的设置
        if (mSetSignThroughCmd) {
            config.setSignData(signatureFile, keypass, storealias, storepass);
        }
        if (mSetMappingThroughCmd) {
            config.setKeepMappingData(mappingFile);
        }
    } catch (IOException | ParserConfigurationException | SAXException e) {
        e.printStackTrace();
        goToError();
    }
}
Also used : Configuration(com.tencent.mm.resourceproguard.Configuration) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) SAXException(org.xml.sax.SAXException)

Example 3 with Configuration

use of com.tencent.mm.resourceproguard.Configuration in project AndResGuard by shwenzhang.

the class ARSCDecoder method proguardFileName.

private void proguardFileName() throws IOException, AndrolibException {
    mMappingWriter = new BufferedWriter(new FileWriter(mApkDecoder.getResMappingFile(), false));
    mProguardBuilder = new ProguardStringBuilder();
    mProguardBuilder.reset();
    final Configuration config = mApkDecoder.getConfig();
    File rawResFile = mApkDecoder.getRawResFile();
    File[] resFiles = rawResFile.listFiles();
    //需要看看哪些类型是要混淆文件路径的
    for (File resFile : resFiles) {
        String raw = resFile.getName();
        if (raw.contains("-")) {
            raw = raw.substring(0, raw.indexOf("-"));
        }
        mShouldProguardTypeSet.add(raw);
    }
    if (!config.mKeepRoot) {
        //需要保持之前的命名方式
        if (config.mUseKeepMapping) {
            HashMap<String, String> fileMapping = config.mOldFileMapping;
            List<String> keepFileNames = new ArrayList<String>();
            //这里面为了兼容以前,也需要用以前的文件名前缀,即res混淆成什么
            String resRoot = TypedValue.RES_FILE_PATH;
            for (String name : fileMapping.values()) {
                int dot = name.indexOf("/");
                if (dot == -1) {
                    throw new IOException(String.format("the old mapping res file path should be like r/a, yours %s\n", name));
                }
                resRoot = name.substring(0, dot);
                keepFileNames.add(name.substring(dot + 1));
            }
            //去掉所有之前保留的命名,为了简单操作,mapping里面有的都去掉
            mProguardBuilder.removeStrings(keepFileNames);
            for (File resFile : resFiles) {
                String raw = "res" + "/" + resFile.getName();
                if (fileMapping.containsKey(raw)) {
                    mOldFileName.put(raw, fileMapping.get(raw));
                } else {
                    mOldFileName.put(raw, resRoot + "/" + mProguardBuilder.getReplaceString());
                }
            }
        } else {
            for (int i = 0; i < resFiles.length; i++) {
                //这里也要用linux的分隔符,如果普通的话,就是r
                mOldFileName.put("res" + "/" + resFiles[i].getName(), TypedValue.RES_FILE_PATH + "/" + mProguardBuilder.getReplaceString());
            }
        }
        generalFileResMapping();
    }
    Utils.cleanDir(mApkDecoder.getOutResFile());
}
Also used : Configuration(com.tencent.mm.resourceproguard.Configuration) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Aggregations

Configuration (com.tencent.mm.resourceproguard.Configuration)3 File (java.io.File)2 IOException (java.io.IOException)2 AndrolibException (com.tencent.mm.androlib.AndrolibException)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Pattern (java.util.regex.Pattern)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXException (org.xml.sax.SAXException)1