Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.67 KB | None | 0 0
  1. import java.awt.AWTException;
  2. import java.awt.Robot;
  3. import java.awt.event.KeyEvent;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.IOException;
  7. import java.util.Formatter;
  8. import java.util.HashMap;
  9. import java.util.Scanner;
  10. import java.util.regex.Matcher;
  11. import java.util.regex.Pattern;
  12.  
  13. public class Methods{
  14.        
  15.    
  16.          static boolean execfound = false;
  17.        
  18.          static void print(String obj)
  19.          {
  20.           System.out.println(obj);
  21.          }
  22.          static void print(int obj)
  23.          {
  24.           System.out.println(obj+"");
  25.          }
  26.          static void print(boolean obj)
  27.          {
  28.           System.out.println(obj?"true":"false");
  29.          }
  30.          static void print(char c)
  31.          {
  32.           System.out.println(c);
  33.          }
  34.          
  35.          static Matcher match(String matchwith,String pattern)
  36.          {
  37.            Pattern p = Pattern.compile(pattern);
  38.            Matcher m = p.matcher(matchwith);
  39.            return m;
  40.          }
  41.          static void KeyPress(Robot bot,String key)
  42.          {
  43.           HashMap<String,Integer> TypeMap = new HashMap<String,Integer>();
  44.           TypeMap.put("space",KeyEvent.VK_SPACE);
  45.  
  46.          
  47.           try
  48.           {
  49.             Thread.sleep(1000);
  50.           }
  51.           catch (InterruptedException e)
  52.           {
  53.    
  54.           }
  55.          
  56.          
  57.          
  58.           if(TypeMap.get(key) != null)
  59.           {
  60.             bot.keyPress(TypeMap.get(key));
  61.             print(bot.getPixelColor(50, 50).getRed());
  62.           }
  63.           return;
  64.          }
  65.          static void OpenFound(String target,File child)
  66.          {
  67.           if(child.listFiles()!=null)
  68.           {
  69.        
  70.            File[] files = child.listFiles();
  71.            
  72.            for(int i = 0;i<files.length;i++)
  73.            {
  74.             if(files[i].getName().toLowerCase().contains(target+".exe"))
  75.             {
  76.              print(files[i].getName());
  77.  
  78.              try
  79.              {
  80.                 Runtime.getRuntime().exec(files[i].getAbsolutePath(),null,child);
  81.                 return;
  82.              }
  83.              catch (IOException e)
  84.              {
  85.                  print("Could not run executive");
  86.              }
  87.             }
  88.             if (execfound==false&&files[i].isDirectory()&&files[i].listFiles()!=null)
  89.             {
  90.              OpenFound(target,files[i]);
  91.              execfound=true;
  92.             }
  93.            }
  94.           }
  95.          }
  96.          static void SearchInDirectory(String target,File directorypath)
  97.          {
  98.          
  99.           File[] children = directorypath.listFiles();
  100.           if(children==null)
  101.           {
  102.             return;
  103.           }
  104.           int length = children.length;
  105.           for(int i = 0;i<length;i++)
  106.           {
  107.        
  108.             File child = children[i];
  109.             String childname = child.getName();
  110.             if(child.exists())
  111.             {
  112.            
  113.              if(childname.toLowerCase().contains(target)&&!(childname.contains("instal")||childname.contains("util")||childname.contains("cmd")))
  114.              {
  115.               String found = child.getAbsolutePath();  
  116.               OpenFound(target,child);
  117.              
  118.              }
  119.              
  120.              if(child.isDirectory()&&child.listFiles()!=null)
  121.              {
  122.              
  123.                 SearchInDirectory(target,child);
  124.              
  125.              }
  126.             }
  127.             else
  128.             {
  129.              print("File does not exist somehow");
  130.             }
  131.           }
  132.          }
  133.          static void SearchForDirectory(String root,String target)
  134.          {
  135.           execfound = false;
  136.           String currentpath = root;
  137.           //for contents of directory,
  138.           // if directory and not name then recurse
  139.          
  140.           File c = new File(currentpath);
  141.           if(c.exists())
  142.           {
  143.            print("Searching...");
  144.            SearchInDirectory(target.toLowerCase(),c);
  145.            
  146.            print("\nSearch complete");
  147.           }
  148.           else
  149.           {
  150.             print("Drive does not exist, the apocalypse has come!");
  151.           }
  152.           //SearchInDirectory(currentpath);
  153.          }
  154.          static void WriteToFile(File file,String text)
  155.          {
  156.           String path = file.getAbsolutePath();
  157.           Formatter formatter = null;
  158.           try {
  159.             formatter = new Formatter(path);
  160.           }
  161.           catch (FileNotFoundException e)
  162.           {
  163.             e.printStackTrace();
  164.           }
  165.           if(formatter!=null)
  166.           {
  167.            print("Writing");
  168.            formatter.format("%s",text);
  169.            formatter.close();
  170.           }
  171.           return;
  172.          }
  173.          static String ReadFile(File file)
  174.          {
  175.           String FileText = "";
  176.           Scanner FileScanner = null;
  177.            try
  178.             {
  179.              FileScanner = new Scanner(file);
  180.             }
  181.            catch (FileNotFoundException e) {
  182.              e.printStackTrace();
  183.             }  
  184.            while(FileScanner.hasNext())
  185.             {
  186.              FileText = FileText + FileScanner.nextLine();
  187.             }  
  188.            return FileText;    
  189.          }
  190.          static int OccupiedLength(String[] array)
  191.          {
  192.           int x = 0;
  193.           for(int i = 0;i<array.length;i++)
  194.           {
  195.            if (array[i]!=null)
  196.            {
  197.             x++;
  198.            }
  199.           }
  200.           return x;
  201.          }
  202.          static String[] GetStringsBetween(String initialstring,char start,char end)
  203.          {
  204.           String[] Sets = new String[100];
  205.           int newstart = 0;
  206.           int SetsFound = 0;
  207.           int newend = 0;
  208.  
  209.           for(int i = 0;i<initialstring.length();i++)
  210.           {
  211.            char character = initialstring.charAt(i);
  212.            if(character==start)
  213.            {
  214.             newstart = i+1;
  215.            }
  216.            if(character == end)
  217.            {
  218.             newend = i;
  219.             Sets[SetsFound] = initialstring.substring(newstart, newend);
  220.             SetsFound++;
  221.            }
  222.           }
  223.           return Sets;
  224.          }
  225.          static String[] SubjectData(String[] subjectbase,String name)
  226.          {
  227.          
  228.          
  229.           for(int i = 0;i<OccupiedLength(subjectbase);i++)
  230.           {
  231.             String subjectdata = subjectbase[i];
  232.          
  233.             String[] subjectnames = GetStringsBetween(GetStringsBetween(subjectdata,'(',')')[0],'<','>');
  234.             for(int x = 0;x<OccupiedLength(subjectnames);x++)
  235.             {
  236.                String subjectname = subjectnames[x];
  237.                if(subjectname.toLowerCase().equals(name.toLowerCase()))
  238.             {
  239.                return GetStringsBetween(subjectdata,'<','>');
  240.             }
  241.            }
  242.           }
  243.           return null;
  244.          }
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement