Skip to content

Scripted Overrides

Neo edited this page Jul 26, 2021 · 2 revisions

Scripted Overrides

A handful of functions (as shown below) have been added to Primitive & Array prototypes to assist in various ways while writing scripts.

The type to which each function belongs is shown within < >

Table of Contents


Converters

toBits

Converts the integer to a bit string and returns the result.

Syntax:

<number>.toBits([count])
Argument Description
count Optional no. of bits required in the string.
The default as well as maximum value is 32.

Returns: the equivalent bit string


toHex

Converts the value provided to equivalent hex string. There are 2 forms of it based on the type of value being converted.

Syntax 1 (for integer):

<number>.toHex([bigEndian])
<number>.toHex(count, [bigEndian])
Argument Description
count Optional no. of bytes required in the string.
The default as well as maximum value is 4.
bigEndian Optional boolean to indicate whether the result should be in Big Endian form or not.
Default is false

Syntax 2 (for ASCII string):

<string>.toHex()

Returns: the equivalent hex string


toIEEE

Converts the floating point number to equivalent IEEE format hex string.

Syntax:

<number>.toIEEE([bigEndian])
Argument Description
bigEndian Optional boolean to indicate whether the result should be in Big Endian form or not.
Default is false

Returns: the equivalent hex string


toInt

Converts the provided (little endian) hex string to equivalent integer.

Syntax:

<string>.toInt([signed])
<string>.toInt(count, [signed])
Argument Description
count Optional no. of bytes expected in the integer. More relevant for signed integers.
The default as well as maximum value is 4.
signed Optional boolean to indicate whether the result should be signed (true) or unsigned (false).
Default is true.

Returns: the equivalent integer


toAscii

Converts the provided hex string to equivalent ascii string.

Syntax:

<string>.toAscii()

Returns: the equivalent ascii text string


le2be

Converts the provided Little Endian hex string to it's equivalent Big Endian form. All the spaces will get removed as well.

Syntax:

<string>.le2be()

Returns: the equivalent big endian hex string


findAs

Extended version of find function of an Array to return a custom value related to the matched element (instead of the element itself).

Syntax:

<array>.findAs( (element, [index], [arr]) =>
{
});

Returns: The 'truthy' value returned by the argument function OR undefined

For Example:

[42, 15, 36, 40].findAs( val => 
{
	if (val % 5 === 0)
		return val + 10;
})

this will return 15 + 10 i.e. 25.


Transformers

These functions returns an altered form of the original value as the result i.e. it 'transforms' the source.

This is needed since the original cannot be modified from within member functions.

remove

Used to remove specific substring from the source string and return the result.

Syntax:

<string>.remove(substring)

Returns: the updated string


replaceAt

Used to replace a specific portion of a string with a new one and return the result.

Syntax:

<string>.replaceAt(index, newstr, [len])
Argument Description
index The position where the replacement needs to happen
newstr The replacement string.
len Optional length/count of characters to be replaced.
If omitted or negative, len will be the replacement string's length. )

Returns: the updated string


insertAt

Complementary to insertAt, this one inserts a new string at the specified position and return the result.

Syntax:

<string>.insertAt(index, newstr)
Argument Description
index The position where the insertion needs to happen
newstr The insertion string.

Returns: the updated string


appendAsHex

Appends the provided value as a hex string to the source and return the result.

If the value is a number, then it is converted to hex first.

Syntax

<string>.appendAsHex(value, [bytecount], [bigEndian])
Argument Description
value The value to be appended. Can be either a nunber or a hex string.
bytecount Optional byte count used for conversion when value is a number.
bigEndian Optional boolean to indicate we need Big Endian or Little Endian.
Used only when value` is a number.

Returns: the updated string


Testers

isEmpty

Override for Arrays & Strings to check for no content inside. Essentially it compares the length property with 0 in both cases.

Syntax 1 (for Strings):

<string>.isEmpty()

Syntax 2 (for Arrays):

<array>.isEmpty()

Returns: true or false


isRegPtr

Checks whether the array is of the form [Register object]. For e.g. [EAX]

Syntax:

<array>.isRegPtr()

Returns: true or false


isDispPtr

Checks whether the array is of the form [], where the offset can be a number or hex string. For e.g. [0x402000] OR ["?? ?? 01 00"]

Syntax:

<array>.isDispPtr()

Returns: true or false


isHex

Checks whether the string contains only valid hex characters (including supported wildcard characters).

Syntax:

<string>.isHex()

Returns: true or false


Calculators

byteCount

Override for Arrays & Strings to calculate the total byte count of all it's components. Only hex strings will be considered in both cases.

Syntax 1 (for hex string):

<string>.byteCount()

Syntax 2 (for array of hex strings)

<array>.byteCount()

Returns: the calculated byte count.


Utilities

last

Retrieves the last value of the array.

Syntax:

<array>.last()

Returns: the retrieved value


take_if

Tests for the type of value at index 0 in the array and shifts it out of the array if it matches.

Syntax:

<array>.take_if(typeName, defVal)
Argument Description
typeName The type string to look for. For e.g. 'boolean'
defVal The default value to return, when the test fails.

Return to top


Further reading