<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.3dbrew.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Erant</id>
	<title>3dbrew - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.3dbrew.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Erant"/>
	<link rel="alternate" type="text/html" href="https://www.3dbrew.org/wiki/Special:Contributions/Erant"/>
	<updated>2026-04-14T22:17:22Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Main_Page/Navigation&amp;diff=456</id>
		<title>Main Page/Navigation</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Main_Page/Navigation&amp;diff=456"/>
		<updated>2011-05-01T23:29:45Z</updated>

		<summary type="html">&lt;p&gt;Erant: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Main page box|Navigation|Main Page/Navigation}}&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: -.3em -1em -1em -1em;&amp;quot;&amp;gt;&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot; bgcolor=&amp;quot;#fff&amp;quot; border=&amp;quot;0&amp;quot; cellpadding=&amp;quot;2px&amp;quot; cellspacing=&amp;quot;2px&amp;quot; style=&amp;quot;margin:auto;&amp;quot;&lt;br /&gt;
|- align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#e7eef6&amp;quot;&lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &#039;&#039;&#039;General&#039;&#039;&#039;&lt;br /&gt;
! width=&amp;quot;34%&amp;quot; | &#039;&#039;&#039;3DS hardware&#039;&#039;&#039;&lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &#039;&#039;&#039;3DS software&#039;&#039;&#039;&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot; style=&amp;quot;background: #F5FAFF;&amp;quot;&lt;br /&gt;
| &lt;br /&gt;
*[[Glossary]]&lt;br /&gt;
*[[FAQ]]&lt;br /&gt;
*[[Friend code]]&lt;br /&gt;
|&lt;br /&gt;
*[[Hardware]]&lt;br /&gt;
*[[Gamecards]]&lt;br /&gt;
| &lt;br /&gt;
*[[Nintendo Software]]&lt;br /&gt;
*[[File Formats]]&lt;br /&gt;
*[[Title list]]&lt;br /&gt;
*[[Title metadata]]&lt;br /&gt;
*[[SD Filesystem]]&lt;br /&gt;
*[[Flash Filesystem]]&lt;br /&gt;
*[[Bootloader]]&lt;br /&gt;
*[[Savegames]]&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
{{box-footer-empty}}&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=User_talk:Erant&amp;diff=455</id>
		<title>User talk:Erant</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=User_talk:Erant&amp;diff=455"/>
		<updated>2011-05-01T16:30:10Z</updated>

		<summary type="html">&lt;p&gt;Erant: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Why did you delate my change?&lt;br /&gt;
I tryed to crash the game,but nothing happened.&lt;br /&gt;
So I reported.Though you don&#039;t like my edit,There are no meaning to delate the stuf.&lt;br /&gt;
And I may know how you search a game exploit.&lt;br /&gt;
write long name string or high score input,&lt;br /&gt;
and controll PC register.&lt;br /&gt;
jump to the address  input you want to execute,then boot a bootloader.&lt;br /&gt;
bootloader reads data from SD card,which to run homebrew.&lt;br /&gt;
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I completely agree with the above user. Why so basement? --[[User:Matthew|Matthew]] 05:32, 26 April 2011 (CEST)&lt;br /&gt;
&lt;br /&gt;
The post was uninformed, contained grammatical errors, and was downright wrong. The 3DS flash save games are wearleveled, partitioned and have filesystems. Simply changing a string in a savegame invalidates the wearleveling checksum, the partition checksums and the filesystem checksum. The post added no meaningful information to the wiki, and would have opened the floodgates to other people trying to simply extend a string in the hopes of crashing a game.&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=405</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=405"/>
		<updated>2011-04-23T15:21:56Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Partitions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done through the usage of blockmaps and a journal. The blockmap is located at offset 0 of the flash chip, and is immediately followed by the journal. The initial state is dictated by the blockmap, and the journal is then applied to that.&lt;br /&gt;
