Skip to content

Instantly share code, notes, and snippets.

@dkosmari
Created July 21, 2018 23:05
Show Gist options
  • Save dkosmari/e43ab558d66f7adb98cb5d950628bb7c to your computer and use it in GitHub Desktop.
Save dkosmari/e43ab558d66f7adb98cb5d950628bb7c to your computer and use it in GitHub Desktop.
ustealth in python to hide FAT32 partitions from Wii U
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Missing argument: device"
exit 1
fi
printf '\xAB' | dd of=$1 bs=1 seek=511 count=1 conv=notrunc
partprobe $1
exit 0
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Missing argument: device"
exit 1
fi
printf '\xAA' | dd of=$1 bs=1 seek=511 count=1 conv=notrunc
partprobe $1
exit 0
#!/bin/env python3
import sys
import subprocess
helpstr = """
ustealth.py: hides or shows partitions from Wii U.
Usage:
\t./ustealth.py hide <block device>
\t./ustealth.py show <block device>
Examples:
\tsudo ./ustealth.py hide /dev/sdc
\tsudo ./ustealth.py show /dev/sdc
"""
byte_offset = 511
hidden_byte = b'\xAB'
visible_byte = b'\xAA'
def change_byte(device, offset, oldbyte, newbyte):
with open(device, mode='r+b', buffering=0) as dev:
dev.seek(offset)
data = dev.read(1)
if data == oldbyte:
dev.seek(offset)
dev.write(newbyte)
else:
sys.exit("Error: expected {}, found {}.".format(oldbyte, data))
print("Trying to re-read partition table.")
cmds = [
['blockdev', '-v', '--rereadpt', device],
['partprobe', '-s', device],
['partx', '-vu', device],
['hdparm', '-z', device]
]
for cmd in cmds:
try:
result = subprocess.run(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True)
if result.returncode == 0:
print("Executed:\n\t{}".format(" ".join(cmd)))
print(result.stdout)
break
except:
pass
if len(sys.argv) != 3:
print(helpstr)
sys.exit("Error: wrong number of arguments.")
action = sys.argv[1]
device = sys.argv[2]
if action == "show":
print("Action: show partitions.")
change_byte(device, byte_offset, hidden_byte, visible_byte)
elif action == "hide":
print("Action: hide partitions.")
change_byte(device, byte_offset, visible_byte, hidden_byte)
else:
print(helpstr)
sys.exit("Error: invalid action: {}.".format(action))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment