Enabling the extension
To use the decompiler, addextensions = "decompiler" to your rule:
Decompiling functions
Theproject:decompile() method accepts a function name, an address, or a pattern query and returns a DecompiledFunction object:
project:decompile() returns nil. When using a FunctionQuery with all = true, it returns a table of DecompiledFunction objects instead.
Running queries
Once you have aDecompiledFunction, you can search its pseudocode using Weggli-compatible syntax queries via the query method.
The simplest form takes a query string. Use $var to capture named variables and _ as a wildcard:
{} before execution. For more control, pass a table with additional options:
regexes field allows filtering matches: use $VAR=pattern to require a match, or $VAR!=pattern to exclude it.
Extracting match results
Thequery method returns a SyntaxMatchResult object. Use its methods to extract addresses and captured variable bindings from the matches:
address_of_match(n)returns the address of the n-th matched element (1-indexed)binding_of_match("$var")returns the code string captured by$var
nil if the requested match or variable is not found.
Example: verifying a patch
The following example decompiles a function and uses a syntax query to verify that a buffer length check precedes a call tostrcpy. If the pattern is found, the rule reports the vulnerability as patched; otherwise, it reports it as a high-severity finding.