catchedContentTypes = new ArrayList<>();
catchedContentTypes.add("application/x-shockwave-flash");
catchedContentTypes.add("application/x-javascript");
catchedContentTypes.add("application/javascript");
catchedContentTypes.add("text/javascript");
catchedContentTypes.add("application/json");
catchedContentTypes.add("text/xml");
catchedContentTypes.add("application/xml");
catchedContentTypes.add("application/octet-stream");
if (!Server.startServer(port, replacements, catchedContentTypes, this, this)) {
JOptionPane.showMessageDialog(this, translate("error.start.server").replace("%port%", "" + port), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
started = false;
return;
}
switchButton.setText(translate("proxy.stop"));
portField.setEditable(false);
} else {
Server.stopServer();
switchButton.setText(translate("proxy.start"));
portField.setEditable(true);
}
}
/**
* Mouse clicked event
*
* @param e event
*/
@Override
public void mouseClicked(MouseEvent e) {
if (e.getSource() == replacementsTable) {
if (e.getClickCount() == 2) {
open();
}
}
}
/**
* Mouse pressed event
*
* @param e event
*/
@Override
public void mousePressed(MouseEvent e) {
}
/**
* Mouse released event
*
* @param e event
*/
@Override
public void mouseReleased(MouseEvent e) {
}
/**
* Mouse entered event
*
* @param e event
*/
@Override
public void mouseEntered(MouseEvent e) {
}
/**
* Mouse exited event
*
* @param e event
*/
@Override
public void mouseExited(MouseEvent e) {
}
/**
* Method called when specified contentType is received
*
* @param contentType Content type
* @param url URL of the method
* @param data Data stream
* @return replacement data
*/
@Override
public byte[] catched(String contentType, String url, InputStream data) {
boolean swfOnly = false;
if (contentType.contains(";")) {
contentType = contentType.substring(0, contentType.indexOf(';'));
}
if ((!sniffSWFCheckBox.isSelected()) && (contentType.equals("application/x-shockwave-flash"))) {
return null;
}
if ((!sniffJSCheckBox.isSelected()) && (contentType.equals("application/javascript") || contentType.equals("application/x-javascript") || contentType.equals("text/javascript") || contentType.equals("application/json"))) {
return null;
}
if ((!sniffXMLCheckBox.isSelected()) && (contentType.equals("application/xml") || contentType.equals("text/xml"))) {
return null;
}
if ((!sniffOSCheckBox.isSelected()) && (contentType.equals("application/octet-stream"))) {
return null;
}
byte[] result = null;
boolean cont = false;
for (Replacement r : replacements) {
if (r.matches(url)) {
cont = true;
break;
}
}
if (!cont) {
try {
byte[] hdr = new byte[3];
if (data.read(hdr) != 3) {
throw new IOException();
}
String shdr = new String(hdr);
if (swfOnly && ((!shdr.equals("FWS")) && (!shdr.equals("CWS")) && (!shdr.equals("ZWS")))) {
return null; //NOT SWF
}
String tempFilePath = Main.tempFile(url);
data.reset();
byte[] dataArray = Helper.readStream(data);
try (FileOutputStream fos = new FileOutputStream(new File(tempFilePath))) {
fos.write(dataArray);
}
result = SWFDecompilerPlugin.fireProxyFileCatched(dataArray);
Replacement r = new Replacement(url, tempFilePath);
r.lastAccess = Calendar.getInstance();
replacements.add(r);
saveReplacements();
tableModel.addRow(new Object[]{
r.lastAccess == null ? "" : format.format(r.lastAccess.getTime()),
new SizeItem(r.targetFile),
r.urlPattern
});
} catch (IOException e) {
}
}
return result;
}
/**
* Shows or hides this {@code Window} depending on the value of parameter
* {@code b}.
*
* @param b if {@code true}, makes the {@code Window} visible, otherwise
* hides the {@code Window}. If the {@code Window} and/or its owner are not
* yet displayable, both are made displayable. The {@code Window} will be
* validated prior to being made visible. If the {@code Window} is already
* visible, this will bring the {@code Window} to the front.
* If {@code false}, hides this {@code Window}, its subcomponents, and all
* of its owned children. The {@code Window} and its subcomponents can be
* made visible again with a call to {@code #setVisible(true)}.
* @see java.awt.Component#isDisplayable
* @see java.awt.Component#setVisible
* @see java.awt.Window#toFront
* @see java.awt.Window#dispose
*/
@Override
public void setVisible(boolean b) {
if (b == true) {
Main.addTrayIcon();
}
super.setVisible(b);
}
@Override
public void replaced(Replacement replacement, String url, String contentType) {
int index = replacements.indexOf(replacement);
tableModel.setValueAt(replacement.lastAccess == null ? "" : format.format(replacement.lastAccess.getTime()), index, 0);
tableModel.setValueAt(new SizeItem(replacement.targetFile), index, 1);
tableModel.setValueAt(replacement.urlPattern, index, 2);
}
}