Skip to content

Commit

Permalink
v0.4:
Browse files Browse the repository at this point in the history
GoldLeaf v0.5 support added
Pay attention! All previous GoldLeaf versions are incompatible with this application
  • Loading branch information
developersu committed Mar 27, 2019
1 parent 4b2402f commit 20e4197
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 46 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -8,7 +8,7 @@
<name>NS-USBloader</name>

<artifactId>ns-usbloader</artifactId>
<version>0.3.2-SNAPSHOT</version>
<version>0.4-SNAPSHOT</version>

<url>https://github.com/developersu/ns-usbloader/</url>
<description>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/nsusbloader/Controllers/NSLMainController.java
Expand Up @@ -91,6 +91,7 @@ public void initialize(URL url, ResourceBundle rb) {
tableFilesListController.setNewProtocol(choiceProtocol.getSelectionModel().getSelectedItem());
if (choiceProtocol.getSelectionModel().getSelectedItem().equals("GoldLeaf")) {
choiceNetUsb.setDisable(true);
choiceNetUsb.getSelectionModel().select("USB");
nsIpLbl.setVisible(false);
nsIpTextField.setVisible(false);
}
Expand All @@ -109,6 +110,7 @@ public void initialize(URL url, ResourceBundle rb) {
choiceNetUsb.getSelectionModel().select(AppPreferences.getInstance().getNetUsb());
if (choiceProtocol.getSelectionModel().getSelectedItem().equals("GoldLeaf")) {
choiceNetUsb.setDisable(true);
choiceNetUsb.getSelectionModel().select("USB");
}
choiceNetUsb.setOnAction(e->{
if (choiceNetUsb.getSelectionModel().getSelectedItem().equals("NET")){
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/nsusbloader/NSLMain.java
Expand Up @@ -12,7 +12,7 @@
import java.util.ResourceBundle;

public class NSLMain extends Application {
public static final String appVersion = "v0.3.2";
public static final String appVersion = "v0.4";
@Override
public void start(Stage primaryStage) throws Exception{

Expand Down
111 changes: 67 additions & 44 deletions src/main/java/nsusbloader/USB/UsbCommunications.java
Expand Up @@ -4,6 +4,7 @@
import nsusbloader.ModelControllers.LogPrinter;
import nsusbloader.NSLDataTypes.EFileStatus;
import nsusbloader.NSLDataTypes.EMsgType;
import nsusbloader.RainbowHexDump;
import nsusbloader.USB.PFS.PFSProvider;
import org.usb4java.*;

Expand Down Expand Up @@ -456,15 +457,16 @@ private boolean sendResponse(byte[] rangeSize){
* */
private class GoldLeaf{
// CMD G L U C ID 0 0 0
private final byte[] CMD_ConnectionRequest = new byte[]{0x47, 0x4c, 0x55, 0x43, 0x00, 0x00, 0x00, 0x00}; // Write-only command
private final byte[] CMD_NSPName = new byte[]{0x47, 0x4c, 0x55, 0x43, 0x02, 0x00, 0x00, 0x00}; // Write-only command
private final byte[] CMD_NSPData = new byte[]{0x47, 0x4c, 0x55, 0x43, 0x04, 0x00, 0x00, 0x00}; // Write-only command
private final byte[] CMD_GLUC = new byte[]{0x47, 0x4c, 0x55, 0x43};
private final byte[] CMD_ConnectionRequest = new byte[]{0x00, 0x00, 0x00, 0x00}; // Write-only command
private final byte[] CMD_NSPName = new byte[]{0x02, 0x00, 0x00, 0x00}; // Write-only command
private final byte[] CMD_NSPData = new byte[]{0x04, 0x00, 0x00, 0x00}; // Write-only command

private final byte[] CMD_ConnectionResponse = new byte[]{0x47, 0x4c, 0x55, 0x43, 0x01, 0x00, 0x00, 0x00};
private final byte[] CMD_Start = new byte[]{0x47, 0x4c, 0x55, 0x43, 0x03, 0x00, 0x00, 0x00};
private final byte[] CMD_NSPContent = new byte[]{0x47, 0x4c, 0x55, 0x43, 0x05, 0x00, 0x00, 0x00};
private final byte[] CMD_NSPTicket = new byte[]{0x47, 0x4c, 0x55, 0x43, 0x06, 0x00, 0x00, 0x00};
private final byte[] CMD_Finish = new byte[]{0x47, 0x4c, 0x55, 0x43, 0x07, 0x00, 0x00, 0x00};
private final byte[] CMD_ConnectionResponse = new byte[]{0x01, 0x00, 0x00, 0x00};
private final byte[] CMD_Start = new byte[]{0x03, 0x00, 0x00, 0x00};
private final byte[] CMD_NSPContent = new byte[]{0x05, 0x00, 0x00, 0x00};
private final byte[] CMD_NSPTicket = new byte[]{0x06, 0x00, 0x00, 0x00};
private final byte[] CMD_Finish = new byte[]{0x07, 0x00, 0x00, 0x00};

GoldLeaf(){
logPrinter.print("===========================================================================", EMsgType.INFO);
Expand All @@ -484,44 +486,54 @@ private boolean initGoldLeafProtocol(PFSProvider pfsElement){
byte[] readByte;

// Go connect to GoldLeaf
if (writeToUsb(CMD_GLUC))
logPrinter.print("GL Initiating GoldLeaf connection: 1/2", EMsgType.PASS);
else {
logPrinter.print("GL Initiating GoldLeaf connection: 1/2", EMsgType.FAIL);
return false;
}
if (writeToUsb(CMD_ConnectionRequest))
logPrinter.print("GL Initiating GoldLeaf connection", EMsgType.PASS);
logPrinter.print("GL Initiating GoldLeaf connection: 2/2", EMsgType.PASS);
else {
logPrinter.print("GL Initiating GoldLeaf connection", EMsgType.FAIL);
logPrinter.print("GL Initiating GoldLeaf connection: 2/2", EMsgType.FAIL);
return false;
}
while (true) {
readByte = readFromUsb();
if (readByte == null)
return false;

if (Arrays.equals(readByte, CMD_ConnectionResponse)) {
if (!handleConnectionResponse(pfsElement))
return false;
else
continue;
}
if (Arrays.equals(readByte, CMD_Start)) {
if (!handleStart(pfsElement))
return false;
else
continue;
}
if (Arrays.equals(readByte, CMD_NSPContent)) {
if (!handleNSPContent(pfsElement, true))
if (Arrays.equals(readByte, CMD_GLUC)) {
readByte = readFromUsb();
if (readByte == null)
return false;
else
continue;
}
if (Arrays.equals(readByte, CMD_NSPTicket)) {
if (!handleNSPContent(pfsElement, false))
return false;
else
continue;
}
if (Arrays.equals(readByte, CMD_Finish)) {
logPrinter.print("GL Closing GoldLeaf connection: Transfer successful.", EMsgType.PASS);
break;
if (Arrays.equals(readByte, CMD_ConnectionResponse)) {
if (!handleConnectionResponse(pfsElement))
return false;
else
continue;
}
if (Arrays.equals(readByte, CMD_Start)) {
if (!handleStart(pfsElement))
return false;
else
continue;
}
if (Arrays.equals(readByte, CMD_NSPContent)) {
if (!handleNSPContent(pfsElement, true))
return false;
else
continue;
}
if (Arrays.equals(readByte, CMD_NSPTicket)) {
if (!handleNSPContent(pfsElement, false))
return false;
else
continue;
}
if (Arrays.equals(readByte, CMD_Finish)) {
logPrinter.print("GL Closing GoldLeaf connection: Transfer successful.", EMsgType.PASS);
break;
}
}
}
return true;
Expand All @@ -531,23 +543,28 @@ private boolean initGoldLeafProtocol(PFSProvider pfsElement){
* */
private boolean handleConnectionResponse(PFSProvider pfsElement){
logPrinter.print("GL 'ConnectionResponse' command:", EMsgType.INFO);
if (!writeToUsb(CMD_GLUC)) {
logPrinter.print(" [1/4]", EMsgType.FAIL);
return false;
}
logPrinter.print(" [1/4]", EMsgType.PASS);
if (!writeToUsb(CMD_NSPName)) {
logPrinter.print(" [1/3]", EMsgType.FAIL);
logPrinter.print(" [2/4]", EMsgType.FAIL);
return false;
}
logPrinter.print(" [1/3]", EMsgType.PASS);
logPrinter.print(" [2/4]", EMsgType.PASS);

if (!writeToUsb(pfsElement.getBytesNspFileNameLength())) {
logPrinter.print(" [2/3]", EMsgType.FAIL);
logPrinter.print(" [3/4]", EMsgType.FAIL);
return false;
}
logPrinter.print(" [2/3]", EMsgType.PASS);
logPrinter.print(" [3/4]", EMsgType.PASS);

if (!writeToUsb(pfsElement.getBytesNspFileName())) {
logPrinter.print(" [3/3]", EMsgType.FAIL);
logPrinter.print(" [4/4]", EMsgType.FAIL);
return false;
}
logPrinter.print(" [3/3]", EMsgType.PASS);
logPrinter.print(" [4/4]", EMsgType.PASS);

return true;
}
Expand All @@ -556,6 +573,12 @@ private boolean handleConnectionResponse(PFSProvider pfsElement){
* */
private boolean handleStart(PFSProvider pfsElement){
logPrinter.print("GL Handle 'Start' command:", EMsgType.INFO);
if (!writeToUsb(CMD_GLUC)) {
logPrinter.print(" [Send command prepare]", EMsgType.FAIL);
return false;
}
logPrinter.print(" [Send command prepare]", EMsgType.PASS);

if (!writeToUsb(CMD_NSPData)) {
logPrinter.print(" [Send command]", EMsgType.FAIL);
return false;
Expand Down Expand Up @@ -602,7 +625,7 @@ private boolean handleStart(PFSProvider pfsElement){
* */
private boolean handleNSPContent(PFSProvider pfsElement, boolean isItRawRequest){
int requestedNcaID;
boolean isProgessBarInitiated = false;

if (isItRawRequest) {
logPrinter.print("GL Handle 'Content' command", EMsgType.INFO);
byte[] readByte = readFromUsb();
Expand Down

0 comments on commit 20e4197

Please sign in to comment.