Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.AWTException;
- import java.awt.Robot;
- import java.awt.event.KeyEvent;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.Formatter;
- import java.util.HashMap;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Methods{
- static boolean execfound = false;
- static void print(String obj)
- {
- System.out.println(obj);
- }
- static void print(int obj)
- {
- System.out.println(obj+"");
- }
- static void print(boolean obj)
- {
- System.out.println(obj?"true":"false");
- }
- static void print(char c)
- {
- System.out.println(c);
- }
- static Matcher match(String matchwith,String pattern)
- {
- Pattern p = Pattern.compile(pattern);
- Matcher m = p.matcher(matchwith);
- return m;
- }
- static void KeyPress(Robot bot,String key)
- {
- HashMap<String,Integer> TypeMap = new HashMap<String,Integer>();
- TypeMap.put("space",KeyEvent.VK_SPACE);
- try
- {
- Thread.sleep(1000);
- }
- catch (InterruptedException e)
- {
- }
- if(TypeMap.get(key) != null)
- {
- bot.keyPress(TypeMap.get(key));
- print(bot.getPixelColor(50, 50).getRed());
- }
- return;
- }
- static void OpenFound(String target,File child)
- {
- if(child.listFiles()!=null)
- {
- File[] files = child.listFiles();
- for(int i = 0;i<files.length;i++)
- {
- if(files[i].getName().toLowerCase().contains(target+".exe"))
- {
- print(files[i].getName());
- try
- {
- Runtime.getRuntime().exec(files[i].getAbsolutePath(),null,child);
- return;
- }
- catch (IOException e)
- {
- print("Could not run executive");
- }
- }
- if (execfound==false&&files[i].isDirectory()&&files[i].listFiles()!=null)
- {
- OpenFound(target,files[i]);
- execfound=true;
- }
- }
- }
- }
- static void SearchInDirectory(String target,File directorypath)
- {
- File[] children = directorypath.listFiles();
- if(children==null)
- {
- return;
- }
- int length = children.length;
- for(int i = 0;i<length;i++)
- {
- File child = children[i];
- String childname = child.getName();
- if(child.exists())
- {
- if(childname.toLowerCase().contains(target)&&!(childname.contains("instal")||childname.contains("util")||childname.contains("cmd")))
- {
- String found = child.getAbsolutePath();
- OpenFound(target,child);
- }
- if(child.isDirectory()&&child.listFiles()!=null)
- {
- SearchInDirectory(target,child);
- }
- }
- else
- {
- print("File does not exist somehow");
- }
- }
- }
- static void SearchForDirectory(String root,String target)
- {
- execfound = false;
- String currentpath = root;
- //for contents of directory,
- // if directory and not name then recurse
- File c = new File(currentpath);
- if(c.exists())
- {
- print("Searching...");
- SearchInDirectory(target.toLowerCase(),c);
- print("\nSearch complete");
- }
- else
- {
- print("Drive does not exist, the apocalypse has come!");
- }
- //SearchInDirectory(currentpath);
- }
- static void WriteToFile(File file,String text)
- {
- String path = file.getAbsolutePath();
- Formatter formatter = null;
- try {
- formatter = new Formatter(path);
- }
- catch (FileNotFoundException e)
- {
- e.printStackTrace();
- }
- if(formatter!=null)
- {
- print("Writing");
- formatter.format("%s",text);
- formatter.close();
- }
- return;
- }
- static String ReadFile(File file)
- {
- String FileText = "";
- Scanner FileScanner = null;
- try
- {
- FileScanner = new Scanner(file);
- }
- catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- while(FileScanner.hasNext())
- {
- FileText = FileText + FileScanner.nextLine();
- }
- return FileText;
- }
- static int OccupiedLength(String[] array)
- {
- int x = 0;
- for(int i = 0;i<array.length;i++)
- {
- if (array[i]!=null)
- {
- x++;
- }
- }
- return x;
- }
- static String[] GetStringsBetween(String initialstring,char start,char end)
- {
- String[] Sets = new String[100];
- int newstart = 0;
- int SetsFound = 0;
- int newend = 0;
- for(int i = 0;i<initialstring.length();i++)
- {
- char character = initialstring.charAt(i);
- if(character==start)
- {
- newstart = i+1;
- }
- if(character == end)
- {
- newend = i;
- Sets[SetsFound] = initialstring.substring(newstart, newend);
- SetsFound++;
- }
- }
- return Sets;
- }
- static String[] SubjectData(String[] subjectbase,String name)
- {
- for(int i = 0;i<OccupiedLength(subjectbase);i++)
- {
- String subjectdata = subjectbase[i];
- String[] subjectnames = GetStringsBetween(GetStringsBetween(subjectdata,'(',')')[0],'<','>');
- for(int x = 0;x<OccupiedLength(subjectnames);x++)
- {
- String subjectname = subjectnames[x];
- if(subjectname.toLowerCase().equals(name.toLowerCase()))
- {
- return GetStringsBetween(subjectdata,'<','>');
- }
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement