Skip to content

Commit

Permalink
- Multiple improvements to Pointer API to make it more flexible and p…
Browse files Browse the repository at this point in the history
…erformant.

- Simplified and optimized native call context management, inspired by ideas from theflow0.
- All IntelliJ run configurations and Maven unit test runs now use uncompressed oops to better reflect PS5 runtime environment.
- Added more unit tests in SDK.
- Deprecate umtx2. It's not very stable (at least on 1.xx). Not sure if it's due to new native optimizations, but maintaining 2 implementations does not appear necessary anymore.
  • Loading branch information
hammer-83 committed Jan 25, 2025
1 parent 4a03eaf commit 1fadc51
Show file tree
Hide file tree
Showing 33 changed files with 1,203 additions and 231 deletions.
1 change: 1 addition & 0 deletions .idea/runConfigurations/DumpClassPath_JAR.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/runConfigurations/FtpServer_JAR.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Maven_Test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/runConfigurations/PrintSystemProperties_JAR.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/runConfigurations/SDK_Unit_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Even if the remote logger is not active by default in the Xlet burned on disc, i
7. A message on screen should inform about loader waiting for JAR or the menu will be displayed if payloads are found on disc.
8. For remote execution, send the JAR using the command:
```shell
java -jar xploit/target/xploit-[version].jar <ps5 ip address>`
java -jar xploit/[payload]/target/[payload]-[version].jar <ps5 ip address>`
```
PS5 should inform on screen about the status of the upload and the execution.
9. Once remote execution is complete, the loader will wait for a new JAR. Do the necessary modifications in `xploit` project, recompile using `mvn package` and re-execute step 8 to retry as many times as necessary.
Expand Down
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<loader.payload.root>jar-payloads</loader.payload.root>

<!-- Do not use the same version as parent project for Xlet because it will be modified less frequently. We only want to burn new disc if Xlet changes -->
<xlet.version>2.2.0</xlet.version>
<xlet.version>3.0.0</xlet.version>
</properties>

<modules>
Expand Down Expand Up @@ -153,6 +153,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<!-- PS5 does not use compressed OOPs -->
<argLine>-XX:-UseCompressedOops</argLine>
</configuration>
</plugin>

<plugin>
Expand Down
54 changes: 34 additions & 20 deletions sdk/src/main/java/org/ps5jb/sdk/core/AbstractPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Root parent for any class that implements a pointer to a memory.
*/
public abstract class AbstractPointer implements Serializable {
private static final long serialVersionUID = 5085573430112354497L;
private static final long serialVersionUID = 5085573430112354495L;

/**
* Wrap the given pointer in a non-null check. Returns the same pointer if it is not NULL.
Expand All @@ -20,7 +20,7 @@ public abstract class AbstractPointer implements Serializable {
* @return Same <code>pointer</code> value if it is not NULL.
* @throws NullPointerException If the input pointer is NULL or points to the address 0.
*/
public static AbstractPointer nonNull(AbstractPointer pointer, String errorMessage) {
public static <T extends AbstractPointer> T nonNull(T pointer, String errorMessage) {
if (pointer == null || pointer.addr() == 0) {
throw new NullPointerException(errorMessage);
}
Expand Down Expand Up @@ -189,39 +189,39 @@ public long read8() {
/**
* Read the given number of bytes from the address pointed to by this pointer instance.
*
* @param size Number of bytes to read.
* @param count Number of bytes to read.
* @return Value read from the memory as an array of bytes.
*/
public byte[] read(int size) {
byte[] result = new byte[size];
read(0, result, 0, size);
public byte[] read(int count) {
byte[] result = new byte[count];
read(0, result, 0, count);
return result;
}

/**
* Read the given number of bytes at the specified offset from the pointer.
*
* @param offset Offset relative to {@link #addr}.
* @param offset Offset in bytes relative to {@link #addr}.
* @param value Buffer to read the value into.
* @param valueOffset Offset in the buffer where to place the read value.
* @param size Number of bytes to read.
* @param valueIndex Starting index in the buffer where to place the read value.
* @param count Number of bytes to read.
* @throws IndexOutOfBoundsException If the buffer is not large enough to hold the value
* of the specified size.
*/
public void read(long offset, byte[] value, int valueOffset, int size) {
overflow(this, offset, size);
public void read(long offset, byte[] value, int valueIndex, int count) {
overflow(this, offset, count);

long buffer;
int bufferLen;

for (int i = 0; i < size; i += bufferLen) {
if ((i + 8) <= size) {
for (int i = 0; i < count; i += bufferLen) {
if ((i + 8) <= count) {
buffer = read8impl(offset + i);
bufferLen = 8;
} else if ((i + 4) <= size) {
} else if ((i + 4) <= count) {
buffer = read4impl(offset + i);
bufferLen = 4;
} else if ((i + 2) <= size) {
} else if ((i + 2) <= count) {
buffer = read2impl(offset + i);
bufferLen = 2;
} else {
Expand All @@ -230,7 +230,7 @@ public void read(long offset, byte[] value, int valueOffset, int size) {
}

for (int j = 0; j < bufferLen; ++j) {
value[valueOffset + i + j] = (byte) ((buffer >> (j * 8)) & 0xFF);
value[valueIndex + i + j] = (byte) ((buffer >> (j * 8)) & 0xFF);
}
}
}
Expand Down Expand Up @@ -434,13 +434,13 @@ public void write(byte[] value) {
*
* @param offset Offset relative to {@link #addr}.
* @param value Buffer to write.
* @param valueOffset Offset in the buffer from which to start writing.
* @param valueIndex Index in the buffer from which to start writing.
* @param count Number of bytes to write.
* @throws IndexOutOfBoundsException If the buffer or the native memory
* are not large enough for the given values of <code>offset</code>,
* <code>valueOffset</code> and <code>count</code>.
* <code>valueIndex</code> and <code>count</code>.
*/
public void write(long offset, byte[] value, int valueOffset, int count) {
public void write(long offset, byte[] value, int valueIndex, int count) {
overflow(this, offset, count);

long buffer;
Expand All @@ -459,7 +459,7 @@ public void write(long offset, byte[] value, int valueOffset, int count) {

buffer = 0;
for (int j = 0; j < bufferLen; ++j) {
buffer |= (((long) (value[valueOffset + i + j] & 0xFF)) << (j * 8));
buffer |= (((long) (value[valueIndex + i + j] & 0xFF)) << (j * 8));
}

if (bufferLen == 8) {
Expand Down Expand Up @@ -502,6 +502,20 @@ public void writeString(String string) {
writeString(0, string, Charset.defaultCharset().name());
}

/**
* Copies values in native memory associated with this pointer to a pointer specified by <code>dest</code>.
*
* @param dest Memory to copy the data to. The data will always be copied starting at offset 0 in <code>dest</code>.
* @param offset Offset in this memory to read the data from.
* @param size Size of data to copy.
* @throws IndexOutOfBoundsException If the read or the write beyond one of the two pointers' sizes occurs.
*/
public void copyTo(AbstractPointer dest, long offset, int size) {
byte[] data = new byte[size];
read(offset, data, 0, size);
dest.write(0, data, 0, size);
}

/**
* Get the native memory address of this pointer.
*
Expand Down
Loading

0 comments on commit 1fadc51

Please sign in to comment.