2014-06-24 04:00:39 +00:00
|
|
|
/* [MS-CFB] 2.6.1 Compound File Directory Entry */
|
2017-11-05 16:54:11 +00:00
|
|
|
function read_directory(dir_start/*:number*/, sector_list/*:SectorList*/, sectors/*:Array<RawBytes>*/, Paths/*:Array<string>*/, nmfs, files, FileIndex, mini) {
|
2014-06-24 04:00:39 +00:00
|
|
|
var minifat_store = 0, pl = (Paths.length?2:0);
|
|
|
|
var sector = sector_list[dir_start].data;
|
2017-07-28 17:53:08 +00:00
|
|
|
var i = 0, namelen = 0, name;
|
2014-06-24 04:00:39 +00:00
|
|
|
for(; i < sector.length; i+= 128) {
|
2017-07-28 17:53:08 +00:00
|
|
|
var blob/*:CFBlob*/ = /*::(*/sector.slice(i, i+128)/*:: :any)*/;
|
2014-06-24 04:00:39 +00:00
|
|
|
prep_blob(blob, 64);
|
|
|
|
namelen = blob.read_shift(2);
|
|
|
|
name = __utf16le(blob,0,namelen-pl);
|
|
|
|
Paths.push(name);
|
2017-07-28 17:53:08 +00:00
|
|
|
var o/*:CFBEntry*/ = ({
|
2014-06-24 04:00:39 +00:00
|
|
|
name: name,
|
|
|
|
type: blob.read_shift(1),
|
|
|
|
color: blob.read_shift(1),
|
|
|
|
L: blob.read_shift(4, 'i'),
|
|
|
|
R: blob.read_shift(4, 'i'),
|
|
|
|
C: blob.read_shift(4, 'i'),
|
|
|
|
clsid: blob.read_shift(16),
|
2017-07-28 17:53:08 +00:00
|
|
|
state: blob.read_shift(4, 'i'),
|
|
|
|
start: 0,
|
|
|
|
size: 0
|
|
|
|
});
|
|
|
|
var ctime/*:number*/ = blob.read_shift(2) + blob.read_shift(2) + blob.read_shift(2) + blob.read_shift(2);
|
|
|
|
if(ctime !== 0) o.ct = read_date(blob, blob.l-8);
|
|
|
|
var mtime/*:number*/ = blob.read_shift(2) + blob.read_shift(2) + blob.read_shift(2) + blob.read_shift(2);
|
|
|
|
if(mtime !== 0) o.mt = read_date(blob, blob.l-8);
|
2014-06-24 04:00:39 +00:00
|
|
|
o.start = blob.read_shift(4, 'i');
|
|
|
|
o.size = blob.read_shift(4, 'i');
|
2017-08-09 06:50:59 +00:00
|
|
|
if(o.size < 0 && o.start < 0) { o.size = o.type = 0; o.start = ENDOFCHAIN; o.name = ""; }
|
2014-06-24 04:00:39 +00:00
|
|
|
if(o.type === 5) { /* root */
|
|
|
|
minifat_store = o.start;
|
|
|
|
if(nmfs > 0 && minifat_store !== ENDOFCHAIN) sector_list[minifat_store].name = "!StreamData";
|
|
|
|
/*minifat_size = o.size;*/
|
|
|
|
} else if(o.size >= 4096 /* MSCSZ */) {
|
|
|
|
o.storage = 'fat';
|
2014-11-03 04:02:42 +00:00
|
|
|
if(sector_list[o.start] === undefined) sector_list[o.start] = get_sector_list(sectors, o.start, sector_list.fat_addrs, sector_list.ssz);
|
2014-06-24 04:00:39 +00:00
|
|
|
sector_list[o.start].name = o.name;
|
2017-07-28 17:53:08 +00:00
|
|
|
o.content = (sector_list[o.start].data.slice(0,o.size)/*:any*/);
|
2014-06-24 04:00:39 +00:00
|
|
|
} else {
|
|
|
|
o.storage = 'minifat';
|
2018-02-12 07:30:44 +00:00
|
|
|
if(o.size < 0) o.size = 0;
|
|
|
|
else if(minifat_store !== ENDOFCHAIN && o.start !== ENDOFCHAIN && sector_list[minifat_store]) {
|
2017-11-05 16:54:11 +00:00
|
|
|
o.content = get_mfat_entry(o, sector_list[minifat_store].data, (sector_list[mini]||{}).data);
|
2014-06-24 04:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-12 07:30:44 +00:00
|
|
|
if(o.content) prep_blob(o.content, 0);
|
2014-06-24 04:00:39 +00:00
|
|
|
files[name] = o;
|
|
|
|
FileIndex.push(o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 17:53:08 +00:00
|
|
|
function read_date(blob/*:RawBytes|CFBlob*/, offset/*:number*/)/*:Date*/ {
|
2014-06-24 04:00:39 +00:00
|
|
|
return new Date(( ( (__readUInt32LE(blob,offset+4)/1e7)*Math.pow(2,32)+__readUInt32LE(blob,offset)/1e7 ) - 11644473600)*1000);
|
|
|
|
}
|
|
|
|
|