package com.stericson.RootTools.internal;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.os.StatFs;
import android.util.Log;
import com.stericson.RootShell.RootShell;
import com.stericson.RootShell.execution.Command;
import com.stericson.RootShell.execution.Shell;
import com.stericson.RootTools.RootTools;
import com.stericson.RootTools.containers.Mount;
import com.stericson.RootTools.containers.Permissions;
import com.stericson.RootTools.containers.Symlink;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class RootToolsInternalMethods
{
  private void commandWait(Shell paramShell, Command paramCommand)
    throws Exception
  {
    while (!paramCommand.isFinished())
    {
      RootTools.log("RootTools v4.2", paramShell.getCommandQueuePositionString(paramCommand));
      RootTools.log("RootTools v4.2", "Processed " + paramCommand.totalOutputProcessed + " of " + paramCommand.totalOutput + " output from command.");
      try
      {
        if (!paramCommand.isFinished()) {
          paramCommand.wait(2000L);
        }
        if ((paramCommand.isExecuting()) || (paramCommand.isFinished())) {
          continue;
        }
        if ((!paramShell.isExecuting) && (!paramShell.isReading))
        {
          Log.e("RootTools v4.2", "Waiting for a command to be executed in a shell that is not executing and not reading! \n\n Command: " + paramCommand.getCommand());
          Exception localException1 = new Exception();
          localException1.setStackTrace(Thread.currentThread().getStackTrace());
          localException1.printStackTrace();
          continue;
        }
      }
      catch (InterruptedException localInterruptedException)
      {
        for (;;)
        {
          localInterruptedException.printStackTrace();
        }
      }
      finally {}
      Exception localException2;
      if ((paramShell.isExecuting) && (!paramShell.isReading))
      {
        Log.e("RootTools v4.2", "Waiting for a command to be executed in a shell that is executing but not reading! \n\n Command: " + paramCommand.getCommand());
        localException2 = new Exception();
        localException2.setStackTrace(Thread.currentThread().getStackTrace());
        localException2.printStackTrace();
      }
      else
      {
        Log.e("RootTools v4.2", "Waiting for a command to be executed in a shell that is not reading! \n\n Command: " + paramCommand.getCommand());
        localException2 = new Exception();
        localException2.setStackTrace(Thread.currentThread().getStackTrace());
        localException2.printStackTrace();
      }
    }
  }
  
  public static void getInstance()
  {
    RootTools.setRim(new RootToolsInternalMethods());
  }
  
  public boolean checkUtil(String paramString)
  {
    Object localObject = RootShell.findBinary(paramString);
    if (((List)localObject).size() > 0)
    {
      Iterator localIterator = ((List)localObject).iterator();
      while (localIterator.hasNext())
      {
        String str = (String)localIterator.next();
        localObject = RootTools.getFilePermissionsSymlinks(str + "/" + paramString);
        if (localObject != null)
        {
          if (Integer.toString(((Permissions)localObject).getPermissions()).length() > 3) {}
          for (localObject = Integer.toString(((Permissions)localObject).getPermissions()).substring(1); (((String)localObject).equals("755")) || (((String)localObject).equals("777")) || (((String)localObject).equals("775")); localObject = Integer.toString(((Permissions)localObject).getPermissions()))
          {
            RootTools.utilPath = str + "/" + paramString;
            return true;
          }
        }
      }
    }
    return false;
  }
  
  public boolean copyFile(String paramString1, String paramString2, boolean paramBoolean1, boolean paramBoolean2)
  {
    Object localObject2 = null;
    localCommand = null;
    bool = true;
    if (paramBoolean1) {
      localObject1 = localObject2;
    }
    for (;;)
    {
      try
      {
        RootTools.remount(paramString2, "RW");
        localObject1 = localObject2;
        if (checkUtil("cp"))
        {
          localObject1 = localObject2;
          RootTools.log("cp command is available!");
          if (paramBoolean2)
          {
            localObject1 = localObject2;
            localCommand = new Command(0, false, new String[] { "cp -fp " + paramString1 + " " + paramString2 });
            paramString1 = localCommand;
          }
        }
      }
      catch (Exception paramString1)
      {
        int i;
        paramString1.printStackTrace();
        bool = false;
        continue;
        paramBoolean2 = false;
        paramString1 = localCommand;
        continue;
      }
      try
      {
        Shell.startRootShell().add(localCommand);
        paramString1 = localCommand;
        commandWait(Shell.startRootShell(), localCommand);
        paramString1 = localCommand;
        i = localCommand.getExitCode();
        if (i != 0) {
          continue;
        }
        paramBoolean2 = true;
        paramString1 = localCommand;
      }
      catch (Exception paramString2)
      {
        localObject1 = paramString1;
        paramString1 = paramString2;
        continue;
        paramString1 = localCommand;
        paramBoolean2 = bool;
        continue;
      }
      localObject1 = paramString1;
      bool = paramBoolean2;
      if (paramBoolean1)
      {
        localObject1 = paramString1;
        RootTools.remount(paramString2, "RO");
        bool = paramBoolean2;
        localObject1 = paramString1;
      }
      if (localObject1 != null)
      {
        if (((Command)localObject1).getExitCode() != 0) {
          break label746;
        }
        bool = true;
      }
      return bool;
      paramBoolean2 = false;
      continue;
      localObject1 = localObject2;
      localCommand = new Command(0, false, new String[] { "cp -f " + paramString1 + " " + paramString2 });
      paramString1 = localCommand;
      Shell.startRootShell().add(localCommand);
      paramString1 = localCommand;
      commandWait(Shell.startRootShell(), localCommand);
      paramString1 = localCommand;
      i = localCommand.getExitCode();
      if (i == 0)
      {
        paramBoolean2 = true;
        paramString1 = localCommand;
      }
      else
      {
        paramBoolean2 = false;
        continue;
        localObject1 = localObject2;
        if (checkUtil("busybox"))
        {
          localObject1 = localObject2;
          if (hasUtil("cp", "busybox"))
          {
            localObject1 = localObject2;
            RootTools.log("busybox cp command is available!");
            if (paramBoolean2)
            {
              localObject1 = localObject2;
              localCommand = new Command(0, false, new String[] { "busybox cp -fp " + paramString1 + " " + paramString2 });
              paramString1 = localCommand;
              Shell.startRootShell().add(localCommand);
              paramString1 = localCommand;
              commandWait(Shell.startRootShell(), localCommand);
              paramString1 = localCommand;
              paramBoolean2 = bool;
              continue;
            }
            localObject1 = localObject2;
            localCommand = new Command(0, false, new String[] { "busybox cp -f " + paramString1 + " " + paramString2 });
            paramString1 = localCommand;
            Shell.startRootShell().add(localCommand);
            paramString1 = localCommand;
            commandWait(Shell.startRootShell(), localCommand);
            paramString1 = localCommand;
            paramBoolean2 = bool;
            continue;
          }
        }
        localObject1 = localObject2;
        if (!checkUtil("cat")) {
          continue;
        }
        localObject1 = localObject2;
        RootTools.log("cp is not available, use cat!");
        i = -1;
        if (paramBoolean2)
        {
          localObject1 = localObject2;
          i = getFilePermissionsSymlinks(paramString1).getPermissions();
        }
        localObject1 = localObject2;
        localCommand = new Command(0, false, new String[] { "cat " + paramString1 + " > " + paramString2 });
        paramString1 = localCommand;
        Shell.startRootShell().add(localCommand);
        paramString1 = localCommand;
        commandWait(Shell.startRootShell(), localCommand);
        if (!paramBoolean2) {
          break label757;
        }
        paramString1 = localCommand;
        localCommand = new Command(0, false, new String[] { "chmod " + i + " " + paramString2 });
        localObject1 = localCommand;
        Shell.startRootShell().add(localCommand);
        localObject1 = localCommand;
        commandWait(Shell.startRootShell(), localCommand);
        paramString1 = localCommand;
        paramBoolean2 = bool;
      }
    }
    label746:
    return false;
  }
  
  public boolean deleteFileOrDirectory(String paramString, boolean paramBoolean)
  {
    bool2 = true;
    if (paramBoolean) {}
    try
    {
      RootTools.remount(paramString, "RW");
      Command localCommand;
      boolean bool1;
      if (hasUtil("rm", "toolbox"))
      {
        RootTools.log("rm command is available!");
        localCommand = new Command(0, false, new String[] { "rm -r " + paramString });
        Shell.startRootShell().add(localCommand);
        commandWait(Shell.startRootShell(), localCommand);
        bool1 = bool2;
        if (localCommand.getExitCode() != 0)
        {
          RootTools.log("target not exist or unable to delete file");
          bool1 = false;
        }
      }
      for (;;)
      {
        bool2 = bool1;
        if (!paramBoolean) {
          break;
        }
        RootTools.remount(paramString, "RO");
        return bool1;
        bool1 = bool2;
        if (checkUtil("busybox"))
        {
          bool1 = bool2;
          if (hasUtil("rm", "busybox"))
          {
            RootTools.log("busybox rm command is available!");
            localCommand = new Command(0, false, new String[] { "busybox rm -rf " + paramString });
            Shell.startRootShell().add(localCommand);
            commandWait(Shell.startRootShell(), localCommand);
            bool1 = bool2;
            if (localCommand.getExitCode() != 0)
            {
              RootTools.log("target not exist or unable to delete file");
              bool1 = false;
            }
          }
        }
      }
      return bool2;
    }
    catch (Exception paramString)
    {
      paramString.printStackTrace();
      bool2 = false;
    }
  }
  
  public void fixUtil(String paramString1, String paramString2)
  {
    try
    {
      RootTools.remount("/system", "rw");
      Object localObject1 = RootShell.findBinary(paramString1);
      if (((List)localObject1).size() > 0)
      {
        localObject1 = ((List)localObject1).iterator();
        while (((Iterator)localObject1).hasNext())
        {
          Object localObject2 = (String)((Iterator)localObject1).next();
          localObject2 = new Command(0, false, new String[] { paramString2 + " rm " + (String)localObject2 + "/" + paramString1 });
          RootShell.getShell(true).add((Command)localObject2);
          commandWait(RootShell.getShell(true), (Command)localObject2);
        }
        paramString1 = new Command(0, false, new String[] { paramString2 + " ln -s " + paramString2 + " /system/bin/" + paramString1, paramString2 + " chmod 0755 /system/bin/" + paramString1 });
        RootShell.getShell(true).add(paramString1);
        commandWait(RootShell.getShell(true), paramString1);
      }
      RootTools.remount("/system", "ro");
      return;
    }
    catch (Exception paramString1) {}
  }
  
  public boolean fixUtils(String[] paramArrayOfString)
    throws Exception
  {
    int j = paramArrayOfString.length;
    int i = 0;
    if (i < j)
    {
      String str = paramArrayOfString[i];
      if (!checkUtil(str))
      {
        if (!checkUtil("busybox")) {
          break label60;
        }
        if (hasUtil(str, "busybox")) {
          fixUtil(str, RootTools.utilPath);
        }
      }
      for (;;)
      {
        i += 1;
        break;
        label60:
        if (!checkUtil("toolbox")) {
          break label94;
        }
        if (hasUtil(str, "toolbox")) {
          fixUtil(str, RootTools.utilPath);
        }
      }
      label94:
      return false;
    }
    return true;
  }
  
  public List<String> getBusyBoxApplets(final String paramString)
    throws Exception
  {
    Object localObject;
    if ((paramString != null) && (!paramString.endsWith("/")) && (!paramString.equals(""))) {
      localObject = paramString + "/";
    }
    do
    {
      paramString = new ArrayList();
      localObject = new Command(3, false, new String[] { (String)localObject + "busybox --list" })
      {
        public void commandOutput(int paramAnonymousInt, String paramAnonymousString)
        {
          if ((paramAnonymousInt == 3) && (!paramAnonymousString.trim().equals("")) && (!paramAnonymousString.trim().contains("not found")) && (!paramAnonymousString.trim().contains("file busy"))) {
            paramString.add(paramAnonymousString);
          }
          super.commandOutput(paramAnonymousInt, paramAnonymousString);
        }
      };
      RootShell.getShell(false).add((Command)localObject);
      commandWait(RootShell.getShell(false), (Command)localObject);
      if (paramString.size() <= 0)
      {
        RootShell.getShell(true).add((Command)localObject);
        commandWait(RootShell.getShell(true), (Command)localObject);
      }
      return paramString;
      localObject = paramString;
    } while (paramString != null);
    throw new Exception("Path is null, please specifiy a path");
  }
  
  public String getBusyBoxVersion(String paramString)
  {
    Object localObject = paramString;
    if (!paramString.equals(""))
    {
      localObject = paramString;
      if (!paramString.endsWith("/")) {
        localObject = paramString + "/";
      }
    }
    InternalVariables.busyboxVersion = "";
    try
    {
      paramString = new Command(4, false, new String[] { (String)localObject + "busybox" })
      {
        public void commandOutput(int paramAnonymousInt, String paramAnonymousString)
        {
          paramAnonymousString = paramAnonymousString.trim();
          if (paramAnonymousInt == 4)
          {
            RootTools.log("Version Output: " + paramAnonymousString);
            String[] arrayOfString = paramAnonymousString.split(" ");
            if ((arrayOfString.length > 1) && (arrayOfString[1].contains("v1.")) && (0 == 0))
            {
              InternalVariables.busyboxVersion = arrayOfString[1];
              RootTools.log("Found Version: " + InternalVariables.busyboxVersion);
            }
          }
          super.commandOutput(paramAnonymousInt, paramAnonymousString);
        }
      };
      RootTools.log("Getting BusyBox Version without root");
      localObject = RootTools.getShell(false);
      ((Shell)localObject).add(paramString);
      commandWait((Shell)localObject, paramString);
      if (InternalVariables.busyboxVersion.length() <= 0)
      {
        RootTools.log("Getting BusyBox Version with root");
        localObject = RootTools.getShell(true);
        ((Shell)localObject).add(paramString);
        commandWait((Shell)localObject, paramString);
      }
      return InternalVariables.busyboxVersion;
    }
    catch (Exception paramString)
    {
      RootTools.log("BusyBox was not found, more information MAY be available with Debugging on.");
    }
    return "";
  }
  
  public long getConvertedSpace(String paramString)
  {
    double d2 = 1.0D;
    for (;;)
    {
      double d1;
      char c;
      try
      {
        StringBuffer localStringBuffer = new StringBuffer();
        int i = 0;
        d1 = d2;
        if (i < paramString.length())
        {
          c = paramString.charAt(i);
          if ((!Character.isDigit(c)) && (c != '.'))
          {
            if (c == 'm') {
              break label106;
            }
            if (c != 'M') {
              break label113;
            }
            break label106;
          }
        }
        else
        {
          return Math.ceil(Double.valueOf(localStringBuffer.toString()).doubleValue() * d1);
        }
        localStringBuffer.append(paramString.charAt(i));
        i += 1;
        continue;
        d1 = 1024.0D;
      }
      catch (Exception paramString)
      {
        return -1L;
      }
      label106:
      continue;
      label113:
      if (c != 'g')
      {
        d1 = d2;
        if (c != 'G') {}
      }
      else
      {
        d1 = 1048576.0D;
      }
    }
  }
  
  public Permissions getFilePermissionsSymlinks(String paramString)
  {
    Permissions localPermissions = null;
    RootTools.log("Checking permissions for " + paramString);
    if (RootTools.exists(paramString)) {
      RootTools.log(paramString + " was found.");
    }
    try
    {
      paramString = new Command(1, false, new String[] { "ls -l " + paramString, "busybox ls -l " + paramString, "/system/bin/failsafe/toolbox ls -l " + paramString, "toolbox ls -l " + paramString })
      {
        public void commandOutput(int paramAnonymousInt, String paramAnonymousString)
        {
          if (paramAnonymousInt == 1)
          {
            str3 = "";
            if (paramAnonymousString.split(" ")[0].length() != 10)
            {
              super.commandOutput(paramAnonymousInt, paramAnonymousString);
              return;
            }
            RootTools.log("Line " + paramAnonymousString);
          }
          for (;;)
          {
            try
            {
              String[] arrayOfString = paramAnonymousString.split(" ");
              str1 = str3;
              if (arrayOfString[(arrayOfString.length - 2)].equals("->"))
              {
                RootTools.log("Symlink found.");
                str1 = arrayOfString[(arrayOfString.length - 1)];
              }
            }
            catch (Exception localException2)
            {
              String str1;
              String str2 = str3;
              continue;
            }
            try
            {
              InternalVariables.permissions = RootToolsInternalMethods.this.getPermissions(paramAnonymousString);
              if (InternalVariables.permissions != null) {
                InternalVariables.permissions.setSymlink(str1);
              }
              super.commandOutput(paramAnonymousInt, paramAnonymousString);
              return;
            }
            catch (Exception localException1)
            {
              RootTools.log(localException1.getMessage());
            }
          }
        }
      };
      RootShell.getShell(true).add(paramString);
      commandWait(RootShell.getShell(true), paramString);
      localPermissions = InternalVariables.permissions;
      return localPermissions;
    }
    catch (Exception paramString)
    {
      RootTools.log(paramString.getMessage());
    }
    return null;
  }
  
  public String getInode(String paramString)
  {
    try
    {
      paramString = new Command(5, false, new String[] { "/data/local/ls -i " + paramString })
      {
        public void commandOutput(int paramAnonymousInt, String paramAnonymousString)
        {
          if ((paramAnonymousInt == 5) && (!paramAnonymousString.trim().equals("")) && (Character.isDigit(paramAnonymousString.trim().substring(0, 1).toCharArray()[0]))) {
            InternalVariables.inode = paramAnonymousString.trim().split(" ")[0];
          }
          super.commandOutput(paramAnonymousInt, paramAnonymousString);
        }
      };
      Shell.startRootShell().add(paramString);
      commandWait(Shell.startRootShell(), paramString);
      paramString = InternalVariables.inode;
      return paramString;
    }
    catch (Exception paramString) {}
    return "";
  }
  
  public String getMountedAs(String paramString)
    throws Exception
  {
    InternalVariables.mounts = getMounts();
    if (InternalVariables.mounts != null)
    {
      Iterator localIterator = InternalVariables.mounts.iterator();
      while (localIterator.hasNext())
      {
        Mount localMount = (Mount)localIterator.next();
        String str = localMount.getMountPoint().getAbsolutePath();
        if (str.equals("/"))
        {
          if (paramString.equals("/")) {
            return (String)localMount.getFlags().toArray()[0];
          }
        }
        else if ((paramString.equals(str)) || (paramString.startsWith(str + "/")))
        {
          RootTools.log((String)localMount.getFlags().toArray()[0]);
          return (String)localMount.getFlags().toArray()[0];
        }
      }
      throw new Exception();
    }
    throw new Exception();
  }
  
  /* Error */
  public ArrayList<Mount> getMounts()
    throws Exception
  {
    // Byte code:
    //   0: iconst_1
    //   1: invokestatic 336	com/stericson/RootTools/RootTools:getShell	(Z)Lcom/stericson/RootShell/execution/Shell;
    //   4: astore_1
    //   5: new 35	com/stericson/RootShell/execution/Command
    //   8: dup
    //   9: iconst_0
    //   10: iconst_0
    //   11: iconst_2
    //   12: anewarray 165	java/lang/String
    //   15: dup
    //   16: iconst_0
    //   17: ldc_w 447
    //   20: aastore
    //   21: dup
    //   22: iconst_1
    //   23: ldc_w 449
    //   26: aastore
    //   27: invokespecial 225	com/stericson/RootShell/execution/Command:<init>	(IZ[Ljava/lang/String;)V
    //   30: astore_2
    //   31: aload_1
    //   32: aload_2
    //   33: invokevirtual 233	com/stericson/RootShell/execution/Shell:add	(Lcom/stericson/RootShell/execution/Command;)Lcom/stericson/RootShell/execution/Command;
    //   36: pop
    //   37: aload_0
    //   38: aload_1
    //   39: aload_2
    //   40: invokespecial 235	com/stericson/RootTools/internal/RootToolsInternalMethods:commandWait	(Lcom/stericson/RootShell/execution/Shell;Lcom/stericson/RootShell/execution/Command;)V
    //   43: aconst_null
    //   44: astore 4
    //   46: aconst_null
    //   47: astore_2
    //   48: new 451	java/io/FileReader
    //   51: dup
    //   52: ldc_w 453
    //   55: invokespecial 454	java/io/FileReader:<init>	(Ljava/lang/String;)V
    //   58: astore_1
    //   59: new 456	java/io/LineNumberReader
    //   62: dup
    //   63: aload_1
    //   64: invokespecial 459	java/io/LineNumberReader:<init>	(Ljava/io/Reader;)V
    //   67: astore_3
    //   68: new 311	java/util/ArrayList
    //   71: dup
    //   72: invokespecial 312	java/util/ArrayList:<init>	()V
    //   75: astore_2
    //   76: aload_3
    //   77: invokevirtual 462	java/io/LineNumberReader:readLine	()Ljava/lang/String;
    //   80: astore 4
    //   82: aload 4
    //   84: ifnull +79 -> 163
    //   87: aload 4
    //   89: invokestatic 218	com/stericson/RootTools/RootTools:log	(Ljava/lang/String;)V
    //   92: aload 4
    //   94: ldc -34
    //   96: invokevirtual 466	java/lang/String:split	(Ljava/lang/String;)[Ljava/lang/String;
    //   99: astore 4
    //   101: aload_2
    //   102: new 423	com/stericson/RootTools/containers/Mount
    //   105: dup
    //   106: new 429	java/io/File
    //   109: dup
    //   110: aload 4
    //   112: iconst_0
    //   113: aaload
    //   114: invokespecial 467	java/io/File:<init>	(Ljava/lang/String;)V
    //   117: new 429	java/io/File
    //   120: dup
    //   121: aload 4
    //   123: iconst_1
    //   124: aaload
    //   125: invokespecial 467	java/io/File:<init>	(Ljava/lang/String;)V
    //   128: aload 4
    //   130: iconst_2
    //   131: aaload
    //   132: aload 4
    //   134: iconst_3
    //   135: aaload
    //   136: invokespecial 470	com/stericson/RootTools/containers/Mount:<init>	(Ljava/io/File;Ljava/io/File;Ljava/lang/String;Ljava/lang/String;)V
    //   139: invokevirtual 472	java/util/ArrayList:add	(Ljava/lang/Object;)Z
    //   142: pop
    //   143: goto -67 -> 76
    //   146: astore 4
    //   148: aload_1
    //   149: astore_2
    //   150: aload 4
    //   152: astore_1
    //   153: aload_2
    //   154: invokevirtual 475	java/io/FileReader:close	()V
    //   157: aload_3
    //   158: invokevirtual 476	java/io/LineNumberReader:close	()V
    //   161: aload_1
    //   162: athrow
    //   163: aload_2
    //   164: putstatic 420	com/stericson/RootTools/internal/InternalVariables:mounts	Ljava/util/ArrayList;
    //   167: getstatic 420	com/stericson/RootTools/internal/InternalVariables:mounts	Ljava/util/ArrayList;
    //   170: ifnull +17 -> 187
    //   173: getstatic 420	com/stericson/RootTools/internal/InternalVariables:mounts	Ljava/util/ArrayList;
    //   176: astore_2
    //   177: aload_1
    //   178: invokevirtual 475	java/io/FileReader:close	()V
    //   181: aload_3
    //   182: invokevirtual 476	java/io/LineNumberReader:close	()V
    //   185: aload_2
    //   186: areturn
    //   187: new 31	java/lang/Exception
    //   190: dup
    //   191: invokespecial 107	java/lang/Exception:<init>	()V
    //   194: athrow
    //   195: astore_1
    //   196: goto -15 -> 181
    //   199: astore_1
    //   200: aload_2
    //   201: areturn
    //   202: astore_2
    //   203: goto -46 -> 157
    //   206: astore_2
    //   207: goto -46 -> 161
    //   210: astore_1
    //   211: aload 4
    //   213: astore_3
    //   214: goto -61 -> 153
    //   217: astore 5
    //   219: aload_1
    //   220: astore_2
    //   221: aload 4
    //   223: astore_3
    //   224: aload 5
    //   226: astore_1
    //   227: goto -74 -> 153
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	230	0	this	RootToolsInternalMethods
    //   4	174	1	localObject1	Object
    //   195	1	1	localException1	Exception
    //   199	1	1	localException2	Exception
    //   210	10	1	localObject2	Object
    //   226	1	1	localObject3	Object
    //   30	171	2	localObject4	Object
    //   202	1	2	localException3	Exception
    //   206	1	2	localException4	Exception
    //   220	1	2	localObject5	Object
    //   67	157	3	localObject6	Object
    //   44	89	4	localObject7	Object
    //   146	76	4	localObject8	Object
    //   217	8	5	localObject9	Object
    // Exception table:
    //   from	to	target	type
    //   68	76	146	finally
    //   76	82	146	finally
    //   87	143	146	finally
    //   163	177	146	finally
    //   187	195	146	finally
    //   177	181	195	java/lang/Exception
    //   181	185	199	java/lang/Exception
    //   153	157	202	java/lang/Exception
    //   157	161	206	java/lang/Exception
    //   48	59	210	finally
    //   59	68	217	finally
  }
  
  public Permissions getPermissions(String paramString)
  {
    paramString = paramString.split(" ")[0];
    if ((paramString.length() == 10) && ((paramString.charAt(0) == '-') || (paramString.charAt(0) == 'd') || (paramString.charAt(0) == 'l')) && ((paramString.charAt(1) == '-') || (paramString.charAt(1) == 'r')) && ((paramString.charAt(2) == '-') || (paramString.charAt(2) == 'w')))
    {
      RootTools.log(paramString);
      Permissions localPermissions = new Permissions();
      localPermissions.setType(paramString.substring(0, 1));
      RootTools.log(localPermissions.getType());
      localPermissions.setUserPermissions(paramString.substring(1, 4));
      RootTools.log(localPermissions.getUserPermissions());
      localPermissions.setGroupPermissions(paramString.substring(4, 7));
      RootTools.log(localPermissions.getGroupPermissions());
      localPermissions.setOtherPermissions(paramString.substring(7, 10));
      RootTools.log(localPermissions.getOtherPermissions());
      StringBuilder localStringBuilder = new StringBuilder();
      localStringBuilder.append(parseSpecialPermissions(paramString));
      localStringBuilder.append(parsePermissions(localPermissions.getUserPermissions()));
      localStringBuilder.append(parsePermissions(localPermissions.getGroupPermissions()));
      localStringBuilder.append(parsePermissions(localPermissions.getOtherPermissions()));
      localPermissions.setPermissions(Integer.parseInt(localStringBuilder.toString()));
      return localPermissions;
    }
    return null;
  }
  
  public long getSpace(String paramString)
  {
    InternalVariables.getSpaceFor = paramString;
    int j = 0;
    RootTools.log("Looking for Space");
    try
    {
      paramString = new Command(6, false, new String[] { "df " + paramString })
      {
        public void commandOutput(int paramAnonymousInt, String paramAnonymousString)
        {
          if ((paramAnonymousInt == 6) && (paramAnonymousString.contains(InternalVariables.getSpaceFor.trim()))) {
            InternalVariables.space = paramAnonymousString.split(" ");
          }
          super.commandOutput(paramAnonymousInt, paramAnonymousString);
        }
      };
      Shell.startRootShell().add(paramString);
      commandWait(Shell.startRootShell(), paramString);
      if (InternalVariables.space != null)
      {
        RootTools.log("First Method");
        paramString = InternalVariables.space;
        int k = paramString.length;
        int i = 0;
        String str;
        while (i < k)
        {
          str = paramString[i];
          RootTools.log(str);
          if (j != 0) {
            return getConvertedSpace(str);
          }
          if (str.equals("used,")) {
            j = 1;
          }
          i += 1;
        }
        k = 0;
        i = 3;
        RootTools.log("Second Method");
        if (InternalVariables.space[0].length() <= 5) {
          i = 2;
        }
        paramString = InternalVariables.space;
        int n = paramString.length;
        j = 0;
        while (j < n)
        {
          str = paramString[j];
          RootTools.log(str);
          int m = k;
          if (str.length() > 0)
          {
            RootTools.log(str + "Valid");
            if (k == i) {
              return getConvertedSpace(str);
            }
            m = k + 1;
          }
          j += 1;
          k = m;
        }
      }
      RootTools.log("Returning -1, space could not be determined.");
      return -1L;
    }
    catch (Exception paramString)
    {
      for (;;) {}
    }
  }
  
  /* Error */
  public ArrayList<Symlink> getSymLinks()
    throws IOException
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore 4
    //   3: aconst_null
    //   4: astore_2
    //   5: new 451	java/io/FileReader
    //   8: dup
    //   9: ldc_w 549
    //   12: invokespecial 454	java/io/FileReader:<init>	(Ljava/lang/String;)V
    //   15: astore_1
    //   16: new 456	java/io/LineNumberReader
    //   19: dup
    //   20: aload_1
    //   21: invokespecial 459	java/io/LineNumberReader:<init>	(Ljava/io/Reader;)V
    //   24: astore_3
    //   25: new 311	java/util/ArrayList
    //   28: dup
    //   29: invokespecial 312	java/util/ArrayList:<init>	()V
    //   32: astore_2
    //   33: aload_3
    //   34: invokevirtual 462	java/io/LineNumberReader:readLine	()Ljava/lang/String;
    //   37: astore 4
    //   39: aload 4
    //   41: ifnull +79 -> 120
    //   44: aload 4
    //   46: invokestatic 218	com/stericson/RootTools/RootTools:log	(Ljava/lang/String;)V
    //   49: aload 4
    //   51: ldc -34
    //   53: invokevirtual 466	java/lang/String:split	(Ljava/lang/String;)[Ljava/lang/String;
    //   56: astore 4
    //   58: aload_2
    //   59: new 551	com/stericson/RootTools/containers/Symlink
    //   62: dup
    //   63: new 429	java/io/File
    //   66: dup
    //   67: aload 4
    //   69: aload 4
    //   71: arraylength
    //   72: iconst_3
    //   73: isub
    //   74: aaload
    //   75: invokespecial 467	java/io/File:<init>	(Ljava/lang/String;)V
    //   78: new 429	java/io/File
    //   81: dup
    //   82: aload 4
    //   84: aload 4
    //   86: arraylength
    //   87: iconst_1
    //   88: isub
    //   89: aaload
    //   90: invokespecial 467	java/io/File:<init>	(Ljava/lang/String;)V
    //   93: invokespecial 554	com/stericson/RootTools/containers/Symlink:<init>	(Ljava/io/File;Ljava/io/File;)V
    //   96: invokevirtual 472	java/util/ArrayList:add	(Ljava/lang/Object;)Z
    //   99: pop
    //   100: goto -67 -> 33
    //   103: astore 4
    //   105: aload_1
    //   106: astore_2
    //   107: aload 4
    //   109: astore_1
    //   110: aload_2
    //   111: invokevirtual 475	java/io/FileReader:close	()V
    //   114: aload_3
    //   115: invokevirtual 476	java/io/LineNumberReader:close	()V
    //   118: aload_1
    //   119: athrow
    //   120: aload_1
    //   121: invokevirtual 475	java/io/FileReader:close	()V
    //   124: aload_3
    //   125: invokevirtual 476	java/io/LineNumberReader:close	()V
    //   128: aload_2
    //   129: areturn
    //   130: astore_1
    //   131: goto -7 -> 124
    //   134: astore_1
    //   135: aload_2
    //   136: areturn
    //   137: astore_2
    //   138: goto -24 -> 114
    //   141: astore_2
    //   142: goto -24 -> 118
    //   145: astore_1
    //   146: aload 4
    //   148: astore_3
    //   149: goto -39 -> 110
    //   152: astore 5
    //   154: aload_1
    //   155: astore_2
    //   156: aload 4
    //   158: astore_3
    //   159: aload 5
    //   161: astore_1
    //   162: goto -52 -> 110
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	165	0	this	RootToolsInternalMethods
    //   15	106	1	localObject1	Object
    //   130	1	1	localException1	Exception
    //   134	1	1	localException2	Exception
    //   145	10	1	localObject2	Object
    //   161	1	1	localObject3	Object
    //   4	132	2	localObject4	Object
    //   137	1	2	localException3	Exception
    //   141	1	2	localException4	Exception
    //   155	1	2	localObject5	Object
    //   24	135	3	localObject6	Object
    //   1	84	4	localObject7	Object
    //   103	54	4	localObject8	Object
    //   152	8	5	localObject9	Object
    // Exception table:
    //   from	to	target	type
    //   25	33	103	finally
    //   33	39	103	finally
    //   44	100	103	finally
    //   120	124	130	java/lang/Exception
    //   124	128	134	java/lang/Exception
    //   110	114	137	java/lang/Exception
    //   114	118	141	java/lang/Exception
    //   5	16	145	finally
    //   16	25	152	finally
  }
  
  public String getSymlink(String paramString)
  {
    RootTools.log("Looking for Symlink for " + paramString);
    try
    {
      final Object localObject = new ArrayList();
      paramString = new Command(7, false, new String[] { "ls -l " + paramString })
      {
        public void commandOutput(int paramAnonymousInt, String paramAnonymousString)
        {
          if ((paramAnonymousInt == 7) && (!paramAnonymousString.trim().equals(""))) {
            localObject.add(paramAnonymousString);
          }
          super.commandOutput(paramAnonymousInt, paramAnonymousString);
        }
      };
      Shell.startRootShell().add(paramString);
      commandWait(Shell.startRootShell(), paramString);
      paramString = ((String)((List)localObject).get(0)).split(" ");
      if ((paramString.length > 2) && (paramString[(paramString.length - 2)].equals("->")))
      {
        RootTools.log("Symlink found.");
        if ((!paramString[(paramString.length - 1)].equals("")) && (!paramString[(paramString.length - 1)].contains("/")))
        {
          localObject = RootShell.findBinary(paramString[(paramString.length - 1)]);
          if (((List)localObject).size() > 0) {
            return (String)((List)localObject).get(0) + paramString[(paramString.length - 1)];
          }
          return paramString[(paramString.length - 1)];
        }
        paramString = paramString[(paramString.length - 1)];
        return paramString;
      }
    }
    catch (Exception paramString)
    {
      if (RootTools.debugMode) {
        paramString.printStackTrace();
      }
      RootTools.log("Symlink not found");
    }
    return "";
  }
  
  public ArrayList<Symlink> getSymlinks(String paramString)
    throws Exception
  {
    if (!checkUtil("find")) {
      throw new Exception();
    }
    Command localCommand = new Command(0, false, new String[] { "dd if=/dev/zero of=/data/local/symlinks.txt bs=1024 count=1", "chmod 0777 /data/local/symlinks.txt" });
    Shell.startRootShell().add(localCommand);
    commandWait(Shell.startRootShell(), localCommand);
    paramString = new Command(0, false, new String[] { "find " + paramString + " -type l -exec ls -l {} \\; > /data/local/symlinks.txt" });
    Shell.startRootShell().add(paramString);
    commandWait(Shell.startRootShell(), paramString);
    InternalVariables.symlinks = getSymLinks();
    if (InternalVariables.symlinks != null) {
      return InternalVariables.symlinks;
    }
    throw new Exception();
  }
  
  public String getWorkingToolbox()
  {
    if (RootTools.checkUtil("busybox")) {
      return "busybox";
    }
    if (RootTools.checkUtil("toolbox")) {
      return "toolbox";
    }
    return "";
  }
  
  public boolean hasEnoughSpaceOnSdCard(long paramLong)
  {
    RootTools.log("Checking SDcard size and that it is mounted as RW");
    if (!Environment.getExternalStorageState().equals("mounted")) {}
    StatFs localStatFs;
    long l;
    do
    {
      return false;
      localStatFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
      l = localStatFs.getBlockSize();
    } while (paramLong >= localStatFs.getAvailableBlocks() * l);
    return true;
  }
  
  public boolean hasUtil(final String paramString1, final String paramString2)
  {
    InternalVariables.found = false;
    if ((!paramString2.endsWith("toolbox")) && (!paramString2.endsWith("busybox"))) {
      return false;
    }
    try
    {
      if (paramString2.endsWith("toolbox")) {}
      for (String str = paramString2 + " " + paramString1;; str = paramString2 + " --list")
      {
        paramString2 = new Command(0, false, new String[] { str })
        {
          public void commandOutput(int paramAnonymousInt, String paramAnonymousString)
          {
            if (paramString2.endsWith("toolbox")) {
              if (paramAnonymousString.contains("no such tool")) {}
            }
            for (InternalVariables.found = true;; InternalVariables.found = true)
            {
              do
              {
                super.commandOutput(paramAnonymousInt, paramAnonymousString);
                return;
              } while ((!paramString2.endsWith("busybox")) || (!paramAnonymousString.contains(paramString1)));
              RootTools.log("Found util!");
            }
          }
        };
        RootTools.getShell(true).add(paramString2);
        commandWait(RootTools.getShell(true), paramString2);
        if (!InternalVariables.found) {
          break;
        }
        RootTools.log("Box contains " + paramString1 + " util!");
        return true;
      }
      RootTools.log("Box does not contain " + paramString1 + " util!");
      return false;
    }
    catch (Exception paramString1)
    {
      RootTools.log(paramString1.getMessage());
    }
    return false;
  }
  
  public boolean installBinary(Context paramContext, int paramInt, String paramString1, String paramString2)
  {
    try
    {
      paramContext = new Installer(paramContext);
      return paramContext.installBinary(paramInt, paramString1, paramString2);
    }
    catch (IOException paramContext)
    {
      if (RootTools.debugMode) {
        paramContext.printStackTrace();
      }
    }
    return false;
  }
  
  public boolean isAppletAvailable(String paramString1, String paramString2)
  {
    boolean bool2 = false;
    try
    {
      paramString2 = getBusyBoxApplets(paramString2).iterator();
      do
      {
        bool1 = bool2;
        if (!paramString2.hasNext()) {
          break;
        }
        bool1 = ((String)paramString2.next()).equals(paramString1);
      } while (!bool1);
      boolean bool1 = true;
      return bool1;
    }
    catch (Exception paramString1)
    {
      RootTools.log(paramString1.toString());
    }
    return false;
  }
  
  public boolean isBinaryAvailable(Context paramContext, String paramString)
  {
    try
    {
      paramContext = new Installer(paramContext);
      return paramContext.isBinaryInstalled(paramString);
    }
    catch (IOException paramContext)
    {
      if (RootTools.debugMode) {
        paramContext.printStackTrace();
      }
    }
    return false;
  }
  
  public boolean isNativeToolsReady(int paramInt, Context paramContext)
  {
    boolean bool = false;
    RootTools.log("Preparing Native Tools");
    for (InternalVariables.nativeToolsReady = false;; InternalVariables.nativeToolsReady = paramContext.installBinary(paramInt, "nativetools", "700"))
    {
      try
      {
        paramContext = new Installer(paramContext);
        if (!paramContext.isBinaryInstalled("nativetools")) {
          continue;
        }
        InternalVariables.nativeToolsReady = true;
        bool = InternalVariables.nativeToolsReady;
      }
      catch (IOException paramContext)
      {
        while (!RootTools.debugMode) {}
        paramContext.printStackTrace();
        return false;
      }
      return bool;
    }
  }
  
  public boolean isProcessRunning(final String paramString)
  {
    RootTools.log("Checks if process is running: " + paramString);
    InternalVariables.processRunning = false;
    try
    {
      paramString = new Command(0, false, new String[] { "ps" })
      {
        public void commandOutput(int paramAnonymousInt, String paramAnonymousString)
        {
          if (paramAnonymousString.contains(paramString)) {
            InternalVariables.processRunning = true;
          }
          super.commandOutput(paramAnonymousInt, paramAnonymousString);
        }
      };
      RootTools.getShell(true).add(paramString);
      commandWait(RootTools.getShell(true), paramString);
      return InternalVariables.processRunning;
    }
    catch (Exception paramString)
    {
      for (;;)
      {
        RootTools.log(paramString.getMessage());
      }
    }
  }
  
  public boolean killProcess(final String paramString)
  {
    RootTools.log("Killing process " + paramString);
    InternalVariables.pid_list = "";
    InternalVariables.processRunning = true;
    try
    {
      paramString = new Command(0, false, new String[] { "ps" })
      {
        public void commandOutput(int paramAnonymousInt, String paramAnonymousString)
        {
          Object localObject;
          if (paramAnonymousString.contains(paramString)) {
            localObject = InternalVariables.psPattern.matcher(paramAnonymousString);
          }
          try
          {
            if (((Matcher)localObject).find())
            {
              localObject = ((Matcher)localObject).group(1);
              InternalVariables.pid_list = InternalVariables.pid_list + " " + (String)localObject;
              InternalVariables.pid_list = InternalVariables.pid_list.trim();
              RootTools.log("Found pid: " + (String)localObject);
            }
            for (;;)
            {
              super.commandOutput(paramAnonymousInt, paramAnonymousString);
              return;
              RootTools.log("Matching in ps command failed!");
            }
          }
          catch (Exception localException)
          {
            for (;;)
            {
              RootTools.log("Error with regex!");
              localException.printStackTrace();
            }
          }
        }
      };
      RootTools.getShell(true).add(paramString);
      commandWait(RootTools.getShell(true), paramString);
      paramString = InternalVariables.pid_list;
      boolean bool = paramString.equals("");
      if (bool) {
        break label156;
      }
      try
      {
        paramString = new Command(0, false, new String[] { "kill -9 " + paramString });
        RootTools.log(paramString.getMessage());
      }
      catch (Exception paramString)
      {
        try
        {
          RootTools.getShell(true).add(paramString);
          commandWait(RootTools.getShell(true), paramString);
          return true;
        }
        catch (Exception paramString)
        {
          for (;;) {}
        }
        paramString = paramString;
      }
    }
    catch (Exception paramString)
    {
      for (;;)
      {
        RootTools.log(paramString.getMessage());
      }
    }
    return false;
    label156:
    return true;
  }
  
  public Intent offerBusyBox(Activity paramActivity, int paramInt)
  {
    RootTools.log("Launching Market for BusyBox");
    Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=stericson.busybox"));
    paramActivity.startActivityForResult(localIntent, paramInt);
    return localIntent;
  }
  
  public void offerBusyBox(Activity paramActivity)
  {
    RootTools.log("Launching Market for BusyBox");
    paramActivity.startActivity(new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=stericson.busybox")));
  }
  
  public Intent offerSuperUser(Activity paramActivity, int paramInt)
  {
    RootTools.log("Launching Play Store for SuperSU");
    Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=eu.chainfire.supersu"));
    paramActivity.startActivityForResult(localIntent, paramInt);
    return localIntent;
  }
  
  public void offerSuperUser(Activity paramActivity)
  {
    RootTools.log("Launching Play Store for SuperSU");
    paramActivity.startActivity(new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=eu.chainfire.supersu")));
  }
  
  public int parsePermissions(String paramString)
  {
    paramString = paramString.toLowerCase(Locale.US);
    int i;
    if (paramString.charAt(0) == 'r')
    {
      i = 4;
      RootTools.log("permission " + i);
      RootTools.log("character " + paramString.charAt(0));
      if (paramString.charAt(1) != 'w') {
        break label225;
      }
      i += 2;
      label84:
      RootTools.log("permission " + i);
      RootTools.log("character " + paramString.charAt(1));
      if ((paramString.charAt(2) != 'x') && (paramString.charAt(2) != 's') && (paramString.charAt(2) != 't')) {
        break label232;
      }
      i += 1;
    }
    for (;;)
    {
      RootTools.log("permission " + i);
      RootTools.log("character " + paramString.charAt(2));
      return i;
      i = 0;
      break;
      label225:
      i += 0;
      break label84;
      label232:
      i += 0;
    }
  }
  
  public int parseSpecialPermissions(String paramString)
  {
    int j = 0;
    if (paramString.charAt(2) == 's') {
      j = 0 + 4;
    }
    int i = j;
    if (paramString.charAt(5) == 's') {
      i = j + 2;
    }
    j = i;
    if (paramString.charAt(8) == 't') {
      j = i + 1;
    }
    RootTools.log("special permissions " + j);
    return j;
  }
}


/* Location:              /home/enzo/Documents/hacking/malwares/viking-horde/classes.jar!/com/stericson/RootTools/internal/RootToolsInternalMethods.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */