new Binary()
Methods
-
(static) calculateEntropy(nOffset, nSize) → {Float}
-
Calculate the entropy of a region of the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. nSizeUInt Number of bytes. Returns:
Result in the form of quantity of bits per byte. Since there are 8 bits in a byte, the maximum entropy will be 8.0.- Type
- Float
-
(static) calculateMD5(nOffset, nSize) → {String}
-
Calculate the MD5 hash of a region of the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. nSizeUInt Number of bytes. Returns:
MD5 hash.- Type
- String
-
(static) compare(sSignature, nOffsetopt) → {Bool}
-
Compares bytes with a hexadecimal string signature.
The signature may contain both lowercase and uppercase hexadecimal digits. Spaces are skipped, and
.and?represent any digit.Text may be matched by using single quotes. For example "01'Test'01".
There are two additional symbols:
#for absolute jump (e.g."68########55");$for relative jump (e.g."E8$$$$$$$$55").Parameters:
Name Type Attributes Default Description sSignatureString The signature. nOffsetUInt <optional>
0 The offset in the file. Returns:
- Type
- Bool
Examples
if(Binary.compare("'7z'BCAF271C")) // compare file header (nOffset=0) { sVersion=Binary.readByte(6)+"."+Binary.readByte(7); bDetected=1; }if(Binary.compare("'WAVEfmt '",8)) // compare file from offset 8 { bDetected=1; } -
(static) findByte(nOffset, nSize, cValue) → {Int}
-
Search for a byte in the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. nSizeUInt Number of bytes to search. cValueUChar The byte value. Returns:
Offset in the file if the value is found;-1otherwise.- Type
- Int
-
(static) findDword(nOffset, nSize, nValue) → {Int}
-
Search for a dword in the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. nSizeUInt Number of bytes to search. nValueUInt The dword value. Returns:
Offset in the file if the value is found;-1otherwise.- Type
- Int
-
(static) findSignature(nOffset, nSize, sValue) → {Int}
-
Search for a signature (see compare) in the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. nSizeUInt Number of bytes to search. sValueString The signature. Returns:
Offset in the file if the signature is found;-1otherwise.- Type
- Int
-
(static) findString(nOffset, nSize, sValue) → {Int}
-
Search for a string in the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. nSizeUInt Number of bytes to search. sValueString The string value. Returns:
Offset in the file if the value is found;-1otherwise.- Type
- Int
-
(static) findWord(nOffset, nSize, sValue) → {Int}
-
Search for a word in the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. nSizeUInt Number of bytes to search. sValueUShort The word value. Returns:
Offset in the file if the value is found;-1otherwise.- Type
- Int
-
(static) getFileBaseName() → {String}
-
Get the base name of the file.
Returns:
- Type
- String
-
(static) getFileCompleteSuffix() → {String}
-
Get the complete suffix of the file.
Returns:
- Type
- String
-
(static) getFileDirectory() → {String}
-
Get the directory of the file.
Returns:
- Type
- String
-
(static) getFileSuffix() → {String}
-
Get the suffix of the file.
Returns:
- Type
- String
-
(static) getSignature(nOffset, nSize) → {String}
-
Get a signature string from the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. nSizeUInt Number of bytes. Returns:
Signature.- Type
- String
Example
var signature=Binary.getSignature(0,4); if(signature=="AA5411DD") { bDetected=1; } -
(static) getSize() → {UInt}
-
Get the size of the file.
Returns:
- Type
- UInt
-
(static) getString(nOffset, nSizeopt) → {String}
-
Get a text string from the file. A string is read up to the first unreadable character or up to the maximum length.
Parameters:
Name Type Attributes Default Description nOffsetUInt The offset in the file. nSizeUInt <optional>
50 The maximum size of the string, in bytes. Returns:
- Type
- String
Example
var sString=Binary.getString(0x100,32); // read a string from offset 0x100, maximum length 32 bytes var sString=Binary.getString(60); // read a string from offset 60, maximum length 50 bytes (default value) -
(static) isSignaturePresent(nOffset, nSize, sSignature) → {Bool}
-
Check if a signature (see compare) exists in a region of the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. nSizeUInt Number of bytes to check. sSignatureString The signature. Returns:
- Type
- Bool
-
(static) readBEDword(nOffset) → {UInt}
-
Read a big-endian dword.
Parameters:
Name Type Description nOffsetUInt The offset in the file. Returns:
The dword value.- Type
- UInt
-
(static) readBEWord(nOffset) → {UShort}
-
Read a big-endian word.
Parameters:
Name Type Description nOffsetUInt The offset in the file. Returns:
The word value.- Type
- UShort
-
(static) readByte(nOffset) → {UChar}
-
Read a byte value from the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. Returns:
The byte value.- Type
- UChar
-
(static) readDword(nOffset) → {UInt}
-
Read a dword value from the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. Returns:
The dword value.- Type
- UInt
-
(static) readEDWord(nOffset, bBE) → {UInt}
-
Read a dword, selecting endianness.
Parameters:
Name Type Description nOffsetUInt The offset in the file. bBEBool True for big-endian. Returns:
The dword value.- Type
- UInt
-
(static) readEWord(nOffset, bBE) → {UShort}
-
Read a word, selecting endianness.
Parameters:
Name Type Description nOffsetUInt The offset in the file. bBEBool True for big-endian. Returns:
The word value.- Type
- UShort
-
(static) readShort(nOffset) → {Short}
-
Read a short (signed 16-bit) value.
Parameters:
Name Type Description nOffsetUInt The offset in the file. Returns:
The short value.- Type
- Short
-
(static) readWord(nOffset) → {UShort}
-
Read a word from the file.
Parameters:
Name Type Description nOffsetUInt The offset in the file. Returns:
The word value.- Type
- UShort
-
(static) swapBytes(nValue) → {Uint}
-
Swap the four bytes of a dword. For example 0x11223344 becomes 0x44332211.
Parameters:
Name Type Description nValueUInt The value. Returns:
The value with its bytes swapped.- Type
- Uint