Skip to content

Commit

Permalink
Sdk mappings for UMTX bug. Update readme with the new IntelliJ setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
hammer-83 committed Sep 27, 2024
1 parent bb67f5f commit 4553c6c
Show file tree
Hide file tree
Showing 64 changed files with 2,694 additions and 73 deletions.
15 changes: 0 additions & 15 deletions .idea/compiler.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/misc.xml

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

8 changes: 8 additions & 0 deletions .idea/runConfigurations/Xploit_JAR.xml

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

10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Either modify the POM directly, or pass the new values from command line, exampl
8. Once 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 #7 to retry as many times as necessary.

## Notes
1. To use with IntelliJ, simply point `File -> Open` dialog to the root of the project.
2. If any of POMs are modified, it's necessary to do `Maven -> Reload Project` in IntelliJ to sync the project files. Syncing Maven project unfortunately modifies [.idea/compiler.xml](.idea/compiler.xml) to contain absolute system paths. Simply replace those with `$PROJECT_DIR$` macro again. IntelliJ also modifies classpaths of the modules defined in various `*.iml` files. These modifications should also mostly be reverted.
1. To use with IntelliJ, point `File -> Open` dialog to the root of the project. Maven import will occur. Then follow manual steps in [IntelliJ Project Structure](#intellij-project-structure) to adjust the dependencies so that IntelliJ sees BD-J classes ahead of JDK classes.
2. If any of POMs are modified, it's necessary to do `Maven -> Reload Project` in IntelliJ to sync the project files.
3. To generate Javadocs, use `mvn verify` rather than `mvn package`. The Javadocs are enabled for [sdk](sdk), [xlet](xlet) and [xploit](xploit) modules and are generated in the `target/site/apidocs` directory of each module.
4. The JAR in the `xploit` module accesses some internal JDK classes by reflection. This will result in warnings which can be safely ignored. To mute the warnings, add the following switch after `java` executable when sending the JAR: `--add-opens java.base/jdk.internal.loader=ALL-UNNAMED`.
5. If the `xploit` JAR does not have PS5 specific dependencies, it can be tested locally. The important part is to have `xlet`, `stubs` and `xploit` JARs all in the same folder. If the payload refers to GEM, BD-J or Java TV API, the corresponding JAR files generated in [lib](lib) directory should also be present in the same folder. Maven build automatically creates this arrangement in `xploit/target` directory so the command to run the payload on development machine is very similar to the one that sends the JAR to PS5:
Expand All @@ -59,5 +59,11 @@ Either modify the POM directly, or pass the new values from command line, exampl
* The `xlet` version is independent and will only be incremented when new disc needs to be burned with the updated JAR loader classes. If the PS5 shows a version different from the one produced by the code of this repo, payloads are not guaranteed to be compatible, so it's best to burn a new loader disc. This version is not expected to be incremented often as the loader is pretty stable. To increment this version, change the value of `xlet.version` property in [pom.xml](pom.xml).
* The rest of the modules use the version from the parent POM. This version will be incremented with the new release and reflects that either the SDK or the payloads have changed. If the loader version remained the same, these new versions of payloads can still be sent to the JAR loader without re-burning the disc. This version can be incremented by executing `mvn versions:set -DnewVersion=[version]`, then refreshing the IntelliJ Maven project as described in bullet point number 2.

## IntelliJ Project Structure
IntelliJ Maven project files are located in a private local folder of IntelliJ. Initial opening and the following reloads of the Maven project incorrectly import some of the settings. In particular, BD-J stack JARs are completely ignored or are imported with a wrong scope. Unfortunately, due to this fact, the following steps need to be performed every time a Maven project reload occurs:
* Syncing Maven project modifies [.idea/compiler.xml](.idea/compiler.xml) to contain absolute system paths. Simply replace those with `$PROJECT_DIR$` macro again.
* Go to `Project Structure` window and switch to `Modules` tab. Go through every module and make sure that the modules `bdj-api`, `javatv-api` and `gem-api` have "Provided" scope.
* In addition, for all the modules that have the above-mentioned dependencies, click on `+ (Add) -> Library` button and add `bdjstack` library dependency. Make sure it is moved in the top position above SDK 11 entry. This setting used to be commited to version control and could be simply reverted, but in recent updates, it has to be performed every time.

## Credits
There are so many who decided to share the knowledge with the community to make this project possible. Please see the Credits section in the [Webkit PS5 Exploit repo](https://github.com/Cryptogenic/PS5-IPV6-Kernel-Exploit#contributors--special-thanks). None of this would be possible without all these contributors. Additionally, big thanks to [psxdev](https://github.com/psxdev) and [John Törnblom](https://github.com/john-tornblom) for their work specifically on BD-J. Finally, the FTP payload is based off work from [pReya](https://github.com/pReya/ftpServer).
4 changes: 4 additions & 0 deletions bdj-tools/bdjo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
and what should be launched when.
</description>

<properties>
<bdjstack.dir>${project.basedir}/../../lib</bdjstack.dir>
</properties>

<dependencies>
<dependency>
<groupId>com.hdcookbook</groupId>
Expand Down
4 changes: 4 additions & 0 deletions bdj-tools/grin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
<packaging>jar</packaging>
<description>This is sort of a lightweight SMIL: it provides a simple timeline, and an extensible presentation engine for certain kinds of animations.</description>

<properties>
<bdjstack.dir>${project.basedir}/../../lib</bdjstack.dir>
</properties>

</project>
4 changes: 4 additions & 0 deletions bdj-tools/id/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<packaging>jar</packaging>
<description>ID tool converts an id.bdmv file to an xml format and back. File id.bdmv includes the disc ID and org ID for a given BD image, and required to be present under the CERTIFICATE dir.</description>

<properties>
<bdjstack.dir>${project.basedir}/../../lib</bdjstack.dir>
</properties>

<dependencies>
<dependency>
<groupId>com.hdcookbook</groupId>
Expand Down
4 changes: 4 additions & 0 deletions bdj-tools/index/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<packaging>jar</packaging>
<description>Index tool converts an index.bdmv file to an xml format and back. File index.bdmv is located in the BDMV directory and contains information about the first playback, topmenu and titles on the disc.</description>

<properties>
<bdjstack.dir>${project.basedir}/../../lib</bdjstack.dir>
</properties>

<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
Expand Down
4 changes: 4 additions & 0 deletions bdj-tools/movieobject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<packaging>jar</packaging>
<description>MovieObject tool converts MovieObject.bdmv file to an xml format and back. MovieObject.bdmv is a file located in the same directory as index.bdmv and contains information and code for HDMV titles. See BD spec 3-1 section 10.3.2.2 for the file syntax.</description>

<properties>
<bdjstack.dir>${project.basedir}/../../lib</bdjstack.dir>
</properties>

<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
Expand Down
4 changes: 4 additions & 0 deletions bdj-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<packaging>pom</packaging>
<description>Tools from HD Cookbook that were adapted to work with JDK 11 and embedded into the build process of the project without any additional steps.</description>

<properties>
<bdjstack.dir>${project.basedir}/../lib</bdjstack.dir>
</properties>

<modules>
<module>security</module>
<module>grin</module>
Expand Down
4 changes: 4 additions & 0 deletions bdj-tools/security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
* BDCredentialSigner - This tool is for signing the application along with generating the credentials in the permission request file, for across disc access of the local storage.
</description>

<properties>
<bdjstack.dir>${project.basedir}/../../lib</bdjstack.dir>
</properties>

<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down
37 changes: 12 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<!-- Name of the Xlet class from "xlet" module that will be run by BD-J when the BD-R disk is played -->
<xlet.className>org.ps5jb.loader.LoaderXlet</xlet.className>

<!-- Do not 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>1.1.1</xlet.version>
<!-- 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>1.1.2</xlet.version>

<!-- Various application configuration properties -->
<loader.port>9025</loader.port>
Expand Down Expand Up @@ -81,25 +81,25 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.1-SNAPSHOT</version>
<version>3.13.0</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.3.2</version>
<version>3.4.0</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<version>3.7.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.1</version>
<version>3.8.0</version>
</plugin>

<plugin>
Expand All @@ -114,7 +114,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.2</version>
<configuration>
<archive>
<!-- Do not include META-INF/maven directory in JARs -->
Expand All @@ -130,7 +130,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version>
<version>3.10.0</version>
</plugin>

<plugin>
Expand All @@ -142,7 +142,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<version>3.6.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
Expand All @@ -151,7 +151,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.1</version>
<version>3.5.0</version>
<configuration>
<!-- Do not run tests on a development machine -->
<skipTests>true</skipTests>
Expand All @@ -161,31 +161,18 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<version>3.4.1</version>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.16.1</version>
<version>2.17.1</version>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<!-- Needed until maven-compiler-plugin 3.12.0 is released -->
<pluginRepositories>
<pluginRepository>
<id>apache-snapshots</id>
<name>Apache Snapshots</name>
<url>https://repository.apache.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>
20 changes: 20 additions & 0 deletions sdk/src/main/java/org/ps5jb/sdk/core/Pointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static Pointer fromString(String string) {
* native string is null-terminated.
*
* @param string String to convert to a native null-terminated string.
* @param charset Character set to use to convert from native bytes to a Java string.
* @return Pointer to the allocated buffer.
* @throws OutOfMemoryError if the allocation is refused by the system.
*/
Expand Down Expand Up @@ -212,6 +213,7 @@ public Pointer(long addr) {
* Constructor of a pointer where the size is known.
*
* @param addr Memory address of the pointer.
* @param size Size of the memory.
*/
public Pointer(long addr, Long size) {
this.addr = addr;
Expand Down Expand Up @@ -301,6 +303,7 @@ 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.
* @return Value read from the memory as an array of bytes.
*/
public byte[] read(int size) {
Expand Down Expand Up @@ -507,6 +510,23 @@ 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 Pointer 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(Pointer dest, long offset, int size) {
overflow(this, offset, size);
overflow(dest, 0, size);

byte[] data = new byte[size];
read(offset, data, 0, size);
dest.write(0, data, 0, size);
}

/**
* Free the native memory associated with this pointer.
*/
Expand Down
32 changes: 32 additions & 0 deletions sdk/src/main/java/org/ps5jb/sdk/include/PThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.ps5jb.sdk.include;

import org.ps5jb.sdk.include.sys.ErrNo;
import org.ps5jb.sdk.include.sys.pthreadtypes.PThreadType;
import org.ps5jb.sdk.lib.LibKernel;

/**
* This class represents <code>include/pthread.h</code> from FreeBSD source.
*/
public class PThread {
private final LibKernel libKernel;
private final ErrNo errNo;

/**
* Constructor.
*
* @param libKernel Instance of the 'libkernel' native library wrapper.
*/
public PThread(LibKernel libKernel) {
this.libKernel = libKernel;
this.errNo = new ErrNo(this.libKernel);
}

/**
* Get thread ID of the calling thread.
*
* @return Thread ID of the calling thread.
*/
public PThreadType self() {
return new PThreadType(libKernel.pthread_self());
}
}
46 changes: 46 additions & 0 deletions sdk/src/main/java/org/ps5jb/sdk/include/PThreadNp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.ps5jb.sdk.include;

import org.ps5jb.sdk.core.SdkException;
import org.ps5jb.sdk.core.SdkRuntimeException;
import org.ps5jb.sdk.include.sys.ErrNo;
import org.ps5jb.sdk.include.sys.errno.NotFoundException;
import org.ps5jb.sdk.include.sys.pthreadtypes.PThreadType;
import org.ps5jb.sdk.lib.LibKernel;

/**
* This class represents <code>include/pthread_np.h</code> from FreeBSD source.
*/
public class PThreadNp {
private final LibKernel libKernel;
private final ErrNo errNo;

/**
* Constructor.
*
* @param libKernel Instance of the 'libkernel' native library wrapper.
*/
public PThreadNp(LibKernel libKernel) {
this.libKernel = libKernel;
this.errNo = new ErrNo(this.libKernel);
}

/**
* Sets internal name for thread specified by tid argument
* to string value specified by name argument.
*
* @param tid Thread to rename.
* @param name New thread name.
* @throws NotFoundException Thread with given tid not found.
*/
public void rename(PThreadType tid, String name) throws NotFoundException {
int ret = libKernel.pthread_rename_np(tid.getPthread(), name);
if (ret != 0) {
SdkException ex = errNo.getLastException(getClass(), "pthread_rename_np");
if (ex instanceof NotFoundException) {
throw (NotFoundException) ex;
} else {
throw new SdkRuntimeException(ex.getMessage(), ex);
}
}
}
}
Loading

0 comments on commit 4553c6c

Please sign in to comment.