Ejemplo n.º 1
0
        // 生成包名对应的
        private static void createBuildConfig(String TargetDir, String packageName, Cmd.Callback call)
        {
            String PackageStr = packageName.Trim('.').Replace('.', '/');    // 形如 com/ltsdk_56_base/leshi
            String content    =
                ".class public final L" + PackageStr + "/BuildConfig;" + "\r\n" +
                ".super Ljava/lang/Object;" + "\r\n" +
                ".source \"BuildConfig.java\"" + "\r\n" +
                "\r\n" +
                "\r\n" +
                "# static fields" + "\r\n" +
                ".field public static final DEBUG:Z = true" + "\r\n" +
                "\r\n" +
                "\r\n" +
                "# direct methods" + "\r\n" +
                ".method public constructor <init>()V" + "\r\n" +
                "    .locals 0" + "\r\n" +
                "\r\n" +
                "    .prologue" + "\r\n" +
                "    .line 4" + "\r\n" +
                "    invoke-direct {p0}, Ljava/lang/Object;-><init>()V" + "\r\n" +
                "\r\n" +
                "    return-void" + "\r\n" +
                ".end method" + "\r\n" + "\r\n";

            // 保存BuildConfig文件到指定包名目录
            FileProcess.SaveProcess(content, TargetDir + "\\BuildConfig.smali");
            if (call != null)
            {
                call("【I】" + PackageStr + "/BuildConfig.smali 已生成..");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 在线获取网游,渠道列表信息
        /// </summary>
        public static Dictionary <String, String> getChannelList(Cmd.Callback call = null)
        {
            string url = "http://netunion.joymeng.com/index.php?m=Api&c=PackTool&a=channelList";

            if (call != null)
            {
                call("【I】 联网获取渠道列表信息...\r\n" + url);
            }
            string str = WebSettings.getWebData(url);

            if (str.Equals(""))
            {
                if (call != null)
                {
                    call("【E】 联网获取渠道列表信息失败!请点击链接查看网络是否正常");
                }
                return(new Dictionary <string, string>());
            }
            else
            {
                channelList_Data iteam = channelList_Data.Parse(str);

                if (call != null)
                {
                    call("【I】 获取渠道列表信息完成");
                }

                return(iteam.data);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加渠道附加资源
        /// </summary>
        private static void addChannelAttachs(ToolSetting toolSet, Cmd.Callback call, String dirSource, String channelAttachDir, String Set_channelId)
        {
            // 获取渠道附加目录资源路径
            String channelDir = toolSet.chargeAPK_dir + "\\" + Set_channelId;
            //String channelAttachDir = channelDir + "\\附加资源";
            String channelAttachDir2 = channelDir + channelAttachDir;

            // 复制渠道附加目录中的文件
            if (Directory.Exists(channelAttachDir2) && !ApkCombine.isEmptyDirectorty(channelAttachDir2))
            {
                bool isEmptyDir = ApkCombine.isEmptyDirectorty(channelAttachDir);

                if (!isEmptyDir && call != null)
                {
                    call("【I】");
                }
                if (!isEmptyDir && call != null)
                {
                    call("【I】复制," + channelAttachDir);
                }
                ApkCombine.CopyFolderTo(channelAttachDir2, dirSource, true, call);
                if (!isEmptyDir && call != null)
                {
                    call("【I】复制," + channelAttachDir + "完成");
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// config.txt文件合并逻辑,将SourceConfig中的所有配置合并到TargetConfig中
        /// </summary>
        public static void Config_Combine(String SourceConfig, String TargetConfig, Cmd.Callback call = null, bool useDirMode = true)
        {
            if (useDirMode)
            {
                SourceConfig = SourceConfig + "\\assets\\ltsdk_res\\config.txt";
                TargetConfig = TargetConfig + "\\assets\\ltsdk_res\\config.txt";
            }

            LT_config config = new LT_config();

            config.load_ConfigFile(TargetConfig);   // 载入目标config配置信息

            string data = FileProcess.fileToString(SourceConfig);

            if (!data.Equals(""))                   // 载入修改的配置信息
            {
                config.AddValues(data);
            }

            // 确保目标路径存在
            String parentDir = TargetConfig.Substring(0, TargetConfig.LastIndexOf("\\config.txt"));

            ToolSetting.confirmDir(parentDir);

            config.save();                          // 保存配置信息

            if (call != null)
            {
                call("【I】混合" + SourceConfig + "到\r\n" + TargetConfig + "中");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 使用OneUtil4Perpre_cmd.jar执行命令
        /// set oldname=%1
        /// set newname=%oldname:.apk=%
        /// java -jar %~dp0OneUtil4Perpre_cmd.jar "%oldname%" "%newname%"
        ///
        /// 从给定的apk文件apkPath在路径desDir下生成perpre.dat
        /// </summary>
        public static String genPerpre_dat(String apkPath, String desDir, Cmd.Callback call)
        {
            String preperTool = AddQuotation(modifyResDir() + "OneUtil4Perpre_cmd.jar");
            String arg        = AddQuotation(apkPath) + " " + AddQuotation(desDir);
            String cmdStr     = "java -jar " + preperTool + " " + arg;

            return(Cmd.Run(cmdStr, call));   // 调用cmd命令,运行apktool.jar
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 添加游戏附加资源
        /// </summary>
        private static void addGameAttachs(ToolSetting toolSet, Cmd.Callback call, String dirTarget, String gameAttachDir, String Set_gameId, String Set_channelId, String tittle = "")
        {
            // 获取选中的游戏包所在的目录的附加资源
            //toolSet.gameAPK_dir + "\\" + Settings.gameId + "\\"
            String selectGameDir = toolSet.gameAPK_dir + "\\" + Set_gameId;

            //String selectVersionDir = Form4.SelectVersionDir;
            //String[] attachDirs = { selectGameDir + "\\游戏Icon或Logo", selectVersionDir + "\\附加资源" };
            //foreach (String gameAttachDir0 in attachDirs)
            {
                String gameAttachDir2 = selectGameDir + gameAttachDir;     // 生成附加资源路径

                // 复制游戏附加目录中的文件
                List <String> list_channel = new List <string>();
                list_channel.Add("所有渠道");
                list_channel.Add(Set_channelId);

                bool isEmptyDir = ApkCombine.isEmptyDirectorty(gameAttachDir2);
                if (!isEmptyDir && call != null)
                {
                    call("【I】");
                }
                if (!isEmptyDir && call != null)
                {
                    call("【I】复制," + gameAttachDir + (tittle.Equals("") ? "" : ("到" + tittle)));
                }
                foreach (String channelId in list_channel)
                {
                    String Dir = gameAttachDir2 + "\\" + channelId;
                    isEmptyDir = ApkCombine.isEmptyDirectorty(Dir);

                    // 拷贝游戏附加资源目录
                    if (channelId != null && !channelId.Equals("") && Directory.Exists(Dir) && !ApkCombine.isEmptyDirectorty(Dir))
                    {
                        if (!isEmptyDir && call != null)
                        {
                            call("【I】复制," + gameAttachDir + "\\" + channelId);
                        }
                        ApkCombine.CopyFolderTo(Dir, dirTarget, true, call);
                        if (!isEmptyDir && call != null)
                        {
                            call("【I】复制," + gameAttachDir + "\\" + channelId + " 完成");
                        }
                    }
                }
            }

            // 复制游戏Icon、Logo
            if (gameAttachDir.Equals("\\游戏Icon或Logo") && StartParam.AutoRun && Form4.channelIconDir.ContainsKey(Set_channelId))
            {
                String ICONDIR = Form4.channelIconDir[Set_channelId];
                if (!ICONDIR.Equals("") && Directory.Exists(ICONDIR))
                {
                    ApkCombine.CopyFolderTo(ICONDIR, dirTarget + @"\res\drawable", true, call);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 执行cmd修改命令,修改xmlPath对应的xml文件
        /// </summary>
        public static void modify(string xmlPath, string cmd, Cmd.Callback call = null)
        {
            if (System.IO.File.Exists(xmlPath))
            {
                XML_File xml = new XML_File(xmlPath);
                xml.runCMD(cmd);

                if (call != null)
                {
                    call("【I3】 " + "对文件" + xmlPath + ",执行修改逻辑" + cmd);
                }
            }
        }
Ejemplo n.º 8
0
        //==========================
        // apk解包打包逻辑封装

        /// <summary>
        /// 若为apk文件,则先行解包
        /// </summary>
        public static String apkUnpack(String apkFile, Cmd.Callback call, bool deletPublicXML = false)
        {
            // 若输入的为apk文件,则自动进行解包
            if (Apktool.isApkFile(apkFile))
            {
                if (call != null)
                {
                    call("【I】" + Path.GetFileName(apkFile));
                }
                if (call != null)
                {
                    call("【I】apk解包开始...");
                }

                string dir = Apktool.unPackage(apkFile, call, deletPublicXML);   // 使用apktool进行apk的解包
                if (dir.Contains("【E】"))
                {
                    return(dir);
                }

                if (call != null)
                {
                    call("【I】apk解包结束!\r\n");
                }

                // 拷贝apk目录下的配置文件到解包文件所在目录
                String configTxt  = apkFile.Replace(".apk", ".txt");
                String configTxt2 = apkFile.Replace(".apk", "-" + Settings.gameId + ".txt");    // 可按游戏获取游戏id对应的配置文件
                if (File.Exists(configTxt2) && !File.Exists(dir + ".txt"))
                {
                    File.Copy(configTxt2, dir + ".txt", false);
                }
                else if (File.Exists(configTxt) && !File.Exists(dir + ".txt"))
                {
                    File.Copy(configTxt, dir + ".txt", false);
                }

                if (File.Exists(dir + ".txt"))
                {
                    // 添加游戏附加配置信息到渠道包,打包配置中
                    String gameAttachConfig = ToolSetting.Instance().serverRoot + "游戏附加配置\\" + Settings.gameId + ".txt";
                    Settings.AppendSettingsTo(gameAttachConfig, dir + ".txt");
                }

                return(dir);
            }
            else
            {
                return(apkFile);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 从一个目录dirTarget中移除文件或目录
        /// </summary>
        public static void RemoveDirFile(string dirTarget, Cmd.Callback call = null, Settings setting = null)
        {
            //检查是否存在目的目录
            if (!Directory.Exists(dirTarget))
            {
                return;
            }

            // 删除所有目录
            foreach (String iteam in setting.deletGameDir)
            {
                // 删除目录
                String subDir = Path.Combine(dirTarget, iteam);
                if (Directory.Exists(subDir))
                {
                    if (call != null)
                    {
                        call("【I2】删除目录:" + subDir);
                    }
                    Directory.Delete(subDir, true);
                }

                // 删除文件
                String parentDir = subDir.Substring(0, subDir.LastIndexOf("\\"));
                if (Directory.Exists(parentDir))
                {
                    DirectoryInfo directoryInfo = new DirectoryInfo(parentDir);
                    FileInfo[]    files         = directoryInfo.GetFiles();
                    foreach (FileInfo file in files)
                    {
                        String relative = relativePath(file.FullName, dirTarget);  // 获取相对路径名
                        if (setting.deletGameDir.Contains(relative) || setting.deletGameDir.Contains(IgnoreExtension(relative)))
                        {
                            if (call != null)
                            {
                                call("【I2】删除文件:" + file.FullName);
                            }
                            file.Delete();
                        }
                    }
                }
            }

            // 移除文件或目录后,清空信息
            setting.deletGameDir.Clear();
        }
Ejemplo n.º 10
0
        // 将节点<public type="attr" name="circle_radius" id="0x7f010000" />转化为name到id的映射表
        private static Dictionary <String, String> toIdDic(List <xmlNode> listTar, Cmd.Callback call)
        {
            Dictionary <String, String> dic = new Dictionary <String, String>();

            foreach (xmlNode iteam in listTar)
            {
                String type = iteam.attributes.Get("type");
                String name = type + ":" + iteam.attributes.Get("name");    // 以type:name标识一个特定的id值
                String id   = iteam.attributes.Get("id");
                if (!dic.ContainsKey(name))
                {
                    dic.Add(name, id);
                }
                else if (call != null)
                {
                    call("【E】public.xml文件中存在重复的同名节点:" + name);
                }
            }

            return(dic);
        }
Ejemplo n.º 11
0
        static bool showCopyInfo = false;  // 是否显示复制信息

        /// <summary>
        /// 对两个apk解包后的文件进行混合,复制目录dirSource下的文件到dirDest中
        /// </summary>
        public static void Combine(String dirSource, String dirDest, Cmd.Callback call)
        {
            if (Apktool.isApkDir(dirDest) && Apktool.isApkDir(dirSource))
            {
                Cmd.Callback tmp = Settings.call;   // 记录call

                Settings.call = call;
                Settings setting = Settings.Load(dirSource, dirDest);

                //setting.GetPackageName_GAMEPRE_CHANNEL(dirSource, dirDest);      // 更新渠道参数信息

                // 若设置为使用所有渠道通用基础配置,则拷贝混合基础配置信息到游戏包
                if (setting.useAllChannelCommon)
                {
                    ToolSetting toolSet = ToolSetting.Instance();                               // 载入配置信息
                    //String AllChannelCommon = toolSet.chargeAPK_dir + "\\所有渠道\\附加资源";   // 获取所有渠道配置目录
                    //ToolSetting.confirmDir(AllChannelCommon);

                    //// 混合所有渠道公用配置
                    //if (!ApkCombine.isEmptyDirectorty(AllChannelCommon))
                    //{
                    //    if (call != null) call("【L】拷贝所有渠道附加资源:");
                    //    Combine(AllChannelCommon, dirDest, call);
                    //    if (call != null) call("【I】拷贝所有渠道附加资源完成!");
                    //}

                    String commonDir = toolSet.chargeAPK_dir + "\\所有渠道";                      // 获取所有渠道配置目录
                    Dictionary <String, String> apk_dirs = Form3.getApk_FileOrDir(commonDir); // 获取目录下的apk文件或解压目录
                    if (apk_dirs.Count > 0)
                    {
                        String apk_dir = apk_dirs.Values.ToArray <String>()[0];
                        if (call != null)
                        {
                            call("【I】");
                        }
                        if (call != null)
                        {
                            call("【I】---------------------------------");
                        }
                        if (call != null)
                        {
                            call("【L】混合,所有渠道,通用基础包资源:\r\n" + apk_dir);
                        }

                        // 所有渠道通用apk解包
                        String AllChannelCommon = Form2.apkUnpack(apk_dir, call);     // 获取所有渠道配置目录
                        if (AllChannelCommon.Contains("【E】"))
                        {
                            return;
                        }

                        // 混合所有渠道公用配置
                        if (!ApkCombine.isEmptyDirectorty(AllChannelCommon))
                        {
                            if (call != null)
                            {
                                call("【L】拷贝所有渠道附加资源:");
                            }
                            Combine(AllChannelCommon, dirDest, call);
                            if (call != null)
                            {
                                call("【I】拷贝所有渠道附加资源完成!");
                            }
                        }
                        if (call != null)
                        {
                            call("【I】---------------------------------\r\n");
                        }

                        // 拷贝所有渠道配置中的【其他渠道参数替换文件列表】
                        string   str        = FileProcess.fileToString(AllChannelCommon + ".txt");
                        Settings allChannel = Settings.Parse(str);
                        setting.addSettings(allChannel, 5);
                        setting.ReplaceLateParams();            // 替换设置的关键字信息为在线获取的参数

                        // 清除所有渠道通用配置缓存
                        Apktool.DeletDir(AllChannelCommon);
                        Apktool.DeletFile(AllChannelCommon + ".txt");   // 清除配置文件信息
                    }
                }


                if (call != null)
                {
                    call("【L】1、拷贝文件前,清除游戏包中指定的文件:");
                }
                RemoveDirFile(dirDest, call, setting);


                if (call != null)
                {
                    call("【L】2、复制所有文件,并忽略忽略列表中的文件和目录:");
                }
                CopyFolderTo_Ignore(dirSource, dirDest, call, setting);    // 复制所有文件,并忽略忽略列表中的文件和目录


                if (call != null)
                {
                    call("【L】3、附加拷贝,附加列表中的文件和目录:");
                }
                CopyFolderTo_addCopyDir(dirSource, dirDest, call, setting); // 附加拷贝,附加列表中的文件和目录
                RemoveDirFile(dirDest, call, setting);                      // 清除复制时,原有目录


                String ManifestPath = dirDest + "\\" + "AndroidManifest.xml";
                if (File.Exists(ManifestPath))
                {
                    if (call != null)
                    {
                        call("【L】4、修改Manifest.xml文件:");
                    }

                    Manifest manifest = new Manifest(ManifestPath);        // 创建Manifest对象
                    Settings.gameLabel = manifest.label;                   // 获取游戏显示名称,如: @string/app_name

                    manifest.runCMD(setting.ManifestCMD);                  // 执行manifest修改逻辑
                    manifest.save();                                       // 保存manifest
                    Settings.gameIcon = manifest.icon;                     // 获取游戏图标名称,如: @drawable/icon
                }


                setting.ReplaceFiles_ChannelParams(dirDest);                // 替换其他文件中配置的渠道参数变量
                setting.ProcessIcon(dirDest);                               // 处理icon


                Settings.call = tmp;    //还原call
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取rootDir目录下,文件内容包含name字段的所有文件
        /// </summary>
        public static void ReplaceFileContent(String rootDir, String source, String target, Cmd.Callback call = null)
        {
            if (source.Equals(target))
            {
                return;                        // 原串与目标串相同则不需要替换
            }
            if (File.Exists(rootDir))
            {
                String content = fileToString(rootDir);         // 获取文件内容
                if (content.Contains(source))                   // 替换为目标串
                {
                    content = content.Replace(source, target);
                    SaveProcess(content, rootDir);

                    if (call != null)
                    {
                        call("【I】修改" + source + "->" + target + ",文件路径:" + rootDir);
                    }
                }
            }

            // 检测目录下文件并替换
            if (Directory.Exists(rootDir))
            {
                List <String> Dirs = getFile_List(rootDir, source);
                foreach (String dir in Dirs)
                {
                    ReplaceFileContent(dir, source, target, call);
                }
            }
        }
Ejemplo n.º 13
0
        public static void updateIds(String fileSource, String fileTarget, String pNameSrc, String pNameTar, List <xmlNode> listSrc, List <xmlNode> listTar, Cmd.Callback call, bool delet = false)
        {
            String data       = FileProcess.fileToString(fileSource);
            bool   isSameFile = fileSource.Equals(fileTarget);             // 源文件与目标文件为同一个文件

            String packageNameSrc = pNameSrc.Trim('.').Replace('.', '/');  // 原有包名,如 com/ltsdk_56_base/leshi
            String packageNameTar = pNameTar.Trim('.').Replace('.', '/');

            if (data.Contains(packageNameSrc) && !isSameFile)
            {
                data = data.Replace(packageNameSrc, packageNameTar);// 修改包名信息
                if (call != null)
                {
                    call("【I】修改包名信息," + packageNameSrc + "->" + packageNameTar);
                }
            }
            data = updateIds(data, listSrc, listTar, call);         // 修改id信息
        }
Ejemplo n.º 14
0
        public static List <String> generateResTypeList;                  // 混合资源R类型


        // 执行R文件资源id生成逻辑
        public static bool Start(String dirTarget, String dirSource, Cmd.Callback call, bool apktool_yml_process = false, bool R_Process_Game = false)
        {
            if (call != null)
            {
                call("【L】5、R$*smali资源编译,逻辑开始...");
            }
            String GAMEPRE_package = Settings.channel_param["GAMEPRE_package"];     // 游戏原有包名
            String CHANNEL_package = Settings.channel_param["CHANNEL_package"];     // 渠道包原有包名
            String package         = Settings.channel_param["package"];             // 获取包名信息

            // 获取游戏包和渠道包,R资源id信息
            if (call != null)
            {
                call("【I】- 1.获取游戏包和渠道包,R资源id信息");
            }
            R_process.gameResDic    = R_process.getResDic(dirTarget + @"\res\values\public.xml", call);
            R_process.channelResDic = R_process.getResDic(dirSource + @"\res\values\public.xml", call);

            //获取游戏包和渠道包,解包路径下的R文件类型信息
            if (call != null)
            {
                call("【I】-   获取游戏包和渠道包,解包路径下的R文件类型信息");
            }
            R_process.gameResTypeList    = R_process.getRes_typeList(dirTarget, GAMEPRE_package);
            R_process.channelResTypeList = R_process.getRes_typeList(dirSource, CHANNEL_package);


            // 根据现有资源,生成新的R$type.smali文件
            bool R_result = R_process.UpdatePublicXML(dirTarget, call);                                     // 从游戏解包资源生成新的public.xml

            if (!R_result)
            {
                return(false);
            }

            R_process.genrateResDic = R_process.getResDic(dirTarget + @"\res\values\public.xml", call);  // 获取新生成的R资源id信息

            if (call != null)
            {
                call("【I】- 6.根据public.xml中资源id信息,生成新的R$*.smali文件...");
            }
            R_process.rebuidR_smali(genrateResDic, dirTarget + "\\smali", package, call);   // 重新生成包名路径下的R文件
            R_process.generateResTypeList = R_process.getRes_typeList(dirTarget, package);  // 获取新的包名路径下,现有的R文件类型信息

            // 复制原有包名路径和渠道包名路径下,其它R.smali文件到新的包名路径下
            copyR_smali(dirTarget, dirTarget, GAMEPRE_package, package, gameResTypeList, generateResTypeList, gameResDic, genrateResDic, call, true);
            copyR_smali(dirSource, dirTarget, CHANNEL_package, package, channelResTypeList, generateResTypeList, channelResDic, genrateResDic, call);

            R_process.generateResTypeList = R_process.getRes_typeList(dirTarget, package);  // 重新获取新的包名路径下,现有的R文件类型信息
            CreateR_smali(generateResTypeList, dirTarget + "\\smali", package, call);       // 根据现有的R资源类型生成对应R.smali文件

            // 修改smal路径下,原有包名路径信息到新的包名路径信息
            ReplaceSmaliPackagePath(dirTarget, GAMEPRE_package, package);
            ReplaceSmaliPackagePath(dirTarget, CHANNEL_package, package);

            // 修改所有非包名路径下的R文件中的id信息
            if (call != null)
            {
                call("【I】- 7.修改所有非包名路径下的R文件中的id信息");
            }
            //if (call != null) call("【I】- 7.暂时屏蔽");
            updateALL_RIds(dirTarget, package, gameResDic, channelResDic, genrateResDic, call, R_Process_Game);

            if (call != null)
            {
                call("【I】R$*.smali文件处理结束\r\n");
            }

            if (apktool_yml_process)
            {
                appendunknown(dirTarget, call);                         // 修改apktool.yml中的Unknown文件列表
            }
            return(true);
        }
Ejemplo n.º 15
0
        // 替换解包smali路径下所有R文件路径,从sourcePackage到targetPackage
        private static void ReplaceSmaliPackagePath(String unpackDir, String sourcePackage, String targetPackage, Cmd.Callback call = null)
        {
            unpackDir    += "\\smali";
            sourcePackage = sourcePackage.Replace(".", "/") + "/R";
            targetPackage = targetPackage.Replace(".", "/") + "/R";

            ReplaceValues.ReplaceFileContent(unpackDir, sourcePackage, targetPackage, call);
        }
Ejemplo n.º 16
0
        // 根据type类型从Src拷贝仅存在与Src中的项到Target目录下
        private static void copyR_smali(String source, String target, String pNameSrc, String pNameTar, List <String> typeListSrc, List <String> typeListTar, Dictionary <String, List <xmlNode> > DicSrc, Dictionary <String, List <xmlNode> > DicTar, Cmd.Callback call, bool delet = false)
        {
            String SourcePath = source + "\\smali\\" + pNameSrc.Trim('.').Replace('.', '\\');    // 形如 com\ltsdk_56_base\leshi
            String TargetPath = target + "\\smali\\" + pNameTar.Trim('.').Replace('.', '\\');

            DependentFiles.checkDir(TargetPath);

            foreach (String type in typeListSrc)
            {
                String name       = "R$" + type + ".smali";
                String fileSource = SourcePath + "\\" + name;          // 获取type类型对应的smali文件
                String fileTarget = TargetPath + "\\" + name;
                if (File.Exists(fileSource))
                {
                    if (!typeListTar.Contains(type))                   // 该smali文件之前未曾生成,则自动复制
                    {
                        List <xmlNode> listSrc = new List <xmlNode>();
                        List <xmlNode> listTar = new List <xmlNode>();

                        if (DicSrc.ContainsKey(type))
                        {
                            listSrc = DicSrc[type];
                        }
                        else
                        {
                            listSrc = DicSrc["AllType"];
                        }
                        //{
                        //    if (call != null) call("【I】" + SourcePath + "对应的public.xml不含有type类型:" + type);
                        //    //listSrc = ToListNode(DicSrc);   // 获取DicSrc中所有节点id信息
                        //}

                        if (DicTar.ContainsKey(type))
                        {
                            listTar = DicTar[type];
                        }
                        else
                        {
                            listTar = DicTar["AllType"];
                        }
                        //{
                        //    if (call != null) call("【I】" + TargetPath + "对应的public.xml不含有type类型:" + type);
                        //    //listTar = ToListNode(DicTar);   // 获取DicTar中所有节点id信息
                        //}

                        if (call != null)
                        {
                            call("【I】复制" + name + "从" + SourcePath + "->" + TargetPath);
                        }
                        //File.Copy(fileSource, fileTarget, true);
                        MoveR_smali(fileSource, fileTarget, pNameSrc, pNameTar, listSrc, listTar, call, delet);
                    }
                    else if (delet && !fileSource.Equals(fileTarget)) // 原文件与目标文件不是相同文件,则删除
                    {
                        File.Delete(fileSource);
                        if (call != null)
                        {
                            call("【I】删除文件," + fileSource);
                        }
                    }
                }
                else if (call != null)
                {
                    call("【I】文件丢失," + fileSource + "...");
                }
            }

            if (delet) // 删除原有的R.smali
            {
                String fileSource = SourcePath + "\\R.smali";
                if (File.Exists(fileSource))
                {
                    File.Delete(fileSource);
                    if (call != null)
                    {
                        call("【I】删除文件," + fileSource);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 添加Dir2中目录和文件到Dir中
        /// 若Dir中没有,该文件或目录,则直接复制
        /// 若有,则合并、替换、或不操作
        ///
        /// 从一个目录将其内容复制到另一目录, 忽略列表中的文件或目录补拷贝
        /// </summary>
        public static void CopyFolderTo_Ignore(string dirSource, string dirTarget, Cmd.Callback call, Settings setting)
        {
            // 若当前拷贝的目录为忽略的目录,则不拷贝
            string relative = relativePath(dirSource, setting.Path);    // 获取当前拷贝目录的相对路径

            if (setting.ingnoreDir.Contains(relative))                  // 若在忽略列表中,则不复制
            {
                if (call != null)
                {
                    call("【I2】忽略目录:" + dirSource);
                }
                return;
            }
            else if (call != null)
            {
                call("【I】复制目录:" + relative);
            }

            if (!havePath(setting.ingnoreDir, relative))    // 若拷贝的目录不包含忽略列表中的文件,则拷贝整个文件夹
            {
                CopyFolderTo(dirSource, dirTarget, true, call, setting);
                return;
            }
            else
            {
                // 检查是否存在目的目录
                if (!Directory.Exists(dirTarget))
                {
                    Directory.CreateDirectory(dirTarget);
                }


                //先来复制文件
                DirectoryInfo directoryInfo = new DirectoryInfo(dirSource);
                FileInfo[]    files         = directoryInfo.GetFiles();

                //复制所有文件
                foreach (FileInfo file in files)
                {
                    String fileSource = Path.Combine(file.DirectoryName, file.Name);
                    String fileTarget = Path.Combine(dirTarget, file.Name);
                    relative = relativePath(fileSource, setting.Path);  // 获取相对路径名
                    if (setting.ingnoreDir.Contains(relative) || setting.ingnoreDir.Contains(IgnoreExtension(relative)))
                    {
                        if (call != null)
                        {
                            call("【I2】忽略文件:" + fileSource);
                        }
                        continue;
                    }
                    else
                    {
                        if (File.Exists(fileTarget))
                        {
                            // 执行替换文件逻辑
                            replaceFile(fileSource, fileTarget, relative, call, setting);
                        }
                        else
                        {
                            if (showCopyInfo && call != null)
                            {
                                call("【I】复制文件:" + relative);
                            }
                            file.CopyTo(fileTarget, true);
                        }
                    }
                }

                //最后复制目录
                DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories();
                foreach (DirectoryInfo dir in directoryInfoArray)
                {
                    CopyFolderTo_Ignore(Path.Combine(dirSource, dir.Name), Path.Combine(dirTarget, dir.Name), call, setting);
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 从一个目录将其内容复制到另一目录
        /// </summary>
        public static void CopyFolderTo(string dirSource, string dirTarget, bool overwirite, Cmd.Callback call = null, Settings setting = null)
        {
            // 先获取Source目录下,当前的文件目录信息。在复制前先读取文件和目录信息,避免父目录向子目录复制时出现的无限复制循环,而只执行一次复制
            DirectoryInfo directoryInfo = new DirectoryInfo(dirSource);

            FileInfo[]      files = directoryInfo.GetFiles();
            DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories();

            // 存在文件或目录
            bool haveFileOrDir = ((files != null && files.Length > 0) || (directoryInfoArray != null && directoryInfoArray.Length > 0));

            //检查目标路径是否存在目的目录
            if (!Directory.Exists(dirTarget))
            {
                Directory.CreateDirectory(dirTarget);
            }

            //先来复制所有文件
            foreach (FileInfo file in files)
            {
                string fileSource = Path.Combine(file.DirectoryName, file.Name);
                string fileTarget = Path.Combine(dirTarget, file.Name);
                if (call != null && setting != null && overwirite)
                {
                    string relative = relativePath(fileSource, setting.Path);  // 获取相对路径名

                    if (File.Exists(fileTarget))
                    {
                        replaceFile(fileSource, fileTarget, relative, call, setting);
                    }
                    else
                    {
                        if (showCopyInfo)
                        {
                            call("【I】复制文件:" + relative);
                        }
                        file.CopyTo(fileTarget, overwirite);
                    }
                }
                else
                {
                    if (fileTarget.EndsWith(".xml"))
                    {
                        xmlCombine(fileSource, fileTarget, "", call, setting);
                    }
                    else
                    {
                        if (overwirite && call != null)
                        {
                            call("【I3】替换文件:" + fileTarget);
                        }
                        file.CopyTo(fileTarget, overwirite);
                    }
                }
            }

            //最后复制目录
            foreach (DirectoryInfo dir in directoryInfoArray)
            {
                CopyFolderTo(Path.Combine(dirSource, dir.Name), Path.Combine(dirTarget, dir.Name), overwirite, call, setting);
            }
        }
Ejemplo n.º 19
0
        // 移动Source路径下的smali文件,并执行修改
        // 修改包名、修改资源id信息
        private static void MoveR_smali(String fileSource, String fileTarget, String pNameSrc, String pNameTar, List <xmlNode> listSrc, List <xmlNode> listTar, Cmd.Callback call, bool delet = false)
        {
            String data       = FileProcess.fileToString(fileSource);
            bool   isSameFile = fileSource.Equals(fileTarget);             // 源文件与目标文件为同一个文件

            String packageNameSrc = pNameSrc.Trim('.').Replace('.', '/');  // 原有包名,如 com/ltsdk_56_base/leshi
            String packageNameTar = pNameTar.Trim('.').Replace('.', '/');

            if (data.Contains(packageNameSrc) && !isSameFile)
            {
                data = data.Replace(packageNameSrc, packageNameTar);// 修改包名信息
                if (call != null)
                {
                    call("【I】修改包名信息," + packageNameSrc + "->" + packageNameTar);
                }
            }
            data = updateIds(data, listSrc, listTar, call); // 修改id信息

            if (!isSameFile)                                // 不是同一个文件,执行替换或删除逻辑
            {
                if (File.Exists(fileTarget))
                {
                    FileProcess.SaveProcess(data, fileTarget);
                    if (call != null)
                    {
                        call("【W】替换文件," + fileSource + "->" + fileTarget);
                    }
                }
                else
                {
                    FileProcess.SaveProcess(data, fileTarget);         // 保存修改后的smali文件
                    if (call != null)
                    {
                        call("【I】保存修改到文件," + fileTarget);
                    }
                }

                if (delet)
                {
                    File.Delete(fileSource);
                    if (call != null)
                    {
                        call("【I】删除文件," + fileSource);
                    }
                }
            }
        }
Ejemplo n.º 20
0
        // 从public.xml创建res资源索引信息
        public static Dictionary <String, List <xmlNode> > getResDic(String publicXML, Cmd.Callback call = null)
        {
            // 按type类型分类子节点。 如节点,<public type="attr" name="pstsIndicatorColor" id="0x7f010004" />
            Dictionary <String, List <xmlNode> > resDic = new Dictionary <String, List <xmlNode> >();

            if (File.Exists(publicXML))
            {
                try
                {
                    String         xml  = FileProcess.fileToString(publicXML); // 获取新生成的public.xml文件内容
                    List <xmlNode> list = xmlNode.Parse(xml);                  // 解析xml文件内容
                    if (!(list.Count > 1 || !list[1].name.Equals("resources")))
                    {
                        return(resDic);                                                            // 第二个节点不是<resources>,则不再解析
                    }
                    // 获取<resources>节点
                    xmlNode root = list[1];
                    foreach (xmlNode iteam in root.childs)
                    {
                        String typeName = iteam.attributes.Get("type"); // 获取节点的type类型
                        if (!resDic.ContainsKey(typeName))              // 生成新的list
                        {
                            List <xmlNode> newTypeList = new List <xmlNode>();
                            resDic.Add(typeName, newTypeList);
                        }

                        List <xmlNode> typeList = resDic[typeName];     // 获取type类型对应的节点list
                        if (!typeList.Contains(iteam))                  // 添加节点到对应的typeList中
                        {
                            typeList.Add(iteam);
                        }
                    }

                    resDic.Add("AllType", root.childs);                 // 记录所有节点id信息
                }
                catch (Exception ex)
                {
                    if (call != null)
                    {
                        call("【E】- " + publicXML + "文件解析异常!\r\n " + ex.ToString());
                    }
                }
            }
            else if (call != null)
            {
                call("【E】- " + publicXML + "文件不存在,无资源id信息...");
            }

            return(resDic);
        }
Ejemplo n.º 21
0
        //从dirTarget目录下获取res资源,重新编译生成public.xml
        private static bool UpdatePublicXML(String dirTarget, Cmd.Callback call)
        {
            ToolSetting settting = ToolSetting.Instance();  // 载入设置信息

            if (call != null)
            {
                call("【I】- 2.解包Empty.apk");
            }
            String emptyApk = DependentFiles.curDir() + "\\tools\\Empty.apk";   // 空项目资源路径

            if (emptyApk.Contains("\\\\"))
            {
                emptyApk = emptyApk.Replace("\\\\", "\\");
            }
            String emptyDir = Apktool.unPackage(emptyApk, null, false);         // 解包空apk

            if (emptyDir.Contains("【E】") && call != null)
            {
                call("【E】  解包Empty.apk异常");
                return(false);
            }

            if (call != null)
            {
                call("【I】-   复制游戏res资源");
            }
            String Res = emptyDir + "\\res";

            ApkCombine.CopyFolderTo(dirTarget + "\\res", Res, true); // 复制Target目录到res目录,到空工程解包路径下

            Program.Delay(3000);                                     // 部分机器复制文件,存在异步延时,确保文件复制完成
            if (call != null)
            {
                call("【I】- 3.使用新的res资源,生成新的Empty.apk");
            }
            String apkFile = Apktool.package(emptyDir, null);                   // 使用apktool进行打包

            if (apkFile.Contains("【E】") && call != null)
            {
                call("【E】  打包Empty.apk异常");
                call("【E】  异常信息:" + apkFile);
                return(false);
            }

            if (call != null)
            {
                call("【I】- 4.解包Empty.apk");
            }
            string unpackDir = Apktool.unPackage(apkFile, null, false);         // 使用apktool进行apk的解包,生成新的public.xml

            if (unpackDir.Contains("【E】") || unpackDir.Trim().Equals(""))
            {
                if (call != null)
                {
                    call("【E】  解包Empty.apk异常");
                }
                return(false);
            }

            if (call != null)
            {
                call("【I】- 5.复制生成的public.xml文件,到游戏res目录中");
            }
            String relativePath = @"\res\values\public.xml";

            File.Copy(unpackDir + relativePath, dirTarget + relativePath, true);      // 替换原有public.xml

            relativePath = @"\res\drawable\empty_ic_launcher.png";
            File.Copy(unpackDir + relativePath, dirTarget + relativePath, true);
            relativePath = @"\res\layout\empty_activity_main.xml";
            File.Copy(unpackDir + relativePath, dirTarget + relativePath, true);

            if (call != null)
            {
                call("【I】-   清除Empty.apk相关缓存资源...");
            }

            // 清除缓存资源
            Directory.Delete(emptyDir, true);       // 删除空项目解包文件
            File.Delete(apkFile);                   // 删除生成的临时文件
            Directory.Delete(unpackDir, true);      // 删除空工程解包目录

            return(true);
        }
Ejemplo n.º 22
0
        // -------------------------------------------

        //unknownFiles:
        //com/tencent/mm/sdk/platformtools/rep5402863540997075488.tmp: '8'
        //com/fxlib/util/version.txt: '8'
        /// <summary>
        /// 修改apktool.yml中的Unknown文件列表
        /// </summary>
        public static void appendunknown(String dirTarget, Cmd.Callback call)
        {
            // 获取文件内容
            String apktoolYmlPath = dirTarget + "\\apktool.yml";
            String apktoolYml     = FileProcess.fileToString(apktoolYmlPath);
            String apktoolYml0    = apktoolYml;

            // 获取文件原有unknown部分
            String unknownFiles = "";

            if (apktoolYml.Contains("unknownFiles"))
            {
                unknownFiles = apktoolYml.Substring(apktoolYml.IndexOf("unknownFiles"));
            }

            String unknown = dirTarget + "\\unknown";

            String[] files = getAllFiles(unknown).Split(';');
            if (files != null && files.Length > 0)
            {
                if (call != null)
                {
                    call("【I】- 8.修改apktool.yml中的Unknown文件列表:");
                }

                // 生成新的unknown
                String appendUnknowns = "";
                foreach (String file in files)
                {
                    String relativeName = ApkCombine.relativePath(file, unknown).Replace('\\', '/');
                    appendUnknowns += "\n  " + relativeName + ": '8'";
                    if (call != null)
                    {
                        call("【I】Unknown添加:" + relativeName);
                    }
                }
                if (!appendUnknowns.Equals(""))
                {
                    appendUnknowns = "unknownFiles:" + appendUnknowns + "\n";
                }


                // 替换为新的unknown文件列表信息
                if (unknownFiles.Equals(""))
                {
                    apktoolYml = apktoolYml + appendUnknowns;
                }
                else
                {
                    apktoolYml = apktoolYml.Replace(unknownFiles, appendUnknowns);
                }
            }

            // 文件内容变动,则保存为新的apktoolYml
            if (!apktoolYml.Equals(apktoolYml0))
            {
                FileProcess.SaveProcess(apktoolYml, apktoolYmlPath);
                if (call != null)
                {
                    call("【I】对apktool.yml的修改已保存!\r\n");
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 从dirSource中拷贝附加目录文件到dirTarget中
        /// </summary>
        public static void CopyFolderTo_addCopyDir(string dirSource, string dirTarget, Cmd.Callback call, Settings setting)
        {
            foreach (string dirAdd0 in setting.addCopyDir)
            {
                string dirAdd  = dirAdd0;   // 记录原有路径
                string destDir = "";        // 记录目标路径

                // "GAMEDIR:smali\{GAMEPRE_package_PATH1}->smali\{package_PATH1}[IGNORE:]assets\bin\Data\mainData,res\2.bin"
                // 忽略,不执行smali引用修改逻辑的文件列表
                List <string> Ignores = new List <string>();
                if (dirAdd.Contains("[IGNORE:]"))   // 执行smali引用修改逻辑时,不修改的文件
                {
                    int    index = dirAdd.IndexOf("[IGNORE:]");
                    string Str   = dirAdd.Substring(index + "[IGNORE:]".Length);
                    dirAdd = dirAdd.Substring(0, index).Trim();
                    string[] A = Str.Replace(",", ",").Split(',');
                    foreach (string a0 in A)
                    {
                        string a = a0.Trim();
                        if (!a.Equals("") && !Ignores.Contains(a))
                        {
                            Ignores.Add(a);
                        }
                    }
                }

                if (dirAdd.Contains("->"))
                {
                    int index = dirAdd.IndexOf("->");
                    destDir = dirAdd.Substring(index + "->".Length);
                    dirAdd  = dirAdd.Substring(0, index);
                }

                string pathSource = Path.Combine(dirSource, dirAdd);

                bool isGameDir = false;             // 标识是否为游戏解包目录
                if (dirAdd.StartsWith("GAMEDIR:"))  // 从游戏解包路径中开始检索
                {
                    isGameDir  = true;
                    dirAdd     = dirAdd.Substring("GAMEDIR:".Length);
                    pathSource = Path.Combine(dirTarget, dirAdd);
                }

                string pathTarget = Path.Combine(dirTarget, destDir.Equals("") ? dirAdd : destDir);

                //// 相同目录则不进行复制和移动
                //if(pathTarget.Equals(pathSource) || (pathTarget.Contains(pathSource) && pathTarget.StartsWith(pathSource + "\\"))) continue;

                string parent = parentDir(pathSource);      // 获取文件的父目录
                if (!Directory.Exists(parent))
                {
                    continue;                               // 若父目录不存在
                }
                //先来复制文件
                DirectoryInfo directoryInfo = new DirectoryInfo(parent);
                FileInfo[]    files         = directoryInfo.GetFiles();

                //复制所有文件
                foreach (FileInfo file in files)
                {
                    String fileSource = Path.Combine(file.DirectoryName, file.Name);                    // 获取目录下的文件
                    String relative   = relativePath(fileSource, isGameDir ? dirTarget : setting.Path); // 获取相对路径名
                    if (dirAdd.Equals(relative) || dirAdd.Equals(IgnoreExtension(relative)))            // 获取的文件与dirAdd匹配
                    {
                        if (!destDir.Equals(""))                                                        // 目标路径非空,重新计算相对路径
                        {
                            String name1 = getLastName(dirAdd);
                            String name2 = getLastName(destDir);

                            String destTmp = destDir;
                            if (name1.Equals(name2))
                            {
                                destTmp = parentDir(destDir);
                            }

                            relative = destTmp + "\\" + getLastName(fileSource);
                        }

                        String fileTarget = Path.Combine(dirTarget, relative);              // 获取对应路径下的目标文件

                        if (File.Exists(fileTarget))
                        {
                            // 替换已存在的文件
                            if (fileSource.Equals(fileTarget))
                            {
                                if (call != null)
                                {
                                    call("【I2】忽略原路径下文件的替换:" + pathSource);
                                }
                                else
                                {
                                    replaceFile(fileSource, fileTarget, relative, call, setting);
                                }
                            }
                        }
                        else
                        {
                            string ParentDirTarget = parentDir(fileTarget);      // 获取文件的父目录
                            if (!Directory.Exists(ParentDirTarget))              // 若父目录不存在先创建
                            {
                                Directory.CreateDirectory(ParentDirTarget);
                            }

                            if (showCopyInfo && call != null)
                            {
                                call("【I】复制文件:" + relative);
                            }
                            file.CopyTo(fileTarget, true);
                        }
                    }
                }

                // 复制目录
                if (Directory.Exists(pathSource))
                {
                    if (Directory.Exists(pathTarget))
                    {
                        if (!pathSource.Equals(pathTarget)) // 源目录与目标目录不相同时,才进行合并
                        {
                            if (call != null)
                            {
                                call("【I3】合并目录:" + pathSource + "到" + pathTarget);
                            }
                            CopyFolderTo(pathSource, pathTarget, true, call, setting);
                        }
                    }
                    else
                    {
                        string relative = relativePath(pathSource, setting.Path);
                        if (call != null)
                        {
                            call("【I】复制目录:" + relative);
                        }
                        CopyFolderTo(pathSource, pathTarget, true);
                    }
                }

                // smali\com\ltgame\cs\vivo\wxapi->smali\game\wxapi
                // 执行所有文件的smali和包名路径,引用修改逻辑
                if (!destDir.Equals("") && destDir.StartsWith(@"smali\") && dirAdd.StartsWith(@"smali\") && setting != null)
                {
                    String key   = dirAdd.Substring(@"smali\".Length);  // 获取原有路径名
                    String value = destDir.Substring(@"smali\".Length); // 获取新的路径名

                    if (!key.Equals(value))
                    {
                        // 替换dirTarget所有文件中的keykey值为Value
                        if (call != null)
                        {
                            call("【I】执行smali引用修改逻辑,修改所有文件中的 " + key + " 为 " + value);
                        }
                        setting.ReplaceDir_ChannelParams(dirTarget, key.Replace("\\", "."), value.Replace("\\", "."), dirTarget, Ignores);
                        setting.ReplaceDir_ChannelParams(dirTarget, key.Replace("\\", "/"), value.Replace("\\", "/"), dirTarget, Ignores);

                        // 将原有文件目录作为删除目录处理,设为清除目录
                        if (!setting.deletGameDir.Contains(dirAdd))
                        {
                            if (pathTarget.StartsWith(pathSource))
                            {
                                call("【I】目标路径 " + destDir + " 为原路径 " + dirAdd + "的子路径,忽略对该路径的删除操作");
                                List <string> list = GetSubIteams(pathTarget, dirTarget, destDir);
                                foreach (string iteam in list)
                                {
                                    if (!setting.deletGameDir.Contains(iteam))
                                    {
                                        setting.deletGameDir.Add(iteam);
                                    }
                                }
                            }
                            else
                            {
                                setting.deletGameDir.Add(dirAdd);    // 删除原路径下文件
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 24
0
        // 根据TypeList中的类型信息,在TargetDir目录下,生成新的R.smali文件
        public static void CreateR_smali(List <String> TypeList, String TargetDir, String packageName, Cmd.Callback call)
        {
            String PackageStr = packageName.Trim('.').Replace('.', '/');    // 形如 com/ltsdk_56_base/leshi
            String TargetPath = TargetDir + "\\" + packageName.Trim('.').Replace('.', '\\');

            String body = "";

            foreach (String type in TypeList)
            {
                String iteam = "        L" + PackageStr + "/R$" + type + ";";
                if (body.Equals(""))
                {
                    body = iteam;
                }
                else
                {
                    body += ",\r\n" + iteam;
                }
            }

            String content =
                ".class public final L" + PackageStr + "/R;" + "\r\n" +
                ".super Ljava/lang/Object;" + "\r\n" +
                ".source \"R.java\"" + "\r\n" +
                "\r\n" +
                "\r\n" +
                "# annotations" + "\r\n" +
                ".annotation system Ldalvik/annotation/MemberClasses;" + "\r\n" +
                "    value = {" + "\r\n" +
                "\r\n" +
                body + "\r\n" +
                "    }" + "\r\n" +
                ".end annotation" + "\r\n" +
                "\r\n" +
                "\r\n" +
                "# direct methods" + "\r\n" +
                ".method public constructor <init>()V" + "\r\n" +
                "    .locals 0" + "\r\n" +
                "\r\n" +
                "    .prologue" + "\r\n" +
                "    invoke-direct {p0}, Ljava/lang/Object;-><init>()V" + "\r\n" +
                "\r\n" +
                "    return-void" + "\r\n" +
                ".end method" + "\r\n" + "\r\n";

            // 保存BuildConfig文件到指定包名目录
            FileProcess.SaveProcess(content, TargetPath + "\\R.smali");
            if (call != null)
            {
                call("【I】" + PackageStr + "/R.smali 已生成..");
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 执行xml文件混合逻辑
        /// </summary>
        public static void xmlCombine(String fileSource, String fileTarget, String relative, Cmd.Callback call, Settings setting)
        {
            bool isManifest = fileTarget.EndsWith("AndroidManifest.xml");       // 是否为AndroidManifest.xml

            if (call != null)
            {
                call((isManifest ? "【I3】Manifest.xml文件合并:" : "【I3】xml文件合并:") + relative);
            }
            if (isManifest)
            {
                Manifest.call = call;
            }
            xmlNode.Combine(fileSource, fileTarget, fileTarget, isManifest, setting != null ? setting.ManifestCMD : null, call);
        }
Ejemplo n.º 26
0
        // 替换除包名路径下,所有R文件中的id信息
        public static void updateALL_RIds(String unpackDir, String package, Dictionary <String, List <xmlNode> > gemeDicSrc, Dictionary <String, List <xmlNode> > DicSrc, Dictionary <String, List <xmlNode> > DicTar, Cmd.Callback call, bool R_Process_Game = false)
        {
            String        packagePath = unpackDir + "\\smali\\" + package.Trim('.').Replace('.', '\\');
            List <String> R_path      = getR_smaliPath(unpackDir);

            int i = 0;

            foreach (String R_smaliDir in R_path)
            {
                if (!R_smaliDir.Equals(packagePath))                    // 非包名路径下的R文件所在路径
                {
                    //string relative = ApkCombine.relativePath(R_smaliDir, unpackDir);
                    //if (relative.StartsWith("smali\\android\\")) continue;
                    //else if (relative.StartsWith("smali\\com\\helpshift")) continue;

                    //string ortherR = ApkCombine.relativePath(R_smaliDir, unpackDir);
                    //if (ortherR.Contains(@"\android\")) continue;     // 忽略android路径下的R文件修改

                    //String relaPath = ApkCombine.relativePath(R_smaliDir, unpackDir);
                    //if (relaPath.Equals(@"smali\com\google\android\gms\common"))
                    //    relaPath = relaPath + "";

                    if (call != null)
                    {
                        call("【I】- 7." + ++i + " 修改路径" + ApkCombine.relativePath(R_smaliDir, unpackDir) + "下所有R文件id信息");
                    }
                    update_RDirIds(R_smaliDir, DicSrc, DicTar, call);
                    if (R_Process_Game)
                    {
                        update_RDirIds(R_smaliDir, gemeDicSrc, DicTar, call);                  // 修改游戏包中对应的资源id
                    }
                }
            }
        }
Ejemplo n.º 27
0
        // 从resDic中的id信息生成R*smali文件
        public static void rebuidR_smali(Dictionary <String, List <xmlNode> > resDic, String TargetDir, String packageName, Cmd.Callback call)
        {
            if (resDic == null || resDic.Count == 0)
            {
                return;
            }

            // 创建包名对应的路径
            String TargetPath = TargetDir + "\\" + packageName.Trim('.').Replace('.', '\\');    // 形如 com\ltsdk_56_base\leshi

            DependentFiles.checkDir(TargetPath);

            // 按照res中的type类型,生成对应的R$type.smali文件资源到指定的包名、路径下
            foreach (String typeName in resDic.Keys)
            {
                if (typeName.Equals("AllType"))
                {
                    continue;
                }

                List <xmlNode> typeList = resDic[typeName];
                createSmali(TargetPath, packageName, typeName, typeList, call);
            }

            // 生成BuildConfig.smali
            createBuildConfig(TargetPath, packageName, call);
        }
Ejemplo n.º 28
0
        //<public type="attr" name="circle_radius" id="0x7f010000" />
        //<public type="attr" name="password_length" id="0x7f010001" />
        // 修改data中所有Src中的id信息到Target根据相同name值进行修改
        private static String updateIds(String data, List <xmlNode> listSrc, List <xmlNode> listTar, Cmd.Callback call)
        {
            Dictionary <String, String> dicSrc = toIdDic(listSrc, call); // 转化为name、id映射表
            Dictionary <String, String> dicTar = toIdDic(listTar, call);

            bool showRsmaliModify = ToolSetting.Instance().showRsmaliModify; // 显示R文件id信息修改逻辑
            bool contains0000     = false;                                   // 文件中是否含有****0000的id值信息

            foreach (String name in dicSrc.Keys)
            {
                String id = dicSrc[name];

                if (!data.Contains(id))     // 若smali文件中不含有旧的资源id,则从smali文件中解析旧的资源id信息
                {
                    String idName = name;
                    //if (idName.Equals("string:common_google_play_services_unknown_issue"))
                    //    idName = idName + "";
                    if (idName.Contains(":"))
                    {
                        idName = idName.Substring(idName.IndexOf(":") + 1);
                    }

                    String idTmp = getSmaliId(data, idName);
                    if (!idTmp.Equals(""))
                    {
                        id = idTmp;
                    }
                }

                if (data.Contains(id))
                {
                    if (id.EndsWith("0000"))
                    {
                        contains0000 = true;
                    }
                    if (dicTar.ContainsKey(name))       // 替换data中同名name对应的id值
                    {
                        String idTar = dicTar[name];    // 目标id值

                        if (!id.Equals(idTar))
                        {
                            String idTarTmp = "0x_@_" + idTar.Substring("0x".Length);  // 替换0x7f00001这样的id串为0x_@_7f00001,避免重复,文件中全部id替换完成后,在统一替换回0x7f00001串
                            data = data.Replace(id, idTarTmp);
                            if (showRsmaliModify && call != null)
                            {
                                call("【I】修改" + name + "的id值," + id + "->" + idTar);
                            }
                        }
                    }
                    else if (call != null)
                    {
                        call("【E】当前新生成的public.xml文件中,不含有资源" + name + "!");
                    }
                }
            }
            if (data.Contains("0x_@_"))
            {
                data = data.Replace("0x_@_", "0x");                         // 剔除附加进去的"_@_"
            }
            if (contains0000 && data.Contains("const/high16"))
            {
                data = data.Replace("const/high16", "const");               // 剔除/high16的限制
                if (showRsmaliModify && call != null)
                {
                    call("【I】修改文件中所有\"const/high16\"为\"const\"");
                }
            }

            return(data);
        }
Ejemplo n.º 29
0
 /// <summary>
 /// 替换文件逻辑
 /// </summary>
 private static void replaceFile(string fileSource, string fileTarget, string relative, Cmd.Callback call = null, Settings setting = null)
 {
     if (fileTarget.EndsWith(".xml"))
     {
         // 若为xml文件,则执行xml文件混合逻辑
         xmlCombine(fileSource, fileTarget, relative, call, setting);
     }
     else if (fileTarget.EndsWith("config.txt") && relative.Equals(@"assets\ltsdk_res\config.txt"))
     {
         LT_config.Config_Combine(fileSource, fileTarget, call, false);         // 混合dirSource目录下的config.txt到dirDest目录下
     }
     else
     {
         if (call != null)
         {
             call("【I3】替换文件:" + relative);
         }
         System.IO.File.Copy(fileSource, fileTarget, true);
     }
 }
Ejemplo n.º 30
0
        //<public type="attr" name="circle_radius" id="0x7f010000" />
        //<public type="attr" name="password_length" id="0x7f010001" />
        //<public type="attr" name="has_pwd_color" id="0x7f010002" />
        // 从type对应的List<xmlNode>创建对应的R$type.smali文件, packageName为包名如"com.sdk.game" ,TargetDir为目标路径, 属性名typeName
        private static void createSmali(String TargetDir, String packageName, String typeName, List <xmlNode> typeList, Cmd.Callback call)
        {
            String FileName   = "R$" + typeName;                            // 生成R文件名称如 R$attr
            String PackageStr = packageName.Trim('.').Replace('.', '/');    // 形如 com/ltsdk_56_base/leshi

            // R$type.smali文件顶部
            String head =
                ".class public final L" + PackageStr + "/" + FileName + ";" + "\r\n" +
                ".super Ljava/lang/Object;" + "\r\n" +
                ".source \"R.java\"" + "\r\n" +
                "\r\n" +
                "\r\n" +
                "# annotations" + "\r\n" +
                ".annotation system Ldalvik/annotation/EnclosingClass;" + "\r\n" +
                "    value = L" + PackageStr + "/R;" + "\r\n" +
                ".end annotation" + "\r\n" +
                "\r\n" +
                ".annotation system Ldalvik/annotation/InnerClass;" + "\r\n" +
                "    accessFlags = 0x19" + "\r\n" +
                "    name = \"" + typeName + "\"" + "\r\n" +
                ".end annotation" + "\r\n" + "\r\n" + "\r\n";

            // R$type.smali文件顶部
            String tail =
                "# direct methods" + "\r\n" +
                ".method public constructor <init>()V" + "\r\n" +
                "    .locals 0" + "\r\n" +
                "\r\n" +
                "    .prologue" + "\r\n" +
                //"    .line 18" + "\r\n" +
                "    invoke-direct {p0}, Ljava/lang/Object;-><init>()V" + "\r\n" +
                "\r\n" +
                "    return-void" + "\r\n" +
                ".end method" + "\r\n" + "\r\n" + "\r\n";

            // R$type.smali文件属性值部分
            String body = "# static fields" + "\r\n";

            foreach (xmlNode iteam in typeList)
            {
                String attrName = iteam.attributes.Get("name");
                if (attrName.Contains("."))
                {
                    attrName = attrName.Replace('.', '$');                          // 修改.为$
                }
                body += ".field " + iteam.name + " static final " + attrName + ":I = " + iteam.attributes.Get("id") + "\r\n" + "\r\n";
            }
            body += "\r\n";

            // 保存为对应的smali文件到对应路径下
            String content = head + body + tail;

            FileProcess.SaveProcess(content, TargetDir + "\\" + FileName + ".smali");

            if (call != null)
            {
                call("【I】" + PackageStr + "/" + FileName + ".smali 已生成..");
            }
        }