Code Monkey home page Code Monkey logo

dnasdw / 3dstool Goto Github PK

View Code? Open in Web Editor NEW
319.0 23.0 32.0 141.57 MB

An all-in-one tool for extracting/creating 3ds roms.

License: MIT License

Shell 0.76% C 79.63% C++ 0.99% Makefile 3.81% Perl 8.12% Assembly 0.26% eC 0.01% Emacs Lisp 0.01% CMake 0.22% Batchfile 0.10% DIGITAL Command Language 0.32% M4 0.86% Python 1.80% Roff 2.14% D 0.13% DTrace 0.01% Java 0.53% OCaml 0.31% PowerShell 0.02% Tcl 0.01%
dnasdw tool nintendo 3ds ctr snake rom cci ncsd cxi

3dstool's Introduction

3dstool

An all-in-one tool for extracting/creating 3ds roms.

History

  • v1.2.0 @ 2018.06.03 - Support auto encryption fully
  • v1.2.1 @ 2018.07.26 - Support openssl 1.1.0
  • v1.2.2 @ 2018.08.27 - Fix not encrypt bug
  • v1.2.3 @ 2018.09.03 - Fix extract cxi without exefs bug
  • v1.2.4 @ 2019.03.28 - Improve lock region
  • v1.2.5 @ 2019.04.20 - Fix extract exefs without exefs-dir bug
  • v1.2.6 @ 2019.05.25 - Sync with libsundaowen_src

v1.1

  • v1.1.0 @ 2018.01.03 - A new beginning
  • v1.1.1 @ 2018.01.21 - Lock region and language

v1.0

  • v1.0.0 @ 2014.12.07 - The very first release
  • v1.0.1 @ 2014.12.09 - Make compatible with Windows XP
  • v1.0.2 @ 2014.12.25 - Support diff and patch
  • v1.0.3 @ 2014.12.26 - Fix diff bug
  • v1.0.4 @ 2014.12.28 - Fix exefs header bug
  • v1.0.5 @ 2015.01.05 - Fix diff bug
  • v1.0.6 @ 2015.01.22 - Fix create romfs with reference bug
  • v1.0.7 @ 2015.01.23 - Support banner
  • v1.0.8 @ 2015.08.30 - Refactoring compression and fix banner bug
  • v1.0.9 @ 2015.10.28 - Support romfs level3 only
  • v1.0.10 @ 2015.11.22 - Support exefs in cfa and abandon romfs level3 only
  • v1.0.11 @ 2016.02.04 - Fix diff bug and support VS2015
  • v1.0.12 @ 2016.04.14 - Support 7.x auto encryption
  • v1.0.13 @ 2016.04.20 - Fix romfs 7.x auto encryption bug
  • v1.0.14 @ 2016.05.17 - Sync with exepatch and support VS2015
  • v1.0.15 @ 2016.05.23 - Support auto encryption with ext key
  • v1.0.16 @ 2016.11.01 - Support huffman, runlength, yaz0 compression, romfs remap ignore and VS2008SP1
  • v1.0.17 @ 2016.11.06 - Fix romfs hash bug
  • v1.0.18 @ 2016.12.04 - Compatible with yaz0 with alignment property
  • v1.0.19 @ 2017.01.11 - Fix romfs hash bug
  • v1.0.20 @ 2017.03.24 - Refactoring
  • v1.0.21 @ 2017.04.02 - Refactoring
  • v1.0.22 @ 2017.04.05 - Commandline support unicode
  • v1.0.23 @ 2017.05.09 - Fix runtime error
  • v1.0.24 @ 2017.05.21 - Support auto encryption
  • v1.0.25 @ 2017.06.18 - Fix auto encryption bug and add download
  • v1.0.26 @ 2017.06.20 - Fix auto encryption bug
  • v1.0.27 @ 2017.10.10 - Fix encoding on macOS

Platforms

  • Windows
  • Linux
  • macOS

Building

Dependencies

  • cmake
  • libiconv
  • openssl-devel / libssl-dev
  • libcurl-devel

Compiling

  • make 64-bit version
mkdir build
cd build
cmake -DUSE_DEP=OFF ..
make
  • make 32-bit version
mkdir build
cd build
cmake -DBUILD64=OFF -DUSE_DEP=OFF ..
make

Installing

make install

Usage

3dstool [option...] [option]...

Options

See 3dstool --help messages.

3dstool's People

Contributors

badda71 avatar captv0rt3x avatar dnasdw avatar quchao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

3dstool's Issues

3dstool does not compile without tweaks

I'm using MSYS2/mingw64, cloned repo, and was trying to use my own libraries, renamed dep to dep1 to make sure it didn't use it, and then ran

mkdir build && cd build
cmake -G "MSYS Makefiles" -DUSE_DEP=OFF ..
make

like suggested, but I had to change <capstone.h> in both code.h and code.cpp to <capstone/capstone.h>, and add capstone to the target_link_libraries() in src/CMakeLists.txt to get it to link right, thought I'd bring it up

Latest commit breaks romFS reinsertion

With the latest commit, if I do:

./3dstool -f file.cxi -x --header header --exh exheader --exefs exefs --romfs romfs --plain plain --exh-xor exheader.xorpad

and then:

./3dstool -f file2.cxi -t cxi -c --header header --exh exheader --exefs exefs --romfs romfs --plain plain --exh-xor exheader.xorpad --not-update-exefs-hash --not-update-romfs-hash

It outputs:

"ERROR: romfs is too short

ERROR: create file failed"

It works fine with the previous commit. Using Mac OS X.
EDIT: looking at the code, I think this is caused from trying to read data from the romFS header, which is encrypted.

help

i am trying to open pokemon alpha sapphire but it its givning me Error:Error opening ticket

Backward LZ77 压缩问题

在给某些文件解压后重新压缩,放入游戏内虽然可以读取,但游戏出现错误;
有一部分文件出现这问题,其他同类文件是可以压缩同原始文件;
尝试对比原始文件,发现文件头里的文件大小值
compactcommon.zip
附件是DQ11的片头内容,原始文件头:

50 41 43 41 44 FD 04 00 00 01 FF FE CB 02 80 00

2次压缩后的文件头,大小值后面不是“00”而是“85”,然后整个压缩的主体内容前移了一个字节:

50 41 43 41 44 FD 04 85 00 FF FE CB 02 90 00 20

文件尾也有少许不同,原始文件尾:

00 00 00 00 00 1A FF FF 40 38 01 0A FC C4 03 00

2次压缩的文件尾:

00 00 00 00 1A FF FF FF 41 38 01 0B FC C4 03 00

Problem with logo.darc.lz

Some games contain the logo.darc.lz file in the exefs folder. The problem is that when unpacking exefs.bin, the logo.darc.lz file is not decrypted.(3dstool 1.2.5)

CXI extraction produces errors if ExeFS path not set

3dstool produces errors and exits in an error state when extracting a cxi file if not extracting the ExeFS. The content is still extracted successfully, but the error state causes issues for scripts which rely on exit state to determine extraction success. No errors are produced if the ExeFS is extracted as well, even if to NUL or /dev/null.

Steps to Reproduce:

Extract any contents from a cxi file excluding the ExeFS.
eg. 3dstool -xvtf cxi "test.cxi" --header header.bin --extendedheader exheader.bin

Expected Results:

Selected contents are extracted without error.

Actual Results:

Selected contents are extracted, but program produces errors: ERROR: open file failed and ERROR: extract file failed

Additional Info:

It appears that m_sExeFsFileName is not checked to contain a path prior to an attempted file open (ncch.cpp:189), causing these errors.

Example of extract with errors:

E:\Citra\Games>3dstool -xvtf cxi "Pokemon SMD.cxi" --header header.bin --extendedheader exheader.bin
save: header.bin
save: exheader.bin
INFO: logoregion is not extract
INFO: plainregion is not extract
ERROR: open file  failed

INFO: romfs is not extract
ERROR: extract file failed

Example of extract without errors:

