// Supplemental read functions. // Authors: unknown guy, Kaens (TG @kaens) // Lots of legacy, // TODO update the old scripts to use the new functions, // and get rid of the functions themselves const _BE = true; const _LE = false; //endianness for read_uint16+ //little-endian = reversed notation (Intel), //big-endian = direct notation (TCP/IP, Motorola, Amiga, ZX Spectrum) const TOEOF = -1; //use for the size parameter in findSignature // ---------- START OF PRE-v3.06 CODE -------------------- /** * Read a big-endian word. * @param {UInt} nOffset - The offset in the file. * @returns {UShort} The word value. * @alias Binary.readBEWord */ File.readBEWord = function(nOffset) { return File.read_uint16(nOffset,_BE) // return (File.readByte(nOffset) << 8) + File.readByte(nOffset+1); } /** * Read a big-endian dword. * @param {UInt} nOffset - The offset in the file. * @returns {UInt} The dword value. * @alias Binary.readBEDword */ File.readBEDword = function(nOffset) { return File.read_uint32(nOffset,_BE) } /** * Read a word, selecting endianness. * @param {UInt} nOffset - The offset in the file. * @param {Bool} bBE - True for big-endian. * @returns {UShort} The word value. * @alias Binary.readEWord */ File.readEWord = function(nOffset,bBE) { return File.read_uint16(nOffset,bBE) } /** * Read a dword, selecting endianness. * @param {UInt} nOffset - The offset in the file. * @param {Bool} bBE - True for big-endian. * @returns {UInt} The dword value. * @alias Binary.readEDWord */ File.readEDword = function(nOffset,bBE) { return File.read_uint16(nOffset,bBE) } /** * Read a short (signed 16-bit) value. * @param {UInt} nOffset - The offset in the file. * @returns {Short} The short value. * @alias Binary.readShort */ File.readShort = function(nOffset) { return File.read_int16(nOffset,_LE) } // -------- END OF PRE-v3.06 CODE const CP437="ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛"+ "┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ "; const JISX0201="→-‚ƒ„…†‡ˆ‰Š‹Œ↑޳™‘’“”•–—˜™š›œ¢žŸ"+//decided to mix it with cp1252 "→。「」、・ヲァィゥェォャュョッーアイウエカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚"+ "àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ" /** * Derive a string hexadecimal value, zero-padded. * @param {Int} a - the numerical value. * @param {UInt} padz (optional,default=2) - how many characters to zero-pad. * @returns {String} The hex value, capital letters A~F, ending with "h". */ function Hex(a,padz) { if(padz==undefined) padz=2; var minus=""; if(a<0) { a=-a; minus="-" } var r = a.toString(16).toUpperCase(); var pads=""; if(r.length < padz) pads = Array(1 + padz - r.length).join('0'); return minus+pads+r+"h" } /** * Read a byte array from file. * @param {UInt} ofs - the offset to start from. * @param {ByteArray} len - the amount of bytes to read. * @returns {[uint8]} The file slice. If you go beyond EoF, read_uint8 only knows what happens. */ function readBytes(ofs,len) { //for now; feels like this should be a system function var s=[]; for (i=0;i