diff --git a/README.md b/README.md index 4137a7a..489d241 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,7 @@ cia-unix/ ├─ makerom └─ Encrypted Game.cia ``` - -## Contributors -ctrtool and makerom are from [*3DSGuy* repository](https://github.com/3DSGuy/Project_CTR) - -*[AdawareDeveloper](https://github.com/AdawareDeveloper)* contributed translating the [windows-only version](https://github.com/matiffeder/3DS-stuff/blob/master/Batch%20CIA%203DS%20Decryptor.bat) +**ctrtool** and **makerom** can be downloaded with `dltools.sh` ## 📋 Roadmap - [x] Decrypt .cia @@ -33,3 +29,8 @@ You’ll need the [Crystal compiler](https://crystal-lang.org/install/) `crystal build cia-unix.cr --release` Dependencies can be compiled with [makerom](https://github.com/3DSGuy/Project_CTR/tree/master/makerom) and [ctrtool](https://github.com/3DSGuy/Project_CTR/tree/master/ctrtool) make files + +## Contributors +ctrtool and makerom are from [*3DSGuy* repository](https://github.com/3DSGuy/Project_CTR) + +*[AdawareDeveloper](https://github.com/AdawareDeveloper)* contributed translating the [windows-only version](https://github.com/matiffeder/3DS-stuff/blob/master/Batch%20CIA%203DS%20Decryptor.bat) \ No newline at end of file diff --git a/cia-unix.cr b/cia-unix.cr index df08e4c..2017231 100644 --- a/cia-unix.cr +++ b/cia-unix.cr @@ -22,12 +22,29 @@ def gen_args(name : String, part_count : Int32) : String return args end +# dependencies check +tools = ["python2.7", "./ctrtool", "./makerom", "decrypt.py"] +tools.each do |tool| + if !File.exists? %x[which #{tool}].chomp + case tool + when "python2.7" + abort "#{"Python 2.7".colorize.mode :bold} not found. Install it before continue" + when "decrypt.py" + if !File.exists? tool + abort "#{tool.colorize.mode :bold} not found. Make sure it's located in the #{"same directory".colorize.mode :underline}" + end + else + abort "#{tool.lchop("./").colorize.mode :bold} not found. Make sure it's located in the #{"same directory".colorize.mode :underline}" + end + end +end + Dir["*.cia"].each do |cia| if cia.includes? "decrypted" next end - puts "Decrypting: #{cia.colorize.mode(:bold)}..." + puts "Decrypting: #{cia.colorize.mode :bold}..." cutn : String = cia.chomp ".cia" args : String = "" content = %x[./ctrtool -tmd '#{cia}'] @@ -44,7 +61,7 @@ Dir["*.cia"].each do |cia| log.puts %x[./makerom -f cia -ignoresign -target p -o '#{cutn}-decfirst.cia' #{args}] elsif content.match /T.*D.*0004000E/ - puts "CIA Type: #{"Patch".colorize.mode(:bold)}" + puts "CIA Type: #{"Patch".colorize.mode :bold}" log.puts %x[python2.7 decrypt.py '#{cia}'] patch_parts : Int32 = Dir["#{cutn}.*.ncch"].size @@ -54,7 +71,7 @@ Dir["*.cia"].each do |cia| check_decrypt("#{cutn} (Patch)", "cia") elsif content.match /T.*D.*0004008C/ - puts "CIA Type: #{"DLC".colorize.mode(:bold)}" + puts "CIA Type: #{"DLC".colorize.mode :bold}" log.puts %x[python2.7 decrypt.py '#{cia}'] dlc_parts : Int32 = Dir["#{cutn}.*.ncch"].size diff --git a/dltools.sh b/dltools.sh new file mode 100755 index 0000000..2637810 --- /dev/null +++ b/dltools.sh @@ -0,0 +1,36 @@ +#!/bin/bash +bold=$(tput bold) +normal=$(tput sgr0) + +if [[ "$OSTYPE" == "darwin"* ]]; then + echo " * Downloading ${bold}ctrtool${normal}" + wget https://github.com/3DSGuy/Project_CTR/releases/download/ctrtool-v0.7/ctrtool-v0.7-macos_x86_64.zip -q + echo " * Extracting ${bold}ctrtool${normal}" + unzip -qq ctrtool-v0.7-macos_x86_64.zip -d ctrtool-v0.7-macos_x86_64 + mv ctrtool-v0.7-macos_x86_64/ctrtool $(cd "$(dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)/ctrtool + echo " * Downloading ${bold}makerom${normal}" + wget https://github.com/3DSGuy/Project_CTR/releases/download/makerom-v0.18/makerom-v0.18-macos_x86_64.zip -q + echo " * Extracting ${bold}makerom${normal}" + unzip -qq makerom-v0.18-macos_x86_64.zip -d makerom-v0.18-macos_x86_64 + mv makerom-v0.18-macos_x86_64/makerom $(cd "$(dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)/makerom + + echo " * Cleaning up" + rm -rf ctrtool-v0.7-macos_x86_64.zip ctrtool-v0.7-macos_x86_64 + rm -rf makerom-v0.18-macos_x86_64.zip makerom-v0.18-macos_x86_64 + +elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + echo " * Downloading ${bold}ctrtool${normal}" + wget https://github.com/3DSGuy/Project_CTR/releases/download/ctrtool-v0.7/ctrtool-v0.7-ubuntu_x86_64.zip -q + echo " * Extracting ${bold}ctrtool${normal}" + unzip -qq ctrtool-v0.7-ubuntu_x86_64.zip -d ctrtool-v0.7-ubuntu_x86_64 + mv ctrtool-v0.7-ubuntu_x86_64/ctrtool $(cd "$(dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)/ctrtool + echo " * Downloading ${bold}makerom${normal}" + wget https://github.com/3DSGuy/Project_CTR/releases/download/makerom-v0.18/makerom-v0.18-ubuntu_x86_64.zip -q + echo " * Extracting ${bold}makerom${normal}" + unzip -qq makerom-v0.18-ubuntu_x86_64.zip -d makerom-v0.18-ubuntu_x86_64 + mv makerom-v0.18-ubuntu_x86_64/makerom $(cd "$(dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)/makerom + + echo " * Cleaning up" + rm -rf ctrtool-v0.7-ubuntu_x86_64.zip ctrtool-v0.7-ubuntu_x86_64 + rm -rf makerom-v0.18-ubuntu_x86_64.zip makerom-v0.18-ubuntu_x86_64 +fi \ No newline at end of file