Skip to content

Commit

Permalink
2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zoogie authored and zoogie committed Feb 22, 2018
1 parent 462aecc commit fc7c967
Show file tree
Hide file tree
Showing 5 changed files with 487 additions and 64 deletions.
2 changes: 1 addition & 1 deletion bfCL
Submodule bfCL updated 2 files
+1 −1 bfcl.c
+13 −3 ocl_brute.c
Binary file modified seedminer/saves/lfcs.dat
Binary file not shown.
Binary file modified seedminer/saves/lfcs_new.dat
Binary file not shown.
146 changes: 83 additions & 63 deletions seedminer/seedminer_launcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import print_function
from __future__ import division
import os,sys,struct,glob
from binascii import hexlify, unhexlify
import os,sys,struct,glob,urllib2

#don't change this mid brute force - can be different amount multiple computers - powers of two recommended for even distribution of workload 1 2 4 8 etc.
process_count=4
Expand All @@ -21,16 +19,11 @@
err_correct=0

def int16bytes(n):
if sys.version_info[0] > 2:
# Python 3
return n.to_bytes(16, 'big')
else:
# Python 2
s=b""
for i in range(16):
s=chr(n & 0xFF)+s
n=n>>8
return s
s=""
for i in range(16):
s=chr(n & 0xFF)+s
n=n>>8
return s

def expand():
for i in range(1,len(lfcs)):
Expand Down Expand Up @@ -82,20 +75,22 @@ def getMsed3Estimate(n,isNew):
xl=(fc[i]-fc[i-1])
y=ft[i-1]
yl=(ft[i]-ft[i-1])
ys=((xs*yl)//xl)+y
ys=((xs*yl)/xl)+y
err_correct=ys
return ((n//5)-ys) | newbit
return ((n/5)-ys) | newbit

return ((n//5)-ft[ft_size-1]) | newbit
return ((n/5)-ft[ft_size-1]) | newbit

def mii_gpu():
from Cryptodome.Cipher import AES

nk31=0x59FC817E6446EA6190347B20E9BDCE52
with open("input.bin", "rb") as f:
enc=f.read()

nonce=enc[:8]+b"\x00"*4
if(len(enc) != 0x70):
print("Error: input.bin is invalid size (likely QR -> input.bin conversion issue)")
sys.exit(0)
nonce=enc[:8]+"\x00"*4
cipher = AES.new(int16bytes(nk31), AES.MODE_CCM, nonce )
dec=cipher.decrypt(enc[8:0x60])
nonce=nonce[:8]
Expand All @@ -108,16 +103,16 @@ def mii_gpu():
else:
print("Error: need to specify new|old movable.sed")
sys.exit(0)
model_str=b""
start_lfcs_old=0x0B000000//2
start_lfcs_new=0x05000000//2
model_str=""
start_lfcs_old=0x0B000000/2
start_lfcs_new=0x05000000/2
start_lfcs=0
year=0
if(len(sys.argv)==4):
year=int(sys.argv[3])

if(model=="old"):
model_str=b"\x00\x00"
model_str="\x00\x00"
if (year==2011):
start_lfcs_old=0x01000000
elif(year==2012):
Expand All @@ -137,7 +132,7 @@ def mii_gpu():
start_lfcs=start_lfcs_old

elif(model=="new"):
model_str=b"\x02\x00"
model_str="\x02\x00"
if (year==2014):
start_lfcs_new=0x00800000
elif (year==2015):
Expand All @@ -150,7 +145,7 @@ def mii_gpu():
print("Year 2014-2017 not entered so beginning at lfcs midpoint "+hex(start_lfcs_new))
start_lfcs=start_lfcs_new
start_lfcs=endian4(start_lfcs)
command="bfcl lfcs %08X %s %s %08X" % (start_lfcs, hexlify(model_str).decode('ascii'), hexlify(final[4:4+8]).decode('ascii'), endian4(offset_override))
command="bfcl lfcs %08X %s %s %08X" % (start_lfcs, model_str.encode('hex'), final[4:4+8].encode('hex'), endian4(offset_override))
print(command)
os.system(command)

Expand All @@ -159,7 +154,7 @@ def generate_part2():
with open("saves/lfcs.dat", "rb") as f:
buf=f.read()

lfcs_len=len(buf)//8
lfcs_len=len(buf)/8
err_correct=0

for i in range(lfcs_len):
Expand All @@ -171,7 +166,7 @@ def generate_part2():
with open("saves/lfcs_new.dat", "rb") as f:
buf=f.read()

lfcs_new_len=len(buf)//8
lfcs_new_len=len(buf)/8

for i in range(lfcs_new_len):
lfcs_new.append(struct.unpack("<i",buf[i*8:i*8+4])[0])
Expand All @@ -181,12 +176,12 @@ def generate_part2():

isNew=False
msed3=0
noobtest=b"\x00"*0x20
noobtest="\x00"*0x20
with open("movable_part1.sed", "rb") as f:
seed=f.read()
if(noobtest in seed[0x10:0x30]):
print("Error: ID0 has been left blank, please add an ID0")
print("Ex: python %s id0 abcdef0123456789abcdef0123456789" % (sys.argv[0]))
print("Ex: python %s id0 abcdef012345EXAMPLEdef0123456789" % (sys.argv[0]))
sys.exit(0)
if(noobtest[:4] in seed[:4]):
print("Error: LFCS has been left blank, did you do a complete two-way friend code exchange before dumping friendlist?")
Expand All @@ -195,10 +190,10 @@ def generate_part2():
print("Error: movable_part1.sed is not 4KB")
sys.exit(0)

if seed[4:5]==b"\x02":
if seed[4:5]=="\x02":
print("New3DS msed")
isNew=True
elif seed[4:5]==b"\x00":
elif seed[4:5]=="\x00":
print("Old3DS msed - this can happen on a New3DS")
isNew=False
else:
Expand All @@ -212,51 +207,47 @@ def generate_part2():
msed3=getMsed3Estimate(bytes2int(seed[0:4]),isNew)

offset=0x10
hash_final=b""
hash_final=""
for i in range(64):
try:
hash=unhexlify(seed[offset:offset+0x20])
hash=seed[offset:offset+0x20].decode("hex")
except:
break
hash_single=byteSwap4(hash[0:4])+byteSwap4(hash[4:8])+byteSwap4(hash[8:12])+byteSwap4(hash[12:16])
print("ID0 hash "+str(i)+": "+hexlify(hash_single).decode('ascii'))
print("ID0 hash "+str(i)+": "+hash_single.encode('hex'))
hash_final+=hash_single
offset+=0x20

print("Hash total: "+str(i))
part2=seed[0:12]+int2bytes(msed3)+hash_final

pad=0x1000-len(part2)
part2+=b"\x00"*pad
part2+="\x00"*pad

with open("movable_part2.sed", "wb") as f:
f.write(part2)
print("movable_part2.sed generation success")

def hash_clusterer():
buf=b""
buf=""
hashcount=0

with open("movable_part1.sed", "rb") as f:
file=f.read()
with open("movable_part1.sed.backup", "wb") as f:
f.write(file)

trim=0
try:
trim=file.index(b"\x00"*0x40)
if(trim<0x10):
trim=0x10
file=file[:trim]
except:
pass

if(len(sys.argv)==3):
dirs=[]
dirs.append(sys.argv[2])
else:
dirs=glob.glob("*")


try:
with open("movable_part1.sed", "rb") as f:
file=f.read()
except:
print("movable_part1.sed not found, generating a new one")
print("don't forget to add an lfcs to it!")
with open("movable_part1.sed", "wb") as f:
file="\x00"*0x1000
f.write(file)

for i in dirs:
try:
print(i,end='')
Expand All @@ -274,16 +265,22 @@ def hash_clusterer():
if(hashcount>1):
print("Too many ID0 dirs! (%d)\nMove the ones your 3ds isn't using!" % (hashcount))
sys.exit(0)

if(hashcount==1):
print("Hash added!")
else:
print("No hashes added!")
sys.exit(0)

with open("movable_part1.sed.backup", "wb") as f:
f.write(file)

file=file[:0x10]
pad_len=0x1000-len(file+buf)
pad=b"\x00"*pad_len
pad="\x00"*pad_len
with open("movable_part1.sed", "wb") as f:
f.write(file+buf+pad)
print("There are now %d ID0 hashes in your movable_part1.sed!" % ((len(file+buf)//0x20)))
print("There are now %d ID0 hashes in your movable_part1.sed!" % ((len(file+buf)/0x20)))
print("Done!")

def do_cpu():
Expand All @@ -299,7 +296,7 @@ def do_cpu():
address_begin=0
address_end=MAX

address_space=MAX//number_of_computers
address_space=MAX/number_of_computers

for i in range(number_of_computers):
if(which_computer_is_this==i):
Expand All @@ -314,7 +311,7 @@ def do_cpu():
print("")

process_space=address_end-address_begin
process_size=process_space//process_count
process_size=process_space/process_count

for i in range(process_count):
process_begin=address_begin+(process_size*i)
Expand All @@ -329,35 +326,51 @@ def do_cpu():
def do_gpu():
with open("movable_part2.sed", "rb") as f:
buf=f.read()
keyy=hexlify(buf[:16]).decode('ascii')
ID0=hexlify(buf[16:32]).decode('ascii')
keyy=buf[:16].encode('hex')
ID0=buf[16:32].encode('hex')
command="bfcl msky %s %s %08X" % (keyy,ID0, endian4(offset_override))
print(command)
os.system(command)

def download(url, dest):
try:
response = urllib2.urlopen(url)
html = response.read()
data=""
with open(dest, "rb") as f:
data=f.read()
if(data != html):
with open(dest, "wb") as f:
f.write(html)
print("Updating "+dest+" success!")
else:
print(dest+" is already up-to-date!")
except:
print("Error updating "+dest)

def update_db():
download("https://github.com/zoogie/seedminer/blob/master/seedminer/saves/lfcs.dat?raw=true","saves/lfcs.dat")
download("https://github.com/zoogie/seedminer/blob/master/seedminer/saves/lfcs_new.dat?raw=true","saves/lfcs_new.dat")

def error_print():
print("\nCommand line error")
print("Usage:")
print("python %s cpu|gpu|id0|mii old|mii new [# cpu processes] [ID0 hash] [year 3ds built]" % (sys.argv[0]))
print("python %s cpu|gpu|id0|mii old|mii new|update-db [# cpu processes] [ID0 hash] [year 3ds built]" % (sys.argv[0]))
print("Examples:")
print("python %s cpu 4" % (sys.argv[0]))
print("python %s gpu" % (sys.argv[0]))
print("python %s id0 abcdef012345EXAMPLEdef0123456789" % (sys.argv[0]))
print("python %s mii new 2017" % (sys.argv[0]))
print("python %s mii old 2011" % (sys.argv[0]))
print("python %s mii old" % (sys.argv[0]))
print("python %s update-db" % (sys.argv[0]))
#---------------------------------------------------------------------------
#command handler
#---------------------------------------------------------------------------
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)

# "SEEDMINER_ALLOW3" is checked to allow Python 3 during testing.
# It should be removed when 3 is ready for everyone to use.
if(sys.version_info[0] != 2 and os.environ.get('SEEDMINER_ALLOW3') != '1'):
print("For the highest levels of customer safety and satisfaction, please use Python 2")
sys.exit(0)
if(len(sys.argv) < 2 or len(sys.argv) > 4):
error_print()
sys.exit(0)
Expand All @@ -379,6 +392,13 @@ def error_print():
elif(sys.argv[1].lower()=="mii"):
print("MII selected")
mii_gpu()
generate_part2()
offset_override=0
do_gpu()
sys.exit(0)
elif(sys.argv[1].lower()=="update-db"):
print("Update msed_data selected")
update_db()
sys.exit(0)
else:
error_print()
Expand Down
Loading

0 comments on commit fc7c967

Please sign in to comment.