E:\Citra\Games>3dstool -xvtf cxi "Pokemon SMD.cxi" --header header.bin --extendedheader exheader.bin --exefs exefs.bin
save: header.bin
save: exheader.bin
INFO: logoregion is not extract
INFO: plainregion is not extract
save: exefs.bin
INFO: romfs is not extract

On an unrelated note, would you consider adding a license to this repo? (maybe MIT or zlib?)

Question about 2 entries...

Sorry to bother you but, I had a small question regarding 3dstool. On ext_key.txt, there's a listing for:
00400000018C400 DC1941EF912EDE118D34C3596BF55FBA

this is apparently CTR-N-RMWA: ミュウ引換用ソフト (the Mew Trading App used in Japan for the RGBY VC releases).

There’s also a listing for:
000400000018C500 9993FB59D175B8861C34F0F7D8BB831D

this is CTR-N-RMWZ: Mew Trading App(E),

How did you come across the encrypted keys? Might you also have the decrypted keys as well?

Any help would be greatly appreciated.

Thanks!

Cross compile target for ARM & maybe provide binaries

I would like this to be usable on Android devices in Termux (at least on armv7l and aarch64) and for that I would like to cross compile it on my x86_64 system running Arch Linux.

Would also be nice if binaries for ARM could be added (then I would not even not to compile it, but it would still be nice to have the option)

ROM with incorrect encryption flag gives error

I have a ROM file in CXI format. It is decrypted, but the ROM's encryption flag is incorrect; it says the ROM is encrypted. (This looks like a common problem with 3DS ROM files, because I have two ROMs like this.)

When I try to unpack the CXI, I see this error:

$ 3dstool -x -t cxi -f pmd3.part0.cxi -v \
	--header header.bin \
	--extendedheader exheader.bin \
	--plainregion plain.bin \
	--exefs exefs.bin \
	--romfs romfs.bin
save: header.bin
save: exheader.bin
save: plain.bin
save: exefs.bin
save: romfs.bin
ERROR: extract file failed

GDB shows that the error happens in CNcch::ExtractFile():

177				if (CExeFs::IsExeFsSuperBlock(exeFsSuperBlock))
(gdb) n
209					bResult = false;
(gdb) 

I thought that maybe if I give the --not-encrypt flag to tell 3dstool that the ROM is decrypted, it would work. But instead, I get a different error:

$ 3dstool -x -t cxi -f pmd3.part0.cxi -v \
	--not-encrypt \
	--header header.bin \
	--extendedheader exheader.bin \
	--plainregion plain.bin \
	--exefs exefs.bin \
	--romfs romfs.bin
ERROR: encrypt error

Trim & Untrim results in different hashes

I was looking for a tool to compress/trim 3DS games (Encrypted and decrypted) and also to decompress/untrim 3DS games to get the original roms back. The reason is to verify roms with no-intro and to archive them in a compressed form. If required the roms should be decompressed/untrimmed to verify the no-intro checksum.

I tried now several roms with the trim/unteim feature. However it seems that roms larger than 4GB cannot be untrimmed. The hashes do not equal the original hashes from no-intro.

Steps to reproduce:

  • Get a encrypted 3DS rom for Bravely Dedault
  • Check the hash with the no-intro dat in romcenter
  • Trim the 3DS rom with 3DSTool.
  • check and verify that the size and hash of the rom is changed (smaller size)
  • untrim the rom with 3DSTool
    -check the size and hash

You will recognize that after the unteimming process the size is correct, however the hash and file structure is wrong (verified with rom center)

How to open this tool?

After I downloaded the tool and release it, I opened the file 3dstool.exe. But just a number of sentences appeared and nothing happened. How can I use it? Are there some use help can I find?

3dstool fails to work with openssl 1.1.0g

Hello guys,

I am on ubuntu 18.04 and i wanted to use 3dstool to test some citra-emu code. However, it doesn't seem to work for me. It fails with the following error.

/home/jenkins/local/Citra-Sys-Arch/shared_font/3dstool/src/3dscrypt.cpp:22:3: error: ‘AES_ctr128_encrypt’ was not declared in this scope
   AES_ctr128_encrypt(pInBuffer, pOutBuffer, static_cast<size_t>(nSize), &key, uCounter, uEcountBuf, &uNum);
   ^~~~~~~~~~~~~~~~~~
