File Encryptor/Decryptor [Vega / 1superchip]
#1
File Encryptor/Decryptor [Vega / 1superchip]

For Wii Console use only. No Dolphin, no Wii U.

This code will allow you to choose a file on your nand to either encrypt or decrypt it using Starlet's AES engine. The original file WILL BE REPLACED with the encrypted/decrypted version. Simply fill out all the values below and run the code. When you launch MKW, there will be a brief moment (visual glitches may occur) until you are returned to the Wii's Main Menu. The code has been executed and the file has been encrypted/decrypted.

NOTE: You need full hardware rights. Guide -> https://mkwii.com/showthread.php?tid=1596

Also, this code makes use of memory addresses 0x800007C0 thru 0x800007C3. Make sure no other codes you have equipped are using those addresses.

X = Encrypt or Decrypt
0 = Encrypt
1 = Decrypt

K = Your Key (in Hex)
V = Your IV (in Hex)
Z = Filepath (Use any online ASCII to Hex converter for assistance)

NTSC-U
C20095F4 00000042
3AE0000X 48000065
KKKKKKKK KKKKKKKK
KKKKKKKK KKKKKKKK
VVVVVVVV VVVVVVVV
VVVVVVVV VVVVVVVV
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
7FE802A6 3FC08016
387F0020 38800001
63CCADBC 7D8803A6
4E800021 7C7D1B78
3C808000 608407C0
7C982378 63CCAF3C
7D8803A6 4E800021
80780000 5460073F
4182000C 54640036
38640010 7C7B1B78
38800020 80ADA358
80A50024 3D808022
618C9490 7D8803A6
4E800021 7C7C1B78
7FA3EB78 7F84E378
7F65DB78 63CCB15C
7D8803A6 4E800021
7FA3EB78 63CCB2E4
7D8803A6 4E800021
7C0000A6 5403045E
7C600124 54198FFE
5760F0BE 7C0903A6
7F83E378 7C00186C
7C0004AC 38630004
4200FFF4 3F40CD82
38000000 48000075
3AC00004 387FFFFC
7EC903A6 84030004
901A000C 4200FFF8
7EC903A6 84030004
901A0010 4200FFF8
5783007E 907A0004
907A0008 5763E13E
3803FFFF 64009000
2C170000 41820008
64000800 48000025
2C190000 7C6000A6
4182000C 60608000
48000008 5460045E
7C000124 48000018
901A0000 801A0000
2C000000 41A0FFF8
4E800020 387F0020
38800002 63CCADBC
7D8803A6 4E800021
7C7D1B78 7F84E378
7F65DB78 63CCB220
7D8803A6 4E800021
7FA3EB78 63CCB2E4
7D8803A6 4E800021
3D80801A 618C87B8
7D8803A6 4E800020
60000000 00000000

PAL
C2009634 00000042
3AE0000X 48000065
KKKKKKKK KKKKKKKK
KKKKKKKK KKKKKKKK
VVVVVVVV VVVVVVVV
VVVVVVVV VVVVVVVV
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
7FE802A6 3FC08016
387F0020 38800001
63CCAE5C 7D8803A6
4E800021 7C7D1B78
3C808000 608407C0
7C982378 63CCAFDC
7D8803A6 4E800021
80780000 5460073F
4182000C 54640036
38640010 7C7B1B78
38800020 80ADA360
80A50024 3D808022
618C9814 7D8803A6
4E800021 7C7C1B78
7FA3EB78 7F84E378
7F65DB78 63CCB1FC
7D8803A6 4E800021
7FA3EB78 63CCB384
7D8803A6 4E800021
7C0000A6 5403045E
7C600124 54198FFE
5760F0BE 7C0903A6
7F83E378 7C00186C
7C0004AC 38630004
4200FFF4 3F40CD82
38000000 48000075
3AC00004 387FFFFC
7EC903A6 84030004
901A000C 4200FFF8
7EC903A6 84030004
901A0010 4200FFF8
5783007E 907A0004
907A0008 5763E13E
3803FFFF 64009000
2C170000 41820008
64000800 48000025
2C190000 7C6000A6
4182000C 60608000
48000008 5460045E
7C000124 48000018
901A0000 801A0000
2C000000 41A0FFF8
4E800020 387F0020
38800002 63CCAE5C
7D8803A6 4E800021
7C7D1B78 7F84E378
7F65DB78 63CCB2C0
7D8803A6 4E800021
7FA3EB78 63CCB384
7D8803A6 4E800021
3D80801A 618C8858
7D8803A6 4E800020
60000000 00000000

