Example #1
0
 public static void Update()
 {
     _commands.Clear();
     using (StringReader reader = new StringReader(ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, false, "busybox", new string[0]))))
     {
         string str = reader.ReadLine();
         if (str.ToLower().Contains($"{"busybox"}: not found") || str.ToLower().Contains("permission denied"))
         {
             _isInstalled = false;
             _version     = string.Empty;
         }
         else
         {
             _isInstalled = true;
             _version     = str.Split(new char[] { ' ' })[1].Substring(1);
             while (reader.ReadLine() != "Currently defined functions:")
             {
             }
             foreach (string str2 in reader.ReadToEnd().Replace(" ", "").Replace("\r\r\n\t", "").Trim(new char[] { '\t', '\r', '\n' }).Split(new char[] { ',' }))
             {
                 _commands.Add(str2);
             }
         }
     }
 }
 public static bool DirectoryExists(string pathToDir, bool createIfNotExist)
 {
     if (createIfNotExist)
     {
         string str = ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, true, "if [ ! -d \"" + pathToDir + "\" ] ;", new string[] { "then mkdir " + pathToDir + " ;", "else", "echo 'Directory exists!' ;", "fi" }));
         return(true);
     }
     return(ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, true, "if [ ! -d \"" + pathToDir + "\" ] ;", new string[] { "then echo 'Directory not exist!' ;", "else", "echo 'Directory exists!' ;", "fi" })).ToLower().Contains("directory exists!"));
 }
        public static bool GetDevicePIT(string outputPath, ref string pitFileName, string devStorageLoc, int bufferSize)
        {
            string property = BuildPropertyParser.GetProperty("ro.product.model");

            if (ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, true, "busybox dd", new string[] { "if=/dev/block/mmcblk0", "of=" + devStorageLoc + "/" + property + ".pit", "bs=1024", "count=" + Conversions.ToString(bufferSize) })).ToLower().Contains("exitcode=0"))
            {
                pitFileName = property + ".pit";
                _device.PullFile(devStorageLoc + "/" + pitFileName, outputPath);
                ADB.IssueADBCmdNoOutput(ADB.CreateADBShellCmd(_device, false, "busybox rm", new string[] { devStorageLoc + "/" + pitFileName }));
                return(true);
            }
            return(false);
        }
 public static string MD5Sum(string str)
 {
     if (!BusyBox.IsInstalled)
     {
         return("BusyBox Not Installed!");
     }
     foreach (string str3 in BusyBox.Commands)
     {
         if (str3 == "md5sum")
         {
             return(ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, true, "busybox", new string[] { "md5sum", "\"" + str + "\"" })).Remove(0x20));
         }
     }
     return("md5sum applet Not Found!");
 }
Example #5
0
        public RootAccessType IsRooted()
        {
            string str  = ADB.IssueADBCmd(ADB.CreateADBShellCmd(this, false, "su", new string[] { "-c", "id" }));
            bool   flag = true;

            if (flag == (str.ToLower().Contains("uid=0") & !str.ToLower().Contains("su: not found")))
            {
                return(RootAccessType.PermRooted);
            }
            if (flag == (str.ToLower().Contains("uid=0") & str.ToLower().Contains("su: not found")))
            {
                return(RootAccessType.TempRooted);
            }
            return(RootAccessType.NotRooted);
        }
Example #6
0
        public static void GetKernelVersion()
        {
            string str = ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, false, "cat", new string[] { "/proc/sys/kernel/osrelease", ";", "cat", "/proc/sys/kernel/version" }));

            if (!string.IsNullOrEmpty(str.TrimEnd(new char[0])))
            {
                string[] strArray = Strings.Split(str.TrimEnd(new char[0]), "\r\n", -1, CompareMethod.Binary);
                _release = strArray[0].TrimEnd(new char[0]);
                _version = strArray[1].TrimEnd(new char[0]);
            }
            else
            {
                _release = string.Empty;
                _version = string.Empty;
            }
        }
        public static string GetMountPoint(string folder)
        {
            string str2 = ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, false, "busybox", new string[] { "mountpoint", "-n", folder }));

            if (string.IsNullOrEmpty(str2))
            {
                return("Unknown");
            }
            if ((str2.ToLower().Contains("no such file or directory") | str2.ToLower().Contains("unknown")) | str2.ToLower().Contains("not a directory"))
            {
                return("Failed!");
            }
            int startIndex = str2.LastIndexOf(' ');

            return(str2.Remove(startIndex));
        }
