Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "3dstypes.h"
- #include "3ds.h"
- #include "draw.h"
- #include "libc.h"
- #include "crypto.h"
- #include "FS.h"
- extern void *start_addr;
- extern void *end_addr;
- /*
- 4 bytes number of entries
- entry:
- 16 bytes CTR
- 16 bytes keyY
- 4 bytes length in megabytes(round up)
- 64 bytes output filename in utf16(could use something like "/ncchcode1.romfs.xorpad")
- #define entry_ctr 0+4 //+4 because first int in the array is not an entry
- #define entry_keyY 16+4
- #define entry_megabytes 32+4
- #define entry_filename 36+4
- */
- struct ncch_info_entry {
- uint8_t CTR[16];
- uint8_t keyY[16];
- uint32_t size_mb;
- wchar_t filename[32];
- };
- struct ncch_info {
- uint32_t n_entries;
- struct ncch_info_entry entries[20];
- };
- void ncch_info_createpad(struct ncch_info_entry *info)
- {
- #define BUFFER_ADDR ((volatile uint8_t*)0x20000000)
- #define BLOCK_SIZE (0x10000)
- uint32_t handle = FileOpen(info->filename);
- setup_aeskey(0x2C, AES_BIG_INPUT|AES_NORMAL_INPUT, info->keyY);
- use_aeskey(0x2C);
- uint8_t ctr[16];
- memcpy(ctr, info->CTR, 16);
- uint8_t zero_buf[16];
- uint32_t size_bytes = info->size_mb*1024*1024;
- uint32_t i, j;
- for (i = 0; i < size_bytes; i += BLOCK_SIZE) {
- for (j = 0; (j < BLOCK_SIZE) && (i+j < size_bytes); j+= 16) {
- memset(zero_buf, 0, 16);
- set_ctr(AES_BIG_INPUT|AES_NORMAL_INPUT, ctr);
- aes_decrypt(zero_buf, (void*)BUFFER_ADDR+j, ctr, 1);
- add_ctr(ctr, 1);
- }
- FlushProcessDataCache(0xFFFF8001, (void*)BUFFER_ADDR, BLOCK_SIZE);
- FileWriteOffset(handle, (void*)BUFFER_ADDR, BLOCK_SIZE, i);
- }
- }
- static volatile u32 runOnce = 1;
- int main()
- {
- while(!runOnce) {};
- runOnce = 0;
- FlushProcessDataCache(0xFFFF8001, (void*)start_addr, start_addr-end_addr);
- ClearScreen(0x0);
- DEBUG("3DS CTR DECRYPTOR by VOiD, refactored by xerpi");
- struct ncch_info info;
- DEBUG("Opening /ncchinfo.bin ...");
- u32 handle = FileOpen(L"/ncchinfo.bin");
- FileRead(handle, &info, 4); //Read number of entries
- DEBUG("\tDone!");
- if (!info.n_entries || info.n_entries > 20) {
- ERROR("Nothing to do.(%i) :/", info.n_entries);
- return 0;
- }
- FileRead(handle, &info, sizeof(struct ncch_info));
- DEBUG("Found %i entries", info.n_entries);
- int i;
- for(i = 0; i < info.n_entries; i++) {
- /*createpad(info.entries[i].CTR,
- info.entries[i].keyY,
- info.entries[i].filename,
- info.entries[i].size_mb,
- i+1);*/
- DEBUG("Creating pad %i, size: %iMB ...", i+1, info.entries[i].filename);
- ncch_info_createpad(&info.entries[i]);
- DEBUG("\tDone!");
- }
- DEBUG("Finished!");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement