Example #1
0
        public void InitServiceTest()
        {
            new Thread(() => {
                while (true)
                {
                    var pid = "0";
                    try
                    {
                        pid = HttpRequestUtil.GetHttpResponse("http://localhost:8081/pid", 3000);
                    }
                    catch (Exception e) { }

                    var p = Convert.ToInt64(pid);
                    if (p > 0)
                    {
                        CmdUtils.RunCmdStandard("taskkill /f /pid " + p);
                        break;
                    }
                    else
                    {
                        Thread.Sleep(3000);
                    }
                }
            }).Start();

            IRpcService rpc = new RpcServiceImpl();

            rpc.ReCreateJMapQuery();
            rpc.InitService();
        }
Example #2
0
        /// <summary>
        /// 签名
        /// </summary>
        /// <param name="config"></param>
        /// <param name="logView"></param>
        /// <returns></returns>
        public static bool SignApk(KeystoreConfig config, ILog logView)
        {
            string tempApkPath = PathUtils.GetPath(Constants.PATH_TEMPAPK);

            if (!File.Exists(tempApkPath))
            {
                logView.Log(">>>>>>签名失败: " + tempApkPath + "未生成!");
                return(false);
            }

            string jarsignerPath = PathUtils.GetPath(Constants.PATH_JARSIGNER);

            if (!File.Exists(jarsignerPath))
            {
                logView.Log(">>>>>>签名失败: " + jarsignerPath + "不存在!");
                return(false);
            }

            logView.Log("↓↓↓↓↓↓ 签名-开始 ↓↓↓↓↓↓");

            string args = jarsignerPath + " -digestalg SHA1 -sigalg SHA1withRSA -keystore " + config.KeystoreFilePath + " -storepass " + config.Password + " -keypass " + config.Aliaspwd + " " + tempApkPath + " " + config.Aliaskey;

            string[] ret = CmdUtils.ExecCmdAndWaitForExit(args, logView);
            if (ret == null || ret.Length < 2 || !string.IsNullOrEmpty(ret[1]))
            {
                logView.Log(">>>>>>签名失败: 执行CMD失败");
                return(false);
            }

            logView.Log("↑↑↑↑↑↑ 签名-结束 ↑↑↑↑↑↑");
            logView.BlankLine();

            return(true);
        }
Example #3
0
        public bool CloseJMapQuery()
        {
            bool status = false;
            var  ss     = ServiceManager.RegistService(x =>
            {
                int queryCount = 0;
                while (queryCount <= 10)
                {
                    var pid = JMapQueryIsRunning();
                    if (pid > 0)
                    {
                        CloseSupervisor();
                        CmdUtils.RunCmdStandard("taskkill /f /pid " + pid);
                        status = true;
                        break;
                    }
                    else
                    {
                        Thread.Sleep(3000);
                        queryCount++;
                    }
                }
            }, null);

            ServiceManager.ExecuteService(ss.Id);

            return(status);
        }
Example #4
0
        private static bool RegenerateProjectUsingUBT(Lifetime lifetime, UnrealHost unrealHost, VirtualFileSystemPath uprojectFile,
                                                      VirtualFileSystemPath pathToUnrealBuildToolBin, VirtualFileSystemPath engineRoot)
        {
            if (uprojectFile.IsNullOrEmpty())
            {
                return(false);
            }

            bool isInstalledBuild = IsInstalledBuild(engineRoot);

            var pipeStreams = CreatePipeStreams(unrealHost, "[UBT]:");
            var startInfo   = CmdUtils.GetProcessStartInfo(pipeStreams, pathToUnrealBuildToolBin,
                                                           pathToUnrealBuildToolBin.Directory, "-ProjectFiles",
                                                           $"-project=\"{uprojectFile.FullPath}\"", "-game", isInstalledBuild ? "-rocket" : "-engine");

            try
            {
                var result = CmdUtils.RunCommandWithLock(lifetime, startInfo, ourLogger) == 0;
                if (!result)
                {
                    ourLogger.Warn($"[UnrealLink]: Failed refresh project files: calling {startInfo.Arguments}");
                }

                return(result);
            }
            catch (ErrorLevelException errorLevelException)
            {
                ourLogger.Error(errorLevelException,
                                $"[UnrealLink]: Failed refresh project files: calling {startInfo.Arguments}");
                return(false);
            }
        }