/home/jenkins/local/Citra-Sys-Arch/shared_font/3dstool/src/3dscrypt.cpp:22:3: note: suggested alternative: ‘AES_cfb128_encrypt’
   AES_ctr128_encrypt(pInBuffer, pOutBuffer, static_cast<size_t>(nSize), &key, uCounter, uEcountBuf, &uNum);
   ^~~~~~~~~~~~~~~~~~
   AES_cfb128_encrypt

Any solutions ?

RomFS is always encrypted when rebuilding NCCH files

I've been trying to rebuild a game with a translation patch for use in Citra, but the RomFS region always comes out encrypted, no matter what flags I use when rebuilding the CXI (including --not-encrypt).

After peeking at the source code, I noticed this:

3dstool/src/ncch.cpp

Lines 966 to 969 in 3cb0ebd

if (m_nEncryptMode == kEncryptModeNone)
{
CopyFile(m_fpNcch, fp, 0, nFileSize);
}

I think that if statement always fails, because:

3dstool/src/3dstool.cpp

Lines 218 to 221 in 3cb0ebd

if (m_nEncryptMode == CNcch::kEncryptModeNone)
{
m_nEncryptMode = CNcch::kEncryptModeAuto;
}

Unless there's something else I'm missing?

Problem with decompressing code.bin in the latest release.