NTSC-J
C2009590 00000042
3AE0000X 48000065
KKKKKKKK KKKKKKKK
KKKKKKKK KKKKKKKK
VVVVVVVV VVVVVVVV
VVVVVVVV VVVVVVVV
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
7FE802A6 3FC08016
387F0020 38800001
63CCAD7C 7D8803A6
4E800021 7C7D1B78
3C808000 608407C0
7C982378 63CCAEFC
7D8803A6 4E800021
80780000 5460073F
4182000C 54640036
38640010 7C7B1B78
38800020 80ADA360
80A50024 3D808022
618C9734 7D8803A6
4E800021 7C7C1B78
7FA3EB78 7F84E378
7F65DB78 63CCB11C
7D8803A6 4E800021
7FA3EB78 63CCB2A4
7D8803A6 4E800021
7C0000A6 5403045E
7C600124 54198FFE
5760F0BE 7C0903A6
7F83E378 7C00186C
7C0004AC 38630004
4200FFF4 3F40CD82
38000000 48000075
3AC00004 387FFFFC
7EC903A6 84030004
901A000C 4200FFF8
7EC903A6 84030004
901A0010 4200FFF8
5783007E 907A0004
907A0008 5763E13E
3803FFFF 64009000
2C170000 41820008
64000800 48000025
2C190000 7C6000A6
4182000C 60608000
48000008 5460045E
7C000124 48000018
901A0000 801A0000
2C000000 41A0FFF8
4E800020 387F0020
38800002 63CCAD7C
7D8803A6 4E800021
7C7D1B78 7F84E378
7F65DB78 63CCB1E0
7D8803A6 4E800021
7FA3EB78 63CCB2A4
7D8803A6 4E800021
3D80801A 618C8778
7D8803A6 4E800020
60000000 00000000

NTSC-K
C200973C 00000042
3AE0000X 48000065
KKKKKKKK KKKKKKKK
KKKKKKKK KKKKKKKK
VVVVVVVV VVVVVVVV
VVVVVVVV VVVVVVVV
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
ZZZZZZZZ ZZZZZZZZ
7FE802A6 3FC08016
387F0020 38800001
63CCAEF8 7D8803A6
4E800021 7C7D1B78
3C808000 608407C0
7C982378 63CCB078
7D8803A6 4E800021
80780000 5460073F
4182000C 54640036
38640010 7C7B1B78
38800020 80ADA380
80A50024 3D808022
618C9B88 7D8803A6
4E800021 7C7C1B78
7FA3EB78 7F84E378
7F65DB78 63CCB298
7D8803A6 4E800021
7FA3EB78 63CCB420
7D8803A6 4E800021
7C0000A6 5403045E
7C600124 54198FFE
5760F0BE 7C0903A6
7F83E378 7C00186C
7C0004AC 38630004
4200FFF4 3F40CD82
38000000 48000075
3AC00004 387FFFFC
7EC903A6 84030004
901A000C 4200FFF8
7EC903A6 84030004
901A0010 4200FFF8
5783007E 907A0004
907A0008 5763E13E
3803FFFF 64009000
2C170000 41820008
64000800 48000025
2C190000 7C6000A6
4182000C 60608000
48000008 5460045E
7C000124 48000018
901A0000 801A0000
2C000000 41A0FFF8
4E800020 387F0020
38800002 63CCAEF8
7D8803A6 4E800021
7C7D1B78 7F84E378
7F65DB78 63CCB35C
7D8803A6 4E800021
7FA3EB78 63CCB420
7D8803A6 4E800021
3D80801A 618C8BB4
7D8803A6 4E800020
60000000 00000000



