mirror of
https://github.com/VirusTotal/yara.git
synced 2026-10-11 22:49:58 +00:00
YR_MAJOR_VERSION, YR_MINOR_VERSION and YR_MICRO_VERSION are fixed when the caller is compiled, so a program linked against a shared libyara has no way to tell which version it actually loaded. Distros ship libyara.so in its own package precisely so it can be updated independently of its consumers, which is exactly the case the macros cannot describe. Add yr_get_version(), which reports the version of the library that is actually loaded. Any argument may be NULL if the caller does not need that component, and since the function touches no global state it can be called before yr_initialize. Closes #2136 --------- Co-authored-by: Victor M. Alvarez <[email protected]>
72 lines
2.5 KiB
C
72 lines
2.5 KiB
C
/*
|
|
Copyright (c) 2016. The YARA Authors. All Rights Reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
this list of conditions and the following disclaimer in the documentation and/or
|
|
other materials provided with the distribution.
|
|
|
|
3. Neither the name of the copyright holder nor the names of its contributors
|
|
may be used to endorse or promote products derived from this software without
|
|
specific prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <strings.h>
|
|
#include <yara.h>
|
|
|
|
#include "util.h"
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
YR_DEBUG_INITIALIZE();
|
|
YR_DEBUG_FPRINTF(1, stderr, "+ %s() { // in %s\n", __FUNCTION__, argv[0]);
|
|
|
|
// make sure that versions defined in configure.ac and in
|
|
// libyara/include/yara/libyara.h are in sync.
|
|
|
|
int result = strcmp(PACKAGE_VERSION, YR_VERSION);
|
|
|
|
// yr_get_version must report the same version the macros carry, and must
|
|
// work before yr_initialize and with any argument omitted.
|
|
|
|
int major = -1, minor = -1, micro = -1;
|
|
|
|
yr_get_version(&major, &minor, µ);
|
|
|
|
if (major != YR_MAJOR_VERSION || minor != YR_MINOR_VERSION ||
|
|
micro != YR_MICRO_VERSION)
|
|
result = 1;
|
|
|
|
major = minor = micro = -1;
|
|
|
|
yr_get_version(&major, NULL, NULL);
|
|
yr_get_version(NULL, &minor, NULL);
|
|
yr_get_version(NULL, NULL, µ);
|
|
yr_get_version(NULL, NULL, NULL);
|
|
|
|
if (major != YR_MAJOR_VERSION || minor != YR_MINOR_VERSION ||
|
|
micro != YR_MICRO_VERSION)
|
|
result = 1;
|
|
|
|
YR_DEBUG_FPRINTF(
|
|
1, stderr, "} = %d // %s() in %s\n", result, __FUNCTION__, argv[0]);
|
|
|
|
return result;
|
|
}
|