Example #5
0
        /// <summary>
        /// 反编译
        /// </summary>
        /// <param name="apkFilePath"></param>
        /// <returns>返回保存反编译信息的目录,为空表示反编译失败</returns>
        public static string DecompileApk(string apkFilePath)
        {
            if (string.IsNullOrEmpty(apkFilePath) ||
                !File.Exists(apkFilePath))
            {
                return(null);
            }

            string apktoolPath = PathUtils.GetPath(Constants.PATH_APKTOOL);

            if (!File.Exists(apktoolPath))
            {
                LogUtils.WriteLine(apktoolPath + "不存在!");
                return(null);
            }

            string decompileDir = PathUtils.GetPath(Constants.DIR_TEMP_DECOMPLIE);

            if (!Directory.Exists(decompileDir))
            {
                Directory.CreateDirectory(decompileDir);
            }
            FileUtils.ClearDir(decompileDir);
            decompileDir = PathUtils.JoinPath(decompileDir, DateTime.Now.ToString("yyyyMMdd_HHmmss"));

            string cmdArgs = apktoolPath + " d " + apkFilePath + " -o " + decompileDir;// -o后面的目录不能已存在

            string[] res = CmdUtils.ExecCmdAndWaitForExit(cmdArgs);
            if (res == null || res.Length < 2 || !string.IsNullOrEmpty(res[1]))
            {
                return(null);
            }

            return(decompileDir);
        }
        private bool BuildPlugin(Lifetime lifetime, VirtualFileSystemPath upluginPath,
                                 VirtualFileSystemPath outputDir, VirtualFileSystemPath engineRoot,
                                 Action <double> progressPump)
        {
            var runUatName = $"RunUAT.{CmdUtils.GetPlatformCmdExtension()}";
            var pathToUat  = engineRoot / "Engine" / "Build" / "BatchFiles" / runUatName;

            if (!pathToUat.ExistsFile)
            {
                myLogger.Warn($"[UnrealLink]: Failed build plugin: {runUatName} is not available");
                var text = $"{runUatName} is not available is not available at expected destination: {pathToUat}<br>";
                myUnrealHost.myModel.RiderLinkInstallMessage(
                    new InstallMessage($"Failed to build RiderLink plugin for {engineRoot}", ContentType.Error));
                myUnrealHost.myModel.RiderLinkInstallMessage(new InstallMessage(text, ContentType.Error));
                return(false);
            }

            try
            {
                var pipeStreams = CreatePipeStreams("[UAT]:", progressPump);
                var startInfo   = CmdUtils.GetProcessStartInfo(pipeStreams, pathToUat, null, "BuildPlugin",
                                                               "-Unversioned", $"-Plugin=\"{upluginPath.FullPath}\"",
                                                               $"-Package=\"{outputDir.FullPath}\"");

                myLogger.Info($"[UnrealLink]: Building UnrealLink plugin with: {startInfo.Arguments}");
                myLogger.Verbose("[UnrealLink]: Start building UnrealLink");

                var result = CmdUtils.RunCommandWithLock(lifetime, startInfo, myLogger);
                myLogger.Verbose("[UnrealLink]: Stop building UnrealLink");
                lifetime.ToCancellationToken().ThrowIfCancellationRequested();

                if (result != 0)
                {
                    myLogger.Warn($"[UnrealLink]: Failed to build plugin for {engineRoot}");
                    myUnrealHost.myModel.RiderLinkInstallMessage(new InstallMessage("Failed to build RiderLink plugin",
                                                                                    ContentType.Error));
                    return(false);
                }
            }
            catch (OperationCanceledException)
            {
                myLogger.Verbose("[UnrealLink]: Build cancelled");
                throw;
            }
            catch (Exception exception)
            {
                myLogger.Verbose("[UnrealLink]: Stop building UnrealLink");
                myLogger.Warn(exception,
                              $"[UnrealLink]: Failed to build plugin for {engineRoot}");

                myUnrealHost.myModel.RiderLinkInstallMessage(
                    new InstallMessage($"Failed to build RiderLink plugin for {engineRoot}", ContentType.Error));
                return(false);
            }

            return(true);
        }
