Add scripts from testing usb sticks
This commit is contained in:
commit
c75e3e1268
41
analyze.py
Executable file
41
analyze.py
Executable file
@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
with open("./differences", "rb") as f:
|
||||
blocks = 0
|
||||
errors = 0
|
||||
error_bits = 0
|
||||
good = 0
|
||||
max_good = 0
|
||||
# failure_map = []
|
||||
# failures = 0
|
||||
b = f.read(512)
|
||||
while len(b) == 512:
|
||||
blocks += 1
|
||||
# failures *= 2
|
||||
if b != 512 * b'\0':
|
||||
errors += 1
|
||||
good = 0
|
||||
# for by in b:
|
||||
# for bit in range(0, 8):
|
||||
# if by & (1 << bit):
|
||||
# error_bits += 1
|
||||
# failures += 1
|
||||
# if blocks % 8 == 0:
|
||||
# failure_map += [failures]
|
||||
# failures = 0
|
||||
else:
|
||||
good += 1
|
||||
if good > max_good:
|
||||
max_good = good
|
||||
good_pos = blocks - good + 1
|
||||
b = f.read(512)
|
||||
if blocks % 100000 == 0:
|
||||
print("I'm at " + str(blocks) + " blocks")
|
||||
if len(b) != 0:
|
||||
print("Unexpected length: " + str(len(b)))
|
||||
print("Errors in " + str(errors) + " of " + str(blocks) + " blocks.")
|
||||
percent = error_bits / errors / 512 / 8 * 100
|
||||
print(str(percent) + " % der Bits in fehlerhaften Sektoren waren gekippt.")
|
||||
print("Ab Sektor " + str(good_pos) + " sind " + str(max_good) + " zusammenhängende Sektoren fehlerfrei (größter Bereich).")
|
||||
# with open("./failure_map", "wb") as f:
|
||||
# f.write(bytes(failure_map))
|
23
create-image.py
Executable file
23
create-image.py
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
overhead = b"BM\xda'\xd0\x02"+4*b"\x00"+b"z"+3*b"\x00"+b"l"+3*b"\x00"+b"\xa0\x0f"+2*b"\x00"+b"]\x0f"+2*b"\x00"+b"\x01\x00\x18"+5*b"\x00"+b"`'\xd0\x02\x13\x0b"+2*b"\x00"+b"\x13\x0b"+10*b"\x00"+b"BGRs"+48*b"\x00"+b"\x02"+15*b"\x00"
|
||||
|
||||
def getbit(filecontent, pos):
|
||||
byte_pos = pos//8
|
||||
bitpos = pos%8
|
||||
if byte_pos >= len(filecontent):
|
||||
return False
|
||||
return (filecontent[byte_pos] & (1<<(7-bitpos))) != 0
|
||||
|
||||
with open("./failure_map", "rb") as f:
|
||||
map_file = f.read()
|
||||
print("Soll: 1966080, Ist: " + str(len(map_file)))
|
||||
|
||||
with open("./map.bmp", "wb") as f:
|
||||
f.write(overhead)
|
||||
for y in range(3932, -1, -1):
|
||||
for x in range(0, 4000):
|
||||
bitpos = y * 4000 + x
|
||||
if getbit(map_file, bitpos):
|
||||
f.write(3*b"\x00")
|
||||
else:
|
||||
f.write(3*b"\xff")
|
Loading…
Reference in New Issue
Block a user