ns-usbloader icon indicating copy to clipboard operation
ns-usbloader copied to clipboard

Automatic payload inject

Open mfsoup opened this issue 5 years ago • 5 comments

Hey, any chance you could add an auto payload inject feature like the one in TecraRcmGUI and Hekado?

mfsoup avatar Feb 11 '20 07:02 mfsoup

Hi. Not sure about it. I don't think that I can even make an indication of NS connection as it's made in TecraRcmGUI (that nice green joycon click).

To do that I have to find a way to constantly check list of connected USB-devices and in case you NS connected in RCM mode send a payload (or indicate this event). Also this trick should not be (significantly) resources-consuming. Also it should be and safe and multiplatform solution.

I really like how it's made in TecraRcmGUI, but this application created for sending payloads and works only on Windows. I don't know how it's made in there (!), but even if (!) this app have a loop where checks the list of connected USB devices (of special devices class etc. since it's possible in win32 drivers API) and indicates connection, it's fine and it's cute and it looks great. In my case you may just want to install few NSPs and in the same time somewhere in background you have a thread that eats memory and running loop of checks 'is device with RCM connected?'. I don't like it to be honest.

Anyway, this is what I have for this moment. Maybe I find workaround or more elegant solution. In other hand it's always possible to take the code from this application and create another one :)

developersu avatar Feb 11 '20 13:02 developersu

Hi Do we need to install a driver if it's the first time someone use ? (like TegraRcmGui can do in settings to install)

deejay87 avatar Feb 11 '20 17:02 deejay87

Hi @ deejay87 Yes, you have to install driver (libusbk) using Zadig or using TegraRcmGui magic function. If you're on Windows.

developersu avatar Feb 11 '20 17:02 developersu

@mfsoup

Want to show you how to make it works on Linux systems, so maybe it'd be a good solution for you:

  1. Create folder to hold auto-payload script and hekate.bin (or any other payload, it's just an example): # mkdir /opt/own/autopayload

  2. Copy Hekate to this folder: cp /somewhere/you/already/have/hekate-some-ver.bin /opt/own/autopayload/hekate.bin

  3. Create auto-payload script:

# vim /opt/own/autopayload/pld.sh
#!/bin/sh
java -jar /opt/own/ns-usbloader-4.1.jar -r /opt/own/autopayload/hekate.bin > /var/log/ns-autopayload.log 2>&1
  1. Make executable # chmod +x /opt/own/autopayload/pld.sh

  2. Make sure that we're still good to go: Run # /opt/own/autopayload/pld.sh Check # cat /var/log/ns-autopayload.log Expected result:

I: Selected: /opt/own/autopayload/hekate.bin
I: =============== RCM ===============
P: Found your OS: Linux
F: NS not found in connected USB device
  1. Create udev rule:
# vim /etc/udev/rules.d/99-nspayload.rules 
SUBSYSTEM=="usb", ATTRS{idVendor}=="0955", ATTRS{idProduct}=="7321", ACTION=="add", RUN+="/opt/own/autopayload/pld.sh"
  1. Apply udev rule: # udevadm control --reload-rules && udevadm trigger

developersu avatar Jul 23 '20 23:07 developersu

A little update to this that could be interesting.

I've just played with udevadm monitor and used '>>' instead of '>' in script line java -jar /opt/own/ns-usbloader-4.1.jar -r /opt/own/autopayload/hekate.bin > /var/log/ns-autopayload.log 2>&1

So actually I see that this rule triggers 3 times. Once effectively and 2 times are not. In other words, next things happens:

# cat /var/log/ns-autopayload.log 
I: Selected: /opt/own/autopayload/hekate.bin
I: =============== RCM ===============
P: Found your OS: Linux
F: Unable to get device ID

         Nothing has been sent to NS. Execution stopped.

I: Selected: /opt/own/autopayload/hekate.bin
I: =============== RCM ===============
P: Found your OS: Linux
P: Found device with ID: 00 ... ... NEVER_SHARE_THIS ... ... 00 
P: Information sent to NS.
P: .:: Payload complete ::.
I: Selected: /opt/own/autopayload/hekate.bin
I: =============== RCM ===============
P: Found your OS: Linux
F: Unable to get device ID

         Nothing has been sent to NS. Execution stopped.

I think it's not a problem because there are no actions performs BEFORE application receives 'device ID': https://github.com/developersu/ns-usbloader/blob/a094d4fc9d0dddf9a3524b75742d1c6a620e0335/src/main/java/nsusbloader/Utilities/Rcm.java#L112-L125

developersu avatar Jul 24 '20 00:07 developersu