Skip to content

Commit 02ba4c0

Browse files
committed
*db/read +db/chunkparsers
db/read: - since File.readBytes is temporarily down, there's now a replacement for it in there; - all affected files also modified db/chunkparsers: - I'm now collecting the chunked file structure parsers into this one cute file. They're supposed to quickly go through some common blocks, gathering the types, data offsets, data sizes (or whatever else would be necessary otherwise) and guessing the correct expected file size and reporting it too
1 parent 7dfe3c4 commit 02ba4c0

8 files changed

+95
-56
lines changed

db/Binary/archives.ancient.sg

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ cccc = [ // They often repeat the other detections below, but more standardised.
424424

425425
function isStoneCracker() {
426426
//won't recognise an archive with a zero-length file in it, by design, to minimise FPs
427-
var ihdr = X.U32(0,_BE), bhdr = X.readBytes(0,3), hdr = X.SA(0,4);
427+
var ihdr = X.U32(0,_BE), bhdr = readU8Array(0,3), hdr = X.SA(0,4);
428428
function _subdetect() {
429429
if(ihdr >= 0x08090A08 && ihdr <= 0x08090A0E && ihdr != 0x08090A09) { gen = 2; return true }
430430
if((ihdr&0xFF) >= 8 && (ihdr&0xFF) <= 0x0E)

db/Binary/audio.DSS.1.sg

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function detect() {
2626
if(charStat(dur,1).indexOf('allnum') < 0 || !isWithin(dur.slice(2,4),'00','59') || !isWithin(dur.slice(4,6),'00','59'))
2727
return false;
2828
dur = dur.slice(0,2)+'h'+dur.slice(2,4)+'m'+dur.slice(4,6)+'s';
29-
auth = X.readBytes(0xC,0x10);
29+
auth = readU8Array(0xC,0x10);
3030
if(charStat(auth,1).indexOf('allxsc') < 0) return false;
3131
else auth = decEncoding(auth,CP437);
3232
if(v1) switch(cn = X.U8(0x2A4)) {
@@ -39,7 +39,7 @@ function detect() {
3939
if(cn == 0) asz = hdrsz+3750*(dur.slice(0,2) * 3600 + dur.slice(3,5) * 60 + dur.slice(6,8)); else asz = -1
4040
cmt = "";
4141
if(v1) {
42-
cmt = X.readBytes(0x31E,0x40);
42+
cmt = readU8Array(0x31E,0x40);
4343
if(charStat(cmt,1).indexOf('allxsc') < 0) return false;
4444
else cmt = decEncoding(cmt,CP437)
4545
} else for(i = 0x240; i < 0x3A6; i += 60) {

db/Binary/bin.PalmFile.1.sg

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function detect() {
4040
switch(tp_) { case 'appl': tp = 'PRC'; break;
4141
case 'pqa ': if(by == 'clpr') tp = 'PQA'; else return;
4242
default:
43-
if(charStat(X.readBytes(p,4),true).indexOf('allasc') >= 0) {
43+
if(charStat(readU8Array(p,4),true).indexOf('allasc') >= 0) {
4444
tp = 'PRC'; bad = bad.addIfNone('!badtype')} }
4545
var dt = palmDateToStr(dtMod,'mod'),endp,reclen=8,m=i=0,mhk='',uniq=[];
4646
if(dtMod && dt === '') sus += 2;

db/Binary/bin.RPGMaker2Kdata.1.sg

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function detect() {
88
/* beautify ignore:start */
99

1010
function isLCF() { //internal
11-
if(!X.isHeuristicScan() && (!X.c("'Lcf'",1) || charStat(X.readBytes(1,X.U8(0)),1).indexOf('allasc' < 0))) return false;
11+
if(!X.isHeuristicScan() && (!X.c("'Lcf'",1) || charStat(readU8Array(1,X.U8(0)),1).indexOf('allasc' < 0))) return false;
1212
return true
1313
}
1414

@@ -150,7 +150,7 @@ if(!bDetected && isLMT()) {
150150
sName = "RPGMaker 2000/2003 map tree data (.LMT)"; bDetected = true;
151151
if(bad.length) sVersion = sVersion.appendS('malformed'+bad,'/')
152152
if(X.isVerbose()) {
153-
sOption('for: '+title); sOption(addEllipsis(maps.join(', '),0xC0), len+' maps:'); sOption(outSz(sz),'sz:')
153+
sOption('for: '+title); sOption(addEllipsis(maps.join('\r'),0xC000), len+' maps:'); sOption(outSz(sz),'sz:')
154154
}
155155
}
156156

db/Binary/databases.1.sg

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ function detect() {
99
if (Binary.compare("00010000'Standard Jet DB'00")) {
1010
sName = "Microsoft Access database (.MDB)";
1111
bDetected = true;
12-
} else if (Binary.compare("00010000'Standard ACE DB'00")) {
13-
sName = "Microsoft Access database (.MDB)";
14-
sVersion = "2010";
15-
bDetected = true;
1612
}
1713

1814
function isDBF() {
@@ -53,7 +49,7 @@ function detect() {
5349
upd = y+'-'+m.padStart(2,'0')+d.padStart(2,'0') }
5450
recc = X.U32(4); if(!recc) return false;
5551
hdrsz = X.U16(8); recsz = X.U16(0xA); if(hdrsz < 0x20 || !recsz) return false;
56-
res0 = X.U24(0xC); res1 = X.readBytes(0xF,13); res2 = X.U32(0x1C);
52+
res0 = X.U24(0xC); res1 = readU8Array(0xF,13); res2 = X.U32(0x1C);
5753
if([4,0x8C].indexOf(nv) >= 0) {
5854
rectp = 0x44; enc = 'CP'+X.SA(0x22,3); if(isWithin((t=X.SA(0x25,1)),'0','9')) enc += t;
5955
if(enc == 'CPKOI8') enc += X.SA(0x26,1); v5 = true
@@ -85,7 +81,7 @@ function detect() {
8581
validC = ['C','N','L','D','M','F','B','G','P','Y','T','I','V','X','@','O','+','0'];
8682
fldc = 0; totalfldsz = 1 /* we begin with a deletion flag */; p = rectp; old = [0,1];
8783
while(X.U8(p) != 0xD && p < hdrsz) {
88-
name = X.readBytes(p,v5? 0x1F: 11); ns = charStat(name,1);
84+
name = readU8Array(p,v5? 0x1F: 11); ns = charStat(name,1);
8985
//_log('fld#'+fldc+' @'+Hex(p)+': '+decEncoding(name,CP866)+' (ns=['+ns+'])')
9086
if(!name[0] || (ns.indexOf('allxsc') < 0 && ns.indexOf('allforeign') < 0)) return false;
9187
tp = X.SA(v5? p+0x20: p+0xB,1); if(validC.indexOf(tp) < 0) return false;

db/Binary/rom.1.sg

+11-8
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ function detect() {
426426
/*9*/'ZX128ksnap','Opentype','ZXexec','UNI-DOSdir','UNI-DOScreate','14?','15?','SAMBASIC','SAMnum.array',
427427
/*18*/'SAMstr.array','SAMcode','SAMscr','MasterDOSdir','SAMDriverapp','SAMDriverbootstrap','EDOSNOMEN',
428428
'EDOSsys','EDOSovl','27?','HDOSHdos','HDOSHdir','HDOSHdisk','HDOSHfree/Htmp'];
429-
if((X.U8(0) & 0x3F) != 19 && charStat(X.readBytes(0xD2,10),1).indexOf('allasc') >= 0) {
429+
if((X.U8(0) & 0x3F) != 19 && charStat(readU8Array(0xD2,10),1).indexOf('allasc') >= 0) {
430430
sam[0] += 10; label = X.SA(0xD2,10).trim() }
431431
//if(xroot) _l2r('mgt',0xFF,xroot+' xroot found!'); if(samboot) _l2r('mgt',0x100,'SAM BOOT found!')
432432
for(p=_sec=_side=_trk=0,end=false; _trk < 4+xroot && p < X.Sz(); ) {
@@ -435,7 +435,7 @@ function detect() {
435435
//_l2r('mgt',p,'looking at rec #'+files+'"'+X.SA(p+1,10)+'": T'+_trk+'S'+_side+'s'+_sec+' type '+X.U8(p))
436436
if(!X.U8(p+1)) {end = true; continue }
437437
if(end) sus++; files++;
438-
var fname1 = X.readBytes(p+2,9); if(charStat(fname1,1).indexOf('allasc') < 0) return false; //space-padded
438+
var fname1 = readU8Array(p+2,9); if(charStat(fname1,1).indexOf('allasc') < 0) return false; //space-padded
439439
var ft = (X.U8(p)&0x3F); if(ft > 0x1F) return false; //file type
440440
if(!ft) erased++; else if(isWithin(ft,1,11)) zx[0]++; else if(isWithin(ft,12,13)) dd[0]++;
441441
else if(isWithin(ft,16,23)) sam[0]++; else hd[0]++;
@@ -732,7 +732,7 @@ function detect() {
732732
}
733733
}
734734

735-
else if(X.c("'ZXST'") && charStat(X.readBytes(0x10+X.U32(0xC),4),1).indexOf('allxsc') >= 0
735+
else if(X.c("'ZXST'") && charStat(readU8Array(0x10+X.U32(0xC),4),1).indexOf('allxsc') >= 0
736736
&& X.fSig(8,0x200,"'Z80R'") > 0 && X.fSig(0x20,0x200,"'SPCR'") > 0
737737
&& isWithin(V=X.U8(4),1,1) && (v=X.U8(5)) <= 5 && (hw=X.U8(6)) <= 16 && (fl=X.U8(7)) <= 1) {
738738
//ref https://sinclair.wiki.zxnet.co.uk/wiki/ZX-State_format
@@ -754,7 +754,7 @@ function detect() {
754754
var p = 8;
755755
while(p < X.Sz()) {
756756
var hkhd = X.SA(p,4), hksz = X.U32(p+4);
757-
if(!hksz || hksz+p > X.Sz() || charStat(X.readBytes(p,4),1).indexOf('allxsc') < 0
757+
if(!hksz || hksz+p > X.Sz() || charStat(readU8Array(p,4),1).indexOf('allxsc') < 0
758758
|| hkhd.length < 2 || hkhd.toUpperCase() != hkhd) break;
759759
p += 8;
760760
switch(hkhd) {
@@ -802,7 +802,7 @@ function detect() {
802802
switch(X.U8(p++)) {
803803
case 0x10:
804804
if(!X.U8(p+4)) { //loading flag(?)
805-
if(charStat(t=X.readBytes(p+6,10), 1).indexOf('allasc') < 0) bad = bad.addIfNone('!nonASCIIfn');
805+
if(charStat(t=readU8Array(p+6,10), 1).indexOf('allasc') < 0) bad = bad.addIfNone('!nonASCIIfn');
806806
t = decEncoding(t,CPSpeccy).trim(); tp = X.U8(p+5);
807807
if(!t && tp < 3) bad = bad.addIfNone('!emptyfn');
808808
fnames = fnames.appendS(t+'.'+types[tp], ',')
@@ -1148,7 +1148,7 @@ function detect() {
11481148
for(; i < maxlump; i++, p += 0x10) {
11491149
if(p+0x10 > X.Sz()) return false;
11501150
var ofs = X.I32(p,en), sz = X.I32(p+4,en); if(ofs < 0 || sz < 0 || !isWithin(ofs,12,X.Sz())) return false;
1151-
if(X.c("'ENDOFWAD'",p+8)) susBE++; lumps.push([ofs,sz,X.readBytes(p+8,8)]);
1151+
if(X.c("'ENDOFWAD'",p+8)) susBE++; lumps.push([ofs,sz,readU8Array(p+8,8)]);
11521152
}
11531153
lumps = lumps.sort(function(a,b){return a[0]-b[0]});
11541154
for(i=0; i < maxlump; i++) {
@@ -1336,7 +1336,10 @@ if(!bDetected && X.isHeuristicScan()) {
13361336
for(i=p; i < p+hksz-1; i++) c ^= X.U8(i); if(c != X.U8(i)) return false;
13371337
}
13381338
if(tp == 0) {
1339-
if(charStat(t=X.readBytes(p+2,10), 1).indexOf('allasc') < 0) { sus++; bad = bad.addIfNone('!nonASCII:'+decEncoding(t,CPSpeccy)) }
1339+
//_l2r('tap',p+2,readU8Array(p+2,10)+':'
1340+
// +outArray(readU8Array(p+2,10),16)
1341+
// +' -> '+decEncoding(readU8Array(p+2,10),CPSpeccy))
1342+
if(charStat(t=readU8Array(p+2,10), 1).indexOf('allasc') < 0) { sus++; bad = bad.addIfNone('!nonASCII:'+decEncoding(t,CPSpeccy)) }
13401343
t = decEncoding(t,CPSpeccy).trim();
13411344
if(!t) if(X.U8(p+1) < 3) return false; else { sus++; bad = bad.addIfNone('!emptyname') }
13421345
fnames = fnames.appendS(t+'.'+types[X.U8(p+1)], ',') }
@@ -1346,7 +1349,7 @@ if(!bDetected && X.isHeuristicScan()) {
13461349
if(!fnames.length && blk) { sus++; bad = bad.addIfNone('!nonameblk0') }
13471350
if(blk < 2 && bad.indexOf('!nonASCII')) sus++;
13481351
//if(X.Sz() != p) sus++;
1349-
if(sus > 2 || !blk || !fnames.length) { delete bad; return false }
1352+
if(sus > 2 || !blk || !fnames.length || p < 17) { delete bad; return false }
13501353
return true
13511354
}
13521355
if(isTAP()) {

db/chunkparsers

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Various systems' DOS chunk format parser functions.
2+
// They return info or the number -1 if it's not the right format.
3+
// Author: Kaens (TG @kaens)
4+
/* beautify ignore:start */
5+
6+
includeScript("read");
7+
8+
/**
9+
* If it's an Amiga hunk file, parses it and tries to be strict in case of garbage past EoF.
10+
* @returns {Array} [nTotalSize,aBlockInfo,c] where:
11+
* - nTotalSize: -1 if the file is not an Atari DOS "binary save", otherwise the total expected size;
12+
* - aBlockInfo: an Array with separate block types, offsets, and sizes, its length reflecting the number of hunks
13+
*/
14+
function parseAmigaHunks() {
15+
//TODO check types, check reslibs, break off if invalid
16+
if(!X.c("000003F3")) return [-1, []]; //is it an Amiga hunk file?
17+
var p = 4, x = sz = i = reslibs = 0, info = [], load = true;
18+
//library strings:
19+
while(p < X.Sz()) {
20+
x = X.U32(4,_BE); p += 4; if(!reslibs && x) load = false; if(x) reslibs++; else break; p += 4*x
21+
}
22+
var hunks = X.U32(p+8,_BE) - X.U32(p+4,_BE) + 1; p += 12;
23+
//sOption(hunks+' hunks')
24+
for(i=0; i < hunks && p < X.Sz(); i++,p+=4) {
25+
//traverse hunks:
26+
var t = X.U32(p,_BE), add = (t>>30) == 3? 4: 0; t &= 0x3FFFFFFF; t <<= 2; t += add;
27+
//_log('@'+Hex(p)+' hunk#'+i+' = '+Hex(t));
28+
info.push([0/*TODO*/,sz,t]); sz += t
29+
}
30+
sz += p;
31+
if(!info.length) return [-1,[]]; else return [sz,info]
32+
}
33+
34+
/**
35+
* If it's an Atari DOS block file, parses it and tries to be strict in case of garbage past EoF.
36+
* @returns {Array} [nTotalSize,aBlockInfo] where:
37+
* - nTotalSize: -1 if the file is not an Atari DOS "binary save", otherwise the total expected size;
38+
* - aBlockInfo: an Array of arrays with each block's offsets and sizes, its length reflecting the number of blocks
39+
*/
40+
function parseAtariBinary() {
41+
if(!X.c("FFFF") || X.Sz() < 6) return [-1, []];
42+
var hksz = 0,
43+
RAM = [],
44+
hkinfo = [],
45+
p = 2;
46+
while(p+4 <= X.Sz() && p < 65520) {
47+
var ptr = X.U16(p);
48+
if(!hkinfo.length && ptr == 0xFFFF) { p += 2; ptr = X.U16(p) } // the subsequent blocks don't have to have a sig
49+
var eptr = X.U16(p+2); if(eptr < ptr || (ptr <= 0xD7FF && eptr >= 0xD000)) break;
50+
hksz = eptr+1-ptr; if(p + hksz > X.Sz()) if(!n) break;
51+
RAM.push(ptr,hksz); if(findIntersections(RAM,true).length) break;
52+
p += 4; hkinfo.push([p,hksz]); p += hksz
53+
}
54+
if(!hkinfo.length) return [-1, []]; else return [p, hkinfo]
55+
}

db/read

+21-36
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
// and get rid of the functions themselves
66
/* beautify ignore:start */
77

8-
var _BE = true, _LE = false; //endianness for read_int16+
8+
const _BE = true, _LE = false; //endianness for read_int16+
99
//little-endian = reversed notation (Intel, ZX Spectrum),
1010
//big-endian = direct notation (TCP/IP, Motorola, Amiga)
1111
//For the BitReader Object, BE is MSB and LE is LSB (intuitively)
12-
var CS_ALL = true, CS_BEST = false; //charStat needall
13-
var TOEOF = -1; //use for the size parameter in findSignature
12+
const CS_ALL = true, CS_BEST = false; //charStat needall
13+
const TOEOF = -1; //use for the size parameter in findSignature
1414

1515
// ---------- START OF PRE-v3.06 CODE --------------------
1616

@@ -70,19 +70,19 @@ const CP866 = "⌂"+ //DOS Cyrillic
7070
'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'+
7171
'абвгдежзийклмноп░▒▓│┤╡╢╖╕╣║╗╝╜╛┐'+
7272
'└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀'+
73-
'рстуфхцчшщъыьэюяЁёЄєЇїЎў°∙·√№¤■ ';
73+
'рстуфхцчшщъыьэюяЁёЄєЇїЎў°∙·√№¤■ ';
7474
const CP1251 = "⌂"+
7575
"ЂЃ‚ѓ„…†‡€‰Љ‹ЊЌЋЏђ‘’“”•–—・™љ›њќћџ"+
76-
" ЎўЈ¤Ґ¦§Ё©Є«¬­®Ї°±Ііґµ¶·ё№є»јЅѕї"+
76+
" ЎўЈ¤Ґ¦§Ё©Є«¬­®Ї°±Ііґµ¶·ё№є»јЅѕї"+
7777
"АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"+
7878
"абвгдежзийклмнопрстуфхцчшщъыьэюя";
7979
const CP1252 = "⌂"+ //aka. Western aka. ISO-8859-1
8080
"€・‚ƒ„…†‡ˆ‰Š‹Œ・Ž・・‘’“”•–—˜™š›œ・žŸ"+
81-
" ¡¢£¤¥¦§¨©ª«¬・®¯°±²³´µ¶·¸¹º»¼½¾¿"+
81+
" ¡¢£¤¥¦§¨©ª«¬・®¯°±²³´µ¶·¸¹º»¼½¾¿"+
8282
"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß"+
8383
"àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
8484
const KOI8R = "⌂"+ //aka. RFC 1489, Morse code based
85-
'─│┌┐└┘├┤┬┴┼▀▄█▌▐░▒▓⌠■∙√≈≤≥ ⌡°²·÷'+
85+
'─│┌┐└┘├┤┬┴┼▀▄█▌▐░▒▓⌠■∙√≈≤≥ ⌡°²·÷'+
8686
'═║╒ё╓╔╕╖╗╘╙╚╛╜╝╞╟╠╡Ё╢╣╤╥╦╧╨╩╪╫╬©'+
8787
'юабцдефгхийклмнопярстужвьызшэщчъ'+
8888
'ЮАБЦДЕФГХИЙКЛМНОПЯРСТУЖВЬЫЗШЭЩЧЪ';
@@ -93,12 +93,12 @@ const JISX0201 = "⌂"+
9393
"àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
9494
const CPAmiga = "⫽"+ // alternatively, "▒""
9595
"абвгдежзийклмнопрстуфхцчшщъыьэюя"+ //0x80~0x9F display Cyrillics, just to fill the void
96-
" ¡¢£¤¥¦§¨©ª«¬–®¯°±²³´µ¶·¸¹º»¼½¾¿"+
96+
" ¡¢£¤¥¦§¨©ª«¬–®¯°±²³´µ¶·¸¹º»¼½¾¿"+
9797
"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß"+
9898
"àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
9999
const CPRISCOS = "⌂"+
100100
"€Ŵŵ◰﯀Ŷŷ�⇦⇨⇩⇧…™‰•‘’‹›“”„–—−Œœ†‡fifl"+
101-
" ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿"+
101+
" ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿"+
102102
"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß"+
103103
"àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
104104
const CPAtariST = "⌂"+
@@ -118,7 +118,16 @@ const CPSpeccy = ['©', //too SPECIAL with all the tokens-for-characters, gotta
118118
const Chars0to1F = "・☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼"; //#0 is a small dot from Japanese
119119
const Chars0to1FLF = "・☺☻♥♦♣♠•◘○\x0A♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼";
120120
const Chars0to1FCRLF = "・☺☻♥♦♣♠•◘○\x0A♂♀\x0D♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼";
121-
const Chars0to1FSpeccy = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; //not mixing... // emit errors on the latest js
121+
const Chars0to1FSpeccy = "\0\1\2\3\4\5,📝⬅➡⬇⬆⌫\x0A№\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; //not mixing...
122+
123+
124+
// a replacement for the duration of the regression in File.readBytes:
125+
function readU8Array(offset,length,ztospace) {
126+
if(typeof ztospace === 'undefined') ztospace = false;
127+
var r = [];
128+
for(var i=0; i < length; i++) r.push(ztospace==0? X.U8(offset+i): X.U8(offset+i) > 0? X.U8(offset+i): 0x20);
129+
return r
130+
}
122131

123132
/**
124133
* Decode a 1-byte encoding from a byte array using the 128-byte-long table given,
@@ -170,7 +179,7 @@ function decEncoding(ansi, dectbl, zstop, tbl01F) {
170179
* @returns {String} a string value usable with js.
171180
*/
172181
function decAnsi(ofs, len, dectbl, zstop, tbl01F) {
173-
return(decEncoding(X.readBytes(ofs,len), dectbl, zstop, tbl01F))
182+
return(decEncoding(readU8Array(ofs,len), dectbl, zstop, tbl01F))
174183
}
175184

176185

@@ -640,30 +649,6 @@ function toBase64(buf) {
640649
return r
641650
}
642651

643-
/**
644-
* If it's an Amiga hunk file, proceeds to process hunks
645-
* @returns {Int} -1 in case of errors, otherwise expected size
646-
*/
647-
function calcAmigaFileSize() {
648-
if(!X.c("000003F3")) return -1; //is it an Amiga hunk file?
649-
var p = 4, x = sz = i = reslibs = 0, sizes = [], load = true;
650-
//library strings:
651-
while(p < X.Sz()) {
652-
x = X.U32(4,_BE); p += 4; if(!reslibs && x) load = false; if(x) reslibs++; else break; p += 4*x
653-
}
654-
var hunks = X.U32(p+8,_BE) - X.U32(p+4,_BE) + 1; p += 12;
655-
sOption(hunks+' hunks')
656-
//hunk table:
657-
for(i=0; i < hunks && p < X.Sz(); i++,p+=4) {
658-
var t = X.U32(p,_BE), add = (t>>30) == 3? 4: 0; t &= 0x3FFFFFFF; t <<= 2; t += add;
659-
_log('@'+Hex(p)+' hunk#'+i+' = '+Hex(t));
660-
sizes.push(t); sz += t
661-
}
662-
//traverse hunks:
663-
sz += p; //if(sz >= X.Sz()) return -1;
664-
return sz
665-
}
666-
667652
function _logBase64(buf) { //simply plops the buffer contents into log stream with a suitable MIME header
668653
var fn = File.getFileBaseName()+'.'+File.getFileCompleteSuffix();
669654
_log('MIME-Version: 1.0\nContent-Type: application/octet-stream; name="'+fn+'.dec"\n'+
@@ -684,7 +669,7 @@ function _logText(buf) { //same but as text put through CP866, or all file with
684669
if(typeof buf === 'object') {
685670
var bf = buf, i = 0; for(; i < buf.length; i++) if(bf[i] == 0) bf[i] = 0x20
686671
}
687-
_log(decEncoding((typeof buf === 'undefined'? X.readBytes(0,X.Sz(),true): bf), CP866, Chars0to1F));
672+
_log(decEncoding((typeof buf === 'undefined'? readU8Array(0,X.Sz(),true): bf), CP866, Chars0to1F));
688673
_log('--->8-')
689674
}
690675

0 commit comments

Comments
 (0)