Some bug fixes

This commit is contained in:
Dmitry Isaenko 2020-05-10 19:33:46 +03:00
parent fa8e07169b
commit 6d4bed20a9
4 changed files with 29 additions and 19 deletions

View file

@ -52,7 +52,11 @@ public class NxdtController implements Initializable {
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
this.rb = resourceBundle; this.rb = resourceBundle;
saveToLocationLbl.setText(AppPreferences.getInstance().getNXDTSaveToLocation()); File saveToValidator = new File(AppPreferences.getInstance().getNXDTSaveToLocation());
if (saveToValidator.exists())
saveToLocationLbl.setText(saveToValidator.getAbsolutePath());
else
saveToLocationLbl.setText(System.getProperty("user.home"));
btnDumpStopImage = new Region(); btnDumpStopImage = new Region();
btnDumpStopImage.getStyleClass().add("regionDump"); btnDumpStopImage.getStyleClass().add("regionDump");

View file

@ -26,6 +26,8 @@ import javafx.scene.image.Image;
import javafx.stage.Stage; import javafx.stage.Stage;
import nsusbloader.Controllers.NSLMainController; import nsusbloader.Controllers.NSLMainController;
import java.io.File;
import java.nio.file.Paths;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;

View file

@ -41,7 +41,7 @@ public class RainbowHexDump {
System.out.println(">"+ANSI_RED+byteArray.length+ANSI_RESET); System.out.println(">"+ANSI_RED+byteArray.length+ANSI_RESET);
for (byte b: byteArray) for (byte b: byteArray)
System.out.print(String.format("%02x ", b)); System.out.print(String.format("%02x ", b));
//System.out.println(); System.out.println();
System.out.print("\t\t\t" System.out.print("\t\t\t"
+ new String(byteArray, StandardCharsets.UTF_8) + new String(byteArray, StandardCharsets.UTF_8)
+ "\n"); + "\n");
@ -54,8 +54,7 @@ public class RainbowHexDump {
for (byte b: byteArray) for (byte b: byteArray)
System.out.print(String.format("%02x ", b)); System.out.print(String.format("%02x ", b));
System.out.println(); System.out.println();
System.out.print("\t\t\t" System.out.print(new String(byteArray, StandardCharsets.UTF_8)
+ new String(byteArray, StandardCharsets.UTF_8)
+ "\n"); + "\n");
} }
@ -66,8 +65,7 @@ public class RainbowHexDump {
System.out.println(">"+ANSI_RED+byteArray.length+ANSI_RESET); System.out.println(">"+ANSI_RED+byteArray.length+ANSI_RESET);
for (byte b: byteArray) for (byte b: byteArray)
System.out.print(String.format("%02x ", b)); System.out.print(String.format("%02x ", b));
System.out.print("\t\t\t" System.out.print(new String(byteArray, StandardCharsets.UTF_16LE)
+ new String(byteArray, StandardCharsets.UTF_16LE)
+ "\n"); + "\n");
} }
} }

View file