Example #7
0
        /// <summary>
        /// 将Dex文件转换为Smali文件
        /// </summary>
        /// <param name="decompileDir"></param>
        /// <param name="logView"></param>
        /// <returns></returns>
        public static bool Dex2Smali(string decompileDir, ILog logView)
        {
            if (string.IsNullOrEmpty(decompileDir) || !Directory.Exists(decompileDir))
            {
                logView.Log(">>>>>>将Dex文件转换为Smali文件失败: " + decompileDir + "目录不存在!");
                return(false);
            }

            string dexFilePath = PathUtils.GetPath(Constants.PATH_CLASSDEX);

            if (!File.Exists(dexFilePath))
            {
                logView.Log(">>>>>>将Dex文件转换为Smali文件失败: " + dexFilePath + "文件未生成!");
                return(false);
            }

            string javaPath  = PathUtils.GetPath(Constants.PATH_JAVA);     // java.exe
            string smaliTool = PathUtils.GetPath(Constants.PATH_BAKSMALI); // baksmali.jar

            if (!File.Exists(javaPath))
            {
                logView.Log(">>>>>>将Dex文件转换为Smali文件失败: " + javaPath + "不存在!");
                return(false);
            }
            if (!File.Exists(smaliTool))
            {
                logView.Log(">>>>>>将Dex文件转换为Smali文件失败: " + smaliTool + "不存在!");
                return(false);
            }


            // 生成smali位置,是Apk反编译目录下的smali目录,用于覆盖apk的smali文件
            string targetDir = PathUtils.JoinPath(decompileDir, Constants.DIR_SMALI);

            logView.Log("↓↓↓↓↓↓ 将Dex文件转换为Smali文件-开始 ↓↓↓↓↓↓");

            string args = javaPath + " -jar " + smaliTool + " -o " + targetDir + " " + dexFilePath;

            string[] ret = CmdUtils.ExecCmdAndWaitForExit(args, logView);
            if (ret == null || ret.Length < 2 || !string.IsNullOrEmpty(ret[1]))
            {
                logView.Log(">>>>>>将Dex文件转换为Smali文件失败: 执行CMD失败");
                return(false);
            }

            logView.Log("↑↑↑↑↑↑ 将Dex文件转换为Smali文件-结束 ↑↑↑↑↑↑");
            logView.BlankLine();

            return(true);
        }
Example #8
0
        private static void TestCustomConsoleOut()
        {
            //First we want to Specify what Messages we want to let trough the LogStream we are creating in a minute.

            //You have multiple ways to create a Bitmask without getting cancer from bitwise operations
            var bMaskWildCard = new BitMask(true); //Creates a Wildcard(Everything will be let through)
            var bMaskNone     = new BitMask();     //Creates the opposite of Wildcard(Nothing will be let through)

            //There are also more readable ways to create a mask.
            //For example with enums. The Implementation will stay the same.
            var bMaskGenericWildcard = new BitMask <LoggingTypes>(true);
            var bMaskGenericNone     = new BitMask <LoggingTypes>();

            //But you can do masks easier now.
            //This bitmask only lets through logs and errors
            var bMaskGenericCustom = new BitMask <LoggingTypes>(LoggingTypes.Error, LoggingTypes.Log);

            //We want to Create a PipeStream that our logstream is basing on(pipe streams are threadsave streams in a single sender/single receiver situation)
            var pipeStream = new PipeStream(); //Create a new instance


            //Then we want to create a LogStream that receives the Messages
            //Important: Its much easier to use CreateLogStreamFromStream than setting everything manually
            var logStream = new LogStream(
                pipeStream,           //The Stream we want to send the Logs to.
                bMaskGenericWildcard, //Lets use the generic wildcard(you can set the mask dynamically when using a custom console.
                MatchType.MatchOne,   //We want to make the logs pass when all tags are included in the filter.
                true                  //Get that fancy timestamp infront of the log.
                );

            //logStream.OverrideChannelTag = false;
            Debug.AddOutputStream(logStream); //Now we have Created the stream, just add it to the system.


            //After Creating the log Stream we want to create a custom Cmd window
            var ccmd
                =                                           //ADL.CustomCMD.CMDUtils.CreateCustomConsole(pipeStream); //Creates a basic Custom cmd with no visual adjustments
                  CmdUtils.CreateCustomConsole(pipeStream); //Creates a custom cmd with color coding and custom font size.

            (ccmd as ADL.CustomCMD.CustomCmdForm).FontColor = Color.White;


            Debug.LogGen(LoggingTypes.Log, "Finished adding the CustomConsole.");

            //Now we want to remove the stream from the system.
            //Debug.RemoveOutputStream(logStream, true); //We want to remove a single one.
            //But we can remove all Streams in one go
            //Debug.RemoveAllOutputStreams(true);
        }
