Hacking Linux alternative to No Ban No Sky

  • Thread starter PHF
  • Start date
  • Views 1,734
  • Replies 3
  • Likes 4

PHF

Member
OP
Newcomer
Joined
Aug 21, 2007
Messages
11
Trophies
1
XP
283
Country
France
Preamble
I have written this tiny utility for myself, and I decided to share it for anyone interested in (if any). This thread is intended for experienced Linux users (or at least Unix users). I will not provide any kind of support on how to use Linux and/or a shell prompt. I have no plan for making an user friendly utility, so feel free to use this as a starting point if you ever want to build a GUI.

The utility is based on sed (if your are not familiar with this awesome tool, you can learn more here). You can either invoke sed with a script file:
Code:
sed -r -f SCRIPT_FILE.txt < template.txt > template_private.txt
or with an inline script:
Code:
sed -r 'INLINE_SCRIPT' < template.txt > template_private.txt

In both invocations, the -r flag allows to use extended regular expressions.

Replacing the unique ID
The following script is 100% equivalent to the "Patch ALL Games" button in No Ban No Sky: the given UNIQUE_ID is applied to all games.

Code:
/^SHA1:/{
    n
    n
    n
    n
    n
    s/^(\s*)(\s*[0-9A-F]{2}){16}(\s*)$/\1UNIQUE_ID\3/
}
Code:
/^SHA1:/{n;n;n;n;n;s/^(\s*)(\s*[0-9A-F]{2}){16}(\s*)$/\1UNIQUE_ID\3/}

Note that UNIQUE_ID must be replaced by 16 pairs of hexadecimal digits (01 23 45 67 89 AB CD EF 01 23 45 67 89 AB CD EF), without altering the surrounding \1 and \3.

Replacing the unique ID and the manufacturer
From my own experience, it appeared that replacing the unique ID was no always enough to play online. However, replacing the manufacturer byte with the one of my private header was much better. I don't know if it works for all games, but it did for all my tests. The following script applies both the given UNIQUE_ID and the given MANUFACTURER to all games.
Code:
/^SHA1:/{
    n
    s/^((\s*[0-9A-F]{2}){4}\s*)[0-9A-F]{2}((\s*[0-9A-F]{2}){11}\s*)$/\1MANUFACTURER\3/
    n
    n
    n
    n
    s/^(\s*)(\s*[0-9A-F]{2}){16}(\s*)$/\1$id\3/
}
Code:
/^SHA1:/{n;s/^((\s*[0-9A-F]{2}){4}\s*)[0-9A-F]{2}((\s*[0-9A-F]{2}){11}\s*)$/\1MANUFACTURER\3/;n;n;n;n;s/^(\s*)(\s*[0-9A-F]{2}){16}(\s*)$/\1UNIQUE_ID\3/}

Note that MANUFACTURER must be replaced by a pair of hexadecimal digits, without altering the surrounding \1 and \3.

All-in-one script
If you are lazy like I am, and don't want to manually extract the UNIQUE_ID and the MANUFACTURER from you private header, you can use the following Bash script (ensure that hexdump is installed on your machine).
Code:
#!/bin/bash

set -eu

if [ "$#" -lt 1 ]
then
    echo "Usage: $(basename "$0") <header.bin>" 1>&2
    exit 1
fi

id="$(hexdump -n 16 -e '16/1 "%X "' "$1")"
man="$(hexdump -s 64 -n 1 -e '"%X"' "$1")"

script="$(cat <<EOF
    /^SHA1:/{
        n
        s/^((\s*[0-9A-F]{2}){4}\s*)[0-9A-F]{2}((\s*[0-9A-F]{2}){11}\s*)$/\1$man\3/
        n
        n
        n
        n
        s/^(\s*)(\s*[0-9A-F]{2}){16}(\s*)$/\1$id\3/
    }
EOF
)"

sed -r "$script"

Save the script in a .sh file, and make it executable. Then run it like this:
Code:
./apply_header.sh PRIVATE_HEADER.bin < template.txt > template_private.txt

Other platforms
I only tested this on Linux, but since sed is a standard Unix tool, you can probably run it also on Mac OS, or even on Windows (using Cygwin or sed for Windows).
 

Skyline969

MENUdo Afficionado
Member
Joined
Nov 18, 2008
Messages
2,209
Trophies
0
Age
32
Location
Saskatchewan
Website
Visit site
XP
518
Country
Canada
This looks incredibly useful, thanks for this. Now forgive me as I'm completely new to the Sky3DS scene, but from what I understand all I need to do is run this script to patch the template file (using a private header and all of that, yes), and then just use it in DiskWriter to write my backups to the MicroSD for the Sky3DS? That's it?
 

Cerberus3

Member
Newcomer
Joined
Feb 27, 2015
Messages
16
Trophies
0
XP
86
Country
United States
your function for writing in the manufacturer id is precisely what i need but i have no experience with programming or linux.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    SylverReZ @ SylverReZ: Sup