Created
January 5, 2023 23:31
-
-
Save EspressoCake/9d4e172fa72108e5a2bedebb6feaa186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Justin Lucas | |
# Date: January 5, 2023 | |
sub packVariadicArguments | |
{ | |
local('$result'); | |
local('$index'); | |
local('$currentArgument'); | |
# Shift and iterate a list with the Beacon ID popped | |
foreach $index => $currentArgument (sublist($1, 1)) | |
{ | |
if ($currentArgument ismatch '\d+') | |
{ | |
# Concatenate to our existing result value | |
$result .= bof_pack($1[0], "i", $currentArgument); | |
} | |
else if ($currentArgument ismatch '^[A-Za-z]+.*$') | |
{ | |
# Concatenate to our existing current value | |
$result .= bof_pack($1[0], "z", $currentArgument); | |
} | |
} | |
return $result; | |
} | |
alias runMyBofWithVariadicArguments { | |
local('$packedArguments'); | |
local('$handle'); | |
local('$BOFData'); | |
# Insert your boilerplate here to read the BOF of your choosing, storing result in $BOFData | |
# | |
# ...................................................... | |
# | |
# Use a splat operator to shovel all arguments into our handler | |
$packedArguments = packVariadicArguments(@_); | |
local('$string'); | |
$string = "Packed Args Concat: "; | |
# This is building a string to illustrate what the data looks like | |
for ($x = 0; $x < strlen($packedArguments); $x++) | |
{ | |
$string .= byteAt($packedArguments, $x) . " "; | |
} | |
# This dumps the string with ordinal equivalents of packed data | |
if (strlen($string) > 0) | |
{ | |
blog($1, $string); | |
} | |
beacon_inline_execute($1, $BOFData, "go", $packedArguments); | |
} | |
beacon_command_register("runMyBofWithVariadicArguments", "An example of creating BOF arguments with an arbitrary number of values and types.", "runMyBofWithVariadicArguments ..."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment