package com.stericson.RootTools.internal;

import com.stericson.RootShell.execution.Command;
import com.stericson.RootShell.execution.Shell;
import com.stericson.RootTools.RootTools;
import com.stericson.RootTools.containers.Mount;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;

public class Remounter
{
  private void commandWait(Command paramCommand)
  {
    try
    {
      if (!paramCommand.isFinished()) {
        paramCommand.wait(2000L);
      }
      return;
    }
    catch (InterruptedException localInterruptedException)
    {
      for (;;)
      {
        localInterruptedException.printStackTrace();
      }
    }
    finally {}
  }
  
  private Mount findMountPointRecursive(String paramString)
  {
    try
    {
      ArrayList localArrayList = RootTools.getMounts();
      Mount localMount;
      boolean bool;
      do
      {
        paramString = new File(paramString);
        Iterator localIterator;
        while (!localIterator.hasNext())
        {
          if (paramString == null) {
            break;
          }
          localIterator = localArrayList.iterator();
        }
        localMount = (Mount)localIterator.next();
        bool = localMount.getMountPoint().equals(paramString);
      } while (!bool);
      return localMount;
      return null;
    }
    catch (IOException paramString)
    {
      if (RootTools.debugMode) {
        paramString.printStackTrace();
      }
      return null;
    }
    catch (Exception paramString)
    {
      for (;;)
      {
        if (RootTools.debugMode) {
          paramString.printStackTrace();
        }
      }
    }
  }
  
  public boolean remount(String paramString1, String paramString2)
  {
    String str = paramString1;
    if (paramString1.endsWith("/"))
    {
      str = paramString1;
      if (!paramString1.equals("/")) {
        str = paramString1.substring(0, paramString1.lastIndexOf("/"));
      }
    }
    int i = 0;
    for (;;)
    {
      if (i == 0) {
        try
        {
          paramString1 = RootTools.getMounts().iterator();
          boolean bool;
          do
          {
            j = i;
            if (!paramString1.hasNext()) {
              break;
            }
            localMount = (Mount)paramString1.next();
            RootTools.log(localMount.getMountPoint().toString());
            bool = str.equals(localMount.getMountPoint().toString());
          } while (!bool);
          j = 1;
          i = j;
          if (j != 0) {}
        }
        catch (Exception paramString1)
        {
          try
          {
            int j;
            str = new File(str).getParent();
            i = j;
          }
          catch (Exception paramString1)
          {
            paramString1.printStackTrace();
            return false;
          }
          paramString1 = paramString1;
          if (RootTools.debugMode) {
            paramString1.printStackTrace();
          }
          return false;
        }
      }
    }
    Mount localMount = findMountPointRecursive(str);
    if (localMount != null)
    {
      RootTools.log("RootTools v4.2", "Remounting " + localMount.getMountPoint().getAbsolutePath() + " as " + paramString2.toLowerCase());
      paramString1 = localMount;
      if (localMount.getFlags().contains(paramString2.toLowerCase())) {}
    }
    try
    {
      paramString1 = new Command(0, true, new String[] { "busybox mount -o remount," + paramString2.toLowerCase() + " " + localMount.getDevice().getAbsolutePath() + " " + localMount.getMountPoint().getAbsolutePath(), "toolbox mount -o remount," + paramString2.toLowerCase() + " " + localMount.getDevice().getAbsolutePath() + " " + localMount.getMountPoint().getAbsolutePath(), "mount -o remount," + paramString2.toLowerCase() + " " + localMount.getDevice().getAbsolutePath() + " " + localMount.getMountPoint().getAbsolutePath(), "/system/bin/toolbox mount -o remount," + paramString2.toLowerCase() + " " + localMount.getDevice().getAbsolutePath() + " " + localMount.getMountPoint().getAbsolutePath() });
      Shell.startRootShell().add(paramString1);
      commandWait(paramString1);
      paramString1 = findMountPointRecursive(str);
      if (paramString1 != null)
      {
        RootTools.log("RootTools v4.2", paramString1.getFlags() + " AND " + paramString2.toLowerCase());
        if (paramString1.getFlags().contains(paramString2.toLowerCase()))
        {
          RootTools.log(paramString1.getFlags().toString());
          return true;
        }
        RootTools.log(paramString1.getFlags().toString());
        return false;
      }
      RootTools.log("mount is null, file was: " + str + " mountType was: " + paramString2);
      for (;;)
      {
        return false;
        RootTools.log("mount is null, file was: " + str + " mountType was: " + paramString2);
      }
    }
    catch (Exception paramString1)
    {
      for (;;) {}
    }
  }
}


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