I'm trying to run a script on the Nox emulator through adb. After connecting to Nox via adb with adb connect localhost:62001 and copying a script into a /data/scripts/script.sh folder, executing it gives me different outputs. The script contains the following:

dd if="/data/scripts/screen.dump" bs=4 skip=540503 count=1 | hd

# Expected output: 00000000  08 04 1D FF

Now, here is the problem: I'm getting different results depending where/how I run the script. For it to work, I need to open the shell first with adb shell, and any of the following commands work from within it:

  • dd if="/data/scripts/screen.dump" bs=4 skip=540503 count=1 | hd
  • . ./data/scripts/script.sh

But I need to be able to run the commands from within a script without having to type them. All of these don't work:

  • adb shell sh ./data/scripts/script.sh
  • adb shell . ./data/scripts/script.sh
  • adb shell 'dd if="/data/scripts/screen.dump" bs=4 skip=540503 count=1 | hd'

The main error I'm getting is Usage: hd [-b base] [-c count] [-r delay] file (which is weird because I know it's correct), and occasionally also dd: stdout: Broken pipe. I've spent about 5 hours today trying only to solve this and I'm out of ideas... If anyone has one let me know!

  • adb shell cannot access directories in /data/ without root access. Are you running with root privileges? What's the ownership of /data/scripts? What's SELinux status? Feb 9 '20 at 15:37
  • @IrfanLatif I'm not sure if I'm answering your question correctly, but running ls -ld /data gave me back system.
    – Zebiano
    Feb 9 '20 at 15:48
  • 1
    What's the output of adb shell id, adb shell ls -l /data/scripts and adb shell getenforce? From where did you get hd binary? Did you try hexdump? Feb 9 '20 at 15:49
  • 1
    1. uid=0(root) gid=0(root) (I've shortened the output) 2. All of them are root 3. getenforce is Disabled 4. I have BusyBox installed under /xbin, and I just tested using hexdump instead of hd and it worked... Why though?
    – Zebiano
    Feb 9 '20 at 16:08
  • For anyone working with hd, take care that replacing it with hexdump won't return the same results as hd! Instead use hexdump -C, more about it here.
    – Zebiano
    Feb 9 '20 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.