This document provides a comprehensive guide to the XParamExtra API, which allows LUA scripters to access various utility functions within their scripts for the XLua framework.
- Logging Functions
- String Manipulation
- Conversion Functions
- Array and Collection Operations
- Random Data Generation
- Reflection Utilities
- System Functions
Functions that control logging behavior and provide debug information.
Enables or disables logging functionality.
- Parameters:
shouldLog- Whether logging should be enabled - Example:
param:setLoggingFlag(false) -- Disable logging
Gets the current logging state.
- Returns: Boolean indicating if logging is enabled
- Example:
local isLoggingEnabled = param:getLoggingFlag()
Stores a setting string in the settings cache.
- Parameters:
lastSetting- The setting to store - Example:
param:setLastSetting("resolution=high")
Conditionally stores a setting string in the settings cache.
- Parameters:
lastSetting- The setting to storeflag- Only store if this is true
- Example:
param:setLastSetting("mode=silent", shouldBeSilent)
Retrieves the most recent setting from the cache.
- Returns: The last stored setting or empty string if none exists
- Example:
local lastSetting = param:getLastSetting()
Sets the old result value for logging.
- Parameters:
oldResult- The old value to log - Example:
param:setLogOld(originalValue)
Gets the stored old result value.
- Returns: The stored old result string
- Example:
local oldValue = param:getLogOld()
Sets the new result value for logging.
- Parameters:
newResult- The new value to log - Example:
param:setLogNew(modifiedValue)
Gets the stored new result value.
- Returns: The stored new result string
- Example:
local newValue = param:getLogNew()
Sets additional logging information.
- Parameters:
settingResult- Extra information to log - Example:
param:setLogExtra("Modified by network filter")
Gets the stored extra log information.
- Returns: The stored extra information prefixed with "Setting:"
- Example:
local extraInfo = param:getLogExtra()
Safely converts any object to a string representation.
- Parameters:
o- The object to convert - Returns: String representation of the object or "null"
- Example:
local safeString = param:safe(result)
Gets the current stack trace.
- Returns: Array of StackTraceElement objects
- Example:
local stack = param:getStackTrace()
Gets the stack trace from a given throwable.
- Parameters:
t- The throwable object - Returns: Array of StackTraceElement objects
- Example:
local exception = param:createException() local stack = param:getStackTrace(exception)
Gets the current stack trace as a formatted string.
- Returns: String representation of the stack trace
- Example:
local stackString = param:getStackTraceString()
Gets the stack trace from a given throwable as a formatted string.
- Parameters:
t- The throwable object - Returns: String representation of the stack trace
- Example:
local exception = param:createException("Failed to process") local stackString = param:getStackTraceString(exception)
Prints the current stack trace to the log.
- Example:
param:printStack()
Prints the contents of a file to the log.
- Parameters:
filePath- Path to the file - Example:
param:printFileContents("/data/data/com.example.app/files/config.txt")
Creates a new Exception object.
- Returns: An Exception instance
- Example:
local exception = param:createException()
Creates a new Exception object with a message.
- Parameters:
msg- The exception message - Returns: An Exception instance with the specified message
- Example:
local exception = param:createException("Invalid operation")
Throws an Exception.
- Throws: A new Exception
- Example:
-- This will halt script execution with an exception param:throwException()
Throws an Exception with a specified message.
- Parameters:
msg- The exception message - Throws: A new Exception with the specified message
- Example:
-- This will halt script execution with an exception param:throwException("Invalid state detected")
Functions for working with strings, including validation, modification, and parsing.
Checks if a string contains only numeric characters.
- Parameters:
s- The string to check - Returns: true if the string is numeric
- Example:
local isNumeric = param:isNumericString("12345")
Checks if a string contains another string.
- Parameters:
s- The source stringcontaining- The substring to check for
- Returns: true if the source string contains the substring
- Example:
local contains = param:stringContains("Hello World", "World")
Checks if a string starts with another string.
- Parameters:
s- The source stringstartsWith- The prefix to check for
- Returns: true if the source string starts with the prefix
- Example:
local startsWith = param:stringStartsWith("Hello World", "Hello")
Checks if a string ends with another string.
- Parameters:
s- The source stringendsWith- The suffix to check for
- Returns: true if the source string ends with the suffix
- Example:
local endsWith = param:stringEndsWith("Hello World", "World")
Gets the length of a string.
- Parameters:
s- The string to measure - Returns: The length of the string or -1 if the string is null
- Example:
local length = param:stringLength("Hello")
Checks if a string is not null and not empty.
- Parameters:
s- The string to check - Returns: true if the string is valid (not null and not empty)
- Example:
local isValid = param:stringIsValid("Hello")
Checks if a string is null.
- Parameters:
s- The string to check - Returns: true if the string is null
- Example:
local isNull = param:stringIsNull(someString)
Checks if a string is null or empty.
- Parameters:
s- The string to check - Returns: true if the string is null or empty
- Example:
local isEmpty = param:stringIsEmpty(someString)
Replaces all occurrences of a pattern in a string.
- Parameters:
s- The source stringregex- The regular expression pattern to matchreplaceWith- The replacement string
- Returns: The string with replacements
- Example:
local replaced = param:stringReplaceAll("Hello World", "o", "0")
Removes leading and trailing whitespace from a string.
- Parameters:
s- The string to trim - Returns: The trimmed string
- Example:
local trimmed = param:stringTrim(" Hello ")
Gets a substring from the specified start index (inclusive) to the end index (exclusive).
- Parameters:
s- The source stringstartIndexInclusive- The start index (inclusive)endIndexExclusive- The end index (exclusive)
- Returns: The extracted substring
- Example:
local subString = param:stringSubString("Hello World", 0, 5)
Gets a substring from the specified start index to the end of the string.
- Parameters:
s- The source stringstartIndexInclusive- The start index (inclusive)
- Returns: The extracted substring
- Example:
local subString = param:stringSubString("Hello World", 6)
Converts a string to lowercase.
- Parameters:
s- The string to convert - Returns: The lowercase string
- Example:
local lowercase = param:stringToLowerCase("Hello World")
Converts a string to uppercase.
- Parameters:
s- The string to convert - Returns: The uppercase string
- Example:
local uppercase = param:stringToUpperCase("Hello World")
Converts a string to a character array.
- Parameters:
s- The string to convert - Returns: An array of characters
- Example:
local charArray = param:stringToCharArray("Hello")
Converts a character array to a string.
- Parameters:
chars- The character array - Returns: The resulting string
- Example:
local str = param:charArrayToString(charArray)
Gets the character at the specified index.
- Parameters:
s- The source stringindex- The index of the character
- Returns: The character at the specified index
- Example:
local char = param:stringCharAt("Hello", 1)
Gets the first character of a string.
- Parameters:
s- The source string - Returns: The first character
- Example:
local firstChar = param:stringFirstChar("Hello")
Gets the last character of a string.
- Parameters:
s- The source string - Returns: The last character
- Example:
local lastChar = param:stringLastChar("Hello")
Converts a character to a string.
- Parameters:
c- The character to convert - Returns: The resulting string
- Example:
local str = param:charToString('A')
Checks if a string contains numeric characters.
- Parameters:
s- The string to check - Returns: true if the string contains numeric characters
- Example:
local hasNumbers = param:stringHasNumbersChars("abc123")
Checks if a string contains alphabetic characters.
- Parameters:
s- The string to check - Returns: true if the string contains alphabetic characters
- Example:
local hasLetters = param:stringHasAlphabeticChars("abc123")
Functions for converting between different data formats.
Converts a string to a byte array using UTF-8 encoding.
- Parameters:
s- The string to convert - Returns: The resulting byte array
- Example:
local bytes = param:stringToBytes("Hello")
Converts a string to a byte array using UTF-16 encoding.
- Parameters:
s- The string to convert - Returns: The resulting byte array
- Example:
local bytes = param:stringToBytesUnicode("Hello")
Converts a string to a byte array using the specified encoding.
- Parameters:
s- The string to convertencoding- The character encoding to use
- Returns: The resulting byte array
- Example:
local bytes = param:stringToBytes("Hello", "ISO-8859-1")
Decodes a Base64 string to a byte array.
- Parameters:
s- The Base64 string - Returns: The decoded byte array
- Example:
local bytes = param:stringBase64ToBytes("SGVsbG8=")
Converts a byte array to a string using UTF-8 encoding.
- Parameters:
bytes- The byte array - Returns: The resulting string
- Example:
local str = param:bytesToString(bytes)
Converts a byte array to a string using UTF-16 encoding.
- Parameters:
bytes- The byte array - Returns: The resulting string
- Example:
local str = param:bytesToStringUnicode(bytes)
Converts a byte array to a string using the specified encoding.
- Parameters:
bytes- The byte arrayencoding- The character encoding to use
- Returns: The resulting string
- Example:
local str = param:bytesToString(bytes, "ISO-8859-1")
Converts a byte array to a hex string representation with spaces.
- Parameters:
bytes- The byte array - Returns: The hex string
- Example:
local hexStr = param:bytesToHexString(bytes)
Converts a byte array to a hex string representation.
- Parameters:
bytes- The byte arrayaddSpaces- Whether to add spaces between hex values
- Returns: The hex string
- Example:
local hexStr = param:bytesToHexString(bytes, false)
Encodes a byte array to a Base64 string.
- Parameters:
bytes- The byte array - Returns: The Base64 encoded string
- Example:
local base64Str = param:bytesToBase64String(bytes)
Encodes a string to Base64 using UTF-8 encoding.
- Parameters:
s- The string to encode - Returns: The Base64 encoded string
- Example:
local base64Str = param:stringToBase64String("Hello")
Encodes a string to Base64 using the specified encoding.
- Parameters:
s- The string to encodeencoding- The character encoding to use
- Returns: The Base64 encoded string
- Example:
local base64Str = param:stringToBase64String("Hello", "ISO-8859-1")
Splits a string into an array using comma as the delimiter.
- Parameters:
s- The string to split - Returns: An array of strings
- Example:
local parts = param:stringSplitToArray("a,b,c")
Splits a string into an array using the specified delimiter.
- Parameters:
s- The string to splitdelimiter- The delimiter to use for splitting
- Returns: An array of strings
- Example:
local parts = param:stringSplitToArray("a|b|c", "|")
Joins an array of strings using comma as the delimiter.
- Parameters:
array- The array to join - Returns: The joined string
- Example:
local joined = param:joinStringArray({"a", "b", "c"})
Joins an array of strings using the specified delimiter.
- Parameters:
array- The array to joindelimiter- The delimiter to use for joining
- Returns: The joined string
- Example:
local joined = param:joinStringArray({"a", "b", "c"}, "|")
Splits a string into a list using comma as the delimiter.
- Parameters:
s- The string to split - Returns: A list of strings
- Example:
local list = param:stringSplitToList("a,b,c")
Splits a string into a list using the specified delimiter.
- Parameters:
s- The string to splitdelimiter- The delimiter to use for splitting
- Returns: A list of strings
- Example:
local list = param:stringSplitToList("a|b|c", "|")
Joins a list of strings using comma as the delimiter.
- Parameters:
list- The list to join - Returns: The joined string
- Example:
local joined = param:joinStringList(list)
Joins a list of strings using the specified delimiter.
- Parameters:
list- The list to joindelimiter- The delimiter to use for joining
- Returns: The joined string
- Example:
local joined = param:joinStringList(list, "|")
Gets the size of a container (array, collection, etc.).
- Parameters:
o- The container object - Returns: The size of the container
- Example:
local size = param:getContainerSize(someArray)
Converts a string to a boolean value. Returns false if conversion fails.
- Parameters:
s- The string to convert - Returns: The boolean value
- Example:
local bool = param:stringToBoolean("true")
Converts a string to a boolean value with a fallback default.
- Parameters:
s- The string to convertdefaultValue- The default value if conversion fails
- Returns: The boolean value
- Example:
local bool = param:stringToBoolean("invalid", true)
Converts a string to an integer value. Returns 0 if conversion fails.
- Parameters:
s- The string to convert - Returns: The integer value
- Example:
local num = param:stringToInt("123")
Converts a string to an integer value with a fallback default.
- Parameters:
s- The string to convertdefaultValue- The default value if conversion fails
- Returns: The integer value
- Example:
local num = param:stringToInt("invalid", -1)
Checks if an object is an array.
- Parameters:
o- The object to check - Returns: true if the object is an array
- Example:
local isArray = param:objectIsArray(someObject)
Checks if an object is a collection.
- Parameters:
o- The object to check - Returns: true if the object is a collection
- Example:
local isCollection = param:objectIsCollection(someObject)
Converts an object to a string.
- Parameters:
o- The object to convert - Returns: The string representation of the object
- Example:
local str = param:objectToString(someObject)
Converts an object to a string with a fallback default if null.
- Parameters:
o- The object to convertdefaultIfNull- The default value if the object is null
- Returns: The string representation of the object
- Example:
local str = param:objectToString(someObject, "N/A")
Gets the class name of an object.
- Parameters:
o- The object - Returns: The class name of the object
- Example:
local className = param:objectTypeToString(someObject)
Checks if two objects are equal.
- Parameters:
a- The first objectb- The second object
- Returns: true if the objects are equal
- Example:
local areEqual = param:objectsAreEqual(obj1, obj2)
Checks if two objects are deeply equal.
- Parameters:
a- The first objectb- The second object
- Returns: true if the objects are deeply equal
- Example:
local areEqual = param:objectsAreEqualDeep(obj1, obj2)
Gets the hash code of an object.
- Parameters:
o- The object - Returns: The hash code of the object
- Example:
local hashCode = param:objectToHashCode(someObject)
Functions for working with arrays and collections.
Creates an empty array of objects.
- Returns: An empty array
- Example:
local emptyArray = param:createArrayEmpty()
Creates an array of objects with the specified size.
- Parameters:
size- The size of the array - Returns: The array
- Example:
local array = param:createArray(5)
Creates an array of a specific type with the specified size.
- Parameters:
elementKind- The fully qualified class name of the element typesize- The size of the array
- Returns: The array
- Example:
local array = param:createArray("java.lang.String", 5)
Creates an array of a specific type with the specified size.
- Parameters:
elementKind- The Class object of the element typesize- The size of the array
- Returns: The array
- Example:
local stringClass = param:classForString() local array = param:createArray(stringClass, 5)
Creates an array of Objects with the specified size.
- Parameters:
size- The size of the array - Returns: The array
- Example:
local array = param:createArrayObject(5)
Creates a byte array with the specified size.
- Parameters:
size- The size of the array - Returns: The byte array
- Example:
local byteArray = param:createArrayByte(10)
Creates a char array with the specified size.
- Parameters:
size- The size of the array - Returns: The char array
- Example:
local charArray = param:createArrayChar(10)
Creates a short array with the specified size.
- Parameters:
size- The size of the array - Returns: The short array
- Example:
local shortArray = param:createArrayShort(10)
Creates an int array with the specified size.
- Parameters:
size- The size of the array - Returns: The int array
- Example:
local intArray = param:createArrayInt(10)
Creates a long array with the specified size.
- Parameters:
size- The size of the array - Returns: The long array
- Example:
local longArray = param:createArrayLong(10)
Creates a String array with the specified size.
- Parameters:
size- The size of the array - Returns: The String array
- Example:
local stringArray = param:createArrayString(5)
Creates an array of a specific type using reflection.
- Parameters:
className- The fully qualified class name of the element typesize- The size of the array
- Returns: The array
- Example:
local array = param:createReflectArray("java.lang.Integer", 5)
Creates an array of a specific type using reflection.
- Parameters:
classType- The Class object of the element typesize- The size of the array
- Returns: The array
- Example:
local intClass = param:classForInt() local array = param:createReflectArray(intClass, 5)
Reverses the order of elements in an array.
- Parameters:
o- The array to reverse - Returns: The reversed array
- Example:
local reversed = param:reverseArray(someArray)
Gets the length of an array.
- Parameters:
o- The array - Returns: The length of the array
- Example:
local size = param:arraySize(someArray)
Checks if an array has at least the specified index.
- Parameters:
o- The arrayminimumIndex- The minimum index to check
- Returns: true if the array has at least the specified index
- Example:
local hasIndex = param:arrayHasMinimumIndex(someArray, 5)
Checks if an array has at least the specified size.
- Parameters:
o- The arrayminimumSize- The minimum size to check
- Returns: true if the array has at least the specified size
- Example:
local hasSize = param:arrayHasMinimumSize(someArray, 5)
Gets the element at the specified index in an array.
- Parameters:
a- The arrayindex- The index of the element
- Returns: The element at the specified index
- Example:
local element = param:arrayElementAt(someArray, 2)
Checks if an array contains a specific element.
- Parameters:
a- The arrayc- The element to check for
- Returns: true if the array contains the element
- Example:
local contains = param:arrayContains(someArray, "test")
Adds an element to an array.
- Parameters:
a- The arraye- The element to add
- Returns: The new array with the added element
- Example:
local newArray = param:addElementToArray(someArray, "newElement")
Sets the element at the specified index in an array.
- Parameters:
a- The arraye- The element to setindex- The index to set the element at
- Example:
param:setArrayElementAtIndex(someArray, "newValue", 2)
Removes the element at the specified index from an array.
- Parameters:
a- The arrayindex- The index of the element to remove
- Example:
param:removeArrayElementAtIndex(someArray, 2)
Gets the index of an element in an array.
- Parameters:
a- The arraye- The element to find
- Returns: The index of the element, or -1 if not found
- Example:
local index = param:elementIndexArray(someArray, "searchElement")
Clears all elements in an array by setting them to null/default values.
- Parameters:
a- The array to clear - Returns: true if the array was cleared successfully
- Example:
param:clearArray(someArray)
Removes duplicate elements from an array.
- Parameters:
a- The array - Returns: A new array with duplicates removed
- Example:
local uniqueArray = param:removeDuplicateArrayElements(someArray)
Removes null elements from an array.
- Parameters:
a- The array - Returns: A new array with null elements removed
- Example:
local nonNullArray = param:removeNullArrayElements(someArray)
Gets the first element of an array.
- Parameters:
a- The array - Returns: The first element of the array
- Example:
local first = param:getFirstArrayElement(someArray)
Gets the last element of an array.
- Parameters:
a- The array - Returns: The last element of the array
- Example:
local last = param:getLastArrayElement(someArray)
Creates an empty list.
- Returns: An empty list
- Example:
local emptyList = param:createListEmpty()
Creates a list with an initial capacity.
- Parameters:
size- The initial capacity of the list - Returns: The list
- Example:
local list = param:createList(10)
Converts an array to a list.
- Parameters:
e- The array to convert - Returns: The resulting list
- Example:
local list = param:arrayToList(someArray)
Converts a list to an array.
- Parameters:
l- The list to convert - Returns: The resulting array
- Example:
local array = param:listToArray(someList)
Converts a list to an array of a specific type.
- Parameters:
l- The list to convertelementKind- The fully qualified class name of the element type
- Returns: The resulting array
- Example:
local array = param:listToArray(someList, "java.lang.String")
Converts a list to an array of a specific type.
- Parameters:
l- The list to convertelementKind- The Class object of the element type
- Returns: The resulting array
- Example:
local stringClass = param:classForString() local array = param:listToArray(someList, stringClass)
Gets the size of a list.
- Parameters:
o- The list - Returns: The size of the list
- Example:
local size = param:sizeList(someList)
Checks if a list has at least the specified index.
- Parameters:
o- The listminimumIndex- The minimum index to check
- Returns: true if the list has at least the specified index
- Example:
local hasIndex = param:listHasMinimumIndex(someList, 5)
Checks if a list has at least the specified size.
- Parameters:
o- The listminimumSize- The minimum size to check
- Returns: true if the list has at least the specified size
- Example:
local hasSize = param:listHasMinimumSize(someList, 5)
Gets the element at the specified index in a list.
- Parameters:
a- The listindex- The index of the element
- Returns: The element at the specified index
- Example:
local element = param:listElementAt(someList, 2)
Checks if a list contains a specific element.
- Parameters:
l- The listc- The element to check for
- Returns: true if the list contains the element
- Example:
local contains = param:listContain(someList, "test")
Adds an element to a list.
- Parameters:
a- The liste- The element to add
- Example:
param:addElementToList(someList, "newElement")
Sets the element at the specified index in a list.
- Parameters:
l- The liste- The element to setindex- The index to set the element at
- Example:
param:setListElementAtIndex(someList, "newValue", 2)
Removes the element at the specified index from a list.
- Parameters:
l- The listindex- The index of the element to remove
- Example:
param:removeListElementAtIndex(someList, 2)
Gets the index of an element in a list.
- Parameters:
l- The liste- The element to find
- Returns: The index of the element, or -1 if not found
- Example:
local index = param:elementIndexList(someList, "searchElement")
Clears all elements from a list.
- Parameters:
l- The list to clear - Returns: true if the list was cleared successfully
- Example:
param:clearList(someList)
Removes duplicate elements from a list.
- Parameters:
l- The list - Returns: true if duplicates were removed successfully
- Example:
param:removeDuplicateListElements(someList)
Removes null elements from a list.
- Parameters:
l- The list - Returns: true if null elements were removed successfully
- Example:
param:removeNullListElements(someList)
Gets the first element of a list.
- Parameters:
l- The list - Returns: The first element of the list
- Example:
local first = param:getFirstListElement(someList)
Gets the last element of a list.
- Parameters:
l- The list - Returns: The last element of the list
- Example:
local last = param:getLastListElement(someList)
Functions for generating random data of various types.
Generates a random string.
- Returns: A random string
- Example:
local randomStr = param:randomString()
Generates a random string with the specified length.
- Parameters:
length- The length of the string - Returns: A random string
- Example:
local randomStr = param:randomString(10)
Generates a random string with a length between the specified bounds.
- Parameters:
origin- The minimum length (inclusive)bound- The maximum length (exclusive)
- Returns: A random string
- Example:
local randomStr = param:randomString(5, 10)
Generates a random hexadecimal string.
- Returns: A random hexadecimal string
- Example:
local randomHex = param:randomHexString()
Generates a random hexadecimal string with the specified length.
- Parameters:
length- The length of the string - Returns: A random hexadecimal string
- Example:
local randomHex = param:randomHexString(8)
Generates a random hexadecimal string with a length between the specified bounds.
- Parameters:
origin- The minimum length (inclusive)bound- The maximum length (exclusive)
- Returns: A random hexadecimal string
- Example:
local randomHex = param:randomHexString(5, 10)
Generates a random alphabetic string.
- Returns: A random alphabetic string
- Example:
local randomAlpha = param:randomAlphabeticString()
Generates a random alphabetic string with the specified length.
- Parameters:
length- The length of the string - Returns: A random alphabetic string
- Example:
local randomAlpha = param:randomAlphabeticString(10)
Generates a random alphabetic string with a length between the specified bounds.
- Parameters:
origin- The minimum length (inclusive)bound- The maximum length (exclusive)
- Returns: A random alphabetic string
- Example:
local randomAlpha = param:randomAlphabeticString(5, 10)
Generates a random numeric string.
- Returns: A random numeric string
- Example:
local randomNum = param:randomNumericString()
Generates a random numeric string with the specified length.
- Parameters:
length- The length of the string - Returns: A random numeric string
- Example:
local randomNum = param:randomNumericString(6)
Generates a random numeric string with a length between the specified bounds.
- Parameters:
origin- The minimum length (inclusive)bound- The maximum length (exclusive)
- Returns: A random numeric string
- Example:
local randomNum = param:randomNumericString(4, 8)
Generates a random UUID string.
- Returns: A random UUID string
- Example:
local uuid = param:randomUuid()
Generates a random short value.
- Returns: A random short value
- Example:
local randomShort = param:randomShort()
Generates a random short value between 0 (inclusive) and the specified bound (exclusive).
- Parameters:
bound- The upper bound (exclusive) - Returns: A random short value
- Example:
local randomShort = param:randomShort(100)
Generates a random short value between the specified bounds.
- Parameters:
origin- The lower bound (inclusive)bound- The upper bound (exclusive)
- Returns: A random short value
- Example:
local randomShort = param:randomShort(10, 100)
Generates a random integer value.
- Returns: A random integer value
- Example:
local randomInt = param:randomInt()
Generates a random integer value between 0 (inclusive) and the specified bound (exclusive).
- Parameters:
bound- The upper bound (exclusive) - Returns: A random integer value
- Example:
local randomInt = param:randomInt(100)
Generates a random integer value between the specified bounds.
- Parameters:
origin- The lower bound (inclusive)bound- The upper bound (exclusive)
- Returns: A random integer value
- Example:
local randomInt = param:randomInt(10, 100)
Generates a random float value.
- Returns: A random float value
- Example:
local randomFloat = param:randomFloat()
Generates a random float value between 0 (inclusive) and the specified bound (exclusive).
- Parameters:
bound- The upper bound (exclusive) - Returns: A random float value
- Example:
local randomFloat = param:randomFloat(10.0)
Generates a random float value between the specified bounds.
- Parameters:
origin- The lower bound (inclusive)bound- The upper bound (exclusive)
- Returns: A random float value
- Example:
local randomFloat = param:randomFloat(1.0, 10.0)
Generates a random double value.
- Returns: A random double value
- Example:
local randomDouble = param:randomDouble()
Generates a random double value between 0 (inclusive) and the specified bound (exclusive).
- Parameters:
bound- The upper bound (exclusive) - Returns: A random double value
- Example:
local randomDouble = param:randomDouble(10.0)
Generates a random double value between the specified bounds.
- Parameters:
origin- The lower bound (inclusive)bound- The upper bound (exclusive)
- Returns: A random double value
- Example:
local randomDouble = param:randomDouble(1.0, 10.0)
Generates a random byte value.
- Returns: A random byte value
- Example:
local randomByte = param:randomByte()
Generates a random boolean value.
- Returns: A random boolean value
- Example:
local randomBool = param:randomBool()
Generates a random boolean with a 50% chance of being true.
- Returns: A random boolean value
- Example:
local result = param:randomChance()
Generates a random boolean with the specified chance of being true.
- Parameters:
chance- The percentage chance (0-100) of the result being true - Returns: A random boolean value
- Example:
local result = param:randomChance(75) -- 75% chance of true
Generates a random byte array.
- Returns: A random byte array
- Example:
local randomBytes = param:randomBytes()
Generates a random byte array with a length between 0 (inclusive) and the specified bound (exclusive).
- Parameters:
bound- The upper bound (exclusive) for the length - Returns: A random byte array
- Example:
local randomBytes = param:randomBytes(10)
Generates a random byte array with a length between the specified bounds.
- Parameters:
origin- The lower bound (inclusive) for the lengthbound- The upper bound (exclusive) for the length
- Returns: A random byte array
- Example:
local randomBytes = param:randomBytes(5, 10)
Functions for working with Java reflection.
Gets a Class object for a class with the specified name.
- Parameters:
className- The fully qualified class name - Returns: The Class object
- Example:
local stringClass = param:classForName("java.lang.String")
Gets the Class object for an object.
- Parameters:
o- The object - Returns: The Class object
- Example:
local class = param:classFromObject(someObject)
Gets the Class object for java.lang.Object.
- Returns: The Class object for java.lang.Object
- Example:
local objectClass = param:classForObject()
Gets the Class object for java.lang.Byte.
- Returns: The Class object for java.lang.Byte
- Example:
local byteClass = param:classForByte()
Gets the Class object for java.lang.Character.
- Returns: The Class object for java.lang.Character
- Example:
local charClass = param:classForChar()
Gets the Class object for java.lang.Short.
- Returns: The Class object for java.lang.Short
- Example:
local shortClass = param:classForShort()
Gets the Class object for java.lang.Integer.
- Returns: The Class object for java.lang.Integer
- Example:
local intClass = param:classForInt()
Gets the Class object for java.lang.Long.
- Returns: The Class object for java.lang.Long
- Example:
local longClass = param:classForLong()
Gets the Class object for java.lang.String.
- Returns: The Class object for java.lang.String
- Example:
local stringClass = param:classForString()
Checks if an object is of the exact type java.lang.Object.
- Parameters:
o- The object to check - Returns: true if the object is of the exact type java.lang.Object
- Example:
local isObject = param:isObjectObject(someObject)
Checks if an object is a java.lang.Byte.
- Parameters:
o- The object to check - Returns: true if the object is a Byte
- Example:
local isByte = param:isObjectByte(someObject)
Checks if an object is a java.lang.Short.
- Parameters:
o- The object to check - Returns: true if the object is a Short
- Example:
local isShort = param:isObjectShort(someObject)
Checks if an object is a java.lang.Integer.
- Parameters:
o- The object to check - Returns: true if the object is an Integer
- Example:
local isInt = param:isObjectInt(someObject)
Checks if an object is a java.lang.Character.
- Parameters:
o- The object to check - Returns: true if the object is a Character
- Example:
local isChar = param:isObjectChar(someObject)
Checks if an object is a Collection.
- Parameters:
o- The object to check - Returns: true if the object is a Collection
- Example:
local isCollection = param:isObjectCollection(someObject)
Checks if an object is an Array.
- Parameters:
o- The object to check - Returns: true if the object is an Array
- Example:
local isArray = param:isObjectArray(someObject)
Checks if an object is a java.lang.String.
- Parameters:
o- The object to check - Returns: true if the object is a String
- Example:
local isString = param:isObjectString(someObject)
Checks if an object's class is assignable from the specified class name.
- Parameters:
o- The objectclassName- The fully qualified class name
- Returns: true if the object's class is assignable from the specified class
- Example:
local isAssignable = param:isAssignableFrom(someObject, "java.lang.CharSequence")
Checks if an object's class is assignable from the specified class.
- Parameters:
o- The objectclazz- The Class object
- Returns: true if the object's class is assignable from the specified class
- Example:
local charSequenceClass = param:classForName("java.lang.CharSequence") local isAssignable = param:isAssignableFrom(someObject, charSequenceClass)
Creates a new instance of a class with the specified name using the provided arguments.
- Parameters:
className- The fully qualified class nameargs- The constructor arguments
- Returns: The new instance
- Example:
local instance = param:newInstance("java.lang.StringBuilder", "Initial text")
Creates a new instance of a class using the provided arguments.
- Parameters:
clazz- The Class objectargs- The constructor arguments
- Returns: The new instance
- Example:
local stringBuilderClass = param:classForName("java.lang.StringBuilder") local instance = param:newInstance(stringBuilderClass, "Initial text")
Creates a new instance of a class with the specified name using the default constructor.
- Parameters:
className- The fully qualified class name - Returns: The new instance
- Example:
local instance = param:newInstance("java.util.ArrayList")
Creates a new instance of a class using the default constructor.
- Parameters:
clazz- The Class object - Returns: The new instance
- Example:
local arrayListClass = param:classForName("java.util.ArrayList") local instance = param:newInstance(arrayListClass)
Checks if a class with the specified name exists.
- Parameters:
className- The fully qualified class name - Returns: true if the class exists
- Example:
local exists = param:hasClass("java.util.HashMap")
Checks if a class has a method with the specified name.
- Parameters:
className- The fully qualified class namemethodName- The name of the method
- Returns: true if the class has the method
- Example:
local hasMethod = param:hasMethod("java.lang.String", "toUpperCase")
Checks if a class has a method with the specified name.
- Parameters:
clazz- The Class objectmethodName- The name of the method
- Returns: true if the class has the method
- Example:
local stringClass = param:classForName("java.lang.String") local hasMethod = param:hasMethod(stringClass, "toUpperCase")
Checks if a class has a method with the specified name and argument count.
- Parameters:
className- The fully qualified class namemethodName- The name of the methodargCount- The number of arguments
- Returns: true if the class has the method with the specified argument count
- Example:
local hasMethod = param:hasMethod("java.lang.String", "substring", 1)
Checks if a class has a method with the specified name and argument count.
- Parameters:
clazz- The Class objectmethodName- The name of the methodargCount- The number of arguments
- Returns: true if the class has the method with the specified argument count
- Example:
local stringClass = param:classForName("java.lang.String") local hasMethod = param:hasMethod(stringClass, "substring", 1)
Checks if a class has a field with the specified name.
- Parameters:
className- The fully qualified class namefieldName- The name of the field
- Returns: true if the class has the field
- Example:
local hasField = param:hasField("java.lang.System", "out")
Checks if a class has a field with the specified name.
- Parameters:
clazz- The Class objectfieldName- The name of the field
- Returns: true if the class has the field
- Example:
local systemClass = param:classForName("java.lang.System") local hasField = param:hasField(systemClass, "out")
Gets a Method object for a method with the specified name in a class.
- Parameters:
className- The fully qualified class namemethodName- The name of the method
- Returns: The Method object
- Example:
local method = param:methodForName("java.lang.String", "toUpperCase")
Gets a Method object for a method with the specified name in a class.
- Parameters:
clazz- The Class objectmethodName- The name of the method
- Returns: The Method object
- Example:
local stringClass = param:classForName("java.lang.String") local method = param:methodForName(stringClass, "toUpperCase")
Gets a Method object for a method with the specified name and argument count in a class.
- Parameters:
clazz- The Class objectmethodName- The name of the methodargCount- The number of arguments
- Returns: The Method object
- Example:
local stringClass = param:classForName("java.lang.String") local method = param:methodForName(stringClass, "substring", 1)
Gets a Method object for a method with the specified name and argument count in a class.
- Parameters:
className- The fully qualified class namemethodName- The name of the methodargCount- The number of arguments
- Returns: The Method object
- Example:
local method = param:methodForName("java.lang.String", "substring", 1)
Gets a Field object for a field with the specified name in a class.
- Parameters:
className- The fully qualified class namefieldName- The name of the field
- Returns: The Field object
- Example:
local field = param:fieldForName("java.lang.System", "out")
Gets a Field object for a field with the specified name in a class.
- Parameters:
clazz- The Class objectfieldName- The name of the field
- Returns: The Field object
- Example:
local systemClass = param:classForName("java.lang.System") local field = param:fieldForName(systemClass, "out")
bypassHiddenApiRestrictions()
Bypasses hidden API restrictions for the current application.
- Returns: true if the operation was successful
- Example:
param:bypassHiddenApiRestrictions()
bypassHiddenApiRestrictions(ClassLoader classLoader)
Bypasses hidden API restrictions for a specific ClassLoader.
- Parameters:
classLoader- The ClassLoader - Returns: true if the operation was successful
- Example:
local classLoader = someObject:getClass():getClassLoader() param:bypassHiddenApiRestrictions(classLoader)
Functions for interacting with the system and runtime environment.
Gets the process ID of the current process.
- Returns: The process ID
- Example:
local pid = param:myPid()
Gets the user ID of the current process.
- Returns: The user ID
- Example:
local uid = param:myUid()
Gets the thread ID of the current thread.
- Returns: The thread ID
- Example:
local tid = param:myTid()
Terminates the current process with status code 0.
- Example:
param:exit()
Terminates the current process with the specified status code.
- Parameters:
status- The exit status code - Example:
param:exit(1)
Interrupts the current thread.
- Example:
param:exitCurrentThread()
Executes a system command.
- Parameters:
command- The command to execute - Returns: A Process object representing the process
- Example:
local process = param:exec("ls -la")
Executes an echo command with the specified message.
- Parameters:
msg- The message to echo - Returns: A Process object representing the process
- Example:
local process = param:execEcho("Hello, World!")
Gets the Runtime object.
- Returns: The Runtime object
- Example:
local runtime = param:getRuntime()
Gets the current thread.
- Returns: The current Thread object
- Example:
local thread = param:getCurrentThread()
Checks if the current thread is the main thread.
- Returns: true if the current thread is the main thread
- Example:
local isMain = param:isCurrentThreadMain()
Clears the LogCat logs.
- Example:
param:clearLogCatLogs()
Converts gigabytes to bytes.
- Parameters:
gigabytes- The number of gigabytes - Returns: The equivalent number of bytes
- Example:
local bytes = param:gigabytesToBytes(2)
Here's a complete example that demonstrates using various functions from the XParamExtra API to manipulate strings and arrays:
-- Create a hook function that modifies a string result
function after_method_call(param)
-- Get the original result
local originalResult = param:getResult()
-- Log the original result
param:setLogOld(originalResult)
-- Only proceed if we have a valid string result
if param:isObjectString(originalResult) and param:stringIsValid(originalResult) then
-- Create a modified version by replacing specific text
local modifiedResult = param:stringReplaceAll(originalResult, "password", "********")
-- Convert to uppercase if not already
if modifiedResult ~= param:stringToUpperCase(modifiedResult) then
modifiedResult = param:stringToUpperCase(modifiedResult)
end
-- Set the new result
param:setResult(modifiedResult)
-- Log the new result
param:setLogNew(modifiedResult)
param:setLogExtra("String was modified and converted to uppercase")
-- Print debug info to logcat
log("Original: " .. param:safe(originalResult))
log("Modified: " .. param:safe(modifiedResult))
end
return true
endWhen using the XParamExtra API in your LUA scripts, keep these best practices in mind:
-
Error Handling: Always check for null values before performing operations on objects.
if param:stringIsValid(someString) then -- Proceed with string operations end
-
Logging: Use the logging functions to keep track of changes for debugging.
param:setLogOld(originalValue) param:setLogNew(newValue) param:setLogExtra("Applied transformation X")
-
Performance: Be mindful of performance implications when working with large arrays or lists.
-- Check array size before operating on it if param:arrayHasMinimumSize(someArray, 1000) then log("Warning: Processing large array") end
-
Reflection: Use reflection operations cautiously as they can impact performance.
-- Cache reflection results local stringClass = param:classForName("java.lang.String") -- Reuse stringClass instead of calling classForName repeatedly
-
Resource Management: Clean up resources when no longer needed.
-- Clear collections when done param:clearList(temporaryList)
Here are some common issues and their solutions:
-
NullPointerException: Check if objects are null before operating on them.
if param:objectToString(obj) ~= "null" then -- Safe to proceed end
-
ClassCastException: Verify object types before casting.
if param:isObjectString(obj) then -- Safe to treat as string end
-
IndexOutOfBoundsException: Validate array/list indices before accessing elements.
if param:arrayHasMinimumIndex(array, index) then -- Safe to access end
-
Security exceptions: Use bypass functions when necessary (with caution).
param:bypassHiddenApiRestrictions()