mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-02-22 03:19:04 +01:00
This commit is contained in:
parent
39f6fd7849
commit
d4c808d413
@ -15,8 +15,8 @@ public class Channel {
|
||||
private final OutputStream out;
|
||||
private final int id;
|
||||
protected final Meterpreter meterpreter;
|
||||
private boolean active = false, closed = false, waiting = false;
|
||||
private byte[] toRead;
|
||||
protected boolean active = false, closed = false, waiting = false;
|
||||
protected byte[] toRead;
|
||||
|
||||
/**
|
||||
* Create a new "generic" channel.
|
||||
@ -66,13 +66,13 @@ public class Channel {
|
||||
* @param maxLength The maximum number of bytes to read.
|
||||
* @return The bytes read, or <code>null</code> if the end of the stream has been reached.
|
||||
*/
|
||||
public synchronized byte[] read(int maxLength) {
|
||||
public synchronized byte[] read(int maxLength) throws IOException, InterruptedException {
|
||||
if (closed)
|
||||
return null;
|
||||
if (active)
|
||||
throw new IllegalStateException("Cannot read; currently interacting with this channel");
|
||||
if (!waiting || (toRead != null && toRead.length == 0))
|
||||
return new byte[0];
|
||||
while (!waiting || (toRead != null && toRead.length == 0))
|
||||
wait();
|
||||
if (toRead == null)
|
||||
return null;
|
||||
byte[] result = new byte[Math.min(toRead.length, maxLength)];
|
||||
|
@ -26,6 +26,30 @@ public class ProcessChannel extends Channel {
|
||||
new StderrThread(err).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read at least one byte, and up to maxLength bytes from this stream.
|
||||
*
|
||||
* @param maxLength The maximum number of bytes to read.
|
||||
* @return The bytes read, or <code>null</code> if the end of the stream has been reached.
|
||||
*/
|
||||
public synchronized byte[] read(int maxLength) {
|
||||
if (closed)
|
||||
return null;
|
||||
if (active)
|
||||
throw new IllegalStateException("Cannot read; currently interacting with this channel");
|
||||
if (!waiting || (toRead != null && toRead.length == 0))
|
||||
return new byte[0];
|
||||
if (toRead == null)
|
||||
return null;
|
||||
byte[] result = new byte[Math.min(toRead.length, maxLength)];
|
||||
System.arraycopy(toRead, 0, result, 0, result.length);
|
||||
byte[] rest = new byte[toRead.length - result.length];
|
||||
System.arraycopy(toRead, result.length, rest, 0, rest.length);
|
||||
toRead = rest;
|
||||
notifyAll();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
process.destroy();
|
||||
err.close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user