I have a problem with decompressing the code.bin file in the latest release of 3dstool (the one that use boot9 keys).
I can extract the DecryptedExeFS.bin file, extract its contents too.
(I extract from a clean game, not decrypted via Decrypt9 as it's not needed anymore with boot9 keys).

But when I try to decompress the code.bin file, 3dstool crash :
http://image.noelshack.com/fichiers/2017/36/2/1504595094-3dstool.png

I have the same error with ctrtool, I got "Error allocating memory" :
http://image.noelshack.com/fichiers/2017/36/2/1504595120-ctrtool.png

If I don't try to decompress, the extraction work fine, but the code.bin make the rebuilded .3ds / .cia corrupted.

So if you have any idea, workaround, or arguments I may have forgotten, please tell me !

unknown entry name 4 on compiling exefs

In my gameboy tetris disassembly (https://github.com/davFaithid/tetris-disassembly), I provide a 3ds version with uses this program to compile. However on compiling the exefs, I encounter this.

"bin/3dstool" -cv -t exefs -f 3DS/exefs.bin --exefs-dir 3DS/exefs --header 3DS/exefs/header.bin
 "bin/3dstool" -cv -t romfs -f 3DS/romfs.bin --romfs-dir 3DS/romfs
 "bin/3dstool" -cv -t cxi -f 3DS/Tetris.cxi --header 3DS/ncch.bin --exh 3DS/exheader.bin  --logo 3DS/logo.bin --exefs 3DS/exefs.bin --romfs 3DS/romfs.bin
load: 3DS/exefs/header.bin
load: 3DS/exefs/code.bin
INFO: unknown entry name 4�
ERROR: open file 3DS/exefs/4�.bin failed

INFO: unknown entry name ?
ERROR: open file 3DS/exefs/?.bin failed

ERROR: create file failed

load: 3DS/romfs/agb.bin
load: 3DS/romfs/buildtime.txt
load: 3DS/romfs/config.ini
load: 3DS/romfs/ErrLayout.arc
load: 3DS/romfs/face_cgb.ttp
load: 3DS/romfs/layout.arc
load: 3DS/romfs/shader.shbin
load: 3DS/romfs/ErrLang/EU-DU-Scale.scale
load: 3DS/romfs/ErrLang/EU-Dutch.lang
load: 3DS/romfs/ErrLang/EU-EN-Scale.scale
load: 3DS/romfs/ErrLang/EU-English.lang
load: 3DS/romfs/ErrLang/EU-FR-Scale.scale
load: 3DS/romfs/ErrLang/EU-French.lang
load: 3DS/romfs/ErrLang/EU-GE-Scale.scale
load: 3DS/romfs/ErrLang/EU-German.lang
load: 3DS/romfs/ErrLang/EU-IT-Scale.scale
load: 3DS/romfs/ErrLang/EU-Italian.lang
load: 3DS/romfs/ErrLang/EU-PO-Scale.scale
load: 3DS/romfs/ErrLang/EU-Portuguese.lang
load: 3DS/romfs/ErrLang/EU-RU-Scale.scale
load: 3DS/romfs/ErrLang/EU-Russian.lang
load: 3DS/romfs/ErrLang/EU-SP-Scale.scale
load: 3DS/romfs/ErrLang/EU-Spanish.lang
load: 3DS/romfs/lang/EU-DU-Scale.scale
load: 3DS/romfs/lang/EU-Dutch.lang
load: 3DS/romfs/lang/EU-EN-Scale.scale
load: 3DS/romfs/lang/EU-English.lang
load: 3DS/romfs/lang/EU-FR-Scale.scale
load: 3DS/romfs/lang/EU-French.lang
load: 3DS/romfs/lang/EU-GE-Scale.scale
load: 3DS/romfs/lang/EU-German.lang
load: 3DS/romfs/lang/EU-IT-Scale.scale
load: 3DS/romfs/lang/EU-Italian.lang
load: 3DS/romfs/lang/EU-PO-Scale.scale
load: 3DS/romfs/lang/EU-Portuguese.lang
load: 3DS/romfs/lang/EU-RU-Scale.scale
load: 3DS/romfs/lang/EU-Russian.lang
load: 3DS/romfs/lang/EU-SP-Scale.scale
load: 3DS/romfs/lang/EU-Spanish.lang
load: 3DS/romfs/rom/vc_rom.bin
load: 3DS/romfs/shader/nwdemo_Common.shbin
load: 3DS/romfs/shader/nwfont_RectDrawerShader.shbin
load: 3DS/romfs/shader/nwfont_TextWriterShader.shbin
load: 3DS/romfs/shader/nwgfx_DefaultShader.csdr
load: 3DS/romfs/shader/nwgfx_DefaultShader.shbin
load: 3DS/romfs/shader/nwgfx_ParticleDefaultShader.csdr
load: 3DS/romfs/shader/nwgfx_ParticleDefaultShader.shbin
load: 3DS/romfs/shader/nwgfx_ParticleGShader.obj
load: 3DS/romfs/shader/nwgfx_ShadowShader.csdr
load: 3DS/romfs/shader/nwgfx_ShadowShader.shbin
load: 3DS/romfs/shader/nwlyt_ConstColorShader.shbin
load: 3DS/romfs/shader/nwlyt_PaneShader.shbin
load: 3DS/romfs/snd/threeb.bcsar
load: 3DS/romfs/snd/threeb.csid
load: 3DS/ncch.bin
load: 3DS/exheader.bin
load: 3DS/logo.bin
load: 3DS/exefs.bin
load: 3DS/romfs.bin

The files in exefs are banner.bin, cert.bin, code.bin, header.bin, icon.bin, and meta.bin

Is there any thing amiss with my code that I should fix?

Thank you

ERROR: open file exefs/logo.darc.lz failed when trying to create cia

I'm trying to edit the paper mario ss cia file. I'm following the guide here. When I try to rebuild the exefs after extracting it, 3dstool throws out the error: ERROR: open file exefs/logo.darc.lz failed. I checked the directories and the logo never existed in a darc.lz file, it only exists in a bin file and a bmca.lz file.

Removing "-auto" strings in v1.1.0

https://github.com/dnasdw/3dstool/issues/9

dnasdw commented on 6 Sep 2017
PS:--exh-auto-key, --exefs-auto-key, --exefs-top-auto-key and --romfs-auto-key will remove after 3dstool v1.1.0.

Asia81 commented on 6 Sep 2017
When you say
PS:--exh-auto-key, --exefs-auto-key, --exefs-top-auto-key and --romfs-auto-key will remove after 3dstool v1.1.0.

Does it mean it will not be anymore to write that? Will be automatically used?

Did you include this feature or not?
Because when I try to don't use them, I can't extract game files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.