Compare commits

..

No commits in common. "272702f0431fb92bde6af84eb413fabfe682e1d7" and "d0131f26b49ba01d9c8624a1a7dc0a49bfce2b2a" have entirely different histories.

40 changed files with 382 additions and 1032 deletions

View file

@ -1,33 +0,0 @@
---
name: Bug report
about: Report a defect
title: ''
labels: ''
assignees: developersu
---
**Describe the bug (mandatory)**
A clear and concise description of what the bug is.
**Information about environment (mandatory):**
- OS: [e.g. Windows 7 x64]
- Java version [run 'java -version']
**Steps to reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots and/or information from application log**
If applicable, add screenshots to help explain your problem.
**Did you see this issue in previous versions?**
Yes / No / Don't know
**Additional context**
Add any other context about the problem here

View file

@ -1,22 +1,18 @@
/* /* NS-USBloader - native libraries for 'special purposes'
Copyright 2019-2020 Dmitry Isaenko * Copyright (C) 2020 Dmitry Isaenko
*
This file is part of NS-USBloader. * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
NS-USBloader is free software: you can redistribute it and/or modify * the Free Software Foundation, either version 3 of the License, or
it under the terms of the GNU General Public License as published by * (at your option) any later version.
the Free Software Foundation, either version 3 of the License, or *
(at your option) any later version. * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
NS-USBloader is distributed in the hope that it will be useful, * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
but WITHOUT ANY WARRANTY; without even the implied warranty of * GNU General Public License for more details.
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 this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
--
Native libraries for 'special purposes'
*/ */
#include <stdlib.h> #include <stdlib.h>

View file