Code creators: Vega, 1superchip
Code credits: Bushing & Sven Peter (AES engine), Megazig (ISFS and OSReturnToMenu), RiiDefi (Egg Alloc)

NOTICE: This source is licensed under GPLv2.



// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License 2.0 for more details.

#START ASSEMBLY

#Address Ports
#800095F4 = NTSC-U
#80009634 = PAL
#80009590 = NTSC-J
#8000973C = NTSC-K

#Compilation Region Setting

.set region, '' #Fill in E, P, J, or K within the quotes for your region when Compiling! Lowercase letters can also be used.

#r31 = LUT Pointer
#r30 = ISFS Upper 16 bits for Macro
#r29 = fd backup
#r28 = heap pointer
#r27 = file size (adjusted) backup
#r26 = AES Upper 16 bits
#r25 = MSR Backup
#r24 = 0x800007C0
#r23 = Decrypt/Encrypt flag
#r22 = CTR for Key and IV sending
#800007C0 = EVA (word) spot where file size is dumped to

.macro call_egg address
lis r12, \address@h
ori r12, r12, \address@l
mtlr r12
blrl
.endm

.macro call_isfs address
ori r12, r30, \address@l
mtlr r12
blrl
.endm

.macro call_nolink address
lis r12, \address@h
ori r12, r12, \address@l
mtlr r12
blr
.endm

.set DecryptEncryptFlag, 1 #Set to 0 to decrypt, 1 to encrypt
.set key1, 0xABCDABCD #Edit in whatever Key you are using
.set key2, 0xFFEEFFEE
.set key3, 0x12121212
.set key4, 0x55559999

.set iv1, 0x2EF70033 #Edit in whatever IV you are using
.set iv2, 0xAABD7EC1
.set iv3, 0x00000005
.set iv4, 0x1C00791C

.if (region == 'E' || region == 'e') # RMCE
.set ISFS_Open, 0xADBC
.set ISFS_Read, 0xB15C
.set ISFS_Write, 0xB220
.set ISFS_Close, 0xB2E4
.set ISFS_GetFileStats, 0xAF3C
.set Wii_Menu, 0x801A87B8
.set Egg_Alloc, 0x80229490
.set Egg_Offset, 0xFFFFA358
.elseif (region == 'P' || region == 'p') # RMCP
.set ISFS_Open, 0xAE5C
.set ISFS_Read, 0xB1FC
.set ISFS_Write, 0xB2C0
.set ISFS_Close, 0xB384
.set ISFS_GetFileStats, 0xAFDC
.set Wii_Menu, 0x801A8858
.set Egg_Alloc, 0x80229814
.set Egg_Offset, 0xFFFFA360
.elseif (region == 'J' || region == 'j') # RMCJ
.set ISFS_Open, 0xAD7C
.set ISFS_Read, 0xB11C
.set ISFS_Write, 0xB1E0
.set ISFS_Close, 0xB2A4
.set ISFS_GetFileStats, 0xAEFC
.set Wii_Menu, 0x801A8778
.set Egg_Alloc, 0x80229734
.set Egg_Offset, 0xFFFFA360
.elseif (region == 'K' || region == 'k') # RMCK
.set ISFS_Open, 0xAEF8
.set ISFS_Read, 0xB298
.set ISFS_Write, 0xB35C
.set ISFS_Close, 0xB420
.set ISFS_GetFileStats, 0xB078
.set Wii_Menu, 0x801A8BB4
.set Egg_Alloc, 0x80229B88
.set Egg_Offset, 0xFFFFA380
.else # Invalid Region
.err
.endif

li r23, 1 #Flag, 1 used for compilaton

bl lut_table

.long key1
.long key2
.long key3
.long key4
.long iv1
.long iv2
.long iv3
.long iv4
.llong 0 #Start of file path, max length is 0x40 (includes final bull byte). Set to Null so source can compile, adjust this on compiled code!
.llong 0
.llong 0
.llong 0
.llong 0
.llong 0
.llong 0
.llong 0

