def dump_props(self): for i in [ ('volname', self.get_volname()), ('voldate', date2str(self.get_voldate())), ('voltime', time2str(self.get_voltime())), ]: print("%-20s: %s" % i) print() self.bs.dump()
def printFileDumpHeader(self, msg, swapDateTime=False, prettyPrint=True): offset = 17 data = [] for i in xrange(2): data += conv7_8(msg[offset:offset + 8]) offset += 8 location = '' while msg[offset] != 0: location += chr(msg[offset]) offset += 1 offset += 1 timestr = list2str(data[2:4]) if swapDateTime else list2str(data[0:2]) datestr = list2str(data[0:2]) if swapDateTime else list2str(data[2:4]) datadict = { "filename": str(bytearray(msg[5:16])), "flags": msg[16], "info.Time": time2str(struct.unpack('>H', timestr)[0]), "info.Date": date2str(struct.unpack('>H', datestr)[0]), "info.Length": struct.unpack('>I', list2str(data[4:8]))[0], "info.DeviceClass": data[8], "info.DeviceSubClass": data[9], "info.DeviceRelease": data[10], "info.FileType": data[11], "info.FileFormat": data[12], "location": location, } if prettyPrint and not self.debug: if datadict["filename"] == "=" * 11: print "%13s %8s %10s %8s %2s %2s %2s %2s %2s %2s %s" % \ ("Filename".center(13), "Size".center(8), "Date".center(8), "Time".center(8), "Fl", "Ty", "Fo", "Cl", "SC", "Re", "Path") print "-" * 80 else: print "%13s %8d %10s %8s %2s %2s %2s %2s %2s %2s %s" % \ (datadict["filename"].ljust(13), datadict["info.Length"], datadict["info.Date"], datadict["info.Time"], datadict["flags"], datadict["info.FileType"], datadict["info.FileFormat"], datadict["info.DeviceClass"], datadict["info.DeviceSubClass"], datadict["info.DeviceRelease"], repr(pretty_path(datadict["location"]))) else: print " Data:" for k, v in sorted(datadict.iteritems()): print " %s:" % k, v print " checksum:", hex(msg[offset]), \ "(calculated 0x%x)" % checksum(msg[1:offset]) if msg[offset + 1] != 0xF7: print " remaining bytes:", [hex(b) for b in msg[offset + 1:]]
def dump_contents(self,start=0,path='A:',header=True): if header: print("-"*80) empty = self.fat.nempty_clusters(self.ndata_clusters()) used = self.ndata_clusters()-empty print("Volume: %-17s %s %s %8s B used %8s B free" % ( self.get_volname(), time2str(self.get_voltime()), date2str(self.get_voldate()), used*self.bs.cluster_size(), empty*self.bs.cluster_size() )) print("-"*80) print("%s %s %s %s %s %s %s" % \ ("Name".center(16), "Size".center(8), "Time".center(8), "Date".center(10), "Att", "Cluster", "(hex)")) print("-"*80) dirs,files = self.read_dir(start,no_dotdirs=True) print(path) empty = True for d in dirs: self.dump_direntry(d,indent=2) empty = False for f in files: self.dump_direntry(f,indent=2) empty = False if empty: print(" <empty>") print() for d in dirs: if d.is_dotdir(): continue self.dump_contents( start=d.start, path=path+"\\"+d.decoded_name(), header=False)
def dump_direntry(self,de,indent=0): name = de.decoded_name() if de.is_dir(): name = '[%s]' % name print('%s%-14s %8d %s %s %2x %7d (0x%x)' % ( indent*' ', name, de.size, time2str(de.mtime), date2str(de.mdate), de.attr,de.start,self.cluster_to_offset(de.start)))