Ejemplo n.º 1
0
        public static string ReadFile(string remote)
        {
            var cmd = CliCommand.Create(CliScope.AdbShell, "cat {0}", remote);
            var res = CliResult.Run(cmd, CliDataType.String);

            return(res.String);
        }
Ejemplo n.º 2
0
        private static CCRecord ReadRecord(CCArguments args)
        {
            string ddCmdStr = args.Compile();

            ddCmdStr = String.Format("\"{0}\"", ddCmdStr);

            var ddCmd = CliCommand.Create(CliScope.AdbExecOut, ddCmdStr);


            var ddRes = CliResult.Run(ddCmd, CliDataType.ByteArray);

            var ccRec = new CCRecord();

            lock (ccRec) {
                ccRec.BinaryRaw = ddRes.ByteArray;
                //ccRec.StatsRaw = Android.Value.ReadFile(args.StatsRedirect);
            }

            //ddRes.CommandProcess.Close();
            //ddRes.CommandProcess.WaitForExit();
            //ddRes.CommandProcess.Kill();


            return(ccRec);
        }
Ejemplo n.º 3
0
        public static void Reset()
        {
            // adb shell "rm /data/local/tmp/busybox"

            CliCommand rmCmd = CliCommand.Create(CliScope.AdbShell, "rm {0}", REMOTE_BUSYBOX_EXE);

            var rmResult = CliResult.Run(rmCmd);
        }
Ejemplo n.º 4
0
        public static string GetFileSha1Hash(string remote)
        {
            var cmd  = CliCommand.Create(CliScope.AdbShell, "sha1sum \"{0}\"", remote);
            var res  = CliResult.Run(cmd, CliDataType.String);
            var hash = res.String.Split(" ")[0];

            return(hash.ToUpper());
        }
Ejemplo n.º 5
0
        public static long GetFileSize(string s)
        {
            // sprintf(buf, "wc -c < \"%s\"", remoteFile);

            var cmd = CliCommand.Create(CliScope.AdbShell, "\"wc -c < \"{0}\"\"", s);
            var res = CliResult.Run(cmd, CliDataType.String);

            //Console.WriteLine(res.Data);
            var n = long.Parse((string)res.Data);


            return(n);
        }
Ejemplo n.º 6
0
        private static string?GetSerial()
        {
            var devices       = CliCommand.Create(CliScope.Adb, "devices");
            var devicesResult = CliResult.Run(devices, CliDataType.StringArray);

            var resultLines = devicesResult.StringArray;


            var hasDevice = resultLines?.Length >= 2 && resultLines[1] != null;

            Debug.Assert(resultLines != null);

            var device = hasDevice ? resultLines[1].SubstringBefore("device").Trim() : null;

            return(device);
        }
Ejemplo n.º 7
0
 private static void ForEachCommand(Action <CliCommand> action)
 {
     using var handler = new CliCommandHandler();
     foreach (string commandName in CliCommand.Names)
     {
         var command = CliCommand.Create(commandName, handler);
         if (command is CliMultiCommand multiCommand)
         {
             foreach (string stringCommandName in multiCommand.SubCommandNames)
             {
                 action(multiCommand.GetCommand(stringCommandName));
             }
         }
         else
         {
             action(command);
         }
     }
 }
Ejemplo n.º 8
0
        public static void Setup()
        {
            if (!HasDevice)
            {
                throw new CliException("No device");
            }

            //
            // adb push busybox /data/local/tmp/busybox
            //

            var pushCmd = CliCommand.Create(CliScope.Adb, "push {0} {1}", BUSYBOX_EXE, REMOTE_BUSYBOX_EXE);

            var pushResult = CliResult.Run(pushCmd, CliDataType.StringArray);

            bool pushOk = pushResult.SuccessfulIfLineContains("busybox: 1 file pushed");


            if (!pushOk)
            {
                throw new CliException("Could not push busybox to device");
            }

            //
            // chmod +x /data/local/tmp/busybox
            //

            var chmodCmd = CliCommand.Create(CliScope.AdbShell, "chmod +x {0}", REMOTE_BUSYBOX_EXE);

            var chmodResult = CliResult.Run(chmodCmd, CliDataType.StringArray);


            if (!HasBusybox)
            {
                throw new CliException("Busybox failure to device");
            }
        }