-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
267 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package de.qtc.rmg.exceptions; | ||
|
||
/** | ||
* @author Tobias Neitzel (@qtc_de) | ||
*/ | ||
public class InvalidGadgetException extends Exception | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public InvalidGadgetException() {} | ||
|
||
public InvalidGadgetException(String message) | ||
{ | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package de.qtc.rmg.io; | ||
|
||
import java.io.IOException; | ||
import java.io.ObjectOutput; | ||
import java.io.ObjectOutputStream; | ||
|
||
public class GadgetOutputStream implements ObjectOutput | ||
{ | ||
private final ObjectOutput out; | ||
|
||
public GadgetOutputStream(ObjectOutput out) | ||
{ | ||
this.out = out; | ||
} | ||
|
||
@Override | ||
public void writeBoolean(boolean v) throws IOException { | ||
out.writeBoolean(v); | ||
} | ||
|
||
@Override | ||
public void writeByte(int v) throws IOException { | ||
out.writeByte(v); | ||
} | ||
|
||
@Override | ||
public void writeShort(int v) throws IOException { | ||
out.writeShort(v); | ||
} | ||
|
||
@Override | ||
public void writeChar(int v) throws IOException { | ||
out.writeChar(v); | ||
} | ||
|
||
@Override | ||
public void writeInt(int v) throws IOException { | ||
out.writeInt(v); | ||
} | ||
|
||
@Override | ||
public void writeLong(long v) throws IOException { | ||
out.writeLong(v); | ||
} | ||
|
||
@Override | ||
public void writeFloat(float v) throws IOException { | ||
out.writeFloat(v); | ||
} | ||
|
||
@Override | ||
public void writeDouble(double v) throws IOException { | ||
out.writeDouble(v); | ||
} | ||
|
||
@Override | ||
public void writeBytes(String s) throws IOException { | ||
out.writeBytes(s); | ||
} | ||
|
||
@Override | ||
public void writeChars(String s) throws IOException { | ||
out.writeChars(s); | ||
} | ||
|
||
@Override | ||
public void writeUTF(String s) throws IOException { | ||
out.writeUTF(s); | ||
} | ||
|
||
@Override | ||
public void writeObject(Object obj) throws IOException { | ||
if (obj instanceof GadgetWrapper) | ||
{ | ||
RawObjectOutputStream rout = new RawObjectOutputStream(out); | ||
rout.writeRawObject(((GadgetWrapper)obj).getGadget()); | ||
} | ||
|
||
else | ||
{ | ||
out.writeObject(obj); | ||
} | ||
} | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
out.write(b); | ||
} | ||
|
||
@Override | ||
public void write(byte[] b) throws IOException { | ||
out.write(b); | ||
} | ||
|
||
@Override | ||
public void write(byte[] b, int off, int len) throws IOException { | ||
out.write(b, off, len); | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
out.flush(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
out.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package de.qtc.rmg.io; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.Base64; | ||
|
||
import de.qtc.rmg.exceptions.InvalidGadgetException; | ||
import de.qtc.rmg.utils.RMGUtils; | ||
|
||
public class GadgetWrapper | ||
{ | ||
private final byte[] gadget; | ||
|
||
public GadgetWrapper(String gadget) throws InvalidGadgetException | ||
{ | ||
this.gadget = truncate(Base64.getDecoder().decode(gadget.getBytes())); | ||
} | ||
|
||
public GadgetWrapper(byte[] gadget) throws InvalidGadgetException | ||
{ | ||
this.gadget = truncate(gadget); | ||
} | ||
|
||
public byte[] getGadget() | ||
{ | ||
return gadget; | ||
} | ||
|
||
private byte[] truncate(byte[] fullGadget) throws InvalidGadgetException | ||
{ | ||
if (!ByteBuffer.wrap(fullGadget, 0, 4).equals(ByteBuffer.wrap(RMGUtils.hexToBytes("aced0005")))) | ||
{ | ||
throw new InvalidGadgetException(); | ||
} | ||
|
||
byte[] truncated = new byte[fullGadget.length - 4]; | ||
System.arraycopy(fullGadget, 4, truncated, 0, truncated.length); | ||
|
||
return truncated; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.