1
+ #!/usr/bin/python3
2
+ import os ,sys ,platform ,time ,shutil ,binascii
3
+
4
+ p = platform .system ()
5
+ if p == 'Windows' : #0-win, 1-lin, 2-mac, x-win lol go with the market leader i guess
6
+ OPSYS = 0
7
+ elif p == 'Linux' :
8
+ OPSYS = 1
9
+ elif p == 'Darwin' :
10
+ OPSYS = 2
11
+ else :
12
+ OPSYS = 0
13
+
14
+ cwd = os .getcwd ()
15
+ trigger = "254DEFE0.txt"
16
+ #trigger="290BEFE0.txt" #new3ds
17
+
18
+ haxid1 = bytes .fromhex ("300032003800360030003000610061003600340008909FE26988A0116808A0117B0000EFD3F021E30C109FE5104F11EE014004E0104F01EE4CF09DE5FAEFFFFF" ) #ID1 - arm injected payload in readable format
19
+ haxid1 = haxid1 .decode ("utf-16le" )
20
+ haxid1_path = ""
21
+ id1 = ""
22
+ id1_root = ""
23
+ id1_path = ""
24
+
25
+ ext_root = ""
26
+ oldtag = "_oldid1"
27
+ mode = 0 #0 setup state, 1 hax state
28
+ id0_count = 0
29
+
30
+ home_menu = [0x8f ,0x98 ,0x82 ] #us,eu,jp
31
+ mii_maker = [0x217 ,0x227 ,0x207 ]
32
+
33
+ if not os .path .exists ("Nintendo 3DS/" ):
34
+ print ("Are you sure you're running this script from the root of your SD card (right next to 'Nintendo 3DS')? You need to!" )
35
+ print ("Current dir: %s" % cwd )
36
+ time .sleep (10 )
37
+ sys .exit (0 )
38
+
39
+
40
+ for root , dirs , files in os .walk ("Nintendo 3DS/" , topdown = True ):
41
+ for name in files :
42
+ pass
43
+ for name in dirs :
44
+ if haxid1 not in name and len (name [:32 ]) == 32 :
45
+ try :
46
+ temp = int (name [:32 ],16 )
47
+ except :
48
+ continue
49
+ if type (temp ) is int :
50
+ if os .path .exists (os .path .join (root , name )+ "/extdata" ):
51
+ id1 = name
52
+ id1_root = root
53
+ id1_path = os .path .join (root , name )
54
+ if oldtag in name :
55
+ mode = 1
56
+ else :
57
+ id0_count += 1
58
+
59
+
60
+ def setup ():
61
+ global mode , id1_path , id1_root , id1
62
+ print ("Setting up..." , end = '' )
63
+ if mode :
64
+ print ("Already setup!" )
65
+ return
66
+ check (id1_path + "/dbs/title.db" , 0x31e400 , 0 )
67
+ check (id1_path + "/dbs/import.db" , 0x31e400 , 0 )
68
+ if os .path .exists (id1_path + "/extdata/" + trigger ):
69
+ os .remove (id1_path + "/extdata/" + trigger )
70
+ if not os .path .exists (id1_root + "/" + haxid1 ):
71
+ haxid1_path = id1_root + "/" + haxid1
72
+ os .mkdir (haxid1_path )
73
+ os .mkdir (haxid1_path + "/extdata" )
74
+ os .mkdir (haxid1_path + "/extdata/00000000" )
75
+ if not os .path .exists (haxid1_path + "/dbs" ):
76
+ shutil .copytree (id1_path + "/dbs" ,haxid1_path + "/dbs" )
77
+
78
+ ext_root = id1_path + "/extdata/00000000"
79
+
80
+ for i in home_menu :
81
+ temp = ext_root + "/%08X" % i
82
+ if os .path .exists (temp ):
83
+ #print(temp,haxid1_path+"/extdata/00000000/%08X" % i)
84
+ shutil .copytree (temp ,haxid1_path + "/extdata/00000000/%08X" % i )
85
+ for i in mii_maker :
86
+ temp = ext_root + "/%08X" % i
87
+ if os .path .exists (temp ):
88
+ shutil .copytree (temp ,haxid1_path + "/extdata/00000000/%08X" % i )
89
+
90
+ if os .path .exists (id1_path ):
91
+ os .rename (id1_path , id1_path + oldtag )
92
+ id1 += oldtag
93
+ id1_path = id1_root + "/" + id1
94
+ mode = 1
95
+ print (" done." )
96
+
97
+ def inject ():
98
+ if mode == 0 :
99
+ print ("Run setup first!" )
100
+ return
101
+ print ("Injecting..." , end = '' )
102
+ trigger_path = id1_root + "/" + haxid1 + "/extdata/" + trigger
103
+ if not os .path .exists (trigger_path ):
104
+ with open (trigger_path ,"w" ) as f :
105
+ f .write ("plz be haxxed mister arm9, thx" )
106
+ f .close ()
107
+ print (" done." )
108
+
109
+ def delete ():
110
+ if mode == 0 :
111
+ print ("Run setup first!" )
112
+ return
113
+ print ("Deleting..." , end = '' )
114
+ trigger_path = id1_root + "/" + haxid1 + "/extdata/" + trigger
115
+ if os .path .exists (trigger_path ):
116
+ os .remove (trigger_path )
117
+ print (" done." )
118
+
119
+ def remove ():
120
+ global mode , id1_path , id1_root , id1
121
+ print ("Removing..." , end = '' )
122
+ if mode == 0 :
123
+ print ("Nothing to remove!" )
124
+ return
125
+ if os .path .exists (id1_path ) and oldtag in id1_path :
126
+ os .rename (id1_path , id1_root + "/" + id1 [:32 ])
127
+ #print(id1_path, id1_root+"/"+id1[:32])
128
+ if os .path .exists (id1_root + "/" + haxid1 ):
129
+ shutil .rmtree (id1_root + "/" + haxid1 )
130
+ id1 = id1 [:32 ]
131
+ id1_path = id1_root + "/" + id1
132
+ mode = 0
133
+ print (" done." )
134
+
135
+ def check (keyfile , size , crc32 ):
136
+ if not os .path .exists (keyfile ):
137
+ print ("%s \n does not exist on SD card!" % keyfile )
138
+ sys .exit (0 )
139
+ elif size :
140
+ s = os .path .getsize (keyfile )
141
+ if size != s :
142
+ print ("%s \n is size %08X, not expected %08X" % (keyfile ,s ,size ))
143
+ sys .exit (0 )
144
+ elif crc32 :
145
+ with open (keyfile ,"rb" ) as f :
146
+ temp = f .read ()
147
+ c = binascii .crc32 (temp )
148
+ if crc32 != c :
149
+ print ("%s \n was not recognized as the correct file" % keyfile )
150
+ sys .exit (0 )
151
+
152
+ check ("boot9strap/boot9strap.firm" , 0 , 0x08129c1f )
153
+ check ("Nintendo 3DS/Private/00020400/phtcache.bin" , 0x7f53c , 0 )
154
+ check ("boot.firm" , 0 , 0 )
155
+ check ("boot.3dsx" , 0 , 0 )
156
+ if id0_count == 0 :
157
+ print ("\n You're supposed to be running this on the 3DS SD card!" )
158
+ print ("NOT \n %s" % cwd )
159
+ time .sleep (10 )
160
+ sys .exit (0 )
161
+ assert (id0_count == 1 )
162
+
163
+ if OPSYS == 0 : #windows
164
+ _ = os .system ('cls' )
165
+ else : #linux or mac
166
+ _ = os .system ('clear' )
167
+
168
+ print ("MSET9 SETUP by zoogie" )
169
+
170
+ print ("-- Please type in a number then hit return --\n " )
171
+ print ("1. Setup MSET9" )
172
+ print ("2. Inject trigger file %s" % trigger )
173
+ print ("3. Delete trigger file %s" % trigger )
174
+ print ("4. Remove MSET9, restore original ID1" )
175
+ print ("5. Exit" )
176
+
177
+ while 1 :
178
+ try :
179
+ command = int (input ('>>>' ))
180
+ except :
181
+ command = 42
182
+
183
+ if command == 1 :
184
+ setup ()
185
+ elif command == 2 :
186
+ inject ()
187
+ elif command == 3 :
188
+ delete ()
189
+ elif command == 4 :
190
+ remove ()
191
+ elif command == 5 :
192
+ print ("Goodbye!" )
193
+ break
194
+ else :
195
+ print ("What you say?" )
196
+
197
+ time .sleep (2 )
0 commit comments