@ -23,7 +23,7 @@ Sometimes I add new posts about this project [on my home page](https://developer
#### License #### License
[GNU General Public License version 3]((https://github.com/developersu/ns-usbloader/blob/master/LICENSE)), or (at your option) any later version. [GNU General Public License v3](https://github.com/developersu/ns-usbloader/blob/master/LICENSE)
#### Used libraries & resources #### Used libraries & resources
* [OpenJFX](https://wiki.openjdk.java.net/display/OpenJFX/Main) * [OpenJFX](https://wiki.openjdk.java.net/display/OpenJFX/Main)

View file

@ -8,7 +8,7 @@
<name>NS-USBloader</name> <name>NS-USBloader</name>
<artifactId>ns-usbloader</artifactId> <artifactId>ns-usbloader</artifactId>
<version>2.2-SNAPSHOT</version> <version>2.1-SNAPSHOT</version>
<url>https://github.com/developersu/ns-usbloader/</url> <url>https://github.com/developersu/ns-usbloader/</url>
<description> <description>

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader;
import java.util.Locale; import java.util.Locale;

View file

@ -1,21 +1,3 @@
/*
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.COM.Helpers; package nsusbloader.COM.Helpers;
import java.io.*; import java.io.*;

View file

@ -1,21 +1,3 @@
/*
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.COM.NET; package nsusbloader.COM.NET;
import javafx.concurrent.Task; import javafx.concurrent.Task;

View file

@ -1,21 +1,3 @@
/*
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.COM.NET; package nsusbloader.COM.NET;
import nsusbloader.NSLMain; import nsusbloader.NSLMain;

View file

@ -1,21 +1,3 @@
/*
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.COM.USB; package nsusbloader.COM.USB;
import javafx.application.Platform; import javafx.application.Platform;

View file

@ -1,21 +1,3 @@
/*
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.COM.USB; package nsusbloader.COM.USB;
import javafx.concurrent.Task; import javafx.concurrent.Task;

View file

@ -1,21 +1,3 @@
/*
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.COM.USB; package nsusbloader.COM.USB;
import javafx.application.Platform; import javafx.application.Platform;

View file

@ -1,21 +1,3 @@
/*
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.COM.USB.PFS; package nsusbloader.COM.USB.PFS;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;

View file

@ -1,21 +1,3 @@
/*
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.COM.USB.PFS; package nsusbloader.COM.USB.PFS;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.LogPrinter;

View file

@ -1,21 +1,3 @@
/*
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.COM.USB; package nsusbloader.COM.USB;
import javafx.concurrent.Task; import javafx.concurrent.Task;
@ -40,19 +22,12 @@ import java.util.LinkedHashMap;
class TinFoil extends TransferModule { class TinFoil extends TransferModule {
// "TUL0".getBytes(StandardCharsets.US_ASCII) // "TUL0".getBytes(StandardCharsets.US_ASCII)
private static final byte[] TUL0 = new byte[]{(byte) 0x54, (byte) 0x55, (byte) 0x4c, (byte) 0x30}; private static final byte[] TUL0 = new byte[]{(byte) 0x54, (byte) 0x55, (byte) 0x4c, (byte) 0x30};
private static final byte[] MAGIC = new byte[]{(byte) 0x54, (byte) 0x55, (byte) 0x43, (byte) 0x30}; // aka 'TUC0' ASCII
private static final byte CMD_EXIT = 0x00;
private static final byte CMD_FILE_RANGE_DEFAULT = 0x01;
private static final byte CMD_FILE_RANGE_ALTERNATIVE = 0x02;
/* byte[] magic = new byte[4];
ByteBuffer bb = StandardCharsets.UTF_8.encode("TUC0").rewind().get(magic); // Let's rephrase this 'string' */
TinFoil(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, LogPrinter logPrinter){ TinFoil(DeviceHandle handler, LinkedHashMap<String, File> nspMap, Task<Void> task, LogPrinter logPrinter){
super(handler, nspMap, task, logPrinter); super(handler, nspMap, task, logPrinter);
logPrinter.print("============= Tinfoil =============", EMsgType.INFO); logPrinter.print("============= TinFoil =============", EMsgType.INFO);
if (! sendListOfFiles()) if (!sendListOfNSP())
return; return;
if (proceedCommands()) // REPORT SUCCESS if (proceedCommands()) // REPORT SUCCESS
@ -61,245 +36,266 @@ class TinFoil extends TransferModule {
/** /**
* Send what NSP will be transferred * Send what NSP will be transferred
* */ * */
private boolean sendListOfFiles(){ private boolean sendListOfNSP(){
final String fileNamesListToSend = getFileNamesToSend(); //Collect file names
StringBuilder nspListNamesBuilder = new StringBuilder(); // Add every title to one stringBuilder
for(String nspFileName: nspMap.keySet()) {
nspListNamesBuilder.append(nspFileName); // And here we come with java string default encoding (UTF-16)
nspListNamesBuilder.append('\n');
}
byte[] nspListNames = getFileNamesToSendAsBytes(fileNamesListToSend); byte[] nspListNames = nspListNamesBuilder.toString().getBytes(StandardCharsets.UTF_8);
byte[] nspListNamesSize = getFileNamesLengthToSendAsBytes(nspListNames); ByteBuffer byteBuffer = ByteBuffer.allocate(Integer.BYTES).order(ByteOrder.LITTLE_ENDIAN); // integer = 4 bytes; BTW Java is stored in big-endian format
byte[] padding = new byte[8]; byteBuffer.putInt(nspListNames.length); // This way we obtain length in int converted to byte array in correct Big-endian order. Trust me.
byte[] nspListSize = byteBuffer.array();
logPrinter.print("TF Send list of files:", EMsgType.INFO);
// Proceed "TUL0"
if (writeUsb(TUL0)) { if (writeUsb(TUL0)) {
logPrinter.print("TF Send list of files: handshake [1/4]", EMsgType.FAIL); logPrinter.print(" handshake [1/4]", EMsgType.FAIL);
return false; return false;
} }
logPrinter.print(" handshake [1/4]", EMsgType.PASS);
if (writeUsb(nspListNamesSize)) { // size of the list we can transfer // Sending NSP list
logPrinter.print("TF Send list of files: list length [2/4]", EMsgType.FAIL); if (writeUsb(nspListSize)) { // size of the list we're going to transfer goes...
logPrinter.print(" list length [2/4]", EMsgType.FAIL);
return false; return false;
} }
logPrinter.print(" list length [2/4]", EMsgType.PASS);
if (writeUsb(padding)) { if (writeUsb(new byte[8])) { // 8 zero bytes goes...
logPrinter.print("TF Send list of files: padding [3/4]", EMsgType.FAIL); logPrinter.print(" padding [3/4]", EMsgType.FAIL);
return false; return false;
} }
logPrinter.print(" padding [3/4]", EMsgType.PASS);
if (writeUsb(nspListNames)) { if (writeUsb(nspListNames)) { // list of the names goes...
logPrinter.print("TF Send list of files: list itself [4/4]", EMsgType.FAIL); logPrinter.print(" list itself [4/4]", EMsgType.FAIL);
return false; return false;
} }
logPrinter.print("TF Send list of files complete.", EMsgType.PASS); logPrinter.print(" list itself [4/4]", EMsgType.PASS);
return true; return true;
} }
private String getFileNamesToSend(){
StringBuilder fileNamesListBuilder = new StringBuilder();
for(String nspFileName: nspMap.keySet()) {
fileNamesListBuilder.append(nspFileName); // And here we come with java string default encoding (UTF-16)
fileNamesListBuilder.append('\n');
}
return fileNamesListBuilder.toString();
}
private byte[] getFileNamesToSendAsBytes(String fileNamesListToSend){
return fileNamesListToSend.getBytes(StandardCharsets.UTF_8);
}
private byte[] getFileNamesLengthToSendAsBytes(byte[] fileNamesListToSendAsBytes){
ByteBuffer byteBuffer = ByteBuffer.allocate(Integer.BYTES).order(ByteOrder.LITTLE_ENDIAN); // integer = 4 bytes; BTW Java is stored in big-endian format
byteBuffer.putInt(fileNamesListToSendAsBytes.length); // This way we obtain length in int converted to byte array in correct Big-endian order. Trust me.
return byteBuffer.array();
}
/** /**
* After we sent commands to NS, this chain starts * After we sent commands to NS, this chain starts
* */ * */
private boolean proceedCommands(){ private boolean proceedCommands(){
logPrinter.print("TF Awaiting for NS commands.", EMsgType.INFO); logPrinter.print("TF Awaiting for NS commands.", EMsgType.INFO);
try{
byte[] deviceReply;
byte command;
while (true){ /* byte[] magic = new byte[4];
deviceReply = readUsb(); ByteBuffer bb = StandardCharsets.UTF_8.encode("TUC0").rewind().get(magic); // Let's rephrase this 'string'
if (! isReplyValid(deviceReply)) */
final byte[] magic = new byte[]{(byte) 0x54, (byte) 0x55, (byte) 0x43, (byte) 0x30}; // eq. 'TUC0' @ UTF-8 (actually ASCII lol, u know what I mean)
byte[] receivedArray;
while (true){ // Check if user interrupted process.
receivedArray = readUsb();
if (receivedArray == null) // catches error
return false;
if (!Arrays.equals(Arrays.copyOfRange(receivedArray, 0,4), magic)) // Bytes from 0 to 3 should contain 'magic' TUC0, so must be verified like this
continue; continue;
command = getCommandFromReply(deviceReply);
switch (command){ // 8th to 12th(explicits) bytes in returned data stands for command ID as unsigned integer (Little-endian). Actually, we have to compare arrays here, but in real world it can't be greater then 0/1/2, thus:
case CMD_EXIT: // BTW also protocol specifies 4th byte to be 0x00 kinda indicating that that this command is valid. But, as you may see, never happens other situation when it's not = 0.
logPrinter.print("TF Transfer complete.", EMsgType.PASS); if (receivedArray[8] == 0x00){ //0x00 - exit
return true; logPrinter.print("TF Received 'EXIT' command. Terminating.", EMsgType.PASS);
case CMD_FILE_RANGE_DEFAULT: return true; // All interaction with USB device should be ended (expected);
case CMD_FILE_RANGE_ALTERNATIVE: }
//logPrinter.print("TF Received 'FILE RANGE' command [0x0"+command+"].", EMsgType.PASS); else if ((receivedArray[8] == 0x01) || (receivedArray[8] == 0x02)){ //0x01 - file range; 0x02 unknown bug on backend side (dirty hack).
if (fileRangeCmd()) logPrinter.print("TF Received 'FILE RANGE' command [0x0"+receivedArray[8]+"].", EMsgType.PASS);
/*// We can get in this pocket a length of file name (+32). Why +32? I dunno man.. Do we need this? Definitely not. This app can live without it.
long receivedSize = ByteBuffer.wrap(Arrays.copyOfRange(receivedArray, 12,20)).order(ByteOrder.LITTLE_ENDIAN).getLong();
logsArea.appendText("[V] Received FILE_RANGE command. Size: "+Long.toUnsignedString(receivedSize)+"\n"); // this shit returns string that will be chosen next '+32'. And, BTW, can't be greater then 512
*/
if (! fileRangeCmd())
return false; // catches exception return false; // catches exception
} }
} }
} }
catch (Exception e){
logPrinter.print(e.getMessage(), EMsgType.INFO);
return false;
}
}
private boolean isReplyValid(byte[] reply){
return Arrays.equals(Arrays.copyOfRange(reply, 0,4), MAGIC);
}
private byte getCommandFromReply(byte[] reply){
return reply[8];
}
/** /**
* This is what returns requested file (files) * This is what returns requested file (files)
* Executes multiple times * Executes multiple times
* @return 'false' if everything is ok * @return 'true' if everything is ok
* 'true' is error/exception occurs * 'false' is error/exception occurs
* */ * */
private boolean fileRangeCmd(){ private boolean fileRangeCmd(){
try { byte[] receivedArray;
byte[] receivedArray = readUsb(); // Here we take information of what other side wants
if ((receivedArray = readUsb()) == null)
return false;
byte[] sizeAsBytes = Arrays.copyOfRange(receivedArray, 0,8); // range_offset of the requested file. In the beginning it will be 0x10.
long size = ByteBuffer.wrap(sizeAsBytes).order(ByteOrder.LITTLE_ENDIAN).getLong(); // could be unsigned long. This app won't support files greater then 8796093022208 Gb long receivedRangeSize = ByteBuffer.wrap(Arrays.copyOfRange(receivedArray, 0,8)).order(ByteOrder.LITTLE_ENDIAN).getLong(); // Note - it could be unsigned long. Unfortunately, this app won't support files greater then 8796093022208 Gb
long offset = ByteBuffer.wrap(Arrays.copyOfRange(receivedArray, 8,16)).order(ByteOrder.LITTLE_ENDIAN).getLong(); // could be unsigned long. This app doesn't support files greater then 8796093022208 Gb byte[] receivedRangeSizeRAW = Arrays.copyOfRange(receivedArray, 0,8); // used (only) when we use sendResponse().
long receivedRangeOffset = ByteBuffer.wrap(Arrays.copyOfRange(receivedArray, 8,16)).order(ByteOrder.LITTLE_ENDIAN).getLong(); // Note - it could be unsigned long. Unfortunately, this app won't support files greater then 8796093022208 Gb
/* Below, it's REAL NSP file name length that we sent before among others (WITHOUT +32 byes). It can't be greater then... see what is written in the beginning of this code.
We don't need this since in next pocket we'll get name itself UTF-8 encoded. Could be used to double-checks or something like that.
long receivedNspNameLen = ByteBuffer.wrap(Arrays.copyOfRange(receivedArray, 16,24)).order(ByteOrder.LITTLE_ENDIAN).getLong(); */
// Requesting UTF-8 file name required: // Requesting UTF-8 file name required:
receivedArray = readUsb(); if ((receivedArray = readUsb()) == null)
return false;
String nspFileName = new String(receivedArray, StandardCharsets.UTF_8); String receivedRequestedNSP = new String(receivedArray, StandardCharsets.UTF_8);
logPrinter.print(String.format("TF Reply for: %s" +
logPrinter.print(String.format("TF Reply to: %s" +
"\n Offset: %-20d 0x%x" + "\n Offset: %-20d 0x%x" +
"\n Size: %-20d 0x%x", "\n Size: %-20d 0x%x",
nspFileName, receivedRequestedNSP,
offset, offset, receivedRangeOffset, receivedRangeOffset,
size, size), EMsgType.INFO); receivedRangeSize, receivedRangeSize), EMsgType.INFO);
File nspFile = nspMap.get(nspFileName); // Sending response header
boolean isSplitFile = nspFile.isDirectory(); if (! sendResponse(receivedRangeSizeRAW)) // Get receivedRangeSize in 'RAW' format exactly as it has been received to simplify the process.
return false;
// Sending response 'header' try {
if (sendMetaInfoForFile(sizeAsBytes)) // Get size in 'RAW' format exactly as it has been received to simplify the process. byte[] bufferCurrent; //= new byte[1048576]; // eq. Allocate 1mb
return true;
if (isSplitFile) long currentOffset = 0;
sendSplitFile(nspFile, size, offset); // 'End Offset' equal to receivedRangeSize.
else int readPice = 8388608; // = 8Mb
sendNormalFile(nspFile, size, offset);
} catch (IOException ioe){ //---------------! Split files start !---------------
logPrinter.print("TF IOException:\n "+ioe.getMessage(), EMsgType.FAIL); if (nspMap.get(receivedRequestedNSP).isDirectory()){
ioe.printStackTrace(); NSSplitReader nsSplitReader = new NSSplitReader(nspMap.get(receivedRequestedNSP), receivedRangeSize);
return true; if (nsSplitReader.seek(receivedRangeOffset) != receivedRangeOffset){
} catch (ArithmeticException ae){ logPrinter.print("TF Requested offset is out of file size. Nothing to transmit.", EMsgType.FAIL);
logPrinter.print("TF ArithmeticException (can't cast 'offset end' - 'offsets current' to 'integer'):" +
"\n "+ae.getMessage(), EMsgType.FAIL);
ae.printStackTrace();
return true;
} catch (NullPointerException npe){
logPrinter.print("TF NullPointerException (in some moment application didn't find something. Something important.):" +
"\n "+npe.getMessage(), EMsgType.FAIL);
npe.printStackTrace();
return true;
}
catch (Exception defe){
logPrinter.print(defe.getMessage(), EMsgType.FAIL);
return true;
}
return false; return false;
} }
void sendSplitFile(File nspFile, long size, long offset) throws IOException, NullPointerException, ArithmeticException { while (currentOffset < receivedRangeSize){
byte[] readBuffer; if ((currentOffset + readPice) >= receivedRangeSize )
long currentOffset = 0; readPice = Math.toIntExact(receivedRangeSize - currentOffset);
int chunk = 8388608; // = 8Mb; //System.out.println("CO: "+currentOffset+"\t\tEO: "+receivedRangeSize+"\t\tRP: "+readPice); // NOTE: DEBUG
// updating progress bar (if a lot of data requested) START BLOCK
//---Tell progress to UI---/
logPrinter.updateProgress((currentOffset+readPice)/(receivedRangeSize/100.0) / 100.0);
//------------------------/
bufferCurrent = new byte[readPice]; // TODO: not perfect moment, consider refactoring.
NSSplitReader nsSplitReader = new NSSplitReader(nspFile, size); if (nsSplitReader.read(bufferCurrent) != readPice) { // changed since @ v0.3.2
if (nsSplitReader.seek(offset) != offset) logPrinter.print("TF Reading from stream suddenly ended.", EMsgType.WARNING);
throw new IOException("TF Requested offset is out of file size. Nothing to transmit."); return false;
}
while (currentOffset < size){ //write to USB
if ((currentOffset + chunk) >= size ) if (writeUsb(bufferCurrent)) {
chunk = Math.toIntExact(size - currentOffset); logPrinter.print("TF Failure during file transfer.", EMsgType.FAIL);
//System.out.println("CO: "+currentOffset+"\t\tEO: "+size+"\t\tRP: "+chunk); // NOTE: DEBUG return false;
logPrinter.updateProgress((currentOffset + chunk) / (size / 100.0) / 100.0); }
currentOffset += readPice;
readBuffer = new byte[chunk]; // TODO: not perfect moment, consider refactoring.
if (nsSplitReader.read(readBuffer) != chunk)
throw new IOException("TF Reading from stream suddenly ended.");
if (writeUsb(readBuffer))
throw new IOException("TF Failure during file transfer.");
currentOffset += chunk;
} }
nsSplitReader.close(); nsSplitReader.close();
logPrinter.updateProgress(1.0);
} }
//---------------! Split files end !---------------
//---------------! Regular files start !---------------
else {
BufferedInputStream bufferedInStream = new BufferedInputStream(new FileInputStream(nspMap.get(receivedRequestedNSP))); // TODO: refactor?
void sendNormalFile(File nspFile, long size, long offset) throws IOException, NullPointerException, ArithmeticException { if (bufferedInStream.skip(receivedRangeOffset) != receivedRangeOffset) {
byte[] readBuffer; logPrinter.print("TF Requested offset is out of file size. Nothing to transmit.", EMsgType.FAIL);
long currentOffset = 0; return false;
int chunk = 8388608; }
/*
File dir = new File(System.getProperty("user.home")+File.separator+"DBG_"+receivedRequestedNSP); //todo: remove
dir.mkdirs(); //todo: remove
BufferedInputStream bufferedInStream = new BufferedInputStream(new FileInputStream(nspFile)); File chunkFile = new File(System.getProperty("user.home")+File.separator+"DBG_"+receivedRequestedNSP+File.separator+receivedRangeSize+"_"+receivedRangeOffset+".part"); //todo: remove
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(chunkFile)); //todo: remove
*/
while (currentOffset < receivedRangeSize) {
if ((currentOffset + readPice) >= receivedRangeSize)
readPice = Math.toIntExact(receivedRangeSize - currentOffset);
//System.out.println("CO: "+currentOffset+"\t\tEO: "+receivedRangeSize+"\t\tRP: "+readPice); // NOTE: DEBUG
//logPrinter.print(String.format("CO: %-20d EO: %-20d RP: %d\n", currentOffset, receivedRangeSize, readPice), EMsgType.NULL); // NOTE: better DEBUG
// updating progress bar (if a lot of data requested) START BLOCK
//---Tell progress to UI---/
logPrinter.updateProgress((currentOffset + readPice) / (receivedRangeSize / 100.0) / 100.0);
//------------------------/
bufferCurrent = new byte[readPice]; // TODO: not perfect moment, consider refactoring.
if (bufferedInStream.skip(offset) != offset) if (bufferedInStream.read(bufferCurrent) != readPice) { // changed since @ v0.3.2
throw new IOException("TF Requested offset is out of file size. Nothing to transmit."); logPrinter.print("TF Reading from stream suddenly ended.", EMsgType.WARNING);
return false;
}
//write to USB
//bos.write(bufferCurrent); //todo: remove
while (currentOffset < size) { if (writeUsb(bufferCurrent)) {
if ((currentOffset + chunk) >= size) logPrinter.print("TF Failure during file transfer.", EMsgType.FAIL);
chunk = Math.toIntExact(size - currentOffset); return false;
//System.out.println("CO: "+currentOffset+"\t\tEO: "+receivedRangeSize+"\t\tRP: "+chunk); // NOTE: DEBUG }
logPrinter.updateProgress((currentOffset + chunk) / (size / 100.0) / 100.0); currentOffset += readPice;
readBuffer = new byte[chunk];
if (bufferedInStream.read(readBuffer) != chunk)
throw new IOException("TF Reading from stream suddenly ended.");
if (writeUsb(readBuffer))
throw new IOException("TF Failure during file transfer.");
currentOffset += chunk;
} }
bufferedInStream.close(); bufferedInStream.close();
//bos.close(); //todo: remove
}
//---------------! Regular files end !---------------
//---Tell progress to UI---/
logPrinter.updateProgress(1.0); logPrinter.updateProgress(1.0);
} catch (FileNotFoundException fnfe){
logPrinter.print("TF FileNotFoundException:\n "+fnfe.getMessage(), EMsgType.FAIL);
fnfe.printStackTrace();
return false;
} catch (IOException ioe){
logPrinter.print("TF IOException:\n "+ioe.getMessage(), EMsgType.FAIL);
ioe.printStackTrace();
return false;
} catch (ArithmeticException ae){
logPrinter.print("TF ArithmeticException (can't cast 'offset end' - 'offsets current' to 'integer'):\n "+ae.getMessage(), EMsgType.FAIL);
ae.printStackTrace();
return false;
} catch (NullPointerException npe){
logPrinter.print("TF NullPointerException (in some moment application didn't find something. Something important.):\n "+npe.getMessage(), EMsgType.FAIL);
npe.printStackTrace();
return false;
}
return true;
} }
/** /**
* Send response header. * Send response header.
* @return false if everything OK * @return true if everything OK
* true if failed * false if failed
* */ * */
private boolean sendMetaInfoForFile(byte[] sizeAsBytes){ private boolean sendResponse(byte[] rangeSize){ // This method as separate function itself for application needed as a cookie in the middle of desert.
final byte[] standardReplyBytes = new byte[] { 0x54, 0x55, 0x43, 0x30, // 'TUC0' final byte[] standardReplyBytes = new byte[] { 0x54, 0x55, 0x43, 0x30, // 'TUC0'
0x01, 0x00, 0x00, 0x00, // CMD_TYPE_RESPONSE = 1 0x01, 0x00, 0x00, 0x00, // CMD_TYPE_RESPONSE = 1
0x01, 0x00, 0x00, 0x00 }; 0x01, 0x00, 0x00, 0x00 };
final byte[] twelveZeroBytes = new byte[12]; final byte[] twelveZeroBytes = new byte[12];
//logPrinter.print("TF Sending response", EMsgType.INFO);
if (writeUsb(standardReplyBytes)){ // Send integer value of '1' in Little-endian format. if (writeUsb(standardReplyBytes) // Send integer value of '1' in Little-endian format.
){
logPrinter.print("TF Sending response failed [1/3]", EMsgType.FAIL); logPrinter.print("TF Sending response failed [1/3]", EMsgType.FAIL);
return true; return false;
} }
if(writeUsb(sizeAsBytes)) { // Send EXACTLY what has been received if(writeUsb(rangeSize)) { // Send EXACTLY what has been received
logPrinter.print("TF Sending response failed [2/3]", EMsgType.FAIL); logPrinter.print("TF Sending response failed [2/3]", EMsgType.FAIL);
return true; return false;
} }
if(writeUsb(twelveZeroBytes)) { // kinda another one padding if(writeUsb(twelveZeroBytes)) { // kinda another one padding
logPrinter.print("TF Sending response failed [3/3]", EMsgType.FAIL); logPrinter.print("TF Sending response failed [3/3]", EMsgType.FAIL);
return true;
}
return false; return false;
} }
logPrinter.print("TF Sending response complete (3/3)", EMsgType.PASS);
return true;
}
/** /**
* Sending any byte array to USB device * Sending any byte array to USB device
* @return 'false' if no issues * @return 'false' if no issues
* 'true' if errors happened * 'true' if errors happened
* */ * */
private boolean writeUsb(byte[] message) { private boolean writeUsb(byte[] message){
ByteBuffer writeBuffer = ByteBuffer.allocateDirect(message.length); //writeBuffer.order() equals BIG_ENDIAN; ByteBuffer writeBuffer = ByteBuffer.allocateDirect(message.length); //writeBuffer.order() equals BIG_ENDIAN;
writeBuffer.put(message); // Don't do writeBuffer.rewind(); writeBuffer.put(message); // Don't do writeBuffer.rewind();
IntBuffer writeBufTransferred = IntBuffer.allocate(1); IntBuffer writeBufTransferred = IntBuffer.allocate(1);
@ -308,7 +304,7 @@ class TinFoil extends TransferModule {
while (! task.isCancelled()) { while (! task.isCancelled()) {
/* /*
if (varVar != 0) if (varVar != 0)
logPrinter.print("writeUsb() retry cnt: "+varVar, EMsgType.INFO); //NOTE: DEBUG logPrinter.print("writeUsb() retry cnt: "+varVar, EMsgType.INFO); //todo:remove
varVar++; varVar++;
*/ */
result = LibUsb.bulkTransfer(handlerNS, (byte) 0x01, writeBuffer, writeBufTransferred, 5050); // last one is TIMEOUT. 0 stands for unlimited. Endpoint OUT = 0x01 result = LibUsb.bulkTransfer(handlerNS, (byte) 0x01, writeBuffer, writeBufTransferred, 5050); // last one is TIMEOUT. 0 stands for unlimited. Endpoint OUT = 0x01
@ -340,7 +336,7 @@ class TinFoil extends TransferModule {
* @return byte array if data read successful * @return byte array if data read successful
* 'null' if read failed * 'null' if read failed
* */ * */
private byte[] readUsb() throws Exception{ private byte[] readUsb(){
ByteBuffer readBuffer = ByteBuffer.allocateDirect(512); ByteBuffer readBuffer = ByteBuffer.allocateDirect(512);
// We can limit it to 32 bytes, but there is a non-zero chance to got OVERFLOW from libusb. // We can limit it to 32 bytes, but there is a non-zero chance to got OVERFLOW from libusb.
IntBuffer readBufTransferred = IntBuffer.allocate(1); IntBuffer readBufTransferred = IntBuffer.allocate(1);
@ -357,11 +353,13 @@ class TinFoil extends TransferModule {
case LibUsb.ERROR_TIMEOUT: case LibUsb.ERROR_TIMEOUT:
continue; continue;
default: default:
throw new Exception("TF Data transfer issue [read]" + logPrinter.print("TF Data transfer issue [read]" +
"\n Returned: " + UsbErrorCodes.getErrCode(result)+ "\n Returned: " + UsbErrorCodes.getErrCode(result)+
"\n (execution stopped)"); "\n (execution stopped)", EMsgType.FAIL);
return null;
} }
} }
throw new InterruptedException("TF Execution interrupted"); logPrinter.print("TF Execution interrupted", EMsgType.INFO);
return null;
} }
} }

View file

@ -1,21 +1,3 @@
/*
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.COM.USB; package nsusbloader.COM.USB;
import javafx.concurrent.Task; import javafx.concurrent.Task;
@ -42,7 +24,7 @@ public abstract class TransferModule {
this.logPrinter = printer; this.logPrinter = printer;
// Validate split files to be sure that there is no crap // Validate split files to be sure that there is no crap
//logPrinter.print("TransferModule: Validating split files ...", EMsgType.INFO); // NOTE: Used for debug logPrinter.print("TransferModule: Validating split files ...", EMsgType.INFO);
Iterator<Map.Entry<String, File>> iterator = nspMap.entrySet().iterator(); Iterator<Map.Entry<String, File>> iterator = nspMap.entrySet().iterator();
while (iterator.hasNext()){ while (iterator.hasNext()){
File f = iterator.next().getValue(); File f = iterator.next().getValue();
@ -65,7 +47,7 @@ public abstract class TransferModule {
} // nice } // nice
} // stairway } // stairway
} // here =) } // here =)
//logPrinter.print("TransferModule: Validation complete.", EMsgType.INFO); // NOTE: Used for debug logPrinter.print("TransferModule: Validation complete.", EMsgType.INFO);
} }
public EFileStatus getStatus(){ return status; } public EFileStatus getStatus(){ return status; }

View file

@ -1,21 +1,3 @@
/*
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.COM.USB; package nsusbloader.COM.USB;
import javafx.concurrent.Task; import javafx.concurrent.Task;
@ -36,7 +18,17 @@ public class UsbCommunications extends Task<Void> {
private LinkedHashMap<String, File> nspMap; private LinkedHashMap<String, File> nspMap;
private String protocol; private String protocol;
private boolean nspFilterForGl; private boolean nspFilterForGl;
/*
Ok, here is a story. We will pass to NS only file names, not full path. => see nspMap where 'key' is a file name.
File name itself should not be greater then 512 bytes, but in real world it's limited by OS to something like 256 bytes.
For sure, there could be FS that supports more then 256 and even more then 512 bytes. So if user decides to set name greater then 512 bytes, everything will ruin.
There is no extra validations for this situation.
Why we poking around 512 bytes? Because it's the maximum size of byte-array that USB endpoind of NS could return. And in runtime it returns the filename.
Therefore, the file name shouldn't be greater then 512. If file name + path-to-file is greater then 512 bytes, we can handle it: sending only file name instead of full path.
Since this application let user an ability (theoretically) to choose same files in different folders, the latest selected file will be added to the list and handled correctly.
I have no idea why he/she will make a decision to do that. Just in case, we're good in this point.
*/
public UsbCommunications(List<File> nspList, String protocol, boolean filterNspFilesOnlyForGl){ public UsbCommunications(List<File> nspList, String protocol, boolean filterNspFilesOnlyForGl){
this.protocol = protocol; this.protocol = protocol;
this.nspFilterForGl = filterNspFilesOnlyForGl; this.nspFilterForGl = filterNspFilesOnlyForGl;
@ -48,9 +40,9 @@ public class UsbCommunications extends Task<Void> {
@Override @Override
protected Void call() { protected Void call() {
logPrinter.print("\tStart", EMsgType.INFO); logPrinter.print("\tStart chain", EMsgType.INFO);
UsbConnect usbConnect = UsbConnect.connectHomebrewMode(logPrinter); UsbConnect usbConnect = new UsbConnect(logPrinter, false);
if (! usbConnect.isConnected()){ if (! usbConnect.isConnected()){
close(EFileStatus.FAILED); close(EFileStatus.FAILED);
@ -88,7 +80,7 @@ public class UsbCommunications extends Task<Void> {
*/ */
private void close(EFileStatus status){ private void close(EFileStatus status){
logPrinter.update(nspMap, status); logPrinter.update(nspMap, status);
logPrinter.print("\tEnd", EMsgType.INFO); logPrinter.print("\tEnd chain", EMsgType.INFO);
logPrinter.close(); logPrinter.close();
} }

View file

@ -1,21 +1,3 @@
/*
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.COM.USB; package nsusbloader.COM.USB;
import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.ModelControllers.LogPrinter;
@ -23,17 +5,7 @@ import nsusbloader.NSLDataTypes.EMsgType;
import org.usb4java.*; import org.usb4java.*;
public class UsbConnect { public class UsbConnect {
private static final int DEFAULT_INTERFACE = 0; private int DEFAULT_INTERFACE = 0;
private static final int DEFAULT_HOMEBREW_CONFIGURATION = 1;
private static final short RCM_VID = 0x0955;
private static final short RCM_PID = 0x7321;
private static final short HOMEBREW_VID = 0x057E;
private static final short HOMEBREW_PID = 0x3000;
// private static final short TEST_VID = 0x1a86;
// private static final short TEST_PID = 0x7523;
private Context contextNS; private Context contextNS;
private DeviceHandle handlerNS; private DeviceHandle handlerNS;
@ -43,152 +15,134 @@ public class UsbConnect {
private boolean connected; // TODO: replace to 'connectionFailure' and invert requests everywhere private boolean connected; // TODO: replace to 'connectionFailure' and invert requests everywhere
private short VENDOR_ID; public UsbConnect(LogPrinter logPrinter, boolean initForRCM){
private short PRODUCT_ID;
private int returningValue;
private DeviceList deviceList;
public static UsbConnect connectRcmMode(LogPrinter logPrinter){
UsbConnect usbConnect = new UsbConnect(logPrinter);
usbConnect.VENDOR_ID = RCM_VID;
usbConnect.PRODUCT_ID = RCM_PID;
try{
usbConnect.createContextAndInitLibUSB();
usbConnect.getDeviceList();
usbConnect.findDevice();
usbConnect.openDevice();
usbConnect.freeDeviceList();
usbConnect.setAutoDetachKernelDriver();
//this.resetDevice();
usbConnect.claimInterface();
usbConnect.connected = true;
}
catch (Exception e){
logPrinter.print(e.getMessage(), EMsgType.FAIL);
usbConnect.close();
}
return usbConnect;
}
public static UsbConnect connectHomebrewMode(LogPrinter logPrinter){
UsbConnect usbConnect = new UsbConnect(logPrinter);
usbConnect.VENDOR_ID = HOMEBREW_VID;
usbConnect.PRODUCT_ID = HOMEBREW_PID;
try {
usbConnect.createContextAndInitLibUSB();
usbConnect.getDeviceList();
usbConnect.findDevice();
usbConnect.openDevice();
usbConnect.freeDeviceList();
usbConnect.setAutoDetachKernelDriver();
//this.resetDevice();
usbConnect.setConfiguration(DEFAULT_HOMEBREW_CONFIGURATION);
usbConnect.claimInterface();
usbConnect.connected = true;
}
catch (Exception e){
logPrinter.print(e.getMessage(), EMsgType.FAIL);
usbConnect.close();
}
return usbConnect;
}
private UsbConnect(){}
private UsbConnect(LogPrinter logPrinter){
this.logPrinter = logPrinter; this.logPrinter = logPrinter;
this.connected = false; this.connected = false;
};
private void createContextAndInitLibUSB() throws Exception{ short VENDOR_ID;
// Creating Context required by libusb. Optional? Consider removing. short PRODUCT_ID;
if (initForRCM){
// CORRECT NV:
VENDOR_ID = 0x0955;
PRODUCT_ID = 0x7321;
/* // QA:
VENDOR_ID = 0x1a86;
PRODUCT_ID = 0x7523;
*/
}
else {
VENDOR_ID = 0x057E;
PRODUCT_ID = 0x3000;
}
int result;
// Creating Context required by libusb. Optional. TODO: Consider removing.
contextNS = new Context(); contextNS = new Context();
result = LibUsb.init(contextNS);
returningValue = LibUsb.init(contextNS); if (result != LibUsb.SUCCESS) {
if (returningValue != LibUsb.SUCCESS) logPrinter.print("libusb initialization\n Returned: "+result, EMsgType.FAIL);
throw new Exception("libusb initialization\n Returned: "+UsbErrorCodes.getErrCode(returningValue)); close();
return;
} }
logPrinter.print("libusb initialization", EMsgType.PASS);
private void getDeviceList() throws Exception{ // Searching for NS in devices: obtain list of all devices
deviceList = new DeviceList(); DeviceList deviceList = new DeviceList();
returningValue = LibUsb.getDeviceList(contextNS, deviceList); result = LibUsb.getDeviceList(contextNS, deviceList);
if (returningValue < 0) if (result < 0) {
throw new Exception("Get device list\n Returned: "+UsbErrorCodes.getErrCode(returningValue)); logPrinter.print("Get device list\n Returned: "+result, EMsgType.FAIL);
close();
return;
} }
logPrinter.print("Get device list", EMsgType.PASS);
private void findDevice() throws Exception{
// Searching for NS in devices: looking for NS // Searching for NS in devices: looking for NS
DeviceDescriptor descriptor; DeviceDescriptor descriptor;
deviceNS = null;
for (Device device: deviceList){ for (Device device: deviceList){
descriptor = new DeviceDescriptor(); descriptor = new DeviceDescriptor(); // mmm.. leave it as is.
returningValue = LibUsb.getDeviceDescriptor(device, descriptor); result = LibUsb.getDeviceDescriptor(device, descriptor);
if (returningValue != LibUsb.SUCCESS){ if (result != LibUsb.SUCCESS){
this.freeDeviceList(); logPrinter.print("Read file descriptors for USB devices\n Returned: "+result, EMsgType.FAIL);
throw new Exception("Read file descriptors for USB devices\n Returned: "+UsbErrorCodes.getErrCode(returningValue)); LibUsb.freeDeviceList(deviceList, true);
close();
return;
} }
if ((descriptor.idVendor() == VENDOR_ID) && descriptor.idProduct() == PRODUCT_ID){ if ((descriptor.idVendor() == VENDOR_ID) && descriptor.idProduct() == PRODUCT_ID){
deviceNS = device; deviceNS = device;
logPrinter.print("Read file descriptors for USB devices", EMsgType.PASS);
break; break;
} }
} }
if (deviceNS == null) { // Free device list.
this.freeDeviceList(); if (deviceNS == null){
throw new Exception("NS not found in connected USB devices"); logPrinter.print("NS in connected USB devices not found", EMsgType.FAIL);
} close();
return;
} }
logPrinter.print("NS in connected USB devices found", EMsgType.PASS);
private void openDevice() throws Exception{
// Handle NS device // Handle NS device
handlerNS = new DeviceHandle(); handlerNS = new DeviceHandle();
returningValue = LibUsb.open(deviceNS, handlerNS); result = LibUsb.open(deviceNS, handlerNS);
if (result != LibUsb.SUCCESS) {
if (returningValue == LibUsb.SUCCESS) logPrinter.print("Open NS USB device\n Returned: "+UsbErrorCodes.getErrCode(result), EMsgType.FAIL);
return; if (result == LibUsb.ERROR_ACCESS)
logPrinter.print("Double check that you have administrator privileges (you're 'root') or check 'udev' rules set for this user (linux only)!\n\n" +
handlerNS = null; // Avoid issue on close(); String.format("Steps to set 'udev' rules:\n" +
if (returningValue == LibUsb.ERROR_ACCESS) { "root # vim /etc/udev/rules.d/99-NS"+(initForRCM?"RCM":"")+".rules\n" +
throw new Exception(String.format(
"Open NS USB device\n Returned: %s\n" +
"Double check that you have administrator privileges (you're 'root') or check 'udev' rules set for this user (linux only)!\n\n" +
"Steps to set 'udev' rules:\n" +
"root # vim /etc/udev/rules.d/99-NS" + ((RCM_VID == VENDOR_ID) ? "RCM" : "") + ".rules\n" +
"SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", GROUP=\"plugdev\"\n" + "SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", GROUP=\"plugdev\"\n" +
"root # udevadm control --reload-rules && udevadm trigger\n", UsbErrorCodes.getErrCode(returningValue), VENDOR_ID, PRODUCT_ID)); "root # udevadm control --reload-rules && udevadm trigger\n", VENDOR_ID, PRODUCT_ID)
, EMsgType.INFO);
// Let's make a bit dirty workaround since such shit happened
logPrinter.print("Requested context close", EMsgType.INFO);
LibUsb.exit(contextNS);
return; // And close
} }
else else
throw new Exception("Open NS USB device\n Returned: "+UsbErrorCodes.getErrCode(returningValue)); logPrinter.print("Open NS USB device", EMsgType.PASS);
}
private void freeDeviceList(){ logPrinter.print("Free device list", EMsgType.INFO);
LibUsb.freeDeviceList(deviceList, true); LibUsb.freeDeviceList(deviceList, true);
}
private void setAutoDetachKernelDriver(){
// Actually, there are no drivers in Linux kernel which uses this device.
returningValue = LibUsb.setAutoDetachKernelDriver(handlerNS, true);
if (returningValue != LibUsb.SUCCESS)
logPrinter.print("Skip kernel driver attach & detach ("+UsbErrorCodes.getErrCode(returningValue)+")", EMsgType.INFO);
}
// DO some stuff to connected NS
// Actually, there are not drivers in Linux kernel that are using this device..
if (LibUsb.setAutoDetachKernelDriver(handlerNS, true) == LibUsb.SUCCESS)
logPrinter.print("Handle kernel driver attach & detach", EMsgType.PASS);
else
logPrinter.print("Skip kernel driver attach & detach", EMsgType.INFO);
/* /*
private void resetDevice(){ // Reset device
result = LibUsb.resetDevice(handlerNS); result = LibUsb.resetDevice(handlerNS);
if (returningValue != LibUsb.SUCCESS) if (result == 0)
throw new Exception("Reset device\n Returned: "+UsbErrorCodes.getErrCode(returningValue)); logPrinter.print("Reset device", EMsgType.PASS);
else {
logPrinter.print("Reset device returned: " + result, EMsgType.FAIL);
updateAndClose();
return;
} }
*/ */
private void setConfiguration(int configuration) throws Exception{ if ( ! initForRCM){
returningValue = LibUsb.setConfiguration(handlerNS, configuration); // Set configuration (soft reset if needed)
if (returningValue != LibUsb.SUCCESS) result = LibUsb.setConfiguration(handlerNS, 1); // 1 - configuration all we need
throw new Exception("Set active configuration to device\n Returned: "+UsbErrorCodes.getErrCode(returningValue)); if (result != LibUsb.SUCCESS){
logPrinter.print("Set active configuration to device\n Returned: "+UsbErrorCodes.getErrCode(result), EMsgType.FAIL);
close();
return;
}
logPrinter.print("Set active configuration to device.", EMsgType.PASS);
} }
private void claimInterface() throws Exception{
// Claim interface // Claim interface
returningValue = LibUsb.claimInterface(handlerNS, DEFAULT_INTERFACE); result = LibUsb.claimInterface(handlerNS, DEFAULT_INTERFACE);
if (returningValue != LibUsb.SUCCESS) if (result != LibUsb.SUCCESS) {
throw new Exception("Claim interface\n Returned: "+UsbErrorCodes.getErrCode(returningValue)); logPrinter.print("Claim interface\n Returned: "+UsbErrorCodes.getErrCode(result), EMsgType.FAIL);
close();
return;
}
logPrinter.print("Claim interface", EMsgType.PASS);
this.connected = true;
} }
/** /**
@ -220,10 +174,11 @@ public class UsbConnect {
// Close handler in the end // Close handler in the end
if (handlerNS != null) { if (handlerNS != null) {
// Try to release interface // Try to release interface
returningValue = LibUsb.releaseInterface(handlerNS, DEFAULT_INTERFACE); int result = LibUsb.releaseInterface(handlerNS, DEFAULT_INTERFACE);
if (returningValue != LibUsb.SUCCESS) if (result != LibUsb.SUCCESS)
logPrinter.print("Release interface\n Returned: "+returningValue+" (sometimes it's not an issue)", EMsgType.WARNING); logPrinter.print("Release interface" +
"\n Returned: "+result+" (sometimes it's not an issue)", EMsgType.WARNING);
else else
logPrinter.print("Release interface", EMsgType.PASS); logPrinter.print("Release interface", EMsgType.PASS);

View file

@ -1,21 +1,3 @@
/*
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.COM.USB; package nsusbloader.COM.USB;
import org.usb4java.LibUsb; import org.usb4java.LibUsb;

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader.Controllers;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader.Controllers;
import javafx.application.HostServices; import javafx.application.HostServices;

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader.Controllers;
import nsusbloader.NSLDataTypes.EFileStatus; import nsusbloader.NSLDataTypes.EFileStatus;

View file

@ -1,21 +1,3 @@
/*
Copyright 2019-2020 Dmitry Isaenko, wolfposd
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; package nsusbloader.Controllers;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader.Controllers;
import javafx.concurrent.Task; import javafx.concurrent.Task;

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader.Controllers;
import javafx.application.HostServices; import javafx.application.HostServices;

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader.Controllers;
import javafx.concurrent.Task; import javafx.concurrent.Task;

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader;
/** /**

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader;
import nsusbloader.Controllers.NSLMainController; import nsusbloader.Controllers.NSLMainController;

View file

@ -1,21 +1,3 @@
/*
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.ModelControllers; package nsusbloader.ModelControllers;
import nsusbloader.NSLDataTypes.EFileStatus; import nsusbloader.NSLDataTypes.EFileStatus;

View file

@ -1,21 +1,3 @@
/*
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.ModelControllers; package nsusbloader.ModelControllers;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;

View file

@ -1,21 +1,3 @@
/*
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.ModelControllers; package nsusbloader.ModelControllers;
import javafx.concurrent.Task; import javafx.concurrent.Task;

View file

@ -1,21 +1,3 @@
/*
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.NSLDataTypes; package nsusbloader.NSLDataTypes;
public enum EFileStatus { public enum EFileStatus {

View file

@ -1,21 +1,3 @@
/*
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.NSLDataTypes; package nsusbloader.NSLDataTypes;
public enum EModule { public enum EModule {

View file

@ -1,21 +1,3 @@
/*
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.NSLDataTypes; package nsusbloader.NSLDataTypes;
public enum EMsgType { public enum EMsgType {

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader;
import javafx.application.Application; import javafx.application.Application;
@ -31,7 +13,7 @@ import java.util.ResourceBundle;
public class NSLMain extends Application { public class NSLMain extends Application {
public static final String appVersion = "v2.2"; public static final String appVersion = "v2.1";
@Override @Override
public void start(Stage primaryStage) throws Exception{ public void start(Stage primaryStage) throws Exception{

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -34,6 +16,7 @@ public class RainbowHexDump {
private static final String ANSI_CYAN = "\u001B[36m"; private static final String ANSI_CYAN = "\u001B[36m";
private static final String ANSI_WHITE = "\u001B[37m"; private static final String ANSI_WHITE = "\u001B[37m";
public static void hexDumpUTF8(byte[] byteArray){ public static void hexDumpUTF8(byte[] byteArray){
System.out.print(ANSI_BLUE); System.out.print(ANSI_BLUE);
for (int i=0; i < byteArray.length; i++) for (int i=0; i < byteArray.length; i++)

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader.Utilities;
import java.io.File; import java.io.File;

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader.Utilities;
public class RcmSmash { public class RcmSmash {

View file

@ -1,28 +1,12 @@
/*
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/>.
--
Implementation of the 'Fusée Gelée' RCM payload that is inspired by 'fusee-launcher' application by ktemkin.
Definitely uses ideas and even some code.
Check original project: https://github.com/reswitched/fusee-launcher
This code is not political. It could be used by anyone.
*/
package nsusbloader.Utilities; package nsusbloader.Utilities;
/*
* Implementation of the 'Fusée Gelée' RCM payload that is inspired by 'fusee-launcher' application by ktemkin.
* Definitely uses ideas and even some code.
* Check original project: https://github.com/reswitched/fusee-launcher
*
* This code is not political. It could be used by anyone.
* Find details in LICENSE file in the root directory of this project.
**/
import javafx.concurrent.Task; import javafx.concurrent.Task;
import nsusbloader.COM.USB.UsbConnect; import nsusbloader.COM.USB.UsbConnect;
@ -107,7 +91,7 @@ public class RcmTask extends Task<Boolean> {
// ================= // =================
// Bring up USB connection // Bring up USB connection
UsbConnect usbConnect = UsbConnect.connectRcmMode(logPrinter); UsbConnect usbConnect = new UsbConnect(logPrinter, true);
if (! usbConnect.isConnected()){ if (! usbConnect.isConnected()){
logPrinter.close(); logPrinter.close();
@ -163,8 +147,8 @@ public class RcmTask extends Task<Boolean> {
logPrinter.close(); logPrinter.close();
return false; return false;
} }
}
logPrinter.print(".:: Payload complete ::.", EMsgType.PASS); logPrinter.print(".:: Payload complete ::.", EMsgType.PASS);
}
usbConnect.close(); usbConnect.close();
logPrinter.close(); logPrinter.close();
@ -287,6 +271,39 @@ public class RcmTask extends Task<Boolean> {
boolean smashMacOS(){ boolean smashMacOS(){
ByteBuffer writeBuffer = ByteBuffer.allocateDirect(28672); ByteBuffer writeBuffer = ByteBuffer.allocateDirect(28672);
LibUsb.controlTransfer(handler, (byte) 0x82, LibUsb.REQUEST_GET_STATUS, (short) 0, (short) 0, writeBuffer, 1000); // Result doesn't matter. LibUsb.controlTransfer(handler, (byte) 0x82, LibUsb.REQUEST_GET_STATUS, (short) 0, (short) 0, writeBuffer, 1000); // Result doesn't matter.
logPrinter.print(".:: Payload complete ::.", EMsgType.PASS);
return false; return false;
} }
//*****************************************************************************************************************/
/*
private void writeTestFile(){
try {
File testFile = new File("/tmp/dmTests.bin");
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(testFile)
);
bos.write(fullPayload);
bos.close();
}
catch (Exception e){ e.printStackTrace(); }
// ------------------ TEST THIS p.2 ----------------------
writeUsbTest(fullPayload);
}
private boolean writeUsbTest(byte[] message){
for (int i=0; i < message.length / 0x1000 ;i++){
try {
File testFile = new File(String.format("/tmp/cnk_%02d.bin", i));
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(testFile)
);
bos.write(Arrays.copyOfRange(message, i*4096, (i+1)*4096));
bos.close();
}
catch (Exception e){ e.printStackTrace(); }
}
return false;
}
*/
} }

View file

@ -1,21 +1,3 @@
/*
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; package nsusbloader.Utilities;
import javafx.concurrent.Task; import javafx.concurrent.Task;