sd - SD card contents

The sd module enables reading and writing of Nintendo 3DS SD card encrypted digital content. This is the “Nintendo 3DS” folder on an SD card and includes application data, save data, and extdata.

Deprecated since version 0.8.0: Replaced with sdfs.

Directory hierarchy

  • Nintendo 3DS

    • <id0>

      • <id1>

        • backup

        • dbs

        • extdata

        • title

        • Nintendo DSiWare

SDFilesystem objects

class pyctr.type.sd.SDFilesystem(path, *, crypto=None, dev=False, sd_key_file=None, sd_key=None)[source]

Read and write encrypted SD card contents in the “Nintendo 3DS” directory.

All methods related to files and directories happen relative to the root of the ID1 folder. Each have an optional id1 parameter to specify a specific ID1 directory. If left unspecified, the value of current_id1 is used.

Parameters:
  • path (str) – Path to the Nintendo 3DS folder.

  • crypto (CryptoEngine) – A custom crypto object to be used. Defaults to None, which causes a new one to be created.

  • sd_key_file (path-like object or binary file) – Path to a movable.sed file to load the SD KeyY from.

  • sd_key (bytes) – SD KeyY to use. Has priority over sd_key_file if both are specified.

Raises:
open_title(title_id, *, case_insensitive=False, seed=None, load_contents=True, id1=None)[source]

Open a title’s contents for reading.

In the case where a title’s directory has multiple tmd files, the first one returned by listdir() is used.

Parameters:
  • title_id (str) – Title ID to open.

  • case_insensitive (bool) – Use case-insensitive paths for the RomFS of each NCCH container.

  • seed (bytes) – Seed to use. This is a quick way to add a seed using add_seed().

  • load_contents (bool) – Load each partition with NCCHReader.

Return type:

SDTitleReader

Raises:

MissingTitleError – If the title could not be found.

open(path, mode='rb', *, id1=None)[source]

Opens a file in the SD filesystem for reading or writing. Unix and Windows style paths are accepted.

This does not support reading or writing files in the “Nintendo DSiWare” directory, which use a very different encryption method. Attempting will raise NotImplementedError.

Parameters:
  • path (path-like object) – File path.

  • mode (str) – Mode to open the file with. Binary mode is always used.

Return type:

CTRFileIO

listdir(path, id1=None)[source]

Returns a list of files in the directory.

Parameters:

path (path-like object) – Directory path.

Return type:

List[str]

isfile(path, id1=None)[source]

Checks if the path points to a file.

Parameters:

path (path-like object) – Path to check.

Return type:

bool

isdir(path, id1=None)[source]

Checks if the path points to a directory.

Parameters:

path (path-like object) – Path to check.

Return type:

bool

id1s: List[str]

A list of ID1 directories found in the ID0 directory.

current_id1: str

The ID1 used as the default when none is specified to a method’s id1 argument, initially set to the first value in id1s.

Note

If there is more than one ID1, the default value is whichever happens to be returned by the OS first. This could be different from what is actually used on someone’s console.

Exceptions

exception pyctr.type.sd.SDFilesystemError[source]

Generic exception for SD filesystem operations.

exception pyctr.type.sd.MissingMovableSedError[source]

movable.sed key is not set up.

exception pyctr.type.sd.MissingID0Error[source]

ID0 directory could not be found.

exception pyctr.type.sd.MissingID1Error[source]

No ID1 directories exist in the ID0 directory.

exception pyctr.type.sd.MissingTitleError[source]

The requested Title ID could not be found.