&lt;br /&gt;
The blockmap structure is simple:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct header_entry {&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
        uint8_t phys_sec;&lt;br /&gt;
        uint8_t alloc_cnt;&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The journal structure is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry{&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
}__attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Partitions ===&lt;br /&gt;
&lt;br /&gt;
There can be multiple partitions on the chip. For some games one is a backup partition, some other games seem to use only one partition, yet other games actually use multiple partitions. Partitions are defined at the start of the de-wearleveled blob. At offset 0x200 into the image, the DIFI blobs start. These 0x130 large blobs describe the partitions. Every DIFI blob describes a partition. In order to find the partitions, you will need the uint32_t at 0x9C into the DIFI blob, and the uint32_t at 0xA4. The uint32_t at 0x9C describes the length of the hash table at the start of the partition, the uint32_t at 0xA4 is the length of the filesystem. Partitions are catted together, so the end of one partition is the beginning of the next. The first partition starts at 0x2000. The hashtable at the start of the partitions describe each in-use block in the partition with a SHA256 of the 0x1000 sized block.&lt;br /&gt;
&lt;br /&gt;
The hash in the DISA blob hashes 300 bytes of the first DIFI blob.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles are stored on the FLASH in a custom filesystem called SAVE. SAVE has a header which describes where the various bits of the filesystem live. The most important is the FST or filesystem table. You can find the FST by first finding the file base offset which is the offset to which all the entries in the FST are relative. The file base offset is a uint16_t at 0x58 from the filesystem start. The FST offset is a uint32_t at 0x6C and is in blocks (which are 0x200 bytes large).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve found the FST, parsing it is fairly straightforward.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct fs_entry {&lt;br /&gt;
     u32 node_cnt;&lt;br /&gt;
     u8  filename[0x10];&lt;br /&gt;
     u32 index;&lt;br /&gt;
     u32 unk1; // magic?&lt;br /&gt;
     u32 block_offset;&lt;br /&gt;
     u32 file_size;&lt;br /&gt;
     u32 unk2;&lt;br /&gt;
     u32 unk3; // flags and/or date?&lt;br /&gt;
     u32 unk4;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first entry is the root directory, easily identifiable by the node_cnt being larger than 1. The node_cnt includes the root directory itself, so there are node_cnt - 1 files in the root directory. The entries that follow after the root directory are the actual files. Reading them out is as simple as taking the file base offset and adding (block_offset * 0x200) to it.&lt;br /&gt;
&lt;br /&gt;
Example from Super MonkeyBall 3D:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0003800: 04000000 21000000 00000000 00000000  ....!...........&lt;br /&gt;
0003810: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003820: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003830: 01000000 736d6233 64732e64 61740000  ....smb3ds.dat..&lt;br /&gt;
0003840: 00000000 00000000 d57b1100 05000000  .........{......&lt;br /&gt;
0003850: e4060000 00000000 c8cf0008 00000000  ................&lt;br /&gt;
0003860: 01000000 6d677265 706c6179 30302e64  ....mgreplay00.d&lt;br /&gt;
0003870: 61740000 01000000 d57b1100 09000000  at.......{......&lt;br /&gt;
0003880: 1c210000 00000000 cd331000 00000000  .!.......3......&lt;br /&gt;
0003890: 01000000 6d677265 706c6179 30312e64  ....mgreplay01.d&lt;br /&gt;
00038a0: 61740000 02000000 d57b1100 1a000000  at.......{......&lt;br /&gt;
00038b0: 1c210000 00000000 00000000 00000000  .!..............&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=3DS_System_Flaws&amp;diff=404</id>
		<title>3DS System Flaws</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=3DS_System_Flaws&amp;diff=404"/>
		<updated>2011-04-23T15:07:48Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==What exploits are==&lt;br /&gt;
==How to search an exploit==&lt;br /&gt;
==Database==&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Gamecards&amp;diff=400</id>
		<title>Gamecards</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Gamecards&amp;diff=400"/>
		<updated>2011-04-22T17:56:51Z</updated>

		<summary type="html">&lt;p&gt;Erant: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:Gamecard.jpg|thumb|right|A 3DS gamecard]] &lt;br /&gt;
[[File:GamecardPhy.jpg|thumb|right|Close-up of PCB]] &lt;br /&gt;
&lt;br /&gt;
===Physical interface===&lt;br /&gt;
The 3DS gamecards have the same physical interface as regular DS and DSi gamecards. There is only a minor cosmetic difference in the plastic case, which has a small extruding notch on the top-right side. As such, it prevents insertion of the gamecard into old Nintendo DS or DSi systems. &lt;br /&gt;
&lt;br /&gt;
When modifying the case so that the 3DS gamecard fits in a DS or DSi system, those systems will refuse to detect the gamecard and show no banner icon.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Pin&lt;br /&gt;
!  Name&lt;br /&gt;
!  Description&lt;br /&gt;
|-&lt;br /&gt;
|  1&lt;br /&gt;
|  GND&lt;br /&gt;
|  Ground&lt;br /&gt;
|-&lt;br /&gt;
|  2&lt;br /&gt;
|  CLK&lt;br /&gt;
|  Clock. Frequencies 6.7MHz and 4.2MHz, 16.6MHz for SPI communication.&lt;br /&gt;
|-&lt;br /&gt;
|  3&lt;br /&gt;
|  NC&lt;br /&gt;
|  Not connected. Possibly used to program cards.&lt;br /&gt;
|-&lt;br /&gt;
|  4&lt;br /&gt;
|  RCS&lt;br /&gt;
|  ROM select, active low. Pulled low to start a ROM transfer.&lt;br /&gt;
|-&lt;br /&gt;
|  5&lt;br /&gt;
|  RST&lt;br /&gt;
|  Reset, active low. &lt;br /&gt;
|-&lt;br /&gt;
|  6&lt;br /&gt;
|  ECS&lt;br /&gt;
|  Savegame chip select, active low. Pulled low to start a savegame SPI transfer.&lt;br /&gt;
|-&lt;br /&gt;
|  7&lt;br /&gt;
|  IRQ&lt;br /&gt;
|  Removal detection.&lt;br /&gt;
|-&lt;br /&gt;
|  8&lt;br /&gt;
|  VCC&lt;br /&gt;
|  Powersupply 3.3V.&lt;br /&gt;
|-&lt;br /&gt;
|  9&lt;br /&gt;
|  DAT0&lt;br /&gt;
|  Bidirectional data bus.&lt;br /&gt;
|-&lt;br /&gt;
|  10&lt;br /&gt;
|  DAT1&lt;br /&gt;
|  Bidirectional data bus.&lt;br /&gt;
|-&lt;br /&gt;
|  11&lt;br /&gt;
|  DAT2&lt;br /&gt;
|  Bidirectional data bus.&lt;br /&gt;
|-&lt;br /&gt;
|  12&lt;br /&gt;
|  DAT3&lt;br /&gt;
|  Bidirectional data bus.&lt;br /&gt;
|-&lt;br /&gt;
|  13&lt;br /&gt;
|  DAT4&lt;br /&gt;
|  Bidirectional data bus / pin NC to savegame chip&lt;br /&gt;
|-&lt;br /&gt;
|  14&lt;br /&gt;
|  DAT5&lt;br /&gt;
|  Bidirectional data bus / pin WP# to savegame chip&lt;br /&gt;
|-&lt;br /&gt;
|  15&lt;br /&gt;
|  DAT6&lt;br /&gt;
|  Bidirectional data bus / SPI data from savegame chip.&lt;br /&gt;
|-&lt;br /&gt;
|  16&lt;br /&gt;
|  DAT7&lt;br /&gt;
|  Bidirectional data bus / SPI data to savegame chip.&lt;br /&gt;
|-&lt;br /&gt;
|  17&lt;br /&gt;
|  GND&lt;br /&gt;
|  Ground&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===SPI flash===&lt;br /&gt;
So far, only one savegame FLASH chip has been identified. The chip identifies as a 0xC22211. The JEDEC manufacturer ID is Macronix, and despite the chip label saying 25L1001, the JEDEC ID matches the MX25L1021E. Datasheet at: http://www.macronix.com/QuickPlace/hq/PageLibrary4825740B00298A3B.nsf/h_Index/3F21BAC2E121E17848257639003A3146/$File/MX25L1021E,%203V,%201Mb,%20v0.01.pdf. However, the MX25L1021E doesn&#039;t support the 4 bit wide transmission that the 3DS uses to talk to the SPI flash. It is thus likely that this is a custom flash chip.&lt;br /&gt;
&lt;br /&gt;
===Protocol===&lt;br /&gt;
The communication protocol between the 3DS system and the 3DS gamecard has changed almost completely in comparison with the DS and DSi gamecard communication protocol.&lt;br /&gt;
&lt;br /&gt;
After the sixth transfer, commands change size from 8 bytes to 16 bytes. Possibly a new encryption is used, such as AES CTR.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a set of sample gamecard commands that a 3DS sends to a 3DS gamecard:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Size&lt;br /&gt;
!  Command&lt;br /&gt;
!  Description&lt;br /&gt;
|-&lt;br /&gt;
|2000&lt;br /&gt;
|9F00000000000000&lt;br /&gt;
| Reset&lt;br /&gt;
|-&lt;br /&gt;
|0000&lt;br /&gt;
|71C93FE9BB0A3B18&lt;br /&gt;
| Unknown&lt;br /&gt;
|-&lt;br /&gt;
|0004&lt;br /&gt;
|9000000000000000&lt;br /&gt;
| Get gamecard ID, response=9000FEC2&lt;br /&gt;
|-&lt;br /&gt;
|0004&lt;br /&gt;
|9000000000000000&lt;br /&gt;
| Get gamecard ID, response=9000FEC2&lt;br /&gt;
|-&lt;br /&gt;
|0004&lt;br /&gt;
|A000000000000000&lt;br /&gt;
| Unknown, response=00000000&lt;br /&gt;
|-&lt;br /&gt;
|0000&lt;br /&gt;
|3E00000000000000&lt;br /&gt;
| Enter 16-byte command mode.&lt;br /&gt;
|-&lt;br /&gt;
|07EC&lt;br /&gt;
|82000000000000000000000000000000&lt;br /&gt;
| Get header&lt;br /&gt;
|-&lt;br /&gt;
|05E3&lt;br /&gt;
|F32C92D85C9D44DED3E0E41DBE7C90D9&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|696B9D8582FB55D31B68CAFE70C74A95&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|BAA4812CA0AC9C5D19399530E3ACCCAB&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|032E&lt;br /&gt;
|178E427C22D87ADB86387249A97D321A&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|E06019B1BD5C9130ED6A4D9F4A9E7193&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|4E0D224862523BBFE2E6255F80E15F37&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|4CDF93D319FB62D0DB632A45E3E8D84C&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|9AA5D80551002F955546D296A57F0FEF&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|C12BA81AEF30DDDBD93FAD5D544C6334&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0532&lt;br /&gt;
|62EC5FB7F420AE1DC6253AE18AFA5BB3&lt;br /&gt;
| Encrypted, read address 0&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|E3FA23AA016BE0C93430D1F42FF41324&lt;br /&gt;
| Encrypted, read address 0x4000&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The header command has some initial dummy bytes, and eventually responds with a 0x200 byte header. Here&#039;s an example for Lego Starwars 3:&lt;br /&gt;
 0000000: 00 8c 03 00 00 00 04 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000010: b3 cf fb c6 6a b1 cb 20 32 af ce 35 d4 1c 74 c9  ....j.. 2..5..t.&lt;br /&gt;
 0000020: 8e 6b 27 2f 08 01 28 3b d4 30 de 44 37 f5 b0 46  .k&#039;/..(;.0.D7..F&lt;br /&gt;
 0000030: 91 59 d7 38 33 48 df 83 fd 71 84 2c 00 00 00 00  .Y.83H...q.,....&lt;br /&gt;
 0000040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000100: 4e 43 43 48 7a 7f 0e 00 00 8c 03 00 00 00 04 00  NCCHz...........&lt;br /&gt;
 0000110: 36 34 02 00 00 00 00 00 00 8c 03 00 00 00 04 00  64..............&lt;br /&gt;
 0000120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000150: 43 54 52 2d 50 2d 41 4c 47 50 00 00 00 00 00 00  CTR-P-ALGP......&lt;br /&gt;
 0000160: 0c 27 e3 c1 de 7b 2a e2 d3 11 4f 32 a4 ee bf 46  .&#039;...{*...O2...F&lt;br /&gt;
 0000170: 9a fd 0c f3 52 c1 1d 49 84 c2 a9 f1 d2 14 4c 63  ....R..I......Lc&lt;br /&gt;
 0000180: 00 04 00 00 00 00 00 00 00 00 00 00 01 03 00 00  ................&lt;br /&gt;
 0000190: 05 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00001a0: 06 00 00 00 1c 0a 00 00 01 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00001b0: 22 0a 00 00 58 75 0e 00 01 00 00 00 00 00 00 00  &amp;quot;...Xu..........&lt;br /&gt;
 00001c0: 13 0c 04 26 15 f6 47 c4 c6 32 25 ea 9e 67 f8 a2  ...&amp;amp;..G..2%..g..&lt;br /&gt;
 00001d0: 7b 15 24 6b 88 fb c7 a9 27 25 7b 84 97 7b 78 7b  {.$k....&#039;%{..{x{&lt;br /&gt;
 00001e0: a6 5b ee 10 60 bb 6a 68 21 bb ce c6 00 03 5b 7e  .[..`.jh!.....[~&lt;br /&gt;
 00001f0: 64 fb 6e ac a7 f0 96 0c fb 1f 5a 37 08 77 28 f7  d.n.......Z7.w(.&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Games&amp;diff=384</id>
		<title>Games</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Games&amp;diff=384"/>
		<updated>2011-04-19T14:40:56Z</updated>

		<summary type="html">&lt;p&gt;Erant: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a page to browse game title and data.&lt;br /&gt;
Feel free to write here.  &lt;br /&gt;
                                                                                  &lt;br /&gt;
The other way to use this page, is hacking with the data.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;32%&amp;quot; | Title&lt;br /&gt;
! width=&amp;quot;23%&amp;quot; | Serial&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; | EUR&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |USA&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |JPN&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |ROM Size&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |FLASH Size&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |FLASH ID&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |FLASH Chip #&lt;br /&gt;
! width=&amp;quot;10%&amp;quot; | Get here&lt;br /&gt;
|-&lt;br /&gt;
| Ridge Racer 3D&lt;br /&gt;
| LNA-CTR-ARRP&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| 8GBit&lt;br /&gt;
| 512kByte&lt;br /&gt;
| 0xC22213&lt;br /&gt;
| 25L4001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Lego Star Wars III: The Clone Wars&lt;br /&gt;
| LNA-CTR-ALGP&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| 4GBit&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Ton Clancy&#039;s Ghost Recon:Shadow Wars&lt;br /&gt;
| LNA-CTR-AGRP&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| No&lt;br /&gt;
| 2GBit&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Raving Rabbids: Travel in Time 3D&lt;br /&gt;
| LNA-CTR-ARBJ&lt;br /&gt;
| ?&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| [http://dl.dropbox.com/u/7830918/3DS%20Upload/decrypted.bin de]/[http://dl.dropbox.com/u/7830918/3DS%20Upload/encrypted.bin en]&lt;br /&gt;
|-&lt;br /&gt;
| The Sims 3&lt;br /&gt;
| LNA-CTR-AS3P&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| 4GBit&lt;br /&gt;
| 512kByte&lt;br /&gt;
| 0xC22213&lt;br /&gt;
| 25L4001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Super Monkey Ball 3D&lt;br /&gt;
| LNA-CTR-ASMP&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| 2GBit&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Splinter Cell 3D&lt;br /&gt;
| LNA-CTR-ASCP&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Super Street Fighter IV - 3D Edition&lt;br /&gt;
| LNA-CTR-ASSP&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Pilotwings Resort&lt;br /&gt;
| LNA-CTR-AWAP&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| ?&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Games&amp;diff=383</id>
		<title>Games</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Games&amp;diff=383"/>
		<updated>2011-04-19T14:23:34Z</updated>

		<summary type="html">&lt;p&gt;Erant: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a page to browse game title and data.&lt;br /&gt;
Feel free to write here.  &lt;br /&gt;
                                                                                  &lt;br /&gt;
The other way to use this page, is hacking with the data.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! width=&amp;quot;32%&amp;quot; | Title&lt;br /&gt;
! width=&amp;quot;23%&amp;quot; | Serial&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; | EUR&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |USA&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |JPN&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |ROM Size&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |FLASH Size&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |FLASH ID&lt;br /&gt;
! width=&amp;quot;5%&amp;quot; |FLASH Chip #&lt;br /&gt;
! width=&amp;quot;10%&amp;quot; | Get here&lt;br /&gt;
|-&lt;br /&gt;
| Ridge Racer 3D&lt;br /&gt;
| LNA-CTR-ARRP&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| 8GBit&lt;br /&gt;
| 512kByte&lt;br /&gt;
| 0xC22213&lt;br /&gt;
| 25L4001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Lego Star Wars III: The Clone Wars&lt;br /&gt;
| LNA-CTR-ALGP&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| 4GBit&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Ton Clancy&#039;s Ghost Recon:Shadow Wars&lt;br /&gt;
| LNA-CTR-AGRP&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| No&lt;br /&gt;
| 2GBit&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Raving Rabbids: Travel in Time 3D&lt;br /&gt;
| LNA-CTR-ARBJ&lt;br /&gt;
| ?&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| [http://dl.dropbox.com/u/7830918/3DS%20Upload/decrypted.bin de]/[http://dl.dropbox.com/u/7830918/3DS%20Upload/encrypted.bin en]&lt;br /&gt;
|-&lt;br /&gt;
| The Sims 3&lt;br /&gt;
| LNA-CTR-AS3P&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| 4GBit&lt;br /&gt;
| 512kByte&lt;br /&gt;
| 0xC22213&lt;br /&gt;
| 25L4001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Super Monkey Ball 3D&lt;br /&gt;
| LNA-CTR-ASMP&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| 2GBit&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Splinter Cell 3D&lt;br /&gt;
| LNA-CTR-ASCP&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Super Street Fighter IV - 3D Edition&lt;br /&gt;
| LNA-CTR-ASSP&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| 128kByte&lt;br /&gt;
| 0xC22211&lt;br /&gt;
| 25L1001&lt;br /&gt;
| ?&lt;br /&gt;
|-&lt;br /&gt;
| Pilotwings Resort&lt;br /&gt;
| LNA-CTR-AWAP&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| Yes&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
| ?&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=332</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=332"/>
		<updated>2011-04-15T03:28:23Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Partitions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps and a journal. The blockmap is located at offset 0 of the flash chip, and is immediately followed by the journal. The initial state is dictated by the blockmap, and the journal is then applied to that.&lt;br /&gt;
&lt;br /&gt;
The blockmap structure is simple:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct header_entry {&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
        uint8_t phys_sec;&lt;br /&gt;
        uint8_t alloc_cnt;&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The journal structure is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry{&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
}__attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Partitions ===&lt;br /&gt;
&lt;br /&gt;
There can be multiple partitions on the chip. For some games one is a backup partition, some other games seem to use only one partition, yet other games actually use multiple partitions. Partitions are defined at the start of the de-wearleveled blob. At offset 0x200 into the image, the DIFI blobs start. These 0x130 large blobs describe the partitions. Every DIFI blob describes a partition. In order to find the partitions, you will need the uint32_t at 0x9C into the DIFI blob, and the uint32_t at 0xA4. The uint32_t at 0x9C describes the length of the hash table at the start of the partition, the uint32_t at 0xA4 is the length of the filesystem. Partitions are catted together, so the end of one partition is the beginning of the next. The first partition starts at 0x2000. The hashtable at the start of the partitions describe each in-use block in the partition with a SHA256 of the 0x1000 sized block.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles are stored on the FLASH in a custom filesystem called SAVE. SAVE has a header which describes where the various bits of the filesystem live. The most important is the FST or filesystem table. You can find the FST by first finding the file base offset which is the offset to which all the entries in the FST are relative. The file base offset is a uint16_t at 0x58 from the filesystem start. The FST offset is a uint32_t at 0x6C and is in blocks (which are 0x200 bytes large).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve found the FST, parsing it is fairly straightforward.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct fs_entry {&lt;br /&gt;
     u32 node_cnt;&lt;br /&gt;
     u8  filename[0x10];&lt;br /&gt;
     u32 index;&lt;br /&gt;
     u32 unk1; // magic?&lt;br /&gt;
     u32 block_offset;&lt;br /&gt;
     u32 file_size;&lt;br /&gt;
     u32 unk2;&lt;br /&gt;
     u32 unk3; // flags and/or date?&lt;br /&gt;
     u32 unk4;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first entry is the root directory, easily identifiable by the node_cnt being larger than 1. The node_cnt includes the root directory itself, so there are node_cnt - 1 files in the root directory. The entries that follow after the root directory are the actual files. Reading them out is as simple as taking the file base offset and adding (block_offset * 0x200) to it.&lt;br /&gt;
&lt;br /&gt;
Example from Super MonkeyBall 3D:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0003800: 04000000 21000000 00000000 00000000  ....!...........&lt;br /&gt;
0003810: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003820: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003830: 01000000 736d6233 64732e64 61740000  ....smb3ds.dat..&lt;br /&gt;
0003840: 00000000 00000000 d57b1100 05000000  .........{......&lt;br /&gt;
0003850: e4060000 00000000 c8cf0008 00000000  ................&lt;br /&gt;
0003860: 01000000 6d677265 706c6179 30302e64  ....mgreplay00.d&lt;br /&gt;
0003870: 61740000 01000000 d57b1100 09000000  at.......{......&lt;br /&gt;
0003880: 1c210000 00000000 cd331000 00000000  .!.......3......&lt;br /&gt;
0003890: 01000000 6d677265 706c6179 30312e64  ....mgreplay01.d&lt;br /&gt;
00038a0: 61740000 02000000 d57b1100 1a000000  at.......{......&lt;br /&gt;
00038b0: 1c210000 00000000 00000000 00000000  .!..............&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=331</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=331"/>
		<updated>2011-04-15T03:02:41Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Partitions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps and a journal. The blockmap is located at offset 0 of the flash chip, and is immediately followed by the journal. The initial state is dictated by the blockmap, and the journal is then applied to that.&lt;br /&gt;
&lt;br /&gt;
The blockmap structure is simple:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct header_entry {&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
        uint8_t phys_sec;&lt;br /&gt;
        uint8_t alloc_cnt;&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The journal structure is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry{&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
}__attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Partitions ===&lt;br /&gt;
&lt;br /&gt;
There can be multiple partitions on the chip. For some games one is a backup partition, some other games seem to use only one partition, yet other games actually use multiple partitions. Partitions are defined at the start of the de-wearleveled blob. At offset 0x200 into the image, the DIFI blobs start. These 0x130 large blobs describe the partitions. Every DIFI blob describes a partition. In order to find the partitions, you will need the uint32_t at 0x9C into the DIFI blob, and the uint32_t at 0xA4. The uint32_t at 0x9C describes the length of the hash table at the start of the partition, the uint32_t at 0xA4 is the length of the filesystem. Partitions are catted together, so the end of one partition is the beginning of the next. The first partition starts at 0x2000. The hashtable at the start of the partitions describe each block in the partition with a SHA256 of the 0x1000 sized block.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles are stored on the FLASH in a custom filesystem called SAVE. SAVE has a header which describes where the various bits of the filesystem live. The most important is the FST or filesystem table. You can find the FST by first finding the file base offset which is the offset to which all the entries in the FST are relative. The file base offset is a uint16_t at 0x58 from the filesystem start. The FST offset is a uint32_t at 0x6C and is in blocks (which are 0x200 bytes large).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve found the FST, parsing it is fairly straightforward.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct fs_entry {&lt;br /&gt;
     u32 node_cnt;&lt;br /&gt;
     u8  filename[0x10];&lt;br /&gt;
     u32 index;&lt;br /&gt;
     u32 unk1; // magic?&lt;br /&gt;
     u32 block_offset;&lt;br /&gt;
     u32 file_size;&lt;br /&gt;
     u32 unk2;&lt;br /&gt;
     u32 unk3; // flags and/or date?&lt;br /&gt;
     u32 unk4;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first entry is the root directory, easily identifiable by the node_cnt being larger than 1. The node_cnt includes the root directory itself, so there are node_cnt - 1 files in the root directory. The entries that follow after the root directory are the actual files. Reading them out is as simple as taking the file base offset and adding (block_offset * 0x200) to it.&lt;br /&gt;
&lt;br /&gt;
Example from Super MonkeyBall 3D:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0003800: 04000000 21000000 00000000 00000000  ....!...........&lt;br /&gt;
0003810: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003820: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003830: 01000000 736d6233 64732e64 61740000  ....smb3ds.dat..&lt;br /&gt;
0003840: 00000000 00000000 d57b1100 05000000  .........{......&lt;br /&gt;
0003850: e4060000 00000000 c8cf0008 00000000  ................&lt;br /&gt;
0003860: 01000000 6d677265 706c6179 30302e64  ....mgreplay00.d&lt;br /&gt;
0003870: 61740000 01000000 d57b1100 09000000  at.......{......&lt;br /&gt;
0003880: 1c210000 00000000 cd331000 00000000  .!.......3......&lt;br /&gt;
0003890: 01000000 6d677265 706c6179 30312e64  ....mgreplay01.d&lt;br /&gt;
00038a0: 61740000 02000000 d57b1100 1a000000  at.......{......&lt;br /&gt;
00038b0: 1c210000 00000000 00000000 00000000  .!..............&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=313</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=313"/>
		<updated>2011-04-12T15:26:14Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Partitions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps and a journal. The blockmap is located at offset 0 of the flash chip, and is immediately followed by the journal. The initial state is dictated by the blockmap, and the journal is then applied to that.&lt;br /&gt;
&lt;br /&gt;
The blockmap structure is simple:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct header_entry {&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
        uint8_t phys_sec;&lt;br /&gt;
        uint8_t alloc_cnt;&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The journal structure is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry{&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
}__attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Partitions ===&lt;br /&gt;
&lt;br /&gt;
There can be multiple partitions on the chip. For some games one is a backup partition, some other games seem to use only one partition, yet other games actually use multiple partitions. Partitions are defined at the start of the de-wearleveled blob. At offset 0x200 into the image, the DIFI blobs start. These 0x130 large blobs describe the partitions. Every DIFI blob describes a partition. In order to find the partitions, you will need the uint32_t at 0x9C into the DIFI blob, and the uint32_t at 0xA4. The uint32_t at 0x9C describes the beginning of the filesystem from the base of the partition, the uint32_t at 0xA4 is the length of the filesystem. Partitions are catted together, so the end of one partition is the beginning of the next. The first partition starts at 0x2000.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles are stored on the FLASH in a custom filesystem called SAVE. SAVE has a header which describes where the various bits of the filesystem live. The most important is the FST or filesystem table. You can find the FST by first finding the file base offset which is the offset to which all the entries in the FST are relative. The file base offset is a uint16_t at 0x58 from the filesystem start. The FST offset is a uint32_t at 0x6C and is in blocks (which are 0x200 bytes large).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve found the FST, parsing it is fairly straightforward.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct fs_entry {&lt;br /&gt;
     u32 node_cnt;&lt;br /&gt;
     u8  filename[0x10];&lt;br /&gt;
     u32 index;&lt;br /&gt;
     u32 unk1; // magic?&lt;br /&gt;
     u32 block_offset;&lt;br /&gt;
     u32 file_size;&lt;br /&gt;
     u32 unk2;&lt;br /&gt;
     u32 unk3; // flags and/or date?&lt;br /&gt;
     u32 unk4;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first entry is the root directory, easily identifiable by the node_cnt being larger than 1. The node_cnt includes the root directory itself, so there are node_cnt - 1 files in the root directory. The entries that follow after the root directory are the actual files. Reading them out is as simple as taking the file base offset and adding (block_offset * 0x200) to it.&lt;br /&gt;
&lt;br /&gt;
Example from Super MonkeyBall 3D:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0003800: 04000000 21000000 00000000 00000000  ....!...........&lt;br /&gt;
0003810: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003820: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003830: 01000000 736d6233 64732e64 61740000  ....smb3ds.dat..&lt;br /&gt;
0003840: 00000000 00000000 d57b1100 05000000  .........{......&lt;br /&gt;
0003850: e4060000 00000000 c8cf0008 00000000  ................&lt;br /&gt;
0003860: 01000000 6d677265 706c6179 30302e64  ....mgreplay00.d&lt;br /&gt;
0003870: 61740000 01000000 d57b1100 09000000  at.......{......&lt;br /&gt;
0003880: 1c210000 00000000 cd331000 00000000  .!.......3......&lt;br /&gt;
0003890: 01000000 6d677265 706c6179 30312e64  ....mgreplay01.d&lt;br /&gt;
00038a0: 61740000 02000000 d57b1100 1a000000  at.......{......&lt;br /&gt;
00038b0: 1c210000 00000000 00000000 00000000  .!..............&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=299</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=299"/>
		<updated>2011-04-11T16:05:46Z</updated>

		<summary type="html">&lt;p&gt;Erant: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps and a journal. The blockmap is located at offset 0 of the flash chip, and is immediately followed by the journal. The initial state is dictated by the blockmap, and the journal is then applied to that.&lt;br /&gt;
&lt;br /&gt;
The blockmap structure is simple:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct header_entry {&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
        uint8_t phys_sec;&lt;br /&gt;
        uint8_t alloc_cnt;&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The journal structure is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry{&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
}__attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Partitions ===&lt;br /&gt;
&lt;br /&gt;
There can be multiple partitions on the chip. For some games one is a backup partition, some other games seem to use only one partition, yet other games actually use multiple partitions.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles are stored on the FLASH in a custom filesystem called SAVE. SAVE has a header which describes where the various bits of the filesystem live. The most important is the FST or filesystem table. You can find the FST by first finding the file base offset which is the offset to which all the entries in the FST are relative. The file base offset is a uint16_t at 0x58 from the filesystem start. The FST offset is a uint32_t at 0x6C and is in blocks (which are 0x200 bytes large).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve found the FST, parsing it is fairly straightforward.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct fs_entry {&lt;br /&gt;
     u32 node_cnt;&lt;br /&gt;
     u8  filename[0x10];&lt;br /&gt;
     u32 index;&lt;br /&gt;
     u32 unk1; // magic?&lt;br /&gt;
     u32 block_offset;&lt;br /&gt;
     u32 file_size;&lt;br /&gt;
     u32 unk2;&lt;br /&gt;
     u32 unk3; // flags and/or date?&lt;br /&gt;
     u32 unk4;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first entry is the root directory, easily identifiable by the node_cnt being larger than 1. The node_cnt includes the root directory itself, so there are node_cnt - 1 files in the root directory. The entries that follow after the root directory are the actual files. Reading them out is as simple as taking the file base offset and adding (block_offset * 0x200) to it.&lt;br /&gt;
&lt;br /&gt;
Example from Super MonkeyBall 3D:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0003800: 04000000 21000000 00000000 00000000  ....!...........&lt;br /&gt;
0003810: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003820: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003830: 01000000 736d6233 64732e64 61740000  ....smb3ds.dat..&lt;br /&gt;
0003840: 00000000 00000000 d57b1100 05000000  .........{......&lt;br /&gt;
0003850: e4060000 00000000 c8cf0008 00000000  ................&lt;br /&gt;
0003860: 01000000 6d677265 706c6179 30302e64  ....mgreplay00.d&lt;br /&gt;
0003870: 61740000 01000000 d57b1100 09000000  at.......{......&lt;br /&gt;
0003880: 1c210000 00000000 cd331000 00000000  .!.......3......&lt;br /&gt;
0003890: 01000000 6d677265 706c6179 30312e64  ....mgreplay01.d&lt;br /&gt;
00038a0: 61740000 02000000 d57b1100 1a000000  at.......{......&lt;br /&gt;
00038b0: 1c210000 00000000 00000000 00000000  .!..............&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=296</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=296"/>
		<updated>2011-04-11T13:26:18Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Filesystem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps and a journal. The blockmap is located at offset 0 of the flash chip, and is immediately followed by the journal. The initial state is dictated by the blockmap, and the journal is then applied to that.&lt;br /&gt;
&lt;br /&gt;
The blockmap structure is simple:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct header_entry {&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
        uint8_t phys_sec;&lt;br /&gt;
        uint8_t alloc_cnt;&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The journal structure is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry{&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
}__attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles are stored on the FLASH in a custom filesystem called SAVE. SAVE has a header which describes where the various bits of the filesystem live. The most important is the FST or filesystem table. You can find the FST by first finding the file base offset which is the offset to which all the entries in the FST are relative. The file base offset is a uint16_t at 0x58 from the filesystem start. The FST offset is a uint32_t at 0x6C and is in blocks (which are 0x200 bytes large).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve found the FST, parsing it is fairly straightforward.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct fs_entry {&lt;br /&gt;
     u32 node_cnt;&lt;br /&gt;
     u8  filename[0x10];&lt;br /&gt;
     u32 index;&lt;br /&gt;
     u32 unk1; // magic?&lt;br /&gt;
     u32 block_offset;&lt;br /&gt;
     u32 file_size;&lt;br /&gt;
     u32 unk2;&lt;br /&gt;
     u32 unk3; // flags and/or date?&lt;br /&gt;
     u32 unk4;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first entry is the root directory, easily identifiable by the node_cnt being larger than 1. The node_cnt includes the root directory itself, so there are node_cnt - 1 files in the root directory. The entries that follow after the root directory are the actual files. Reading them out is as simple as taking the file base offset and adding (block_offset * 0x200) to it.&lt;br /&gt;
&lt;br /&gt;
Example from Super MonkeyBall 3D:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0003800: 04000000 21000000 00000000 00000000  ....!...........&lt;br /&gt;
0003810: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003820: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003830: 01000000 736d6233 64732e64 61740000  ....smb3ds.dat..&lt;br /&gt;
0003840: 00000000 00000000 d57b1100 05000000  .........{......&lt;br /&gt;
0003850: e4060000 00000000 c8cf0008 00000000  ................&lt;br /&gt;
0003860: 01000000 6d677265 706c6179 30302e64  ....mgreplay00.d&lt;br /&gt;
0003870: 61740000 01000000 d57b1100 09000000  at.......{......&lt;br /&gt;
0003880: 1c210000 00000000 cd331000 00000000  .!.......3......&lt;br /&gt;
0003890: 01000000 6d677265 706c6179 30312e64  ....mgreplay01.d&lt;br /&gt;
00038a0: 61740000 02000000 d57b1100 1a000000  at.......{......&lt;br /&gt;
00038b0: 1c210000 00000000 00000000 00000000  .!..............&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=290</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=290"/>
		<updated>2011-04-10T22:28:36Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Wearleveling */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps and a journal. The blockmap is located at offset 0 of the flash chip, and is immediately followed by the journal. The initial state is dictated by the blockmap, and the journal is then applied to that.&lt;br /&gt;
&lt;br /&gt;
The blockmap structure is simple:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct header_entry {&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
        uint8_t phys_sec;&lt;br /&gt;
        uint8_t alloc_cnt;&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The journal structure is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry{&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
}__attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles stored on the FLASH are using a custom FS.&lt;br /&gt;
 &lt;br /&gt;
It seems the file entries are stored somewhere in the third block. &lt;br /&gt;
&lt;br /&gt;
The first entry is the root directory, stored with a filename of &#039;!&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct fs_entry {&lt;br /&gt;
     u32 nodes;&lt;br /&gt;
     u8  filename[0x10];&lt;br /&gt;
     u32 index;&lt;br /&gt;
     u32 unk1; // magic?&lt;br /&gt;
     u32 block_offset;&lt;br /&gt;
     u32 file_size;&lt;br /&gt;
     u32 unk2;&lt;br /&gt;
     u32 unk3; // flags and/or date?&lt;br /&gt;
     u32 unk4;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example from Super MonkeyBall 3D:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0003800: 04000000 21000000 00000000 00000000  ....!...........&lt;br /&gt;
0003810: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003820: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003830: 01000000 736d6233 64732e64 61740000  ....smb3ds.dat..&lt;br /&gt;
0003840: 00000000 00000000 d57b1100 05000000  .........{......&lt;br /&gt;
0003850: e4060000 00000000 c8cf0008 00000000  ................&lt;br /&gt;
0003860: 01000000 6d677265 706c6179 30302e64  ....mgreplay00.d&lt;br /&gt;
0003870: 61740000 01000000 d57b1100 09000000  at.......{......&lt;br /&gt;
0003880: 1c210000 00000000 cd331000 00000000  .!.......3......&lt;br /&gt;
0003890: 01000000 6d677265 706c6179 30312e64  ....mgreplay01.d&lt;br /&gt;
00038a0: 61740000 02000000 d57b1100 1a000000  at.......{......&lt;br /&gt;
00038b0: 1c210000 00000000 00000000 00000000  .!..............&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=289</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=289"/>
		<updated>2011-04-10T20:40:56Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Wearleveling */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps. Depending on the size of the flashchip, these are located somewhere at the beginning of the flashchip, in the first sector. The structure is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t phys_realloc_cnt;// Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t virt_realloc_cnt;// Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((packed));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry {&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles stored on the FLASH are using a custom FS.&lt;br /&gt;
 &lt;br /&gt;
It seems the file entries are stored somewhere in the third block. &lt;br /&gt;
&lt;br /&gt;
The first entry is the root directory, stored with a filename of &#039;!&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct fs_entry {&lt;br /&gt;
     u32 nodes;&lt;br /&gt;
     u8  filename[0x10];&lt;br /&gt;
     u32 index;&lt;br /&gt;
     u32 unk1; // magic?&lt;br /&gt;
     u32 block_offset;&lt;br /&gt;
     u32 file_size;&lt;br /&gt;
     u32 unk2;&lt;br /&gt;
     u32 unk3; // flags and/or date?&lt;br /&gt;
     u32 unk4;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example from Super MonkeyBall 3D:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0003800: 04000000 21000000 00000000 00000000  ....!...........&lt;br /&gt;
0003810: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003820: 00000000 00000000 00000000 00000000  ................&lt;br /&gt;
0003830: 01000000 736d6233 64732e64 61740000  ....smb3ds.dat..&lt;br /&gt;
0003840: 00000000 00000000 d57b1100 05000000  .........{......&lt;br /&gt;
0003850: e4060000 00000000 c8cf0008 00000000  ................&lt;br /&gt;
0003860: 01000000 6d677265 706c6179 30302e64  ....mgreplay00.d&lt;br /&gt;
0003870: 61740000 01000000 d57b1100 09000000  at.......{......&lt;br /&gt;
0003880: 1c210000 00000000 cd331000 00000000  .!.......3......&lt;br /&gt;
0003890: 01000000 6d677265 706c6179 30312e64  ....mgreplay01.d&lt;br /&gt;
00038a0: 61740000 02000000 d57b1100 1a000000  at.......{......&lt;br /&gt;
00038b0: 1c210000 00000000 00000000 00000000  .!..............&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=286</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=286"/>
		<updated>2011-04-10T18:04:23Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Wearleveling */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps. Depending on the size of the flashchip, these are located somewhere at the beginning of the flashchip, in the first sector. The structure is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t phys_realloc_cnt;// Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t virt_realloc_cnt;// Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((packed));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry {&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles stored on the FLASH are using a custom FS.&lt;br /&gt;
 &lt;br /&gt;
It seems the file entries are stored somewhere in the third block. &lt;br /&gt;
&lt;br /&gt;
An fs_entry that has nodes &amp;gt; 1, is probably a directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct fs_entry {&lt;br /&gt;
     u32 nodes;&lt;br /&gt;
     u8  filename[0x10];&lt;br /&gt;
     u32 file_id;&lt;br /&gt;
     u32 unk1;&lt;br /&gt;
     u32 block_offset;&lt;br /&gt;
     u32 file_size;&lt;br /&gt;
     u32 unk2;&lt;br /&gt;
     u32 unk3;&lt;br /&gt;
     u32 unk4;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=285</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=285"/>
		<updated>2011-04-10T17:34:54Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Filesystem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps. Depending on the size of the flashchip, these are located somewhere at the beginning of the flashchip, in the first sector. The structure is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t virt_realloc_cnt;// Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t phys_realloc_cnt;// Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((packed));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry {&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles stored on the FLASH are using a custom FS.&lt;br /&gt;
 &lt;br /&gt;
It seems the file entries are stored somewhere in the third block. &lt;br /&gt;
&lt;br /&gt;
An fs_entry that has nodes &amp;gt; 1, is probably a directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct fs_entry {&lt;br /&gt;
     u32 nodes;&lt;br /&gt;
     u8  filename[0x10];&lt;br /&gt;
     u32 file_id;&lt;br /&gt;
     u32 unk1;&lt;br /&gt;
     u32 block_offset;&lt;br /&gt;
     u32 file_size;&lt;br /&gt;
     u32 unk2;&lt;br /&gt;
     u32 unk3;&lt;br /&gt;
     u32 unk4;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=284</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=284"/>
		<updated>2011-04-10T15:10:43Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Filesystem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps. Depending on the size of the flashchip, these are located somewhere at the beginning of the flashchip, in the first sector. The structure is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t virt_realloc_cnt;// Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t phys_realloc_cnt;// Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((packed));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry {&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles stored on the FLASH are using a custom FS.&lt;br /&gt;
 &lt;br /&gt;
It seems the file entries are stored at a static offset of 0x3a00. &lt;br /&gt;
&lt;br /&gt;
An fs_entry that has nodes &amp;gt; 1, is probably a directory. If that directory has filename 0x11, it is the root dir.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct fs_entry {&lt;br /&gt;
     u32 nodes;&lt;br /&gt;
     u8  filename[0x10];&lt;br /&gt;
     u32 file_id;&lt;br /&gt;
     u32 unk1;&lt;br /&gt;
     u32 block_offset;&lt;br /&gt;
     u32 file_size;&lt;br /&gt;
     u32 unk2;&lt;br /&gt;
     u32 unk3;&lt;br /&gt;
     u32 unk4;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=201</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=201"/>
		<updated>2011-04-09T02:44:38Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Filesystem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps. Depending on the size of the flashchip, these are located somewhere at the beginning of the flashchip, in the first sector. The structure is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((packed));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry {&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles stored on the FLASH are using a custom FS.&lt;br /&gt;
 &lt;br /&gt;
It seems the file entries are stored at a static offset of 0x3a00. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 struct FileEntry {&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u8  FileName[0x10];&lt;br /&gt;
     u32 EntryID;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 FileSize;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=200</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=200"/>
		<updated>2011-04-09T02:42:35Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Filesystem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps. Depending on the size of the flashchip, these are located somewhere at the beginning of the flashchip, in the first sector. The structure is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((packed));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry {&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles stored on the FLASH are using a custom FS.&lt;br /&gt;
 &lt;br /&gt;
It is still unknown how to get correctly to the file table, but here is the file entry struct.&lt;br /&gt;
&lt;br /&gt;
 struct FileEntry {&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u8  FileName[0x10];&lt;br /&gt;
     u32 EntryID;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 FileSize;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=199</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=199"/>
		<updated>2011-04-09T02:42:23Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Encryption */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps. Depending on the size of the flashchip, these are located somewhere at the beginning of the flashchip, in the first sector. The structure is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((packed));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry {&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles stored on the EEPROM are using a custom FS.&lt;br /&gt;
 &lt;br /&gt;
It is still unknown how to get correctly to the file table, but here is the file entry struct.&lt;br /&gt;
&lt;br /&gt;
 struct FileEntry {&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u8  FileName[0x10];&lt;br /&gt;
     u32 EntryID;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 FileSize;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=198</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=198"/>
		<updated>2011-04-09T02:40:27Z</updated>

		<summary type="html">&lt;p&gt;Erant: /* Wearleveling */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on an EEPROM in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps. Depending on the size of the flashchip, these are located somewhere at the beginning of the flashchip, in the first sector. The structure is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((packed));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry {&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles stored on the EEPROM are using a custom FS.&lt;br /&gt;
 &lt;br /&gt;
It is still unknown how to get correctly to the file table, but here is the file entry struct.&lt;br /&gt;
&lt;br /&gt;
 struct FileEntry {&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u8  FileName[0x10];&lt;br /&gt;
     u32 EntryID;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 FileSize;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=197</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=197"/>
		<updated>2011-04-09T02:38:53Z</updated>

		<summary type="html">&lt;p&gt;Erant: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Encryption ===&lt;br /&gt;
&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on an EEPROM in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
=== Wearleveling ===&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wearleveling scheme on the savegame FLASH chips. This is done trough blockmaps. Depending on the size of the flashchip, these are located somewhere at the beginning of the flashchip, in the first sector. The structure is as follows:&lt;br /&gt;
&lt;br /&gt;
struct sector_entry {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((packed));&lt;br /&gt;
&lt;br /&gt;
struct long_sector_entry{&lt;br /&gt;
        struct sector_entry sector;&lt;br /&gt;
        struct sector_entry dupe;&lt;br /&gt;
        uint32_t magic;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
With magic being a constant 0x080d6ce0.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem ===&lt;br /&gt;
 &lt;br /&gt;
Savefiles stored on the EEPROM are using a custom FS.&lt;br /&gt;
 &lt;br /&gt;
It is still unknown how to get correctly to the file table, but here is the file entry struct.&lt;br /&gt;
&lt;br /&gt;
 struct FileEntry {&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u8  FileName[0x10];&lt;br /&gt;
     u32 EntryID;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 FileSize;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
     u32 Unknown;&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Gamecards&amp;diff=184</id>
		<title>Gamecards</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Gamecards&amp;diff=184"/>
		<updated>2011-04-08T15:09:37Z</updated>

		<summary type="html">&lt;p&gt;Erant: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:Gamecard.jpg|thumb|right|A 3DS gamecard]] &lt;br /&gt;
[[File:GamecardPhy.jpg|thumb|right|Close-up of PCB]] &lt;br /&gt;
&lt;br /&gt;
===Physical interface===&lt;br /&gt;
The 3DS gamecards have the same physical interface as regular DS and DSi gamecards. There is only a minor cosmetic difference in the plastic case, which has a small extruding notch on the top-right side. As such, it prevents insertion of the gamecard into old Nintendo DS or DSi systems. &lt;br /&gt;
&lt;br /&gt;
When modifying the case so that the 3DS gamecard fits in a DS or DSi system, those systems will refuse to detect the gamecard and show no banner icon.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Pin&lt;br /&gt;
!  Name&lt;br /&gt;
!  Description&lt;br /&gt;
|-&lt;br /&gt;
|  1&lt;br /&gt;
|  GND&lt;br /&gt;
|  Ground&lt;br /&gt;
|-&lt;br /&gt;
|  2&lt;br /&gt;
|  CLK&lt;br /&gt;
|  Clock. Frequencies 6.7MHz and 4.2MHz)&lt;br /&gt;
|-&lt;br /&gt;
|  3&lt;br /&gt;
|  NC&lt;br /&gt;
|  Not connected. Possibly used to program cards.&lt;br /&gt;
|-&lt;br /&gt;
|  4&lt;br /&gt;
|  RCS&lt;br /&gt;
|  ROM select, active low. Pulled low to start a ROM transfer.&lt;br /&gt;
|-&lt;br /&gt;
|  5&lt;br /&gt;
|  RST&lt;br /&gt;
|  Reset, active low. &lt;br /&gt;
|-&lt;br /&gt;
|  6&lt;br /&gt;
|  ECS&lt;br /&gt;
|  Savegame chip select, active low. Pulled low to start a savegame SPI transfer.&lt;br /&gt;
|-&lt;br /&gt;
|  7&lt;br /&gt;
|  IRQ&lt;br /&gt;
|  Removal detection.&lt;br /&gt;
|-&lt;br /&gt;
|  8&lt;br /&gt;
|  VCC&lt;br /&gt;
|  Powersupply 3.3V.&lt;br /&gt;
|-&lt;br /&gt;
|  9&lt;br /&gt;
|  DAT0&lt;br /&gt;
|  Bidirectional data bus.&lt;br /&gt;
|-&lt;br /&gt;
|  10&lt;br /&gt;
|  DAT1&lt;br /&gt;
|  Bidirectional data bus.&lt;br /&gt;
|-&lt;br /&gt;
|  11&lt;br /&gt;
|  DAT2&lt;br /&gt;
|  Bidirectional data bus.&lt;br /&gt;
|-&lt;br /&gt;
|  12&lt;br /&gt;
|  DAT3&lt;br /&gt;
|  Bidirectional data bus.&lt;br /&gt;
|-&lt;br /&gt;
|  13&lt;br /&gt;
|  DAT4&lt;br /&gt;
|  Bidirectional data bus.&lt;br /&gt;
|-&lt;br /&gt;
|  14&lt;br /&gt;
|  DAT5&lt;br /&gt;
|  Bidirectional data bus.&lt;br /&gt;
|-&lt;br /&gt;
|  15&lt;br /&gt;
|  DAT6&lt;br /&gt;
|  Bidirectional data bus / SPI data from savegame chip.&lt;br /&gt;
|-&lt;br /&gt;
|  16&lt;br /&gt;
|  DAT7&lt;br /&gt;
|  Bidirectional data bus / SPI data to savegame chip.&lt;br /&gt;
|-&lt;br /&gt;
|  17&lt;br /&gt;
|  GND&lt;br /&gt;
|  Ground&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===SPI flash===&lt;br /&gt;
So far, only one savegame FLASH chip has been identified. The chip identifies as a 0xC22211. The JEDEC manufacturer ID is Macronix, and despite the chip label saying 25L1001 it is actually an MX25L1021E. Datasheet at: http://www.macronix.com/QuickPlace/hq/PageLibrary4825740B00298A3B.nsf/h_Index/3F21BAC2E121E17848257639003A3146/$File/MX25L1021E,%203V,%201Mb,%20v0.01.pdf.&lt;br /&gt;
&lt;br /&gt;
===Protocol===&lt;br /&gt;
The communication protocol between the 3DS system and the 3DS gamecard has changed almost completely in comparison with the DS and DSi gamecard communication protocol.&lt;br /&gt;
&lt;br /&gt;
After the sixth transfer, commands change size from 8 bytes to 16 bytes. Possibly a new encryption is used, such as AES CTR.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a set of sample gamecard commands that a 3DS sends to a 3DS gamecard:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Size&lt;br /&gt;
!  Command&lt;br /&gt;
!  Description&lt;br /&gt;
|-&lt;br /&gt;
|2000&lt;br /&gt;
|9F00000000000000&lt;br /&gt;
| Reset&lt;br /&gt;
|-&lt;br /&gt;
|0000&lt;br /&gt;
|71C93FE9BB0A3B18&lt;br /&gt;
| Unknown&lt;br /&gt;
|-&lt;br /&gt;
|0004&lt;br /&gt;
|9000000000000000&lt;br /&gt;
| Get gamecard ID, response=9000FEC2&lt;br /&gt;
|-&lt;br /&gt;
|0004&lt;br /&gt;
|9000000000000000&lt;br /&gt;
| Get gamecard ID, response=9000FEC2&lt;br /&gt;
|-&lt;br /&gt;
|0004&lt;br /&gt;
|A000000000000000&lt;br /&gt;
| Unknown, response=00000000&lt;br /&gt;
|-&lt;br /&gt;
|0000&lt;br /&gt;
|3E00000000000000&lt;br /&gt;
| Enter 16-byte command mode.&lt;br /&gt;
|-&lt;br /&gt;
|07EC&lt;br /&gt;
|82000000000000000000000000000000&lt;br /&gt;
| Get header&lt;br /&gt;
|-&lt;br /&gt;
|05E3&lt;br /&gt;
|F32C92D85C9D44DED3E0E41DBE7C90D9&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|696B9D8582FB55D31B68CAFE70C74A95&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|BAA4812CA0AC9C5D19399530E3ACCCAB&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|032E&lt;br /&gt;
|178E427C22D87ADB86387249A97D321A&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|E06019B1BD5C9130ED6A4D9F4A9E7193&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|4E0D224862523BBFE2E6255F80E15F37&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|4CDF93D319FB62D0DB632A45E3E8D84C&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|9AA5D80551002F955546D296A57F0FEF&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|C12BA81AEF30DDDBD93FAD5D544C6334&lt;br /&gt;
| Encrypted, unknown&lt;br /&gt;
|-&lt;br /&gt;
|0532&lt;br /&gt;
|62EC5FB7F420AE1DC6253AE18AFA5BB3&lt;br /&gt;
| Encrypted, read address 0&lt;br /&gt;
|-&lt;br /&gt;
|0332&lt;br /&gt;
|E3FA23AA016BE0C93430D1F42FF41324&lt;br /&gt;
| Encrypted, read address 0x4000&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The header command has some initial dummy bytes, and eventually responds with a 0x200 byte header. Here&#039;s an example for Lego Starwars 3:&lt;br /&gt;
 0000000: 00 8c 03 00 00 00 04 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000010: b3 cf fb c6 6a b1 cb 20 32 af ce 35 d4 1c 74 c9  ....j.. 2..5..t.&lt;br /&gt;
 0000020: 8e 6b 27 2f 08 01 28 3b d4 30 de 44 37 f5 b0 46  .k&#039;/..(;.0.D7..F&lt;br /&gt;
 0000030: 91 59 d7 38 33 48 df 83 fd 71 84 2c 00 00 00 00  .Y.83H...q.,....&lt;br /&gt;
 0000040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000100: 4e 43 43 48 7a 7f 0e 00 00 8c 03 00 00 00 04 00  NCCHz...........&lt;br /&gt;
 0000110: 36 34 02 00 00 00 00 00 00 8c 03 00 00 00 04 00  64..............&lt;br /&gt;
 0000120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 0000150: 43 54 52 2d 50 2d 41 4c 47 50 00 00 00 00 00 00  CTR-P-ALGP......&lt;br /&gt;
 0000160: 0c 27 e3 c1 de 7b 2a e2 d3 11 4f 32 a4 ee bf 46  .&#039;...{*...O2...F&lt;br /&gt;
 0000170: 9a fd 0c f3 52 c1 1d 49 84 c2 a9 f1 d2 14 4c 63  ....R..I......Lc&lt;br /&gt;
 0000180: 00 04 00 00 00 00 00 00 00 00 00 00 01 03 00 00  ................&lt;br /&gt;
 0000190: 05 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00001a0: 06 00 00 00 1c 0a 00 00 01 00 00 00 00 00 00 00  ................&lt;br /&gt;
 00001b0: 22 0a 00 00 58 75 0e 00 01 00 00 00 00 00 00 00  &amp;quot;...Xu..........&lt;br /&gt;
 00001c0: 13 0c 04 26 15 f6 47 c4 c6 32 25 ea 9e 67 f8 a2  ...&amp;amp;..G..2%..g..&lt;br /&gt;
 00001d0: 7b 15 24 6b 88 fb c7 a9 27 25 7b 84 97 7b 78 7b  {.$k....&#039;%{..{x{&lt;br /&gt;
 00001e0: a6 5b ee 10 60 bb 6a 68 21 bb ce c6 00 03 5b 7e  .[..`.jh!.....[~&lt;br /&gt;
 00001f0: 64 fb 6e ac a7 f0 96 0c fb 1f 5a 37 08 77 28 f7  d.n.......Z7.w(.&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=110</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=110"/>
		<updated>2011-04-01T03:45:10Z</updated>

		<summary type="html">&lt;p&gt;Erant: Created page with &amp;quot;On the 3DS savegames are stored much like on the DS, that is on an EEPROM in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;On the 3DS savegames are stored much like on the DS, that is on an EEPROM in the gamecart. On the DS these savegames were stored in plaintext but on the 3DS a layer of encryption was added. This is highly likely a streamcipher, as the contents of several savegames exhibit the odd behaviour that xor-ing certain parts of the savegame together will result in the plaintext appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the streamcipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a streamcipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plaintext (in our case, zeroes) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Main_Page/Navigation&amp;diff=108</id>
		<title>Main Page/Navigation</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Main_Page/Navigation&amp;diff=108"/>
		<updated>2011-04-01T03:37:41Z</updated>

		<summary type="html">&lt;p&gt;Erant: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Main page box|Navigation|Main Page/Navigation}}&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: -.3em -1em -1em -1em;&amp;quot;&amp;gt;&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot; bgcolor=&amp;quot;#fff&amp;quot; border=&amp;quot;0&amp;quot; cellpadding=&amp;quot;2px&amp;quot; cellspacing=&amp;quot;2px&amp;quot; style=&amp;quot;margin:auto;&amp;quot;&lt;br /&gt;
|- align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#e7eef6&amp;quot;&lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &#039;&#039;&#039;General&#039;&#039;&#039;&lt;br /&gt;
! width=&amp;quot;34%&amp;quot; | &#039;&#039;&#039;3DS hardware&#039;&#039;&#039;&lt;br /&gt;
! width=&amp;quot;33%&amp;quot; | &#039;&#039;&#039;3DS software&#039;&#039;&#039;&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot; style=&amp;quot;background: #F5FAFF;&amp;quot;&lt;br /&gt;
| &lt;br /&gt;
*[[3DS exploits]]&lt;br /&gt;
*[[Glossary]]&lt;br /&gt;
*[[FAQ]]&lt;br /&gt;
|&lt;br /&gt;
*[[Hardware]]&lt;br /&gt;
*[[Gamecards]]&lt;br /&gt;
| &lt;br /&gt;
*[[Nintendo Software]]&lt;br /&gt;
*[[File Formats]]&lt;br /&gt;
*[[Title list]]&lt;br /&gt;
*[[Title metadata]]&lt;br /&gt;
*[[SD Filesystem]]&lt;br /&gt;
*[[Flash Filesystem]]&lt;br /&gt;
*[[Bootloader]]&lt;br /&gt;
*[[Savegames]]&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
{{box-footer-empty}}&lt;/div&gt;</summary>
		<author><name>Erant</name></author>
	</entry>
</feed>