lut_table:
mflr r31

set_isfs_upperbits:
lis r30, 0x8016

isfs_open_read:
addi r3, r31, 0x20
li r4, 1
call_isfs ISFS_Open
mr r29, r3

isfs_getfilestats:
lis r4, 0x8000
ori r4, r4, 0x07C0
mr r24, r4
call_isfs ISFS_GetFileStats

get_file_size:
lwz r3, 0 (r24)

align_16_bytes:
clrlwi. r0, r3, 28 #Check if file size is divisible by 0x10 (16), leave 4 right-side bits exposed for comparison
beq- already_16_byte_aligned_size

clrrwi r4, r3, 4 #Erase last 4 bits; Increment file size so it is divisible by 0x10

addi r3, r4, 0x10 #File size currently rounded down, increment size to next value that is 16-byte aligned

already_16_byte_aligned_size:
mr r27, r3

alloc_memory:
li r4, 0x20
lwz r5, Egg_Offset (r13)
lwz r5, 0x24 (r5)
call_egg Egg_Alloc
mr r28, r3 #save heap pointer

readfile:
mr r3, r29
mr r4, r28
mr r5, r27
call_isfs ISFS_Read

closefile:
mr r3, r29
call_isfs ISFS_Close

disable_interrupts:
mfmsr r0
rlwinm r3, r0, 0, 17, 15 #Flip off 'Allow interrupts' bit
mtmsr r3 #Update MSR
rlwinm r25, r0, 17, 31, 31 #Backup modified MSR state

data_cache_block_store: #Needed or else AES engine won't work due to old values in cache
srwi r0, r27, 2 #Get amount of words in file size; divide by 4
mtctr r0

mr r3, r28 #Get heap pointer for cache updating

cache_loop:
dcbst 0, r3
sync #Wait for data cache updates to be completed
addi r3, r3, 4
bdnz+ cache_loop

set_starlet_address:
lis r26, 0xCD82

reset_engine:
li r0, 0
bl command_then_check

senduserKeyIV: #Key first, then IV
li r22, 4
addi r3, r31, -0x4 #Point to -0x4 in reference to where key is in LUT
mtctr r22
fifo_loop:
lwzu r0, 0x4 (r3)
stw r0, 0xC (r26)
bdnz+ fifo_loop

mtctr r22
fifo_loop2:
lwzu r0, 0x4 (r3) #r3 already set since IV is after Key
stw r0, 0x10 (r26)
bdnz+ fifo_loop2

send_sourceDMA:
clrlwi r3, r28, 1 #Change address to physical
stw r3, 0x4 (r26)

send_destDMA:
stw r3, 0x8 (r26)

calc_aesengine_blocksize:
srwi r3, r27, 4 #Divide by 0x10 to get amount of 16 byte blocks
addi r0, r3, -1 #AES Engine requires a minus 1 for 16-byte block size
oris r0, r0, 0x9000 #EXEC and ENA bits flipped high

check_flag:
cmpwi r23, 0
beq- encrypt

decrypt:
oris r0, r0, 0x0800 #Flip DEC bit high

encrypt:

activate_engine:
bl command_then_check

restore_interrupts:
cmpwi r25, 0
mfmsr r3
beq- clear_bit
ori r0, r3, 0x8000
b skip_clear_bit
clear_bit:
rlwinm r0, r3, 0, 17, 15
skip_clear_bit:
mtmsr r0
b isfs_open_write

command_then_check: #Subroutine for sending commands to the AES engine
stw r0, 0 (r26)
final_busy_check:
check_busy:
lwz r0, 0 (r26)
cmpwi r0, 0
blt- check_busy
blr

isfs_open_write:
addi r3, r31, 0x20
li r4, 2
call_isfs ISFS_Open
mr r29, r3

writefile:
mr r4, r28
mr r5, r27
call_isfs ISFS_Write

closewrittenfile:
mr r3, r29
call_isfs ISFS_Close

end_code:
call_nolink Wii_Menu
Reply
#2
Awesome. Thanks for posting it!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)