Skip to content

Instantly share code, notes, and snippets.

@mipsparc mipsparc/fat_ls.py

Last active Apr 12, 2016
Embed
What would you like to do?
show SFN like ls on FAT12/FAT16(prototype)
import struct
FILENAME = 'testimg1'
data = open(FILENAME, 'rb').read()
dir_start = 1536 #0x600
entry_size = 32
while True:
name, attr = struct.unpack_from(b'> 11s c', data, dir_start)
if name==b'\x00'*11:
break
if not attr==b'\x0f': #avoid LFN
if name[0:1]==b'\xe5': #一文字目が削除フラグ0xE5か
print(name[1:].decode('ascii'),' (DELETED)')
else:
print(name.decode('ascii'))
dir_start += entry_size
#####結果
#$ python3 fat_info.py
#HOGEBA~1SWP
#TESO TXT
#FOOO TXT
#TESUTO TXT
#ESO~1 TXT (DELETED)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.