CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/msfJavaToolkit/javaCompile/SignJar.java
Views: 11780
1
// Based on the example from http://www.java2s.com/Code/Java/JDK-6/CompilingfromMemory.htm
2
3
package javaCompile;
4
5
import java.io.PrintStream;
6
import java.io.FilterOutputStream;
7
import java.io.ByteArrayOutputStream;
8
import java.io.OutputStream;
9
import java.io.IOException;
10
import sun.security.tools.KeyTool;
11
import sun.security.tools.JarSigner;
12
13
public class SignJar {
14
15
static PrintStream filteredstream =
16
new PrintStream(
17
new FilteredStream(
18
new ByteArrayOutputStream()));
19
20
public static void KeyToolMSF( String[] args ) {
21
try {
22
RedirectStd();
23
KeyTool.main( args );
24
} catch( Exception ex ) { ex.printStackTrace(); }
25
}
26
27
public static void JarSignerMSF( String[] args ) {
28
try {
29
RedirectStd();
30
JarSigner.main( args );
31
} catch( Exception ex ) { ex.printStackTrace(); }
32
}
33
34
private static void RedirectStd() {
35
try {
36
System.setOut( filteredstream );
37
System.setErr( filteredstream );
38
} catch( Exception ex ) { ex.printStackTrace(); }
39
}
40
41
static class FilteredStream extends FilterOutputStream {
42
public FilteredStream( OutputStream aStream ) { super ( aStream ); }
43
44
public void write( byte b[] ) throws IOException {
45
String aString = new String( b );
46
// Do stuff with the output.
47
}
48
49
public void write( byte b[], int off, int len) throws IOException {
50
String aString = new String( b, off, len );
51
// Do stuff with the output.
52
}
53
}
54
}
55
56