Example #9
0
        private void Awake()
        {
            Configuration.Prepare();
            CustomCmdConfig.Prepare();
            Debug.LoadConfig(Configuration);


            DontDestroyOnLoad(gameObject);
            foreach (var lsp in Streams)
            {
                LogStream ls;

                if (lsp.CreateCustomConsole)
                {
                    ls = lsp.ToLogStream(new PipeStream());
                    CmdUtils.CreateCustomConsoleNoReturn(ls.PBaseStream as PipeStream,
                                                         CustomCmdConfig); // Currently not working due to referencing problems with my compiled code(using System.Windows.Forms)
                    //Apparently Unity Editor dll loading capabilities were never meant to load system resources.(The error is that the windows forms code is not able to find System.Runtime.Interopservices.Marshal.ReadInt16)
                    //Probably dumb mistake by me. Otherwise i manage to poke some super old 16 bit code that is not supported on my 64bit machine.
                }
                else
                {
                    ls = lsp.ToLogStream();
                }

                Debug.AddOutputStream(ls);
            }

            if (UseConsole)
            {
                if (ConsoleParams.CreateCustomConsole)
                {
                    var ls = ConsoleParams.ToLogStream(new PipeStream());
                    Debug.AddOutputStream(ls);
                    CmdUtils.CreateCustomConsoleNoReturn(ls.PBaseStream as PipeStream, CustomCmdConfig);
                }
                else
                {
                    UnityUtils.CreateUnityConsole(ConsoleParams, ConsoleWarningMask, ConsoleErrorMask);
                }
            }

            if (Debug.SendUpdateMessageOnFirstLog)
            {
                CheckForUpdates();
            }
        }
Example #10
0
        private static void CreateAdlCustomCmdConfig()
        {
            var colorCoding =
                new SerializableDictionary <int, SerializableColor>(
                    new Dictionary <int, SerializableColor>
            {
                { 8, Color.Red },       //Every errror message should be drawn in red.
                { 4, Color.Orange },    //Every warning is painted in orange
                { 32, Color.Green }
            });
            var config = AdlCustomConsoleConfig.Standard;

            config.FontSize    = 13;
            config.FrameTime   = 50;
            config.FontColor   = Color.White;
            config.ColorCoding = colorCoding;
            CmdUtils.SaveConfig(config);
        }
Example #11
0
        /// <summary>
        /// 用jadx-gui.bat打开文件
        /// </summary>
        /// <param name="filePath">以.jar/.dex/.apk为后缀的文件路径</param>
        public static void OpenJadxGUI(string filePath)
        {
            if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
            {
                return;
            }

            string jadxPath = PathUtils.GetPath(Constants.PATH_JADXGUI);

            if (!File.Exists(jadxPath))
            {
                LogUtils.WriteLine(jadxPath + "不存在!");
                return;
            }

            string cmdArgs = jadxPath + " " + filePath;

            CmdUtils.ExecCmd(cmdArgs);
        }
Example #12
0
        private static bool GenerateProjectFilesCmd(Lifetime lifetime, ISolution solution, UnrealHost unrealHost,
                                                    VirtualFileSystemPath uprojectFile, VirtualFileSystemPath engineRoot)
        {
            // Invalid uproject file means we couldn't get uproject file from solution detector and the project might be
            // under Engine source
            var invalidUprojectFile  = !uprojectFile.IsValidAndExistFile();
            var isProjectUnderEngine = uprojectFile.StartsWith(engineRoot) || invalidUprojectFile;

            if (!isProjectUnderEngine)
            {
                ourLogger.Info($"[UnrealLink]: {solution.SolutionFilePath} is not in {engineRoot} ");
                return(false);
            }

            var generateProjectFilesCmd = engineRoot / $"GenerateProjectFiles.{CmdUtils.GetPlatformCmdExtension()}";

            if (!generateProjectFilesCmd.ExistsFile)
            {
                ourLogger.Info($"[UnrealLink]: {generateProjectFilesCmd} is not available");
                return(false);
            }

            var pipeStreams = CreatePipeStreams(unrealHost, "[GenerateProjectFiles]:");
            var startInfo   = CmdUtils.GetProcessStartInfo(pipeStreams, generateProjectFilesCmd, generateProjectFilesCmd.Directory);

            ourLogger.Info($"[UnrealLink]: Regenerating project files: {startInfo.Arguments}");
            try
            {
                var result = CmdUtils.RunCommandWithLock(lifetime, startInfo, ourLogger) == 0;
                if (!result)
                {
                    ourLogger.Warn($"[UnrealLink]: Failed refresh project files, calling {generateProjectFilesCmd} went wrong");
                }

                return(result);
            }
            catch (ErrorLevelException errorLevelException)
            {
                ourLogger.Error(errorLevelException,
                                $"[UnrealLink]: Failed refresh project files, calling {generateProjectFilesCmd} went wrong");
                return(false);
            }
        }
Example #13
0
        /// <summary>
        /// 回编译
        /// </summary>
        /// <param name="decompileDir"></param>
        /// <param name="logView"></param>
        /// <returns></returns>
        public static bool RecompileApk(string decompileDir, ILog logView)
        {
            if (string.IsNullOrEmpty(decompileDir) || !Directory.Exists(decompileDir))
            {
                logView.Log(">>>>>>回编译失败: " + decompileDir + "目录不存在!");
                return(false);
            }

            string apktoolPath = PathUtils.GetPath(Constants.PATH_APKTOOL);

            if (!File.Exists(apktoolPath))
            {
                LogUtils.WriteLine(">>>>>>回编译失败: " + apktoolPath + "不存在!");
                return(false);
            }

            string tempApkPath = PathUtils.GetPath(Constants.PATH_TEMPAPK);

            if (File.Exists(tempApkPath))
            {
                File.Delete(tempApkPath);
            }

            logView.Log("↓↓↓↓↓↓ 回编译-开始 ↓↓↓↓↓↓");

            string args = apktoolPath + " b " + decompileDir + " -o " + tempApkPath;

            string[] ret = CmdUtils.ExecCmdAndWaitForExit(args, logView);
            if (ret == null || ret.Length < 2 || !string.IsNullOrEmpty(ret[1]))
            {
                logView.Log(">>>>>>回编译失败: 执行CMD失败");
                return(false);
            }

            logView.Log("↑↑↑↑↑↑ 回编译-结束 ↑↑↑↑↑↑");
            logView.BlankLine();

            return(true);
        }
Example #14
0
        /// <summary>
        /// 对齐优化
        /// </summary>
        /// <param name="newApkPath"></param>
        /// <param name="logView"></param>
        /// <returns></returns>
        public static bool AlignApk(string newApkPath, ILog logView)
        {
            string tempApkPath = PathUtils.GetPath(Constants.PATH_TEMPAPK);

            if (!File.Exists(tempApkPath))
            {
                logView.Log(">>>>>>对齐优化失败: " + tempApkPath + "未生成!");
                return(false);
            }

            string zipalignPath = PathUtils.GetPath(Constants.PATH_ZIPALIGN);

            if (!File.Exists(zipalignPath))
            {
                logView.Log(">>>>>>对齐优化失败: " + zipalignPath + "不存在!");
                return(false);
            }

            logView.Log("↓↓↓↓↓↓ 对齐优化-开始 ↓↓↓↓↓↓");

            string args = zipalignPath + " -f 4 " + tempApkPath + " " + newApkPath;

            string[] ret = CmdUtils.ExecCmdAndWaitForExit(args, logView);
            if (ret == null || ret.Length < 2 || !string.IsNullOrEmpty(ret[1]))
            {
                logView.Log(">>>>>>对齐优化失败: 执行CMD失败");
                return(false);
            }

            logView.Log("↑↑↑↑↑↑ 对齐优化-结束 ↑↑↑↑↑↑");
            logView.BlankLine();
            logView.Log("导出apk为: " + newApkPath);
            logView.BlankLine();

            return(true);
        }
Example #15
0
 /// <summary>
 /// 线程主体函数;
 /// </summary>
 public void AutoRun(object sender, System.Timers.ElapsedEventArgs e)
 {
     try
     {
         //1、扫描文件列表;2、检测出新文件;3、拼接命令;4、执行命令;
         DirectoryInfo TheFolder = new DirectoryInfo(exeDir);
         string        finalCmd  = string.Empty;
         DateTime      now       = DateTime.Now;
         //1、扫描文件列表;
         foreach (FileInfo thisFile in TheFolder.GetFiles())
         {
             DateTime creatTime = thisFile.CreationTime;
             string   fileType  = thisFile.Extension;
             //2、检测出新exe文件;
             if (fileType == ".exe" && DateTimeUtils.ExecDateDiff(creatTime, now) <= (intervalTime + 2))
             {
                 string fullPath = thisFile.FullName;
                 //3、拼接命令;
                 string thisCmd = "start /wait " + fullPath + " /S ";
                 finalCmd = finalCmd + thisCmd;
             }
         }
         //4、执行命令;
         string execuResult = string.Empty;
         if (!string.IsNullOrEmpty(finalCmd))
         {
             CmdUtils.RunCmd(finalCmd + " exit", out execuResult);
         }
         //Console.WriteLine(exeDir);
         return;
     }
     catch (Exception exp)
     {
         return;
     }
 }
Example #16
0
        private static bool RegenerateProjectUsingUVS(Lifetime lifetime, UnrealHost unrealHost, VirtualFileSystemPath uprojectFile,
                                                      VirtualFileSystemPath pathToUnrealVersionSelector)
        {
            if (!uprojectFile.IsValidAndExistFile())
            {
                return(false);
            }
            if (!pathToUnrealVersionSelector.ExistsFile)
            {
                ourLogger.Info($"[UnrealLink]: {pathToUnrealVersionSelector} is not available");
                return(false);
            }

            var pipeStreams = CreatePipeStreams(unrealHost, "[UVS]:");
            var startInfo   = CmdUtils.GetProcessStartInfo(pipeStreams, pathToUnrealVersionSelector,
                                                           pathToUnrealVersionSelector.Directory,
                                                           "-projectFiles", $"\"{uprojectFile}\"");

            try
            {
                var result = CmdUtils.RunCommandWithLock(lifetime, startInfo, ourLogger) == 0;
                if (!result)
                {
                    ourLogger.Warn(
                        $"[UnrealLink]: Failed refresh project files: calling {pathToUnrealVersionSelector} {startInfo.Arguments}");
                }

                return(result);
            }
            catch (ErrorLevelException errorLevelException)
            {
                ourLogger.Error(errorLevelException,
                                $"[UnrealLink]: Failed refresh project files: calling {pathToUnrealVersionSelector} {startInfo.Arguments}");
                return(false);
            }
        }
Example #17
0
        /// <summary>
        /// Jar文件转换成Dex文件
        /// </summary>
        /// <param name="jarPath">Jar文件或目录</param>
        /// <param name="logView"></param>
        /// <returns>返回生成dex文件的路径,为null时表示转换dex文件失败</returns>
        public static string Jar2Dex(string jarPath, ILog logView)
        {
            string javaPath    = PathUtils.GetPath(Constants.PATH_JAVA); // java.exe
            string dexToolPath = PathUtils.GetPath(Constants.PATH_DX);   // dx.jar

            if (!File.Exists(javaPath))
            {
                logView.Log(">>>>>>Jar文件转换成Dex文件失败: " + javaPath + "文件未生成!");
                return(null);
            }
            if (!File.Exists(dexToolPath))
            {
                logView.Log(">>>>>>Jar文件转换成Dex文件失败: " + dexToolPath + "文件未生成!");
                return(null);
            }


            string dexFilePath = PathUtils.GetPath(Constants.DIR_DEX);

            if (!Directory.Exists(dexFilePath))
            {
                Directory.CreateDirectory(dexFilePath);
            }
            FileUtils.ClearDir(dexFilePath);
            // 生成的dex文件路径
            dexFilePath = PathUtils.GetPath(Constants.PATH_CLASSDEX);

            string args = javaPath + " -jar -Xms1024m -Xmx1024m " + dexToolPath + " --dex --output=" + dexFilePath;

            logView.Log("↓↓↓↓↓↓ Jar文件转换成Dex文件-开始 ↓↓↓↓↓↓");
            if (Directory.Exists(jarPath))
            {
                string[] files = Directory.GetFiles(jarPath);
                if (files != null && files.Length > 0)
                {
                    for (int i = 0; i < files.Length; i++)
                    {
                        if (files[i].EndsWith(".jar"))
                        {
                            args += " " + files[i];
                        }
                    }
                }
            }
            else if (File.Exists(jarPath) && jarPath.EndsWith(".jar"))
            {
                args += " " + jarPath;
            }

            string[] ret = CmdUtils.ExecCmdAndWaitForExit(args, logView);
            if (ret == null || ret.Length < 2 || !string.IsNullOrEmpty(ret[1]))
            {
                logView.Log(">>>>>>Jar文件转换成Dex文件失败: 执行CMD失败");
                return(null);
            }

            logView.Log("↑↑↑↑↑↑ Jar文件转换成Dex文件-结束 ↑↑↑↑↑↑");
            logView.BlankLine();

            if (File.Exists(dexFilePath))
            {
                logView.Log("已生成dex文件:" + dexFilePath);
            }
            else
            {
                logView.Log("没生成dex文件:" + dexFilePath);
            }
            logView.BlankLine();

            return(dexFilePath);
        }
Example #18
0
        /// <summary>
        /// 重签名
        /// </summary>
        /// <param name="apkFilePath"></param>
        /// <param name="newApkPath"></param>
        /// <param name="config"></param>
        /// <param name="logView"></param>
        /// <returns></returns>
        public static bool ResignApk(string apkFilePath, string newApkPath, KeystoreConfig config, ILog logView)
        {
            if (string.IsNullOrEmpty(apkFilePath) || !File.Exists(apkFilePath))
            {
                logView.Log(">>>>>>重新签名失败: " + apkFilePath + "不存在!");
                return(false);
            }

            string tempDir = PathUtils.GetPath(Constants.DIR_TEMP_RESIGNAPK);

            if (!Directory.Exists(tempDir))
            {
                Directory.CreateDirectory(tempDir);
            }
            FileUtils.ClearDir(tempDir);
            string tempApkFilePath = PathUtils.JoinPath(tempDir, "temp.apk");

            // 拷贝一份APK作为临时文件,在该临时文件上操作
            FileInfo fi = new FileInfo(apkFilePath);

            if (fi.Exists)
            {
                fi.CopyTo(tempApkFilePath, true);
            }

            logView.BlankLine();
            logView.Log("删除APK文件中META-INF目录下的签名文件");
            ZipUtils.RemoveApkCertFile(tempApkFilePath, logView);

            logView.BlankLine();
            logView.Log("↓↓↓↓↓↓ 重签名-开始 ↓↓↓↓↓↓");

            string jarsignerPath = PathUtils.GetPath(Constants.PATH_JARSIGNER);
            string args          = jarsignerPath + " -digestalg SHA1 -sigalg SHA1withRSA -keystore " + config.KeystoreFilePath + " -storepass " + config.Password + " -keypass " + config.Aliaspwd + " " + tempApkFilePath + " " + config.Aliaskey;

            string[] ret = CmdUtils.ExecCmdAndWaitForExit(args, logView);
            if (ret == null || ret.Length < 2 || !string.IsNullOrEmpty(ret[1]))
            {
                logView.Log(">>>>>>重新签名失败: 执行CMD失败");
                return(false);
            }
            logView.Log("↑↑↑↑↑↑ 重签名-结束 ↑↑↑↑↑↑");


            logView.BlankLine();
            logView.Log("↓↓↓↓↓↓ 对齐优化-开始 ↓↓↓↓↓↓");
            string zipalignPath = PathUtils.GetPath(Constants.PATH_ZIPALIGN);

            args = zipalignPath + " -f 4 " + tempApkFilePath + " " + newApkPath;

            ret = CmdUtils.ExecCmdAndWaitForExit(args, logView);
            if (ret == null || ret.Length < 2 || !string.IsNullOrEmpty(ret[1]))
            {
                logView.Log(">>>>>>对齐优化失败: 执行CMD失败");
                return(false);
            }
            logView.Log("↑↑↑↑↑↑ 对齐优化-结束 ↑↑↑↑↑↑");
            logView.BlankLine();


            if (!File.Exists(newApkPath))
            {
                logView.Log(">>>>>>重新签名失败: " + newApkPath + "导出的新apk文件不存在!");
                return(false);
            }

            logView.Log("导出apk为: " + newApkPath);

            return(true);
        }
Example #19
0
 public List <string> Run(bool isReturn)
 {
     CmdUtils.RunCmdListSync(cmdList, isReturn);
     return(null);
 }
Example #20
0
 /// <summary>
 /// 最后统一执行所有命令
 /// </summary>
 public void Run2(int id, out int number)
 {
     CmdUtils.RunCmdListSync12(cmdList, id, out number);
 }
Example #21
0
 /// <summary>
 /// 最后统一执行所有命令
 /// </summary>
 public void Run()
 {
     CmdUtils.RunCmdListSync1(cmdList);
 }
Example #22
0
 public void RunCmdStandardTest()
 {
     CmdUtils.RunCmdStandard("ipconfig");
 }