@ -31,6 +31,7 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
class NxdtUsbAbi1 { class NxdtUsbAbi1 {
@ -104,7 +105,7 @@ class NxdtUsbAbi1 {
while (true){ while (true){
directive = readUsbDirective(); directive = readUsbDirective();
RainbowHexDump.hexDumpUTF8ForWin(directive); RainbowHexDump.hexDumpUTF8(directive);
if (isInvalidDirective(directive)) if (isInvalidDirective(directive))
continue; continue;
@ -132,7 +133,7 @@ class NxdtUsbAbi1 {
} }
catch (Exception e){ catch (Exception e){
e.printStackTrace(); e.printStackTrace();
logPrinter.print(e.getCause()+" "+e.getMessage(), EMsgType.INFO); logPrinter.print(e.getMessage(), EMsgType.INFO);
logPrinter.print("Terminating now", EMsgType.FAIL); logPrinter.print("Terminating now", EMsgType.FAIL);
} }
}; };
@ -145,17 +146,24 @@ class NxdtUsbAbi1 {
} }
if (message.length < 0x10){ if (message.length < 0x10){
writeUsb(USBSTATUS_MALFORMED_REQUEST); writeUsb(USBSTATUS_MALFORMED_REQUEST);
logPrinter.print("Invalid directive size. "+message.length+" bytes received.", EMsgType.FAIL); logPrinter.print("Directive is too small to be a command. Only "+message.length+" bytes received.", EMsgType.FAIL);
return true;
}
int payloadSize = getLEint(message, 0x8);
if (payloadSize + 0x10 != message.length){
writeUsb(USBSTATUS_MALFORMED_REQUEST);
logPrinter.print("Invalid directive size. "+message.length+" bytes received while "+payloadSize+" expected.", EMsgType.FAIL);
return true; return true;
} }
return false; return false;
} }
private void performHandshake(byte[] message) throws Exception{ private void performHandshake(byte[] message) throws Exception{
final byte versionMajor = message[10]; final byte versionMajor = message[0x10];
final byte versionMinor = message[11]; final byte versionMinor = message[0x11];
final byte versionMicro = message[12]; final byte versionMicro = message[0x12];
final byte versionABI = message[13]; final byte versionABI = message[0x13];
logPrinter.print("nxdumptool v"+versionMajor+"."+versionMinor+"."+versionMicro+" ABI v"+versionABI, EMsgType.INFO); logPrinter.print("nxdumptool v"+versionMajor+"."+versionMinor+"."+versionMicro+" ABI v"+versionABI, EMsgType.INFO);
@ -185,7 +193,6 @@ class NxdtUsbAbi1 {
filename = saveToPath + filename; filename = saveToPath + filename;
File fileToDump = new File(filename); File fileToDump = new File(filename);
// Check if enough space // Check if enough space
if (fileToDump.getParentFile().getFreeSpace() <= fileSize){ if (fileToDump.getParentFile().getFreeSpace() <= fileSize){
writeUsb(USBSTATUS_HOSTIOERROR); writeUsb(USBSTATUS_HOSTIOERROR);
@ -193,7 +200,7 @@ class NxdtUsbAbi1 {
return; return;
} }
// Check if FS is NOT read-only // Check if FS is NOT read-only
if (! fileToDump.canWrite()){ if (! (fileToDump.canWrite() || fileToDump.createNewFile()) ){
writeUsb(USBSTATUS_HOSTIOERROR); writeUsb(USBSTATUS_HOSTIOERROR);
logPrinter.print("Unable to write into selected volume: "+fileToDump.getAbsolutePath(), EMsgType.FAIL); logPrinter.print("Unable to write into selected volume: "+fileToDump.getAbsolutePath(), EMsgType.FAIL);
return; return;
@ -234,7 +241,7 @@ class NxdtUsbAbi1 {
} }
private void dumpFile(File file, long size) throws Exception{ private void dumpFile(File file, long size) throws Exception{
RandomAccessFile raf = new RandomAccessFile(file, "rw"); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, false));
byte[] readBuffer; byte[] readBuffer;
long received = 0; long received = 0;
@ -242,7 +249,7 @@ class NxdtUsbAbi1 {
while (received < size){ while (received < size){
readBuffer = readUsbFile(); readBuffer = readUsbFile();
raf.write(readBuffer); bos.write(readBuffer);
bufferSize = readBuffer.length; bufferSize = readBuffer.length;
received += bufferSize; received += bufferSize;
@ -250,10 +257,9 @@ class NxdtUsbAbi1 {
} }
logPrinter.updateProgress(1.0); logPrinter.updateProgress(1.0);
raf.close(); bos.close();
} }
/** /**
* Sending any byte array to USB device * Sending any byte array to USB device
* @return 'false' if no issues * @return 'false' if no issues