Expand description
C bindings for the YARA-X library.
This crate defines the C-compatible API that C/C++ programs can use for
interfacing with the YARA-X Rust library. A header file for this library
(yara_x.h) will be automatically generated by cbindgen, during
compilation, together with dynamic-linking and static-linking versions of
the library.
§How to build and install
You will need cargo-c for building this library, if you didn’t install
it before, this is the first step:
cargo install cargo-cYou will also need the openssl library, depending on your platform you
can choose one of the following methods:
Ubuntu:
sudo apt install libssl-devMacOS (using brew):
brew install openssl@3Windows (using vcpkg):
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
bootstrap-vcpkg.bat
vcpkg install openssl:x64-windows-static
set OPENSSL_DIR=%cd%\installed\x64-windows-staticOnce you have installed the pre-requisites, go to the root directory of the YARA-X repository and type:
cargo cinstall -p yara-x-capi --releaseThe command above will put the library and header files in the correct path
in your system (usually /usr/local/lib and /usr/local/include for Linux
and macOS users), and will generate a .pc file so that pkg-config knows
about the library.
In Linux and macOS you can check if everything went fine by compiling a simple test program, like this:
cat <<EOF > test.c
#include <yara_x.h>
int main() {
YRX_RULES* rules;
yrx_compile("rule dummy { condition: true }", &rules);
yrx_rules_destroy(rules);
}
EOFgcc `pkg-config --cflags yara_x_capi` `pkg-config --libs yara_x_capi` test.cThe compilation should succeed without errors.
Windows users can find all the files you need for importing the YARA-X library
in your project in the target/x86_64-pc-windows-msvc/release directory. This
includes:
- A header file (
yara_x.h) - A module definition file (
yara_x_capi.def) - A DLL file (
yara_x_capi.dll) with its corresponding import library (yara_x_capi.dll.lib) - A static library (
yara_x_capi.lib)
Structs§
- YRX_
BUFFER - Represents a buffer with arbitrary data.
- YRX_
MATCH - Contains information about a pattern match.
- YRX_
METADATA - A metadata entry.
- YRX_
METADATA_ BYTES - Represents a metadata value that contains raw bytes.
- YRX_
PATTERN - A pattern defined in a rule.
- YRX_
RULE - A single YARA rule.
- YRX_
RULES - A set of compiled YARA rules.
- YRX_
SCANNER - A scanner that scans data with a set of compiled YARA rules.
Enums§
- YRX_
METADATA_ TYPE - Types of metadata values.
- YRX_
RESULT - Error codes returned by functions in this API.
Functions§
- yrx_
buffer_ ⚠destroy - Destroys a
YRX_BUFFERobject. - yrx_
compile ⚠ - Compiles YARA source code and creates a
YRX_RULESobject that contains the compiled rules. - yrx_
finalize ⚠ - Finalizes YARA-X.
- yrx_
last_ ⚠error - Returns the error message for the most recent function in this API invoked by the current thread.
- yrx_
pattern_ ⚠identifier - Returns the name of the pattern represented by
YRX_PATTERN. - yrx_
pattern_ ⚠iter_ matches - Iterates over the matches of a pattern, calling the callback with a pointer
to a
YRX_MATCHstructure for each pattern. - yrx_
rule_ ⚠identifier - Returns the name of the rule represented by
YRX_RULE. - yrx_
rule_ ⚠iter_ metadata - Iterates over the metadata of a rule, calling the callback with a pointer
to a
YRX_METADATAstructure for each metadata in the rule. - yrx_
rule_ ⚠iter_ patterns - Iterates over the patterns in a rule, calling the callback with a pointer
to a
YRX_PATTERNstructure for each pattern. - yrx_
rule_ ⚠iter_ tags - Iterates over the tags in a rule, calling the callback with a pointer to each tag.
- yrx_
rule_ ⚠namespace - Returns the namespace of the rule represented by
YRX_RULE. - yrx_
rules_ ⚠count - Returns the total number of rules.
- yrx_
rules_ ⚠deserialize - Deserializes the rules from a sequence of bytes produced by
yrx_rules_serialize. - yrx_
rules_ ⚠destroy - Destroys a
YRX_RULESobject. - yrx_
rules_ ⚠iter - Iterates over the compiled rules, calling the callback function for each rule.
- yrx_
rules_ ⚠iter_ imports - Iterates over the modules imported by the rules, calling the callback with the name of each imported module.
- yrx_
rules_ ⚠serialize - Serializes the rules as a sequence of bytes.
- yrx_
scanner_ ⚠clear_ profiling_ data - Clears all accumulated profiling data.
- yrx_
scanner_ ⚠create - Creates a
YRX_SCANNERobject that can be used for scanning data with the providedYRX_RULES. - yrx_
scanner_ ⚠destroy - Destroys a
YRX_SCANNERobject. - yrx_
scanner_ ⚠fast_ scan - Enables or disables fast scan mode for the scanner.
- yrx_
scanner_ ⚠finish - Finalizes the scan of a set of memory blocks.
- yrx_
scanner_ ⚠iter_ slowest_ rules - Iterates over the slowest N rules, calling the callback for each rule.
- yrx_
scanner_ ⚠on_ console_ log - Sets the callback for console module.
- yrx_
scanner_ ⚠on_ matching_ rule - Sets a callback function that is called by the scanner for each rule that matched during a scan.
- yrx_
scanner_ ⚠scan - Scans a data buffer.
- yrx_
scanner_ ⚠scan_ block - Scans a block of data.
- yrx_
scanner_ ⚠scan_ file - Scans a file.
- yrx_
scanner_ ⚠set_ global_ bool - Sets the value of a global variable of type bool.
- yrx_
scanner_ ⚠set_ global_ float - Sets the value of a global variable of type float.
- yrx_
scanner_ ⚠set_ global_ int - Sets the value of a global variable of type int.
- yrx_
scanner_ ⚠set_ global_ json - Sets the value of a global variable from a JSON-encoded string.
- yrx_
scanner_ ⚠set_ global_ str - Sets the value of a global variable of type string.
- yrx_
scanner_ ⚠set_ module_ data - Specifies metadata for a module.
- yrx_
scanner_ ⚠set_ module_ output - Specifies the output data structure for a module.
- yrx_
scanner_ ⚠set_ timeout - Sets a timeout (in seconds) for scan operations.
Type Aliases§
- YRX_
CONSOLE_ CALLBACK - Callback function used when a YARA rule calls the console module.
- YRX_
IMPORT_ CALLBACK - Callback function passed to
yrx_rules_iter_imports. - YRX_
MATCH_ CALLBACK - Callback function passed to
yrx_pattern_iter_matches. - YRX_
METADATA_ CALLBACK - Callback function passed to
yrx_rule_iter_metadata. - YRX_
PATTERN_ CALLBACK - Callback function passed to
yrx_rule_iter_patterns. - YRX_
RULE_ CALLBACK - Callback function passed to
yrx_scanner_on_matching_ruleoryrx_rules_iter. - YRX_
SLOWEST_ RULES_ CALLBACK - Callback function passed to
yrx_scanner_iter_slowest_rules. - YRX_
TAG_ CALLBACK - Callback function passed to
yrx_rule_iter_tags.
Unions§
- YRX_
METADATA_ VALUE - A metadata value.