Example #8
0
 private static void Update()
 {
     _prop.Clear();
     using (StringReader reader = new StringReader(ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, false, "getprop", new string[0]))))
     {
         while (reader.Peek() != -1)
         {
             string str2 = reader.ReadLine();
             if (str2.StartsWith("["))
             {
                 string[] strArray = str2.Split(new char[] { ':' });
                 if (strArray.Length > 2)
                 {
                     int num3 = strArray.Length - 1;
                     for (int i = 2; i <= num3; i++)
                     {
                         string[] strArray2 = strArray;
                         int      num4      = 1;
                         strArray2[num4] = strArray2[num4] + ":" + strArray[i];
                     }
                 }
                 int index = 0;
                 do
                 {
                     if (index == 0)
                     {
                         strArray[index] = strArray[index].Replace("[", string.Empty).Trim();
                     }
                     else
                     {
                         strArray[index] = strArray[index].Replace(" [", string.Empty).Trim();
                     }
                     strArray[index] = strArray[index].Replace("]", string.Empty).Trim();
                     index++;
                 }while (index <= 1);
                 if (string.IsNullOrEmpty(strArray[1].TrimEnd(new char[0])))
                 {
                     _prop.Add(strArray[0].TrimEnd(new char[0]), string.Empty);
                 }
                 else
                 {
                     _prop.Add(strArray[0].TrimEnd(new char[0]), strArray[1].TrimEnd(new char[0]));
                 }
             }
         }
     }
 }
        public static List <PartitionInfo> GetSamsungPartitions(string pitFile)
        {
            List <PartitionInfo> list2 = new List <PartitionInfo>();

            using (FileStream stream = new FileStream(pitFile, FileMode.Open, FileAccess.Read))
            {
                PitInputStream inputStream = new PitInputStream(stream);
                PitData        data        = new PitData();
                if (!data.ReadPITFile(inputStream))
                {
                    return(list2);
                }
                string[] strArray = Strings.Split(ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, false, "busybox", new string[] { "find", "/dev/block", "-maxdepth 1", "-iname", "'mmcblk0p*'", "|", "busybox", "tac" })), "\r\n", -1, CompareMethod.Binary);
                if (strArray.Length <= 1)
                {
                    stream.Close();
                    throw new Exception("Unable to enumerate partitions!");
                }
                foreach (string str5 in strArray)
                {
                    int num;
                    if (int.TryParse(str5.Substring(str5.LastIndexOf("p") + 1), out num))
                    {
                        foreach (PitEntry entry in data.Entries)
                        {
                            if (entry.PartitionID == num)
                            {
                                string partitionName = entry.PartitionName;
                                string str2          = str5;
                                string str           = str5.Remove(0, str5.LastIndexOf("/") + 1);
                                if (!string.IsNullOrEmpty(entry.FlashFileName.Trim(Invalids)) & (entry.FlashFileName.Trim(Invalids) != "-"))
                                {
                                    list2.Add(new PartitionInfo(partitionName.Trim(Invalids).ToLower(), entry.FlashFileName.Trim(Invalids).ToLower(), str2.Trim(Invalids), str.Trim(Invalids)));
                                }
                                else
                                {
                                    list2.Add(new PartitionInfo(partitionName.Trim(Invalids).ToLower(), partitionName.Trim(Invalids).ToLower() + ".epb", str2.Trim(Invalids), str.Trim(Invalids)));
                                }
                                break;
                            }
                        }
                    }
                }
            }
            return(list2);
        }
 private static void GetSUInfo()
 {
     using (StringReader reader = new StringReader(ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, false, "su", new string[] { "-v" }))))
     {
         string str = reader.ReadLine();
         if (str.ToLower().Contains("not found") | str.ToLower().Contains("permission denied"))
         {
             _version   = string.Empty;
             _isPresent = false;
         }
         else
         {
             _version   = str;
             _isPresent = true;
         }
     }
 }
        public static string EnableHiddenMenu(bool enable)
        {
            string str        = "/system/build.prop";
            string mountPoint = GetMountPoint("/system");

            if (!mountPoint.ToLower().StartsWith("/dev/block"))
            {
                throw new Exception("Unable to detect '/system' mount point!");
            }
            if (!FileExists("/efs/carrier/HiddenMenu"))
            {
                throw new Exception("HiddenMenu flag not found! This is not intended for your device variant!");
            }
            if (enable)
            {
                return(ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, true, "mount -o rw,remount " + mountPoint + " /system ;", new string[] { "if busybox grep -qe \"sys.hiddenmenu.enable=0\" " + str + " ;", "then busybox sed -n 's/^sys.hiddenmenu.enable=0$/sys.hiddenmenu.enable=1/'", str, "; echo -n ON > /efs/carrier/HiddenMenu ; echo 'HiddenMenu has been enabled!' ; elif ! grep -qe \"sys.hiddenmenu.enable\"", str, ";", @"then sed -i '$ a\sys.hiddenmenu.enable=1' " + str + " ;", "echo -n ON > /efs/carrier/HiddenMenu ; echo 'HiddenMenu has been enabled!' ; else", "echo 'HiddenMenu already enabled!' ;", "fi ; mount -o ro,remount " + mountPoint + " /system" })));
            }
            return(ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, true, "mount -o rw,remount " + mountPoint + " /system ;", new string[] { "if busybox grep -qe \"sys.hiddenmenu.enable\" " + str + " ;", "then busybox sed -i '/sys.hiddenmenu.enable/d' " + str + " ; echo -n OFF > /efs/carrier/HiddenMenu ; echo 'HiddenMenu has been disabled!' ; else", "echo 'HiddenMenu already disabled!' ;", "fi ; mount -o ro,remount " + mountPoint + " /system" })));
        }
        public static ListingType IsFileOrDirectory(string location)
        {
            if (!BusyBox.IsInstalled)
            {
                return(ListingType.BBOX_ERROR);
            }
            ADBCommand cmd     = ADB.CreateADBShellCmd(_device, false, $"if [ -f {location} ]; then echo " 1 "; else echo " 0 "; fi", new string[0]);
            ADBCommand command = ADB.CreateADBShellCmd(_device, false, $"if [ -d {location} ]; then echo " 1 "; else echo " 0 "; fi", new string[0]);

            if (ADB.IssueADBCmd(cmd).Contains("1"))
            {
                return(ListingType.FILE);
            }
            if (ADB.IssueADBCmd(command).Contains("1"))
            {
                return(ListingType.DIRECTORY);
            }
            return(ListingType.NONE);
        }
        public static List <PartitionInfo> GetPartitions()
        {
            List <PartitionInfo> list2 = new List <PartitionInfo>();

            string[] strArray = Strings.Split(ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, false, "Partition=$(busybox", new string[] {
                "find", "/dev/block/platform", "-type", "d", "-iname", "'by-name'", "-exec", "busybox", "find", "{}", "-maxdepth 1", "-type", "l", @"\;", "|", "busybox",
                "tac", ")", ";", "for", "Blocks", "in", "$Partition", ";", "do", "busybox", "basename", "$Blocks", "|", "busybox", "tr", @"'\n'",
                "' '", ";", "busybox", "busybox", "readlink", "$Blocks", ";", "done"
            })), "\r\n", -1, CompareMethod.Binary);
            if (strArray.Length <= 1)
            {
                throw new Exception("Unable to enumerate partitions!");
            }
            foreach (string str5 in strArray)
            {
                string str3 = str5.Remove(str5.IndexOf(' ') + 1);
                string str2 = str5.Remove(0, str5.IndexOf(' ') + 1);
                string str  = str5.Remove(0, str5.LastIndexOf("/") + 1);
                list2.Add(new PartitionInfo(str3.Trim(Invalids).ToLower(), str3.Trim(Invalids).ToLower() + ".epb", str2.Trim(Invalids), str.Trim(Invalids)));
            }
            return(list2);
        }
Example #14
0
 public bool InstallAPK(string location) =>
 Conversions.ToBoolean(ADB.IssueADBCmd(ADB.CreateADBCmd(this, "install", new string[] { "\"" + location + "\"" })));
Example #15
0
 public bool IsSecureDevice() =>
 ADB.IssueADBCmd(ADB.CreateADBShellCmd(this, false, "cat", new string[] { "/default.prop" })).ToLower().Contains("ro.secure=1");
 public static bool FileExists(string pathToFile) =>
 ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, true, "if [ ! -f \"" + pathToFile + "\" ];", new string[] { "then echo 'File not exist!';", "else", "echo 'File exists!';", "fi" })).ToLower().Contains("file exists!");
Example #17
0
 public string PullDirectory(string location, string destination) =>
 ADB.IssueADBCmd(ADB.CreateADBCmd(this, "pull", new string[] { "\"" + (location.EndsWith("/") ? location : (location + "/")) + "\"", "\"" + destination + "\"" }));
 public static bool CheckMMCBlk0Exists() =>
 ADB.IssueADBCmd(ADB.CreateADBShellCmd(_device, false, "busybox ls", new string[] { "/dev/block/mmcblk0" })).ToLower().Contains("/dev/block/mmcblk0");
Example #19
0
 public string PushFile(string localPath, string remotePath) =>
 ADB.IssueADBCmd(ADB.CreateADBCmd(this, "push", new string[] { "\"" + localPath + "\"", "\"" + remotePath + "\"" }));