DarkMatterCore/nxdumptool support
This commit is contained in:
parent
63341008a5
commit
4643c08cc2
17 changed files with 641 additions and 5 deletions
2
pom.xml
2
pom.xml
|
@ -8,7 +8,7 @@
|
|||
<name>NS-USBloader</name>
|
||||
|
||||
<artifactId>ns-usbloader</artifactId>
|
||||
<version>2.2.1-SNAPSHOT</version>
|
||||
<version>3.0-SNAPSHOT</version>
|
||||
|
||||
<url>https://github.com/developersu/ns-usbloader/</url>
|
||||
<description>
|
||||
|
|
|
@ -152,4 +152,7 @@ public class AppPreferences {
|
|||
// RCM //
|
||||
public String getRecentRcm(int num){ return preferences.get(String.format("RCM_%02d", num), ""); }
|
||||
public void setRecentRcm(int num, String value){ preferences.put(String.format("RCM_%02d", num), value); }
|
||||
// NXDT //
|
||||
public String getNXDTSaveToLocation(){ return preferences.get("nxdt_saveto", System.getProperty("user.home")); }
|
||||
public void setNXDTSaveToLocation(String value){ preferences.put("nxdt_saveto", value); }
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@ public class NSLMainController implements Initializable {
|
|||
private SplitMergeController SplitMergeTabController;
|
||||
@FXML
|
||||
private RcmController RcmTabController;
|
||||
@FXML
|
||||
private NxdtController NXDTabController;
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb) {
|
||||
|
@ -110,6 +112,8 @@ public class NSLMainController implements Initializable {
|
|||
}
|
||||
|
||||
public RcmController getRcmCtrlr(){ return RcmTabController; }
|
||||
|
||||
public NxdtController getNXDTabController(){ return NXDTabController; }
|
||||
/**
|
||||
* Save preferences before exit
|
||||
* */
|
||||
|
@ -135,5 +139,6 @@ public class NSLMainController implements Initializable {
|
|||
|
||||
SplitMergeTabController.updatePreferencesOnExit(); // NOTE: This shit above should be re-written to similar pattern
|
||||
RcmTabController.updatePreferencesOnExit();
|
||||
NXDTabController.updatePreferencesOnExit();
|
||||
}
|
||||
}
|
||||
|
|
133
src/main/java/nsusbloader/Controllers/NxdtController.java
Normal file
133
src/main/java/nsusbloader/Controllers/NxdtController.java
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
Copyright 2019-2020 Dmitry Isaenko
|
||||
|
||||
This file is part of NS-USBloader.
|
||||
|
||||
NS-USBloader is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NS-USBloader is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package nsusbloader.Controllers;
|
||||
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
import nsusbloader.AppPreferences;
|
||||
import nsusbloader.MediatorControl;
|
||||
import nsusbloader.NSLDataTypes.EModule;
|
||||
import nsusbloader.Utilities.NxdtTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class NxdtController implements Initializable {
|
||||
@FXML
|
||||
private Label saveToLocationLbl, statusLbl;
|
||||
|
||||
@FXML
|
||||
private Button injectPldBtn;
|
||||
|
||||
private ResourceBundle rb;
|
||||
|
||||
private Region btnDumpStopImage;
|
||||
|
||||
private Task<Boolean> NxdtTask;
|
||||
private Thread workThread;
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
this.rb = resourceBundle;
|
||||
|
||||
saveToLocationLbl.setText(AppPreferences.getInstance().getNXDTSaveToLocation());
|
||||
|
||||
btnDumpStopImage = new Region();
|
||||
btnDumpStopImage.getStyleClass().add("regionDump");
|
||||
|
||||
injectPldBtn.getStyleClass().add("buttonUp");
|
||||
injectPldBtn.setGraphic(btnDumpStopImage);
|
||||
|
||||
injectPldBtn.setOnAction(event -> startDumpProcess());
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void bntSelectSaveTo(){
|
||||
DirectoryChooser dc = new DirectoryChooser();
|
||||
dc.setTitle(rb.getString("tabSplMrg_Btn_SelectFolder"));
|
||||
dc.setInitialDirectory(new File(saveToLocationLbl.getText()));
|
||||
File saveToDir = dc.showDialog(saveToLocationLbl.getScene().getWindow());
|
||||
if (saveToDir != null)
|
||||
saveToLocationLbl.setText(saveToDir.getAbsolutePath());
|
||||
}
|
||||
/**
|
||||
* Start reading commands from NXDT button handler
|
||||
* */
|
||||
private void startDumpProcess(){
|
||||
if ((workThread == null || ! workThread.isAlive())){
|
||||
MediatorControl.getInstance().getContoller().logArea.clear();
|
||||
|
||||
NxdtTask = new NxdtTask(saveToLocationLbl.getText());
|
||||
NxdtTask.setOnSucceeded(event -> {
|
||||
if (NxdtTask.getValue())
|
||||
statusLbl.setText(rb.getString("done_txt"));
|
||||
else
|
||||
statusLbl.setText(rb.getString("failure_txt"));
|
||||
});
|
||||
|
||||
workThread = new Thread(NxdtTask);
|
||||
workThread.setDaemon(true);
|
||||
workThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupt thread NXDT button handler
|
||||
* */
|
||||
private void stopBtnAction(){
|
||||
//TODO
|
||||
}
|
||||
|
||||
public void notifyThreadStarted(boolean isActive, EModule type){
|
||||
if (! type.equals(EModule.NXDT)){
|
||||
injectPldBtn.setDisable(isActive);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isActive) {
|
||||
btnDumpStopImage.getStyleClass().clear();
|
||||
btnDumpStopImage.getStyleClass().add("regionStop");
|
||||
|
||||
injectPldBtn.setOnAction(e-> stopBtnAction());
|
||||
injectPldBtn.setText(rb.getString("btn_Stop"));
|
||||
injectPldBtn.getStyleClass().remove("buttonUp");
|
||||
injectPldBtn.getStyleClass().add("buttonStop");
|
||||
return;
|
||||
}
|
||||
btnDumpStopImage.getStyleClass().clear();
|
||||
btnDumpStopImage.getStyleClass().add("regionDump");
|
||||
|
||||
injectPldBtn.setOnAction(e-> startDumpProcess());
|
||||
injectPldBtn.setText(rb.getString("tabNXDT_Btn_Start"));
|
||||
injectPldBtn.getStyleClass().remove("buttonStop");
|
||||
injectPldBtn.getStyleClass().add("buttonUp");
|
||||
}
|
||||
/**
|
||||
* Save application settings on exit
|
||||
* */
|
||||
public void updatePreferencesOnExit(){
|
||||
AppPreferences.getInstance().setNXDTSaveToLocation(saveToLocationLbl.getText());
|
||||
}
|
||||
}
|
|
@ -44,6 +44,7 @@ public class MediatorControl {
|
|||
mainCtrler.getFrontCtrlr().notifyTransmThreadStarted(isActive, appModuleType);
|
||||
mainCtrler.getSmCtrlr().notifySmThreadStarted(isActive, appModuleType);
|
||||
mainCtrler.getRcmCtrlr().notifySmThreadStarted(isActive, appModuleType);
|
||||
mainCtrler.getNXDTabController().notifyThreadStarted(isActive, appModuleType);
|
||||
}
|
||||
public synchronized boolean getTransferActive() { return this.isTransferActive.get(); }
|
||||
}
|
||||
|
|
|
@ -21,5 +21,6 @@ package nsusbloader.NSLDataTypes;
|
|||
public enum EModule {
|
||||
USB_NET_TRANSFERS,
|
||||
SPLIT_MERGE_TOOL,
|
||||
RCM
|
||||
RCM,
|
||||
NXDT
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.util.ResourceBundle;
|
|||
|
||||
public class NSLMain extends Application {
|
||||
|
||||
public static final String appVersion = "v2.2.1";
|
||||
public static final String appVersion = "v3.0";
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception{
|
||||
|
|
60
src/main/java/nsusbloader/Utilities/NxdtTask.java
Normal file
60
src/main/java/nsusbloader/Utilities/NxdtTask.java
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
Copyright 2019-2020 Dmitry Isaenko
|
||||
|
||||
This file is part of NS-USBloader.
|
||||
|
||||
NS-USBloader is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NS-USBloader is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package nsusbloader.Utilities;
|
||||
|
||||
import javafx.concurrent.Task;
|
||||
import nsusbloader.COM.USB.UsbConnect;
|
||||
import nsusbloader.ModelControllers.LogPrinter;
|
||||
import nsusbloader.NSLDataTypes.EModule;
|
||||
import nsusbloader.NSLDataTypes.EMsgType;
|
||||
import org.usb4java.DeviceHandle;
|
||||
|
||||
public class NxdtTask extends Task<Boolean> {
|
||||
|
||||
private LogPrinter logPrinter;
|
||||
private String saveToLocation;
|
||||
|
||||
public NxdtTask(String saveToLocation){
|
||||
this.logPrinter = new LogPrinter(EModule.NXDT);
|
||||
this.saveToLocation = saveToLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean call() {
|
||||
logPrinter.print("Save to location: "+ saveToLocation, EMsgType.INFO);
|
||||
logPrinter.print("=============== nxdumptool ===============", EMsgType.INFO);
|
||||
|
||||
UsbConnect usbConnect = UsbConnect.connectHomebrewMode(logPrinter);
|
||||
|
||||
if (! usbConnect.isConnected()){
|
||||
logPrinter.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
DeviceHandle handler = usbConnect.getNsHandler();
|
||||
|
||||
new NxdtUsbAbi1(handler, this, logPrinter, saveToLocation);
|
||||
|
||||
logPrinter.print(".:: Complete ::.", EMsgType.PASS);
|
||||
|
||||
usbConnect.close();
|
||||
logPrinter.close();
|
||||
return true;
|
||||
}
|
||||
}
|
327
src/main/java/nsusbloader/Utilities/NxdtUsbAbi1.java
Normal file
327
src/main/java/nsusbloader/Utilities/NxdtUsbAbi1.java
Normal file
|
@ -0,0 +1,327 @@
|
|||
/*
|
||||
Copyright 2019-2020 Dmitry Isaenko
|
||||
|
||||
This file is part of NS-USBloader.
|
||||
|
||||
NS-USBloader is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NS-USBloader is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package nsusbloader.Utilities;
|
||||
|
||||
import javafx.concurrent.Task;
|
||||
import nsusbloader.COM.USB.UsbErrorCodes;
|
||||
import nsusbloader.ModelControllers.LogPrinter;
|
||||
import nsusbloader.NSLDataTypes.EMsgType;
|
||||
import org.usb4java.DeviceHandle;
|
||||
import org.usb4java.LibUsb;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
class NxdtUsbAbi1 {
|
||||
private LogPrinter logPrinter;
|
||||
private DeviceHandle handlerNS;
|
||||
private Task<Boolean> task;
|
||||
private String saveToPath;
|
||||
|
||||
private boolean isWindows;
|
||||
|
||||
private static final int NXDT_COMMAND_SIZE = 0x1000;
|
||||
private static final int NXDT_FILE_CHUNK_SIZE = 0x800000;
|
||||
|
||||
private static final byte ABI_VERSION = 1;
|
||||
private static final byte[] MAGIC_NXDT = { 0x4e, 0x58, 0x44, 0x54 };
|
||||
|
||||
private static final byte CMD_HANDSHAKE = 0;
|
||||
private static final byte CMD_SEND_FILE_PROPERTIES = 1;
|
||||
private static final byte CMD_ENDSESSION = 3;
|
||||
|
||||
// Standard set of possible replies
|
||||
private static final byte[] USBSTATUS_SUCCESS = { 0x4e, 0x58, 0x44, 0x54,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00 };
|
||||
private static final byte[] USBSTATUS_INVALID_MAGIC = { 0x4e, 0x58, 0x44, 0x54,
|
||||
0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00 };
|
||||
private static final byte[] USBSTATUS_UNSUPPORTED_ABI = { 0x4e, 0x58, 0x44, 0x54,
|
||||
0x06, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00 };
|
||||
private static final byte[] USBSTATUS_UNSUPPORTED_CMD = { 0x4e, 0x58, 0x44, 0x54,
|
||||
0x07, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00 };
|
||||
private static final byte[] USBSTATUS_HOSTIOERROR = { 0x4e, 0x58, 0x44, 0x54,
|
||||
0x08, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
public NxdtUsbAbi1(DeviceHandle handler,
|
||||
Task<Boolean> task,
|
||||
LogPrinter logPrinter,
|
||||
String saveToPath
|
||||
){
|
||||
this.handlerNS = handler;
|
||||
this.task = task;
|
||||
this.logPrinter = logPrinter;
|
||||
this.isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
|
||||
|
||||
if (! saveToPath.endsWith(File.separator))
|
||||
this.saveToPath = saveToPath + File.separator;
|
||||
else
|
||||
this.saveToPath = saveToPath;
|
||||
|
||||
readLoop();
|
||||
}
|
||||
|
||||
private void readLoop(){
|
||||
logPrinter.print("Awaiting for handshake", EMsgType.INFO);
|
||||
try {
|
||||
byte[] deviceCommand;
|
||||
|
||||
while (true){
|
||||
deviceCommand = readUsbCmd();
|
||||
|
||||
if (isInvalidCommand(deviceCommand))
|
||||
continue;
|
||||
|
||||
switch (deviceCommand[4]){
|
||||
case CMD_HANDSHAKE:
|
||||
performHandshake(deviceCommand);
|
||||
break;
|
||||
case CMD_SEND_FILE_PROPERTIES:
|
||||
handleSendFileProperties(deviceCommand);
|
||||
break;
|
||||
case CMD_ENDSESSION:
|
||||
logPrinter.print("Session successfully ended", EMsgType.PASS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InterruptedException ioe){
|
||||
logPrinter.print("Execution interrupted", EMsgType.INFO);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
logPrinter.print(e.getMessage(), EMsgType.INFO);
|
||||
logPrinter.print("Terminating now", EMsgType.FAIL);
|
||||
}
|
||||
};
|
||||
|
||||
private boolean isInvalidCommand(byte[] message) throws Exception{
|
||||
boolean returnValue = false;
|
||||
if (! Arrays.equals(Arrays.copyOfRange(message, 0,4), MAGIC_NXDT)){
|
||||
writeUsb(USBSTATUS_INVALID_MAGIC);
|
||||
logPrinter.print("Invalid magic command", EMsgType.INFO);
|
||||
returnValue = true;
|
||||
}
|
||||
if (message.length != NXDT_COMMAND_SIZE){
|
||||
writeUsb(USBSTATUS_UNSUPPORTED_CMD);
|
||||
logPrinter.print("Invalid command size. Expected size is 4096 while received is "+message.length, EMsgType.INFO);
|
||||
returnValue = true;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private void performHandshake(byte[] message) throws Exception{
|
||||
logPrinter.print("nxdumptool v"+message[8]+"."+message[9]+"."+message[10]+" ABI v"+message[11], EMsgType.INFO);
|
||||
|
||||
if (ABI_VERSION != message[11]){
|
||||
writeUsb(USBSTATUS_UNSUPPORTED_ABI);
|
||||
throw new Exception("ABI v"+message[11]+" is not supported in current version.");
|
||||
}
|
||||
writeUsb(USBSTATUS_SUCCESS);
|
||||
// consider refactoring: create sub-classes for various ABI versions and check if it's supported or not
|
||||
}
|
||||
|
||||
private void handleSendFileProperties(byte[] message) throws Exception{
|
||||
long fileSize = getLElong(message, 8);
|
||||
int fileNameLen = getLEint(message, 12);
|
||||
String filename = new String(Arrays.copyOfRange(message, 16, fileNameLen), StandardCharsets.UTF_8);
|
||||
|
||||
// TODO: In here should be also a field with NSP Header size that would be transmitted after the end of main data transfer; NOTE: Handle with RandomAccessFile.
|
||||
|
||||
logPrinter.print("Write request for: '"+filename+"' ("+fileSize+" bytes)", EMsgType.INFO);
|
||||
// If RomFs related
|
||||
if (filename.startsWith("/")) {
|
||||
if (isWindows)
|
||||
filename = saveToPath + filename.replaceAll("/", "\\\\");
|
||||
else
|
||||
filename = saveToPath + filename;
|
||||
|
||||
try {
|
||||
createPath(filename);
|
||||
}
|
||||
catch (Exception e){
|
||||
writeUsb(USBSTATUS_HOSTIOERROR);
|
||||
logPrinter.print("Unable to create dir(s) for file in "+filename+
|
||||
"\n Returned: "+e.getMessage(), EMsgType.FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
filename = saveToPath + filename;
|
||||
|
||||
File fileToDump = new File(filename);
|
||||
|
||||
// Check if enough space
|
||||
if (fileToDump.getFreeSpace() <= fileSize){
|
||||
writeUsb(USBSTATUS_HOSTIOERROR);
|
||||
logPrinter.print("Not enough space on selected volume. Need: "+fileSize+" while available: "+fileToDump.getFreeSpace(), EMsgType.FAIL);
|
||||
return;
|
||||
}
|
||||
// Check if FS is NOT read-only
|
||||
if (! fileToDump.canWrite()){
|
||||
writeUsb(USBSTATUS_HOSTIOERROR);
|
||||
logPrinter.print("Unable to write into selected volume: "+fileToDump.getAbsolutePath(), EMsgType.FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
dumpFile(fileToDump, fileSize);
|
||||
|
||||
writeUsb(USBSTATUS_SUCCESS);
|
||||
|
||||
// TODO: check if NSP_SIZE != 0 then go dump header
|
||||
}
|
||||
|
||||
private void createPath(String path) throws Exception{
|
||||
File resultingFile = new File(path);
|
||||
File folderForTheFile = resultingFile.getParentFile();
|
||||
folderForTheFile.mkdirs();
|
||||
}
|
||||
|
||||
private void dumpFile(File file, long size) throws Exception{
|
||||
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, false));
|
||||
|
||||
byte[] readBuffer;
|
||||
long received = 0;
|
||||
int bufferSize;
|
||||
|
||||
while (received < size){
|
||||
readBuffer = readUsbFile();
|
||||
bos.write(readBuffer);
|
||||
bufferSize = readBuffer.length;
|
||||
received += bufferSize;
|
||||
|
||||
logPrinter.updateProgress((received + bufferSize) / (size / 100.0) / 100.0);
|
||||
}
|
||||
|
||||
logPrinter.updateProgress(1.0);
|
||||
bos.close();
|
||||
}
|
||||
|
||||
|
||||
public static int getLEint(byte[] bytes, int fromOffset){
|
||||
return ByteBuffer.wrap(bytes, fromOffset, 0x4).order(ByteOrder.LITTLE_ENDIAN).getInt();
|
||||
}
|
||||
|
||||
public static long getLElong(byte[] bytes, int fromOffset){
|
||||
return ByteBuffer.wrap(bytes, fromOffset, 0x8).order(ByteOrder.LITTLE_ENDIAN).getLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sending any byte array to USB device
|
||||
* @return 'false' if no issues
|
||||
* 'true' if errors happened
|
||||
* */
|
||||
private void writeUsb(byte[] message) throws Exception{
|
||||
ByteBuffer writeBuffer = ByteBuffer.allocateDirect(message.length);
|
||||
writeBuffer.put(message);
|
||||
IntBuffer writeBufTransferred = IntBuffer.allocate(1);
|
||||
int result;
|
||||
|
||||
while (! task.isCancelled()) {
|
||||
result = LibUsb.bulkTransfer(handlerNS, (byte) 0x01, writeBuffer, writeBufTransferred, 5050);
|
||||
|
||||
switch (result){
|
||||
case LibUsb.SUCCESS:
|
||||
if (writeBufTransferred.get() == message.length)
|
||||
return;
|
||||
throw new Exception("Data transfer issue [write]" +
|
||||
"\n Requested: "+message.length+
|
||||
"\n Transferred: "+writeBufTransferred.get());
|
||||
case LibUsb.ERROR_TIMEOUT:
|
||||
continue;
|
||||
default:
|
||||
throw new Exception("Data transfer issue [write]" +
|
||||
"\n Returned: "+ UsbErrorCodes.getErrCode(result) +
|
||||
"\n (execution stopped)");
|
||||
}
|
||||
}
|
||||
throw new InterruptedException("Execution interrupted");
|
||||
}
|
||||
/**
|
||||
* Reading what USB device responded (command).
|
||||
* @return byte array if data read successful
|
||||
* 'null' if read failed
|
||||
* */
|
||||
private byte[] readUsbCmd() throws Exception{
|
||||
ByteBuffer readBuffer = ByteBuffer.allocateDirect(NXDT_COMMAND_SIZE);
|
||||
// We can limit it to 32 bytes, but there is a non-zero chance to got OVERFLOW from libusb.
|
||||
IntBuffer readBufTransferred = IntBuffer.allocate(1);
|
||||
int result;
|
||||
while (! task.isCancelled()) {
|
||||
result = LibUsb.bulkTransfer(handlerNS, (byte) 0x81, readBuffer, readBufTransferred, 1000); // last one is TIMEOUT. 0 stands for unlimited. Endpoint IN = 0x81
|
||||
|
||||
switch (result) {
|
||||
case LibUsb.SUCCESS:
|
||||
int trans = readBufTransferred.get();
|
||||
byte[] receivedBytes = new byte[trans];
|
||||
readBuffer.get(receivedBytes);
|
||||
return receivedBytes;
|
||||
case LibUsb.ERROR_TIMEOUT:
|
||||
continue;
|
||||
default:
|
||||
throw new Exception("Data transfer issue [read command]" +
|
||||
"\n Returned: " + UsbErrorCodes.getErrCode(result)+
|
||||
"\n (execution stopped)");
|
||||
}
|
||||
}
|
||||
throw new InterruptedException();
|
||||
}
|
||||
/**
|
||||
* Reading what USB device responded (file).
|
||||
* @return byte array if data read successful
|
||||
* 'null' if read failed
|
||||
* */
|
||||
private byte[] readUsbFile() throws Exception{
|
||||
ByteBuffer readBuffer = ByteBuffer.allocateDirect(NXDT_FILE_CHUNK_SIZE);
|
||||
IntBuffer readBufTransferred = IntBuffer.allocate(1);
|
||||
int result;
|
||||
while (! task.isCancelled()) {
|
||||
result = LibUsb.bulkTransfer(handlerNS, (byte) 0x81, readBuffer, readBufTransferred, 1000);
|
||||
|
||||
switch (result) {
|
||||
case LibUsb.SUCCESS:
|
||||
int trans = readBufTransferred.get();
|
||||
byte[] receivedBytes = new byte[trans];
|
||||
readBuffer.get(receivedBytes);
|
||||
return receivedBytes;
|
||||
case LibUsb.ERROR_TIMEOUT:
|
||||
continue;
|
||||
default:
|
||||
throw new Exception("Data transfer issue [read file]" +
|
||||
"\n Returned: " + UsbErrorCodes.getErrCode(result)+
|
||||
"\n (execution stopped)");
|
||||
}
|
||||
}
|
||||
throw new InterruptedException();
|
||||
}
|
||||
}
|
|
@ -31,6 +31,14 @@
|
|||
<SVGPath content="M 5.2753906 0.9453125 C 3.4702091 0.94491305 2.0128532 1.7453477 1.0566406 2.9082031 C 0.10042811 4.0710585 -0.40065633 5.5585011 -0.55664062 7.0488281 C -0.71262492 8.5391552 -0.52822452 10.042928 0.0078125 11.292969 C 0.54008474 12.534229 1.4899019 13.5834 2.8300781 13.826172 L 2.828125 13.837891 L 4.2050781 13.837891 L 4.6484375 11.080078 L 5.3496094 11.080078 L 5.9257812 13.837891 L 7.4042969 13.837891 L 7.4042969 13.753906 L 6.703125 10.685547 C 7.49408 10.281262 7.9297095 9.5624699 8.0097656 8.5292969 C 8.0610016 7.8485775 7.9209243 7.3118876 7.5878906 6.9179688 C 7.254857 6.5240499 6.7748288 6.3176076 6.1503906 6.296875 L 4.0371094 6.2910156 L 3.0976562 12.150391 C 2.4734416 12.023142 1.945837 11.518943 1.5625 10.625 C 1.1696133 9.7087867 0.99863233 8.4506302 1.1269531 7.2246094 C 1.2552739 5.9985885 1.6798073 4.8135983 2.3632812 3.9824219 C 3.0467553 3.1512454 3.9413986 2.6383771 5.2734375 2.6386719 L 20.007812 2.640625 C 20.496454 2.6407331 20.818797 2.788345 21.136719 3.0976562 C 21.454641 3.4069676 21.743658 3.910529 21.949219 4.5761719 C 22.36034 5.9074576 22.421621 7.8407685 22.128906 9.7714844 C 21.836191 11.7022 21.195943 13.639966 20.339844 15.023438 C 19.483744 16.406908 18.498727 17.154297 17.46875 17.154297 L -0.59375 17.154297 L -0.59375 18.845703 L 17.46875 18.845703 C 19.298148 18.845703 20.755291 17.568872 21.779297 15.914062 C 22.803302 14.259253 23.481257 12.145818 23.802734 10.025391 C 24.124212 7.904966 24.093647 5.7854271 23.566406 4.078125 C 23.302786 3.2244739 22.911503 2.4618437 22.318359 1.8847656 C 21.725216 1.3076876 20.907952 0.94941793 20.007812 0.94921875 L 5.2753906 0.9453125 z M 11.574219 6.1875 C 10.831297 6.1702229 10.207831 6.4450285 9.7050781 7.0117188 C 9.2055276 7.578409 8.8809744 8.3951633 8.7304688 9.4628906 L 8.5527344 10.712891 C 8.5207119 10.975503 8.5072674 11.234984 8.5136719 11.494141 C 8.5328854 12.254335 8.7132962 12.848871 9.0527344 13.277344 C 9.3921725 13.705817 9.8729047 13.927585 10.494141 13.941406 C 11.217848 13.962139 11.814426 13.735112 12.285156 13.261719 C 12.759089 12.78487 13.038539 12.137296 13.125 11.318359 L 11.775391 11.328125 C 11.698537 11.846439 11.565182 12.208239 11.373047 12.412109 C 11.180912 12.612524 10.923036 12.704777 10.599609 12.6875 C 10.080845 12.663312 9.8371182 12.277623 9.8691406 11.53125 C 9.8723429 11.403399 9.8965748 11.131448 9.9414062 10.716797 L 10.113281 9.4160156 C 10.190135 8.7145637 10.339592 8.209426 10.560547 7.8984375 C 10.781502 7.5839935 11.081823 7.4334439 11.462891 7.4472656 C 11.956037 7.4645428 12.209143 7.763238 12.21875 8.34375 L 12.208984 8.8574219 L 13.595703 8.8613281 C 13.595703 7.9974711 13.421311 7.3393799 13.072266 6.8867188 C 12.723221 6.4306022 12.224275 6.1978663 11.574219 6.1875 z M 14.869141 6.2910156 L 13.658203 13.837891 L 15.037109 13.837891 L 15.353516 11.847656 L 15.753906 8.5976562 L 16.28125 13.837891 L 17.21875 13.837891 L 19.361328 8.7675781 L 18.755859 11.748047 L 18.419922 13.837891 L 19.802734 13.837891 L 21.017578 6.2910156 L 19.201172 6.2910156 L 17.054688 11.716797 L 16.646484 6.2910156 L 14.869141 6.2910156 z M 5.2148438 7.5605469 L 6.09375 7.5664062 C 6.4491994 7.5940497 6.6336754 7.8344483 6.6464844 8.2871094 C 6.6496866 8.7466813 6.5554161 9.1146416 6.3632812 9.3945312 C 6.1711464 9.6709655 5.9072524 9.8134016 5.5742188 9.8203125 L 4.8496094 9.8105469 L 5.2148438 7.5605469 z" />
|
||||
</graphic>
|
||||
</Tab>
|
||||
<Tab closable="false">
|
||||
<content>
|
||||
<fx:include fx:id="NXDTab" source="NXDTab.fxml" VBox.vgrow="ALWAYS" />
|
||||
</content>
|
||||
<graphic>
|
||||
<SVGPath content="M 7 0 L 0 4 C -0.02484618 7.6613523 4.6259293e-18 7.3229335 0 10.984375 C 0 10.993031 0.015625 7 0.015625 8 L 13 0 L 7 0 z M 17.966797 6.46875 L 17.966797 10.673828 C 17.715715 10.211268 17.396999 9.8685131 17.011719 9.6464844 C 16.630766 9.4198301 16.171566 9.3066406 15.634766 9.3066406 C 14.755976 9.3066406 14.040441 9.682293 13.486328 10.431641 C 12.936542 11.180987 12.660156 12.165561 12.660156 13.386719 C 12.660156 14.607877 12.936542 15.59245 13.486328 16.341797 C 14.040441 17.091144 14.755976 17.466797 15.634766 17.466797 C 16.171566 17.466797 16.630766 17.354841 17.011719 17.132812 C 17.396999 16.90616 17.715715 16.562169 17.966797 16.099609 L 17.966797 17.265625 L 19.160156 17.265625 L 19.160156 6.46875 L 17.966797 6.46875 z M 20.572266 7.3652344 L 20.572266 9.5546875 L 19.800781 9.5546875 L 19.800781 10.539062 L 20.572266 10.539062 L 20.572266 14.724609 C 20.572266 15.688531 20.728201 16.353495 21.037109 16.720703 C 21.346016 17.083321 21.906432 17.265625 22.71875 17.265625 L 23.800781 17.265625 L 23.800781 16.205078 L 22.71875 16.205078 C 22.280176 16.205078 21.98867 16.114559 21.84375 15.935547 C 21.702645 15.756534 21.630859 15.353453 21.630859 14.724609 L 21.630859 10.539062 L 23.800781 10.539062 L 23.800781 9.5546875 L 21.630859 9.5546875 L 21.630859 7.3652344 L 20.572266 7.3652344 z M 3.6386719 9.3066406 C 3.1397071 9.3066406 2.6982722 9.4230165 2.3144531 9.6542969 C 1.9348986 9.8855772 1.6037331 10.233986 1.3222656 10.701172 L 1.3222656 9.4941406 L 0.13867188 9.4941406 L 0.13867188 17.265625 L 1.3222656 17.265625 L 1.3222656 12.873047 C 1.3222656 12.114448 1.5062865 11.515605 1.8730469 11.076172 C 2.2398077 10.636739 2.7395664 10.417969 3.375 10.417969 C 3.9038175 10.417969 4.3000442 10.599421 4.5644531 10.964844 C 4.8288618 11.330266 4.9609375 11.881715 4.9609375 12.617188 L 4.9609375 17.265625 L 6.1386719 17.265625 L 6.1386719 12.576172 C 6.1386719 11.503031 5.9280604 10.691072 5.5058594 10.140625 C 5.0836585 9.5855522 4.4617505 9.3066406 3.6386719 9.3066406 z M 6.984375 9.4941406 L 9.2207031 13.199219 L 6.7773438 17.265625 L 7.9960938 17.265625 L 9.828125 14.212891 L 11.658203 17.265625 L 12.878906 17.265625 L 10.484375 13.275391 L 12.759766 9.4941406 L 11.541016 9.4941406 L 9.8730469 12.263672 L 8.2050781 9.4941406 L 6.984375 9.4941406 z M 15.927734 10.375 C 16.559769 10.375 17.056283 10.643118 17.419922 11.179688 C 17.783557 11.711631 17.966797 12.447722 17.966797 13.386719 C 17.966797 14.325715 17.783557 15.06304 17.419922 15.599609 C 17.056283 16.131553 16.559769 16.398437 15.927734 16.398438 C 15.295699 16.398438 14.797233 16.131553 14.433594 15.599609 C 14.074286 15.06304 13.894531 14.325715 13.894531 13.386719 C 13.894531 12.447722 14.074286 11.711631 14.433594 11.179688 C 14.797233 10.643118 15.295699 10.375 15.927734 10.375 z M 24 18.400391 C 24.0056 21.386719 23.984375 22 23.984375 19 L 15 23.982422 L 23.984375 23.996094 C 23.993075 23.996094 24 23.990492 24 23.982422 L 24 18.400391 z" />
|
||||
</graphic>
|
||||
</Tab>
|
||||
<Tab closable="false">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
|
|
78
src/main/resources/NXDTab.fxml
Normal file
78
src/main/resources/NXDTab.fxml
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Separator?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.shape.SVGPath?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<VBox spacing="15.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="nsusbloader.Controllers.NxdtController">
|
||||
<HBox alignment="CENTER">
|
||||
<children>
|
||||
<Label styleClass="nxdt" text="nx">
|
||||
<font>
|
||||
<Font name="System Bold" size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label text="dumptool">
|
||||
<font>
|
||||
<Font name="System Bold" size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" percentWidth="90.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Separator prefWidth="200.0" styleClass="strangeSeparator" GridPane.columnIndex="1" />
|
||||
</children>
|
||||
</GridPane>
|
||||
<BorderPane>
|
||||
<left>
|
||||
<Label text="%tabSplMrg_Lbl_SaveToLocation" BorderPane.alignment="CENTER" />
|
||||
</left>
|
||||
<center>
|
||||
<Label fx:id="saveToLocationLbl" BorderPane.alignment="CENTER_LEFT" />
|
||||
</center>
|
||||
<right>
|
||||
<Button mnemonicParsing="false" onAction="#bntSelectSaveTo" styleClass="buttonSelect" BorderPane.alignment="CENTER">
|
||||
<graphic>
|
||||
<SVGPath content="M3,4C1.89,4 1,4.89 1,6V18A2,2 0 0,0 3,20H11V18.11L21,8.11V8C21,6.89 20.1,6 19,6H11L9,4H3M21.04,11.13C20.9,11.13 20.76,11.19 20.65,11.3L19.65,12.3L21.7,14.35L22.7,13.35C22.92,13.14 22.92,12.79 22.7,12.58L21.42,11.3C21.31,11.19 21.18,11.13 21.04,11.13M19.07,12.88L13,18.94V21H15.06L21.12,14.93L19.07,12.88Z" fill="#289de8" />
|
||||
</graphic>
|
||||
</Button>
|
||||
</right>
|
||||
<VBox.margin>
|
||||
<Insets left="15.0" right="15.0" />
|
||||
</VBox.margin>
|
||||
</BorderPane>
|
||||
<Pane VBox.vgrow="ALWAYS" />
|
||||
<HBox alignment="CENTER">
|
||||
<children>
|
||||
<Label fx:id="statusLbl" alignment="CENTER" />
|
||||
</children>
|
||||
</HBox>
|
||||
<Pane />
|
||||
<HBox alignment="CENTER">
|
||||
<children>
|
||||
<Button fx:id="injectPldBtn" contentDisplay="TOP" minWidth="100.0" mnemonicParsing="false" styleClass="buttonUp" text="%tabNXDT_Btn_Start" />
|
||||
</children>
|
||||
</HBox>
|
||||
<padding>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</padding>
|
||||
</VBox>
|
|
@ -62,3 +62,4 @@ done_txt=Done!
|
|||
failure_txt=Failed
|
||||
btn_Select=Select
|
||||
btn_InjectPayloader=Inject payload
|
||||
tabNXDT_Btn_Start=Start!
|
||||
|
|
|
@ -62,4 +62,5 @@ done_txt=\u0413\u043E\u0442\u043E\u0432\u043E!
|
|||
failure_txt=\u041D\u0435\u0443\u0434\u0430\u0447\u0430
|
||||
btn_Select=\u0412\u044B\u0431\u0440\u0430\u0442\u044C
|
||||
btn_InjectPayloader=\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C payload
|
||||
tabNXDT_Btn_Start=\u0421\u0442\u0430\u0440\u0442!
|
||||
|
||||
|
|
|
@ -62,3 +62,4 @@ done_txt=\u0413\u043E\u0442\u043E\u0432\u043E!
|
|||
failure_txt=\u041D\u0435\u0432\u0434\u0430\u0447\u0430
|
||||
btn_Select=\u0412\u0438\u0431\u0440\u0430\u0442\u0438
|
||||
btn_InjectPayloader=\u0417\u0430\u0432\u0430\u043D\u0442\u0430\u0436\u0438\u0442\u0438 payload
|
||||
tabNXDT_Btn_Start=\u0421\u0442\u0430\u0440\u0442!
|
|
@ -373,6 +373,12 @@
|
|||
-fx-min-height: 24;
|
||||
-fx-min-width: 36;
|
||||
}
|
||||
.regionDump{
|
||||
-fx-shape: "M 4.0078125 0 C 1.5078125 0 0 1.4882812 0 3.984375 L 0 15.988281 C 0 18.417969 1.4927148 20 4.0078125 20 L 6.5 20 L 6.5 0 L 4.0078125 0 z M 23.5 0 L 23.5 20 C 24.504057 19.999294 25.159942 20 25.992188 20 C 28.414062 20 30 18.496094 30 15.996094 L 30 3.9765625 C 30 1.5195311 28.508726 0 26.003906 0 L 23.5 0 z M 11.990234 2.8886719 L 11.990234 9.9003906 L 6.9902344 9.9003906 L 14.990234 20 L 22.990234 9.9003906 L 17.990234 9.9003906 C 17.990234 8.2387016 17.9999 3.6538029 18 2.8886719 L 11.990234 2.8886719 z M 3.1015625 2.9570312 C 4.1485235 2.9562481 4.9977514 3.8046013 4.9980469 4.8515625 C 4.998831 5.8992865 4.1492865 6.7488309 3.1015625 6.7480469 C 2.0546013 6.7477509 1.2062483 5.8985235 1.2070312 4.8515625 C 1.2073268 3.8053642 2.0553642 2.9573267 3.1015625 2.9570312 z M 26.865234 11.148438 C 27.912958 11.147652 28.762503 11.997198 28.761719 13.044922 C 28.761423 14.091883 27.912195 14.940236 26.865234 14.939453 C 25.819036 14.939158 24.970999 14.09112 24.970703 13.044922 C 24.96992 11.997961 25.818273 11.148733 26.865234 11.148438 z ";
|
||||
-fx-background-color: #71e016;
|
||||
-fx-min-height: 24;
|
||||
-fx-min-width: 36;
|
||||
}
|
||||
.regionStop{
|
||||
-fx-shape: "M12,2C17.53,2 22,6.47 22,12C22,17.53 17.53,22 12,22C6.47,22 2,17.53 2,12C2,6.47 6.47,2 12,2M15.59,7L12,10.59L8.41,7L7,8.41L10.59,12L7,15.59L8.41,17L12,13.41L15.59,17L17,15.59L13.41,12L17,8.41L15.59,7Z";
|
||||
-fx-background-color: #fb582c;
|
||||
|
@ -394,6 +400,9 @@
|
|||
-size: 17.5;
|
||||
-fx-min-width: 20;
|
||||
}
|
||||
.nxdt.label .text {
|
||||
-fx-fill: #cb0010;
|
||||
}
|
||||
//
|
||||
//.lineGradient {
|
||||
// -fx-background-color: linear-gradient(from 41px 34px to 50px 50px, reflect, #00c8fc 30%, transparent 45%);
|
||||
|
|
|
@ -291,7 +291,12 @@
|
|||
-fx-min-height: 24;
|
||||
-fx-min-width: 36;
|
||||
}
|
||||
|
||||
.regionDump{
|
||||
-fx-shape: "M 4.0078125 0 C 1.5078125 0 0 1.4882812 0 3.984375 L 0 15.988281 C 0 18.417969 1.4927148 20 4.0078125 20 L 6.5 20 L 6.5 0 L 4.0078125 0 z M 23.5 0 L 23.5 20 C 24.504057 19.999294 25.159942 20 25.992188 20 C 28.414062 20 30 18.496094 30 15.996094 L 30 3.9765625 C 30 1.5195311 28.508726 0 26.003906 0 L 23.5 0 z M 11.990234 2.8886719 L 11.990234 9.9003906 L 6.9902344 9.9003906 L 14.990234 20 L 22.990234 9.9003906 L 17.990234 9.9003906 C 17.990234 8.2387016 17.9999 3.6538029 18 2.8886719 L 11.990234 2.8886719 z M 3.1015625 2.9570312 C 4.1485235 2.9562481 4.9977514 3.8046013 4.9980469 4.8515625 C 4.998831 5.8992865 4.1492865 6.7488309 3.1015625 6.7480469 C 2.0546013 6.7477509 1.2062483 5.8985235 1.2070312 4.8515625 C 1.2073268 3.8053642 2.0553642 2.9573267 3.1015625 2.9570312 z M 26.865234 11.148438 C 27.912958 11.147652 28.762503 11.997198 28.761719 13.044922 C 28.761423 14.091883 27.912195 14.940236 26.865234 14.939453 C 25.819036 14.939158 24.970999 14.09112 24.970703 13.044922 C 24.96992 11.997961 25.818273 11.148733 26.865234 11.148438 z ";
|
||||
-fx-background-color: #71e016;
|
||||
-fx-min-height: 24;
|
||||
-fx-min-width: 36;
|
||||
}
|
||||
.regionStop{
|
||||
-fx-shape: "M12,2C17.53,2 22,6.47 22,12C22,17.53 17.53,22 12,22C6.47,22 2,17.53 2,12C2,6.47 6.47,2 12,2M15.59,7L12,10.59L8.41,7L7,8.41L10.59,12L7,15.59L8.41,17L12,13.41L15.59,17L17,15.59L13.41,12L17,8.41L15.59,7Z";
|
||||
-fx-background-color: #fb582c;
|
||||
|
@ -313,3 +318,6 @@
|
|||
-size: 17.5;
|
||||
-fx-min-width: 20;
|
||||
}
|
||||
.nxdt.label .text {
|
||||
-fx-fill: #9d010e;
|
||||
}
|
BIN
src/main/resources/res/nxdt_icon.jpg
Normal file
BIN
src/main/resources/res/nxdt_icon.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
Loading…
Reference in a new issue