Advertisement
Guest User

Gh0sT - Cleaned PowerBot AccountManager.java

a guest
Jan 20th, 2011
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 6.94 KB | None | 0 0
  1. // java; class file size 12731 bytes
  2. // this won't compile lol (just showing how much of the file is just GUI)
  3.  
  4. package org.rsbot.gui;
  5.  
  6. import java.io.File;
  7. import java.io.FileReader;
  8. import java.io.BufferedReader;
  9. import java.io.IOException;
  10. import java.net.InetAddress;
  11. import java.net.NetworkInterface;
  12.  
  13.   static private java.util.Map accounts;
  14.   static private String key;
  15.  
  16.   static private String cipher(String s1, boolean b2) {
  17.     byte[] b3;
  18.     NoSuchAlgorithmException n4;
  19.     UnsupportedEncodingException u1;
  20.     String s1;
  21.     byte[] b7;
  22.     int i8;
  23.     String[] s3;
  24.     int i10;
  25.     if (s1 == null) {
  26.       return null;
  27.     }
  28.     try {
  29.       b3 = SHA1(key);
  30.     }
  31.     catch (n4) {
  32.       n4.printStackTrace();
  33.       return s1;
  34.     }
  35.     catch (u1) {
  36.       u1.printStackTrace();
  37.       return s1;
  38.     }
  39.     if (b2) {
  40.       s1 = "";
  41.       b7 = s1.getBytes();
  42.       i8 = 0;
  43.       while (i8 < b3.length) {
  44.         if (i8 < s1.length()) {
  45.           s1 = new StringBuilder().append(s1).append(b3[i8] + b7[i8]).append("a").toString();
  46.         }
  47.         else {
  48.           s1 = new StringBuilder().append(s1).append(b3[i8]).append("a").toString();
  49.         }
  50.         i8++;
  51.       }
  52.       return s1.substring(0, s1.length() - "a".length());
  53.     }
  54.     s3 = s1.split("a");
  55.     b7 = new byte[s3.length];
  56.     i8 = 0;
  57.     for (;;) {
  58.       {
  59.         if (i8 < b3.length) {
  60.           i10 = Integer.parseInt(s3[i8]);
  61.           if (b3[i8] == i10) {
  62.           }
  63.         }
  64.         break;
  65.       }
  66.       b7[i8] = (byte)(i10 - b3[i8]);
  67.       i8++;
  68.     }
  69.     return new String(b7, 0, i8);
  70.   }
  71.  
  72.   static private String fixName(String s1) {
  73.     if (s1.charAt(0) > 91) {
  74.       s1 = new StringBuilder().append((char) (s1.charAt(0) - 32)).append(s1.substring(1)).toString();
  75.     }
  76.     if (s1.contains("@") == false) {
  77.       s1 = s1.replaceAll("\s", "_");
  78.     }
  79.     return s1;
  80.   }
  81.  
  82.   static public String[] getAccountNames() {
  83.     return (String[]) accounts.keySet().toArray(new String[accounts.size()]);
  84.   }
  85.  
  86.   static public AccountManager getInstance() {
  87.     return new AccountManager();
  88.   }
  89.  
  90.   static public String getPassword(String s1) {
  91.     Map m2;
  92.     String s3;
  93.     m2 = (java.util.Map) accounts.get(s1);
  94.     s3 = (String) m2.get("password");
  95.     if (s3 == null) {
  96.       return "";
  97.     }
  98.     return s3;
  99.   }
  100.  
  101.   static public String getPin(String s1) {
  102.     Map m2;
  103.     String s3;
  104.     m2 = (java.util.Map) accounts.get(s1);
  105.     s3 = (String) m2.get("pin");
  106.     if (s3 == null) {
  107.       s3 = "-1";
  108.     }
  109.     return s3;
  110.   }
  111.  
  112.   static public String getReward(String s1) {
  113.     Map m2;
  114.     String s3;
  115.     m2 = (java.util.Map) accounts.get(s1);
  116.     s3 = (String) m2.get("reward");
  117.     if (s3 == null) {
  118.       return "Cash";
  119.     }
  120.     return s3;
  121.   }
  122.  
  123.   static public boolean isMember(String s1) {
  124.     Map m2;
  125.     String s3;
  126.     m2 = (java.util.Map) accounts.get(s1);
  127.     s3 = (String) m2.get("member");
  128.     return (s3 != null) && (s3.equalsIgnoreCase("true"));
  129.   }
  130.  
  131.   static public boolean isTakingBreaks(String s1) {
  132.     Map m2;
  133.     String s3;
  134.     m2 = (java.util.Map) accounts.get(s1);
  135.     s3 = (String) m2.get("take_breaks");
  136.     return (s3 != null) && (s3.equalsIgnoreCase("true"));
  137.   }
  138.  
  139.   static private boolean isValidKey(String s1) {
  140.     String[] s2;
  141.     int i4;
  142.     String s5;
  143.     s2 = VALID_KEYS;
  144.     l3 = s2.length;
  145.     i4 = 0;
  146.     while (i4 < l3) {
  147.       s5 = s2[i4];
  148.       if (s1.equalsIgnoreCase(s5)) {
  149.         return true;
  150.       }
  151.       i4++;
  152.     }
  153.     return false;
  154.   }
  155.  
  156.   static private boolean isValidPin(String s1) {
  157.     int i2;
  158.     char c3;
  159.     if (s1.length() == 4) {
  160.       i2 = 0;
  161.       while (i2 < s1.length()) {
  162.         c3 = s1.charAt(i2);
  163.         if ((c3 < 48) || (c3 > 57)) {
  164.           return false;
  165.         }
  166.         i2++;
  167.       }
  168.       return true;
  169.     }
  170.     return false;
  171.   }
  172.  
  173.   static private java.util.Map loadAccounts() {
  174.     TreeMap t1;
  175.     java.util.TreeMap o2;
  176.     File f3;
  177.     BufferedReader b4;
  178.     String s5;
  179.     String s6;
  180.     String[] s7;
  181.     String s8;
  182.     Exception e5;
  183.     t1 = new java.util.TreeMap();
  184.     o2 = null;
  185.     f3 = new java.io.File(FILE_NAME);
  186.     if (f3.exists()) {
  187.       try {
  188.         b4 = new java.io.BufferedReader(new java.io.FileReader(f3));
  189.         s5 = "";
  190.         while ((s6 = b4.readLine()) != null) {
  191.           if ((s6.startsWith("[")) && (s6.endsWith("]"))) {
  192.             if (s5.isEmpty() == false) {
  193.               t1.put(fixName(s5), o2);
  194.             }
  195.             s5 = s6.trim().substring(1).substring(0, s6.length() - 2);
  196.             o2 = new java.util.TreeMap();
  197.             continue;
  198.           }
  199.           if ((o2 != null) && (s6.matches("^\w+=.+$"))) {
  200.             if (s5.isEmpty()) {
  201.               continue;
  202.             }
  203.             s7 = s6.trim().split("=");
  204.             if (isValidKey(s7[0])) {
  205.               s8 = s7[1];
  206.               if ((s7[0].equals("pin")) && (isValidPin(s8) == false)) {
  207.                 log.warning(new StringBuilder().append("Invalid pin '").append(s8).append("' on account: ").append(s5).append(" (ignored)").toString());
  208.                 s8 = null;
  209.               }
  210.               if (s7[0].equals("password")) {
  211.                 s8 = cipher(s8, 0);
  212.               }
  213.               o2.put(s7[0], s8);
  214.             }
  215.           }
  216.         }
  217.         if (s5.isEmpty() == false) {
  218.           t1.put(fixName(s5), o2);
  219.         }
  220.         b4.close();
  221.       }
  222.       catch (e5) {
  223.         e5.printStackTrace();
  224.       }
  225.     }
  226.     return t1;
  227.   }
  228.  
  229.   static private byte[] SHA1(String s1) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException {
  230.     MessageDigest m2;
  231.     m2 = java.security.MessageDigest.getInstance("SHA-1");
  232.     m2.update(s1.getBytes("iso-8859-1"), 0, s1.length());
  233.     return m2.digest();
  234.   }
  235.  
  236.   static String[] access$000() {
  237.     return RANDOM_REWARDS;
  238.   }
  239.  
  240.   static javax.swing.JTable access$100(AccountManager a1) {
  241.     return a1.table;
  242.   }
  243.  
  244.   static javax.swing.JButton access$200(AccountManager a1) {
  245.     return a1.removeButton;
  246.   }
  247.  
  248.   static java.util.Map access$300() {
  249.     return accounts;
  250.   }
  251.  
  252.   static String[] access$400() {
  253.     return VALID_KEYS;
  254.   }
  255.  
  256.   static  {
  257.     InetAddress i1;
  258.     NetworkInterface n2;
  259.     Exception e2;
  260.     FILE_NAME = org.rsbot.util.GlobalConfiguration$Paths.getAccountsFile();
  261.     RANDOM_REWARDS = {"Cash","Runes","Coal","Essence","Ore","Bars","Gems","Herbs","Seeds","Charms","Surprise","Emote","Costume","Attack","Defence","Strength","Constitution","Range","Prayer","Magic","Cooking","Woodcutting","Fletching","Fishing","Firemaking","Crafting","Smithing","Mining","Herblore","Agility","Thieving","Slayer","Farming","Runecrafting","Hunter","Construction","Summoning","Dungeoneering"};
  262.     VALID_KEYS = {"password","pin","reward","member","take_breaks"};
  263.     log = java.util.logging.Logger.getLogger(getName());
  264.     try {
  265.       i1 = java.net.InetAddress.getLocalHost();
  266.       n2 = java.net.NetworkInterface.getByInetAddress(i1);
  267.       key = new String(n2.getHardwareAddress());
  268.     }
  269.     catch (e2) {
  270.       key = new StringBuilder().append(System.getProperty("user.name")).append(System.getProperty("user.language")).toString();
  271.     }
  272.     accounts = loadAccounts();
  273.   }
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement