Skip to content

Instantly share code, notes, and snippets.

@mipsparc
Last active April 12, 2016 12:47
Show Gist options
  • Save mipsparc/2db7796b3f7672700486ecb0b9d75f74 to your computer and use it in GitHub Desktop.
Save mipsparc/2db7796b3f7672700486ecb0b9d75f74 to your computer and use it in GitHub Desktop.
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