diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..baaf3c2686 --- /dev/null +++ b/.clang-format @@ -0,0 +1,156 @@ +--- +Language: Cpp +BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignConsecutiveMacros: true +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: true + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: true + AfterUnion: false + AfterExternBlock: false + BeforeCatch: true + BeforeElse: true + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Allman +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: 2 + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 +IncludeIsMainRegex: '([-_](test|unittest))?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: "^\ +begin_declarations|\ +begin_struct.*$" +MacroBlockEnd: "^\ +end_declarations|\ +end_struct.*$" +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 100 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 1000 +PointerAlignment: Left +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + CanonicalDelimiter: '' + BasedOnStyle: google +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +... diff --git a/cli/args.c b/cli/args.c index 008cfaa176..0addf240ae 100644 --- a/cli/args.c +++ b/cli/args.c @@ -27,25 +27,21 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "args.h" + #include -#include #include - +#include #include -#include "args.h" - -#define args_is_long_arg(arg) \ - (arg[0] == '-' && arg[1] == '-' && arg[2] != '\0') +#define args_is_long_arg(arg) (arg[0] == '-' && arg[1] == '-' && arg[2] != '\0') -#define args_is_short_arg(arg) \ - (arg[0] == '-' && arg[1] != '-' && arg[1] != '\0') +#define args_is_short_arg(arg) \ + (arg[0] == '-' && arg[1] != '-' && arg[1] != '\0') -args_option_t* args_get_short_option( - args_option_t *options, - const char opt) +args_option_t* args_get_short_option(args_option_t* options, const char opt) { while (options->type != ARGS_OPT_END) { @@ -59,11 +55,9 @@ args_option_t* args_get_short_option( } -args_option_t* args_get_long_option( - args_option_t *options, - const char* arg) +args_option_t* args_get_long_option(args_option_t* options, const char* arg) { - arg += 2; // skip starting -- + arg += 2; // skip starting -- while (options->type != ARGS_OPT_END) { @@ -90,52 +84,52 @@ args_error_type_t args_parse_option( const char* opt_arg, int* opt_arg_was_used) { - char *endptr = NULL; + char* endptr = NULL; if (opt_arg_was_used != NULL) - *opt_arg_was_used = 0; + *opt_arg_was_used = 0; if (opt->count == opt->max_count) return ARGS_ERROR_TOO_MANY; switch (opt->type) { - case ARGS_OPT_BOOLEAN: - *(bool*) opt->value = !(*(bool*) opt->value); - break; + case ARGS_OPT_BOOLEAN: + *(bool*) opt->value = !(*(bool*) opt->value); + break; - case ARGS_OPT_INTEGER: + case ARGS_OPT_INTEGER: - if (opt_arg == NULL) - return ARGS_ERROR_REQUIRED_INTEGER_ARG; + if (opt_arg == NULL) + return ARGS_ERROR_REQUIRED_INTEGER_ARG; - *(int*) opt->value = strtol(opt_arg, &endptr, 0); + *(int*) opt->value = strtol(opt_arg, &endptr, 0); - if (*endptr != '\0') - return ARGS_ERROR_REQUIRED_INTEGER_ARG; + if (*endptr != '\0') + return ARGS_ERROR_REQUIRED_INTEGER_ARG; - if (opt_arg_was_used != NULL) - *opt_arg_was_used = 1; + if (opt_arg_was_used != NULL) + *opt_arg_was_used = 1; - break; + break; - case ARGS_OPT_STRING: + case ARGS_OPT_STRING: - if (opt_arg == NULL) - return ARGS_ERROR_REQUIRED_STRING_ARG; + if (opt_arg == NULL) + return ARGS_ERROR_REQUIRED_STRING_ARG; - if (opt->max_count > 1) - ((const char**)opt->value)[opt->count] = opt_arg; - else - *(const char**) opt->value = opt_arg; + if (opt->max_count > 1) + ((const char**) opt->value)[opt->count] = opt_arg; + else + *(const char**) opt->value = opt_arg; - if (opt_arg_was_used != NULL) - *opt_arg_was_used = 1; + if (opt_arg_was_used != NULL) + *opt_arg_was_used = 1; - break; + break; - default: - assert(0); + default: + assert(0); } opt->count++; @@ -144,37 +138,32 @@ args_error_type_t args_parse_option( } -void args_print_error( - args_error_type_t error, - const char* option) +void args_print_error(args_error_type_t error, const char* option) { - switch(error) + switch (error) { - case ARGS_ERROR_UNKNOWN_OPT: - fprintf(stderr, "unknown option `%s`\n", option); - break; - case ARGS_ERROR_TOO_MANY: - fprintf(stderr, "too many `%s` options\n", option); - break; - case ARGS_ERROR_REQUIRED_INTEGER_ARG: - fprintf(stderr, "option `%s` requires an integer argument\n", option); - break; - case ARGS_ERROR_REQUIRED_STRING_ARG: - fprintf(stderr, "option `%s` requires a string argument\n", option); - break; - case ARGS_ERROR_UNEXPECTED_ARG: - fprintf(stderr, "option `%s` doesn't expect an argument\n", option); - break; - default: - return; + case ARGS_ERROR_UNKNOWN_OPT: + fprintf(stderr, "unknown option `%s`\n", option); + break; + case ARGS_ERROR_TOO_MANY: + fprintf(stderr, "too many `%s` options\n", option); + break; + case ARGS_ERROR_REQUIRED_INTEGER_ARG: + fprintf(stderr, "option `%s` requires an integer argument\n", option); + break; + case ARGS_ERROR_REQUIRED_STRING_ARG: + fprintf(stderr, "option `%s` requires a string argument\n", option); + break; + case ARGS_ERROR_UNEXPECTED_ARG: + fprintf(stderr, "option `%s` doesn't expect an argument\n", option); + break; + default: + return; } } -int args_parse( - args_option_t *options, - int argc, - const char **argv) +int args_parse(args_option_t* options, int argc, const char** argv) { args_error_type_t error = ARGS_ERROR_OK; @@ -257,9 +246,7 @@ int args_parse( } -void args_print_usage( - args_option_t *options, - int help_alignment) +void args_print_usage(args_option_t* options, int help_alignment) { char buffer[128]; @@ -278,8 +265,7 @@ void args_print_usage( if (options->long_name != NULL) len += sprintf(buffer + len, "--%s", options->long_name); - if (options->type == ARGS_OPT_STRING || - options->type == ARGS_OPT_INTEGER) + if (options->type == ARGS_OPT_STRING || options->type == ARGS_OPT_INTEGER) { len += sprintf( buffer + len, diff --git a/cli/args.h b/cli/args.h index 1f9d267edf..b5a6658dfc 100644 --- a/cli/args.h +++ b/cli/args.h @@ -34,68 +34,76 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -typedef enum _args_error_type { - ARGS_ERROR_OK, - ARGS_ERROR_UNKNOWN_OPT, - ARGS_ERROR_TOO_MANY, - ARGS_ERROR_REQUIRED_INTEGER_ARG, - ARGS_ERROR_REQUIRED_STRING_ARG, - ARGS_ERROR_UNEXPECTED_ARG, -} args_error_type_t; - - -typedef enum _args_option_type { - // special - ARGS_OPT_END, - ARGS_OPT_GROUP, - // options with no arguments - ARGS_OPT_BOOLEAN, - // options with arguments (optional or required) - ARGS_OPT_INTEGER, - ARGS_OPT_STRING, -} args_option_type_t; - - -typedef struct _args_option { - args_option_type_t type; - const char short_name; - const char *long_name; - void *value; - int max_count; - const char *help; - const char *type_help; - int count; -} args_option_t; - - -#define OPT_BOOLEAN(short_name, long_name, value, ...) \ - { ARGS_OPT_BOOLEAN, short_name, long_name, value, 1, __VA_ARGS__ } - -#define OPT_INTEGER(short_name, long_name, value, ...) \ - { ARGS_OPT_INTEGER, short_name, long_name, value, 1, __VA_ARGS__ } - -#define OPT_STRING_MULTI(short_name, long_name, value, max_count, ...) \ - { ARGS_OPT_STRING, short_name, long_name, value, max_count, __VA_ARGS__ } + typedef enum _args_error_type + { + ARGS_ERROR_OK, + ARGS_ERROR_UNKNOWN_OPT, + ARGS_ERROR_TOO_MANY, + ARGS_ERROR_REQUIRED_INTEGER_ARG, + ARGS_ERROR_REQUIRED_STRING_ARG, + ARGS_ERROR_UNEXPECTED_ARG, + } args_error_type_t; + + + typedef enum _args_option_type + { + // special + ARGS_OPT_END, + ARGS_OPT_GROUP, + // options with no arguments + ARGS_OPT_BOOLEAN, + // options with arguments (optional or required) + ARGS_OPT_INTEGER, + ARGS_OPT_STRING, + } args_option_type_t; + + + typedef struct _args_option + { + args_option_type_t type; + const char short_name; + const char *long_name; + void *value; + int max_count; + const char *help; + const char *type_help; + int count; + } args_option_t; + + +#define OPT_BOOLEAN(short_name, long_name, value, ...) \ + { \ + ARGS_OPT_BOOLEAN, short_name, long_name, value, 1, __VA_ARGS__ \ + } + +#define OPT_INTEGER(short_name, long_name, value, ...) \ + { \ + ARGS_OPT_INTEGER, short_name, long_name, value, 1, __VA_ARGS__ \ + } + +#define OPT_STRING_MULTI(short_name, long_name, value, max_count, ...) \ + { \ + ARGS_OPT_STRING, short_name, long_name, value, max_count, __VA_ARGS__ \ + } #define OPT_STRING(short_name, long_name, value, ...) \ - OPT_STRING_MULTI(short_name, long_name, value, 1, __VA_ARGS__) + OPT_STRING_MULTI(short_name, long_name, value, 1, __VA_ARGS__) -#define OPT_END() { ARGS_OPT_END, 0 } +#define OPT_END() \ + { \ + ARGS_OPT_END, 0 \ + } -int args_parse( - args_option_t *options, - int argc, - const char **argv); + int args_parse(args_option_t *options, int argc, const char **argv); -void args_print_usage( - args_option_t *options, - int alignment); + void args_print_usage(args_option_t *options, int alignment); #ifdef __cplusplus diff --git a/cli/common.h b/cli/common.h index 721a2762e6..d8dd1f1302 100644 --- a/cli/common.h +++ b/cli/common.h @@ -34,19 +34,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #ifdef _WIN32 - #include - #define access _access_s +#include +#define access _access_s #else - #include +#include #endif -#define exit_with_code(code) { result = code; goto _exit; } +#define exit_with_code(code) \ + { \ + result = code; \ + goto _exit; \ + } -bool compile_files( - YR_COMPILER* compiler, - int argc, - const char** argv) +bool compile_files(YR_COMPILER* compiler, int argc, const char** argv) { for (int i = 0; i < argc - 1; i++) { @@ -69,7 +70,6 @@ bool compile_files( // backslash. if (colon && *(colon + 1) != '\\' && *(colon + 1) != '/') { - file_name = colon + 1; *colon = '\0'; ns = argv[i]; @@ -103,7 +103,7 @@ bool compile_files( } -bool is_integer(const char *str) +bool is_integer(const char* str) { if (*str == '-') str++; @@ -111,7 +111,7 @@ bool is_integer(const char *str) if (*str == '\0') return false; - while(*str) + while (*str) { if (!isdigit(*str)) return false; @@ -122,21 +122,21 @@ bool is_integer(const char *str) } -bool is_float(const char *str) +bool is_float(const char* str) { bool has_dot = false; - if (*str == '-') // skip the minus sign if present + if (*str == '-') // skip the minus sign if present str++; - if (*str == '.') // float can't start with a dot + if (*str == '.') // float can't start with a dot return false; - while(*str) + while (*str) { if (*str == '.') { - if (has_dot) // two dots, not a float + if (has_dot) // two dots, not a float return false; has_dot = true; @@ -149,7 +149,7 @@ bool is_float(const char *str) str++; } - return has_dot; // to be float must contain a dot + return has_dot; // to be float must contain a dot } #endif diff --git a/cli/threading.c b/cli/threading.c index 7b52351a3d..3d51401f58 100644 --- a/cli/threading.c +++ b/cli/threading.c @@ -42,64 +42,58 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "threading.h" -int mutex_init( - MUTEX* mutex) +int mutex_init(MUTEX* mutex) { - #if defined(_WIN32) || defined(__CYGWIN__) - InitializeCriticalSection(mutex); - return 0; - #else +#if defined(_WIN32) || defined(__CYGWIN__) + InitializeCriticalSection(mutex); + return 0; +#else return pthread_mutex_init(mutex, NULL); - #endif +#endif } -void mutex_destroy( - MUTEX* mutex) +void mutex_destroy(MUTEX* mutex) { - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) DeleteCriticalSection(mutex); - #else +#else pthread_mutex_destroy(mutex); - #endif +#endif } -void mutex_lock( - MUTEX* mutex) +void mutex_lock(MUTEX* mutex) { - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) EnterCriticalSection(mutex); - #else +#else pthread_mutex_lock(mutex); - #endif +#endif } -void mutex_unlock( - MUTEX* mutex) +void mutex_unlock(MUTEX* mutex) { - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) LeaveCriticalSection(mutex); - #else +#else pthread_mutex_unlock(mutex); - #endif +#endif } -int semaphore_init( - SEMAPHORE* semaphore, - int value) +int semaphore_init(SEMAPHORE* semaphore, int value) { - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) *semaphore = CreateSemaphore(NULL, value, 65535, NULL); if (*semaphore == NULL) return GetLastError(); - #elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) *semaphore = malloc(sizeof(sem_t)); if (*semaphore == NULL) return errno; return sem_init(*semaphore, 0, value); - #else +#else // Mac OS X doesn't support unnamed semaphores via sem_init, that's why // we use sem_open instead sem_init and immediately unlink the semaphore // from the name. More info at: @@ -107,10 +101,11 @@ int semaphore_init( // http://stackoverflow.com/questions/1413785/sem-init-on-os-x // // Also create name for semaphore from PID because running multiple instances - // of YARA at the same time can cause that sem_open() was called in two processes - // simultaneously while neither of them had chance to call sem_unlink() yet. + // of YARA at the same time can cause that sem_open() was called in two + // processes simultaneously while neither of them had chance to call + // sem_unlink() yet. char name[20]; - snprintf(name, sizeof(name), "/yara.sem.%i", (int)getpid()); + snprintf(name, sizeof(name), "/yara.sem.%i", (int) getpid()); *semaphore = sem_open(name, O_CREAT, S_IRUSR, value); if (*semaphore == SEM_FAILED) @@ -118,45 +113,42 @@ int semaphore_init( if (sem_unlink(name) != 0) return errno; - #endif +#endif return 0; } -void semaphore_destroy( - SEMAPHORE* semaphore) +void semaphore_destroy(SEMAPHORE* semaphore) { - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) CloseHandle(*semaphore); - #elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) sem_close(*semaphore); free(*semaphore); - #else +#else sem_close(*semaphore); - #endif +#endif } -void semaphore_wait( - SEMAPHORE* semaphore) +void semaphore_wait(SEMAPHORE* semaphore) { - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) WaitForSingleObject(*semaphore, INFINITE); - #else +#else sem_wait(*semaphore); - #endif +#endif } -void semaphore_release( - SEMAPHORE* semaphore) +void semaphore_release(SEMAPHORE* semaphore) { - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) ReleaseSemaphore(*semaphore, 1, NULL); - #else +#else sem_post(*semaphore); - #endif +#endif } @@ -165,24 +157,23 @@ int create_thread( THREAD_START_ROUTINE start_routine, void* param) { - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) *thread = CreateThread(NULL, 0, start_routine, param, 0, NULL); if (*thread == NULL) return GetLastError(); else return 0; - #else +#else return pthread_create(thread, NULL, start_routine, param); - #endif +#endif } -void thread_join( - THREAD* thread) +void thread_join(THREAD* thread) { - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) WaitForSingleObject(*thread, INFINITE); - #else +#else pthread_join(*thread, NULL); - #endif +#endif } diff --git a/cli/threading.h b/cli/threading.h index 43a68b6274..2b5ddb4469 100644 --- a/cli/threading.h +++ b/cli/threading.h @@ -34,9 +34,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(_WIN32) || defined(__CYGWIN__) #include #else -#include #include #include +#include #endif #if defined(_WIN32) || defined(__CYGWIN__) @@ -52,41 +52,31 @@ typedef LPTHREAD_START_ROUTINE THREAD_START_ROUTINE; typedef sem_t* SEMAPHORE; typedef pthread_mutex_t MUTEX; typedef pthread_t THREAD; -typedef void *(*THREAD_START_ROUTINE) (void *); +typedef void* (*THREAD_START_ROUTINE)(void*); #endif -int mutex_init( - MUTEX* mutex); +int mutex_init(MUTEX* mutex); -void mutex_destroy( - MUTEX* mutex); +void mutex_destroy(MUTEX* mutex); -void mutex_lock( - MUTEX* mutex); +void mutex_lock(MUTEX* mutex); -void mutex_unlock( - MUTEX* mutex); +void mutex_unlock(MUTEX* mutex); -int semaphore_init( - SEMAPHORE* semaphore, - int value); +int semaphore_init(SEMAPHORE* semaphore, int value); -void semaphore_destroy( - SEMAPHORE* semaphore); +void semaphore_destroy(SEMAPHORE* semaphore); -void semaphore_wait( - SEMAPHORE* semaphore); +void semaphore_wait(SEMAPHORE* semaphore); -void semaphore_release( - SEMAPHORE* semaphore); +void semaphore_release(SEMAPHORE* semaphore); int create_thread( THREAD* thread, THREAD_START_ROUTINE start_routine, void* param); -void thread_join( - THREAD* thread); +void thread_join(THREAD* thread); #endif diff --git a/cli/yara.c b/cli/yara.c index 5500c996b1..51cab5251f 100644 --- a/cli/yara.c +++ b/cli/yara.c @@ -32,10 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // for getline(3) #define _POSIX_C_SOURCE 200809L -#include #include -#include #include +#include +#include #else @@ -46,12 +46,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif -#include +#include #include #include #include -#include - +#include #include #include "args.h" @@ -59,19 +58,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "threading.h" -#define ERROR_COULD_NOT_CREATE_THREAD 100 +#define ERROR_COULD_NOT_CREATE_THREAD 100 #ifndef MAX_PATH #define MAX_PATH 256 #endif #ifndef min -#define min(x, y) ((x < y) ? (x) : (y)) +#define min(x, y) ((x < y) ? (x) : (y)) #endif #ifdef _MSC_VER #define snprintf _snprintf -#define strdup _strdup +#define strdup _strdup #endif #define MAX_QUEUED_FILES 64 @@ -96,10 +95,10 @@ typedef struct _CALLBACK_ARGS typedef struct _THREAD_ARGS { - YR_SCANNER* scanner; - CALLBACK_ARGS callback_args; - time_t start_time; - int current_count; + YR_SCANNER* scanner; + CALLBACK_ARGS callback_args; + time_t start_time; + int current_count; } THREAD_ARGS; @@ -125,10 +124,10 @@ typedef struct SCAN_OPTIONS } SCAN_OPTIONS; -#define MAX_ARGS_TAG 32 -#define MAX_ARGS_IDENTIFIER 32 -#define MAX_ARGS_EXT_VAR 32 -#define MAX_ARGS_MODULE_DATA 32 +#define MAX_ARGS_TAG 32 +#define MAX_ARGS_IDENTIFIER 32 +#define MAX_ARGS_EXT_VAR 32 +#define MAX_ARGS_MODULE_DATA 32 static char* atom_quality_table; static char* tags[MAX_ARGS_TAG + 1]; @@ -163,97 +162,158 @@ static int max_strings_per_rule = DEFAULT_MAX_STRINGS_PER_RULE; #define USAGE_STRING \ - "Usage: yara [OPTION]... [NAMESPACE:]RULES_FILE... FILE | DIR | PID" - - -args_option_t options[] = -{ - OPT_STRING(0, "atom-quality-table", &atom_quality_table, - "path to a file with the atom quality table", "FILE"), - - OPT_BOOLEAN('C', "compiled-rules", &rules_are_compiled, - "load compiled rules"), - - OPT_BOOLEAN('c', "count", &print_count_only, - "print only number of matches"), - - OPT_STRING_MULTI('d', "define", &ext_vars, MAX_ARGS_EXT_VAR, - "define external variable", "VAR=VALUE"), - - OPT_BOOLEAN(0, "fail-on-warnings", &fail_on_warnings, - "fail on warnings"), - - OPT_BOOLEAN('f', "fast-scan", &fast_scan, - "fast matching mode"), - - OPT_BOOLEAN('h', "help", &show_help, - "show this help and exit"), - - OPT_STRING_MULTI('i', "identifier", &identifiers, MAX_ARGS_IDENTIFIER, - "print only rules named IDENTIFIER", "IDENTIFIER"), - - OPT_INTEGER('l', "max-rules", &limit, - "abort scanning after matching a NUMBER of rules", "NUMBER"), - - OPT_INTEGER(0, "max-strings-per-rule", &max_strings_per_rule, - "set maximum number of strings per rule (default=10000)", "NUMBER"), - - OPT_STRING_MULTI('x', "module-data", &modules_data, MAX_ARGS_MODULE_DATA, - "pass FILE's content as extra data to MODULE", "MODULE=FILE"), - - OPT_BOOLEAN('n', "negate", &negate, - "print only not satisfied rules (negate)", NULL), - - OPT_BOOLEAN('w', "no-warnings", &ignore_warnings, - "disable warnings"), - - OPT_BOOLEAN('m', "print-meta", &show_meta, - "print metadata"), - - OPT_BOOLEAN('D', "print-module-data", &show_module_data, - "print module data"), - - OPT_BOOLEAN('e', "print-namespace", &show_namespace, - "print rules' namespace"), - - OPT_BOOLEAN('S', "print-stats", &show_stats, - "print rules' statistics"), - - OPT_BOOLEAN('s', "print-strings", &show_strings, - "print matching strings"), - - OPT_BOOLEAN('L', "print-string-length", &show_string_length, - "print length of matched strings"), - - OPT_BOOLEAN('g', "print-tags", &show_tags, - "print tags"), - - OPT_BOOLEAN('r', "recursive", &recursive_search, - "recursively search directories"), - - OPT_BOOLEAN('N', "no-follow-symlinks", &follow_symlinks, - "do not follow symlinks when scanning"), - - OPT_BOOLEAN(0, "scan-list", &scan_list_search, - "scan files listed in FILE, one per line"), - - OPT_INTEGER('k', "stack-size", &stack_size, - "set maximum stack size (default=16384)", "SLOTS"), - - OPT_STRING_MULTI('t', "tag", &tags, MAX_ARGS_TAG, - "print only rules tagged as TAG", "TAG"), - - OPT_INTEGER('p', "threads", &threads, - "use the specified NUMBER of threads to scan a directory", "NUMBER"), - - OPT_INTEGER('a', "timeout", &timeout, - "abort scanning after the given number of SECONDS", "SECONDS"), - - OPT_BOOLEAN('v', "version", &show_version, - "show version information"), - - OPT_END() -}; + "Usage: yara [OPTION]... [NAMESPACE:]RULES_FILE... FILE | DIR | PID" + + +args_option_t options[] = { + OPT_STRING( + 0, + "atom-quality-table", + &atom_quality_table, + "path to a file with the atom quality table", + "FILE"), + + OPT_BOOLEAN( + 'C', + "compiled-rules", + &rules_are_compiled, + "load compiled rules"), + + OPT_BOOLEAN( + 'c', + "count", + &print_count_only, + "print only number of matches"), + + OPT_STRING_MULTI( + 'd', + "define", + &ext_vars, + MAX_ARGS_EXT_VAR, + "define external variable", + "VAR=VALUE"), + + OPT_BOOLEAN(0, "fail-on-warnings", &fail_on_warnings, "fail on warnings"), + + OPT_BOOLEAN('f', "fast-scan", &fast_scan, "fast matching mode"), + + OPT_BOOLEAN('h', "help", &show_help, "show this help and exit"), + + OPT_STRING_MULTI( + 'i', + "identifier", + &identifiers, + MAX_ARGS_IDENTIFIER, + "print only rules named IDENTIFIER", + "IDENTIFIER"), + + OPT_INTEGER( + 'l', + "max-rules", + &limit, + "abort scanning after matching a NUMBER of rules", + "NUMBER"), + + OPT_INTEGER( + 0, + "max-strings-per-rule", + &max_strings_per_rule, + "set maximum number of strings per rule (default=10000)", + "NUMBER"), + + OPT_STRING_MULTI( + 'x', + "module-data", + &modules_data, + MAX_ARGS_MODULE_DATA, + "pass FILE's content as extra data to MODULE", + "MODULE=FILE"), + + OPT_BOOLEAN( + 'n', + "negate", + &negate, + "print only not satisfied rules (negate)", + NULL), + + OPT_BOOLEAN('w', "no-warnings", &ignore_warnings, "disable warnings"), + + OPT_BOOLEAN('m', "print-meta", &show_meta, "print metadata"), + + OPT_BOOLEAN( + 'D', + "print-module-data", + &show_module_data, + "print module data"), + + OPT_BOOLEAN( + 'e', + "print-namespace", + &show_namespace, + "print rules' namespace"), + + OPT_BOOLEAN('S', "print-stats", &show_stats, "print rules' statistics"), + + OPT_BOOLEAN('s', "print-strings", &show_strings, "print matching strings"), + + OPT_BOOLEAN( + 'L', + "print-string-length", + &show_string_length, + "print length of matched strings"), + + OPT_BOOLEAN('g', "print-tags", &show_tags, "print tags"), + + OPT_BOOLEAN( + 'r', + "recursive", + &recursive_search, + "recursively search directories"), + + OPT_BOOLEAN( + 'N', + "no-follow-symlinks", + &follow_symlinks, + "do not follow symlinks when scanning"), + + OPT_BOOLEAN( + 0, + "scan-list", + &scan_list_search, + "scan files listed in FILE, one per line"), + + OPT_INTEGER( + 'k', + "stack-size", + &stack_size, + "set maximum stack size (default=16384)", + "SLOTS"), + + OPT_STRING_MULTI( + 't', + "tag", + &tags, + MAX_ARGS_TAG, + "print only rules tagged as TAG", + "TAG"), + + OPT_INTEGER( + 'p', + "threads", + &threads, + "use the specified NUMBER of threads to scan a directory", + "NUMBER"), + + OPT_INTEGER( + 'a', + "timeout", + &timeout, + "abort scanning after the given number of SECONDS", + "SECONDS"), + + OPT_BOOLEAN('v', "version", &show_version, "show version information"), + + OPT_END()}; // file_queue is size-limited queue stored as a circular array, files are @@ -293,7 +353,7 @@ static int file_queue_init() if (result != 0) return result; - return semaphore_init(&unused_slots, MAX_QUEUED_FILES); + return semaphore_init(&unused_slots, MAX_QUEUED_FILES); } @@ -309,13 +369,11 @@ static void file_queue_finish() { int i; - for (i = 0; i < YR_MAX_THREADS; i++) - semaphore_release(&used_slots); + for (i = 0; i < YR_MAX_THREADS; i++) semaphore_release(&used_slots); } -static void file_queue_put( - const char* file_path) +static void file_queue_put(const char* file_path) { semaphore_wait(&unused_slots); mutex_lock(&queue_mutex); @@ -335,7 +393,7 @@ static char* file_queue_get() semaphore_wait(&used_slots); mutex_lock(&queue_mutex); - if (queue_head == queue_tail) // queue is empty + if (queue_head == queue_tail) // queue is empty { result = NULL; } @@ -354,13 +412,12 @@ static char* file_queue_get() #if defined(_WIN32) || defined(__CYGWIN__) -static bool is_directory( - const char* path) +static bool is_directory(const char* path) { DWORD attributes = GetFileAttributes(path); if (attributes != INVALID_FILE_ATTRIBUTES && - attributes & FILE_ATTRIBUTE_DIRECTORY) + attributes & FILE_ATTRIBUTE_DIRECTORY) return true; else return false; @@ -384,16 +441,17 @@ static void scan_dir( { char full_path[MAX_PATH]; - snprintf(full_path, sizeof(full_path), "%s\\%s", - dir, FindFileData.cFileName); + snprintf( + full_path, sizeof(full_path), "%s\\%s", dir, FindFileData.cFileName); if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { file_queue_put(full_path); } - else if (scan_opts->recursive_search && - strcmp(FindFileData.cFileName, ".") != 0 && - strcmp(FindFileData.cFileName, "..") != 0) + else if ( + scan_opts->recursive_search && + strcmp(FindFileData.cFileName, ".") != 0 && + strcmp(FindFileData.cFileName, "..") != 0) { scan_dir(full_path, scan_opts, start_time); } @@ -418,8 +476,13 @@ static int populate_scan_list( DWORD nread; HANDLE hFile = CreateFile( - filename, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + filename, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); if (hFile == INVALID_HANDLE_VALUE) { @@ -431,8 +494,8 @@ static int populate_scan_list( if (fileSize == INVALID_FILE_SIZE) { - fprintf(stderr, - "error: could not determine size of file \"%s\".\n", filename); + fprintf( + stderr, "error: could not determine size of file \"%s\".\n", filename); CloseHandle(hFile); return ERROR_COULD_NOT_READ_FILE; } @@ -443,8 +506,10 @@ static int populate_scan_list( if (buf == NULL) { - fprintf(stderr, - "error: could not allocate memory for file \"%s\".\n", filename); + fprintf( + stderr, + "error: could not allocate memory for file \"%s\".\n", + filename); CloseHandle(hFile); return ERROR_INSUFFICIENT_MEMORY; } @@ -486,8 +551,7 @@ static int populate_scan_list( #else -static bool is_directory( - const char* path) +static bool is_directory(const char* path) { struct stat st; @@ -531,10 +595,9 @@ static void scan_dir( { file_queue_put(full_path); } - else if (scan_opts->recursive_search && - S_ISDIR(st.st_mode) && - strcmp(de->d_name, ".") != 0 && - strcmp(de->d_name, "..") != 0) + else if ( + scan_opts->recursive_search && S_ISDIR(st.st_mode) && + strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) { scan_dir(full_path, scan_opts, start_time); } @@ -585,9 +648,7 @@ static int populate_scan_list( #endif -static void print_string( - const uint8_t* data, - int length) +static void print_string(const uint8_t* data, int length) { for (int i = 0; i < length; i++) { @@ -601,18 +662,13 @@ static void print_string( } -static char cescapes[] = -{ - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 'a', - 'b', 't', 'n', 'v', 'f', 'r', 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , +static char cescapes[] = { + 0, 0, 0, 0, 0, 0, 0, 'a', 'b', 't', 'n', 'v', 'f', 'r', 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -static void print_escaped( - const uint8_t* data, - size_t length) +static void print_escaped(const uint8_t* data, size_t length) { size_t i; @@ -620,29 +676,27 @@ static void print_escaped( { switch (data[i]) { - case '\"': - case '\'': - case '\\': - printf("\\%c", data[i]); - break; + case '\"': + case '\'': + case '\\': + printf("\\%c", data[i]); + break; - default: - if (data[i] >= 127) - printf("\\%03o", data[i]); - else if (data[i] >= 32) - putchar(data[i]); - else if (cescapes[data[i]] != 0) - printf("\\%c", cescapes[data[i]]); - else - printf("\\%03o", data[i]); + default: + if (data[i] >= 127) + printf("\\%03o", data[i]); + else if (data[i] >= 32) + putchar(data[i]); + else if (cescapes[data[i]] != 0) + printf("\\%c", cescapes[data[i]]); + else + printf("\\%03o", data[i]); } } } -static void print_hex_string( - const uint8_t* data, - int length) +static void print_hex_string(const uint8_t* data, int length) { for (int i = 0; i < min(32, length); i++) printf("%s%02X", (i == 0 ? "" : " "), data[i]); @@ -651,53 +705,52 @@ static void print_hex_string( } -static void print_error( - int error) +static void print_error(int error) { switch (error) { - case ERROR_SUCCESS: - break; - case ERROR_COULD_NOT_ATTACH_TO_PROCESS: - fprintf(stderr, "can not attach to process (try running as root)\n"); - break; - case ERROR_INSUFFICIENT_MEMORY: - fprintf(stderr, "not enough memory\n"); - break; - case ERROR_SCAN_TIMEOUT: - fprintf(stderr, "scanning timed out\n"); - break; - case ERROR_COULD_NOT_OPEN_FILE: - fprintf(stderr, "could not open file\n"); - break; - case ERROR_UNSUPPORTED_FILE_VERSION: - fprintf(stderr, "rules were compiled with a different version of YARA\n"); - break; - case ERROR_INVALID_FILE: - fprintf(stderr, "invalid compiled rules file.\n"); - break; - case ERROR_CORRUPT_FILE: - fprintf(stderr, "corrupt compiled rules file.\n"); - break; - case ERROR_EXEC_STACK_OVERFLOW: - fprintf(stderr, "stack overflow while evaluating condition " - "(see --stack-size argument) \n"); - break; - case ERROR_INVALID_EXTERNAL_VARIABLE_TYPE: - fprintf(stderr, "invalid type for external variable\n"); - break; - case ERROR_TOO_MANY_MATCHES: - fprintf(stderr, "too many matches\n"); - break; - default: - fprintf(stderr, "error: %d\n", error); - break; + case ERROR_SUCCESS: + break; + case ERROR_COULD_NOT_ATTACH_TO_PROCESS: + fprintf(stderr, "can not attach to process (try running as root)\n"); + break; + case ERROR_INSUFFICIENT_MEMORY: + fprintf(stderr, "not enough memory\n"); + break; + case ERROR_SCAN_TIMEOUT: + fprintf(stderr, "scanning timed out\n"); + break; + case ERROR_COULD_NOT_OPEN_FILE: + fprintf(stderr, "could not open file\n"); + break; + case ERROR_UNSUPPORTED_FILE_VERSION: + fprintf(stderr, "rules were compiled with a different version of YARA\n"); + break; + case ERROR_INVALID_FILE: + fprintf(stderr, "invalid compiled rules file.\n"); + break; + case ERROR_CORRUPT_FILE: + fprintf(stderr, "corrupt compiled rules file.\n"); + break; + case ERROR_EXEC_STACK_OVERFLOW: + fprintf( + stderr, + "stack overflow while evaluating condition " + "(see --stack-size argument) \n"); + break; + case ERROR_INVALID_EXTERNAL_VARIABLE_TYPE: + fprintf(stderr, "invalid type for external variable\n"); + break; + case ERROR_TOO_MANY_MATCHES: + fprintf(stderr, "too many matches\n"); + break; + default: + fprintf(stderr, "error: %d\n", error); + break; } } -static void print_scanner_error( - YR_SCANNER* scanner, - int error) +static void print_scanner_error(YR_SCANNER* scanner, int error) { YR_RULE* rule = yr_scanner_last_error_rule(scanner); YR_STRING* string = yr_scanner_last_error_string(scanner); @@ -712,10 +765,7 @@ static void print_scanner_error( } else if (rule != NULL) { - fprintf( - stderr, - "rule \"%s\" caused ", - rule->identifier); + fprintf(stderr, "rule \"%s\" caused ", rule->identifier); } print_error(error); @@ -761,18 +811,12 @@ static void print_compiler_error( else { fprintf( - stderr, - "%s(%d): %s: %s\n", - file_name, - line_number, - msg_type, - message); + stderr, "%s(%d): %s: %s\n", file_name, line_number, msg_type, message); } } -static void print_rules_stats( - YR_RULES* rules) +static void print_rules_stats(YR_RULES* rules) { YR_RULES_STATS stats; @@ -783,29 +827,21 @@ static void print_rules_stats( if (result != ERROR_SUCCESS) { - print_error(result); - return; + print_error(result); + return; } - printf( - "size of AC transition table : %d\n", - stats.ac_tables_size); + printf("size of AC transition table : %d\n", stats.ac_tables_size); printf( "average length of AC matches lists : %f\n", stats.ac_average_match_list_length); - printf( - "number of rules : %d\n", - stats.num_rules); + printf("number of rules : %d\n", stats.num_rules); - printf( - "number of strings : %d\n", - stats.num_strings); + printf("number of strings : %d\n", stats.num_strings); - printf( - "number of AC matches : %d\n", - stats.ac_matches); + printf("number of AC matches : %d\n", stats.ac_matches); printf( "number of AC matches in root node : %d\n", @@ -945,14 +981,16 @@ static int handle_message( yr_string_matches_foreach(context, string, match) { if (show_string_length) - printf("0x%" PRIx64 ":%d:%s", - match->base + match->offset, - match->data_length, - string->identifier); + printf( + "0x%" PRIx64 ":%d:%s", + match->base + match->offset, + match->data_length, + string->identifier); else - printf("0x%" PRIx64 ":%s", - match->base + match->offset, - string->identifier); + printf( + "0x%" PRIx64 ":%s", + match->base + match->offset, + string->identifier); if (show_strings) { @@ -997,47 +1035,46 @@ static int callback( YR_OBJECT* object; MODULE_DATA* module_data; - switch(message) + switch (message) { - case CALLBACK_MSG_RULE_MATCHING: - case CALLBACK_MSG_RULE_NOT_MATCHING: - return handle_message( - context, message, (YR_RULE*) message_data, user_data); + case CALLBACK_MSG_RULE_MATCHING: + case CALLBACK_MSG_RULE_NOT_MATCHING: + return handle_message(context, message, (YR_RULE*) message_data, user_data); - case CALLBACK_MSG_IMPORT_MODULE: + case CALLBACK_MSG_IMPORT_MODULE: - mi = (YR_MODULE_IMPORT*) message_data; - module_data = modules_data_list; + mi = (YR_MODULE_IMPORT*) message_data; + module_data = modules_data_list; - while (module_data != NULL) + while (module_data != NULL) + { + if (strcmp(module_data->module_name, mi->module_name) == 0) { - if (strcmp(module_data->module_name, mi->module_name) == 0) - { - mi->module_data = (void*) module_data->mapped_file.data; - mi->module_data_size = module_data->mapped_file.size; - break; - } - - module_data = module_data->next; + mi->module_data = (void*) module_data->mapped_file.data; + mi->module_data_size = module_data->mapped_file.size; + break; } - return CALLBACK_CONTINUE; + module_data = module_data->next; + } - case CALLBACK_MSG_MODULE_IMPORTED: + return CALLBACK_CONTINUE; - if (show_module_data) - { - object = (YR_OBJECT*) message_data; + case CALLBACK_MSG_MODULE_IMPORTED: - mutex_lock(&output_mutex); + if (show_module_data) + { + object = (YR_OBJECT*) message_data; - yr_object_print_data(object, 0, 1); - printf("\n"); + mutex_lock(&output_mutex); - mutex_unlock(&output_mutex); - } + yr_object_print_data(object, 0, 1); + printf("\n"); - return CALLBACK_CONTINUE; + mutex_unlock(&output_mutex); + } + + return CALLBACK_CONTINUE; } return CALLBACK_ERROR; @@ -1095,9 +1132,7 @@ static void* scanning_thread(void* param) } -static int define_external_variables( - YR_RULES* rules, - YR_COMPILER* compiler) +static int define_external_variables(YR_RULES* rules, YR_COMPILER* compiler) { int result = ERROR_SUCCESS; @@ -1123,58 +1158,40 @@ static int define_external_variables( if (is_float(value)) { if (rules != NULL) - result = yr_rules_define_float_variable( - rules, - identifier, - atof(value)); + result = yr_rules_define_float_variable(rules, identifier, atof(value)); if (compiler != NULL) result = yr_compiler_define_float_variable( - compiler, - identifier, - atof(value)); + compiler, identifier, atof(value)); } else if (is_integer(value)) { if (rules != NULL) result = yr_rules_define_integer_variable( - rules, - identifier, - atoi(value)); + rules, identifier, atoi(value)); if (compiler != NULL) result = yr_compiler_define_integer_variable( - compiler, - identifier, - atoi(value)); + compiler, identifier, atoi(value)); } else if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) { if (rules != NULL) result = yr_rules_define_boolean_variable( - rules, - identifier, - strcmp(value, "true") == 0); + rules, identifier, strcmp(value, "true") == 0); if (compiler != NULL) result = yr_compiler_define_boolean_variable( - compiler, - identifier, - strcmp(value, "true") == 0); + compiler, identifier, strcmp(value, "true") == 0); } else { if (rules != NULL) - result = yr_rules_define_string_variable( - rules, - identifier, - value); + result = yr_rules_define_string_variable(rules, identifier, value); if (compiler != NULL) result = yr_compiler_define_string_variable( - compiler, - identifier, - value); + compiler, identifier, value); } } @@ -1224,7 +1241,7 @@ static void unload_modules_data() { MODULE_DATA* module_data = modules_data_list; - while(module_data != NULL) + while (module_data != NULL) { MODULE_DATA* next_module_data = module_data->next; @@ -1238,9 +1255,7 @@ static void unload_modules_data() } -int main( - int argc, - const char** argv) +int main(int argc, const char** argv) { COMPILER_RESULTS cr; @@ -1267,13 +1282,16 @@ int main( if (show_help) { printf( - "YARA %s, the pattern matching swiss army knife.\n" - "%s\n\n" - "Mandatory arguments to long options are mandatory for " - "short options too.\n\n", YR_VERSION, USAGE_STRING); + "YARA %s, the pattern matching swiss army knife.\n" + "%s\n\n" + "Mandatory arguments to long options are mandatory for " + "short options too.\n\n", + YR_VERSION, + USAGE_STRING); args_print_usage(options, 40); - printf("\nSend bug reports and suggestions to: vmalvarez@virustotal.com.\n"); + printf( + "\nSend bug reports and suggestions to: vmalvarez@virustotal.com.\n"); return EXIT_SUCCESS; } @@ -1321,9 +1339,10 @@ int main( if (argc != 2) { - fprintf(stderr, - "error: can't accept multiple rules files if one of them is in " - "compiled form.\n"); + fprintf( + stderr, + "error: can't accept multiple rules files if one of them is in " + "compiled form.\n"); exit_with_code(EXIT_FAILURE); } @@ -1430,9 +1449,7 @@ int main( } yr_scanner_set_callback( - thread_args[i].scanner, - callback, - &thread_args[i].callback_args); + thread_args[i].scanner, callback, &thread_args[i].callback_args); yr_scanner_set_flags(thread_args[i].scanner, flags); @@ -1458,17 +1475,15 @@ int main( file_queue_finish(); // Wait for scan threads to finish - for (i = 0; i < threads; i++) - thread_join(&thread[i]); + for (i = 0; i < threads; i++) thread_join(&thread[i]); - for (i = 0; i < threads; i++) - yr_scanner_destroy(thread_args[i].scanner); + for (i = 0; i < threads; i++) yr_scanner_destroy(thread_args[i].scanner); file_queue_destroy(); } else { - CALLBACK_ARGS user_data = { argv[argc - 1], 0 }; + CALLBACK_ARGS user_data = {argv[argc - 1], 0}; result = yr_scanner_create(rules, &scanner); @@ -1497,9 +1512,9 @@ int main( if (print_count_only) printf("%d\n", user_data.current_count); - #ifdef YR_PROFILING_ENABLED +#ifdef YR_PROFILING_ENABLED yr_scanner_print_profiling_info(scanner); - #endif +#endif } result = EXIT_SUCCESS; diff --git a/cli/yarac.c b/cli/yarac.c index 1b124eb2bb..22997e7cd7 100644 --- a/cli/yarac.c +++ b/cli/yarac.c @@ -29,10 +29,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef _WIN32 -#include #include -#include +#include #include +#include #else @@ -40,10 +40,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif +#include #include #include #include -#include #include #include "args.h" @@ -54,7 +54,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define MAX_PATH 256 #endif -#define MAX_ARGS_EXT_VAR 32 +#define MAX_ARGS_EXT_VAR 32 typedef struct COMPILER_RESULTS @@ -75,33 +75,40 @@ static int max_strings_per_rule = DEFAULT_MAX_STRINGS_PER_RULE; #define USAGE_STRING \ - "Usage: yarac [OPTION]... [NAMESPACE:]SOURCE_FILE... OUTPUT_FILE" + "Usage: yarac [OPTION]... [NAMESPACE:]SOURCE_FILE... OUTPUT_FILE" -args_option_t options[] = -{ - OPT_STRING(0, "atom-quality-table", &atom_quality_table, - "path to a file with the atom quality table", "FILE"), +args_option_t options[] = { + OPT_STRING( + 0, + "atom-quality-table", + &atom_quality_table, + "path to a file with the atom quality table", + "FILE"), - OPT_STRING_MULTI('d', "define", &ext_vars, MAX_ARGS_EXT_VAR, - "define external variable", "VAR=VALUE"), + OPT_STRING_MULTI( + 'd', + "define", + &ext_vars, + MAX_ARGS_EXT_VAR, + "define external variable", + "VAR=VALUE"), - OPT_BOOLEAN(0, "fail-on-warnings", &fail_on_warnings, - "fail on warnings"), + OPT_BOOLEAN(0, "fail-on-warnings", &fail_on_warnings, "fail on warnings"), - OPT_BOOLEAN('h', "help", &show_help, - "show this help and exit"), + OPT_BOOLEAN('h', "help", &show_help, "show this help and exit"), - OPT_INTEGER(0, "max-strings-per-rule", &max_strings_per_rule, - "set maximum number of strings per rule (default=10000)", "NUMBER"), + OPT_INTEGER( + 0, + "max-strings-per-rule", + &max_strings_per_rule, + "set maximum number of strings per rule (default=10000)", + "NUMBER"), - OPT_BOOLEAN('w', "no-warnings", &ignore_warnings, - "disable warnings"), + OPT_BOOLEAN('w', "no-warnings", &ignore_warnings, "disable warnings"), - OPT_BOOLEAN('v', "version", &show_version, - "show version information"), + OPT_BOOLEAN('v', "version", &show_version, "show version information"), - OPT_END() -}; + OPT_END()}; static void report_error( @@ -143,18 +150,12 @@ static void report_error( else { fprintf( - stderr, - "%s(%d): %s: %s\n", - file_name, - line_number, - msg_type, - message); + stderr, "%s(%d): %s: %s\n", file_name, line_number, msg_type, message); } } -static bool define_external_variables( - YR_COMPILER* compiler) +static bool define_external_variables(YR_COMPILER* compiler) { for (int i = 0; ext_vars[i] != NULL; i++) { @@ -177,31 +178,20 @@ static bool define_external_variables( if (is_float(value)) { - yr_compiler_define_float_variable( - compiler, - identifier, - atof(value)); + yr_compiler_define_float_variable(compiler, identifier, atof(value)); } else if (is_integer(value)) { - yr_compiler_define_integer_variable( - compiler, - identifier, - atoi(value)); + yr_compiler_define_integer_variable(compiler, identifier, atoi(value)); } else if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) { yr_compiler_define_boolean_variable( - compiler, - identifier, - strcmp(value, "true") == 0); + compiler, identifier, strcmp(value, "true") == 0); } else { - yr_compiler_define_string_variable( - compiler, - identifier, - value); + yr_compiler_define_string_variable(compiler, identifier, value); } } @@ -209,9 +199,7 @@ static bool define_external_variables( } -int main( - int argc, - const char** argv) +int main(int argc, const char** argv) { COMPILER_RESULTS cr; diff --git a/libyara/ahocorasick.c b/libyara/ahocorasick.c index 6dcbd06b00..00a077ff9f 100644 --- a/libyara/ahocorasick.c +++ b/libyara/ahocorasick.c @@ -30,21 +30,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include - -#include #include +#include #include #include -#include #include +#include typedef struct _QUEUE_NODE { YR_AC_STATE* value; - struct _QUEUE_NODE* previous; - struct _QUEUE_NODE* next; + struct _QUEUE_NODE* previous; + struct _QUEUE_NODE* next; } QUEUE_NODE; @@ -70,9 +69,7 @@ typedef struct _QUEUE // ERROR_SUCCESS if succeed or the corresponding error code otherwise. // -static int _yr_ac_queue_push( - QUEUE* queue, - YR_AC_STATE* value) +static int _yr_ac_queue_push(QUEUE* queue, YR_AC_STATE* value) { QUEUE_NODE* pushed_node; @@ -87,7 +84,7 @@ static int _yr_ac_queue_push( if (queue->tail != NULL) queue->tail->next = pushed_node; - else // queue is empty + else // queue is empty queue->head = pushed_node; queue->tail = pushed_node; @@ -108,8 +105,7 @@ static int _yr_ac_queue_push( // Pointer to the poped state. // -static YR_AC_STATE* _yr_ac_queue_pop( - QUEUE* queue) +static YR_AC_STATE* _yr_ac_queue_pop(QUEUE* queue) { YR_AC_STATE* result; QUEUE_NODE* popped_node; @@ -122,7 +118,7 @@ static YR_AC_STATE* _yr_ac_queue_pop( if (queue->head) queue->head->previous = NULL; - else // queue is empty + else // queue is empty queue->tail = NULL; result = popped_node->value; @@ -144,8 +140,7 @@ static YR_AC_STATE* _yr_ac_queue_pop( // true if queue is empty, false otherwise. // -static int _yr_ac_queue_is_empty( - QUEUE* queue) +static int _yr_ac_queue_is_empty(QUEUE* queue) { return queue->head == NULL; } @@ -165,9 +160,7 @@ static int _yr_ac_queue_is_empty( // Pointer to the next automaton state. // -static YR_AC_STATE* _yr_ac_next_state( - YR_AC_STATE* state, - uint8_t input) +static YR_AC_STATE* _yr_ac_next_state(YR_AC_STATE* state, uint8_t input) { YR_AC_STATE* next_state = state->first_child; @@ -197,9 +190,7 @@ static YR_AC_STATE* _yr_ac_next_state( // YR_AC_STATE* pointer to the newly allocated state or NULL in case // of error. -static YR_AC_STATE* _yr_ac_state_create( - YR_AC_STATE* state, - uint8_t input) +static YR_AC_STATE* _yr_ac_state_create(YR_AC_STATE* state, uint8_t input) { YR_AC_STATE* new_state = (YR_AC_STATE*) yr_malloc(sizeof(YR_AC_STATE)); @@ -223,8 +214,7 @@ static YR_AC_STATE* _yr_ac_state_create( // _yr_ac_state_destroy // -static int _yr_ac_state_destroy( - YR_AC_STATE* state) +static int _yr_ac_state_destroy(YR_AC_STATE* state) { YR_AC_STATE* child_state = state->first_child; @@ -248,8 +238,7 @@ static int _yr_ac_state_destroy( // be called after all the strings have been added to the automaton. // -static int _yr_ac_create_failure_links( - YR_AC_AUTOMATON* automaton) +static int _yr_ac_create_failure_links(YR_AC_AUTOMATON* automaton) { YR_AC_STATE* current_state; YR_AC_STATE* failure_state; @@ -285,14 +274,12 @@ static int _yr_ac_create_failure_links( while (!_yr_ac_queue_is_empty(&queue)) { current_state = _yr_ac_queue_pop(&queue); - match = yr_arena_ref_to_ptr( - automaton->arena, ¤t_state->matches_ref); + match = yr_arena_ref_to_ptr(automaton->arena, ¤t_state->matches_ref); if (match != NULL) { // Find the last match in the list of matches. - while (match->next != NULL) - match = match->next; + while (match->next != NULL) match = match->next; if (match->backtrack > 0) match->next = yr_arena_ref_to_ptr( @@ -315,8 +302,7 @@ static int _yr_ac_create_failure_links( while (1) { - temp_state = _yr_ac_next_state( - failure_state, transition_state->input); + temp_state = _yr_ac_next_state(failure_state, transition_state->input); if (temp_state != NULL) { @@ -334,8 +320,7 @@ static int _yr_ac_create_failure_links( assert(match != NULL); // Find the last match in the list of matches. - while (match->next != NULL) - match = match->next; + while (match->next != NULL) match = match->next; match->next = yr_arena_ref_to_ptr( automaton->arena, &temp_state->matches_ref); @@ -355,12 +340,12 @@ static int _yr_ac_create_failure_links( failure_state = failure_state->failure; } } - } // while(1) + } // while(1) transition_state = transition_state->siblings; } - } // while(!__yr_ac_queue_is_empty(&queue)) + } // while(!__yr_ac_queue_is_empty(&queue)) return ERROR_SUCCESS; } @@ -374,9 +359,7 @@ static int _yr_ac_create_failure_links( // accepted in s1 too. // -static bool _yr_ac_transitions_subset( - YR_AC_STATE* s1, - YR_AC_STATE* s2) +static bool _yr_ac_transitions_subset(YR_AC_STATE* s1, YR_AC_STATE* s2) { uint8_t set[32]; @@ -410,10 +393,9 @@ static bool _yr_ac_transitions_subset( // Removes unnecessary failure links. // -static int _yr_ac_optimize_failure_links( - YR_AC_AUTOMATON* automaton) +static int _yr_ac_optimize_failure_links(YR_AC_AUTOMATON* automaton) { - QUEUE queue = { NULL, NULL}; + QUEUE queue = {NULL, NULL}; // Push root's children. YR_AC_STATE* root_state = automaton->root; @@ -497,31 +479,25 @@ static int _yr_ac_find_suitable_transition_table_slot( if (*slot > automaton->tables_size - 257) { - FAIL_ON_ERROR(yr_arena_allocate_zeroed_memory( - arena, - YR_AC_TRANSITION_TABLE, - 257 * sizeof(YR_AC_TRANSITION), - NULL)); + FAIL_ON_ERROR(yr_arena_allocate_zeroed_memory( + arena, YR_AC_TRANSITION_TABLE, 257 * sizeof(YR_AC_TRANSITION), NULL)); - FAIL_ON_ERROR(yr_arena_allocate_zeroed_memory( - arena, - YR_AC_STATE_MATCHES_TABLE, - 257 * sizeof(uint8_t*), - NULL)); + FAIL_ON_ERROR(yr_arena_allocate_zeroed_memory( + arena, YR_AC_STATE_MATCHES_TABLE, 257 * sizeof(uint8_t*), NULL)); - size_t bm_len = YR_BITMASK_SIZE(automaton->tables_size) * - sizeof(YR_BITMASK); + size_t bm_len = YR_BITMASK_SIZE(automaton->tables_size) * + sizeof(YR_BITMASK); - size_t bm_len_incr = YR_BITMASK_SIZE(257) * sizeof(YR_BITMASK); + size_t bm_len_incr = YR_BITMASK_SIZE(257) * sizeof(YR_BITMASK); - automaton->bitmask = yr_realloc(automaton->bitmask, bm_len + bm_len_incr); + automaton->bitmask = yr_realloc(automaton->bitmask, bm_len + bm_len_incr); - if (automaton->bitmask == NULL) - return ERROR_INSUFFICIENT_MEMORY; + if (automaton->bitmask == NULL) + return ERROR_INSUFFICIENT_MEMORY; - memset((uint8_t*) automaton->bitmask + bm_len, 0, bm_len_incr); + memset((uint8_t*) automaton->bitmask + bm_len, 0, bm_len_incr); - automaton->tables_size += 257; + automaton->tables_size += 257; } return ERROR_SUCCESS; @@ -585,8 +561,7 @@ static int _yr_ac_find_suitable_transition_table_slot( // // A more detailed description can be found in: http://goo.gl/lE6zG -static int _yr_ac_build_transition_table( - YR_AC_AUTOMATON* automaton) +static int _yr_ac_build_transition_table(YR_AC_AUTOMATON* automaton) { YR_AC_TRANSITION* t_table; uint32_t* m_table; @@ -596,7 +571,7 @@ static int _yr_ac_build_transition_table( uint32_t slot; - QUEUE queue = { NULL, NULL }; + QUEUE queue = {NULL, NULL}; // Both t_table and m_table have 512 slots initially, which is enough for the // root node's transition table. @@ -722,20 +697,23 @@ static void _yr_ac_print_automaton_state( YR_AC_MATCH* match; YR_AC_STATE* child_state; - for (int i = 0; i < state->depth; i++) - printf(" "); + for (int i = 0; i < state->depth; i++) printf(" "); child_state = state->first_child; child_count = 0; - while(child_state != NULL) + while (child_state != NULL) { child_count++; child_state = child_state->siblings; } - printf("%p childs:%d depth:%d failure:%p", - state, child_count, state->depth, state->failure); + printf( + "%p childs:%d depth:%d failure:%p", + state, + child_count, + state->depth, + state->failure); match = yr_arena_ref_to_ptr(automaton->arena, &state->matches_ref); @@ -743,8 +721,7 @@ static void _yr_ac_print_automaton_state( { printf("\n"); - for (int i = 0; i < state->depth + 1; i++) - printf(" "); + for (int i = 0; i < state->depth + 1; i++) printf(" "); printf("%s = ", match->string->identifier); @@ -783,7 +760,7 @@ static void _yr_ac_print_automaton_state( child_state = state->first_child; - while(child_state != NULL) + while (child_state != NULL) { _yr_ac_print_automaton_state(automaton, child_state); child_state = child_state->siblings; @@ -797,9 +774,7 @@ static void _yr_ac_print_automaton_state( // Creates a new automaton // -int yr_ac_automaton_create( - YR_ARENA* arena, - YR_AC_AUTOMATON** automaton) +int yr_ac_automaton_create(YR_ARENA* arena, YR_AC_AUTOMATON** automaton) { YR_AC_AUTOMATON* new_automaton; YR_AC_STATE* root_state; @@ -839,8 +814,7 @@ int yr_ac_automaton_create( // Destroys automaton // -int yr_ac_automaton_destroy( - YR_AC_AUTOMATON* automaton) +int yr_ac_automaton_destroy(YR_AC_AUTOMATON* automaton) { _yr_ac_state_destroy(automaton->root); @@ -927,14 +901,12 @@ int yr_ac_add_string( // are written in the provided arena. // -int yr_ac_compile( - YR_AC_AUTOMATON* automaton, - YR_ARENA* arena) +int yr_ac_compile(YR_AC_AUTOMATON* automaton, YR_ARENA* arena) { FAIL_ON_ERROR(_yr_ac_create_failure_links(automaton)); FAIL_ON_ERROR(_yr_ac_optimize_failure_links(automaton)); FAIL_ON_ERROR(_yr_ac_build_transition_table(automaton)); - + return ERROR_SUCCESS; } @@ -950,4 +922,3 @@ void yr_ac_print_automaton(YR_AC_AUTOMATON* automaton) _yr_ac_print_automaton_state(automaton, automaton->root); printf("-------------------------------------------------------\n"); } - diff --git a/libyara/arena.c b/libyara/arena.c index dd47f25580..ae58fbd3fc 100644 --- a/libyara/arena.c +++ b/libyara/arena.c @@ -30,10 +30,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include - #include -#include #include +#include typedef struct YR_ARENA_FILE_HEADER YR_ARENA_FILE_HEADER; typedef struct YR_ARENA_FILE_BUFFER YR_ARENA_FILE_BUFFER; @@ -113,7 +112,7 @@ static int _yr_arena_make_ptr_relocatable( } // Flags for _yr_arena_allocate_memory. -#define YR_ARENA_ZERO_MEMORY 1 +#define YR_ARENA_ZERO_MEMORY 1 // @@ -153,21 +152,20 @@ static int _yr_arena_allocate_memory( { size_t new_size = (b->size == 0) ? arena->initial_buffer_size : b->size * 2; - while (new_size < b->used + size) - new_size *= 2; + while (new_size < b->used + size) new_size *= 2; uint8_t* new_data = yr_realloc(b->data, new_size); if (new_data == NULL) return ERROR_INSUFFICIENT_MEMORY; - // When yr_realloc uses the Windows API (HeapAlloc, HeapReAlloc) under the - // hood this is not necessary because HeapReAlloc already sets the new - // memory to zero. - #if !defined(_WIN32) && !defined(__CYGWIN__) +// When yr_realloc uses the Windows API (HeapAlloc, HeapReAlloc) under the +// hood this is not necessary because HeapReAlloc already sets the new +// memory to zero. +#if !defined(_WIN32) && !defined(__CYGWIN__) if (flags & YR_ARENA_ZERO_MEMORY) memset(new_data + b->used, 0, new_size - b->used); - #endif +#endif YR_RELOC* reloc = arena->reloc_list_head; @@ -177,8 +175,9 @@ static int _yr_arena_allocate_memory( // the base pointer that we use to access the buffer must be new_data, // as arena->buffers[reloc->buffer_id].data which is the same than // b->data can't be accessed anymore after the call to yr_realloc. - uint8_t* base = buffer_id == reloc->buffer_id ? - new_data : arena->buffers[reloc->buffer_id].data; + uint8_t* base = buffer_id == reloc->buffer_id + ? new_data + : arena->buffers[reloc->buffer_id].data; // reloc_address holds the address inside the buffer where the pointer // to be relocated resides. @@ -246,8 +245,7 @@ int yr_arena_create( return ERROR_SUCCESS; } -void yr_arena_acquire( - YR_ARENA* arena) +void yr_arena_acquire(YR_ARENA* arena) { arena->xrefs++; } @@ -262,8 +260,7 @@ void yr_arena_acquire( // [in] YR_ARENA* arena - Pointer to the arena. // -int yr_arena_release( - YR_ARENA* arena) +int yr_arena_release(YR_ARENA* arena) { arena->xrefs--; @@ -297,8 +294,7 @@ int yr_arena_allocate_memory( size_t size, YR_ARENA_REF* ref) { - return _yr_arena_allocate_memory( - arena, 0, buffer_id, size, ref); + return _yr_arena_allocate_memory(arena, 0, buffer_id, size, ref); } @@ -394,9 +390,7 @@ void* yr_arena_get_ptr( } -yr_arena_off_t yr_arena_get_current_offset( - YR_ARENA* arena, - uint32_t buffer_id) +yr_arena_off_t yr_arena_get_current_offset(YR_ARENA* arena, uint32_t buffer_id) { assert(buffer_id < arena->num_buffers); @@ -404,10 +398,7 @@ yr_arena_off_t yr_arena_get_current_offset( } -int yr_arena_ptr_to_ref( - YR_ARENA* arena, - const void* address, - YR_ARENA_REF* ref) +int yr_arena_ptr_to_ref(YR_ARENA* arena, const void* address, YR_ARENA_REF* ref) { *ref = YR_ARENA_NULL_REF; @@ -417,7 +408,7 @@ int yr_arena_ptr_to_ref( for (int i = 0; i < arena->num_buffers; ++i) { if ((uint8_t*) address >= arena->buffers[i].data && - (uint8_t*) address < arena->buffers[i].data + arena->buffers[i].used) + (uint8_t*) address < arena->buffers[i].data + arena->buffers[i].used) { ref->buffer_id = i; ref->offset = (uint8_t*) address - arena->buffers[i].data; @@ -428,24 +419,21 @@ int yr_arena_ptr_to_ref( return 0; } -void* yr_arena_ref_to_ptr( - YR_ARENA* arena, - YR_ARENA_REF* ref) +void* yr_arena_ref_to_ptr(YR_ARENA* arena, YR_ARENA_REF* ref) { if (YR_ARENA_IS_NULL_REF(*ref)) return NULL; - #if defined(__arm__) +#if defined(__arm__) YR_ARENA_REF tmp_ref; memcpy(&tmp_ref, ref, sizeof(YR_ARENA_REF)); ref = &tmp_ref; - #endif +#endif return yr_arena_get_ptr(arena, ref->buffer_id, ref->offset); } - // // yr_arena_make_ptr_relocatable // @@ -461,18 +449,14 @@ void* yr_arena_ref_to_ptr( // ERROR_SUCCESS if succeed or the corresponding error code otherwise. // -int yr_arena_make_ptr_relocatable( - YR_ARENA* arena, - uint32_t buffer_id, - ...) +int yr_arena_make_ptr_relocatable(YR_ARENA* arena, uint32_t buffer_id, ...) { int result; va_list offsets; va_start(offsets, buffer_id); - result = _yr_arena_make_ptr_relocatable( - arena, buffer_id, 0, offsets); + result = _yr_arena_make_ptr_relocatable(arena, buffer_id, 0, offsets); va_end(offsets); @@ -511,8 +495,7 @@ int yr_arena_write_string( const char* string, YR_ARENA_REF* ref) { - return yr_arena_write_data( - arena, buffer_id, string, strlen(string) + 1, ref); + return yr_arena_write_data(arena, buffer_id, string, strlen(string) + 1, ref); } @@ -522,24 +505,18 @@ int yr_arena_write_uint32( uint32_t integer, YR_ARENA_REF* ref) { - return yr_arena_write_data( - arena, buffer_id, &integer, sizeof(integer), ref); + return yr_arena_write_data(arena, buffer_id, &integer, sizeof(integer), ref); } - -int yr_arena_load_stream( - YR_STREAM* stream, - YR_ARENA** arena) +int yr_arena_load_stream(YR_STREAM* stream, YR_ARENA** arena) { YR_ARENA_FILE_HEADER hdr; if (yr_stream_read(&hdr, sizeof(hdr), 1, stream) != 1) return ERROR_INVALID_FILE; - if (hdr.magic[0] != 'Y' || - hdr.magic[1] != 'A' || - hdr.magic[2] != 'R' || + if (hdr.magic[0] != 'Y' || hdr.magic[1] != 'A' || hdr.magic[2] != 'R' || hdr.magic[3] != 'A') { return ERROR_INVALID_FILE; @@ -571,8 +548,7 @@ int yr_arena_load_stream( YR_ARENA_REF ref; FAIL_ON_ERROR_WITH_CLEANUP( - yr_arena_allocate_memory( - new_arena, i, buffers[i].size, &ref), + yr_arena_allocate_memory(new_arena, i, buffers[i].size, &ref), yr_arena_release(new_arena)) void* ptr = yr_arena_get_ptr(new_arena, i, ref.offset); @@ -604,10 +580,7 @@ int yr_arena_load_stream( FAIL_ON_ERROR_WITH_CLEANUP( yr_arena_make_ptr_relocatable( - new_arena, - ref.buffer_id, - ref.offset, - EOL), + new_arena, ref.buffer_id, ref.offset, EOL), yr_arena_release(new_arena)) } @@ -617,9 +590,7 @@ int yr_arena_load_stream( } -int yr_arena_save_stream( - YR_ARENA* arena, - YR_STREAM* stream) +int yr_arena_save_stream(YR_ARENA* arena, YR_STREAM* stream) { YR_ARENA_FILE_HEADER hdr; @@ -636,14 +607,14 @@ int yr_arena_save_stream( // The first buffer in the file is after the header and the buffer table, // calculate its offset accordingly. - uint64_t offset = sizeof(YR_ARENA_FILE_HEADER) - + sizeof(YR_ARENA_FILE_BUFFER) * arena->num_buffers; + uint64_t offset = sizeof(YR_ARENA_FILE_HEADER) + + sizeof(YR_ARENA_FILE_BUFFER) * arena->num_buffers; for (int i = 0; i < arena->num_buffers; ++i) { YR_ARENA_FILE_BUFFER buffer = { - .offset = offset, - .size = arena->buffers[i].used, + .offset = offset, + .size = arena->buffers[i].used, }; if (yr_stream_write(&buffer, sizeof(buffer), 1, stream) != 1) @@ -663,19 +634,19 @@ int yr_arena_save_stream( { // reloc_ptr is a pointer to the relocatable pointer, while *reloc_ptr // is the relocatable pointer itself. - void** reloc_ptr = (void**) ( - arena->buffers[reloc->buffer_id].data + reloc->offset); + void** reloc_ptr = + (void**) (arena->buffers[reloc->buffer_id].data + reloc->offset); YR_ARENA_REF ref; - #if !defined(NDEBUG) +#if !defined(NDEBUG) int found = yr_arena_ptr_to_ref(arena, *reloc_ptr, &ref); // yr_arena_ptr_to_ref returns 0 if the relocatable pointer is pointing // outside the arena, this should not happen. assert(found); - #else +#else yr_arena_ptr_to_ref(arena, *reloc_ptr, &ref); - #endif +#endif // Replace the relocatable pointer with a reference that holds information // about the buffer and offset where the relocatable pointer is pointing to. @@ -701,15 +672,15 @@ int yr_arena_save_stream( while (reloc != NULL) { YR_ARENA_REF ref = { - .buffer_id = reloc->buffer_id, - .offset = reloc->offset, + .buffer_id = reloc->buffer_id, + .offset = reloc->offset, }; if (yr_stream_write(&ref, sizeof(ref), 1, stream) != 1) return ERROR_WRITING_FILE; - void** reloc_ptr = (void**) ( - arena->buffers[reloc->buffer_id].data + reloc->offset); + void** reloc_ptr = + (void**) (arena->buffers[reloc->buffer_id].data + reloc->offset); // reloc_ptr is now pointing to a YR_ARENA_REF. YR_ARENA_REF* ref_ptr = (YR_ARENA_REF*) reloc_ptr; diff --git a/libyara/atoms.c b/libyara/atoms.c index f4f7b532c0..7f340238af 100644 --- a/libyara/atoms.c +++ b/libyara/atoms.c @@ -80,15 +80,14 @@ will end up using the "Look" atom alone, but in /a(bcd|efg)h/ atoms "bcd" and #include #include - -#include -#include #include +#include +#include #include #include -#include -#include #include +#include +#include // @@ -109,9 +108,7 @@ will end up using the "Look" atom alone, but in /a(bcd|efg)h/ atoms "bcd" and // An integer indicating the atom's quality // -int yr_atoms_heuristic_quality( - YR_ATOMS_CONFIG* config, - YR_ATOM* atom) +int yr_atoms_heuristic_quality(YR_ATOMS_CONFIG* config, YR_ATOM* atom) { YR_BITMASK seen_bytes[YR_BITMASK_SIZE(256)]; @@ -127,52 +124,51 @@ int yr_atoms_heuristic_quality( { switch (atom->mask[i]) { + case 0x00: + quality -= 6; + break; + case 0x0F: + quality += 1; + break; + case 0xF0: + quality += 1; + break; + case 0xFF: + switch (atom->bytes[i]) + { case 0x00: - quality -= 6; - break; - case 0x0F: - quality += 1; - break; - case 0xF0: - quality += 1; - break; + case 0x20: + case 0xCC: case 0xFF: - switch (atom->bytes[i]) - { - case 0x00: - case 0x20: - case 0xCC: - case 0xFF: - // Common bytes contribute less to the quality than the rest. - quality += 15; - break; - default: - // Bytes in the a-z and A-Z ranges have a slightly lower quality - // than the rest. We want to favor atoms that contain bytes outside - // those ranges because they generate less additional atoms during - // calls to _yr_atoms_case_combinations. - if ( yr_lowercase[atom->bytes[i]] >= 'a' && - yr_lowercase[atom->bytes[i]] <= 'z') - quality += 19; - else - quality += 20; - }; - if (!yr_bitmask_is_set(seen_bytes, atom->bytes[i])) - { - yr_bitmask_set(seen_bytes, atom->bytes[i]); - unique_bytes++; - } + // Common bytes contribute less to the quality than the rest. + quality += 15; + break; + default: + // Bytes in the a-z and A-Z ranges have a slightly lower quality + // than the rest. We want to favor atoms that contain bytes outside + // those ranges because they generate less additional atoms during + // calls to _yr_atoms_case_combinations. + if (yr_lowercase[atom->bytes[i]] >= 'a' && + yr_lowercase[atom->bytes[i]] <= 'z') + quality += 19; + else + quality += 20; + }; + if (!yr_bitmask_is_set(seen_bytes, atom->bytes[i])) + { + yr_bitmask_set(seen_bytes, atom->bytes[i]); + unique_bytes++; + } } } // If all the bytes in the atom are equal and very common, let's penalize // it heavily. - if (unique_bytes == 1 && - (yr_bitmask_is_set(seen_bytes, 0x00) || - yr_bitmask_is_set(seen_bytes, 0x20) || - yr_bitmask_is_set(seen_bytes, 0xCC) || - yr_bitmask_is_set(seen_bytes, 0xFF))) + if (unique_bytes == 1 && (yr_bitmask_is_set(seen_bytes, 0x00) || + yr_bitmask_is_set(seen_bytes, 0x20) || + yr_bitmask_is_set(seen_bytes, 0xCC) || + yr_bitmask_is_set(seen_bytes, 0xFF))) { quality -= 10 * atom->length; } @@ -195,25 +191,23 @@ int yr_atoms_heuristic_quality( // = 0 if a1 is equal or matches a2. // -static int _yr_atoms_cmp( - const uint8_t* a1, - YR_ATOM* a2) +static int _yr_atoms_cmp(const uint8_t* a1, YR_ATOM* a2) { int result = 0; - int i = 0; + int i = 0; while (result == 0 && i < a2->length) { switch (a2->mask[i]) { - case 0xFF: - case 0x0F: - case 0xF0: - case 0x00: - result = (a1[i] & a2->mask[i]) - a2->bytes[i]; - break; - default: - assert(false); + case 0xFF: + case 0x0F: + case 0xF0: + case 0x00: + result = (a1[i] & a2->mask[i]) - a2->bytes[i]; + break; + default: + assert(false); } i++; @@ -239,9 +233,7 @@ static int _yr_atoms_cmp( // An integer indicating the atom's quality // -int yr_atoms_table_quality( - YR_ATOMS_CONFIG* config, - YR_ATOM* atom) +int yr_atoms_table_quality(YR_ATOMS_CONFIG* config, YR_ATOM* atom) { YR_ATOM_QUALITY_TABLE_ENTRY* table = config->quality_table; @@ -301,9 +293,7 @@ int yr_atoms_table_quality( // Returns the quality for the worst quality atom in a list. // -int yr_atoms_min_quality( - YR_ATOMS_CONFIG* config, - YR_ATOM_LIST_ITEM* atom_list) +int yr_atoms_min_quality(YR_ATOMS_CONFIG* config, YR_ATOM_LIST_ITEM* atom_list) { YR_ATOM_LIST_ITEM* atom; @@ -335,11 +325,10 @@ int yr_atoms_min_quality( // Creates a new node for an atoms tree. // -static YR_ATOM_TREE_NODE* _yr_atoms_tree_node_create( - uint8_t type) +static YR_ATOM_TREE_NODE* _yr_atoms_tree_node_create(uint8_t type) { - YR_ATOM_TREE_NODE* new_node = (YR_ATOM_TREE_NODE*) \ - yr_malloc(sizeof(YR_ATOM_TREE_NODE)); + YR_ATOM_TREE_NODE* new_node = (YR_ATOM_TREE_NODE*) yr_malloc( + sizeof(YR_ATOM_TREE_NODE)); if (new_node != NULL) { @@ -360,8 +349,7 @@ static YR_ATOM_TREE_NODE* _yr_atoms_tree_node_create( // Destroys a node from an atoms tree. // -static void _yr_atoms_tree_node_destroy( - YR_ATOM_TREE_NODE* node) +static void _yr_atoms_tree_node_destroy(YR_ATOM_TREE_NODE* node) { YR_ATOM_TREE_NODE* child; YR_ATOM_TREE_NODE* next_child; @@ -411,8 +399,7 @@ static void _yr_atoms_tree_node_append( // Destroys an atoms tree. // -static void _yr_atoms_tree_destroy( - YR_ATOM_TREE* atom_tree) +static void _yr_atoms_tree_destroy(YR_ATOM_TREE* atom_tree) { _yr_atoms_tree_node_destroy(atom_tree->root_node); yr_free(atom_tree); @@ -425,8 +412,7 @@ static void _yr_atoms_tree_destroy( // Destroys an atoms list. // -void yr_atoms_list_destroy( - YR_ATOM_LIST_ITEM* list_head) +void yr_atoms_list_destroy(YR_ATOM_LIST_ITEM* list_head) { YR_ATOM_LIST_ITEM* item = list_head; YR_ATOM_LIST_ITEM* next; @@ -482,16 +468,14 @@ static YR_ATOM_LIST_ITEM* _yr_atoms_list_concat( // The number of bytes that were trimmed from the beginning of the atom. // -int _yr_atoms_trim( - YR_ATOM* atom) +int _yr_atoms_trim(YR_ATOM* atom) { int mask_00 = 0; int mask_ff = 0; int i, trim_left = 0; - while (trim_left < atom->length && atom->mask[trim_left] == 0) - trim_left++; + while (trim_left < atom->length && atom->mask[trim_left] == 0) trim_left++; while (atom->length > trim_left && atom->mask[atom->length - 1] == 0) atom->length--; @@ -643,8 +627,7 @@ static int _yr_atoms_choose( if (item != NULL) { tail = item; - while (tail->next != NULL) - tail = tail->next; + while (tail->next != NULL) tail = tail->next; tail->next = *chosen_atoms; *chosen_atoms = item; @@ -687,10 +670,7 @@ static uint8_t* _yr_atoms_case_combinations( if (atom_offset + 1 < atom_length) output_buffer = _yr_atoms_case_combinations( - atom, - atom_length, - atom_offset + 1, - output_buffer); + atom, atom_length, atom_offset + 1, output_buffer); c = atom[atom_offset]; @@ -713,10 +693,7 @@ static uint8_t* _yr_atoms_case_combinations( if (atom_offset + 1 < atom_length) output_buffer = _yr_atoms_case_combinations( - new_atom, - atom_length, - atom_offset + 1, - output_buffer); + new_atom, atom_length, atom_offset + 1, output_buffer); } if (atom_offset == 0) @@ -729,11 +706,11 @@ static uint8_t* _yr_atoms_case_combinations( // the possible combinations for an atom. Each atom has up to YR_MAX_ATOM_LENGTH // characters and each character has two possible values (upper and lower case). // That means 2 ^ YR_MAX_ATOM_LENGTH combinations for an atom, where each atom -// occupies YR_MAX_ATOM_LENGTH + 1 bytes (the atom itself +1 byte for its length) -// One extra bytes is allocated for the zero value indicating the end. +// occupies YR_MAX_ATOM_LENGTH + 1 bytes (the atom itself +1 byte for its +// length) One extra bytes is allocated for the zero value indicating the end. #define CASE_COMBINATIONS_BUFFER_SIZE \ - (1 << YR_MAX_ATOM_LENGTH) * (YR_MAX_ATOM_LENGTH + 1) + 1 + (1 << YR_MAX_ATOM_LENGTH) * (YR_MAX_ATOM_LENGTH + 1) + 1 // // _yr_atoms_case_insensitive @@ -760,11 +737,7 @@ static int _yr_atoms_case_insensitive( while (atom != NULL) { - _yr_atoms_case_combinations( - atom->atom.bytes, - atom->atom.length, - 0, - buffer); + _yr_atoms_case_combinations(atom->atom.bytes, atom->atom.length, 0, buffer); atoms_cursor = buffer; atom_length = *atoms_cursor; @@ -911,20 +884,20 @@ static int _yr_atoms_wide( struct STACK_ITEM { - RE_NODE* re_node; - YR_ATOM_TREE_NODE* new_appending_node; + RE_NODE* re_node; + YR_ATOM_TREE_NODE* new_appending_node; }; -#define make_atom_from_re_nodes(atom, nodes_length, nodes) \ - { \ - atom.length = nodes_length; \ - for (i = 0; i < atom.length; i++) \ - { \ - atom.bytes[i] = (uint8_t) (recent_re_nodes)[i]->value; \ - atom.mask[i] = (uint8_t) (recent_re_nodes)[i]->mask; \ - } \ - } +#define make_atom_from_re_nodes(atom, nodes_length, nodes) \ + { \ + atom.length = nodes_length; \ + for (i = 0; i < atom.length; i++) \ + { \ + atom.bytes[i] = (uint8_t)(recent_re_nodes)[i]->value; \ + atom.mask[i] = (uint8_t)(recent_re_nodes)[i]->mask; \ + } \ + } // @@ -984,8 +957,7 @@ static int _yr_atoms_extract_from_re( si.new_appending_node = appending_node; FAIL_ON_ERROR_WITH_CLEANUP( - yr_stack_push(stack, (void*) &si), - yr_stack_destroy(stack)); + yr_stack_push(stack, (void*) &si), yr_stack_destroy(stack)); // Start processing the root node. si.re_node = re_ast->root_node; @@ -995,8 +967,7 @@ static int _yr_atoms_extract_from_re( si.new_appending_node = appending_node; FAIL_ON_ERROR_WITH_CLEANUP( - yr_stack_push(stack, (void*) &si), - yr_stack_destroy(stack)); + yr_stack_push(stack, (void*) &si), yr_stack_destroy(stack)); while (yr_stack_pop(stack, (void*) &si)) { @@ -1027,9 +998,7 @@ static int _yr_atoms_extract_from_re( { memcpy(&leaf->atom, &best_atom, sizeof(best_atom)); memcpy( - &leaf->re_nodes, - &best_atom_re_nodes, - sizeof(best_atom_re_nodes)); + &leaf->re_nodes, &best_atom_re_nodes, sizeof(best_atom_re_nodes)); } _yr_atoms_tree_node_append(current_appending_node, leaf); @@ -1041,195 +1010,187 @@ static int _yr_atoms_extract_from_re( if (si.re_node != NULL) { - switch(si.re_node->type) + switch (si.re_node->type) { - case RE_NODE_LITERAL: - case RE_NODE_MASKED_LITERAL: - case RE_NODE_ANY: + case RE_NODE_LITERAL: + case RE_NODE_MASKED_LITERAL: + case RE_NODE_ANY: - if (n < YR_MAX_ATOM_LENGTH) - { - recent_re_nodes[n] = si.re_node; - best_atom_re_nodes[n] = si.re_node; - best_atom.bytes[n] = (uint8_t) si.re_node->value; - best_atom.mask[n] = (uint8_t) si.re_node->mask; - best_atom.length = ++n; - } - else if (best_quality < YR_MAX_ATOM_QUALITY) - { - make_atom_from_re_nodes(atom, n, recent_re_nodes); - shift = _yr_atoms_trim(&atom); - quality = config->get_atom_quality(config, &atom); + if (n < YR_MAX_ATOM_LENGTH) + { + recent_re_nodes[n] = si.re_node; + best_atom_re_nodes[n] = si.re_node; + best_atom.bytes[n] = (uint8_t) si.re_node->value; + best_atom.mask[n] = (uint8_t) si.re_node->mask; + best_atom.length = ++n; + } + else if (best_quality < YR_MAX_ATOM_QUALITY) + { + make_atom_from_re_nodes(atom, n, recent_re_nodes); + shift = _yr_atoms_trim(&atom); + quality = config->get_atom_quality(config, &atom); - if (quality > best_quality) + if (quality > best_quality) + { + for (i = 0; i < atom.length; i++) { - for (i = 0; i < atom.length; i++) - { - best_atom.bytes[i] = atom.bytes[i]; - best_atom.mask[i] = atom.mask[i]; - best_atom_re_nodes[i] = recent_re_nodes[i + shift]; - } - - best_atom.length = atom.length; - best_quality = quality; + best_atom.bytes[i] = atom.bytes[i]; + best_atom.mask[i] = atom.mask[i]; + best_atom_re_nodes[i] = recent_re_nodes[i + shift]; } - for (i = 1; i < YR_MAX_ATOM_LENGTH; i++) - recent_re_nodes[i - 1] = recent_re_nodes[i]; - - recent_re_nodes[YR_MAX_ATOM_LENGTH - 1] = si.re_node; + best_atom.length = atom.length; + best_quality = quality; } - break; + for (i = 1; i < YR_MAX_ATOM_LENGTH; i++) + recent_re_nodes[i - 1] = recent_re_nodes[i]; - case RE_NODE_CONCAT: + recent_re_nodes[YR_MAX_ATOM_LENGTH - 1] = si.re_node; + } - re_node = si.re_node->children_tail; + break; - // Push children right to left, they are poped left to right. - while (re_node != NULL) - { - si.new_appending_node = NULL; - si.re_node = re_node; + case RE_NODE_CONCAT: - FAIL_ON_ERROR_WITH_CLEANUP( - yr_stack_push(stack, &si), - yr_stack_destroy(stack)); + re_node = si.re_node->children_tail; - re_node = re_node->prev_sibling; - } + // Push children right to left, they are poped left to right. + while (re_node != NULL) + { + si.new_appending_node = NULL; + si.re_node = re_node; + + FAIL_ON_ERROR_WITH_CLEANUP( + yr_stack_push(stack, &si), yr_stack_destroy(stack)); - break; + re_node = re_node->prev_sibling; + } - case RE_NODE_ALT: + break; - // Create ATOM_TREE_AND node with two ATOM_TREE_OR children nodes. - and_node = _yr_atoms_tree_node_create(ATOM_TREE_AND); - left_node = _yr_atoms_tree_node_create(ATOM_TREE_OR); - right_node = _yr_atoms_tree_node_create(ATOM_TREE_OR); + case RE_NODE_ALT: - if (and_node == NULL || left_node == NULL || right_node == NULL) - { - _yr_atoms_tree_node_destroy(and_node); - _yr_atoms_tree_node_destroy(left_node); - _yr_atoms_tree_node_destroy(right_node); + // Create ATOM_TREE_AND node with two ATOM_TREE_OR children nodes. + and_node = _yr_atoms_tree_node_create(ATOM_TREE_AND); + left_node = _yr_atoms_tree_node_create(ATOM_TREE_OR); + right_node = _yr_atoms_tree_node_create(ATOM_TREE_OR); - yr_stack_destroy(stack); + if (and_node == NULL || left_node == NULL || right_node == NULL) + { + _yr_atoms_tree_node_destroy(and_node); + _yr_atoms_tree_node_destroy(left_node); + _yr_atoms_tree_node_destroy(right_node); - return ERROR_INSUFFICIENT_MEMORY; - } + yr_stack_destroy(stack); - and_node->children_head = left_node; - and_node->children_tail = right_node; - left_node->next_sibling = right_node; + return ERROR_INSUFFICIENT_MEMORY; + } - // Add the ATOM_TREE_AND as children of the current node. - _yr_atoms_tree_node_append(current_appending_node, and_node); + and_node->children_head = left_node; + and_node->children_tail = right_node; + left_node->next_sibling = right_node; - re_node = si.re_node; + // Add the ATOM_TREE_AND as children of the current node. + _yr_atoms_tree_node_append(current_appending_node, and_node); - si.new_appending_node = current_appending_node; - si.re_node = NULL; + re_node = si.re_node; - FAIL_ON_ERROR_WITH_CLEANUP( - yr_stack_push(stack, &si), - yr_stack_destroy(stack)); + si.new_appending_node = current_appending_node; + si.re_node = NULL; - // RE_NODE_ALT nodes has only two children, so children_head is the - // left one, and children_tail is right one. - si.new_appending_node = right_node; - si.re_node = re_node->children_tail; + FAIL_ON_ERROR_WITH_CLEANUP( + yr_stack_push(stack, &si), yr_stack_destroy(stack)); - FAIL_ON_ERROR_WITH_CLEANUP( - yr_stack_push(stack, &si), - yr_stack_destroy(stack)); + // RE_NODE_ALT nodes has only two children, so children_head is the + // left one, and children_tail is right one. + si.new_appending_node = right_node; + si.re_node = re_node->children_tail; - si.new_appending_node = left_node; - si.re_node = re_node->children_head; + FAIL_ON_ERROR_WITH_CLEANUP( + yr_stack_push(stack, &si), yr_stack_destroy(stack)); - FAIL_ON_ERROR_WITH_CLEANUP( - yr_stack_push(stack, &si), - yr_stack_destroy(stack)); + si.new_appending_node = left_node; + si.re_node = re_node->children_head; - break; + FAIL_ON_ERROR_WITH_CLEANUP( + yr_stack_push(stack, &si), yr_stack_destroy(stack)); - case RE_NODE_PLUS: + break; - re_node = si.re_node; + case RE_NODE_PLUS: - si.new_appending_node = current_appending_node; - si.re_node = NULL; + re_node = si.re_node; - FAIL_ON_ERROR_WITH_CLEANUP( - yr_stack_push(stack, &si), - yr_stack_destroy(stack)); + si.new_appending_node = current_appending_node; + si.re_node = NULL; - si.new_appending_node = NULL; - // RE_NODE_PLUS nodes has a single child, which is children_head. - si.re_node = re_node->children_head; + FAIL_ON_ERROR_WITH_CLEANUP( + yr_stack_push(stack, &si), yr_stack_destroy(stack)); - FAIL_ON_ERROR_WITH_CLEANUP( - yr_stack_push(stack, &si), - yr_stack_destroy(stack)); + si.new_appending_node = NULL; + // RE_NODE_PLUS nodes has a single child, which is children_head. + si.re_node = re_node->children_head; - break; + FAIL_ON_ERROR_WITH_CLEANUP( + yr_stack_push(stack, &si), yr_stack_destroy(stack)); - case RE_NODE_RANGE: + break; - re_node = si.re_node; + case RE_NODE_RANGE: - si.new_appending_node = current_appending_node; - si.re_node = NULL; + re_node = si.re_node; - FAIL_ON_ERROR_WITH_CLEANUP( - yr_stack_push(stack, &si), - yr_stack_destroy(stack)); + si.new_appending_node = current_appending_node; + si.re_node = NULL; - si.new_appending_node = NULL; - // RE_NODE_RANGE nodes has a single child, which is children_head. - si.re_node = re_node->children_head; + FAIL_ON_ERROR_WITH_CLEANUP( + yr_stack_push(stack, &si), yr_stack_destroy(stack)); - // In a regexp like /a{10,20}/ the optimal atom is 'aaaa' (assuming - // that YR_MAX_ATOM_LENGTH = 4) because the 'a' character must appear - // at least 10 times in the matching string. Each call in the loop - // will append one 'a' to the atom, so YR_MAX_ATOM_LENGTH iterations - // are enough. + si.new_appending_node = NULL; - for (i = 0; i < yr_min(re_node->start, YR_MAX_ATOM_LENGTH); i++) - { - FAIL_ON_ERROR_WITH_CLEANUP( - yr_stack_push(stack, &si), - yr_stack_destroy(stack)); - } + // RE_NODE_RANGE nodes has a single child, which is children_head. + si.re_node = re_node->children_head; - break; - - case RE_NODE_RANGE_ANY: - case RE_NODE_STAR: - case RE_NODE_CLASS: - case RE_NODE_WORD_CHAR: - case RE_NODE_NON_WORD_CHAR: - case RE_NODE_SPACE: - case RE_NODE_NON_SPACE: - case RE_NODE_DIGIT: - case RE_NODE_NON_DIGIT: - case RE_NODE_EMPTY: - case RE_NODE_ANCHOR_START: - case RE_NODE_ANCHOR_END: - case RE_NODE_WORD_BOUNDARY: - case RE_NODE_NON_WORD_BOUNDARY: - - si.new_appending_node = current_appending_node; - si.re_node = NULL; + // In a regexp like /a{10,20}/ the optimal atom is 'aaaa' (assuming + // that YR_MAX_ATOM_LENGTH = 4) because the 'a' character must appear + // at least 10 times in the matching string. Each call in the loop + // will append one 'a' to the atom, so YR_MAX_ATOM_LENGTH iterations + // are enough. + for (i = 0; i < yr_min(re_node->start, YR_MAX_ATOM_LENGTH); i++) + { FAIL_ON_ERROR_WITH_CLEANUP( - yr_stack_push(stack, &si), - yr_stack_destroy(stack)); + yr_stack_push(stack, &si), yr_stack_destroy(stack)); + } - break; + break; + + case RE_NODE_RANGE_ANY: + case RE_NODE_STAR: + case RE_NODE_CLASS: + case RE_NODE_WORD_CHAR: + case RE_NODE_NON_WORD_CHAR: + case RE_NODE_SPACE: + case RE_NODE_NON_SPACE: + case RE_NODE_DIGIT: + case RE_NODE_NON_DIGIT: + case RE_NODE_EMPTY: + case RE_NODE_ANCHOR_START: + case RE_NODE_ANCHOR_END: + case RE_NODE_WORD_BOUNDARY: + case RE_NODE_NON_WORD_BOUNDARY: + + si.new_appending_node = current_appending_node; + si.re_node = NULL; + + FAIL_ON_ERROR_WITH_CLEANUP( + yr_stack_push(stack, &si), yr_stack_destroy(stack)); + + break; - default: - assert(false); + default: + assert(false); } } } @@ -1240,15 +1201,13 @@ static int _yr_atoms_extract_from_re( } - // // _yr_atoms_clone_list_item // // Makes an exact copy of an YR_ATOM_LIST_ITEM. // -static YR_ATOM_LIST_ITEM* _yr_atoms_clone_list_item( - YR_ATOM_LIST_ITEM* item) +static YR_ATOM_LIST_ITEM* _yr_atoms_clone_list_item(YR_ATOM_LIST_ITEM* item) { YR_ATOM_LIST_ITEM* clone = (YR_ATOM_LIST_ITEM*) yr_malloc( sizeof(YR_ATOM_LIST_ITEM)); @@ -1278,8 +1237,7 @@ static YR_ATOM_LIST_ITEM* _yr_atoms_clone_list_item( // ERROR_SUCCESS or ERROR_INSUFFICIENT_MEMORY. // -static int _yr_atoms_expand_wildcards( - YR_ATOM_LIST_ITEM* atoms) +static int _yr_atoms_expand_wildcards(YR_ATOM_LIST_ITEM* atoms) { int i; @@ -1296,30 +1254,30 @@ static int _yr_atoms_expand_wildcards( { uint16_t a, s, e, incr = 1; - switch(atom->atom.mask[i]) + switch (atom->atom.mask[i]) { - case 0x00: - expanded = true; - s = 0x00; - e = 0xFF; - break; - - case 0x0F: - expanded = true; - s = atom->atom.bytes[i]; - e = atom->atom.bytes[i] | 0xF0; - incr = 0x10; - break; - - case 0xF0: - expanded = true; - s = atom->atom.bytes[i]; - e = atom->atom.bytes[i] | 0x0F; - break; - - default: - s = 0; - e = 0; + case 0x00: + expanded = true; + s = 0x00; + e = 0xFF; + break; + + case 0x0F: + expanded = true; + s = atom->atom.bytes[i]; + e = atom->atom.bytes[i] | 0xF0; + incr = 0x10; + break; + + case 0xF0: + expanded = true; + s = atom->atom.bytes[i]; + e = atom->atom.bytes[i] | 0x0F; + break; + + default: + s = 0; + e = 0; } if (s != e) @@ -1401,7 +1359,7 @@ int yr_atoms_extract_from_re( FAIL_ON_ERROR_WITH_CLEANUP( _yr_atoms_expand_wildcards(*atoms), - { + { // Cleanup yr_atoms_list_destroy(*atoms); *atoms = NULL; }); @@ -1415,7 +1373,7 @@ int yr_atoms_extract_from_re( { FAIL_ON_ERROR_WITH_CLEANUP( _yr_atoms_wide(*atoms, &wide_atoms), - { + { // Cleanup yr_atoms_list_destroy(*atoms); yr_atoms_list_destroy(wide_atoms); *atoms = NULL; @@ -1436,7 +1394,7 @@ int yr_atoms_extract_from_re( { FAIL_ON_ERROR_WITH_CLEANUP( _yr_atoms_case_insensitive(*atoms, &case_insensitive_atoms), - { + { // Cleanup yr_atoms_list_destroy(*atoms); yr_atoms_list_destroy(case_insensitive_atoms); *atoms = NULL; @@ -1536,7 +1494,7 @@ int yr_atoms_extract_from_string( { FAIL_ON_ERROR_WITH_CLEANUP( _yr_atoms_wide(*atoms, &wide_atoms), - { + { // Cleanup yr_atoms_list_destroy(*atoms); yr_atoms_list_destroy(wide_atoms); *atoms = NULL; @@ -1557,7 +1515,7 @@ int yr_atoms_extract_from_string( { FAIL_ON_ERROR_WITH_CLEANUP( _yr_atoms_case_insensitive(*atoms, &case_insensitive_atoms), - { + { // Cleanup yr_atoms_list_destroy(*atoms); yr_atoms_list_destroy(case_insensitive_atoms); *atoms = NULL; @@ -1569,16 +1527,15 @@ int yr_atoms_extract_from_string( if (modifier.flags & STRING_FLAGS_XOR) { FAIL_ON_ERROR_WITH_CLEANUP( - _yr_atoms_xor(*atoms, modifier.xor_min, modifier.xor_max, &xor_atoms), - { - yr_atoms_list_destroy(*atoms); - yr_atoms_list_destroy(xor_atoms); - *atoms = NULL; - }); + _yr_atoms_xor(*atoms, modifier.xor_min, modifier.xor_max, &xor_atoms), + { // Cleanup + yr_atoms_list_destroy(*atoms); + yr_atoms_list_destroy(xor_atoms); + *atoms = NULL; + }); yr_atoms_list_destroy(*atoms); *atoms = xor_atoms; - } // Recheck the atom quality, in case we have just generated some poor atoms. @@ -1600,11 +1557,9 @@ int yr_atoms_extract_from_string( // Prints an atom tree node. Used only for debugging purposes. // -void yr_atoms_tree_node_print( - YR_ATOM_TREE_NODE* node) +void yr_atoms_tree_node_print(YR_ATOM_TREE_NODE* node) { YR_ATOM_TREE_NODE* child; - int i; if (node == NULL) { @@ -1612,10 +1567,10 @@ void yr_atoms_tree_node_print( return; } - switch(node->type) + switch (node->type) { case ATOM_TREE_LEAF: - for (i = 0; i < node->atom.length; i++) + for (int i = 0; i < node->atom.length; i++) printf("%02X", node->atom.bytes[i]); break; diff --git a/libyara/base64.c b/libyara/base64.c index db3c219e92..3228a25124 100644 --- a/libyara/base64.c +++ b/libyara/base64.c @@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include - #include #include #include @@ -80,8 +79,7 @@ static SIZED_STRING* _yr_modified_base64_encode( // Prepend appropriate number of bytes and copy remaining input bytes into // temporary buffer. - for (j = 0; j < i; j++) - tmp[j] = 'A'; + for (j = 0; j < i; j++) tmp[j] = 'A'; memcpy(tmp + j, src, len); src = tmp; @@ -174,30 +172,17 @@ static SIZED_STRING* _yr_base64_get_base64_substring( // RE metacharacters which need to be escaped when generating the final RE. -#define IS_METACHAR(x) \ - (x == '\\' || \ - x == '^' || \ - x == '$' || \ - x == '|' || \ - x == '(' || \ - x == ')' || \ - x == '[' || \ - x == ']' || \ - x == '*' || \ - x == '?' || \ - x == '{' || \ - x == ',' || \ - x == '.' || \ - x == '+' || \ - x == '}') +#define IS_METACHAR(x) \ + (x == '\\' || x == '^' || x == '$' || x == '|' || x == '(' || x == ')' || \ + x == '[' || x == ']' || x == '*' || x == '?' || x == '{' || x == ',' || \ + x == '.' || x == '+' || x == '}') // // Given a SIZED_STRING return the number of characters which will need to be // escaped when generating the final string to pass to the regexp compiler. // -static int _yr_base64_count_escaped( - SIZED_STRING* str) +static int _yr_base64_count_escaped(SIZED_STRING* str) { uint32_t i; int c = 0; @@ -246,11 +231,11 @@ static int _yr_base64_create_nodes( // Now take the encoded string and strip the bytes which are affected by // the leading and trailing bytes of the plaintext. FAIL_ON_NULL_WITH_CLEANUP( - final_str = _yr_base64_get_base64_substring(encoded_str, wide, i, pad), - { - yr_free(encoded_str); - yr_free(node); - }); + final_str = _yr_base64_get_base64_substring(encoded_str, wide, i, pad), + { + yr_free(encoded_str); + yr_free(node); + }); yr_free(encoded_str); @@ -279,8 +264,7 @@ static int _yr_base64_create_nodes( // // Useful for printing the encoded strings. // -void _yr_base64_print_nodes( - BASE64_NODE* head) +void _yr_base64_print_nodes(BASE64_NODE* head) { size_t i; BASE64_NODE* p = head; @@ -306,8 +290,7 @@ void _yr_base64_print_nodes( // // Destroy a list of base64 nodes. // -static void _yr_base64_destroy_nodes( - BASE64_NODE* head) +static void _yr_base64_destroy_nodes(BASE64_NODE* head) { BASE64_NODE* p = head; BASE64_NODE* next; @@ -337,7 +320,8 @@ int _yr_base64_create_regexp( char* s; uint32_t i; uint32_t length = 0; - uint32_t c = 0; // The number of nodes in the list, used to know how many '|'. + uint32_t c = + 0; // The number of nodes in the list, used to know how many '|'. BASE64_NODE* p = head; while (p != NULL) @@ -386,11 +370,10 @@ int _yr_base64_create_regexp( *s = '\x00'; // Useful for debugging as long as the string has no NULL bytes in it. ;) - //printf("%s\n", re_str); + // printf("%s\n", re_str); FAIL_ON_ERROR_WITH_CLEANUP( - yr_re_parse(re_str, re_ast, re_error), - yr_free(re_str)); + yr_re_parse(re_str, re_ast, re_error), yr_free(re_str)); yr_free(re_str); return ERROR_SUCCESS; @@ -427,7 +410,7 @@ int yr_base64_ast_from_string( { FAIL_ON_ERROR_WITH_CLEANUP( _yr_base64_create_nodes(wide_str, modifier.alphabet, 0, &head, &tail), - { + { // Cleanup strcpy(error->message, "Failure encoding base64 wide string"); yr_free(wide_str); _yr_base64_destroy_nodes(head); @@ -438,7 +421,7 @@ int yr_base64_ast_from_string( { FAIL_ON_ERROR_WITH_CLEANUP( _yr_base64_create_nodes(wide_str, modifier.alphabet, 1, &head, &tail), - { + { // Cleanup strcpy(error->message, "Failure encoding base64wide wide string"); yr_free(wide_str); _yr_base64_destroy_nodes(head); @@ -454,7 +437,7 @@ int yr_base64_ast_from_string( { FAIL_ON_ERROR_WITH_CLEANUP( _yr_base64_create_nodes(in_str, modifier.alphabet, 0, &head, &tail), - { + { // Cleanup strcpy(error->message, "Failure encoding base64 ascii string"); _yr_base64_destroy_nodes(head); }); @@ -464,7 +447,7 @@ int yr_base64_ast_from_string( { FAIL_ON_ERROR_WITH_CLEANUP( _yr_base64_create_nodes(in_str, modifier.alphabet, 1, &head, &tail), - { + { // Cleanup strcpy(error->message, "Failure encoding base64wide ascii string"); _yr_base64_destroy_nodes(head); }); @@ -478,7 +461,7 @@ int yr_base64_ast_from_string( { FAIL_ON_ERROR_WITH_CLEANUP( _yr_base64_create_nodes(in_str, modifier.alphabet, 0, &head, &tail), - { + { // Cleanup strcpy(error->message, "Failure encoding base64 string"); _yr_base64_destroy_nodes(head); }); @@ -488,7 +471,7 @@ int yr_base64_ast_from_string( { FAIL_ON_ERROR_WITH_CLEANUP( _yr_base64_create_nodes(in_str, modifier.alphabet, 1, &head, &tail), - { + { // Cleanup strcpy(error->message, "Failure encoding base64wide string"); _yr_base64_destroy_nodes(head); }); diff --git a/libyara/bitmask.c b/libyara/bitmask.c index a1faa209b3..de27e510c0 100644 --- a/libyara/bitmask.c +++ b/libyara/bitmask.c @@ -28,9 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include - -#include #include +#include // // yr_bitmask_find_non_colliding_offset @@ -78,7 +77,8 @@ uint32_t yr_bitmask_find_non_colliding_offset( // within such slots. for (i = *off_a / YR_BITMASK_SLOT_BITS; i <= len_a / YR_BITMASK_SLOT_BITS && a[i] == -1L; - i++); + i++) + ; *off_a = i; @@ -102,7 +102,7 @@ uint32_t yr_bitmask_find_non_colliding_offset( if ((i + k <= len_a / YR_BITMASK_SLOT_BITS) && (m & a[i + k]) != 0) { found = false; - break ; + break; } } diff --git a/libyara/compiler.c b/libyara/compiler.c index 598817e1fe..cf4685f577 100644 --- a/libyara/compiler.c +++ b/libyara/compiler.c @@ -41,15 +41,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #endif -#include -#include #include -#include #include +#include +#include +#include #include #include -#include #include +#include static void _yr_compiler_default_include_free( @@ -58,7 +58,7 @@ static void _yr_compiler_default_include_free( { if (callback_result_ptr != NULL) { - yr_free((void*)callback_result_ptr); + yr_free((void*) callback_result_ptr); } } @@ -69,56 +69,56 @@ const char* _yr_compiler_default_include_callback( const char* calling_rule_namespace, void* user_data) { - #ifndef _MSC_VER +#ifndef _MSC_VER struct stat stbuf; - #endif +#endif char* file_buffer; - #ifdef _MSC_VER +#ifdef _MSC_VER long file_size; - #else +#else off_t file_size; - #endif +#endif int fd = -1; - #if defined(_MSC_VER) +#if defined(_MSC_VER) _sopen_s(&fd, include_name, _O_RDONLY | _O_BINARY, _SH_DENYWR, _S_IREAD); - #elif defined(_WIN32) || defined(__CYGWIN__) +#elif defined(_WIN32) || defined(__CYGWIN__) fd = open(include_name, O_RDONLY | O_BINARY); - #else +#else fd = open(include_name, O_RDONLY); - #endif +#endif if (fd == -1) return NULL; - #ifdef _MSC_VER +#ifdef _MSC_VER file_size = _filelength(fd); if (file_size == -1) { _close(fd); return NULL; } - #else +#else if ((fstat(fd, &stbuf) != 0) || (!S_ISREG(stbuf.st_mode))) { close(fd); return NULL; } file_size = stbuf.st_size; - #endif +#endif file_buffer = (char*) yr_malloc((size_t) file_size + 1); if (file_buffer == NULL) { - #ifdef _MSC_VER +#ifdef _MSC_VER _close(fd); - #else +#else close(fd); - #endif +#endif return NULL; } @@ -127,11 +127,11 @@ const char* _yr_compiler_default_include_callback( { yr_free(file_buffer); - #ifdef _MSC_VER +#ifdef _MSC_VER _close(fd); - #else +#else close(fd); - #endif +#endif return NULL; } @@ -140,11 +140,11 @@ const char* _yr_compiler_default_include_callback( file_buffer[file_size] = '\0'; } - #ifdef _MSC_VER +#ifdef _MSC_VER _close(fd); - #else +#else close(fd); - #endif +#endif return file_buffer; } @@ -158,8 +158,7 @@ const char* _yr_compiler_default_include_callback( // limited scope where you can be sure that no other rule is being written // during the pointer's lifetime. // -YR_RULE* _yr_compiler_get_rule_by_idx( - YR_COMPILER* compiler, uint32_t rule_idx) +YR_RULE* _yr_compiler_get_rule_by_idx(YR_COMPILER* compiler, uint32_t rule_idx) { return (YR_RULE*) yr_arena_get_ptr( compiler->arena, YR_RULES_TABLE, rule_idx * sizeof(YR_RULE)); @@ -188,18 +187,10 @@ int _yr_compiler_store_data( // the reference's offset in the hash table. Storing the buffer number // is not necessary, it's always YR_SZ_POOL. FAIL_ON_ERROR(yr_arena_write_data( - compiler->arena, - YR_SZ_POOL, - data, - data_length, - ref)); + compiler->arena, YR_SZ_POOL, data, data_length, ref)); FAIL_ON_ERROR(yr_hash_table_add_uint32_raw_key( - compiler->sz_table, - data, - data_length, - NULL, - ref->offset)); + compiler->sz_table, data, data_length, NULL, ref->offset)); } else { @@ -223,13 +214,12 @@ int _yr_compiler_store_string( return _yr_compiler_store_data( compiler, (void*) string, - strlen(string) + 1, // include the null terminator + strlen(string) + 1, // include the null terminator ref); } -YR_API int yr_compiler_create( - YR_COMPILER** compiler) +YR_API int yr_compiler_create(YR_COMPILER** compiler) { int result; YR_COMPILER* new_compiler; @@ -262,7 +252,7 @@ YR_API int yr_compiler_create( new_compiler->loop_for_of_var_index = -1; new_compiler->atoms_config.get_atom_quality = yr_atoms_heuristic_quality; - new_compiler->atoms_config.quality_warning_threshold = \ + new_compiler->atoms_config.quality_warning_threshold = YR_ATOM_QUALITY_WARNING_THRESHOLD; result = yr_hash_table_create(5000, &new_compiler->rules_table); @@ -277,13 +267,11 @@ YR_API int yr_compiler_create( result = yr_hash_table_create(10000, &new_compiler->sz_table); if (result == ERROR_SUCCESS) - result = yr_arena_create( - YR_NUM_SECTIONS, 1048576, &new_compiler->arena); + result = yr_arena_create(YR_NUM_SECTIONS, 1048576, &new_compiler->arena); if (result == ERROR_SUCCESS) result = yr_ac_automaton_create( - new_compiler->arena, - &new_compiler->automaton); + new_compiler->arena, &new_compiler->automaton); if (result == ERROR_SUCCESS) { @@ -298,25 +286,18 @@ YR_API int yr_compiler_create( } -YR_API void yr_compiler_destroy( - YR_COMPILER* compiler) +YR_API void yr_compiler_destroy(YR_COMPILER* compiler) { yr_arena_release(compiler->arena); if (compiler->automaton != NULL) yr_ac_automaton_destroy(compiler->automaton); - yr_hash_table_destroy( - compiler->rules_table, - NULL); + yr_hash_table_destroy(compiler->rules_table, NULL); - yr_hash_table_destroy( - compiler->strings_table, - NULL); + yr_hash_table_destroy(compiler->strings_table, NULL); - yr_hash_table_destroy( - compiler->sz_table, - NULL); + yr_hash_table_destroy(compiler->sz_table, NULL); yr_hash_table_destroy( compiler->objects_table, @@ -413,8 +394,7 @@ YR_API void yr_compiler_set_atom_quality_table( compiler->atoms_config.quality_warning_threshold = warning_threshold; compiler->atoms_config.get_atom_quality = yr_atoms_table_quality; compiler->atoms_config.quality_table_entries = entries; - compiler->atoms_config.quality_table = \ - (YR_ATOM_QUALITY_TABLE_ENTRY*) table; + compiler->atoms_config.quality_table = (YR_ATOM_QUALITY_TABLE_ENTRY*) table; } // @@ -476,9 +456,7 @@ YR_API int yr_compiler_load_atom_quality_table( } -int _yr_compiler_push_file_name( - YR_COMPILER* compiler, - const char* file_name) +int _yr_compiler_push_file_name(YR_COMPILER* compiler, const char* file_name) { char* str; int i; @@ -504,8 +482,7 @@ int _yr_compiler_push_file_name( } -void _yr_compiler_pop_file_name( - YR_COMPILER* compiler) +void _yr_compiler_pop_file_name(YR_COMPILER* compiler) { if (compiler->file_name_stack_ptr > 0) { @@ -516,8 +493,7 @@ void _yr_compiler_pop_file_name( } -int _yr_compiler_get_var_frame( - YR_COMPILER* compiler) +int _yr_compiler_get_var_frame(YR_COMPILER* compiler) { int i, result = 0; @@ -531,8 +507,7 @@ int _yr_compiler_get_var_frame( } -YR_API char* yr_compiler_get_current_file_name( - YR_COMPILER* compiler) +YR_API char* yr_compiler_get_current_file_name(YR_COMPILER* compiler) { if (compiler->file_name_stack_ptr > 0) { @@ -578,10 +553,7 @@ static int _yr_compiler_set_namespace( ns = (YR_NAMESPACE*) yr_arena_ref_to_ptr(compiler->arena, &ref); - FAIL_ON_ERROR(_yr_compiler_store_string( - compiler, - namespace_, - &ref)); + FAIL_ON_ERROR(_yr_compiler_store_string(compiler, namespace_, &ref)); ns->name = (const char*) yr_arena_ref_to_ptr(compiler->arena, &ref); ns->idx = compiler->num_namespaces; @@ -697,8 +669,7 @@ YR_API int yr_compiler_add_string( } -static int _yr_compiler_compile_rules( - YR_COMPILER* compiler) +static int _yr_compiler_compile_rules(YR_COMPILER* compiler) { YR_RULE null_rule; YR_EXTERNAL_VARIABLE null_external; @@ -707,22 +678,14 @@ static int _yr_compiler_compile_rules( // Write halt instruction at the end of code. FAIL_ON_ERROR(yr_arena_write_data( - compiler->arena, - YR_CODE_SECTION, - &halt, - sizeof(uint8_t), - NULL)); + compiler->arena, YR_CODE_SECTION, &halt, sizeof(uint8_t), NULL)); // Write a null rule indicating the end. memset(&null_rule, 0xFA, sizeof(YR_RULE)); null_rule.flags = RULE_FLAGS_NULL; FAIL_ON_ERROR(yr_arena_write_data( - compiler->arena, - YR_RULES_TABLE, - &null_rule, - sizeof(YR_RULE), - NULL)); + compiler->arena, YR_RULES_TABLE, &null_rule, sizeof(YR_RULE), NULL)); // Write a null external indicating the end. memset(&null_external, 0xFA, sizeof(YR_EXTERNAL_VARIABLE)); @@ -736,18 +699,12 @@ static int _yr_compiler_compile_rules( NULL)); // Write Aho-Corasick automaton to arena. - FAIL_ON_ERROR(yr_ac_compile( - compiler->automaton, - compiler->arena)); + FAIL_ON_ERROR(yr_ac_compile(compiler->automaton, compiler->arena)); YR_ARENA_REF ref; FAIL_ON_ERROR(yr_arena_allocate_struct( - compiler->arena, - YR_SUMMARY_SECTION, - sizeof(YR_SUMMARY), - &ref, - EOL)); + compiler->arena, YR_SUMMARY_SECTION, sizeof(YR_SUMMARY), &ref, EOL)); YR_SUMMARY* summary = (YR_SUMMARY*) yr_arena_ref_to_ptr( compiler->arena, &ref); @@ -760,9 +717,7 @@ static int _yr_compiler_compile_rules( } -YR_API int yr_compiler_get_rules( - YR_COMPILER* compiler, - YR_RULES** rules) +YR_API int yr_compiler_get_rules(YR_COMPILER* compiler, YR_RULES** rules) { // Don't allow calls to yr_compiler_get_rules() if a previous call to // yr_compiler_add_XXXX failed. @@ -771,7 +726,7 @@ YR_API int yr_compiler_get_rules( *rules = NULL; if (compiler->rules == NULL) - FAIL_ON_ERROR(_yr_compiler_compile_rules(compiler)); + FAIL_ON_ERROR(_yr_compiler_compile_rules(compiler)); *rules = compiler->rules; @@ -789,9 +744,7 @@ static int _yr_compiler_define_variable( return ERROR_INVALID_ARGUMENT; object = (YR_OBJECT*) yr_hash_table_lookup( - compiler->objects_table, - external->identifier, - NULL); + compiler->objects_table, external->identifier, NULL); if (object != NULL) return ERROR_DUPLICATED_EXTERNAL_VARIABLE; @@ -807,16 +760,12 @@ static int _yr_compiler_define_variable( offsetof(YR_EXTERNAL_VARIABLE, identifier), EOL)); - ext = (YR_EXTERNAL_VARIABLE*) yr_arena_ref_to_ptr( - compiler->arena, &ext_ref); + ext = (YR_EXTERNAL_VARIABLE*) yr_arena_ref_to_ptr(compiler->arena, &ext_ref); - FAIL_ON_ERROR(_yr_compiler_store_string( - compiler, - external->identifier, - &ref)); + FAIL_ON_ERROR( + _yr_compiler_store_string(compiler, external->identifier, &ref)); - ext->identifier = (const char*) yr_arena_ref_to_ptr( - compiler->arena, &ref); + ext->identifier = (const char*) yr_arena_ref_to_ptr(compiler->arena, &ref); ext->type = external->type; ext->value = external->value; @@ -826,10 +775,7 @@ static int _yr_compiler_define_variable( if (external->value.s == NULL) return ERROR_INVALID_ARGUMENT; - FAIL_ON_ERROR(_yr_compiler_store_string( - compiler, - external->value.s, - &ref)); + FAIL_ON_ERROR(_yr_compiler_store_string(compiler, external->value.s, &ref)); FAIL_ON_ERROR(yr_arena_make_ptr_relocatable( compiler->arena, @@ -837,20 +783,14 @@ static int _yr_compiler_define_variable( ext_ref.offset + offsetof(YR_EXTERNAL_VARIABLE, value.s), EOL)); - ext->value.s = (char*) yr_arena_ref_to_ptr( - compiler->arena, &ref); + ext->value.s = (char*) yr_arena_ref_to_ptr(compiler->arena, &ref); } - FAIL_ON_ERROR(yr_object_from_external_variable( - external, - &object)); + FAIL_ON_ERROR(yr_object_from_external_variable(external, &object)); - FAIL_ON_ERROR_WITH_CLEANUP(yr_hash_table_add( - compiler->objects_table, - external->identifier, - NULL, - (void*) object), - // cleanup + FAIL_ON_ERROR_WITH_CLEANUP( + yr_hash_table_add( + compiler->objects_table, external->identifier, NULL, (void*) object), yr_object_destroy(object)); return ERROR_SUCCESS; @@ -868,8 +808,7 @@ YR_API int yr_compiler_define_integer_variable( external.identifier = identifier; external.value.i = value; - FAIL_ON_ERROR(_yr_compiler_define_variable( - compiler, &external)); + FAIL_ON_ERROR(_yr_compiler_define_variable(compiler, &external)); return ERROR_SUCCESS; } @@ -886,8 +825,7 @@ YR_API int yr_compiler_define_boolean_variable( external.identifier = identifier; external.value.i = value; - FAIL_ON_ERROR(_yr_compiler_define_variable( - compiler, &external)); + FAIL_ON_ERROR(_yr_compiler_define_variable(compiler, &external)); return ERROR_SUCCESS; } @@ -904,8 +842,7 @@ YR_API int yr_compiler_define_float_variable( external.identifier = identifier; external.value.f = value; - FAIL_ON_ERROR(_yr_compiler_define_variable( - compiler, &external)); + FAIL_ON_ERROR(_yr_compiler_define_variable(compiler, &external)); return ERROR_SUCCESS; } @@ -922,8 +859,7 @@ YR_API int yr_compiler_define_string_variable( external.identifier = identifier; external.value.s = (char*) value; - FAIL_ON_ERROR(_yr_compiler_define_variable( - compiler, &external)); + FAIL_ON_ERROR(_yr_compiler_define_variable(compiler, &external)); return ERROR_SUCCESS; } @@ -936,231 +872,194 @@ YR_API char* yr_compiler_get_error_message( { uint32_t max_strings_per_rule; - switch(compiler->last_error) + switch (compiler->last_error) { - case ERROR_INSUFFICIENT_MEMORY: - snprintf(buffer, buffer_size, "not enough memory"); - break; - case ERROR_DUPLICATED_IDENTIFIER: - snprintf( - buffer, - buffer_size, - "duplicated identifier \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_DUPLICATED_STRING_IDENTIFIER: - snprintf( - buffer, - buffer_size, - "duplicated string identifier \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_DUPLICATED_TAG_IDENTIFIER: - snprintf( - buffer, - buffer_size, - "duplicated tag identifier \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_DUPLICATED_META_IDENTIFIER: - snprintf( - buffer, - buffer_size, - "duplicated metadata identifier \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_DUPLICATED_LOOP_IDENTIFIER: - snprintf( - buffer, - buffer_size, - "duplicated loop identifier \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_UNDEFINED_STRING: - snprintf( - buffer, - buffer_size, - "undefined string \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_UNDEFINED_IDENTIFIER: - snprintf( - buffer, - buffer_size, - "undefined identifier \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_UNREFERENCED_STRING: - snprintf( - buffer, - buffer_size, - "unreferenced string \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_EMPTY_STRING: - snprintf( - buffer, - buffer_size, - "empty string \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_NOT_A_STRUCTURE: - snprintf( - buffer, - buffer_size, - "\"%s\" is not a structure", - compiler->last_error_extra_info); - break; - case ERROR_NOT_INDEXABLE: - snprintf( - buffer, - buffer_size, - "\"%s\" is not an array or dictionary", - compiler->last_error_extra_info); - break; - case ERROR_NOT_A_FUNCTION: - snprintf( - buffer, - buffer_size, - "\"%s\" is not a function", - compiler->last_error_extra_info); - break; - case ERROR_INVALID_FIELD_NAME: - snprintf( - buffer, - buffer_size, - "invalid field name \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_MISPLACED_ANONYMOUS_STRING: - snprintf( - buffer, - buffer_size, - "wrong use of anonymous string"); - break; - case ERROR_INCLUDES_CIRCULAR_REFERENCE: - snprintf( - buffer, - buffer_size, - "include circular reference"); - break; - case ERROR_INCLUDE_DEPTH_EXCEEDED: - snprintf(buffer, - buffer_size, - "too many levels of included rules"); - break; - case ERROR_LOOP_NESTING_LIMIT_EXCEEDED: - snprintf(buffer, - buffer_size, - "loop nesting limit exceeded"); - break; - case ERROR_NESTED_FOR_OF_LOOP: - snprintf(buffer, - buffer_size, - "'for of ' loops can't be nested"); - break; - case ERROR_UNKNOWN_MODULE: - snprintf( - buffer, - buffer_size, - "unknown module \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_INVALID_MODULE_NAME: - snprintf( - buffer, - buffer_size, - "invalid module name \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_DUPLICATED_STRUCTURE_MEMBER: - snprintf(buffer, - buffer_size, - "duplicated structure member"); - break; - case ERROR_WRONG_ARGUMENTS: - snprintf( - buffer, - buffer_size, - "wrong arguments for function \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_WRONG_RETURN_TYPE: - snprintf(buffer, - buffer_size, - "wrong return type for overloaded function"); - break; - case ERROR_INVALID_HEX_STRING: - case ERROR_INVALID_REGULAR_EXPRESSION: - case ERROR_SYNTAX_ERROR: - case ERROR_WRONG_TYPE: - snprintf( - buffer, - buffer_size, - "%s", - compiler->last_error_extra_info); - break; - case ERROR_INTERNAL_FATAL_ERROR: - snprintf( - buffer, - buffer_size, - "internal fatal error"); - break; - case ERROR_DIVISION_BY_ZERO: - snprintf( - buffer, - buffer_size, - "division by zero"); - break; - case ERROR_REGULAR_EXPRESSION_TOO_LARGE: - snprintf( - buffer, - buffer_size, - "regular expression is too large"); - break; - case ERROR_REGULAR_EXPRESSION_TOO_COMPLEX: - snprintf( - buffer, - buffer_size, - "regular expression is too complex"); - break; - case ERROR_TOO_MANY_STRINGS: - yr_get_configuration( - YR_CONFIG_MAX_STRINGS_PER_RULE, - &max_strings_per_rule); - snprintf( - buffer, - buffer_size, - "too many strings in rule \"%s\" (limit: %d)", - compiler->last_error_extra_info, - max_strings_per_rule); - break; - case ERROR_INTEGER_OVERFLOW: - snprintf( - buffer, - buffer_size, - "integer overflow in \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_COULD_NOT_READ_FILE: - snprintf( - buffer, - buffer_size, - "could not read file"); - break; - case ERROR_INVALID_MODIFIER: - snprintf( - buffer, - buffer_size, - "invalid modifier combination \"%s\"", - compiler->last_error_extra_info); - break; - case ERROR_DUPLICATED_MODIFIER: - snprintf( - buffer, - buffer_size, - "duplicated modifier"); - break; + case ERROR_INSUFFICIENT_MEMORY: + snprintf(buffer, buffer_size, "not enough memory"); + break; + case ERROR_DUPLICATED_IDENTIFIER: + snprintf( + buffer, + buffer_size, + "duplicated identifier \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_DUPLICATED_STRING_IDENTIFIER: + snprintf( + buffer, + buffer_size, + "duplicated string identifier \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_DUPLICATED_TAG_IDENTIFIER: + snprintf( + buffer, + buffer_size, + "duplicated tag identifier \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_DUPLICATED_META_IDENTIFIER: + snprintf( + buffer, + buffer_size, + "duplicated metadata identifier \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_DUPLICATED_LOOP_IDENTIFIER: + snprintf( + buffer, + buffer_size, + "duplicated loop identifier \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_UNDEFINED_STRING: + snprintf( + buffer, + buffer_size, + "undefined string \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_UNDEFINED_IDENTIFIER: + snprintf( + buffer, + buffer_size, + "undefined identifier \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_UNREFERENCED_STRING: + snprintf( + buffer, + buffer_size, + "unreferenced string \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_EMPTY_STRING: + snprintf( + buffer, + buffer_size, + "empty string \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_NOT_A_STRUCTURE: + snprintf( + buffer, + buffer_size, + "\"%s\" is not a structure", + compiler->last_error_extra_info); + break; + case ERROR_NOT_INDEXABLE: + snprintf( + buffer, + buffer_size, + "\"%s\" is not an array or dictionary", + compiler->last_error_extra_info); + break; + case ERROR_NOT_A_FUNCTION: + snprintf( + buffer, + buffer_size, + "\"%s\" is not a function", + compiler->last_error_extra_info); + break; + case ERROR_INVALID_FIELD_NAME: + snprintf( + buffer, + buffer_size, + "invalid field name \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_MISPLACED_ANONYMOUS_STRING: + snprintf(buffer, buffer_size, "wrong use of anonymous string"); + break; + case ERROR_INCLUDES_CIRCULAR_REFERENCE: + snprintf(buffer, buffer_size, "include circular reference"); + break; + case ERROR_INCLUDE_DEPTH_EXCEEDED: + snprintf(buffer, buffer_size, "too many levels of included rules"); + break; + case ERROR_LOOP_NESTING_LIMIT_EXCEEDED: + snprintf(buffer, buffer_size, "loop nesting limit exceeded"); + break; + case ERROR_NESTED_FOR_OF_LOOP: + snprintf( + buffer, + buffer_size, + "'for of ' loops can't be nested"); + break; + case ERROR_UNKNOWN_MODULE: + snprintf( + buffer, + buffer_size, + "unknown module \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_INVALID_MODULE_NAME: + snprintf( + buffer, + buffer_size, + "invalid module name \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_DUPLICATED_STRUCTURE_MEMBER: + snprintf(buffer, buffer_size, "duplicated structure member"); + break; + case ERROR_WRONG_ARGUMENTS: + snprintf( + buffer, + buffer_size, + "wrong arguments for function \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_WRONG_RETURN_TYPE: + snprintf(buffer, buffer_size, "wrong return type for overloaded function"); + break; + case ERROR_INVALID_HEX_STRING: + case ERROR_INVALID_REGULAR_EXPRESSION: + case ERROR_SYNTAX_ERROR: + case ERROR_WRONG_TYPE: + snprintf(buffer, buffer_size, "%s", compiler->last_error_extra_info); + break; + case ERROR_INTERNAL_FATAL_ERROR: + snprintf(buffer, buffer_size, "internal fatal error"); + break; + case ERROR_DIVISION_BY_ZERO: + snprintf(buffer, buffer_size, "division by zero"); + break; + case ERROR_REGULAR_EXPRESSION_TOO_LARGE: + snprintf(buffer, buffer_size, "regular expression is too large"); + break; + case ERROR_REGULAR_EXPRESSION_TOO_COMPLEX: + snprintf(buffer, buffer_size, "regular expression is too complex"); + break; + case ERROR_TOO_MANY_STRINGS: + yr_get_configuration(YR_CONFIG_MAX_STRINGS_PER_RULE, &max_strings_per_rule); + snprintf( + buffer, + buffer_size, + "too many strings in rule \"%s\" (limit: %d)", + compiler->last_error_extra_info, + max_strings_per_rule); + break; + case ERROR_INTEGER_OVERFLOW: + snprintf( + buffer, + buffer_size, + "integer overflow in \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_COULD_NOT_READ_FILE: + snprintf(buffer, buffer_size, "could not read file"); + break; + case ERROR_INVALID_MODIFIER: + snprintf( + buffer, + buffer_size, + "invalid modifier combination \"%s\"", + compiler->last_error_extra_info); + break; + case ERROR_DUPLICATED_MODIFIER: + snprintf(buffer, buffer_size, "duplicated modifier"); + break; } return buffer; diff --git a/libyara/crypto.h b/libyara/crypto.h index 4a0e5ceade..4309d46793 100644 --- a/libyara/crypto.h +++ b/libyara/crypto.h @@ -43,30 +43,21 @@ typedef MD5_CTX yr_md5_ctx; typedef SHA_CTX yr_sha1_ctx; typedef SHA256_CTX yr_sha256_ctx; -#define yr_md5_init(ctx) \ - MD5_Init(ctx) -#define yr_md5_update(ctx,data,len) \ - MD5_Update(ctx,data,len) -#define yr_md5_final(digest,ctx) \ - MD5_Final(digest,ctx) - -#define yr_sha1_init(ctx) \ - SHA1_Init(ctx) -#define yr_sha1_update(ctx,data,len) \ - SHA1_Update(ctx,data,len) -#define yr_sha1_final(digest,ctx) \ - SHA1_Final(digest,ctx) +#define yr_md5_init(ctx) MD5_Init(ctx) +#define yr_md5_update(ctx, data, len) MD5_Update(ctx, data, len) +#define yr_md5_final(digest, ctx) MD5_Final(digest, ctx) -#define yr_sha256_init(ctx) \ - SHA256_Init(ctx) -#define yr_sha256_update(ctx,data,len) \ - SHA256_Update(ctx,data,len) -#define yr_sha256_final(digest,ctx) \ - SHA256_Final(digest,ctx) +#define yr_sha1_init(ctx) SHA1_Init(ctx) +#define yr_sha1_update(ctx, data, len) SHA1_Update(ctx, data, len) +#define yr_sha1_final(digest, ctx) SHA1_Final(digest, ctx) + +#define yr_sha256_init(ctx) SHA256_Init(ctx) +#define yr_sha256_update(ctx, data, len) SHA256_Update(ctx, data, len) +#define yr_sha256_final(digest, ctx) SHA256_Final(digest, ctx) #elif defined(HAVE_WINCRYPT_H) -#include #include +#include HCRYPTPROV yr_cryptprov; @@ -74,35 +65,36 @@ typedef HCRYPTHASH yr_md5_ctx; typedef HCRYPTHASH yr_sha1_ctx; typedef HCRYPTHASH yr_sha256_ctx; -#define yr_md5_init(ctx) \ - CryptCreateHash(yr_cryptprov, CALG_MD5, 0, 0, ctx) -#define yr_md5_update(ctx,data,len) \ - CryptHashData(*ctx, (const BYTE*)data, len, 0) -#define yr_md5_final(digest,ctx) { \ - DWORD len = YR_MD5_LEN; \ - CryptGetHashParam(*ctx, HP_HASHVAL, digest, &len, 0); \ - CryptDestroyHash(*ctx); \ -} - -#define yr_sha1_init(ctx) \ - CryptCreateHash(yr_cryptprov, CALG_SHA1, 0, 0, ctx) -#define yr_sha1_update(ctx,data,len) \ - CryptHashData(*ctx, (const BYTE*)data, len, 0) -#define yr_sha1_final(digest,ctx) { \ - DWORD len = YR_SHA1_LEN; \ - CryptGetHashParam(*ctx, HP_HASHVAL, digest, &len, 0); \ - CryptDestroyHash(*ctx); \ -} +#define yr_md5_init(ctx) CryptCreateHash(yr_cryptprov, CALG_MD5, 0, 0, ctx) +#define yr_md5_update(ctx, data, len) \ + CryptHashData(*ctx, (const BYTE*) data, len, 0) +#define yr_md5_final(digest, ctx) \ + { \ + DWORD len = YR_MD5_LEN; \ + CryptGetHashParam(*ctx, HP_HASHVAL, digest, &len, 0); \ + CryptDestroyHash(*ctx); \ + } + +#define yr_sha1_init(ctx) CryptCreateHash(yr_cryptprov, CALG_SHA1, 0, 0, ctx) +#define yr_sha1_update(ctx, data, len) \ + CryptHashData(*ctx, (const BYTE*) data, len, 0) +#define yr_sha1_final(digest, ctx) \ + { \ + DWORD len = YR_SHA1_LEN; \ + CryptGetHashParam(*ctx, HP_HASHVAL, digest, &len, 0); \ + CryptDestroyHash(*ctx); \ + } #define yr_sha256_init(ctx) \ CryptCreateHash(yr_cryptprov, CALG_SHA_256, 0, 0, ctx) -#define yr_sha256_update(ctx,data,len) \ - CryptHashData(*ctx, (const BYTE*)data, len, 0) -#define yr_sha256_final(digest,ctx) { \ - DWORD len = YR_SHA256_LEN; \ - CryptGetHashParam(*ctx, HP_HASHVAL, digest, &len, 0); \ - CryptDestroyHash(*ctx); \ -} +#define yr_sha256_update(ctx, data, len) \ + CryptHashData(*ctx, (const BYTE*) data, len, 0) +#define yr_sha256_final(digest, ctx) \ + { \ + DWORD len = YR_SHA256_LEN; \ + CryptGetHashParam(*ctx, HP_HASHVAL, digest, &len, 0); \ + CryptDestroyHash(*ctx); \ + } #elif defined(HAVE_COMMONCRYPTO_COMMONCRYPTO_H) #include @@ -111,26 +103,17 @@ typedef CC_MD5_CTX yr_md5_ctx; typedef CC_SHA1_CTX yr_sha1_ctx; typedef CC_SHA256_CTX yr_sha256_ctx; -#define yr_md5_init(ctx) \ - CC_MD5_Init(ctx) -#define yr_md5_update(ctx,data,len) \ - CC_MD5_Update(ctx, data, len) -#define yr_md5_final(digest,ctx) \ - CC_MD5_Final(digest, ctx) +#define yr_md5_init(ctx) CC_MD5_Init(ctx) +#define yr_md5_update(ctx, data, len) CC_MD5_Update(ctx, data, len) +#define yr_md5_final(digest, ctx) CC_MD5_Final(digest, ctx) -#define yr_sha1_init(ctx) \ - CC_SHA1_Init(ctx) -#define yr_sha1_update(ctx,data,len) \ - CC_SHA1_Update(ctx, data, len) -#define yr_sha1_final(digest,ctx) \ - CC_SHA1_Final(digest, ctx) +#define yr_sha1_init(ctx) CC_SHA1_Init(ctx) +#define yr_sha1_update(ctx, data, len) CC_SHA1_Update(ctx, data, len) +#define yr_sha1_final(digest, ctx) CC_SHA1_Final(digest, ctx) -#define yr_sha256_init(ctx) \ - CC_SHA256_Init(ctx) -#define yr_sha256_update(ctx,data,len) \ - CC_SHA256_Update(ctx, data, len) -#define yr_sha256_final(digest,ctx) \ - CC_SHA256_Final(digest, ctx) +#define yr_sha256_init(ctx) CC_SHA256_Init(ctx) +#define yr_sha256_update(ctx, data, len) CC_SHA256_Update(ctx, data, len) +#define yr_sha256_final(digest, ctx) CC_SHA256_Final(digest, ctx) #endif diff --git a/libyara/endian.c b/libyara/endian.c index 02fff634ad..829388e132 100644 --- a/libyara/endian.c +++ b/libyara/endian.c @@ -36,18 +36,20 @@ uint16_t _yr_bswap16(uint16_t x) uint32_t _yr_bswap32(uint32_t x) { - return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | - (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); + return ( + (((x) &0xff000000) >> 24) | (((x) &0x00ff0000) >> 8) | + (((x) &0x0000ff00) << 8) | (((x) &0x000000ff) << 24)); } uint64_t _yr_bswap64(uint64_t x) { - return ((((x) & 0xff00000000000000ull) >> 56) - | (((x) & 0x00ff000000000000ull) >> 40) - | (((x) & 0x0000ff0000000000ull) >> 24) - | (((x) & 0x000000ff00000000ull) >> 8) - | (((x) & 0x00000000ff000000ull) << 8) - | (((x) & 0x0000000000ff0000ull) << 24) - | (((x) & 0x000000000000ff00ull) << 40) - | (((x) & 0x00000000000000ffull) << 56)); + return ( + (((x) &0xff00000000000000ull) >> 56) | + (((x) &0x00ff000000000000ull) >> 40) | + (((x) &0x0000ff0000000000ull) >> 24) | + (((x) &0x000000ff00000000ull) >> 8) | + (((x) &0x00000000ff000000ull) << 8) | + (((x) &0x0000000000ff0000ull) << 24) | + (((x) &0x000000000000ff00ull) << 40) | + (((x) &0x00000000000000ffull) << 56)); } diff --git a/libyara/exception.h b/libyara/exception.h index 218cdeabbe..c76d3b74b6 100644 --- a/libyara/exception.h +++ b/libyara/exception.h @@ -43,32 +43,37 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -static LONG CALLBACK exception_handler( - PEXCEPTION_POINTERS ExceptionInfo) +static LONG CALLBACK exception_handler(PEXCEPTION_POINTERS ExceptionInfo) { - switch(ExceptionInfo->ExceptionRecord->ExceptionCode) + switch (ExceptionInfo->ExceptionRecord->ExceptionCode) { - case EXCEPTION_IN_PAGE_ERROR: - case EXCEPTION_ACCESS_VIOLATION: - return EXCEPTION_EXECUTE_HANDLER; + case EXCEPTION_IN_PAGE_ERROR: + case EXCEPTION_ACCESS_VIOLATION: + return EXCEPTION_EXECUTE_HANDLER; } return EXCEPTION_CONTINUE_SEARCH; } -#define YR_TRYCATCH(_do_,_try_clause_,_catch_clause_) \ - do \ - { \ - if (_do_) \ - { \ - __try \ - { _try_clause_ } \ - __except(exception_handler(GetExceptionInformation())) \ - { _catch_clause_ } \ - } \ - else \ - { _try_clause_ } \ - } while(0) +#define YR_TRYCATCH(_do_, _try_clause_, _catch_clause_) \ + do \ + { \ + if (_do_) \ + { \ + __try \ + { \ + _try_clause_ \ + } \ + __except (exception_handler(GetExceptionInformation())) \ + { \ + _catch_clause_ \ + } \ + } \ + else \ + { \ + _try_clause_ \ + } \ + } while (0) #else @@ -76,48 +81,49 @@ static LONG CALLBACK exception_handler( #include -static LONG CALLBACK exception_handler( - PEXCEPTION_POINTERS ExceptionInfo) +static LONG CALLBACK exception_handler(PEXCEPTION_POINTERS ExceptionInfo) { jmp_buf* jb_ptr; - switch(ExceptionInfo->ExceptionRecord->ExceptionCode) + switch (ExceptionInfo->ExceptionRecord->ExceptionCode) { - case EXCEPTION_IN_PAGE_ERROR: - case EXCEPTION_ACCESS_VIOLATION: - jb_ptr = (jmp_buf*) yr_thread_storage_get_value( - &yr_trycatch_trampoline_tls); + case EXCEPTION_IN_PAGE_ERROR: + case EXCEPTION_ACCESS_VIOLATION: + jb_ptr = + (jmp_buf*) yr_thread_storage_get_value(&yr_trycatch_trampoline_tls); - if (jb_ptr != NULL) - longjmp(*jb_ptr, 1); + if (jb_ptr != NULL) + longjmp(*jb_ptr, 1); } return EXCEPTION_CONTINUE_SEARCH; } -#define YR_TRYCATCH(_do_,_try_clause_,_catch_clause_) \ - do \ - { \ - if (_do_) \ - { \ - jmp_buf jb; \ - /* Store pointer to sigjmp_buf in TLS */ \ - yr_thread_storage_set_value( \ - &yr_trycatch_trampoline_tls, &jb); \ - HANDLE exh = AddVectoredExceptionHandler(1, exception_handler); \ - if (setjmp(jb) == 0) \ - { _try_clause_ } \ - else \ - { _catch_clause_ } \ - RemoveVectoredExceptionHandler(exh); \ - yr_thread_storage_set_value( \ - &yr_trycatch_trampoline_tls, NULL); \ - } \ - else \ - { \ - _try_clause_ \ - } \ - } while(0) +#define YR_TRYCATCH(_do_, _try_clause_, _catch_clause_) \ + do \ + { \ + if (_do_) \ + { \ + jmp_buf jb; \ + /* Store pointer to sigjmp_buf in TLS */ \ + yr_thread_storage_set_value(&yr_trycatch_trampoline_tls, &jb); \ + HANDLE exh = AddVectoredExceptionHandler(1, exception_handler); \ + if (setjmp(jb) == 0) \ + { \ + _try_clause_ \ + } \ + else \ + { \ + _catch_clause_ \ + } \ + RemoveVectoredExceptionHandler(exh); \ + yr_thread_storage_set_value(&yr_trycatch_trampoline_tls, NULL); \ + } \ + else \ + { \ + _try_clause_ \ + } \ + } while (0) #endif @@ -127,11 +133,12 @@ static LONG CALLBACK exception_handler( #include #include -static void exception_handler(int sig) { +static void exception_handler(int sig) +{ if (sig == SIGBUS || sig == SIGSEGV) { - jmp_buf* jb_ptr = (jmp_buf*) yr_thread_storage_get_value( - &yr_trycatch_trampoline_tls); + jmp_buf* jb_ptr = + (jmp_buf*) yr_thread_storage_get_value(&yr_trycatch_trampoline_tls); if (jb_ptr != NULL) siglongjmp(*jb_ptr, 1); @@ -140,38 +147,40 @@ static void exception_handler(int sig) { typedef struct sigaction sa; -#define YR_TRYCATCH(_do_,_try_clause_, _catch_clause_) \ - do \ - { \ - if (_do_) \ - { \ - struct sigaction old_sigbus_act; \ - struct sigaction old_sigsegv_act; \ - struct sigaction act; \ - sigjmp_buf jb; \ - /* Store pointer to sigjmp_buf in TLS */ \ - yr_thread_storage_set_value( \ - &yr_trycatch_trampoline_tls, &jb); \ - /* Set exception handler for SIGBUS and SIGSEGV*/ \ - act.sa_handler = exception_handler; \ - act.sa_flags = 0; /* SA_ONSTACK? */ \ - sigfillset(&act.sa_mask); \ - sigaction(SIGBUS, &act, &old_sigbus_act); \ - sigaction(SIGSEGV, &act, &old_sigsegv_act); \ - if (sigsetjmp(jb, 1) == 0) \ - { _try_clause_ } \ - else \ - { _catch_clause_ } \ - /* Stop capturing SIGBUS and SIGSEGV */ \ - sigaction(SIGBUS, &old_sigbus_act, NULL); \ - sigaction(SIGSEGV, &old_sigsegv_act, NULL); \ - yr_thread_storage_set_value( \ - &yr_trycatch_trampoline_tls, NULL); \ - } \ - else \ - { \ - _try_clause_ \ - } \ +#define YR_TRYCATCH(_do_, _try_clause_, _catch_clause_) \ + do \ + { \ + if (_do_) \ + { \ + struct sigaction old_sigbus_act; \ + struct sigaction old_sigsegv_act; \ + struct sigaction act; \ + sigjmp_buf jb; \ + /* Store pointer to sigjmp_buf in TLS */ \ + yr_thread_storage_set_value(&yr_trycatch_trampoline_tls, &jb); \ + /* Set exception handler for SIGBUS and SIGSEGV*/ \ + act.sa_handler = exception_handler; \ + act.sa_flags = 0; /* SA_ONSTACK? */ \ + sigfillset(&act.sa_mask); \ + sigaction(SIGBUS, &act, &old_sigbus_act); \ + sigaction(SIGSEGV, &act, &old_sigsegv_act); \ + if (sigsetjmp(jb, 1) == 0) \ + { \ + _try_clause_ \ + } \ + else \ + { \ + _catch_clause_ \ + } \ + /* Stop capturing SIGBUS and SIGSEGV */ \ + sigaction(SIGBUS, &old_sigbus_act, NULL); \ + sigaction(SIGSEGV, &old_sigsegv_act, NULL); \ + yr_thread_storage_set_value(&yr_trycatch_trampoline_tls, NULL); \ + } \ + else \ + { \ + _try_clause_ \ + } \ } while (0) #endif diff --git a/libyara/exec.c b/libyara/exec.c index 8f0bfb3577..cd4919c025 100644 --- a/libyara/exec.c +++ b/libyara/exec.c @@ -27,28 +27,25 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include -#include #include - -#include +#include +#include +#include #include #include +#include #include +#include #include -#include -#include +#include #include +#include #include #include +#include #include #include -#include -#include - - -#include // Turn on paranoid mode by default if not defined otherwise. In paranoid @@ -66,123 +63,123 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ensure that they haven't been modified by someone else. #if !defined(YR_PARANOID_EXEC) -#define YR_PARANOID_EXEC 1 +#define YR_PARANOID_EXEC 1 #endif -#define MEM_SIZE \ - YR_MAX_LOOP_NESTING * (YR_MAX_LOOP_VARS + YR_INTERNAL_LOOP_VARS) +#define MEM_SIZE YR_MAX_LOOP_NESTING*(YR_MAX_LOOP_VARS + YR_INTERNAL_LOOP_VARS) -#define push(x) \ - if (stack.sp < stack.capacity) \ - { \ - stack.items[stack.sp++] = (x); \ - } \ - else \ - { \ - result = ERROR_EXEC_STACK_OVERFLOW; \ - stop = true; \ - break; \ - } \ +#define push(x) \ + if (stack.sp < stack.capacity) \ + { \ + stack.items[stack.sp++] = (x); \ + } \ + else \ + { \ + result = ERROR_EXEC_STACK_OVERFLOW; \ + stop = true; \ + break; \ + } -#define pop(x) { assert(stack.sp > 0); x = stack.items[--stack.sp]; } +#define pop(x) \ + { \ + assert(stack.sp > 0); \ + x = stack.items[--stack.sp]; \ + } #define is_undef(x) IS_UNDEFINED((x).i) #define ensure_defined(x) \ - if (is_undef(x)) \ - { \ - r1.i = YR_UNDEFINED; \ - push(r1); \ - break; \ - } + if (is_undef(x)) \ + { \ + r1.i = YR_UNDEFINED; \ + push(r1); \ + break; \ + } -#define ensure_within_mem(x) \ - if (x < 0 || x >= MEM_SIZE) \ - { \ - stop = true; \ - result = ERROR_INTERNAL_FATAL_ERROR; \ - break; \ - } +#define ensure_within_mem(x) \ + if (x < 0 || x >= MEM_SIZE) \ + { \ + stop = true; \ + result = ERROR_INTERNAL_FATAL_ERROR; \ + break; \ + } // Make sure that the string pointer is within the rules arena. -#define ensure_within_rules_arena(x) \ - { \ - YR_ARENA_REF ref; \ - if (yr_arena_ptr_to_ref(context->rules->arena, x, &ref) == 0) \ - { \ - stop = true; \ - result = ERROR_INTERNAL_FATAL_ERROR; \ - break; \ - } \ - } +#define ensure_within_rules_arena(x) \ + { \ + YR_ARENA_REF ref; \ + if (yr_arena_ptr_to_ref(context->rules->arena, x, &ref) == 0) \ + { \ + stop = true; \ + result = ERROR_INTERNAL_FATAL_ERROR; \ + break; \ + } \ + } -#define check_object_canary(o) \ - if (o->canary != context->canary) \ - { \ - stop = true; \ - result = ERROR_INTERNAL_FATAL_ERROR; \ - break; \ - } +#define check_object_canary(o) \ + if (o->canary != context->canary) \ + { \ + stop = true; \ + result = ERROR_INTERNAL_FATAL_ERROR; \ + break; \ + } -#define little_endian_uint8_t(x) (x) -#define little_endian_int8_t(x) (x) -#define little_endian_uint16_t(x) yr_le16toh(x) -#define little_endian_int16_t(x) yr_le16toh(x) -#define little_endian_uint32_t(x) yr_le32toh(x) -#define little_endian_int32_t(x) yr_le32toh(x) - -#define big_endian_uint8_t(x) (x) -#define big_endian_int8_t(x) (x) -#define big_endian_uint16_t(x) yr_be16toh(x) -#define big_endian_int16_t(x) yr_be16toh(x) -#define big_endian_uint32_t(x) yr_be32toh(x) -#define big_endian_int32_t(x) yr_be32toh(x) - - -#define function_read(type, endianess) \ - int64_t read_##type##_##endianess(YR_MEMORY_BLOCK_ITERATOR* iterator, size_t offset) \ - { \ - YR_MEMORY_BLOCK* block = iterator->first(iterator); \ - while (block != NULL) \ - { \ - if (offset >= block->base && \ - block->size >= sizeof(type) && \ - offset <= block->base + block->size - sizeof(type)) \ - { \ - type result; \ - const uint8_t* data = block->fetch_data(block); \ - if (data == NULL) \ - return YR_UNDEFINED; \ - result = *(type *)(data + offset - block->base); \ - result = endianess##_##type(result); \ - return result; \ - } \ - block = iterator->next(iterator); \ - } \ - return YR_UNDEFINED; \ - }; - - -function_read(uint8_t, little_endian) -function_read(uint16_t, little_endian) -function_read(uint32_t, little_endian) -function_read(int8_t, little_endian) -function_read(int16_t, little_endian) -function_read(int32_t, little_endian) -function_read(uint8_t, big_endian) -function_read(uint16_t, big_endian) -function_read(uint32_t, big_endian) -function_read(int8_t, big_endian) -function_read(int16_t, big_endian) -function_read(int32_t, big_endian) - - -static const uint8_t* jmp_if( - int condition, - const uint8_t* ip) +#define little_endian_uint8_t(x) (x) +#define little_endian_int8_t(x) (x) +#define little_endian_uint16_t(x) yr_le16toh(x) +#define little_endian_int16_t(x) yr_le16toh(x) +#define little_endian_uint32_t(x) yr_le32toh(x) +#define little_endian_int32_t(x) yr_le32toh(x) + +#define big_endian_uint8_t(x) (x) +#define big_endian_int8_t(x) (x) +#define big_endian_uint16_t(x) yr_be16toh(x) +#define big_endian_int16_t(x) yr_be16toh(x) +#define big_endian_uint32_t(x) yr_be32toh(x) +#define big_endian_int32_t(x) yr_be32toh(x) + + +#define function_read(type, endianess) \ + int64_t read_##type##_##endianess( \ + YR_MEMORY_BLOCK_ITERATOR* iterator, size_t offset) \ + { \ + YR_MEMORY_BLOCK* block = iterator->first(iterator); \ + while (block != NULL) \ + { \ + if (offset >= block->base && block->size >= sizeof(type) && \ + offset <= block->base + block->size - sizeof(type)) \ + { \ + type result; \ + const uint8_t* data = block->fetch_data(block); \ + if (data == NULL) \ + return YR_UNDEFINED; \ + result = *(type*) (data + offset - block->base); \ + result = endianess##_##type(result); \ + return result; \ + } \ + block = iterator->next(iterator); \ + } \ + return YR_UNDEFINED; \ + }; + + +function_read(uint8_t, little_endian) function_read(uint16_t, little_endian) + function_read(uint32_t, little_endian) function_read(int8_t, little_endian) + function_read(int16_t, little_endian) + function_read(int32_t, little_endian) + function_read(uint8_t, big_endian) + function_read(uint16_t, big_endian) + function_read(uint32_t, big_endian) + function_read(int8_t, big_endian) + function_read(int16_t, big_endian) + function_read(int32_t, big_endian) + + + static const + uint8_t* jmp_if(int condition, const uint8_t* ip) { size_t off; @@ -192,7 +189,7 @@ static const uint8_t* jmp_if( // amount specified by the jump's offset. The offset is relative to the // jump opcode, but now the instruction pointer is pointing past the opcode // that's why we decrement the offset by 1. - off = *(int32_t*)(ip) - 1; + off = *(int32_t*) (ip) -1; } else { @@ -205,9 +202,7 @@ static const uint8_t* jmp_if( } -static int iter_array_next( - YR_ITERATOR* self, - YR_VALUE_STACK* stack) +static int iter_array_next(YR_ITERATOR* self, YR_VALUE_STACK* stack) { YR_OBJECT* obj; @@ -244,9 +239,7 @@ static int iter_array_next( } -static int iter_dict_next( - YR_ITERATOR* self, - YR_VALUE_STACK* stack) +static int iter_dict_next(YR_ITERATOR* self, YR_VALUE_STACK* stack) { YR_DICTIONARY_ITEMS* items = object_as_dictionary(self->dict_it.dict)->items; @@ -289,9 +282,7 @@ static int iter_dict_next( } -static int iter_int_range_next( - YR_ITERATOR* self, - YR_VALUE_STACK* stack) +static int iter_int_range_next(YR_ITERATOR* self, YR_VALUE_STACK* stack) { // Check that there's two available slots in the stack, one for the next // item returned by the iterator and another one for the boolean that @@ -320,9 +311,7 @@ static int iter_int_range_next( } -static int iter_int_enum_next( - YR_ITERATOR* self, - YR_VALUE_STACK* stack) +static int iter_int_enum_next(YR_ITERATOR* self, YR_VALUE_STACK* stack) { // Check that there's two available slots in the stack, one for the next // item returned by the iterator and another one for the boolean that @@ -336,7 +325,8 @@ static int iter_int_enum_next( { // Push the false value that indicates that the iterator is not exhausted. stack->items[stack->sp++].i = 0; - stack->items[stack->sp++].i = self->int_enum_it.items[self->int_enum_it.next]; + stack->items[stack->sp++].i = + self->int_enum_it.items[self->int_enum_it.next]; self->int_enum_it.next++; } else @@ -351,8 +341,7 @@ static int iter_int_enum_next( } -int yr_execute_code( - YR_SCAN_CONTEXT* context) +int yr_execute_code(YR_SCAN_CONTEXT* context) { const uint8_t* ip = context->rules->code_start; @@ -367,9 +356,9 @@ int yr_execute_code( uint64_t elapsed_time; - #ifdef YR_PROFILING_ENABLED +#ifdef YR_PROFILING_ENABLED uint64_t start_time; - #endif +#endif uint32_t current_rule_idx = 0; YR_RULE* current_rule = NULL; @@ -411,15 +400,15 @@ int yr_execute_code( yr_arena_release(obj_arena); yr_free(stack.items)); - #ifdef YR_PROFILING_ENABLED +#ifdef YR_PROFILING_ENABLED start_time = yr_stopwatch_elapsed_ns(&context->stopwatch); - #endif +#endif - #if YR_PARANOID_EXEC +#if YR_PARANOID_EXEC memset(mem, 0, MEM_SIZE * sizeof(mem[0])); - #endif +#endif - while(!stop) + while (!stop) { // Read the opcode from the address indicated by the instruction pointer. opcode = *ip; @@ -427,1286 +416,1282 @@ int yr_execute_code( // Advance the instruction pointer, which now points past the opcode. ip++; - switch(opcode) + switch (opcode) { - case OP_NOP: - break; + case OP_NOP: + break; - case OP_HALT: - assert(stack.sp == 0); // When HALT is reached the stack should be empty. - stop = true; - break; + case OP_HALT: + assert(stack.sp == 0); // When HALT is reached the stack should be empty. + stop = true; + break; - case OP_ITER_START_ARRAY: - r2.p = yr_notebook_alloc(it_notebook, sizeof(YR_ITERATOR)); + case OP_ITER_START_ARRAY: + r2.p = yr_notebook_alloc(it_notebook, sizeof(YR_ITERATOR)); - if (r2.p == NULL) - { - result = ERROR_INSUFFICIENT_MEMORY; - } - else - { - pop(r1); - r2.it->array_it.array = r1.o; - r2.it->array_it.index = 0; - r2.it->next = iter_array_next; - push(r2); - } + if (r2.p == NULL) + { + result = ERROR_INSUFFICIENT_MEMORY; + } + else + { + pop(r1); + r2.it->array_it.array = r1.o; + r2.it->array_it.index = 0; + r2.it->next = iter_array_next; + push(r2); + } - stop = (result != ERROR_SUCCESS); - break; + stop = (result != ERROR_SUCCESS); + break; - case OP_ITER_START_DICT: - r2.p = yr_notebook_alloc(it_notebook, sizeof(YR_ITERATOR)); + case OP_ITER_START_DICT: + r2.p = yr_notebook_alloc(it_notebook, sizeof(YR_ITERATOR)); - if (r2.p == NULL) - { - result = ERROR_INSUFFICIENT_MEMORY; - } - else - { - pop(r1); - r2.it->dict_it.dict = r1.o; - r2.it->dict_it.index = 0; - r2.it->next = iter_dict_next; - push(r2); - } + if (r2.p == NULL) + { + result = ERROR_INSUFFICIENT_MEMORY; + } + else + { + pop(r1); + r2.it->dict_it.dict = r1.o; + r2.it->dict_it.index = 0; + r2.it->next = iter_dict_next; + push(r2); + } - stop = (result != ERROR_SUCCESS); - break; + stop = (result != ERROR_SUCCESS); + break; - case OP_ITER_START_INT_RANGE: - // Creates an iterator for an integer range. The higher bound of the - // range is at the top of the stack followed by the lower bound. - r3.p = yr_notebook_alloc(it_notebook, sizeof(YR_ITERATOR)); + case OP_ITER_START_INT_RANGE: + // Creates an iterator for an integer range. The higher bound of the + // range is at the top of the stack followed by the lower bound. + r3.p = yr_notebook_alloc(it_notebook, sizeof(YR_ITERATOR)); - if (r3.p == NULL) - { - result = ERROR_INSUFFICIENT_MEMORY; - } - else - { - pop(r2); - pop(r1); - r3.it->int_range_it.next = r1.i; - r3.it->int_range_it.last = r2.i; - r3.it->next = iter_int_range_next; - push(r3); - } + if (r3.p == NULL) + { + result = ERROR_INSUFFICIENT_MEMORY; + } + else + { + pop(r2); + pop(r1); + r3.it->int_range_it.next = r1.i; + r3.it->int_range_it.last = r2.i; + r3.it->next = iter_int_range_next; + push(r3); + } - stop = (result != ERROR_SUCCESS); - break; + stop = (result != ERROR_SUCCESS); + break; - case OP_ITER_START_INT_ENUM: - // Creates an iterator for an integer enumeration. The number of items - // in the enumeration is at the top of the stack, followed by the - // items in reverse order. - pop(r1); + case OP_ITER_START_INT_ENUM: + // Creates an iterator for an integer enumeration. The number of items + // in the enumeration is at the top of the stack, followed by the + // items in reverse order. + pop(r1); - r3.p = yr_notebook_alloc( - it_notebook, sizeof(YR_ITERATOR) + sizeof(uint64_t) * r1.i); + r3.p = yr_notebook_alloc( + it_notebook, sizeof(YR_ITERATOR) + sizeof(uint64_t) * r1.i); + + if (r3.p == NULL) + { + result = ERROR_INSUFFICIENT_MEMORY; + } + else + { + r3.it->int_enum_it.count = r1.i; + r3.it->int_enum_it.next = 0; + r3.it->next = iter_int_enum_next; - if (r3.p == NULL) + for (i = r1.i; i > 0; i--) { - result = ERROR_INSUFFICIENT_MEMORY; + pop(r2); + r3.it->int_enum_it.items[i - 1] = r2.i; } - else - { - r3.it->int_enum_it.count = r1.i; - r3.it->int_enum_it.next = 0; - r3.it->next = iter_int_enum_next; - - for (i = r1.i; i > 0; i--) - { - pop(r2); - r3.it->int_enum_it.items[i - 1] = r2.i; - } - push(r3); - } + push(r3); + } - stop = (result != ERROR_SUCCESS); - break; + stop = (result != ERROR_SUCCESS); + break; + + case OP_ITER_NEXT: + // Loads the iterator in r1, but leaves the iterator in the stack. + pop(r1); + push(r1); + // The iterator's next function is responsible for pushing the next + // item in the stack, and a boolean indicating if there are more items + // to retrieve. The boolean will be at the top of the stack after + // calling "next". + result = r1.it->next(r1.it, &stack); + stop = (result != ERROR_SUCCESS); + break; + + case OP_PUSH: + memcpy(&r1.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); + push(r1); + break; + + case OP_PUSH_8: + r1.i = *ip; + ip += sizeof(uint8_t); + push(r1); + break; + + case OP_PUSH_16: + r1.i = *(uint16_t*) (ip); + ip += sizeof(uint16_t); + push(r1); + break; + + case OP_PUSH_32: + r1.i = *(uint32_t*) (ip); + ip += sizeof(uint32_t); + push(r1); + break; + + case OP_PUSH_U: + r1.i = YR_UNDEFINED; + push(r1); + break; + + case OP_POP: + pop(r1); + break; + + case OP_CLEAR_M: + memcpy(&r1.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); +#if YR_PARANOID_EXEC + ensure_within_mem(r1.i); +#endif + mem[r1.i].i = 0; + break; + + case OP_ADD_M: + memcpy(&r1.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); +#if YR_PARANOID_EXEC + ensure_within_mem(r1.i); +#endif + pop(r2); + if (!is_undef(r2)) + mem[r1.i].i += r2.i; + break; + + case OP_INCR_M: + memcpy(&r1.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); +#if YR_PARANOID_EXEC + ensure_within_mem(r1.i); +#endif + mem[r1.i].i++; + break; + + case OP_PUSH_M: + memcpy(&r1.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); +#if YR_PARANOID_EXEC + ensure_within_mem(r1.i); +#endif + r1 = mem[r1.i]; + push(r1); + break; + + case OP_POP_M: + memcpy(&r1.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); +#if YR_PARANOID_EXEC + ensure_within_mem(r1.i); +#endif + pop(r2); + mem[r1.i] = r2; + break; + + case OP_SET_M: + memcpy(&r1.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); +#if YR_PARANOID_EXEC + ensure_within_mem(r1.i); +#endif + pop(r2); + push(r2); + if (!is_undef(r2)) + mem[r1.i] = r2; + break; - case OP_ITER_NEXT: - // Loads the iterator in r1, but leaves the iterator in the stack. - pop(r1); - push(r1); - // The iterator's next function is responsible for pushing the next - // item in the stack, and a boolean indicating if there are more items - // to retrieve. The boolean will be at the top of the stack after - // calling "next". - result = r1.it->next(r1.it, &stack); - stop = (result != ERROR_SUCCESS); - break; + case OP_SWAPUNDEF: + memcpy(&r1.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); +#if YR_PARANOID_EXEC + ensure_within_mem(r1.i); +#endif + pop(r2); - case OP_PUSH: - memcpy(&r1.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); + if (is_undef(r2)) + { + r1 = mem[r1.i]; push(r1); - break; - - case OP_PUSH_8: - r1.i = *ip; - ip += sizeof(uint8_t); + } + else + { + push(r2); + } + break; + + case OP_JNUNDEF: + pop(r1); + push(r1); + ip = jmp_if(!is_undef(r1), ip); + break; + + case OP_JUNDEF_P: + pop(r1); + ip = jmp_if(is_undef(r1), ip); + break; + + case OP_JL_P: + pop(r2); + pop(r1); + ip = jmp_if(r1.i < r2.i, ip); + break; + + case OP_JLE_P: + pop(r2); + pop(r1); + ip = jmp_if(r1.i <= r2.i, ip); + break; + + case OP_JTRUE: + pop(r1); + push(r1); + ip = jmp_if(!is_undef(r1) && r1.i, ip); + break; + + case OP_JTRUE_P: + pop(r1); + ip = jmp_if(!is_undef(r1) && r1.i, ip); + break; + + case OP_JFALSE: + pop(r1); + push(r1); + ip = jmp_if(is_undef(r1) || !r1.i, ip); + break; + + case OP_JFALSE_P: + pop(r1); + ip = jmp_if(is_undef(r1) || !r1.i, ip); + break; + + case OP_JZ: + pop(r1); + push(r1); + ip = jmp_if(r1.i == 0, ip); + break; + + case OP_JZ_P: + pop(r1); + ip = jmp_if(r1.i == 0, ip); + break; + + case OP_AND: + pop(r2); + pop(r1); + + if (is_undef(r1) || is_undef(r2)) + r1.i = 0; + else + r1.i = r1.i && r2.i; + + push(r1); + break; + + case OP_OR: + pop(r2); + pop(r1); + + if (is_undef(r1)) + { + push(r2); + } + else if (is_undef(r2)) + { push(r1); - break; - - case OP_PUSH_16: - r1.i = *(uint16_t*)(ip); - ip += sizeof(uint16_t); + } + else + { + r1.i = r1.i || r2.i; push(r1); - break; + } + break; - case OP_PUSH_32: - r1.i = *(uint32_t*)(ip); - ip += sizeof(uint32_t); - push(r1); - break; + case OP_NOT: + pop(r1); - case OP_PUSH_U: + if (is_undef(r1)) r1.i = YR_UNDEFINED; - push(r1); - break; - - case OP_POP: - pop(r1); - break; + else + r1.i = !r1.i; + + push(r1); + break; + + case OP_MOD: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + if (r2.i != 0) + r1.i = r1.i % r2.i; + else + r1.i = YR_UNDEFINED; + push(r1); + break; + + case OP_SHR: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + if (r2.i < 0) + r1.i = YR_UNDEFINED; + else if (r2.i < 64) + r1.i = r1.i >> r2.i; + else + r1.i = 0; + push(r1); + break; + + case OP_SHL: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + if (r2.i < 0) + r1.i = YR_UNDEFINED; + else if (r2.i < 64) + r1.i = r1.i << r2.i; + else + r1.i = 0; + push(r1); + break; + + case OP_BITWISE_NOT: + pop(r1); + ensure_defined(r1); + r1.i = ~r1.i; + push(r1); + break; + + case OP_BITWISE_AND: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + r1.i = r1.i & r2.i; + push(r1); + break; + + case OP_BITWISE_OR: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + r1.i = r1.i | r2.i; + push(r1); + break; + + case OP_BITWISE_XOR: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + r1.i = r1.i ^ r2.i; + push(r1); + break; + + case OP_PUSH_RULE: + memcpy(&r1.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); + + rule = &context->rules->rules_list_head[r1.i]; + + if (RULE_IS_DISABLED(rule)) + { + r2.i = YR_UNDEFINED; + } + else + { + if yr_bitmask_is_set (context->rule_matches_flags, r1.i) + r2.i = 1; + else + r2.i = 0; + } - case OP_CLEAR_M: - memcpy(&r1.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); - #if YR_PARANOID_EXEC - ensure_within_mem(r1.i); - #endif - mem[r1.i].i = 0; - break; + push(r2); + break; - case OP_ADD_M: - memcpy(&r1.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); - #if YR_PARANOID_EXEC - ensure_within_mem(r1.i); - #endif - pop(r2); - if (!is_undef(r2)) - mem[r1.i].i += r2.i; - break; + case OP_INIT_RULE: + // After the opcode there's an int32_t corresponding to the jump's + // offset and an uint32_t corresponding to the rule's index. + current_rule_idx = *(uint32_t*) (ip + sizeof(int32_t)); - case OP_INCR_M: - memcpy(&r1.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); - #if YR_PARANOID_EXEC - ensure_within_mem(r1.i); - #endif - mem[r1.i].i++; - break; + assert(current_rule_idx < context->rules->num_rules); - case OP_PUSH_M: - memcpy(&r1.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); - #if YR_PARANOID_EXEC - ensure_within_mem(r1.i); - #endif - r1 = mem[r1.i]; - push(r1); - break; + current_rule = &context->rules->rules_list_head[current_rule_idx]; - case OP_POP_M: - memcpy(&r1.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); - #if YR_PARANOID_EXEC - ensure_within_mem(r1.i); - #endif - pop(r2); - mem[r1.i] = r2; - break; + // If the rule is disabled let's skip its code. + ip = jmp_if(RULE_IS_DISABLED(current_rule), ip); - case OP_SET_M: - memcpy(&r1.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); - #if YR_PARANOID_EXEC - ensure_within_mem(r1.i); - #endif - pop(r2); - push(r2); - if (!is_undef(r2)) - mem[r1.i] = r2; - break; + // Skip the bytes corresponding to the rule's index, but only if not + // taking the jump. + if (!RULE_IS_DISABLED(current_rule)) + ip += sizeof(uint32_t); - case OP_SWAPUNDEF: - memcpy(&r1.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); - #if YR_PARANOID_EXEC - ensure_within_mem(r1.i); - #endif - pop(r2); + break; - if (is_undef(r2)) - { - r1 = mem[r1.i]; - push(r1); - } - else - { - push(r2); - } - break; + case OP_MATCH_RULE: + pop(r1); - case OP_JNUNDEF: - pop(r1); - push(r1); - ip = jmp_if(!is_undef(r1), ip); - break; + memcpy(&r2.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); - case OP_JUNDEF_P: - pop(r1); - ip = jmp_if(is_undef(r1), ip); - break; + rule = &context->rules->rules_list_head[r2.i]; - case OP_JL_P: - pop(r2); - pop(r1); - ip = jmp_if(r1.i < r2.i, ip); - break; +#if YR_PARANOID_EXEC + ensure_within_rules_arena(rule); +#endif - case OP_JLE_P: - pop(r2); - pop(r1); - ip = jmp_if(r1.i <= r2.i, ip); - break; + if (!is_undef(r1) && r1.i) + yr_bitmask_set(context->rule_matches_flags, r2.i); + else if (RULE_IS_GLOBAL(rule)) + yr_bitmask_set(context->ns_unsatisfied_flags, rule->ns->idx); - case OP_JTRUE: - pop(r1); - push(r1); - ip = jmp_if(!is_undef(r1) && r1.i, ip); - break; +#ifdef YR_PROFILING_ENABLED + elapsed_time = yr_stopwatch_elapsed_ns(&context->stopwatch); + context->profiling_info[r2.i].exec_time += (elapsed_time - start_time); + start_time = elapsed_time; +#endif - case OP_JTRUE_P: - pop(r1); - ip = jmp_if(!is_undef(r1) && r1.i, ip); - break; + assert(stack.sp == 0); // at this point the stack should be empty. + break; - case OP_JFALSE: - pop(r1); - push(r1); - ip = jmp_if(is_undef(r1) || !r1.i, ip); - break; + case OP_OBJ_LOAD: + identifier = *(char**) (ip); + ip += sizeof(uint64_t); - case OP_JFALSE_P: - pop(r1); - ip = jmp_if(is_undef(r1) || !r1.i, ip); - break; +#if YR_PARANOID_EXEC + ensure_within_rules_arena(identifier); +#endif - case OP_JZ: - pop(r1); - push(r1); - ip = jmp_if(r1.i == 0, ip); - break; + r1.o = (YR_OBJECT*) yr_hash_table_lookup( + context->objects_table, identifier, NULL); - case OP_JZ_P: - pop(r1); - ip = jmp_if(r1.i == 0, ip); - break; + assert(r1.o != NULL); + push(r1); + break; - case OP_AND: - pop(r2); - pop(r1); + case OP_OBJ_FIELD: + identifier = *(char**) (ip); + ip += sizeof(uint64_t); - if (is_undef(r1) || is_undef(r2)) - r1.i = 0; - else - r1.i = r1.i && r2.i; +#if YR_PARANOID_EXEC + ensure_within_rules_arena(identifier); +#endif - push(r1); - break; + pop(r1); + ensure_defined(r1); - case OP_OR: - pop(r2); - pop(r1); + r1.o = yr_object_lookup_field(r1.o, identifier); - if (is_undef(r1)) - { - push(r2); - } - else if (is_undef(r2)) - { - push(r1); - } - else - { - r1.i = r1.i || r2.i; - push(r1); - } + if (r1.o == NULL) + { + result = ERROR_INVALID_FIELD_NAME; + stop = true; break; + } - case OP_NOT: - pop(r1); + push(r1); + break; - if (is_undef(r1)) - r1.i = YR_UNDEFINED; - else - r1.i = !r1.i; + case OP_OBJ_VALUE: + pop(r1); + ensure_defined(r1); - push(r1); - break; +#if YR_PARANOID_EXEC + check_object_canary(r1.o); +#endif - case OP_MOD: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - if (r2.i != 0) - r1.i = r1.i % r2.i; - else - r1.i = YR_UNDEFINED; - push(r1); + switch (r1.o->type) + { + case OBJECT_TYPE_INTEGER: + r1.i = r1.o->value.i; break; - case OP_SHR: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - if (r2.i < 0) + case OBJECT_TYPE_FLOAT: + if (isnan(r1.o->value.d)) r1.i = YR_UNDEFINED; - else if (r2.i < 64) - r1.i = r1.i >> r2.i; else - r1.i = 0; - push(r1); + r1.d = r1.o->value.d; break; - case OP_SHL: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - if (r2.i < 0) + case OBJECT_TYPE_STRING: + if (r1.o->value.ss == NULL) r1.i = YR_UNDEFINED; - else if (r2.i < 64) - r1.i = r1.i << r2.i; else - r1.i = 0; - push(r1); - break; - - case OP_BITWISE_NOT: - pop(r1); - ensure_defined(r1); - r1.i = ~r1.i; - push(r1); - break; - - case OP_BITWISE_AND: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - r1.i = r1.i & r2.i; - push(r1); + r1.ss = r1.o->value.ss; break; - case OP_BITWISE_OR: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - r1.i = r1.i | r2.i; - push(r1); - break; + default: + assert(false); + } - case OP_BITWISE_XOR: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - r1.i = r1.i ^ r2.i; - push(r1); - break; + push(r1); + break; - case OP_PUSH_RULE: - memcpy(&r1.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); + case OP_INDEX_ARRAY: + pop(r1); // index + pop(r2); // array - rule = &context->rules->rules_list_head[r1.i]; + ensure_defined(r1); + ensure_defined(r2); - if (RULE_IS_DISABLED(rule)) - { - r2.i = YR_UNDEFINED; - } - else - { - if yr_bitmask_is_set(context->rule_matches_flags, r1.i) - r2.i = 1; - else - r2.i = 0; - } + assert(r2.o->type == OBJECT_TYPE_ARRAY); - push(r2); - break; +#if YR_PARANOID_EXEC + check_object_canary(r2.o); +#endif - case OP_INIT_RULE: - // After the opcode there's an int32_t corresponding to the jump's - // offset and an uint32_t corresponding to the rule's index. - current_rule_idx = *(uint32_t*)(ip + sizeof(int32_t)); + r1.o = yr_object_array_get_item(r2.o, 0, (int) r1.i); - assert(current_rule_idx < context->rules->num_rules); + if (r1.o == NULL) + r1.i = YR_UNDEFINED; - current_rule = &context->rules->rules_list_head[current_rule_idx]; + push(r1); + break; - // If the rule is disabled let's skip its code. - ip = jmp_if(RULE_IS_DISABLED(current_rule), ip); + case OP_LOOKUP_DICT: + pop(r1); // key + pop(r2); // dictionary - // Skip the bytes corresponding to the rule's index, but only if not - // taking the jump. - if (!RULE_IS_DISABLED(current_rule)) - ip += sizeof(uint32_t); + ensure_defined(r1); + ensure_defined(r2); - break; + assert(r2.o->type == OBJECT_TYPE_DICTIONARY); - case OP_MATCH_RULE: - pop(r1); +#if YR_PARANOID_EXEC + check_object_canary(r2.o); +#endif - memcpy(&r2.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); + r1.o = yr_object_dict_get_item(r2.o, 0, r1.ss->c_string); - rule = &context->rules->rules_list_head[r2.i]; + if (r1.o == NULL) + r1.i = YR_UNDEFINED; - #if YR_PARANOID_EXEC - ensure_within_rules_arena(rule); - #endif + push(r1); + break; - if (!is_undef(r1) && r1.i) - yr_bitmask_set(context->rule_matches_flags, r2.i); - else if (RULE_IS_GLOBAL(rule)) - yr_bitmask_set(context->ns_unsatisfied_flags, rule->ns->idx); + case OP_CALL: + args_fmt = *(char**) (ip); + ip += sizeof(uint64_t); - #ifdef YR_PROFILING_ENABLED - elapsed_time = yr_stopwatch_elapsed_ns(&context->stopwatch); - context->profiling_info[r2.i].exec_time += (elapsed_time - start_time); - start_time = elapsed_time; - #endif + i = (int) strlen(args_fmt); + count = 0; - assert(stack.sp == 0); // at this point the stack should be empty. +#if YR_PARANOID_EXEC + if (i > YR_MAX_FUNCTION_ARGS) + { + stop = true; + result = ERROR_INTERNAL_FATAL_ERROR; break; + } +#endif - case OP_OBJ_LOAD: - identifier = *(char**)(ip); - ip += sizeof(uint64_t); + // pop arguments from stack and copy them to args array - #if YR_PARANOID_EXEC - ensure_within_rules_arena(identifier); - #endif - - r1.o = (YR_OBJECT*) yr_hash_table_lookup( - context->objects_table, - identifier, - NULL); - - assert(r1.o != NULL); - push(r1); - break; - - case OP_OBJ_FIELD: - identifier = *(char**)(ip); - ip += sizeof(uint64_t); - - #if YR_PARANOID_EXEC - ensure_within_rules_arena(identifier); - #endif - - pop(r1); - ensure_defined(r1); - - r1.o = yr_object_lookup_field(r1.o, identifier); - - if (r1.o == NULL) - { - result = ERROR_INVALID_FIELD_NAME; - stop = true; - break; - } - - push(r1); - break; - - case OP_OBJ_VALUE: + while (i > 0) + { pop(r1); - ensure_defined(r1); - - #if YR_PARANOID_EXEC - check_object_canary(r1.o); - #endif - - switch(r1.o->type) - { - case OBJECT_TYPE_INTEGER: - r1.i = r1.o->value.i; - break; - - case OBJECT_TYPE_FLOAT: - if (isnan(r1.o->value.d)) - r1.i = YR_UNDEFINED; - else - r1.d = r1.o->value.d; - break; - - case OBJECT_TYPE_STRING: - if (r1.o->value.ss == NULL) - r1.i = YR_UNDEFINED; - else - r1.ss = r1.o->value.ss; - break; - - default: - assert(false); - } - - push(r1); - break; - - case OP_INDEX_ARRAY: - pop(r1); // index - pop(r2); // array - - ensure_defined(r1); - ensure_defined(r2); - - assert(r2.o->type == OBJECT_TYPE_ARRAY); - - #if YR_PARANOID_EXEC - check_object_canary(r2.o); - #endif - - r1.o = yr_object_array_get_item(r2.o, 0, (int) r1.i); - - if (r1.o == NULL) - r1.i = YR_UNDEFINED; - - push(r1); - break; - case OP_LOOKUP_DICT: - pop(r1); // key - pop(r2); // dictionary - - ensure_defined(r1); - ensure_defined(r2); + if (is_undef(r1)) // count the number of undefined args + count++; - assert(r2.o->type == OBJECT_TYPE_DICTIONARY); + args[i - 1] = r1; + i--; + } - #if YR_PARANOID_EXEC - check_object_canary(r2.o); - #endif + pop(r2); + ensure_defined(r2); - r1.o = yr_object_dict_get_item( - r2.o, 0, r1.ss->c_string); +#if YR_PARANOID_EXEC + check_object_canary(r2.o); +#endif - if (r1.o == NULL) - r1.i = YR_UNDEFINED; + if (count > 0) + { + // If there are undefined args, result for function call + // is undefined as well. + r1.i = YR_UNDEFINED; push(r1); break; + } - case OP_CALL: - args_fmt = *(char**)(ip); - ip += sizeof(uint64_t); - - i = (int) strlen(args_fmt); - count = 0; + function = object_as_function(r2.o); + result = ERROR_INTERNAL_FATAL_ERROR; - #if YR_PARANOID_EXEC - if (i > YR_MAX_FUNCTION_ARGS) - { - stop = true; - result = ERROR_INTERNAL_FATAL_ERROR; + for (i = 0; i < YR_MAX_OVERLOADED_FUNCTIONS; i++) + { + if (function->prototypes[i].arguments_fmt == NULL) break; - } - #endif - - // pop arguments from stack and copy them to args array - - while (i > 0) - { - pop(r1); - - if (is_undef(r1)) // count the number of undefined args - count++; - - args[i - 1] = r1; - i--; - } - - pop(r2); - ensure_defined(r2); - #if YR_PARANOID_EXEC - check_object_canary(r2.o); - #endif - - if (count > 0) + if (strcmp(function->prototypes[i].arguments_fmt, args_fmt) == 0) { - // If there are undefined args, result for function call - // is undefined as well. - - r1.i = YR_UNDEFINED; - push(r1); + result = function->prototypes[i].code(args, context, function); break; } + } - function = object_as_function(r2.o); - result = ERROR_INTERNAL_FATAL_ERROR; + // If i == YR_MAX_OVERLOADED_FUNCTIONS at this point no matching + // prototype was found, but this shouldn't happen. + assert(i < YR_MAX_OVERLOADED_FUNCTIONS); - for (i = 0; i < YR_MAX_OVERLOADED_FUNCTIONS; i++) - { - if (function->prototypes[i].arguments_fmt == NULL) - break; - - if (strcmp(function->prototypes[i].arguments_fmt, args_fmt) == 0) - { - result = function->prototypes[i].code(args, context, function); - break; - } - } + // Make a copy of the returned object and push the copy into the stack, + // function->return_obj can't be pushed because it can change in + // subsequent calls to the same function. + if (result == ERROR_SUCCESS) + result = yr_object_copy(function->return_obj, &r1.o); - // If i == YR_MAX_OVERLOADED_FUNCTIONS at this point no matching - // prototype was found, but this shouldn't happen. - assert(i < YR_MAX_OVERLOADED_FUNCTIONS); + // A pointer to the copied object is stored in a arena in order to + // free the object before exiting yr_execute_code, obj_count tracks + // the number of objects written. + if (result == ERROR_SUCCESS) + { + result = yr_arena_write_data(obj_arena, 0, &r1.o, sizeof(r1.o), NULL); + obj_count++; + } - // Make a copy of the returned object and push the copy into the stack, - // function->return_obj can't be pushed because it can change in - // subsequent calls to the same function. - if (result == ERROR_SUCCESS) - result = yr_object_copy(function->return_obj, &r1.o); + stop = (result != ERROR_SUCCESS); + push(r1); + break; - // A pointer to the copied object is stored in a arena in order to - // free the object before exiting yr_execute_code, obj_count tracks - // the number of objects written. - if (result == ERROR_SUCCESS) - { - result = yr_arena_write_data( - obj_arena, 0, &r1.o, sizeof(r1.o), NULL); - obj_count++; - } + case OP_FOUND: + pop(r1); + r2.i = context->matches[r1.s->idx].tail != NULL ? 1 : 0; + push(r2); + break; + + case OP_FOUND_AT: + pop(r2); + pop(r1); - stop = (result != ERROR_SUCCESS); + if (is_undef(r1)) + { + r1.i = 0; push(r1); break; + } - case OP_FOUND: - pop(r1); - r2.i = context->matches[r1.s->idx].tail != NULL ? 1 : 0; - push(r2); - break; +#if YR_PARANOID_EXEC + ensure_within_rules_arena(r2.p); +#endif - case OP_FOUND_AT: - pop(r2); - pop(r1); + match = context->matches[r2.s->idx].head; + r3.i = false; - if (is_undef(r1)) + while (match != NULL) + { + if (r1.i == match->base + match->offset) { - r1.i = 0; - push(r1); + r3.i = true; break; } - #if YR_PARANOID_EXEC - ensure_within_rules_arena(r2.p); - #endif - - match = context->matches[r2.s->idx].head; - r3.i = false; - - while (match != NULL) - { - if (r1.i == match->base + match->offset) - { - r3.i = true; - break; - } - - if (r1.i < match->base + match->offset) - break; + if (r1.i < match->base + match->offset) + break; - match = match->next; - } + match = match->next; + } - push(r3); - break; + push(r3); + break; - case OP_FOUND_IN: - pop(r3); - pop(r2); - pop(r1); + case OP_FOUND_IN: + pop(r3); + pop(r2); + pop(r1); - ensure_defined(r1); - ensure_defined(r2); + ensure_defined(r1); + ensure_defined(r2); - #if YR_PARANOID_EXEC - ensure_within_rules_arena(r3.p); - #endif +#if YR_PARANOID_EXEC + ensure_within_rules_arena(r3.p); +#endif - match = context->matches[r3.s->idx].head; - r4.i = false; + match = context->matches[r3.s->idx].head; + r4.i = false; - while (match != NULL && !r4.i) + while (match != NULL && !r4.i) + { + if (match->base + match->offset >= r1.i && + match->base + match->offset <= r2.i) { - if (match->base + match->offset >= r1.i && - match->base + match->offset <= r2.i) - { - r4.i = true; - } + r4.i = true; + } - if (match->base + match->offset > r2.i) - break; + if (match->base + match->offset > r2.i) + break; - match = match->next; - } + match = match->next; + } - push(r4); - break; + push(r4); + break; - case OP_COUNT: - pop(r1); + case OP_COUNT: + pop(r1); - #if YR_PARANOID_EXEC - ensure_within_rules_arena(r1.p); - #endif +#if YR_PARANOID_EXEC + ensure_within_rules_arena(r1.p); +#endif - r2.i = context->matches[r1.s->idx].count; - push(r2); - break; + r2.i = context->matches[r1.s->idx].count; + push(r2); + break; - case OP_OFFSET: - pop(r2); - pop(r1); + case OP_OFFSET: + pop(r2); + pop(r1); - ensure_defined(r1); + ensure_defined(r1); - #if YR_PARANOID_EXEC - ensure_within_rules_arena(r2.p); - #endif +#if YR_PARANOID_EXEC + ensure_within_rules_arena(r2.p); +#endif - match = context->matches[r2.s->idx].head; + match = context->matches[r2.s->idx].head; - i = 1; - r3.i = YR_UNDEFINED; + i = 1; + r3.i = YR_UNDEFINED; - while (match != NULL && r3.i == YR_UNDEFINED) - { - if (r1.i == i) - r3.i = match->base + match->offset; + while (match != NULL && r3.i == YR_UNDEFINED) + { + if (r1.i == i) + r3.i = match->base + match->offset; - i++; - match = match->next; - } + i++; + match = match->next; + } - push(r3); - break; + push(r3); + break; - case OP_LENGTH: - pop(r2); - pop(r1); + case OP_LENGTH: + pop(r2); + pop(r1); - ensure_defined(r1); + ensure_defined(r1); - #if YR_PARANOID_EXEC - ensure_within_rules_arena(r2.p); - #endif +#if YR_PARANOID_EXEC + ensure_within_rules_arena(r2.p); +#endif - match = context->matches[r2.s->idx].head; + match = context->matches[r2.s->idx].head; - i = 1; - r3.i = YR_UNDEFINED; + i = 1; + r3.i = YR_UNDEFINED; - while (match != NULL && r3.i == YR_UNDEFINED) - { - if (r1.i == i) - r3.i = match->match_length; + while (match != NULL && r3.i == YR_UNDEFINED) + { + if (r1.i == i) + r3.i = match->match_length; - i++; - match = match->next; - } + i++; + match = match->next; + } - push(r3); - break; + push(r3); + break; - case OP_OF: - found = 0; - count = 0; - pop(r1); + case OP_OF: + found = 0; + count = 0; + pop(r1); - while (!is_undef(r1)) + while (!is_undef(r1)) + { + if (context->matches[r1.s->idx].tail != NULL) { - if (context->matches[r1.s->idx].tail != NULL) - { - found++; - } - count++; - pop(r1); + found++; } - - pop(r2); - - if (is_undef(r2)) - r1.i = found >= count ? 1 : 0; - else - r1.i = found >= r2.i ? 1 : 0; - - push(r1); - break; - - case OP_FILESIZE: - r1.i = context->file_size; - push(r1); - break; - - case OP_ENTRYPOINT: - r1.i = context->entry_point; - push(r1); - break; - - case OP_INT8: - pop(r1); - r1.i = read_int8_t_little_endian(context->iterator, (size_t) r1.i); - push(r1); - break; - - case OP_INT16: + count++; pop(r1); - r1.i = read_int16_t_little_endian(context->iterator, (size_t) r1.i); - push(r1); - break; - - case OP_INT32: - pop(r1); - r1.i = read_int32_t_little_endian(context->iterator, (size_t) r1.i); - push(r1); - break; - - case OP_UINT8: - pop(r1); - r1.i = read_uint8_t_little_endian(context->iterator, (size_t) r1.i); - push(r1); - break; - - case OP_UINT16: - pop(r1); - r1.i = read_uint16_t_little_endian(context->iterator, (size_t) r1.i); - push(r1); - break; + } - case OP_UINT32: - pop(r1); - r1.i = read_uint32_t_little_endian(context->iterator, (size_t) r1.i); - push(r1); - break; + pop(r2); + + if (is_undef(r2)) + r1.i = found >= count ? 1 : 0; + else + r1.i = found >= r2.i ? 1 : 0; + + push(r1); + break; + + case OP_FILESIZE: + r1.i = context->file_size; + push(r1); + break; + + case OP_ENTRYPOINT: + r1.i = context->entry_point; + push(r1); + break; + + case OP_INT8: + pop(r1); + r1.i = read_int8_t_little_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_INT16: + pop(r1); + r1.i = read_int16_t_little_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_INT32: + pop(r1); + r1.i = read_int32_t_little_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_UINT8: + pop(r1); + r1.i = read_uint8_t_little_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_UINT16: + pop(r1); + r1.i = read_uint16_t_little_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_UINT32: + pop(r1); + r1.i = read_uint32_t_little_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_INT8BE: + pop(r1); + r1.i = read_int8_t_big_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_INT16BE: + pop(r1); + r1.i = read_int16_t_big_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_INT32BE: + pop(r1); + r1.i = read_int32_t_big_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_UINT8BE: + pop(r1); + r1.i = read_uint8_t_big_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_UINT16BE: + pop(r1); + r1.i = read_uint16_t_big_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_UINT32BE: + pop(r1); + r1.i = read_uint32_t_big_endian(context->iterator, (size_t) r1.i); + push(r1); + break; + + case OP_IMPORT: + memcpy(&r1.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); + +#if YR_PARANOID_EXEC + ensure_within_rules_arena(r1.p); +#endif - case OP_INT8BE: - pop(r1); - r1.i = read_int8_t_big_endian(context->iterator, (size_t) r1.i); - push(r1); - break; + result = yr_modules_load((char*) r1.p, context); - case OP_INT16BE: - pop(r1); - r1.i = read_int16_t_big_endian(context->iterator, (size_t) r1.i); - push(r1); - break; - - case OP_INT32BE: - pop(r1); - r1.i = read_int32_t_big_endian(context->iterator, (size_t) r1.i); - push(r1); - break; + if (result != ERROR_SUCCESS) + stop = true; - case OP_UINT8BE: - pop(r1); - r1.i = read_uint8_t_big_endian(context->iterator, (size_t) r1.i); - push(r1); - break; + break; - case OP_UINT16BE: - pop(r1); - r1.i = read_uint16_t_big_endian(context->iterator, (size_t) r1.i); - push(r1); - break; + case OP_MATCHES: + pop(r2); + pop(r1); - case OP_UINT32BE: - pop(r1); - r1.i = read_uint32_t_big_endian(context->iterator, (size_t) r1.i); + if (is_undef(r1) || is_undef(r2) || r1.ss->length == 0) + { + r1.i = false; push(r1); break; + } - case OP_IMPORT: - memcpy(&r1.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); - - #if YR_PARANOID_EXEC - ensure_within_rules_arena(r1.p); - #endif + result = yr_re_exec( + context, + (uint8_t*) r2.re->code, + (uint8_t*) r1.ss->c_string, + r1.ss->length, + 0, + r2.re->flags | RE_FLAGS_SCAN, + NULL, + NULL, + &found); + + if (result != ERROR_SUCCESS) + stop = true; - result = yr_modules_load((char*) r1.p, context); + r1.i = found >= 0; + push(r1); + break; - if (result != ERROR_SUCCESS) - stop = true; + case OP_INT_TO_DBL: + memcpy(&r1.i, ip, sizeof(uint64_t)); + ip += sizeof(uint64_t); +#if YR_PARANOID_EXEC + if (r1.i > stack.sp || stack.sp - r1.i >= stack.capacity) + { + stop = true; + result = ERROR_INTERNAL_FATAL_ERROR; break; + } +#endif - case OP_MATCHES: - pop(r2); - pop(r1); - - if (is_undef(r1) || is_undef(r2) || r1.ss->length == 0) + r2 = stack.items[stack.sp - r1.i]; + + if (is_undef(r2)) + stack.items[stack.sp - r1.i].i = YR_UNDEFINED; + else + stack.items[stack.sp - r1.i].d = (double) r2.i; + break; + + case OP_STR_TO_BOOL: + pop(r1); + ensure_defined(r1); + r1.i = r1.ss->length > 0; + push(r1); + break; + + case OP_INT_EQ: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = r1.i == r2.i; + push(r1); + break; + + case OP_INT_NEQ: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = r1.i != r2.i; + push(r1); + break; + + case OP_INT_LT: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = r1.i < r2.i; + push(r1); + break; + + case OP_INT_GT: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = r1.i > r2.i; + push(r1); + break; + + case OP_INT_LE: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = r1.i <= r2.i; + push(r1); + break; + + case OP_INT_GE: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = r1.i >= r2.i; + push(r1); + break; + + case OP_INT_ADD: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + r1.i = r1.i + r2.i; + push(r1); + break; + + case OP_INT_SUB: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + r1.i = r1.i - r2.i; + push(r1); + break; + + case OP_INT_MUL: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + r1.i = r1.i * r2.i; + push(r1); + break; + + case OP_INT_DIV: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + if (r2.i != 0) + r1.i = r1.i / r2.i; + else + r1.i = YR_UNDEFINED; + push(r1); + break; + + case OP_INT_MINUS: + pop(r1); + ensure_defined(r1); + r1.i = -r1.i; + push(r1); + break; + + case OP_DBL_LT: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = r1.d < r2.d; + push(r1); + break; + + case OP_DBL_GT: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = r1.d > r2.d; + push(r1); + break; + + case OP_DBL_LE: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = r1.d <= r2.d; + push(r1); + break; + + case OP_DBL_GE: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = r1.d >= r2.d; + push(r1); + break; + + case OP_DBL_EQ: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = fabs(r1.d - r2.d) < DBL_EPSILON; + push(r1); + break; + + case OP_DBL_NEQ: + pop(r2); + pop(r1); + if (is_undef(r1) || is_undef(r2)) + r1.i = false; + else + r1.i = fabs(r1.d - r2.d) >= DBL_EPSILON; + push(r1); + break; + + case OP_DBL_ADD: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + r1.d = r1.d + r2.d; + push(r1); + break; + + case OP_DBL_SUB: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + r1.d = r1.d - r2.d; + push(r1); + break; + + case OP_DBL_MUL: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + r1.d = r1.d * r2.d; + push(r1); + break; + + case OP_DBL_DIV: + pop(r2); + pop(r1); + ensure_defined(r2); + ensure_defined(r1); + r1.d = r1.d / r2.d; + push(r1); + break; + + case OP_DBL_MINUS: + pop(r1); + ensure_defined(r1); + r1.d = -r1.d; + push(r1); + break; + + case OP_STR_EQ: + case OP_STR_NEQ: + case OP_STR_LT: + case OP_STR_LE: + case OP_STR_GT: + case OP_STR_GE: + + pop(r2); + pop(r1); + + if (is_undef(r1) || is_undef(r2)) + { + r1.i = false; + } + else + { + switch (opcode) { - r1.i = false; - push(r1); + case OP_STR_EQ: + r1.i = (ss_compare(r1.ss, r2.ss) == 0); break; - } - - result = yr_re_exec( - context, - (uint8_t*) r2.re->code, - (uint8_t*) r1.ss->c_string, - r1.ss->length, - 0, - r2.re->flags | RE_FLAGS_SCAN, - NULL, - NULL, - &found); - - if (result != ERROR_SUCCESS) - stop = true; - - r1.i = found >= 0; - push(r1); - break; - - case OP_INT_TO_DBL: - memcpy(&r1.i, ip, sizeof(uint64_t)); - ip += sizeof(uint64_t); - - #if YR_PARANOID_EXEC - if (r1.i > stack.sp || stack.sp - r1.i >= stack.capacity) - { - stop = true; - result = ERROR_INTERNAL_FATAL_ERROR; + case OP_STR_NEQ: + r1.i = (ss_compare(r1.ss, r2.ss) != 0); + break; + case OP_STR_LT: + r1.i = (ss_compare(r1.ss, r2.ss) < 0); + break; + case OP_STR_LE: + r1.i = (ss_compare(r1.ss, r2.ss) <= 0); + break; + case OP_STR_GT: + r1.i = (ss_compare(r1.ss, r2.ss) > 0); + break; + case OP_STR_GE: + r1.i = (ss_compare(r1.ss, r2.ss) >= 0); break; } - #endif - - r2 = stack.items[stack.sp - r1.i]; - - if (is_undef(r2)) - stack.items[stack.sp - r1.i].i = YR_UNDEFINED; - else - stack.items[stack.sp - r1.i].d = (double) r2.i; - break; - - case OP_STR_TO_BOOL: - pop(r1); - ensure_defined(r1); - r1.i = r1.ss->length > 0; - push(r1); - break; - - case OP_INT_EQ: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = r1.i == r2.i; - push(r1); - break; - - case OP_INT_NEQ: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = r1.i != r2.i; - push(r1); - break; - - case OP_INT_LT: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = r1.i < r2.i; - push(r1); - break; - - case OP_INT_GT: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = r1.i > r2.i; - push(r1); - break; - - case OP_INT_LE: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = r1.i <= r2.i; - push(r1); - break; - - case OP_INT_GE: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = r1.i >= r2.i; - push(r1); - break; - - case OP_INT_ADD: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - r1.i = r1.i + r2.i; - push(r1); - break; - - case OP_INT_SUB: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - r1.i = r1.i - r2.i; - push(r1); - break; - - case OP_INT_MUL: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - r1.i = r1.i * r2.i; - push(r1); - break; - - case OP_INT_DIV: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - if (r2.i != 0) - r1.i = r1.i / r2.i; - else - r1.i = YR_UNDEFINED; - push(r1); - break; - - case OP_INT_MINUS: - pop(r1); - ensure_defined(r1); - r1.i = -r1.i; - push(r1); - break; - - case OP_DBL_LT: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = r1.d < r2.d; - push(r1); - break; - - case OP_DBL_GT: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = r1.d > r2.d; - push(r1); - break; - - case OP_DBL_LE: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = r1.d <= r2.d; - push(r1); - break; - - case OP_DBL_GE: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = r1.d >= r2.d; - push(r1); - break; - - case OP_DBL_EQ: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = fabs(r1.d - r2.d) < DBL_EPSILON; - push(r1); - break; - - case OP_DBL_NEQ: - pop(r2); - pop(r1); - if (is_undef(r1) || is_undef(r2)) - r1.i = false; - else - r1.i = fabs(r1.d - r2.d) >= DBL_EPSILON; - push(r1); - break; - - case OP_DBL_ADD: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - r1.d = r1.d + r2.d; - push(r1); - break; - - case OP_DBL_SUB: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - r1.d = r1.d - r2.d; - push(r1); - break; - - case OP_DBL_MUL: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - r1.d = r1.d * r2.d; - push(r1); - break; - - case OP_DBL_DIV: - pop(r2); - pop(r1); - ensure_defined(r2); - ensure_defined(r1); - r1.d = r1.d / r2.d; - push(r1); - break; - - case OP_DBL_MINUS: - pop(r1); - ensure_defined(r1); - r1.d = -r1.d; - push(r1); - break; - - case OP_STR_EQ: - case OP_STR_NEQ: - case OP_STR_LT: - case OP_STR_LE: - case OP_STR_GT: - case OP_STR_GE: - - pop(r2); - pop(r1); - - if (is_undef(r1) || is_undef(r2)) - { - r1.i = false; - } - else - { - switch(opcode) - { - case OP_STR_EQ: - r1.i = (ss_compare(r1.ss, r2.ss) == 0); - break; - case OP_STR_NEQ: - r1.i = (ss_compare(r1.ss, r2.ss) != 0); - break; - case OP_STR_LT: - r1.i = (ss_compare(r1.ss, r2.ss) < 0); - break; - case OP_STR_LE: - r1.i = (ss_compare(r1.ss, r2.ss) <= 0); - break; - case OP_STR_GT: - r1.i = (ss_compare(r1.ss, r2.ss) > 0); - break; - case OP_STR_GE: - r1.i = (ss_compare(r1.ss, r2.ss) >= 0); - break; - } - } + } - push(r1); - break; + push(r1); + break; - case OP_CONTAINS: - case OP_ICONTAINS: - case OP_STARTSWITH: - case OP_ISTARTSWITH: - case OP_ENDSWITH: - case OP_IENDSWITH: + case OP_CONTAINS: + case OP_ICONTAINS: + case OP_STARTSWITH: + case OP_ISTARTSWITH: + case OP_ENDSWITH: + case OP_IENDSWITH: - pop(r2); - pop(r1); + pop(r2); + pop(r1); - if (is_undef(r1) || is_undef(r2)) - { - r1.i = false; - } - else + if (is_undef(r1) || is_undef(r2)) + { + r1.i = false; + } + else + { + switch (opcode) { - switch(opcode) - { - case OP_CONTAINS: - r1.i = ss_contains(r1.ss, r2.ss); - break; - case OP_ICONTAINS: - r1.i = ss_icontains(r1.ss, r2.ss); - break; - case OP_STARTSWITH: - r1.i = ss_startswith(r1.ss, r2.ss); - break; - case OP_ISTARTSWITH: - r1.i = ss_istartswith(r1.ss, r2.ss); - break; - case OP_ENDSWITH: - r1.i = ss_endswith(r1.ss, r2.ss); - break; - case OP_IENDSWITH: - r1.i = ss_iendswith(r1.ss, r2.ss); - break; - } + case OP_CONTAINS: + r1.i = ss_contains(r1.ss, r2.ss); + break; + case OP_ICONTAINS: + r1.i = ss_icontains(r1.ss, r2.ss); + break; + case OP_STARTSWITH: + r1.i = ss_startswith(r1.ss, r2.ss); + break; + case OP_ISTARTSWITH: + r1.i = ss_istartswith(r1.ss, r2.ss); + break; + case OP_ENDSWITH: + r1.i = ss_endswith(r1.ss, r2.ss); + break; + case OP_IENDSWITH: + r1.i = ss_iendswith(r1.ss, r2.ss); + break; } + } - push(r1); - break; + push(r1); + break; - default: - // Unknown instruction, this shouldn't happen. - assert(false); + default: + // Unknown instruction, this shouldn't happen. + assert(false); } // Check for timeout every 100 instruction cycles. If timeout == 0 it means @@ -1718,10 +1703,10 @@ int yr_execute_code( if (elapsed_time > context->timeout) { - #ifdef YR_PROFILING_ENABLED - context->profiling_info[current_rule_idx].exec_time += ( - elapsed_time - start_time); - #endif +#ifdef YR_PROFILING_ENABLED + context->profiling_info[current_rule_idx].exec_time += + (elapsed_time - start_time); +#endif result = ERROR_SCAN_TIMEOUT; stop = true; } @@ -1732,8 +1717,7 @@ int yr_execute_code( obj_ptr = yr_arena_get_ptr(obj_arena, 0, 0); - for (int i = 0; i < obj_count; i++) - yr_object_destroy(obj_ptr[i]); + for (int i = 0; i < obj_count; i++) yr_object_destroy(obj_ptr[i]); yr_arena_release(obj_arena); yr_notebook_destroy(it_notebook); diff --git a/libyara/exefiles.c b/libyara/exefiles.c index aa9451257f..8480e8adc0 100644 --- a/libyara/exefiles.c +++ b/libyara/exefiles.c @@ -28,11 +28,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include - -#include -#include #include +#include #include +#include #include #ifndef NULL @@ -40,7 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif #ifndef MIN -#define MIN(x,y) ((x < y)?(x):(y)) +#define MIN(x, y) ((x < y) ? (x) : (y)) #endif @@ -64,14 +63,13 @@ PIMAGE_NT_HEADERS32 yr_get_pe_header( if ((int32_t) yr_le32toh(mz_header->e_lfanew) < 0) return NULL; - headers_size = yr_le32toh(mz_header->e_lfanew) + \ - sizeof(pe_header->Signature) + \ - sizeof(IMAGE_FILE_HEADER); + headers_size = yr_le32toh(mz_header->e_lfanew) + + sizeof(pe_header->Signature) + sizeof(IMAGE_FILE_HEADER); if (buffer_length < headers_size) return NULL; - pe_header = (PIMAGE_NT_HEADERS32) (buffer + yr_le32toh(mz_header->e_lfanew)); + pe_header = (PIMAGE_NT_HEADERS32)(buffer + yr_le32toh(mz_header->e_lfanew)); headers_size += sizeof(IMAGE_OPTIONAL_HEADER32); @@ -103,10 +101,11 @@ uint64_t yr_pe_rva_to_offset( section_rva = 0; section_offset = 0; - while(i < MIN(yr_le16toh(pe_header->FileHeader.NumberOfSections), 60)) + while (i < MIN(yr_le16toh(pe_header->FileHeader.NumberOfSections), 60)) { - if ((uint8_t*) section - \ - (uint8_t*) pe_header + sizeof(IMAGE_SECTION_HEADER) < buffer_length) + if ((uint8_t*) section - (uint8_t*) pe_header + + sizeof(IMAGE_SECTION_HEADER) < + buffer_length) { if (rva >= section->VirtualAddress && section_rva <= yr_le32toh(section->VirtualAddress)) @@ -128,9 +127,7 @@ uint64_t yr_pe_rva_to_offset( } -int yr_get_elf_type( - const uint8_t* buffer, - size_t buffer_length) +int yr_get_elf_type(const uint8_t* buffer, size_t buffer_length) { elf_ident_t* elf_ident; @@ -144,22 +141,23 @@ int yr_get_elf_type( return 0; } - switch (elf_ident->_class) { - case ELF_CLASS_32: - if (buffer_length < sizeof(elf32_header_t)) - { - return 0; - } - break; - case ELF_CLASS_64: - if (buffer_length < sizeof(elf64_header_t)) - { - return 0; - } - break; - default: - /* Unexpected class */ + switch (elf_ident->_class) + { + case ELF_CLASS_32: + if (buffer_length < sizeof(elf32_header_t)) + { + return 0; + } + break; + case ELF_CLASS_64: + if (buffer_length < sizeof(elf64_header_t)) + { return 0; + } + break; + default: + /* Unexpected class */ + return 0; } return elf_ident->_class; @@ -183,29 +181,32 @@ static uint64_t yr_elf_rva_to_offset_32( // check to prevent integer wraps if (ULONG_MAX - yr_le16toh(elf_header->ph_entry_count) < - sizeof(elf32_program_header_t) * yr_le16toh(elf_header->ph_entry_count)) + sizeof(elf32_program_header_t) * yr_le16toh(elf_header->ph_entry_count)) return 0; // check that 'ph_offset' doesn't wrap when added to the // size of entries. - if(ULONG_MAX - yr_le32toh(elf_header->ph_offset) < - sizeof(elf32_program_header_t) * yr_le16toh(elf_header->ph_entry_count)) + if (ULONG_MAX - yr_le32toh(elf_header->ph_offset) < + sizeof(elf32_program_header_t) * yr_le16toh(elf_header->ph_entry_count)) return 0; // ensure we don't exceed the buffer size - if (yr_le32toh(elf_header->ph_offset) + sizeof(elf32_program_header_t) * - yr_le16toh(elf_header->ph_entry_count) > buffer_length) + if (yr_le32toh(elf_header->ph_offset) + + sizeof(elf32_program_header_t) * + yr_le16toh(elf_header->ph_entry_count) > + buffer_length) return 0; - program = (elf32_program_header_t*) - ((uint8_t*) elf_header + yr_le32toh(elf_header->ph_offset)); + program = + (elf32_program_header_t*) ((uint8_t*) elf_header + yr_le32toh(elf_header->ph_offset)); for (i = 0; i < yr_le16toh(elf_header->ph_entry_count); i++) { if (rva >= yr_le32toh(program->virt_addr) && - rva < yr_le32toh(program->virt_addr) + yr_le32toh(program->mem_size)) + rva < yr_le32toh(program->virt_addr) + yr_le32toh(program->mem_size)) { - return yr_le32toh(program->offset) + (rva - yr_le32toh(program->virt_addr)); + return yr_le32toh(program->offset) + + (rva - yr_le32toh(program->virt_addr)); } program++; @@ -223,18 +224,20 @@ static uint64_t yr_elf_rva_to_offset_32( // check to prevent integer wraps if (ULONG_MAX - yr_le16toh(elf_header->sh_entry_count) < - sizeof(elf32_section_header_t) * yr_le16toh(elf_header->sh_entry_count)) + sizeof(elf32_section_header_t) * yr_le16toh(elf_header->sh_entry_count)) return 0; // check that 'sh_offset' doesn't wrap when added to the // size of entries. if (ULONG_MAX - yr_le32toh(elf_header->sh_offset) < - sizeof(elf32_section_header_t) * yr_le16toh(elf_header->sh_entry_count)) + sizeof(elf32_section_header_t) * yr_le16toh(elf_header->sh_entry_count)) return 0; - if (yr_le32toh(elf_header->sh_offset) + sizeof(elf32_section_header_t) * - yr_le16toh(elf_header->sh_entry_count) > buffer_length) + if (yr_le32toh(elf_header->sh_offset) + + sizeof(elf32_section_header_t) * + yr_le16toh(elf_header->sh_entry_count) > + buffer_length) return 0; section = (elf32_section_header_t*) @@ -245,14 +248,16 @@ static uint64_t yr_elf_rva_to_offset_32( if (yr_le32toh(section->type) != ELF_SHT_NULL && yr_le32toh(section->type) != ELF_SHT_NOBITS && rva >= yr_le32toh(section->addr) && - rva < yr_le32toh(section->addr) + yr_le32toh(section->size)) + rva < yr_le32toh(section->addr) + yr_le32toh(section->size)) { // prevent integer wrapping with the return value - if (ULONG_MAX - yr_le32toh(section->offset) < (rva - yr_le32toh(section->addr))) + if (ULONG_MAX - yr_le32toh(section->offset) < + (rva - yr_le32toh(section->addr))) return 0; else - return yr_le32toh(section->offset) + (rva - yr_le32toh(section->addr)); + return yr_le32toh(section->offset) + + (rva - yr_le32toh(section->addr)); } section++; @@ -260,7 +265,6 @@ static uint64_t yr_elf_rva_to_offset_32( } return 0; - } @@ -281,24 +285,27 @@ static uint64_t yr_elf_rva_to_offset_64( // check that 'ph_offset' doesn't wrap when added to the // size of entries. - if(ULONG_MAX - yr_le64toh(elf_header->ph_offset) < - sizeof(elf64_program_header_t) * yr_le16toh(elf_header->ph_entry_count)) + if (ULONG_MAX - yr_le64toh(elf_header->ph_offset) < + sizeof(elf64_program_header_t) * yr_le16toh(elf_header->ph_entry_count)) return 0; // ensure we don't exceed the buffer size - if (yr_le64toh(elf_header->ph_offset) + sizeof(elf64_program_header_t) * - yr_le16toh(elf_header->ph_entry_count) > buffer_length) + if (yr_le64toh(elf_header->ph_offset) + + sizeof(elf64_program_header_t) * + yr_le16toh(elf_header->ph_entry_count) > + buffer_length) return 0; - program = (elf64_program_header_t*) - ((uint8_t*) elf_header + yr_le64toh(elf_header->ph_offset)); + program = + (elf64_program_header_t*) ((uint8_t*) elf_header + yr_le64toh(elf_header->ph_offset)); for (i = 0; i < yr_le16toh(elf_header->ph_entry_count); i++) { if (rva >= yr_le64toh(program->virt_addr) && - rva < yr_le64toh(program->virt_addr) + yr_le64toh(program->mem_size)) + rva < yr_le64toh(program->virt_addr) + yr_le64toh(program->mem_size)) { - return yr_le64toh(program->offset) + (rva - yr_le64toh(program->virt_addr)); + return yr_le64toh(program->offset) + + (rva - yr_le64toh(program->virt_addr)); } program++; @@ -315,23 +322,25 @@ static uint64_t yr_elf_rva_to_offset_64( // check that 'sh_offset' doesn't wrap when added to the // size of entries. - if(ULONG_MAX - yr_le64toh(elf_header->sh_offset) < - sizeof(elf64_section_header_t) * yr_le16toh(elf_header->sh_entry_count)) + if (ULONG_MAX - yr_le64toh(elf_header->sh_offset) < + sizeof(elf64_section_header_t) * yr_le16toh(elf_header->sh_entry_count)) return 0; - if (yr_le64toh(elf_header->sh_offset) + sizeof(elf64_section_header_t) * - yr_le16toh(elf_header->sh_entry_count) > buffer_length) + if (yr_le64toh(elf_header->sh_offset) + + sizeof(elf64_section_header_t) * + yr_le16toh(elf_header->sh_entry_count) > + buffer_length) return 0; - section = (elf64_section_header_t*) - ((uint8_t*) elf_header + yr_le64toh(elf_header->sh_offset)); + section = + (elf64_section_header_t*) ((uint8_t*) elf_header + yr_le64toh(elf_header->sh_offset)); for (i = 0; i < yr_le16toh(elf_header->sh_entry_count); i++) { if (yr_le32toh(section->type) != ELF_SHT_NULL && yr_le32toh(section->type) != ELF_SHT_NOBITS && rva >= yr_le64toh(section->addr) && - rva < yr_le64toh(section->addr) + yr_le64toh(section->size)) + rva < yr_le64toh(section->addr) + yr_le64toh(section->size)) { return yr_le64toh(section->offset) + (rva - yr_le64toh(section->addr)); } @@ -344,9 +353,7 @@ static uint64_t yr_elf_rva_to_offset_64( } -uint64_t yr_get_entry_point_offset( - const uint8_t* buffer, - size_t buffer_length) +uint64_t yr_get_entry_point_offset(const uint8_t* buffer, size_t buffer_length) { PIMAGE_NT_HEADERS32 pe_header; elf32_header_t* elf_header32; @@ -362,21 +369,17 @@ uint64_t yr_get_entry_point_offset( buffer_length - ((uint8_t*) pe_header - buffer)); } - switch(yr_get_elf_type(buffer, buffer_length)) + switch (yr_get_elf_type(buffer, buffer_length)) { - case ELF_CLASS_32: - elf_header32 = (elf32_header_t*) buffer; - return yr_elf_rva_to_offset_32( - elf_header32, - yr_le32toh(elf_header32->entry), - buffer_length); - - case ELF_CLASS_64: - elf_header64 = (elf64_header_t*) buffer; - return yr_elf_rva_to_offset_64( - elf_header64, - yr_le64toh(elf_header64->entry), - buffer_length); + case ELF_CLASS_32: + elf_header32 = (elf32_header_t*) buffer; + return yr_elf_rva_to_offset_32( + elf_header32, yr_le32toh(elf_header32->entry), buffer_length); + + case ELF_CLASS_64: + elf_header64 = (elf64_header_t*) buffer; + return yr_elf_rva_to_offset_64( + elf_header64, yr_le64toh(elf_header64->entry), buffer_length); } return YR_UNDEFINED; @@ -403,23 +406,23 @@ uint64_t yr_get_entry_point_address( // If file is executable ELF, not shared library. - switch(yr_get_elf_type(buffer, buffer_length)) + switch (yr_get_elf_type(buffer, buffer_length)) { - case ELF_CLASS_32: - elf_header32 = (elf32_header_t*) buffer; + case ELF_CLASS_32: + elf_header32 = (elf32_header_t*) buffer; - if (elf_header32->type == ELF_ET_EXEC) - return elf_header32->entry; + if (elf_header32->type == ELF_ET_EXEC) + return elf_header32->entry; - break; + break; - case ELF_CLASS_64: - elf_header64 = (elf64_header_t*) buffer; + case ELF_CLASS_64: + elf_header64 = (elf64_header_t*) buffer; - if (elf_header64->type == ELF_ET_EXEC) - return elf_header64->entry; + if (elf_header64->type == ELF_ET_EXEC) + return elf_header64->entry; - break; + break; } return YR_UNDEFINED; diff --git a/libyara/filemap.c b/libyara/filemap.c index bb8cac2287..91ac2d6e68 100644 --- a/libyara/filemap.c +++ b/libyara/filemap.c @@ -32,13 +32,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(_WIN32) || defined(__CYGWIN__) #include #else -#include #include +#include #include #endif -#include #include +#include // @@ -58,9 +58,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ERROR_COULD_NOT_MAP_FILE // -YR_API int yr_filemap_map( - const char* file_path, - YR_MAPPED_FILE* pmapped_file) +YR_API int yr_filemap_map(const char* file_path, YR_MAPPED_FILE* pmapped_file) { return yr_filemap_map_ex(file_path, 0, 0, pmapped_file); } @@ -112,11 +110,11 @@ YR_API int yr_filemap_map_fd( if (GetFileSizeEx(pmapped_file->file, &fs)) { - #ifdef _WIN64 +#ifdef _WIN64 file_size = fs.QuadPart; - #else +#else file_size = fs.LowPart; - #endif +#endif } else { @@ -128,19 +126,14 @@ YR_API int yr_filemap_map_fd( return ERROR_COULD_NOT_MAP_FILE; if (size == 0) - size = (size_t) (file_size - offset); + size = (size_t)(file_size - offset); - pmapped_file->size = yr_min(size, (size_t) (file_size - offset)); + pmapped_file->size = yr_min(size, (size_t)(file_size - offset)); if (pmapped_file->size != 0) { pmapped_file->mapping = CreateFileMapping( - pmapped_file->file, - NULL, - PAGE_READONLY, - 0, - 0, - NULL); + pmapped_file->file, NULL, PAGE_READONLY, 0, 0, NULL); if (pmapped_file->mapping == NULL) { @@ -174,27 +167,27 @@ YR_API int yr_filemap_map_fd( return ERROR_SUCCESS; } -#else // POSIX +#else // POSIX #define MAP_EXTRA_FLAGS 0 -#if defined (__APPLE__) +#if defined(__APPLE__) // MacOS defines some extra flags for mmap.The MAP_RESILIENT_CODESIGN allows // to read from binaries whose code signature is invalid, without this flags // any attempt to read from such binaries causes a crash, see: // https://github.com/VirusTotal/yara/issues/1309. // -// Also, reading from files in removable media that becomes unavailable crashes -// the program if the MAP_RESILIENT_MEDIA flag is not set. +// Also, reading from files in removable media that becomes unavailable +// crashes the program if the MAP_RESILIENT_MEDIA flag is not set. #if defined(MAP_RESILIENT_CODESIGN) - #undef MAP_EXTRA_FLAGS - #if defined(MAP_RESILIENT_MEDIA) - #define MAP_EXTRA_FLAGS MAP_RESILIENT_CODESIGN | MAP_RESILIENT_MEDIA - #else - #define MAP_EXTRA_FLAGS MAP_RESILIENT_CODESIGN - #endif -#endif // #if defined(MAP_RESILIENT_CODESIGN) -#endif // #if defined (__APPLE__) +#undef MAP_EXTRA_FLAGS +#if defined(MAP_RESILIENT_MEDIA) +#define MAP_EXTRA_FLAGS MAP_RESILIENT_CODESIGN | MAP_RESILIENT_MEDIA +#else +#define MAP_EXTRA_FLAGS MAP_RESILIENT_CODESIGN +#endif +#endif // #if defined(MAP_RESILIENT_CODESIGN) +#endif // #if defined (__APPLE__) YR_API int yr_filemap_map_fd( YR_FILE_DESCRIPTOR file, @@ -219,9 +212,9 @@ YR_API int yr_filemap_map_fd( return ERROR_COULD_NOT_MAP_FILE; if (size == 0) - size = (size_t) (st.st_size - offset); + size = (size_t)(st.st_size - offset); - pmapped_file->size = yr_min(size, (size_t) (st.st_size - offset)); + pmapped_file->size = yr_min(size, (size_t)(st.st_size - offset)); if (pmapped_file->size != 0) { @@ -312,7 +305,7 @@ YR_API int yr_filemap_map_ex( return result; } -#else // POSIX +#else // POSIX YR_API int yr_filemap_map_ex( const char* file_path, @@ -353,8 +346,7 @@ YR_API int yr_filemap_map_ex( #ifdef WIN32 -YR_API void yr_filemap_unmap_fd( - YR_MAPPED_FILE* pmapped_file) +YR_API void yr_filemap_unmap_fd(YR_MAPPED_FILE* pmapped_file) { if (pmapped_file->data != NULL) UnmapViewOfFile(pmapped_file->data); @@ -367,8 +359,7 @@ YR_API void yr_filemap_unmap_fd( pmapped_file->size = 0; } -YR_API void yr_filemap_unmap( - YR_MAPPED_FILE* pmapped_file) +YR_API void yr_filemap_unmap(YR_MAPPED_FILE* pmapped_file) { yr_filemap_unmap_fd(pmapped_file); @@ -379,10 +370,9 @@ YR_API void yr_filemap_unmap( } } -#else // POSIX +#else // POSIX -YR_API void yr_filemap_unmap_fd( - YR_MAPPED_FILE* pmapped_file) +YR_API void yr_filemap_unmap_fd(YR_MAPPED_FILE* pmapped_file) { if (pmapped_file->data != NULL) munmap((void*) pmapped_file->data, pmapped_file->size); @@ -391,8 +381,7 @@ YR_API void yr_filemap_unmap_fd( pmapped_file->size = 0; } -YR_API void yr_filemap_unmap( - YR_MAPPED_FILE* pmapped_file) +YR_API void yr_filemap_unmap(YR_MAPPED_FILE* pmapped_file) { yr_filemap_unmap_fd(pmapped_file); diff --git a/libyara/grammar.c b/libyara/grammar.c index d6393342df..0284fb648c 100644 --- a/libyara/grammar.c +++ b/libyara/grammar.c @@ -60,37 +60,35 @@ /* Substitute the variable and function names. */ -#define yyparse yara_yyparse -#define yylex yara_yylex -#define yyerror yara_yyerror -#define yydebug yara_yydebug -#define yynerrs yara_yynerrs +#define yyparse yara_yyparse +#define yylex yara_yylex +#define yyerror yara_yyerror +#define yydebug yara_yydebug +#define yynerrs yara_yynerrs /* Copy the first part of user declarations. */ #line 30 "grammar.y" /* yacc.c:339 */ - #include -#include -#include #include -#include #include - +#include +#include +#include #include -#include -#include -#include #include -#include -#include -#include #include -#include +#include +#include #include +#include +#include #include +#include +#include +#include #if defined(_MSC_VER) #define llabs _abs64 @@ -99,110 +97,111 @@ #define YYERROR_VERBOSE #define YYMALLOC yr_malloc -#define YYFREE yr_free +#define YYFREE yr_free #define FOR_EXPRESSION_ALL 1 #define FOR_EXPRESSION_ANY 2 -#define fail_with_error(e) \ - { \ - compiler->last_error = e; \ - yyerror(yyscanner, compiler, NULL); \ - YYERROR; \ - } +#define fail_with_error(e) \ + { \ + compiler->last_error = e; \ + yyerror(yyscanner, compiler, NULL); \ + YYERROR; \ + } -#define fail_if_error(e) \ - if (e != ERROR_SUCCESS) \ - { \ - fail_with_error(e); \ - } \ +#define fail_if_error(e) \ + if (e != ERROR_SUCCESS) \ + { \ + fail_with_error(e); \ + } #define check_type_with_cleanup(expression, expected_type, op, cleanup) \ - if (((expression.type) & (expected_type)) == 0) \ - { \ - switch(expression.type) \ - { \ - case EXPRESSION_TYPE_INTEGER: \ - yr_compiler_set_error_extra_info( \ - compiler, "wrong type \"integer\" for " op " operator"); \ - break; \ - case EXPRESSION_TYPE_FLOAT: \ - yr_compiler_set_error_extra_info( \ - compiler, "wrong type \"float\" for " op " operator"); \ - break; \ - case EXPRESSION_TYPE_STRING: \ - yr_compiler_set_error_extra_info( \ - compiler, "wrong type \"string\" for " op " operator"); \ - break; \ - case EXPRESSION_TYPE_BOOLEAN: \ - yr_compiler_set_error_extra_info( \ - compiler, "wrong type \"boolean\" for " op " operator"); \ - break; \ - } \ - cleanup; \ - compiler->last_error = ERROR_WRONG_TYPE; \ - yyerror(yyscanner, compiler, NULL); \ - YYERROR; \ - } + if (((expression.type) & (expected_type)) == 0) \ + { \ + switch (expression.type) \ + { \ + case EXPRESSION_TYPE_INTEGER: \ + yr_compiler_set_error_extra_info( \ + compiler, "wrong type \"integer\" for " op " operator"); \ + break; \ + case EXPRESSION_TYPE_FLOAT: \ + yr_compiler_set_error_extra_info( \ + compiler, "wrong type \"float\" for " op " operator"); \ + break; \ + case EXPRESSION_TYPE_STRING: \ + yr_compiler_set_error_extra_info( \ + compiler, "wrong type \"string\" for " op " operator"); \ + break; \ + case EXPRESSION_TYPE_BOOLEAN: \ + yr_compiler_set_error_extra_info( \ + compiler, "wrong type \"boolean\" for " op " operator"); \ + break; \ + } \ + cleanup; \ + compiler->last_error = ERROR_WRONG_TYPE; \ + yyerror(yyscanner, compiler, NULL); \ + YYERROR; \ + } // check_type(expression, EXPRESSION_TYPE_INTEGER | EXPRESSION_TYPE_FLOAT) is // used to ensure that the type of "expression" is either integer or float. #define check_type(expression, expected_type, op) \ - check_type_with_cleanup(expression, expected_type, op, ) - - -#define loop_vars_cleanup(loop_index) \ - { \ - YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[loop_index]; \ - for (int i = 0; i < loop_ctx->vars_count; i++) \ - { \ - yr_free((void*) loop_ctx->vars[i].identifier.ptr); \ - loop_ctx->vars[i].identifier.ptr = NULL; \ - loop_ctx->vars[i].identifier.ref = YR_ARENA_NULL_REF; \ - } \ - loop_ctx->vars_count = 0; \ - } \ + check_type_with_cleanup(expression, expected_type, op, ) + + +#define loop_vars_cleanup(loop_index) \ + { \ + YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[loop_index]; \ + for (int i = 0; i < loop_ctx->vars_count; i++) \ + { \ + yr_free((void*) loop_ctx->vars[i].identifier.ptr); \ + loop_ctx->vars[i].identifier.ptr = NULL; \ + loop_ctx->vars[i].identifier.ref = YR_ARENA_NULL_REF; \ + } \ + loop_ctx->vars_count = 0; \ + } // Given a YR_EXPRESSION returns its identifier. It returns identifier.ptr if // not NULL and relies on identifier.ref if otherwise. -#define expression_identifier(expr) \ - ((expr).identifier.ptr != NULL ? \ - (expr).identifier.ptr : \ - (const char*) yr_arena_ref_to_ptr(compiler->arena, &(expr).identifier.ref)) +#define expression_identifier(expr) \ + ((expr).identifier.ptr != NULL \ + ? (expr).identifier.ptr \ + : (const char*) yr_arena_ref_to_ptr( \ + compiler->arena, &(expr).identifier.ref)) #define DEFAULT_BASE64_ALPHABET \ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" #line 182 "grammar.c" /* yacc.c:339 */ -# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# endif +#ifndef YY_NULLPTR +#if defined __cplusplus && 201103L <= __cplusplus +#define YY_NULLPTR nullptr +#else +#define YY_NULLPTR 0 +#endif +#endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 +#undef YYERROR_VERBOSE +#define YYERROR_VERBOSE 1 #else -# define YYERROR_VERBOSE 0 +#define YYERROR_VERBOSE 0 #endif /* In a future release of Bison, this section will be replaced by #include "y.tab.h". */ #ifndef YY_YARA_YY_GRAMMAR_H_INCLUDED -# define YY_YARA_YY_GRAMMAR_H_INCLUDED +#define YY_YARA_YY_GRAMMAR_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG -# define YYDEBUG 0 +#define YYDEBUG 0 #endif #if YYDEBUG extern int yara_yydebug; @@ -210,144 +209,144 @@ extern int yara_yydebug; /* Token type. */ #ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - _END_OF_FILE_ = 0, - _END_OF_INCLUDED_FILE_ = 258, - _DOT_DOT_ = 259, - _RULE_ = 260, - _PRIVATE_ = 261, - _GLOBAL_ = 262, - _META_ = 263, - _STRINGS_ = 264, - _CONDITION_ = 265, - _IDENTIFIER_ = 266, - _STRING_IDENTIFIER_ = 267, - _STRING_COUNT_ = 268, - _STRING_OFFSET_ = 269, - _STRING_LENGTH_ = 270, - _STRING_IDENTIFIER_WITH_WILDCARD_ = 271, - _NUMBER_ = 272, - _DOUBLE_ = 273, - _INTEGER_FUNCTION_ = 274, - _TEXT_STRING_ = 275, - _HEX_STRING_ = 276, - _REGEXP_ = 277, - _ASCII_ = 278, - _WIDE_ = 279, - _XOR_ = 280, - _BASE64_ = 281, - _BASE64_WIDE_ = 282, - _NOCASE_ = 283, - _FULLWORD_ = 284, - _AT_ = 285, - _FILESIZE_ = 286, - _ENTRYPOINT_ = 287, - _ALL_ = 288, - _ANY_ = 289, - _IN_ = 290, - _OF_ = 291, - _FOR_ = 292, - _THEM_ = 293, - _MATCHES_ = 294, - _CONTAINS_ = 295, - _STARTSWITH_ = 296, - _ENDSWITH_ = 297, - _ICONTAINS_ = 298, - _ISTARTSWITH_ = 299, - _IENDSWITH_ = 300, - _IMPORT_ = 301, - _TRUE_ = 302, - _FALSE_ = 303, - _OR_ = 304, - _AND_ = 305, - _NOT_ = 306, - _EQ_ = 307, - _NEQ_ = 308, - _LT_ = 309, - _LE_ = 310, - _GT_ = 311, - _GE_ = 312, - _SHIFT_LEFT_ = 313, - _SHIFT_RIGHT_ = 314, - UNARY_MINUS = 315 - }; +#define YYTOKENTYPE +enum yytokentype +{ + _END_OF_FILE_ = 0, + _END_OF_INCLUDED_FILE_ = 258, + _DOT_DOT_ = 259, + _RULE_ = 260, + _PRIVATE_ = 261, + _GLOBAL_ = 262, + _META_ = 263, + _STRINGS_ = 264, + _CONDITION_ = 265, + _IDENTIFIER_ = 266, + _STRING_IDENTIFIER_ = 267, + _STRING_COUNT_ = 268, + _STRING_OFFSET_ = 269, + _STRING_LENGTH_ = 270, + _STRING_IDENTIFIER_WITH_WILDCARD_ = 271, + _NUMBER_ = 272, + _DOUBLE_ = 273, + _INTEGER_FUNCTION_ = 274, + _TEXT_STRING_ = 275, + _HEX_STRING_ = 276, + _REGEXP_ = 277, + _ASCII_ = 278, + _WIDE_ = 279, + _XOR_ = 280, + _BASE64_ = 281, + _BASE64_WIDE_ = 282, + _NOCASE_ = 283, + _FULLWORD_ = 284, + _AT_ = 285, + _FILESIZE_ = 286, + _ENTRYPOINT_ = 287, + _ALL_ = 288, + _ANY_ = 289, + _IN_ = 290, + _OF_ = 291, + _FOR_ = 292, + _THEM_ = 293, + _MATCHES_ = 294, + _CONTAINS_ = 295, + _STARTSWITH_ = 296, + _ENDSWITH_ = 297, + _ICONTAINS_ = 298, + _ISTARTSWITH_ = 299, + _IENDSWITH_ = 300, + _IMPORT_ = 301, + _TRUE_ = 302, + _FALSE_ = 303, + _OR_ = 304, + _AND_ = 305, + _NOT_ = 306, + _EQ_ = 307, + _NEQ_ = 308, + _LT_ = 309, + _LE_ = 310, + _GT_ = 311, + _GE_ = 312, + _SHIFT_LEFT_ = 313, + _SHIFT_RIGHT_ = 314, + UNARY_MINUS = 315 +}; #endif /* Tokens. */ -#define _END_OF_FILE_ 0 -#define _END_OF_INCLUDED_FILE_ 258 -#define _DOT_DOT_ 259 -#define _RULE_ 260 -#define _PRIVATE_ 261 -#define _GLOBAL_ 262 -#define _META_ 263 -#define _STRINGS_ 264 -#define _CONDITION_ 265 -#define _IDENTIFIER_ 266 -#define _STRING_IDENTIFIER_ 267 -#define _STRING_COUNT_ 268 -#define _STRING_OFFSET_ 269 -#define _STRING_LENGTH_ 270 +#define _END_OF_FILE_ 0 +#define _END_OF_INCLUDED_FILE_ 258 +#define _DOT_DOT_ 259 +#define _RULE_ 260 +#define _PRIVATE_ 261 +#define _GLOBAL_ 262 +#define _META_ 263 +#define _STRINGS_ 264 +#define _CONDITION_ 265 +#define _IDENTIFIER_ 266 +#define _STRING_IDENTIFIER_ 267 +#define _STRING_COUNT_ 268 +#define _STRING_OFFSET_ 269 +#define _STRING_LENGTH_ 270 #define _STRING_IDENTIFIER_WITH_WILDCARD_ 271 -#define _NUMBER_ 272 -#define _DOUBLE_ 273 -#define _INTEGER_FUNCTION_ 274 -#define _TEXT_STRING_ 275 -#define _HEX_STRING_ 276 -#define _REGEXP_ 277 -#define _ASCII_ 278 -#define _WIDE_ 279 -#define _XOR_ 280 -#define _BASE64_ 281 -#define _BASE64_WIDE_ 282 -#define _NOCASE_ 283 -#define _FULLWORD_ 284 -#define _AT_ 285 -#define _FILESIZE_ 286 -#define _ENTRYPOINT_ 287 -#define _ALL_ 288 -#define _ANY_ 289 -#define _IN_ 290 -#define _OF_ 291 -#define _FOR_ 292 -#define _THEM_ 293 -#define _MATCHES_ 294 -#define _CONTAINS_ 295 -#define _STARTSWITH_ 296 -#define _ENDSWITH_ 297 -#define _ICONTAINS_ 298 -#define _ISTARTSWITH_ 299 -#define _IENDSWITH_ 300 -#define _IMPORT_ 301 -#define _TRUE_ 302 -#define _FALSE_ 303 -#define _OR_ 304 -#define _AND_ 305 -#define _NOT_ 306 -#define _EQ_ 307 -#define _NEQ_ 308 -#define _LT_ 309 -#define _LE_ 310 -#define _GT_ 311 -#define _GE_ 312 -#define _SHIFT_LEFT_ 313 -#define _SHIFT_RIGHT_ 314 -#define UNARY_MINUS 315 +#define _NUMBER_ 272 +#define _DOUBLE_ 273 +#define _INTEGER_FUNCTION_ 274 +#define _TEXT_STRING_ 275 +#define _HEX_STRING_ 276 +#define _REGEXP_ 277 +#define _ASCII_ 278 +#define _WIDE_ 279 +#define _XOR_ 280 +#define _BASE64_ 281 +#define _BASE64_WIDE_ 282 +#define _NOCASE_ 283 +#define _FULLWORD_ 284 +#define _AT_ 285 +#define _FILESIZE_ 286 +#define _ENTRYPOINT_ 287 +#define _ALL_ 288 +#define _ANY_ 289 +#define _IN_ 290 +#define _OF_ 291 +#define _FOR_ 292 +#define _THEM_ 293 +#define _MATCHES_ 294 +#define _CONTAINS_ 295 +#define _STARTSWITH_ 296 +#define _ENDSWITH_ 297 +#define _ICONTAINS_ 298 +#define _ISTARTSWITH_ 299 +#define _IENDSWITH_ 300 +#define _IMPORT_ 301 +#define _TRUE_ 302 +#define _FALSE_ 303 +#define _OR_ 304 +#define _AND_ 305 +#define _NOT_ 306 +#define _EQ_ 307 +#define _NEQ_ 308 +#define _LT_ 309 +#define _LE_ 310 +#define _GT_ 311 +#define _GE_ 312 +#define _SHIFT_LEFT_ 313 +#define _SHIFT_RIGHT_ 314 +#define UNARY_MINUS 315 /* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED union YYSTYPE { #line 302 "grammar.y" /* yacc.c:355 */ - YR_EXPRESSION expression; - SIZED_STRING* sized_string; - char* c_string; - int64_t integer; - double double_; - YR_MODIFIER modifier; + YR_EXPRESSION expression; + SIZED_STRING* sized_string; + char* c_string; + int64_t integer; + double double_; + YR_MODIFIER modifier; YR_ARENA_REF tag; YR_ARENA_REF rule; @@ -358,13 +357,12 @@ union YYSTYPE }; typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 +#define YYSTYPE_IS_TRIVIAL 1 +#define YYSTYPE_IS_DECLARED 1 #endif - -int yara_yyparse (void *yyscanner, YR_COMPILER* compiler); +int yara_yyparse(void* yyscanner, YR_COMPILER* compiler); #endif /* !YY_YARA_YY_GRAMMAR_H_INCLUDED */ @@ -373,7 +371,7 @@ int yara_yyparse (void *yyscanner, YR_COMPILER* compiler); #line 374 "grammar.c" /* yacc.c:358 */ #ifdef short -# undef short +#undef short #endif #ifdef YYTYPE_UINT8 @@ -401,157 +399,163 @@ typedef short int yytype_int16; #endif #ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif ! defined YYSIZE_T -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned int -# endif +#ifdef __SIZE_TYPE__ +#define YYSIZE_T __SIZE_TYPE__ +#elif defined size_t +#define YYSIZE_T size_t +#elif !defined YYSIZE_T +#include /* INFRINGES ON USER NAME SPACE */ +#define YYSIZE_T size_t +#else +#define YYSIZE_T unsigned int +#endif #endif #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) -# endif -# endif -# ifndef YY_ -# define YY_(Msgid) Msgid -# endif +#if defined YYENABLE_NLS && YYENABLE_NLS +#if ENABLE_NLS +#include /* INFRINGES ON USER NAME SPACE */ +#define YY_(Msgid) dgettext("bison-runtime", Msgid) +#endif +#endif +#ifndef YY_ +#define YY_(Msgid) Msgid +#endif #endif #ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif +#if ( \ + defined __GNUC__ && \ + (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) || \ + defined __SUNPRO_C && 0x5110 <= __SUNPRO_C +#define YY_ATTRIBUTE(Spec) __attribute__(Spec) +#else +#define YY_ATTRIBUTE(Spec) /* empty */ +#endif #endif #ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#define YY_ATTRIBUTE_PURE YY_ATTRIBUTE((__pure__)) #endif #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +#define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE((__unused__)) #endif -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) -# endif +#if !defined _Noreturn && \ + (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) +#if defined _MSC_VER && 1200 <= _MSC_VER +#define _Noreturn __declspec(noreturn) +#else +#define _Noreturn YY_ATTRIBUTE((__noreturn__)) +#endif #endif /* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +#if !defined lint || defined __GNUC__ +#define YYUSE(E) ((void) (E)) #else -# define YYUSE(E) /* empty */ +#define YYUSE(E) /* empty */ #endif #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") +#define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +#define YY_IGNORE_MAYBE_UNINITIALIZED_END _Pragma("GCC diagnostic pop") #else -# define YY_INITIAL_VALUE(Value) Value +#define YY_INITIAL_VALUE(Value) Value #endif #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +#define YY_IGNORE_MAYBE_UNINITIALIZED_END #endif #ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif -#if ! defined yyoverflow || YYERROR_VERBOSE +#if !defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ -# ifdef YYSTACK_USE_ALLOCA -# if YYSTACK_USE_ALLOCA -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# elif defined __BUILTIN_VA_ARG_INCR -# include /* INFRINGES ON USER NAME SPACE */ -# elif defined _AIX -# define YYSTACK_ALLOC __alloca -# elif defined _MSC_VER -# include /* INFRINGES ON USER NAME SPACE */ -# define alloca _alloca -# else -# define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS -# include /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's 'empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# ifndef YYSTACK_ALLOC_MAXIMUM - /* The OS might guarantee only one guard page at the bottom of the stack, - and a page size can be as small as 4096 bytes. So we cannot safely - invoke alloca (N) if N exceeds 4096. Use a slightly smaller number - to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ -# endif -# else -# define YYSTACK_ALLOC YYMALLOC -# define YYSTACK_FREE YYFREE -# ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM -# endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) -# include /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# ifndef YYMALLOC -# define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS -void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# ifndef YYFREE -# define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS -void free (void *); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# endif +#ifdef YYSTACK_USE_ALLOCA +#if YYSTACK_USE_ALLOCA +#ifdef __GNUC__ +#define YYSTACK_ALLOC __builtin_alloca +#elif defined __BUILTIN_VA_ARG_INCR +#include /* INFRINGES ON USER NAME SPACE */ +#elif defined _AIX +#define YYSTACK_ALLOC __alloca +#elif defined _MSC_VER +#include /* INFRINGES ON USER NAME SPACE */ +#define alloca _alloca +#else +#define YYSTACK_ALLOC alloca +#if !defined _ALLOCA_H && !defined EXIT_SUCCESS +#include /* INFRINGES ON USER NAME SPACE */ +/* Use EXIT_SUCCESS as a witness for stdlib.h. */ +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#endif +#endif +#endif +#endif + +#ifdef YYSTACK_ALLOC +/* Pacify GCC's 'empty if-body' warning. */ +#define YYSTACK_FREE(Ptr) \ + do \ + { /* empty */ \ + ; \ + } while (0) +#ifndef YYSTACK_ALLOC_MAXIMUM +/* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +#define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +#endif +#else +#define YYSTACK_ALLOC YYMALLOC +#define YYSTACK_FREE YYFREE +#ifndef YYSTACK_ALLOC_MAXIMUM +#define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +#endif +#if ( \ + defined __cplusplus && !defined EXIT_SUCCESS && \ + !((defined YYMALLOC || defined malloc) && \ + (defined YYFREE || defined free))) +#include /* INFRINGES ON USER NAME SPACE */ +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#endif +#ifndef YYMALLOC +#define YYMALLOC malloc +#if !defined malloc && !defined EXIT_SUCCESS +void* malloc(YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +#endif +#endif +#ifndef YYFREE +#define YYFREE free +#if !defined free && !defined EXIT_SUCCESS +void free(void*); /* INFRINGES ON USER NAME SPACE */ +#endif +#endif +#endif #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ -#if (! defined yyoverflow \ - && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) +#if ( \ + !defined yyoverflow && \ + (!defined __cplusplus || \ + (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc @@ -561,536 +565,520 @@ union yyalloc }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +#define YYSTACK_GAP_MAXIMUM (sizeof(union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) +#define YYSTACK_BYTES(N) \ + ((N) * (sizeof(yytype_int16) + sizeof(YYSTYPE)) + YYSTACK_GAP_MAXIMUM) -# define YYCOPY_NEEDED 1 +#define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (0) +#define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY(&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof(*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof(*yyptr); \ + } while (0) #endif #if defined YYCOPY_NEEDED && YYCOPY_NEEDED /* Copy COUNT objects from SRC to DST. The source and destination do not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) -# else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ - while (0) -# endif -# endif +#ifndef YYCOPY +#if defined __GNUC__ && 1 < __GNUC__ +#define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy(Dst, Src, (Count) * sizeof(*(Src))) +#else +#define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) (Dst)[yyi] = (Src)[yyi]; \ + } while (0) +#endif +#endif #endif /* !YYCOPY_NEEDED */ /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 2 +#define YYFINAL 2 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 396 +#define YYLAST 396 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 81 +#define YYNTOKENS 81 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 48 +#define YYNNTS 48 /* YYNRULES -- Number of rules. */ -#define YYNRULES 151 +#define YYNRULES 151 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 252 +#define YYNSTATES 252 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned by yylex, with out-of-bounds checking. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 316 +#define YYUNDEFTOK 2 +#define YYMAXUTOK 316 -#define YYTRANSLATE(YYX) \ +#define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex, without out-of-bounds checking. */ -static const yytype_uint8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 67, 62, 2, - 75, 76, 65, 63, 80, 64, 77, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 73, 2, - 2, 74, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 78, 66, 79, 61, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 71, 60, 72, 68, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, 58, 59, 69, 70 -}; +static const yytype_uint8 yytranslate[] = { + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 67, + 62, 2, 75, 76, 65, 63, 80, 64, 77, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 73, 2, 2, 74, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 78, 66, 79, 61, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 71, 60, 72, 68, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 69, 70}; #if YYDEBUG - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = -{ - 0, 319, 319, 321, 322, 323, 324, 325, 326, 334, - 347, 352, 346, 379, 382, 398, 401, 416, 421, 422, - 427, 428, 434, 437, 453, 462, 504, 505, 510, 527, - 541, 555, 569, 587, 588, 594, 593, 610, 609, 630, - 629, 654, 660, 720, 721, 722, 723, 724, 725, 731, - 752, 783, 788, 805, 810, 830, 831, 845, 846, 847, - 848, 849, 853, 854, 868, 872, 967, 1015, 1076, 1123, - 1124, 1128, 1163, 1216, 1259, 1282, 1288, 1294, 1306, 1316, - 1326, 1336, 1346, 1356, 1366, 1380, 1395, 1406, 1485, 1523, - 1425, 1683, 1682, 1772, 1778, 1785, 1784, 1830, 1829, 1873, - 1880, 1887, 1894, 1901, 1908, 1915, 1919, 1927, 1947, 1975, - 2049, 2077, 2085, 2094, 2118, 2133, 2153, 2152, 2158, 2169, - 2170, 2175, 2182, 2193, 2197, 2202, 2211, 2215, 2223, 2235, - 2249, 2256, 2263, 2288, 2300, 2312, 2327, 2339, 2354, 2397, - 2418, 2453, 2488, 2522, 2547, 2564, 2574, 2584, 2594, 2604, - 2624, 2644 -}; +/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = { + 0, 319, 319, 321, 322, 323, 324, 325, 326, 334, 347, 352, + 346, 379, 382, 398, 401, 416, 421, 422, 427, 428, 434, 437, + 453, 462, 504, 505, 510, 527, 541, 555, 569, 587, 588, 594, + 593, 610, 609, 630, 629, 654, 660, 720, 721, 722, 723, 724, + 725, 731, 752, 783, 788, 805, 810, 830, 831, 845, 846, 847, + 848, 849, 853, 854, 868, 872, 967, 1015, 1076, 1123, 1124, 1128, + 1163, 1216, 1259, 1282, 1288, 1294, 1306, 1316, 1326, 1336, 1346, 1356, + 1366, 1380, 1395, 1406, 1485, 1523, 1425, 1683, 1682, 1772, 1778, 1785, + 1784, 1830, 1829, 1873, 1880, 1887, 1894, 1901, 1908, 1915, 1919, 1927, + 1947, 1975, 2049, 2077, 2085, 2094, 2118, 2133, 2153, 2152, 2158, 2169, + 2170, 2175, 2182, 2193, 2197, 2202, 2211, 2215, 2223, 2235, 2249, 2256, + 2263, 2288, 2300, 2312, 2327, 2339, 2354, 2397, 2418, 2453, 2488, 2522, + 2547, 2564, 2574, 2584, 2594, 2604, 2624, 2644}; #endif #if YYDEBUG || YYERROR_VERBOSE || 0 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "\"end of file\"", "error", "$undefined", "\"end of included file\"", - "\"..\"", "\"\"", "\"\"", "\"\"", "\"\"", - "\"\"", "\"\"", "\"identifier\"", - "\"string identifier\"", "\"string count\"", "\"string offset\"", - "\"string length\"", "\"string identifier with wildcard\"", - "\"integer number\"", "\"floating point number\"", - "\"integer function\"", "\"text string\"", "\"hex string\"", - "\"regular expression\"", "\"\"", "\"\"", "\"\"", - "\"\"", "\"\"", "\"\"", "\"\"", - "\"\"", "\"\"", "\"\"", "\"\"", - "\"\"", "\"\"", "\"\"", "\"\"", "\"\"", - "\"\"", "\"\"", "\"\"", "\"\"", - "\"\"", "\"\"", "\"\"", - "\"\"", "\"\"", "\"\"", "\"\"", - "\"\"", "\"==\"", "\"!=\"", "\"<\"", "\"<=\"", "\">\"", "\">=\"", - "\"<<\"", "\">>\"", "'|'", "'^'", "'&'", "'+'", "'-'", "'*'", "'\\\\'", - "'%'", "'~'", "UNARY_MINUS", "\"include\"", "'{'", "'}'", "':'", "'='", - "'('", "')'", "'.'", "'['", "']'", "','", "$accept", "rules", "import", - "rule", "@1", "$@2", "meta", "strings", "condition", "rule_modifiers", - "rule_modifier", "tags", "tag_list", "meta_declarations", - "meta_declaration", "string_declarations", "string_declaration", "$@3", - "$@4", "$@5", "string_modifiers", "string_modifier", "regexp_modifiers", - "regexp_modifier", "hex_modifiers", "hex_modifier", "identifier", - "arguments", "arguments_list", "regexp", "boolean_expression", - "expression", "$@6", "$@7", "$@8", "$@9", "$@10", "for_variables", - "iterator", "integer_set", "range", "integer_enumeration", "string_set", - "$@11", "string_enumeration", "string_enumeration_item", - "for_expression", "primary_expression", YY_NULLPTR -}; +static const char* const yytname[] = { + "\"end of file\"", + "error", + "$undefined", + "\"end of included file\"", + "\"..\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"identifier\"", + "\"string identifier\"", + "\"string count\"", + "\"string offset\"", + "\"string length\"", + "\"string identifier with wildcard\"", + "\"integer number\"", + "\"floating point number\"", + "\"integer function\"", + "\"text string\"", + "\"hex string\"", + "\"regular expression\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"\"", + "\"==\"", + "\"!=\"", + "\"<\"", + "\"<=\"", + "\">\"", + "\">=\"", + "\"<<\"", + "\">>\"", + "'|'", + "'^'", + "'&'", + "'+'", + "'-'", + "'*'", + "'\\\\'", + "'%'", + "'~'", + "UNARY_MINUS", + "\"include\"", + "'{'", + "'}'", + "':'", + "'='", + "'('", + "')'", + "'.'", + "'['", + "']'", + "','", + "$accept", + "rules", + "import", + "rule", + "@1", + "$@2", + "meta", + "strings", + "condition", + "rule_modifiers", + "rule_modifier", + "tags", + "tag_list", + "meta_declarations", + "meta_declaration", + "string_declarations", + "string_declaration", + "$@3", + "$@4", + "$@5", + "string_modifiers", + "string_modifier", + "regexp_modifiers", + "regexp_modifier", + "hex_modifiers", + "hex_modifier", + "identifier", + "arguments", + "arguments_list", + "regexp", + "boolean_expression", + "expression", + "$@6", + "$@7", + "$@8", + "$@9", + "$@10", + "for_variables", + "iterator", + "integer_set", + "range", + "integer_enumeration", + "string_set", + "$@11", + "string_enumeration", + "string_enumeration_item", + "for_expression", + "primary_expression", + YY_NULLPTR}; #endif -# ifdef YYPRINT +#ifdef YYPRINT /* YYTOKNUM[NUM] -- (External) token number corresponding to the (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, - 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 124, 94, 38, 43, 45, 42, 92, 37, 126, 315, - 316, 123, 125, 58, 61, 40, 41, 46, 91, 93, - 44 -}; -# endif +static const yytype_uint16 yytoknum[] = { + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, + 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, + 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, 124, 94, 38, 43, 45, 42, 92, 37, 126, 315, + 316, 123, 125, 58, 61, 40, 41, 46, 91, 93, 44}; +#endif #define YYPACT_NINF -74 -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-74))) +#define yypact_value_is_default(Yystate) (!!((Yystate) == (-74))) #define YYTABLE_NINF -124 -#define yytable_value_is_error(Yytable_value) \ - 0 - - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -static const yytype_int16 yypact[] = -{ - -74, 153, -74, -34, -74, -4, -74, -74, 114, -74, - -74, -74, -74, 7, -74, -74, -74, -74, -36, 16, - -8, -74, 73, 62, -74, 30, 107, 98, 50, -74, - 56, 98, -74, 124, 122, 14, -74, 70, 124, -74, - 94, 117, -74, -74, -74, -74, 152, 59, -74, 54, - -74, -74, 176, 190, 177, -74, -6, -74, 119, 135, - -74, -74, 151, -74, -74, -74, -74, -74, -74, 93, - -74, -74, 54, 120, 120, 54, 68, -74, 100, -74, - 207, 213, -74, -74, -74, 120, 169, 120, 120, 120, - 120, 81, 329, -74, -74, -74, 100, 170, 175, 54, - 234, 120, -74, -74, 39, 225, 120, 120, 120, 120, - 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, - 120, 120, 120, 120, 120, 120, 120, 120, 258, 142, - 242, 329, 120, -74, 230, 240, 272, 291, -74, 39, - 239, -74, -74, 183, 180, 123, -74, 262, 54, 54, - -74, -74, -74, -74, 329, 329, 329, 329, 329, 329, - 329, 329, 329, 329, 329, 329, 158, 158, 116, 31, - 127, 97, 97, -74, -74, -74, -74, -74, -74, 186, - 187, 188, -74, -74, -74, -74, -74, -74, -74, -74, - -74, -74, -74, 143, -74, -74, -74, 235, -74, -20, - -74, 54, -74, 260, -74, -2, 294, 292, 293, 120, - -74, 0, 303, 123, -74, -74, -48, -74, -51, 241, - 264, 310, 243, 120, 68, 269, -74, -74, -74, -74, - -2, 298, -74, -74, -74, -74, 54, 3, 143, -74, - -74, 267, -46, -74, 120, 270, -74, -74, 329, 54, - -41, -74 -}; - - /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 2, 0, 1, 18, 8, 0, 4, 3, 0, 7, - 6, 5, 9, 0, 20, 21, 19, 10, 22, 0, - 0, 24, 23, 13, 25, 0, 15, 0, 0, 11, - 0, 14, 26, 0, 0, 0, 27, 0, 16, 33, - 0, 0, 29, 28, 31, 32, 0, 35, 34, 0, - 12, 30, 0, 0, 0, 65, 84, 133, 135, 137, - 130, 131, 0, 132, 73, 127, 128, 124, 125, 0, - 75, 76, 0, 0, 0, 0, 138, 151, 17, 74, - 0, 105, 41, 55, 62, 0, 0, 0, 0, 0, - 0, 0, 123, 94, 139, 148, 0, 74, 105, 69, - 0, 0, 97, 95, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 36, 38, - 40, 85, 0, 86, 0, 0, 0, 0, 87, 0, - 0, 106, 126, 0, 70, 71, 66, 0, 0, 0, - 118, 116, 93, 77, 78, 80, 82, 79, 81, 83, - 103, 104, 99, 101, 100, 102, 149, 150, 147, 145, - 146, 140, 141, 142, 143, 144, 47, 44, 43, 48, - 51, 53, 45, 46, 42, 61, 58, 57, 59, 60, - 56, 64, 63, 0, 134, 136, 129, 0, 107, 0, - 68, 0, 67, 98, 96, 0, 0, 0, 0, 0, - 91, 0, 0, 72, 121, 122, 0, 119, 0, 0, - 0, 0, 0, 0, 109, 0, 110, 112, 108, 117, - 0, 0, 49, 52, 54, 113, 0, 0, 114, 89, - 120, 0, 0, 111, 0, 0, 50, 92, 115, 0, - 0, 90 -}; - - /* YYPGOTO[NTERM-NUM]. */ -static const yytype_int16 yypgoto[] = -{ - -74, -74, 313, 341, -74, -74, -74, -74, -74, -74, - -74, -74, -74, -74, 315, -74, 309, -74, -74, -74, - -74, -74, -74, -74, -74, -74, 148, -74, -74, 255, - -49, -73, -74, -74, -74, -74, -74, -74, -74, -74, - 150, -74, 223, -74, -74, 133, 295, -68 -}; - - /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int16 yydefgoto[] = -{ - -1, 1, 6, 7, 18, 34, 26, 29, 41, 8, - 16, 20, 22, 31, 32, 38, 39, 52, 53, 54, - 128, 184, 129, 190, 130, 192, 76, 143, 144, 77, - 96, 79, 140, 245, 222, 149, 148, 199, 225, 226, - 133, 237, 152, 205, 216, 217, 80, 81 -}; - - /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_int16 yytable[] = -{ - 78, 92, 97, 102, 103, 94, 95, 98, 102, 103, - 214, 55, 5, 231, 215, 211, 12, 131, 17, 134, - 135, 136, 137, 93, 85, 232, 145, 21, 229, 86, - 247, 42, 230, 147, 43, 251, 9, 19, 154, 155, - 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, - 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, - 212, 44, 45, 23, 193, 55, 56, 57, 58, 59, - 25, 60, 61, 62, 63, 223, 64, 150, 46, 243, - -39, -37, 138, 244, 24, 65, 66, 67, 68, 118, - 119, 69, -88, 122, 123, 124, 125, 126, 127, 203, - 204, 70, 71, 27, 55, 72, 57, 58, 59, 30, - 60, 61, 62, 63, 151, 64, 28, 139, 73, 13, - 14, 15, 74, 33, 65, 66, 67, 68, 213, 75, - 35, 55, 40, 57, 58, 59, 37, 60, 61, 62, - 63, 221, 64, 99, 47, 100, 101, 209, 185, 102, - 103, 65, 66, 2, 3, 238, 4, 73, -18, -18, - -18, 74, 125, 126, 127, 186, 187, 49, 90, 51, - 188, 189, -74, -74, 118, 119, 248, 121, 122, 123, - 124, 125, 126, 127, 73, 118, 119, 242, 74, 50, - 123, 124, 125, 126, 127, 90, 82, 87, 84, 5, - 250, 118, 119, 120, 121, 122, 123, 124, 125, 126, - 127, -123, 83, 88, 105, 106, 107, 108, 109, 110, - 111, 123, 124, 125, 126, 127, 89, 112, 113, 114, - 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, - 125, 126, 127, 104, 132, 146, 141, 64, 191, -123, - 198, 142, 105, 106, 107, 108, 109, 110, 111, 200, - 201, 206, 207, 208, 176, 112, 113, 114, 115, 116, - 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, - 127, 177, 178, 179, 180, 181, 182, 183, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 127, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 127, 210, 194, - 103, 218, 219, 220, 228, 241, 10, 233, 236, 195, - 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, - 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, - 234, 202, 239, 246, 11, 249, 36, 48, 196, 118, - 119, 120, 121, 122, 123, 124, 125, 126, 127, 224, - 153, 227, 197, 240, 91, 0, 0, 142, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 127, 0, 0, - 0, 0, 0, 0, 0, 0, 235, 118, 119, 120, - 121, 122, 123, 124, 125, 126, 127 -}; - -static const yytype_int16 yycheck[] = -{ - 49, 69, 75, 49, 50, 73, 74, 75, 49, 50, - 12, 11, 46, 64, 16, 35, 20, 85, 11, 87, - 88, 89, 90, 72, 30, 76, 99, 11, 76, 35, - 76, 17, 80, 101, 20, 76, 70, 73, 106, 107, - 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, - 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, - 80, 47, 48, 71, 132, 11, 12, 13, 14, 15, - 8, 17, 18, 19, 20, 75, 22, 38, 64, 76, - 21, 22, 1, 80, 11, 31, 32, 33, 34, 58, - 59, 37, 11, 62, 63, 64, 65, 66, 67, 148, - 149, 47, 48, 73, 11, 51, 13, 14, 15, 11, - 17, 18, 19, 20, 75, 22, 9, 36, 64, 5, - 6, 7, 68, 73, 31, 32, 33, 34, 201, 75, - 74, 11, 10, 13, 14, 15, 12, 17, 18, 19, - 20, 209, 22, 75, 74, 77, 78, 4, 6, 49, - 50, 31, 32, 0, 1, 223, 3, 64, 5, 6, - 7, 68, 65, 66, 67, 23, 24, 73, 75, 17, - 28, 29, 49, 50, 58, 59, 244, 61, 62, 63, - 64, 65, 66, 67, 64, 58, 59, 236, 68, 72, - 63, 64, 65, 66, 67, 75, 20, 78, 21, 46, - 249, 58, 59, 60, 61, 62, 63, 64, 65, 66, - 67, 36, 22, 78, 39, 40, 41, 42, 43, 44, - 45, 63, 64, 65, 66, 67, 75, 52, 53, 54, - 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 36, 75, 11, 76, 22, 6, 36, - 11, 76, 39, 40, 41, 42, 43, 44, 45, 76, - 80, 75, 75, 75, 6, 52, 53, 54, 55, 56, - 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, - 67, 23, 24, 25, 26, 27, 28, 29, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, 73, 79, - 50, 17, 20, 20, 11, 17, 3, 76, 75, 79, - 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, - 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, - 76, 79, 73, 76, 3, 75, 31, 38, 76, 58, - 59, 60, 61, 62, 63, 64, 65, 66, 67, 211, - 105, 211, 139, 230, 69, -1, -1, 76, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, -1, -1, - -1, -1, -1, -1, -1, -1, 76, 58, 59, 60, - 61, 62, 63, 64, 65, 66, 67 -}; - - /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = -{ - 0, 82, 0, 1, 3, 46, 83, 84, 90, 70, - 83, 84, 20, 5, 6, 7, 91, 11, 85, 73, - 92, 11, 93, 71, 11, 8, 87, 73, 9, 88, - 11, 94, 95, 73, 86, 74, 95, 12, 96, 97, - 10, 89, 17, 20, 47, 48, 64, 74, 97, 73, - 72, 17, 98, 99, 100, 11, 12, 13, 14, 15, - 17, 18, 19, 20, 22, 31, 32, 33, 34, 37, - 47, 48, 51, 64, 68, 75, 107, 110, 111, 112, - 127, 128, 20, 22, 21, 30, 35, 78, 78, 75, - 75, 127, 128, 111, 128, 128, 111, 112, 128, 75, - 77, 78, 49, 50, 36, 39, 40, 41, 42, 43, - 44, 45, 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, 101, 103, - 105, 128, 75, 121, 128, 128, 128, 128, 1, 36, - 113, 76, 76, 108, 109, 112, 11, 128, 117, 116, - 38, 75, 123, 110, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 6, 23, 24, 25, - 26, 27, 28, 29, 102, 6, 23, 24, 28, 29, - 104, 6, 106, 128, 79, 79, 76, 123, 11, 118, - 76, 80, 79, 111, 111, 124, 75, 75, 75, 4, - 73, 35, 80, 112, 12, 16, 125, 126, 17, 20, - 20, 128, 115, 75, 107, 119, 120, 121, 11, 76, - 80, 64, 76, 76, 76, 76, 75, 122, 128, 73, - 126, 17, 111, 76, 80, 114, 76, 76, 128, 75, - 111, 76 -}; - - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 81, 82, 82, 82, 82, 82, 82, 82, 83, - 85, 86, 84, 87, 87, 88, 88, 89, 90, 90, - 91, 91, 92, 92, 93, 93, 94, 94, 95, 95, - 95, 95, 95, 96, 96, 98, 97, 99, 97, 100, - 97, 101, 101, 102, 102, 102, 102, 102, 102, 102, - 102, 102, 102, 102, 102, 103, 103, 104, 104, 104, - 104, 104, 105, 105, 106, 107, 107, 107, 107, 108, - 108, 109, 109, 110, 111, 112, 112, 112, 112, 112, - 112, 112, 112, 112, 112, 112, 112, 112, 113, 114, - 112, 115, 112, 112, 112, 116, 112, 117, 112, 112, - 112, 112, 112, 112, 112, 112, 112, 118, 118, 119, - 119, 120, 120, 121, 122, 122, 124, 123, 123, 125, - 125, 126, 126, 127, 127, 127, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128 -}; - - /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 0, 2, 2, 3, 3, 3, 2, 2, - 0, 0, 11, 0, 3, 0, 3, 3, 0, 2, - 1, 1, 0, 2, 1, 2, 1, 2, 3, 3, - 4, 3, 3, 1, 2, 0, 5, 0, 5, 0, - 5, 0, 2, 1, 1, 1, 1, 1, 1, 4, - 6, 1, 4, 1, 4, 0, 2, 1, 1, 1, - 1, 1, 0, 2, 1, 1, 3, 4, 4, 0, - 1, 1, 3, 1, 1, 1, 1, 3, 3, 3, - 3, 3, 3, 3, 1, 3, 3, 3, 0, 0, - 11, 0, 9, 3, 2, 0, 4, 0, 4, 3, - 3, 3, 3, 3, 3, 1, 3, 1, 3, 1, - 1, 3, 1, 5, 1, 3, 0, 4, 1, 1, - 3, 1, 1, 1, 1, 1, 3, 1, 1, 4, - 1, 1, 1, 1, 4, 1, 4, 1, 1, 2, - 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, - 3, 1 -}; - - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab - - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (yyscanner, compiler, YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (0) +#define yytable_value_is_error(Yytable_value) 0 + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int16 yypact[] = { + -74, 153, -74, -34, -74, -4, -74, -74, 114, -74, -74, -74, -74, 7, -74, + -74, -74, -74, -36, 16, -8, -74, 73, 62, -74, 30, 107, 98, 50, -74, + 56, 98, -74, 124, 122, 14, -74, 70, 124, -74, 94, 117, -74, -74, -74, + -74, 152, 59, -74, 54, -74, -74, 176, 190, 177, -74, -6, -74, 119, 135, + -74, -74, 151, -74, -74, -74, -74, -74, -74, 93, -74, -74, 54, 120, 120, + 54, 68, -74, 100, -74, 207, 213, -74, -74, -74, 120, 169, 120, 120, 120, + 120, 81, 329, -74, -74, -74, 100, 170, 175, 54, 234, 120, -74, -74, 39, + 225, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, + 120, 120, 120, 120, 120, 120, 120, 120, 258, 142, 242, 329, 120, -74, 230, + 240, 272, 291, -74, 39, 239, -74, -74, 183, 180, 123, -74, 262, 54, 54, + -74, -74, -74, -74, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, + 329, 158, 158, 116, 31, 127, 97, 97, -74, -74, -74, -74, -74, -74, 186, + 187, 188, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, 143, -74, + -74, -74, 235, -74, -20, -74, 54, -74, 260, -74, -2, 294, 292, 293, 120, + -74, 0, 303, 123, -74, -74, -48, -74, -51, 241, 264, 310, 243, 120, 68, + 269, -74, -74, -74, -74, -2, 298, -74, -74, -74, -74, 54, 3, 143, -74, + -74, 267, -46, -74, 120, 270, -74, -74, 329, 54, -41, -74}; + +/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = { + 2, 0, 1, 18, 8, 0, 4, 3, 0, 7, 6, 5, 9, 0, 20, + 21, 19, 10, 22, 0, 0, 24, 23, 13, 25, 0, 15, 0, 0, 11, + 0, 14, 26, 0, 0, 0, 27, 0, 16, 33, 0, 0, 29, 28, 31, + 32, 0, 35, 34, 0, 12, 30, 0, 0, 0, 65, 84, 133, 135, 137, + 130, 131, 0, 132, 73, 127, 128, 124, 125, 0, 75, 76, 0, 0, 0, + 0, 138, 151, 17, 74, 0, 105, 41, 55, 62, 0, 0, 0, 0, 0, + 0, 0, 123, 94, 139, 148, 0, 74, 105, 69, 0, 0, 97, 95, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 36, 38, 40, 85, 0, 86, 0, + 0, 0, 0, 87, 0, 0, 106, 126, 0, 70, 71, 66, 0, 0, 0, + 118, 116, 93, 77, 78, 80, 82, 79, 81, 83, 103, 104, 99, 101, 100, + 102, 149, 150, 147, 145, 146, 140, 141, 142, 143, 144, 47, 44, 43, 48, + 51, 53, 45, 46, 42, 61, 58, 57, 59, 60, 56, 64, 63, 0, 134, + 136, 129, 0, 107, 0, 68, 0, 67, 98, 96, 0, 0, 0, 0, 0, + 91, 0, 0, 72, 121, 122, 0, 119, 0, 0, 0, 0, 0, 0, 109, + 0, 110, 112, 108, 117, 0, 0, 49, 52, 54, 113, 0, 0, 114, 89, + 120, 0, 0, 111, 0, 0, 50, 92, 115, 0, 0, 90}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = { + -74, -74, 313, 341, -74, -74, -74, -74, -74, -74, -74, -74, + -74, -74, 315, -74, 309, -74, -74, -74, -74, -74, -74, -74, + -74, -74, 148, -74, -74, 255, -49, -73, -74, -74, -74, -74, + -74, -74, -74, -74, 150, -74, 223, -74, -74, 133, 295, -68}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = { + -1, 1, 6, 7, 18, 34, 26, 29, 41, 8, 16, 20, + 22, 31, 32, 38, 39, 52, 53, 54, 128, 184, 129, 190, + 130, 192, 76, 143, 144, 77, 96, 79, 140, 245, 222, 149, + 148, 199, 225, 226, 133, 237, 152, 205, 216, 217, 80, 81}; + +/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_int16 yytable[] = { + 78, 92, 97, 102, 103, 94, 95, 98, 102, 103, 214, 55, 5, 231, 215, + 211, 12, 131, 17, 134, 135, 136, 137, 93, 85, 232, 145, 21, 229, 86, + 247, 42, 230, 147, 43, 251, 9, 19, 154, 155, 156, 157, 158, 159, 160, + 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, + 212, 44, 45, 23, 193, 55, 56, 57, 58, 59, 25, 60, 61, 62, 63, + 223, 64, 150, 46, 243, -39, -37, 138, 244, 24, 65, 66, 67, 68, 118, + 119, 69, -88, 122, 123, 124, 125, 126, 127, 203, 204, 70, 71, 27, 55, + 72, 57, 58, 59, 30, 60, 61, 62, 63, 151, 64, 28, 139, 73, 13, + 14, 15, 74, 33, 65, 66, 67, 68, 213, 75, 35, 55, 40, 57, 58, + 59, 37, 60, 61, 62, 63, 221, 64, 99, 47, 100, 101, 209, 185, 102, + 103, 65, 66, 2, 3, 238, 4, 73, -18, -18, -18, 74, 125, 126, 127, + 186, 187, 49, 90, 51, 188, 189, -74, -74, 118, 119, 248, 121, 122, 123, + 124, 125, 126, 127, 73, 118, 119, 242, 74, 50, 123, 124, 125, 126, 127, + 90, 82, 87, 84, 5, 250, 118, 119, 120, 121, 122, 123, 124, 125, 126, + 127, -123, 83, 88, 105, 106, 107, 108, 109, 110, 111, 123, 124, 125, 126, + 127, 89, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, + 125, 126, 127, 104, 132, 146, 141, 64, 191, -123, 198, 142, 105, 106, 107, + 108, 109, 110, 111, 200, 201, 206, 207, 208, 176, 112, 113, 114, 115, 116, + 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 177, 178, 179, 180, + 181, 182, 183, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 127, 210, 194, 103, 218, 219, 220, 228, + 241, 10, 233, 236, 195, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 234, 202, 239, 246, 11, + 249, 36, 48, 196, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 224, + 153, 227, 197, 240, 91, 0, 0, 142, 118, 119, 120, 121, 122, 123, 124, + 125, 126, 127, 0, 0, 0, 0, 0, 0, 0, 0, 235, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127}; + +static const yytype_int16 yycheck[] = { + 49, 69, 75, 49, 50, 73, 74, 75, 49, 50, 12, 11, 46, 64, 16, + 35, 20, 85, 11, 87, 88, 89, 90, 72, 30, 76, 99, 11, 76, 35, + 76, 17, 80, 101, 20, 76, 70, 73, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 80, 47, 48, 71, 132, 11, 12, 13, 14, 15, 8, 17, 18, 19, 20, + 75, 22, 38, 64, 76, 21, 22, 1, 80, 11, 31, 32, 33, 34, 58, + 59, 37, 11, 62, 63, 64, 65, 66, 67, 148, 149, 47, 48, 73, 11, + 51, 13, 14, 15, 11, 17, 18, 19, 20, 75, 22, 9, 36, 64, 5, + 6, 7, 68, 73, 31, 32, 33, 34, 201, 75, 74, 11, 10, 13, 14, + 15, 12, 17, 18, 19, 20, 209, 22, 75, 74, 77, 78, 4, 6, 49, + 50, 31, 32, 0, 1, 223, 3, 64, 5, 6, 7, 68, 65, 66, 67, + 23, 24, 73, 75, 17, 28, 29, 49, 50, 58, 59, 244, 61, 62, 63, + 64, 65, 66, 67, 64, 58, 59, 236, 68, 72, 63, 64, 65, 66, 67, + 75, 20, 78, 21, 46, 249, 58, 59, 60, 61, 62, 63, 64, 65, 66, + 67, 36, 22, 78, 39, 40, 41, 42, 43, 44, 45, 63, 64, 65, 66, + 67, 75, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 36, 75, 11, 76, 22, 6, 36, 11, 76, 39, 40, 41, + 42, 43, 44, 45, 76, 80, 75, 75, 75, 6, 52, 53, 54, 55, 56, + 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 23, 24, 25, 26, + 27, 28, 29, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 73, 79, 50, 17, 20, 20, 11, + 17, 3, 76, 75, 79, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 76, 79, 73, 76, 3, + 75, 31, 38, 76, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 211, + 105, 211, 139, 230, 69, -1, -1, 76, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, -1, -1, -1, -1, -1, -1, -1, -1, 76, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = { + 0, 82, 0, 1, 3, 46, 83, 84, 90, 70, 83, 84, 20, 5, 6, + 7, 91, 11, 85, 73, 92, 11, 93, 71, 11, 8, 87, 73, 9, 88, + 11, 94, 95, 73, 86, 74, 95, 12, 96, 97, 10, 89, 17, 20, 47, + 48, 64, 74, 97, 73, 72, 17, 98, 99, 100, 11, 12, 13, 14, 15, + 17, 18, 19, 20, 22, 31, 32, 33, 34, 37, 47, 48, 51, 64, 68, + 75, 107, 110, 111, 112, 127, 128, 20, 22, 21, 30, 35, 78, 78, 75, + 75, 127, 128, 111, 128, 128, 111, 112, 128, 75, 77, 78, 49, 50, 36, + 39, 40, 41, 42, 43, 44, 45, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 101, 103, 105, 128, 75, 121, 128, + 128, 128, 128, 1, 36, 113, 76, 76, 108, 109, 112, 11, 128, 117, 116, + 38, 75, 123, 110, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 6, 23, 24, 25, + 26, 27, 28, 29, 102, 6, 23, 24, 28, 29, 104, 6, 106, 128, 79, + 79, 76, 123, 11, 118, 76, 80, 79, 111, 111, 124, 75, 75, 75, 4, + 73, 35, 80, 112, 12, 16, 125, 126, 17, 20, 20, 128, 115, 75, 107, + 119, 120, 121, 11, 76, 80, 64, 76, 76, 76, 76, 75, 122, 128, 73, + 126, 17, 111, 76, 80, 114, 76, 76, 128, 75, 111, 76}; + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = { + 0, 81, 82, 82, 82, 82, 82, 82, 82, 83, 85, 86, 84, 87, + 87, 88, 88, 89, 90, 90, 91, 91, 92, 92, 93, 93, 94, 94, + 95, 95, 95, 95, 95, 96, 96, 98, 97, 99, 97, 100, 97, 101, + 101, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 103, + 103, 104, 104, 104, 104, 104, 105, 105, 106, 107, 107, 107, 107, 108, + 108, 109, 109, 110, 111, 112, 112, 112, 112, 112, 112, 112, 112, 112, + 112, 112, 112, 112, 113, 114, 112, 115, 112, 112, 112, 116, 112, 117, + 112, 112, 112, 112, 112, 112, 112, 112, 112, 118, 118, 119, 119, 120, + 120, 121, 122, 122, 124, 123, 123, 125, 125, 126, 126, 127, 127, 127, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}; + +/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = { + 0, 2, 0, 2, 2, 3, 3, 3, 2, 2, 0, 0, 11, 0, 3, 0, 3, 3, 0, 2, 1, 1, + 0, 2, 1, 2, 1, 2, 3, 3, 4, 3, 3, 1, 2, 0, 5, 0, 5, 0, 5, 0, 2, 1, + 1, 1, 1, 1, 1, 4, 6, 1, 4, 1, 4, 0, 2, 1, 1, 1, 1, 1, 0, 2, 1, 1, + 3, 4, 4, 0, 1, 1, 3, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, + 0, 0, 11, 0, 9, 3, 2, 0, 4, 0, 4, 3, 3, 3, 3, 3, 3, 1, 3, 1, 3, 1, + 1, 3, 1, 5, 1, 3, 0, 4, 1, 1, 3, 1, 1, 1, 1, 1, 3, 1, 1, 4, 1, 1, + 1, 1, 4, 1, 4, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 1}; + + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK(yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror(yyscanner, compiler, YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) /* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - +#define YYTERROR 1 +#define YYERRCODE 256 /* Enable debugging if requested. */ #if YYDEBUG -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif +#ifndef YYFPRINTF +#include /* INFRINGES ON USER NAME SPACE */ +#define YYFPRINTF fprintf +#endif -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) +#define YYDPRINTF(Args) \ + do \ + { \ + if (yydebug) \ + YYFPRINTF Args; \ + } while (0) /* This macro is provided for backward compatibility. */ #ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#define YY_LOCATION_PRINT(File, Loc) ((void) 0) #endif -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value, yyscanner, compiler); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) +#define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ + do \ + { \ + if (yydebug) \ + { \ + YYFPRINTF(stderr, "%s ", Title); \ + yy_symbol_print(stderr, Type, Value, yyscanner, compiler); \ + YYFPRINTF(stderr, "\n"); \ + } \ + } while (0) /*----------------------------------------. | Print this symbol's value on YYOUTPUT. | `----------------------------------------*/ -static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *yyscanner, YR_COMPILER* compiler) +static void yy_symbol_value_print( + FILE* yyoutput, + int yytype, + YYSTYPE const* const yyvaluep, + void* yyscanner, + YR_COMPILER* compiler) { - FILE *yyo = yyoutput; - YYUSE (yyo); - YYUSE (yyscanner); - YYUSE (compiler); + FILE* yyo = yyoutput; + YYUSE(yyo); + YYUSE(yyscanner); + YYUSE(compiler); if (!yyvaluep) return; -# ifdef YYPRINT +#ifdef YYPRINT if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - YYUSE (yytype); + YYPRINT(yyoutput, yytoknum[yytype], *yyvaluep); +#endif + YYUSE(yytype); } @@ -1098,14 +1086,21 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue | Print this symbol on YYOUTPUT. | `--------------------------------*/ -static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *yyscanner, YR_COMPILER* compiler) +static void yy_symbol_print( + FILE* yyoutput, + int yytype, + YYSTYPE const* const yyvaluep, + void* yyscanner, + YR_COMPILER* compiler) { - YYFPRINTF (yyoutput, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); - - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yyscanner, compiler); - YYFPRINTF (yyoutput, ")"); + YYFPRINTF( + yyoutput, + "%s %s (", + yytype < YYNTOKENS ? "token" : "nterm", + yytname[yytype]); + + yy_symbol_value_print(yyoutput, yytype, yyvaluep, yyscanner, compiler); + YYFPRINTF(yyoutput, ")"); } /*------------------------------------------------------------------. @@ -1113,69 +1108,76 @@ yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, voi | TOP (included). | `------------------------------------------------------------------*/ -static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +static void yy_stack_print(yytype_int16* yybottom, yytype_int16* yytop) { - YYFPRINTF (stderr, "Stack now"); + YYFPRINTF(stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) - { - int yybot = *yybottom; - YYFPRINTF (stderr, " %d", yybot); - } - YYFPRINTF (stderr, "\n"); + { + int yybot = *yybottom; + YYFPRINTF(stderr, " %d", yybot); + } + YYFPRINTF(stderr, "\n"); } -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (0) +#define YY_STACK_PRINT(Bottom, Top) \ + do \ + { \ + if (yydebug) \ + yy_stack_print((Bottom), (Top)); \ + } while (0) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, void *yyscanner, YR_COMPILER* compiler) +static void yy_reduce_print( + yytype_int16* yyssp, + YYSTYPE* yyvsp, + int yyrule, + void* yyscanner, + YR_COMPILER* compiler) { unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); + YYFPRINTF( + stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) - { - YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &(yyvsp[(yyi + 1) - (yynrhs)]) - , yyscanner, compiler); - YYFPRINTF (stderr, "\n"); - } + { + YYFPRINTF(stderr, " $%d = ", yyi + 1); + yy_symbol_print( + stderr, + yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)]), + yyscanner, + compiler); + YYFPRINTF(stderr, "\n"); + } } -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, Rule, yyscanner, compiler); \ -} while (0) +#define YY_REDUCE_PRINT(Rule) \ + do \ + { \ + if (yydebug) \ + yy_reduce_print(yyssp, yyvsp, Rule, yyscanner, compiler); \ + } while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) +#define YYDPRINTF(Args) +#define YY_SYMBOL_PRINT(Title, Type, Value, Location) +#define YY_STACK_PRINT(Bottom, Top) +#define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH -# define YYINITDEPTH 200 +#define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only @@ -1186,49 +1188,45 @@ int yydebug; evaluated with infinite-precision integer arithmetic. */ #ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 +#define YYMAXDEPTH 10000 #endif #if YYERROR_VERBOSE -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else +#ifndef yystrlen +#if defined __GLIBC__ && defined _STRING_H +#define yystrlen strlen +#else /* Return the length of YYSTR. */ -static YYSIZE_T -yystrlen (const char *yystr) +static YYSIZE_T yystrlen(const char* yystr) { YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; + for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; } -# endif -# endif +#endif +#endif -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else +#ifndef yystpcpy +#if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +#define yystpcpy stpcpy +#else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ -static char * -yystpcpy (char *yydest, const char *yysrc) +static char* yystpcpy(char* yydest, const char* yysrc) { - char *yyd = yydest; - const char *yys = yysrc; + char* yyd = yydest; + const char* yys = yysrc; - while ((*yyd++ = *yys++) != '\0') - continue; + while ((*yyd++ = *yys++) != '\0') continue; return yyd - 1; } -# endif -# endif +#endif +#endif -# ifndef yytnamerr +#ifndef yytnamerr /* Copy to YYRES the contents of YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is that double-quoting is unnecessary unless the string @@ -1236,45 +1234,43 @@ yystpcpy (char *yydest, const char *yysrc) backslash-backslash). YYSTR is taken from yytname. If YYRES is null, do not copy; instead, return the length of what the result would have been. */ -static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) +static YYSIZE_T yytnamerr(char* yyres, const char* yystr) { if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; + { + YYSIZE_T yyn = 0; + char const* yyp = yystr; - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; + for (;;) switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes:; + } - if (! yyres) - return yystrlen (yystr); + if (!yyres) + return yystrlen(yystr); - return yystpcpy (yyres, yystr) - yyres; + return yystpcpy(yyres, yystr) - yyres; } -# endif +#endif /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message about the unexpected token YYTOKEN for the state stack whose top is @@ -1284,17 +1280,22 @@ yytnamerr (char *yyres, const char *yystr) not large enough to hold the message. In that case, also set *YYMSG_ALLOC to the required number of bytes. Return 2 if the required number of bytes is too large to store. */ -static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) +static int yysyntax_error( + YYSIZE_T* yymsg_alloc, + char** yymsg, + yytype_int16* yyssp, + int yytoken) { - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + YYSIZE_T yysize0 = yytnamerr(YY_NULLPTR, yytname[yytoken]); YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + enum + { + YYERROR_VERBOSE_ARGS_MAXIMUM = 5 + }; /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; + const char* yyformat = YY_NULLPTR; /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + char const* yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; /* Number of reported tokens (one for the "unexpected", one per "expected"). */ int yycount = 0; @@ -1323,91 +1324,90 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, accepted due to an error action in a later state. */ if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default(yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR && + !yytable_value_is_error(yytable[yyx + yyn])) { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = yysize + yytnamerr(YY_NULLPTR, yytname[yyx]); + if (!(yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } } } + } switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - default: /* Avoid compiler warnings. */ - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: /* Avoid compiler warnings. */ + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_( + 5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + YYSIZE_T yysize1 = yysize + yystrlen(yyformat); + if (!(yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) return 2; yysize = yysize1; } if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } + { + *yymsg_alloc = 2 * yysize; + if (!(yysize <= *yymsg_alloc && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } /* Avoid sprintf, as that infringes on the user's name space. Don't have undefined behavior even if the translation produced a string with the wrong number of "%s"s. */ { - char *yyp = *yymsg; + char* yyp = *yymsg; int yyi = 0; while ((*yyp = *yyformat) != '\0') if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } + { + yyp += yytnamerr(yyp, yyarg[yyi++]); + yyformat += 2; + } else - { - yyp++; - yyformat++; - } + { + yyp++; + yyformat++; + } } return 0; } @@ -1417,161 +1417,195 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, | Release the memory associated to this symbol. | `-----------------------------------------------*/ -static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, void *yyscanner, YR_COMPILER* compiler) +static void yydestruct( + const char* yymsg, + int yytype, + YYSTYPE* yyvaluep, + void* yyscanner, + YR_COMPILER* compiler) { - YYUSE (yyvaluep); - YYUSE (yyscanner); - YYUSE (compiler); + YYUSE(yyvaluep); + YYUSE(yyscanner); + YYUSE(compiler); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT(yymsg, yytype, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN switch (yytype) - { - case 11: /* "identifier" */ + { + case 11: /* "identifier" */ #line 272 "grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; } + { + yr_free(((*yyvaluep).c_string)); + ((*yyvaluep).c_string) = NULL; + } #line 1437 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 12: /* "string identifier" */ + case 12: /* "string identifier" */ #line 276 "grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; } + { + yr_free(((*yyvaluep).c_string)); + ((*yyvaluep).c_string) = NULL; + } #line 1443 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 13: /* "string count" */ + case 13: /* "string count" */ #line 273 "grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; } + { + yr_free(((*yyvaluep).c_string)); + ((*yyvaluep).c_string) = NULL; + } #line 1449 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 14: /* "string offset" */ + case 14: /* "string offset" */ #line 274 "grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; } + { + yr_free(((*yyvaluep).c_string)); + ((*yyvaluep).c_string) = NULL; + } #line 1455 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 15: /* "string length" */ + case 15: /* "string length" */ #line 275 "grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; } + { + yr_free(((*yyvaluep).c_string)); + ((*yyvaluep).c_string) = NULL; + } #line 1461 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 16: /* "string identifier with wildcard" */ + case 16: /* "string identifier with wildcard" */ #line 277 "grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; } + { + yr_free(((*yyvaluep).c_string)); + ((*yyvaluep).c_string) = NULL; + } #line 1467 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 20: /* "text string" */ + case 20: /* "text string" */ #line 278 "grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).sized_string)); ((*yyvaluep).sized_string) = NULL; } + { + yr_free(((*yyvaluep).sized_string)); + ((*yyvaluep).sized_string) = NULL; + } #line 1473 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 21: /* "hex string" */ + case 21: /* "hex string" */ #line 279 "grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).sized_string)); ((*yyvaluep).sized_string) = NULL; } + { + yr_free(((*yyvaluep).sized_string)); + ((*yyvaluep).sized_string) = NULL; + } #line 1479 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 22: /* "regular expression" */ + case 22: /* "regular expression" */ #line 280 "grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).sized_string)); ((*yyvaluep).sized_string) = NULL; } + { + yr_free(((*yyvaluep).sized_string)); + ((*yyvaluep).sized_string) = NULL; + } #line 1485 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 101: /* string_modifiers */ + case 101: /* string_modifiers */ #line 293 "grammar.y" /* yacc.c:1258 */ - { - if (((*yyvaluep).modifier).alphabet != NULL) { - yr_free(((*yyvaluep).modifier).alphabet); - ((*yyvaluep).modifier).alphabet = NULL; + if (((*yyvaluep).modifier).alphabet != NULL) + { + yr_free(((*yyvaluep).modifier).alphabet); + ((*yyvaluep).modifier).alphabet = NULL; + } } -} #line 1497 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 102: /* string_modifier */ + case 102: /* string_modifier */ #line 285 "grammar.y" /* yacc.c:1258 */ - { - if (((*yyvaluep).modifier).alphabet != NULL) { - yr_free(((*yyvaluep).modifier).alphabet); - ((*yyvaluep).modifier).alphabet = NULL; + if (((*yyvaluep).modifier).alphabet != NULL) + { + yr_free(((*yyvaluep).modifier).alphabet); + ((*yyvaluep).modifier).alphabet = NULL; + } } -} #line 1509 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 108: /* arguments */ + case 108: /* arguments */ #line 282 "grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; } + { + yr_free(((*yyvaluep).c_string)); + ((*yyvaluep).c_string) = NULL; + } #line 1515 "grammar.c" /* yacc.c:1258 */ - break; + break; - case 109: /* arguments_list */ + case 109: /* arguments_list */ #line 283 "grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).c_string)); ((*yyvaluep).c_string) = NULL; } + { + yr_free(((*yyvaluep).c_string)); + ((*yyvaluep).c_string) = NULL; + } #line 1521 "grammar.c" /* yacc.c:1258 */ - break; + break; - default: - break; - } + default: + break; + } YY_IGNORE_MAYBE_UNINITIALIZED_END } - - /*----------. | yyparse. | `----------*/ -int -yyparse (void *yyscanner, YR_COMPILER* compiler) +int yyparse(void* yyscanner, YR_COMPILER* compiler) { -/* The lookahead symbol. */ -int yychar; + /* The lookahead symbol. */ + int yychar; -/* The semantic value of the lookahead symbol. */ -/* Default value used for initialization, for pacifying older GCCs - or non-GCC compilers. */ -YY_INITIAL_VALUE (static YYSTYPE yyval_default;) -YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); + /* The semantic value of the lookahead symbol. */ + /* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ + YY_INITIAL_VALUE(static YYSTYPE yyval_default;) + YYSTYPE yylval YY_INITIAL_VALUE(= yyval_default); - /* Number of syntax errors so far. */ - int yynerrs; + /* Number of syntax errors so far. */ + int yynerrs; - int yystate; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. + /* The stacks and their tools: + 'yyss': related to states. + 'yyvs': related to semantic values. - Refer to the stacks through separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16* yyss; + yytype_int16* yyssp; - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE* yyvs; + YYSTYPE* yyvsp; - YYSIZE_T yystacksize; + YYSIZE_T yystacksize; int yyn; int yyresult; @@ -1584,11 +1618,11 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); #if YYERROR_VERBOSE /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; - char *yymsg = yymsgbuf; + char* yymsg = yymsgbuf; YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ @@ -1598,7 +1632,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yyvsp = yyvs = yyvsa; yystacksize = YYINITDEPTH; - YYDPRINTF ((stderr, "Starting parse\n")); + YYDPRINTF((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; @@ -1606,79 +1640,84 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; -/*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | -`------------------------------------------------------------*/ - yynewstate: + /*------------------------------------------------------------. + | yynewstate -- Push a new state, which is found in yystate. | + `------------------------------------------------------------*/ +yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; - yysetstate: +yysetstate: *yyssp = yystate; if (yyss + yystacksize - 1 <= yyssp) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; - } + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE* yyvs1 = yyvs; + yytype_int16* yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow( + YY_("memory exhausted"), + &yyss1, + yysize * sizeof(*yyssp), + &yyvs1, + yysize * sizeof(*yyvsp), + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } #else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE +#ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +#else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; -# else - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; - { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif + { + yytype_int16* yyss1 = yyss; + union yyalloc* yyptr = (union yyalloc*) YYSTACK_ALLOC( + YYSTACK_BYTES(yystacksize)); + if (!yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE(yyss_alloc, yyss); + YYSTACK_RELOCATE(yyvs_alloc, yyvs); +#undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE(yyss1); + } +#endif #endif /* no yyoverflow */ - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); + YYDPRINTF( + (stderr, + "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YYDPRINTF((stderr, "Entering state %d\n", yystate)); if (yystate == YYFINAL) YYACCEPT; @@ -1695,28 +1734,28 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) + if (yypact_value_is_default(yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (&yylval, yyscanner, compiler); - } + { + YYDPRINTF((stderr, "Reading a token: ")); + yychar = yylex(&yylval, yyscanner, compiler); + } if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } + { + yychar = yytoken = YYEOF; + YYDPRINTF((stderr, "Now at end of input.\n")); + } else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } + { + yytoken = YYTRANSLATE(yychar); + YY_SYMBOL_PRINT("Next token is", yytoken, &yylval, &yylloc); + } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ @@ -1725,12 +1764,12 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) - { - if (yytable_value_is_error (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } + { + if (yytable_value_is_error(yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } /* Count tokens shifted since error; after three, turn off error status. */ @@ -1738,7 +1777,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yyerrstatus--; /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + YY_SYMBOL_PRINT("Shifting", yytoken, &yylval, &yylloc); /* Discard the shifted token. */ yychar = YYEMPTY; @@ -1776,2719 +1815,2774 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; + yyval = yyvsp[1 - yylen]; - YY_REDUCE_PRINT (yyn); + YY_REDUCE_PRINT(yyn); switch (yyn) - { - case 8: + { + case 8: #line 327 "grammar.y" /* yacc.c:1663 */ - { - _yr_compiler_pop_file_name(compiler); - } -#line 1791 "grammar.c" /* yacc.c:1663 */ - break; + { + _yr_compiler_pop_file_name(compiler); + } +#line 1791 "grammar.c" /* yacc.c:1663 */ + break; case 9: #line 335 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_import(yyscanner, (yyvsp[0].sized_string)); + { + int result = yr_parser_reduce_import(yyscanner, (yyvsp[0].sized_string)); - yr_free((yyvsp[0].sized_string)); + yr_free((yyvsp[0].sized_string)); - fail_if_error(result); - } + fail_if_error(result); + } #line 1803 "grammar.c" /* yacc.c:1663 */ - break; + break; case 10: #line 347 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_reduce_rule_declaration_phase_1( - yyscanner, (int32_t) (yyvsp[-2].integer), (yyvsp[0].c_string), &(yyval.rule))); - } + { + fail_if_error(yr_parser_reduce_rule_declaration_phase_1( + yyscanner, + (int32_t)(yyvsp[-2].integer), + (yyvsp[0].c_string), + &(yyval.rule))); + } #line 1812 "grammar.c" /* yacc.c:1663 */ - break; + break; case 11: #line 352 "grammar.y" /* yacc.c:1663 */ - { - YR_RULE* rule = (YR_RULE*) yr_arena_ref_to_ptr( - compiler->arena, &(yyvsp[-4].rule)); + { + YR_RULE* rule = (YR_RULE*) yr_arena_ref_to_ptr( + compiler->arena, &(yyvsp[-4].rule)); - rule->tags = (char*) yr_arena_ref_to_ptr( - compiler->arena, &(yyvsp[-3].tag)); + rule->tags = (char*) yr_arena_ref_to_ptr(compiler->arena, &(yyvsp[-3].tag)); - rule->metas = (YR_META*) yr_arena_ref_to_ptr( - compiler->arena, &(yyvsp[-1].meta)); + rule->metas = (YR_META*) yr_arena_ref_to_ptr( + compiler->arena, &(yyvsp[-1].meta)); - rule->strings = (YR_STRING*) yr_arena_ref_to_ptr( - compiler->arena, &(yyvsp[0].string)); - } + rule->strings = (YR_STRING*) yr_arena_ref_to_ptr( + compiler->arena, &(yyvsp[0].string)); + } #line 1830 "grammar.c" /* yacc.c:1663 */ - break; + break; case 12: #line 366 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_rule_declaration_phase_2( - yyscanner, &(yyvsp[-7].rule)); // rule created in phase 1 + { + int result = yr_parser_reduce_rule_declaration_phase_2( + yyscanner, &(yyvsp[-7].rule)); // rule created in phase 1 - yr_free((yyvsp[-8].c_string)); + yr_free((yyvsp[-8].c_string)); - fail_if_error(result); - } + fail_if_error(result); + } #line 1843 "grammar.c" /* yacc.c:1663 */ - break; + break; case 13: #line 379 "grammar.y" /* yacc.c:1663 */ - { - (yyval.meta) = YR_ARENA_NULL_REF; - } + { + (yyval.meta) = YR_ARENA_NULL_REF; + } #line 1851 "grammar.c" /* yacc.c:1663 */ - break; + break; case 14: #line 383 "grammar.y" /* yacc.c:1663 */ - { - YR_META* meta = yr_arena_get_ptr( - compiler->arena, - YR_METAS_TABLE, - (compiler->current_meta_idx - 1) * sizeof(YR_META)); + { + YR_META* meta = yr_arena_get_ptr( + compiler->arena, + YR_METAS_TABLE, + (compiler->current_meta_idx - 1) * sizeof(YR_META)); - meta->flags |= META_FLAGS_LAST_IN_RULE; + meta->flags |= META_FLAGS_LAST_IN_RULE; - (yyval.meta) = (yyvsp[0].meta); - } + (yyval.meta) = (yyvsp[0].meta); + } #line 1866 "grammar.c" /* yacc.c:1663 */ - break; + break; case 15: #line 398 "grammar.y" /* yacc.c:1663 */ - { - (yyval.string) = YR_ARENA_NULL_REF; - } + { + (yyval.string) = YR_ARENA_NULL_REF; + } #line 1874 "grammar.c" /* yacc.c:1663 */ - break; + break; case 16: #line 402 "grammar.y" /* yacc.c:1663 */ - { - YR_STRING* string = (YR_STRING*) yr_arena_get_ptr( - compiler->arena, - YR_STRINGS_TABLE, - (compiler->current_string_idx - 1) * sizeof(YR_STRING)); + { + YR_STRING* string = (YR_STRING*) yr_arena_get_ptr( + compiler->arena, + YR_STRINGS_TABLE, + (compiler->current_string_idx - 1) * sizeof(YR_STRING)); - string->flags |= STRING_FLAGS_LAST_IN_RULE; + string->flags |= STRING_FLAGS_LAST_IN_RULE; - (yyval.string) = (yyvsp[0].string); - } + (yyval.string) = (yyvsp[0].string); + } #line 1889 "grammar.c" /* yacc.c:1663 */ - break; + break; case 18: #line 421 "grammar.y" /* yacc.c:1663 */ - { (yyval.integer) = 0; } + { + (yyval.integer) = 0; + } #line 1895 "grammar.c" /* yacc.c:1663 */ - break; + break; case 19: #line 422 "grammar.y" /* yacc.c:1663 */ - { (yyval.integer) = (yyvsp[-1].integer) | (yyvsp[0].integer); } + { + (yyval.integer) = (yyvsp[-1].integer) | (yyvsp[0].integer); + } #line 1901 "grammar.c" /* yacc.c:1663 */ - break; + break; case 20: #line 427 "grammar.y" /* yacc.c:1663 */ - { (yyval.integer) = RULE_FLAGS_PRIVATE; } + { + (yyval.integer) = RULE_FLAGS_PRIVATE; + } #line 1907 "grammar.c" /* yacc.c:1663 */ - break; + break; case 21: #line 428 "grammar.y" /* yacc.c:1663 */ - { (yyval.integer) = RULE_FLAGS_GLOBAL; } + { + (yyval.integer) = RULE_FLAGS_GLOBAL; + } #line 1913 "grammar.c" /* yacc.c:1663 */ - break; + break; case 22: #line 434 "grammar.y" /* yacc.c:1663 */ - { - (yyval.tag) = YR_ARENA_NULL_REF; - } + { + (yyval.tag) = YR_ARENA_NULL_REF; + } #line 1921 "grammar.c" /* yacc.c:1663 */ - break; + break; case 23: #line 438 "grammar.y" /* yacc.c:1663 */ - { - // Tags list is represented in the arena as a sequence - // of null-terminated strings, the sequence ends with an - // additional null character. Here we write the ending null - //character. Example: tag1\0tag2\0tag3\0\0 + { + // Tags list is represented in the arena as a sequence + // of null-terminated strings, the sequence ends with an + // additional null character. Here we write the ending null + // character. Example: tag1\0tag2\0tag3\0\0 - fail_if_error(yr_arena_write_string( - yyget_extra(yyscanner)->arena, YR_SZ_POOL, "", NULL)); + fail_if_error(yr_arena_write_string( + yyget_extra(yyscanner)->arena, YR_SZ_POOL, "", NULL)); - (yyval.tag) = (yyvsp[0].tag); - } + (yyval.tag) = (yyvsp[0].tag); + } #line 1937 "grammar.c" /* yacc.c:1663 */ - break; + break; case 24: #line 454 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_arena_write_string( - yyget_extra(yyscanner)->arena, YR_SZ_POOL, (yyvsp[0].c_string), &(yyval.tag)); + { + int result = yr_arena_write_string( + yyget_extra(yyscanner)->arena, + YR_SZ_POOL, + (yyvsp[0].c_string), + &(yyval.tag)); - yr_free((yyvsp[0].c_string)); + yr_free((yyvsp[0].c_string)); - fail_if_error(result); - } + fail_if_error(result); + } #line 1950 "grammar.c" /* yacc.c:1663 */ - break; + break; case 25: #line 463 "grammar.y" /* yacc.c:1663 */ - { - YR_ARENA_REF ref; + { + YR_ARENA_REF ref; - // Write the new tag identifier. - int result = yr_arena_write_string( - yyget_extra(yyscanner)->arena, YR_SZ_POOL, (yyvsp[0].c_string), &ref); + // Write the new tag identifier. + int result = yr_arena_write_string( + yyget_extra(yyscanner)->arena, YR_SZ_POOL, (yyvsp[0].c_string), &ref); - yr_free((yyvsp[0].c_string)); + yr_free((yyvsp[0].c_string)); - fail_if_error(result); + fail_if_error(result); - // Get the address for the tag identifier just written. - char* new_tag = (char*) yr_arena_ref_to_ptr( - compiler->arena, &ref); + // Get the address for the tag identifier just written. + char* new_tag = (char*) yr_arena_ref_to_ptr(compiler->arena, &ref); - // Take the address of first tag's identifier in the list. - char* tag = (char*) yr_arena_ref_to_ptr( - compiler->arena, &(yyval.tag)); + // Take the address of first tag's identifier in the list. + char* tag = (char*) yr_arena_ref_to_ptr(compiler->arena, &(yyval.tag)); - // Search for duplicated tags. Tags are written one after - // the other, with zeroes in between (i.e: tag1/0tag2/0tag3) - // that's why can use tag < new_tag as the condition for the - // loop. - while (tag < new_tag) - { - if (strcmp(tag, new_tag) == 0) - { - yr_compiler_set_error_extra_info(compiler, tag); - fail_with_error(ERROR_DUPLICATED_TAG_IDENTIFIER); - } + // Search for duplicated tags. Tags are written one after + // the other, with zeroes in between (i.e: tag1/0tag2/0tag3) + // that's why can use tag < new_tag as the condition for the + // loop. + while (tag < new_tag) + { + if (strcmp(tag, new_tag) == 0) + { + yr_compiler_set_error_extra_info(compiler, tag); + fail_with_error(ERROR_DUPLICATED_TAG_IDENTIFIER); + } - tag += strlen(tag) + 1; - } + tag += strlen(tag) + 1; + } - (yyval.tag) = (yyvsp[-1].tag); - } + (yyval.tag) = (yyvsp[-1].tag); + } #line 1991 "grammar.c" /* yacc.c:1663 */ - break; + break; case 26: #line 504 "grammar.y" /* yacc.c:1663 */ - { (yyval.meta) = (yyvsp[0].meta); } + { + (yyval.meta) = (yyvsp[0].meta); + } #line 1997 "grammar.c" /* yacc.c:1663 */ - break; + break; case 27: #line 505 "grammar.y" /* yacc.c:1663 */ - { (yyval.meta) = (yyvsp[-1].meta); } + { + (yyval.meta) = (yyvsp[-1].meta); + } #line 2003 "grammar.c" /* yacc.c:1663 */ - break; + break; case 28: #line 511 "grammar.y" /* yacc.c:1663 */ - { - SIZED_STRING* sized_string = (yyvsp[0].sized_string); + { + SIZED_STRING* sized_string = (yyvsp[0].sized_string); - int result = yr_parser_reduce_meta_declaration( - yyscanner, - META_TYPE_STRING, - (yyvsp[-2].c_string), - sized_string->c_string, - 0, - &(yyval.meta)); + int result = yr_parser_reduce_meta_declaration( + yyscanner, + META_TYPE_STRING, + (yyvsp[-2].c_string), + sized_string->c_string, + 0, + &(yyval.meta)); - yr_free((yyvsp[-2].c_string)); - yr_free((yyvsp[0].sized_string)); + yr_free((yyvsp[-2].c_string)); + yr_free((yyvsp[0].sized_string)); - fail_if_error(result); - } + fail_if_error(result); + } #line 2024 "grammar.c" /* yacc.c:1663 */ - break; + break; case 29: #line 528 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_meta_declaration( - yyscanner, - META_TYPE_INTEGER, - (yyvsp[-2].c_string), - NULL, - (yyvsp[0].integer), - &(yyval.meta)); + { + int result = yr_parser_reduce_meta_declaration( + yyscanner, + META_TYPE_INTEGER, + (yyvsp[-2].c_string), + NULL, + (yyvsp[0].integer), + &(yyval.meta)); - yr_free((yyvsp[-2].c_string)); + yr_free((yyvsp[-2].c_string)); - fail_if_error(result); - } + fail_if_error(result); + } #line 2042 "grammar.c" /* yacc.c:1663 */ - break; + break; case 30: #line 542 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_meta_declaration( - yyscanner, - META_TYPE_INTEGER, - (yyvsp[-3].c_string), - NULL, - -(yyvsp[0].integer), - &(yyval.meta)); + { + int result = yr_parser_reduce_meta_declaration( + yyscanner, + META_TYPE_INTEGER, + (yyvsp[-3].c_string), + NULL, + -(yyvsp[0].integer), + &(yyval.meta)); - yr_free((yyvsp[-3].c_string)); + yr_free((yyvsp[-3].c_string)); - fail_if_error(result); - } + fail_if_error(result); + } #line 2060 "grammar.c" /* yacc.c:1663 */ - break; + break; case 31: #line 556 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_meta_declaration( - yyscanner, - META_TYPE_BOOLEAN, - (yyvsp[-2].c_string), - NULL, - true, - &(yyval.meta)); + { + int result = yr_parser_reduce_meta_declaration( + yyscanner, + META_TYPE_BOOLEAN, + (yyvsp[-2].c_string), + NULL, + true, + &(yyval.meta)); - yr_free((yyvsp[-2].c_string)); + yr_free((yyvsp[-2].c_string)); - fail_if_error(result); - } + fail_if_error(result); + } #line 2078 "grammar.c" /* yacc.c:1663 */ - break; + break; case 32: #line 570 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_meta_declaration( - yyscanner, - META_TYPE_BOOLEAN, - (yyvsp[-2].c_string), - NULL, - false, - &(yyval.meta)); + { + int result = yr_parser_reduce_meta_declaration( + yyscanner, + META_TYPE_BOOLEAN, + (yyvsp[-2].c_string), + NULL, + false, + &(yyval.meta)); - yr_free((yyvsp[-2].c_string)); + yr_free((yyvsp[-2].c_string)); - fail_if_error(result); - } + fail_if_error(result); + } #line 2096 "grammar.c" /* yacc.c:1663 */ - break; + break; case 33: #line 587 "grammar.y" /* yacc.c:1663 */ - { (yyval.string) = (yyvsp[0].string); } + { + (yyval.string) = (yyvsp[0].string); + } #line 2102 "grammar.c" /* yacc.c:1663 */ - break; + break; case 34: #line 588 "grammar.y" /* yacc.c:1663 */ - { (yyval.string) = (yyvsp[-1].string); } + { + (yyval.string) = (yyvsp[-1].string); + } #line 2108 "grammar.c" /* yacc.c:1663 */ - break; + break; case 35: #line 594 "grammar.y" /* yacc.c:1663 */ - { - compiler->current_line = yyget_lineno(yyscanner); - } + { + compiler->current_line = yyget_lineno(yyscanner); + } #line 2116 "grammar.c" /* yacc.c:1663 */ - break; + break; case 36: #line 598 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_string_declaration( - yyscanner, (yyvsp[0].modifier), (yyvsp[-4].c_string), (yyvsp[-1].sized_string), &(yyval.string)); - - yr_free((yyvsp[-4].c_string)); - yr_free((yyvsp[-1].sized_string)); - yr_free((yyvsp[0].modifier).alphabet); - - fail_if_error(result); - compiler->current_line = 0; - } + { + int result = yr_parser_reduce_string_declaration( + yyscanner, + (yyvsp[0].modifier), + (yyvsp[-4].c_string), + (yyvsp[-1].sized_string), + &(yyval.string)); + + yr_free((yyvsp[-4].c_string)); + yr_free((yyvsp[-1].sized_string)); + yr_free((yyvsp[0].modifier).alphabet); + + fail_if_error(result); + compiler->current_line = 0; + } #line 2132 "grammar.c" /* yacc.c:1663 */ - break; + break; case 37: #line 610 "grammar.y" /* yacc.c:1663 */ - { - compiler->current_line = yyget_lineno(yyscanner); - } + { + compiler->current_line = yyget_lineno(yyscanner); + } #line 2140 "grammar.c" /* yacc.c:1663 */ - break; + break; case 38: #line 614 "grammar.y" /* yacc.c:1663 */ - { - int result; + { + int result; - (yyvsp[0].modifier).flags |= STRING_FLAGS_REGEXP; + (yyvsp[0].modifier).flags |= STRING_FLAGS_REGEXP; - result = yr_parser_reduce_string_declaration( - yyscanner, (yyvsp[0].modifier), (yyvsp[-4].c_string), (yyvsp[-1].sized_string), &(yyval.string)); + result = yr_parser_reduce_string_declaration( + yyscanner, + (yyvsp[0].modifier), + (yyvsp[-4].c_string), + (yyvsp[-1].sized_string), + &(yyval.string)); - yr_free((yyvsp[-4].c_string)); - yr_free((yyvsp[-1].sized_string)); + yr_free((yyvsp[-4].c_string)); + yr_free((yyvsp[-1].sized_string)); - fail_if_error(result); + fail_if_error(result); - compiler->current_line = 0; - } + compiler->current_line = 0; + } #line 2160 "grammar.c" /* yacc.c:1663 */ - break; + break; case 39: #line 630 "grammar.y" /* yacc.c:1663 */ - { - compiler->current_line = yyget_lineno(yyscanner); - } + { + compiler->current_line = yyget_lineno(yyscanner); + } #line 2168 "grammar.c" /* yacc.c:1663 */ - break; + break; case 40: #line 634 "grammar.y" /* yacc.c:1663 */ - { - int result; + { + int result; - (yyvsp[0].modifier).flags |= STRING_FLAGS_HEXADECIMAL; + (yyvsp[0].modifier).flags |= STRING_FLAGS_HEXADECIMAL; - result = yr_parser_reduce_string_declaration( - yyscanner, (yyvsp[0].modifier), (yyvsp[-4].c_string), (yyvsp[-1].sized_string), &(yyval.string)); + result = yr_parser_reduce_string_declaration( + yyscanner, + (yyvsp[0].modifier), + (yyvsp[-4].c_string), + (yyvsp[-1].sized_string), + &(yyval.string)); - yr_free((yyvsp[-4].c_string)); - yr_free((yyvsp[-1].sized_string)); + yr_free((yyvsp[-4].c_string)); + yr_free((yyvsp[-1].sized_string)); - fail_if_error(result); + fail_if_error(result); - compiler->current_line = 0; - } + compiler->current_line = 0; + } #line 2188 "grammar.c" /* yacc.c:1663 */ - break; + break; case 41: #line 654 "grammar.y" /* yacc.c:1663 */ - { - (yyval.modifier).flags = 0; - (yyval.modifier).xor_min = 0; - (yyval.modifier).xor_max = 0; - (yyval.modifier).alphabet = NULL; - } + { + (yyval.modifier).flags = 0; + (yyval.modifier).xor_min = 0; + (yyval.modifier).xor_max = 0; + (yyval.modifier).alphabet = NULL; + } #line 2199 "grammar.c" /* yacc.c:1663 */ - break; + break; case 42: #line 661 "grammar.y" /* yacc.c:1663 */ - { - (yyval.modifier) = (yyvsp[-1].modifier); + { + (yyval.modifier) = (yyvsp[-1].modifier); - // Only set the xor minimum and maximum if we are dealing with the - // xor modifier. If we don't check for this then we can end up with - // "xor wide" resulting in whatever is on the stack for "wide" - // overwriting the values for xor. - if ((yyvsp[0].modifier).flags & STRING_FLAGS_XOR) - { - (yyval.modifier).xor_min = (yyvsp[0].modifier).xor_min; - (yyval.modifier).xor_max = (yyvsp[0].modifier).xor_max; - } + // Only set the xor minimum and maximum if we are dealing with the + // xor modifier. If we don't check for this then we can end up with + // "xor wide" resulting in whatever is on the stack for "wide" + // overwriting the values for xor. + if ((yyvsp[0].modifier).flags & STRING_FLAGS_XOR) + { + (yyval.modifier).xor_min = (yyvsp[0].modifier).xor_min; + (yyval.modifier).xor_max = (yyvsp[0].modifier).xor_max; + } - // Only set the base64 alphabet if we are dealing with the base64 - // modifier. If we don't check for this then we can end up with - // "base64 ascii" resulting in whatever is on the stack for "ascii" - // overwriting the values for base64. - if (((yyvsp[0].modifier).flags & STRING_FLAGS_BASE64) || - ((yyvsp[0].modifier).flags & STRING_FLAGS_BASE64_WIDE)) + // Only set the base64 alphabet if we are dealing with the base64 + // modifier. If we don't check for this then we can end up with + // "base64 ascii" resulting in whatever is on the stack for "ascii" + // overwriting the values for base64. + if (((yyvsp[0].modifier).flags & STRING_FLAGS_BASE64) || + ((yyvsp[0].modifier).flags & STRING_FLAGS_BASE64_WIDE)) + { + if ((yyval.modifier).alphabet != NULL) + { + if (ss_compare( + (yyval.modifier).alphabet, (yyvsp[0].modifier).alphabet) != 0) { - if ((yyval.modifier).alphabet != NULL) - { - if (ss_compare((yyval.modifier).alphabet, (yyvsp[0].modifier).alphabet) != 0) - { - yr_compiler_set_error_extra_info( - compiler, "can not specify multiple alphabets"); - - yr_free((yyvsp[0].modifier).alphabet); - yr_free((yyval.modifier).alphabet); - - fail_with_error(ERROR_INVALID_MODIFIER); - } - else - { - yr_free((yyvsp[0].modifier).alphabet); - } - } - else - { - (yyval.modifier).alphabet = (yyvsp[0].modifier).alphabet; - } - } + yr_compiler_set_error_extra_info( + compiler, "can not specify multiple alphabets"); - if ((yyval.modifier).flags & (yyvsp[0].modifier).flags) - { - if ((yyval.modifier).alphabet != NULL) - yr_free((yyval.modifier).alphabet); + yr_free((yyvsp[0].modifier).alphabet); + yr_free((yyval.modifier).alphabet); - fail_with_error(ERROR_DUPLICATED_MODIFIER); + fail_with_error(ERROR_INVALID_MODIFIER); } else { - (yyval.modifier).flags = (yyval.modifier).flags | (yyvsp[0].modifier).flags; + yr_free((yyvsp[0].modifier).alphabet); } } + else + { + (yyval.modifier).alphabet = (yyvsp[0].modifier).alphabet; + } + } + + if ((yyval.modifier).flags & (yyvsp[0].modifier).flags) + { + if ((yyval.modifier).alphabet != NULL) + yr_free((yyval.modifier).alphabet); + + fail_with_error(ERROR_DUPLICATED_MODIFIER); + } + else + { + (yyval.modifier).flags = (yyval.modifier).flags | + (yyvsp[0].modifier).flags; + } + } #line 2259 "grammar.c" /* yacc.c:1663 */ - break; + break; case 43: #line 720 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = STRING_FLAGS_WIDE; } + { + (yyval.modifier).flags = STRING_FLAGS_WIDE; + } #line 2265 "grammar.c" /* yacc.c:1663 */ - break; + break; case 44: #line 721 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = STRING_FLAGS_ASCII; } + { + (yyval.modifier).flags = STRING_FLAGS_ASCII; + } #line 2271 "grammar.c" /* yacc.c:1663 */ - break; + break; case 45: #line 722 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = STRING_FLAGS_NO_CASE; } + { + (yyval.modifier).flags = STRING_FLAGS_NO_CASE; + } #line 2277 "grammar.c" /* yacc.c:1663 */ - break; + break; case 46: #line 723 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = STRING_FLAGS_FULL_WORD; } + { + (yyval.modifier).flags = STRING_FLAGS_FULL_WORD; + } #line 2283 "grammar.c" /* yacc.c:1663 */ - break; + break; case 47: #line 724 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = STRING_FLAGS_PRIVATE; } + { + (yyval.modifier).flags = STRING_FLAGS_PRIVATE; + } #line 2289 "grammar.c" /* yacc.c:1663 */ - break; + break; case 48: #line 726 "grammar.y" /* yacc.c:1663 */ - { - (yyval.modifier).flags = STRING_FLAGS_XOR; - (yyval.modifier).xor_min = 0; - (yyval.modifier).xor_max = 255; - } + { + (yyval.modifier).flags = STRING_FLAGS_XOR; + (yyval.modifier).xor_min = 0; + (yyval.modifier).xor_max = 255; + } #line 2299 "grammar.c" /* yacc.c:1663 */ - break; + break; case 49: #line 732 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + { + int result = ERROR_SUCCESS; - if ((yyvsp[-1].integer) < 0 || (yyvsp[-1].integer) > 255) - { - yr_compiler_set_error_extra_info(compiler, "invalid xor range"); - result = ERROR_INVALID_MODIFIER; - } + if ((yyvsp[-1].integer) < 0 || (yyvsp[-1].integer) > 255) + { + yr_compiler_set_error_extra_info(compiler, "invalid xor range"); + result = ERROR_INVALID_MODIFIER; + } - fail_if_error(result); + fail_if_error(result); - (yyval.modifier).flags = STRING_FLAGS_XOR; - (yyval.modifier).xor_min = (yyvsp[-1].integer); - (yyval.modifier).xor_max = (yyvsp[-1].integer); - } + (yyval.modifier).flags = STRING_FLAGS_XOR; + (yyval.modifier).xor_min = (yyvsp[-1].integer); + (yyval.modifier).xor_max = (yyvsp[-1].integer); + } #line 2319 "grammar.c" /* yacc.c:1663 */ - break; + break; case 50: #line 753 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + { + int result = ERROR_SUCCESS; - if ((yyvsp[-3].integer) < 0) - { - yr_compiler_set_error_extra_info( - compiler, "lower bound for xor range exceeded (min: 0)"); - result = ERROR_INVALID_MODIFIER; - } + if ((yyvsp[-3].integer) < 0) + { + yr_compiler_set_error_extra_info( + compiler, "lower bound for xor range exceeded (min: 0)"); + result = ERROR_INVALID_MODIFIER; + } - if ((yyvsp[-1].integer) > 255) - { - yr_compiler_set_error_extra_info( - compiler, "upper bound for xor range exceeded (max: 255)"); - result = ERROR_INVALID_MODIFIER; - } + if ((yyvsp[-1].integer) > 255) + { + yr_compiler_set_error_extra_info( + compiler, "upper bound for xor range exceeded (max: 255)"); + result = ERROR_INVALID_MODIFIER; + } - if ((yyvsp[-3].integer) > (yyvsp[-1].integer)) - { - yr_compiler_set_error_extra_info( - compiler, "xor lower bound exceeds upper bound"); - result = ERROR_INVALID_MODIFIER; - } + if ((yyvsp[-3].integer) > (yyvsp[-1].integer)) + { + yr_compiler_set_error_extra_info( + compiler, "xor lower bound exceeds upper bound"); + result = ERROR_INVALID_MODIFIER; + } - fail_if_error(result); + fail_if_error(result); - (yyval.modifier).flags = STRING_FLAGS_XOR; - (yyval.modifier).xor_min = (yyvsp[-3].integer); - (yyval.modifier).xor_max = (yyvsp[-1].integer); - } + (yyval.modifier).flags = STRING_FLAGS_XOR; + (yyval.modifier).xor_min = (yyvsp[-3].integer); + (yyval.modifier).xor_max = (yyvsp[-1].integer); + } #line 2354 "grammar.c" /* yacc.c:1663 */ - break; + break; case 51: #line 784 "grammar.y" /* yacc.c:1663 */ - { - (yyval.modifier).flags = STRING_FLAGS_BASE64; - (yyval.modifier).alphabet = ss_new(DEFAULT_BASE64_ALPHABET); - } + { + (yyval.modifier).flags = STRING_FLAGS_BASE64; + (yyval.modifier).alphabet = ss_new(DEFAULT_BASE64_ALPHABET); + } #line 2363 "grammar.c" /* yacc.c:1663 */ - break; + break; case 52: #line 789 "grammar.y" /* yacc.c:1663 */ + { + int result = ERROR_SUCCESS; + + if ((yyvsp[-1].sized_string)->length != 64) { - int result = ERROR_SUCCESS; + yr_free((yyvsp[-1].sized_string)); + result = yr_compiler_set_error_extra_info( + compiler, "length of base64 alphabet must be 64"); + result = ERROR_INVALID_MODIFIER; + } - if ((yyvsp[-1].sized_string)->length != 64) - { - yr_free((yyvsp[-1].sized_string)); - result = yr_compiler_set_error_extra_info( - compiler, "length of base64 alphabet must be 64"); - result = ERROR_INVALID_MODIFIER; - } + fail_if_error(result); - fail_if_error(result); - - (yyval.modifier).flags = STRING_FLAGS_BASE64; - (yyval.modifier).alphabet = (yyvsp[-1].sized_string); - } -#line 2384 "grammar.c" /* yacc.c:1663 */ - break; + (yyval.modifier).flags = STRING_FLAGS_BASE64; + (yyval.modifier).alphabet = (yyvsp[-1].sized_string); + } +#line 2384 "grammar.c" /* yacc.c:1663 */ + break; case 53: #line 806 "grammar.y" /* yacc.c:1663 */ - { - (yyval.modifier).flags = STRING_FLAGS_BASE64_WIDE; - (yyval.modifier).alphabet = ss_new(DEFAULT_BASE64_ALPHABET); - } + { + (yyval.modifier).flags = STRING_FLAGS_BASE64_WIDE; + (yyval.modifier).alphabet = ss_new(DEFAULT_BASE64_ALPHABET); + } #line 2393 "grammar.c" /* yacc.c:1663 */ - break; + break; case 54: #line 811 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + { + int result = ERROR_SUCCESS; - if ((yyvsp[-1].sized_string)->length != 64) - { - yr_free((yyvsp[-1].sized_string)); - result = yr_compiler_set_error_extra_info( - compiler, "length of base64 alphabet must be 64"); - result = ERROR_INVALID_MODIFIER; - } + if ((yyvsp[-1].sized_string)->length != 64) + { + yr_free((yyvsp[-1].sized_string)); + result = yr_compiler_set_error_extra_info( + compiler, "length of base64 alphabet must be 64"); + result = ERROR_INVALID_MODIFIER; + } - fail_if_error(result); + fail_if_error(result); - (yyval.modifier).flags = STRING_FLAGS_BASE64_WIDE; - (yyval.modifier).alphabet = (yyvsp[-1].sized_string); - } + (yyval.modifier).flags = STRING_FLAGS_BASE64_WIDE; + (yyval.modifier).alphabet = (yyvsp[-1].sized_string); + } #line 2414 "grammar.c" /* yacc.c:1663 */ - break; + break; case 55: #line 830 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = 0; } + { + (yyval.modifier).flags = 0; + } #line 2420 "grammar.c" /* yacc.c:1663 */ - break; + break; case 56: #line 832 "grammar.y" /* yacc.c:1663 */ + { + if ((yyvsp[-1].modifier).flags & (yyvsp[0].modifier).flags) { - if ((yyvsp[-1].modifier).flags & (yyvsp[0].modifier).flags) - { - fail_with_error(ERROR_DUPLICATED_MODIFIER); - } - else - { - (yyval.modifier).flags = (yyvsp[-1].modifier).flags | (yyvsp[0].modifier).flags; - } - } + fail_with_error(ERROR_DUPLICATED_MODIFIER); + } + else + { + (yyval.modifier).flags = (yyvsp[-1].modifier).flags | + (yyvsp[0].modifier).flags; + } + } #line 2435 "grammar.c" /* yacc.c:1663 */ - break; + break; case 57: #line 845 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = STRING_FLAGS_WIDE; } + { + (yyval.modifier).flags = STRING_FLAGS_WIDE; + } #line 2441 "grammar.c" /* yacc.c:1663 */ - break; + break; case 58: #line 846 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = STRING_FLAGS_ASCII; } + { + (yyval.modifier).flags = STRING_FLAGS_ASCII; + } #line 2447 "grammar.c" /* yacc.c:1663 */ - break; + break; case 59: #line 847 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = STRING_FLAGS_NO_CASE; } + { + (yyval.modifier).flags = STRING_FLAGS_NO_CASE; + } #line 2453 "grammar.c" /* yacc.c:1663 */ - break; + break; case 60: #line 848 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = STRING_FLAGS_FULL_WORD; } + { + (yyval.modifier).flags = STRING_FLAGS_FULL_WORD; + } #line 2459 "grammar.c" /* yacc.c:1663 */ - break; + break; case 61: #line 849 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = STRING_FLAGS_PRIVATE; } + { + (yyval.modifier).flags = STRING_FLAGS_PRIVATE; + } #line 2465 "grammar.c" /* yacc.c:1663 */ - break; + break; case 62: #line 853 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = 0; } + { + (yyval.modifier).flags = 0; + } #line 2471 "grammar.c" /* yacc.c:1663 */ - break; + break; case 63: #line 855 "grammar.y" /* yacc.c:1663 */ + { + if ((yyvsp[-1].modifier).flags & (yyvsp[0].modifier).flags) { - if ((yyvsp[-1].modifier).flags & (yyvsp[0].modifier).flags) - { - fail_with_error(ERROR_DUPLICATED_MODIFIER); - } - else - { - (yyval.modifier).flags = (yyvsp[-1].modifier).flags | (yyvsp[0].modifier).flags; - } - } + fail_with_error(ERROR_DUPLICATED_MODIFIER); + } + else + { + (yyval.modifier).flags = (yyvsp[-1].modifier).flags | + (yyvsp[0].modifier).flags; + } + } #line 2486 "grammar.c" /* yacc.c:1663 */ - break; + break; case 64: #line 868 "grammar.y" /* yacc.c:1663 */ - { (yyval.modifier).flags = STRING_FLAGS_PRIVATE; } + { + (yyval.modifier).flags = STRING_FLAGS_PRIVATE; + } #line 2492 "grammar.c" /* yacc.c:1663 */ - break; + break; case 65: #line 873 "grammar.y" /* yacc.c:1663 */ + { + YR_EXPRESSION expr; + + int result = ERROR_SUCCESS; + int var_index = yr_parser_lookup_loop_variable( + yyscanner, (yyvsp[0].c_string), &expr); + + if (var_index >= 0) { - YR_EXPRESSION expr; + // The identifier corresponds to a loop variable. + result = yr_parser_emit_with_arg( + yyscanner, OP_PUSH_M, var_index, NULL, NULL); - int result = ERROR_SUCCESS; - int var_index = yr_parser_lookup_loop_variable(yyscanner, (yyvsp[0].c_string), &expr); + // The expression associated to this identifier is the same one + // associated to the loop variable. + (yyval.expression) = expr; + } + else + { + // Search for identifier within the global namespace, where the + // externals variables reside. - if (var_index >= 0) - { - // The identifier corresponds to a loop variable. - result = yr_parser_emit_with_arg( + YR_OBJECT* object = (YR_OBJECT*) yr_hash_table_lookup( + compiler->objects_table, (yyvsp[0].c_string), NULL); + + YR_NAMESPACE* ns = (YR_NAMESPACE*) yr_arena_get_ptr( + compiler->arena, + YR_NAMESPACES_TABLE, + compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE)); + + if (object == NULL) + { + // If not found, search within the current namespace. + object = (YR_OBJECT*) yr_hash_table_lookup( + compiler->objects_table, (yyvsp[0].c_string), ns->name); + } + + if (object != NULL) + { + YR_ARENA_REF ref; + + result = _yr_compiler_store_string(compiler, (yyvsp[0].c_string), &ref); + + if (result == ERROR_SUCCESS) + result = yr_parser_emit_with_arg_reloc( yyscanner, - OP_PUSH_M, - var_index, + OP_OBJ_LOAD, + yr_arena_ref_to_ptr(compiler->arena, &ref), NULL, NULL); - // The expression associated to this identifier is the same one - // associated to the loop variable. - (yyval.expression) = expr; - } - else + (yyval.expression).type = EXPRESSION_TYPE_OBJECT; + (yyval.expression).value.object = object; + (yyval.expression).identifier.ptr = NULL; + (yyval.expression).identifier.ref = ref; + } + else + { + uint32_t rule_idx = yr_hash_table_lookup_uint32( + compiler->rules_table, (yyvsp[0].c_string), ns->name); + + if (rule_idx != UINT32_MAX) { - // Search for identifier within the global namespace, where the - // externals variables reside. + result = yr_parser_emit_with_arg( + yyscanner, OP_PUSH_RULE, rule_idx, NULL, NULL); - YR_OBJECT* object = (YR_OBJECT*) yr_hash_table_lookup( - compiler->objects_table, (yyvsp[0].c_string), NULL); + YR_RULE* rule = _yr_compiler_get_rule_by_idx(compiler, rule_idx); - YR_NAMESPACE* ns = (YR_NAMESPACE*) yr_arena_get_ptr( + yr_arena_ptr_to_ref( compiler->arena, - YR_NAMESPACES_TABLE, - compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE)); - - if (object == NULL) - { - // If not found, search within the current namespace. - object = (YR_OBJECT*) yr_hash_table_lookup( - compiler->objects_table, (yyvsp[0].c_string), ns->name); - } + rule->identifier, + &(yyval.expression).identifier.ref); - if (object != NULL) - { - YR_ARENA_REF ref; - - result = _yr_compiler_store_string( - compiler, (yyvsp[0].c_string), &ref); - - if (result == ERROR_SUCCESS) - result = yr_parser_emit_with_arg_reloc( - yyscanner, - OP_OBJ_LOAD, - yr_arena_ref_to_ptr(compiler->arena, &ref), - NULL, - NULL); - - (yyval.expression).type = EXPRESSION_TYPE_OBJECT; - (yyval.expression).value.object = object; - (yyval.expression).identifier.ptr = NULL; - (yyval.expression).identifier.ref = ref; - } - else - { - uint32_t rule_idx = yr_hash_table_lookup_uint32( - compiler->rules_table, (yyvsp[0].c_string), ns->name); - - if (rule_idx != UINT32_MAX) - { - result = yr_parser_emit_with_arg( - yyscanner, - OP_PUSH_RULE, - rule_idx, - NULL, - NULL); - - YR_RULE* rule = _yr_compiler_get_rule_by_idx(compiler, rule_idx); - - yr_arena_ptr_to_ref(compiler->arena, rule->identifier, &(yyval.expression).identifier.ref); - - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - (yyval.expression).value.integer = YR_UNDEFINED; - (yyval.expression).identifier.ptr = NULL; - } - else - { - yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string)); - result = ERROR_UNDEFINED_IDENTIFIER; - } - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + (yyval.expression).value.integer = YR_UNDEFINED; + (yyval.expression).identifier.ptr = NULL; } + else + { + yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string)); + result = ERROR_UNDEFINED_IDENTIFIER; + } + } + } - yr_free((yyvsp[0].c_string)); + yr_free((yyvsp[0].c_string)); - fail_if_error(result); - } + fail_if_error(result); + } #line 2591 "grammar.c" /* yacc.c:1663 */ - break; + break; case 66: #line 968 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; - YR_OBJECT* field = NULL; + { + int result = ERROR_SUCCESS; + YR_OBJECT* field = NULL; - if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_OBJECT && - (yyvsp[-2].expression).value.object->type == OBJECT_TYPE_STRUCTURE) - { - field = yr_object_lookup_field((yyvsp[-2].expression).value.object, (yyvsp[0].c_string)); + if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_OBJECT && + (yyvsp[-2].expression).value.object->type == OBJECT_TYPE_STRUCTURE) + { + field = yr_object_lookup_field( + (yyvsp[-2].expression).value.object, (yyvsp[0].c_string)); - if (field != NULL) - { - YR_ARENA_REF ref; - - result = _yr_compiler_store_string( - compiler, (yyvsp[0].c_string), &ref); - - if (result == ERROR_SUCCESS) - result = yr_parser_emit_with_arg_reloc( - yyscanner, - OP_OBJ_FIELD, - yr_arena_ref_to_ptr(compiler->arena, &ref), - NULL, - NULL); - - (yyval.expression).type = EXPRESSION_TYPE_OBJECT; - (yyval.expression).value.object = field; - (yyval.expression).identifier.ref = ref; - (yyval.expression).identifier.ptr = NULL; - } - else - { - yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string)); - result = ERROR_INVALID_FIELD_NAME; - } - } - else - { - yr_compiler_set_error_extra_info( - compiler, expression_identifier((yyvsp[-2].expression))); + if (field != NULL) + { + YR_ARENA_REF ref; - result = ERROR_NOT_A_STRUCTURE; - } + result = _yr_compiler_store_string(compiler, (yyvsp[0].c_string), &ref); - yr_free((yyvsp[0].c_string)); + if (result == ERROR_SUCCESS) + result = yr_parser_emit_with_arg_reloc( + yyscanner, + OP_OBJ_FIELD, + yr_arena_ref_to_ptr(compiler->arena, &ref), + NULL, + NULL); - fail_if_error(result); + (yyval.expression).type = EXPRESSION_TYPE_OBJECT; + (yyval.expression).value.object = field; + (yyval.expression).identifier.ref = ref; + (yyval.expression).identifier.ptr = NULL; + } + else + { + yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string)); + result = ERROR_INVALID_FIELD_NAME; } + } + else + { + yr_compiler_set_error_extra_info( + compiler, expression_identifier((yyvsp[-2].expression))); + + result = ERROR_NOT_A_STRUCTURE; + } + + yr_free((yyvsp[0].c_string)); + + fail_if_error(result); + } #line 2643 "grammar.c" /* yacc.c:1663 */ - break; + break; case 67: #line 1016 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; - YR_OBJECT_ARRAY* array; - YR_OBJECT_DICTIONARY* dict; + { + int result = ERROR_SUCCESS; + YR_OBJECT_ARRAY* array; + YR_OBJECT_DICTIONARY* dict; - if ((yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT && - (yyvsp[-3].expression).value.object->type == OBJECT_TYPE_ARRAY) - { - if ((yyvsp[-1].expression).type != EXPRESSION_TYPE_INTEGER) - { - yr_compiler_set_error_extra_info( - compiler, "array indexes must be of integer type"); - result = ERROR_WRONG_TYPE; - } + if ((yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT && + (yyvsp[-3].expression).value.object->type == OBJECT_TYPE_ARRAY) + { + if ((yyvsp[-1].expression).type != EXPRESSION_TYPE_INTEGER) + { + yr_compiler_set_error_extra_info( + compiler, "array indexes must be of integer type"); + result = ERROR_WRONG_TYPE; + } - fail_if_error(result); + fail_if_error(result); - result = yr_parser_emit( - yyscanner, OP_INDEX_ARRAY, NULL); + result = yr_parser_emit(yyscanner, OP_INDEX_ARRAY, NULL); - array = object_as_array((yyvsp[-3].expression).value.object); + array = object_as_array((yyvsp[-3].expression).value.object); - (yyval.expression).type = EXPRESSION_TYPE_OBJECT; - (yyval.expression).value.object = array->prototype_item; - (yyval.expression).identifier.ptr = array->identifier; - (yyval.expression).identifier.ref = YR_ARENA_NULL_REF; - } - else if ((yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT && - (yyvsp[-3].expression).value.object->type == OBJECT_TYPE_DICTIONARY) - { - if ((yyvsp[-1].expression).type != EXPRESSION_TYPE_STRING) - { - yr_compiler_set_error_extra_info( - compiler, "dictionary keys must be of string type"); - result = ERROR_WRONG_TYPE; - } + (yyval.expression).type = EXPRESSION_TYPE_OBJECT; + (yyval.expression).value.object = array->prototype_item; + (yyval.expression).identifier.ptr = array->identifier; + (yyval.expression).identifier.ref = YR_ARENA_NULL_REF; + } + else if ( + (yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT && + (yyvsp[-3].expression).value.object->type == OBJECT_TYPE_DICTIONARY) + { + if ((yyvsp[-1].expression).type != EXPRESSION_TYPE_STRING) + { + yr_compiler_set_error_extra_info( + compiler, "dictionary keys must be of string type"); + result = ERROR_WRONG_TYPE; + } - fail_if_error(result); + fail_if_error(result); - result = yr_parser_emit( - yyscanner, OP_LOOKUP_DICT, NULL); + result = yr_parser_emit(yyscanner, OP_LOOKUP_DICT, NULL); - dict = object_as_dictionary((yyvsp[-3].expression).value.object); + dict = object_as_dictionary((yyvsp[-3].expression).value.object); - (yyval.expression).type = EXPRESSION_TYPE_OBJECT; - (yyval.expression).value.object = dict->prototype_item; - (yyval.expression).identifier.ptr = dict->identifier; - (yyval.expression).identifier.ref = YR_ARENA_NULL_REF; - } - else - { - yr_compiler_set_error_extra_info( - compiler, expression_identifier((yyvsp[-3].expression))); + (yyval.expression).type = EXPRESSION_TYPE_OBJECT; + (yyval.expression).value.object = dict->prototype_item; + (yyval.expression).identifier.ptr = dict->identifier; + (yyval.expression).identifier.ref = YR_ARENA_NULL_REF; + } + else + { + yr_compiler_set_error_extra_info( + compiler, expression_identifier((yyvsp[-3].expression))); - result = ERROR_NOT_INDEXABLE; - } + result = ERROR_NOT_INDEXABLE; + } - fail_if_error(result); - } + fail_if_error(result); + } #line 2707 "grammar.c" /* yacc.c:1663 */ - break; + break; case 68: #line 1077 "grammar.y" /* yacc.c:1663 */ + { + YR_ARENA_REF ref; + int result = ERROR_SUCCESS; + YR_OBJECT_FUNCTION* function; + + if ((yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT && + (yyvsp[-3].expression).value.object->type == OBJECT_TYPE_FUNCTION) { - YR_ARENA_REF ref; - int result = ERROR_SUCCESS; - YR_OBJECT_FUNCTION* function; + result = yr_parser_check_types( + compiler, + object_as_function((yyvsp[-3].expression).value.object), + (yyvsp[-1].c_string)); - if ((yyvsp[-3].expression).type == EXPRESSION_TYPE_OBJECT && - (yyvsp[-3].expression).value.object->type == OBJECT_TYPE_FUNCTION) - { - result = yr_parser_check_types( - compiler, object_as_function((yyvsp[-3].expression).value.object), (yyvsp[-1].c_string)); - - if (result == ERROR_SUCCESS) - result = _yr_compiler_store_string( - compiler, (yyvsp[-1].c_string), &ref); - - if (result == ERROR_SUCCESS) - result = yr_parser_emit_with_arg_reloc( - yyscanner, - OP_CALL, - yr_arena_ref_to_ptr(compiler->arena, &ref), - NULL, - NULL); - - function = object_as_function((yyvsp[-3].expression).value.object); - - (yyval.expression).type = EXPRESSION_TYPE_OBJECT; - (yyval.expression).value.object = function->return_obj; - (yyval.expression).identifier.ref = ref; - (yyval.expression).identifier.ptr = NULL; - } - else - { - yr_compiler_set_error_extra_info( - compiler, expression_identifier((yyvsp[-3].expression))); + if (result == ERROR_SUCCESS) + result = _yr_compiler_store_string( + compiler, (yyvsp[-1].c_string), &ref); - result = ERROR_NOT_A_FUNCTION; - } + if (result == ERROR_SUCCESS) + result = yr_parser_emit_with_arg_reloc( + yyscanner, + OP_CALL, + yr_arena_ref_to_ptr(compiler->arena, &ref), + NULL, + NULL); - yr_free((yyvsp[-1].c_string)); + function = object_as_function((yyvsp[-3].expression).value.object); - fail_if_error(result); - } + (yyval.expression).type = EXPRESSION_TYPE_OBJECT; + (yyval.expression).value.object = function->return_obj; + (yyval.expression).identifier.ref = ref; + (yyval.expression).identifier.ptr = NULL; + } + else + { + yr_compiler_set_error_extra_info( + compiler, expression_identifier((yyvsp[-3].expression))); + + result = ERROR_NOT_A_FUNCTION; + } + + yr_free((yyvsp[-1].c_string)); + + fail_if_error(result); + } #line 2754 "grammar.c" /* yacc.c:1663 */ - break; + break; case 69: #line 1123 "grammar.y" /* yacc.c:1663 */ - { (yyval.c_string) = yr_strdup(""); } + { + (yyval.c_string) = yr_strdup(""); + } #line 2760 "grammar.c" /* yacc.c:1663 */ - break; + break; case 70: #line 1124 "grammar.y" /* yacc.c:1663 */ - { (yyval.c_string) = (yyvsp[0].c_string); } + { + (yyval.c_string) = (yyvsp[0].c_string); + } #line 2766 "grammar.c" /* yacc.c:1663 */ - break; + break; case 71: #line 1129 "grammar.y" /* yacc.c:1663 */ - { - (yyval.c_string) = (char*) yr_malloc(YR_MAX_FUNCTION_ARGS + 1); - - if ((yyval.c_string) == NULL) - fail_with_error(ERROR_INSUFFICIENT_MEMORY); - - switch((yyvsp[0].expression).type) - { - case EXPRESSION_TYPE_INTEGER: - strlcpy((yyval.c_string), "i", YR_MAX_FUNCTION_ARGS); - break; - case EXPRESSION_TYPE_FLOAT: - strlcpy((yyval.c_string), "f", YR_MAX_FUNCTION_ARGS); - break; - case EXPRESSION_TYPE_BOOLEAN: - strlcpy((yyval.c_string), "b", YR_MAX_FUNCTION_ARGS); - break; - case EXPRESSION_TYPE_STRING: - strlcpy((yyval.c_string), "s", YR_MAX_FUNCTION_ARGS); - break; - case EXPRESSION_TYPE_REGEXP: - strlcpy((yyval.c_string), "r", YR_MAX_FUNCTION_ARGS); - break; - case EXPRESSION_TYPE_UNKNOWN: - yr_free((yyval.c_string)); - yr_compiler_set_error_extra_info( - compiler, "unknown type for argument 1 in function call"); - fail_with_error(ERROR_WRONG_TYPE); - break; - default: - // An unknown expression type is OK iff an error ocurred. - assert(compiler->last_error != ERROR_SUCCESS); - } - } + { + (yyval.c_string) = (char*) yr_malloc(YR_MAX_FUNCTION_ARGS + 1); + + if ((yyval.c_string) == NULL) + fail_with_error(ERROR_INSUFFICIENT_MEMORY); + + switch ((yyvsp[0].expression).type) + { + case EXPRESSION_TYPE_INTEGER: + strlcpy((yyval.c_string), "i", YR_MAX_FUNCTION_ARGS); + break; + case EXPRESSION_TYPE_FLOAT: + strlcpy((yyval.c_string), "f", YR_MAX_FUNCTION_ARGS); + break; + case EXPRESSION_TYPE_BOOLEAN: + strlcpy((yyval.c_string), "b", YR_MAX_FUNCTION_ARGS); + break; + case EXPRESSION_TYPE_STRING: + strlcpy((yyval.c_string), "s", YR_MAX_FUNCTION_ARGS); + break; + case EXPRESSION_TYPE_REGEXP: + strlcpy((yyval.c_string), "r", YR_MAX_FUNCTION_ARGS); + break; + case EXPRESSION_TYPE_UNKNOWN: + yr_free((yyval.c_string)); + yr_compiler_set_error_extra_info( + compiler, "unknown type for argument 1 in function call"); + fail_with_error(ERROR_WRONG_TYPE); + break; + default: + // An unknown expression type is OK iff an error ocurred. + assert(compiler->last_error != ERROR_SUCCESS); + } + } #line 2805 "grammar.c" /* yacc.c:1663 */ - break; + break; case 72: #line 1164 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + { + int result = ERROR_SUCCESS; - if (strlen((yyvsp[-2].c_string)) == YR_MAX_FUNCTION_ARGS) - { - result = ERROR_TOO_MANY_ARGUMENTS; - } - else - { - switch((yyvsp[0].expression).type) - { - case EXPRESSION_TYPE_INTEGER: - strlcat((yyvsp[-2].c_string), "i", YR_MAX_FUNCTION_ARGS); - break; - case EXPRESSION_TYPE_FLOAT: - strlcat((yyvsp[-2].c_string), "f", YR_MAX_FUNCTION_ARGS); - break; - case EXPRESSION_TYPE_BOOLEAN: - strlcat((yyvsp[-2].c_string), "b", YR_MAX_FUNCTION_ARGS); - break; - case EXPRESSION_TYPE_STRING: - strlcat((yyvsp[-2].c_string), "s", YR_MAX_FUNCTION_ARGS); - break; - case EXPRESSION_TYPE_REGEXP: - strlcat((yyvsp[-2].c_string), "r", YR_MAX_FUNCTION_ARGS); - break; - case EXPRESSION_TYPE_UNKNOWN: - result = ERROR_WRONG_TYPE; - yr_compiler_set_error_extra_info_fmt( - compiler, "unknown type for argument %zu in function call", - // As we add one character per argument, the length of $1 is - // the number of arguments parsed so far, and the argument - // represented by is length of $1 plus one. - strlen((yyvsp[-2].c_string)) + 1); - break; - default: - // An unknown expression type is OK iff an error ocurred. - assert(compiler->last_error != ERROR_SUCCESS); - } - } + if (strlen((yyvsp[-2].c_string)) == YR_MAX_FUNCTION_ARGS) + { + result = ERROR_TOO_MANY_ARGUMENTS; + } + else + { + switch ((yyvsp[0].expression).type) + { + case EXPRESSION_TYPE_INTEGER: + strlcat((yyvsp[-2].c_string), "i", YR_MAX_FUNCTION_ARGS); + break; + case EXPRESSION_TYPE_FLOAT: + strlcat((yyvsp[-2].c_string), "f", YR_MAX_FUNCTION_ARGS); + break; + case EXPRESSION_TYPE_BOOLEAN: + strlcat((yyvsp[-2].c_string), "b", YR_MAX_FUNCTION_ARGS); + break; + case EXPRESSION_TYPE_STRING: + strlcat((yyvsp[-2].c_string), "s", YR_MAX_FUNCTION_ARGS); + break; + case EXPRESSION_TYPE_REGEXP: + strlcat((yyvsp[-2].c_string), "r", YR_MAX_FUNCTION_ARGS); + break; + case EXPRESSION_TYPE_UNKNOWN: + result = ERROR_WRONG_TYPE; + yr_compiler_set_error_extra_info_fmt( + compiler, + "unknown type for argument %zu in function call", + // As we add one character per argument, the length of $1 is + // the number of arguments parsed so far, and the argument + // represented by is length of $1 plus one. + strlen((yyvsp[-2].c_string)) + 1); + break; + default: + // An unknown expression type is OK iff an error ocurred. + assert(compiler->last_error != ERROR_SUCCESS); + } + } - if (result != ERROR_SUCCESS) - yr_free((yyvsp[-2].c_string)); + if (result != ERROR_SUCCESS) + yr_free((yyvsp[-2].c_string)); - fail_if_error(result); + fail_if_error(result); - (yyval.c_string) = (yyvsp[-2].c_string); - } + (yyval.c_string) = (yyvsp[-2].c_string); + } #line 2858 "grammar.c" /* yacc.c:1663 */ - break; + break; case 73: #line 1217 "grammar.y" /* yacc.c:1663 */ - { - SIZED_STRING* sized_string = (yyvsp[0].sized_string); - YR_ARENA_REF re_ref; - RE_ERROR error; + { + SIZED_STRING* sized_string = (yyvsp[0].sized_string); + YR_ARENA_REF re_ref; + RE_ERROR error; - int result = ERROR_SUCCESS; - int re_flags = 0; + int result = ERROR_SUCCESS; + int re_flags = 0; - if (sized_string->flags & SIZED_STRING_FLAGS_NO_CASE) - re_flags |= RE_FLAGS_NO_CASE; + if (sized_string->flags & SIZED_STRING_FLAGS_NO_CASE) + re_flags |= RE_FLAGS_NO_CASE; - if (sized_string->flags & SIZED_STRING_FLAGS_DOT_ALL) - re_flags |= RE_FLAGS_DOT_ALL; + if (sized_string->flags & SIZED_STRING_FLAGS_DOT_ALL) + re_flags |= RE_FLAGS_DOT_ALL; - result = yr_re_compile( - sized_string->c_string, - re_flags, - compiler->arena, - &re_ref, - &error); + result = yr_re_compile( + sized_string->c_string, re_flags, compiler->arena, &re_ref, &error); - yr_free((yyvsp[0].sized_string)); + yr_free((yyvsp[0].sized_string)); - if (result == ERROR_INVALID_REGULAR_EXPRESSION) - yr_compiler_set_error_extra_info(compiler, error.message); + if (result == ERROR_INVALID_REGULAR_EXPRESSION) + yr_compiler_set_error_extra_info(compiler, error.message); - if (result == ERROR_SUCCESS) - result = yr_parser_emit_with_arg_reloc( - yyscanner, - OP_PUSH, - yr_arena_ref_to_ptr(compiler->arena, &re_ref), - NULL, - NULL); + if (result == ERROR_SUCCESS) + result = yr_parser_emit_with_arg_reloc( + yyscanner, + OP_PUSH, + yr_arena_ref_to_ptr(compiler->arena, &re_ref), + NULL, + NULL); - fail_if_error(result); + fail_if_error(result); - (yyval.expression).type = EXPRESSION_TYPE_REGEXP; - } + (yyval.expression).type = EXPRESSION_TYPE_REGEXP; + } #line 2901 "grammar.c" /* yacc.c:1663 */ - break; + break; case 74: #line 1260 "grammar.y" /* yacc.c:1663 */ + { + if ((yyvsp[0].expression).type == EXPRESSION_TYPE_STRING) { - if ((yyvsp[0].expression).type == EXPRESSION_TYPE_STRING) - { - if (!YR_ARENA_IS_NULL_REF((yyvsp[0].expression).value.sized_string_ref)) - { - SIZED_STRING* sized_string = yr_arena_ref_to_ptr( - compiler->arena, &(yyvsp[0].expression).value.sized_string_ref); + if (!YR_ARENA_IS_NULL_REF((yyvsp[0].expression).value.sized_string_ref)) + { + SIZED_STRING* sized_string = yr_arena_ref_to_ptr( + compiler->arena, &(yyvsp[0].expression).value.sized_string_ref); - yywarning(yyscanner, - "Using literal string \"%s\" in a boolean operation.", - sized_string->c_string); - } + yywarning( + yyscanner, + "Using literal string \"%s\" in a boolean operation.", + sized_string->c_string); + } - fail_if_error(yr_parser_emit( - yyscanner, OP_STR_TO_BOOL, NULL)); - } + fail_if_error(yr_parser_emit(yyscanner, OP_STR_TO_BOOL, NULL)); + } - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 2925 "grammar.c" /* yacc.c:1663 */ - break; + break; case 75: #line 1283 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_emit_push_const(yyscanner, 1)); + { + fail_if_error(yr_parser_emit_push_const(yyscanner, 1)); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 2935 "grammar.c" /* yacc.c:1663 */ - break; + break; case 76: #line 1289 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_emit_push_const(yyscanner, 0)); + { + fail_if_error(yr_parser_emit_push_const(yyscanner, 0)); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 2945 "grammar.c" /* yacc.c:1663 */ - break; + break; case 77: #line 1295 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "matches"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_REGEXP, "matches"); + { + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "matches"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_REGEXP, "matches"); - fail_if_error(yr_parser_emit( - yyscanner, - OP_MATCHES, - NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_MATCHES, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 2961 "grammar.c" /* yacc.c:1663 */ - break; + break; case 78: #line 1307 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "contains"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "contains"); + { + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "contains"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "contains"); - fail_if_error(yr_parser_emit( - yyscanner, OP_CONTAINS, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_CONTAINS, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 2975 "grammar.c" /* yacc.c:1663 */ - break; + break; case 79: #line 1317 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "icontains"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "icontains"); + { + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "icontains"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "icontains"); - fail_if_error(yr_parser_emit( - yyscanner, OP_ICONTAINS, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_ICONTAINS, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 2989 "grammar.c" /* yacc.c:1663 */ - break; + break; case 80: #line 1327 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "startswith"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "startswith"); + { + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "startswith"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "startswith"); - fail_if_error(yr_parser_emit( - yyscanner, OP_STARTSWITH, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_STARTSWITH, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3003 "grammar.c" /* yacc.c:1663 */ - break; + break; case 81: #line 1337 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "istartswith"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "istartswith"); + { + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "istartswith"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "istartswith"); - fail_if_error(yr_parser_emit( - yyscanner, OP_ISTARTSWITH, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_ISTARTSWITH, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3017 "grammar.c" /* yacc.c:1663 */ - break; + break; case 82: #line 1347 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "endswith"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "endswith"); + { + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "endswith"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "endswith"); - fail_if_error(yr_parser_emit( - yyscanner, OP_ENDSWITH, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_ENDSWITH, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3031 "grammar.c" /* yacc.c:1663 */ - break; + break; case 83: #line 1357 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "iendswith"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "iendswith"); + { + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_STRING, "iendswith"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_STRING, "iendswith"); - fail_if_error(yr_parser_emit( - yyscanner, OP_IENDSWITH, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_IENDSWITH, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3045 "grammar.c" /* yacc.c:1663 */ - break; + break; case 84: #line 1367 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_string_identifier( - yyscanner, - (yyvsp[0].c_string), - OP_FOUND, - YR_UNDEFINED); + { + int result = yr_parser_reduce_string_identifier( + yyscanner, (yyvsp[0].c_string), OP_FOUND, YR_UNDEFINED); - yr_free((yyvsp[0].c_string)); + yr_free((yyvsp[0].c_string)); - fail_if_error(result); + fail_if_error(result); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3063 "grammar.c" /* yacc.c:1663 */ - break; + break; case 85: #line 1381 "grammar.y" /* yacc.c:1663 */ - { - int result; + { + int result; - check_type_with_cleanup((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "at", yr_free((yyvsp[-2].c_string))); + check_type_with_cleanup( + (yyvsp[0].expression), + EXPRESSION_TYPE_INTEGER, + "at", + yr_free((yyvsp[-2].c_string))); - result = yr_parser_reduce_string_identifier( - yyscanner, (yyvsp[-2].c_string), OP_FOUND_AT, (yyvsp[0].expression).value.integer); + result = yr_parser_reduce_string_identifier( + yyscanner, + (yyvsp[-2].c_string), + OP_FOUND_AT, + (yyvsp[0].expression).value.integer); - yr_free((yyvsp[-2].c_string)); + yr_free((yyvsp[-2].c_string)); - fail_if_error(result); + fail_if_error(result); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3082 "grammar.c" /* yacc.c:1663 */ - break; + break; case 86: #line 1396 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_string_identifier( - yyscanner, (yyvsp[-2].c_string), OP_FOUND_IN, YR_UNDEFINED); + { + int result = yr_parser_reduce_string_identifier( + yyscanner, (yyvsp[-2].c_string), OP_FOUND_IN, YR_UNDEFINED); - yr_free((yyvsp[-2].c_string)); + yr_free((yyvsp[-2].c_string)); - fail_if_error(result); + fail_if_error(result); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3097 "grammar.c" /* yacc.c:1663 */ - break; + break; case 87: #line 1407 "grammar.y" /* yacc.c:1663 */ - { - int i; + { + int i; - // Free all the loop variable identifiers, including the variables for - // the current loop (represented by loop_index), and set loop_index to - // -1. This is OK even if we have nested loops. If an error occurs while - // parsing the inner loop, it will be propagated to the outer loop - // anyways, so it's safe to do this cleanup while processing the error - // for the inner loop. + // Free all the loop variable identifiers, including the variables for + // the current loop (represented by loop_index), and set loop_index to + // -1. This is OK even if we have nested loops. If an error occurs while + // parsing the inner loop, it will be propagated to the outer loop + // anyways, so it's safe to do this cleanup while processing the error + // for the inner loop. - for (i = 0; i <= compiler->loop_index; i++) - { - loop_vars_cleanup(i); - } + for (i = 0; i <= compiler->loop_index; i++) + { + loop_vars_cleanup(i); + } - compiler->loop_index = -1; - YYERROR; - } + compiler->loop_index = -1; + YYERROR; + } #line 3120 "grammar.c" /* yacc.c:1663 */ - break; + break; case 88: #line 1485 "grammar.y" /* yacc.c:1663 */ - { - // var_frame is used for accessing local variables used in this loop. - // All local variables are accessed using var_frame as a reference, - // like var_frame + 0, var_frame + 1, etc. Here we initialize var_frame - // with the correct value, which depends on the number of variables - // defined by any outer loops. + { + // var_frame is used for accessing local variables used in this loop. + // All local variables are accessed using var_frame as a reference, + // like var_frame + 0, var_frame + 1, etc. Here we initialize var_frame + // with the correct value, which depends on the number of variables + // defined by any outer loops. - int var_frame; - int result = ERROR_SUCCESS; + int var_frame; + int result = ERROR_SUCCESS; - if (compiler->loop_index + 1 == YR_MAX_LOOP_NESTING) - result = ERROR_LOOP_NESTING_LIMIT_EXCEEDED; + if (compiler->loop_index + 1 == YR_MAX_LOOP_NESTING) + result = ERROR_LOOP_NESTING_LIMIT_EXCEEDED; - fail_if_error(result); + fail_if_error(result); - compiler->loop_index++; + compiler->loop_index++; - // This loop uses internal variables besides the ones explicitly - // defined by the user. - compiler->loop[compiler->loop_index].vars_internal_count = \ - YR_INTERNAL_LOOP_VARS; + // This loop uses internal variables besides the ones explicitly + // defined by the user. + compiler->loop[compiler->loop_index].vars_internal_count = + YR_INTERNAL_LOOP_VARS; - // Initialize the number of variables, this number will be incremented - // as variable declaration are processed by for_variables. - compiler->loop[compiler->loop_index].vars_count = 0; + // Initialize the number of variables, this number will be incremented + // as variable declaration are processed by for_variables. + compiler->loop[compiler->loop_index].vars_count = 0; - var_frame = _yr_compiler_get_var_frame(compiler); + var_frame = _yr_compiler_get_var_frame(compiler); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_CLEAR_M, var_frame + 0, NULL, NULL)); + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_CLEAR_M, var_frame + 0, NULL, NULL)); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_CLEAR_M, var_frame + 1, NULL, NULL)); + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_CLEAR_M, var_frame + 1, NULL, NULL)); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_POP_M, var_frame + 2, NULL, NULL)); - } + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_POP_M, var_frame + 2, NULL, NULL)); + } #line 3162 "grammar.c" /* yacc.c:1663 */ - break; + break; case 89: #line 1523 "grammar.y" /* yacc.c:1663 */ - { - YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index]; - YR_FIXUP* fixup; + { + YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index]; + YR_FIXUP* fixup; - YR_ARENA_REF loop_start_ref; - YR_ARENA_REF jmp_offset_ref; + YR_ARENA_REF loop_start_ref; + YR_ARENA_REF jmp_offset_ref; - int var_frame = _yr_compiler_get_var_frame(compiler); - int i; + int var_frame = _yr_compiler_get_var_frame(compiler); + int i; - fail_if_error(yr_parser_emit( - yyscanner, OP_ITER_NEXT, &loop_start_ref)); + fail_if_error(yr_parser_emit(yyscanner, OP_ITER_NEXT, &loop_start_ref)); - // For each variable generate an instruction that pops the value from - // the stack and store it into one memory slot starting at var_frame + - // YR_INTERNAL_LOOP_VARS because the first YR_INTERNAL_LOOP_VARS slots - // in the frame are for the internal variables. + // For each variable generate an instruction that pops the value from + // the stack and store it into one memory slot starting at var_frame + + // YR_INTERNAL_LOOP_VARS because the first YR_INTERNAL_LOOP_VARS slots + // in the frame are for the internal variables. - for (i = 0; i < loop_ctx->vars_count; i++) - { - fail_if_error(yr_parser_emit_with_arg( - yyscanner, - OP_POP_M, - var_frame + YR_INTERNAL_LOOP_VARS + i, - NULL, - NULL)); - } + for (i = 0; i < loop_ctx->vars_count; i++) + { + fail_if_error(yr_parser_emit_with_arg( + yyscanner, + OP_POP_M, + var_frame + YR_INTERNAL_LOOP_VARS + i, + NULL, + NULL)); + } - fail_if_error(yr_parser_emit_with_arg_int32( - yyscanner, - OP_JTRUE_P, - 0, // still don't know the jump offset, use 0 for now. - NULL, - &jmp_offset_ref)); + fail_if_error(yr_parser_emit_with_arg_int32( + yyscanner, + OP_JTRUE_P, + 0, // still don't know the jump offset, use 0 for now. + NULL, + &jmp_offset_ref)); - // We still don't know the jump's target, so we push a fixup entry - // in the stack, so that the jump's offset can be set once we know it. + // We still don't know the jump's target, so we push a fixup entry + // in the stack, so that the jump's offset can be set once we know it. - fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP)); + fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP)); - if (fixup == NULL) - fail_with_error(ERROR_INSUFFICIENT_MEMORY); + if (fixup == NULL) + fail_with_error(ERROR_INSUFFICIENT_MEMORY); - fixup->ref = jmp_offset_ref; - fixup->next = compiler->fixup_stack_head; - compiler->fixup_stack_head = fixup; + fixup->ref = jmp_offset_ref; + fixup->next = compiler->fixup_stack_head; + compiler->fixup_stack_head = fixup; - loop_ctx->start_ref = loop_start_ref; - } + loop_ctx->start_ref = loop_start_ref; + } #line 3216 "grammar.c" /* yacc.c:1663 */ - break; + break; case 90: #line 1573 "grammar.y" /* yacc.c:1663 */ - { - int32_t jmp_offset; - YR_FIXUP* fixup; - YR_ARENA_REF pop_ref; - YR_ARENA_REF jmp_offset_ref; + { + int32_t jmp_offset; + YR_FIXUP* fixup; + YR_ARENA_REF pop_ref; + YR_ARENA_REF jmp_offset_ref; - int var_frame = _yr_compiler_get_var_frame(compiler); + int var_frame = _yr_compiler_get_var_frame(compiler); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_ADD_M, var_frame + 0, NULL, NULL)); + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_ADD_M, var_frame + 0, NULL, NULL)); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_INCR_M, var_frame + 1, NULL, NULL)); + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_INCR_M, var_frame + 1, NULL, NULL)); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_PUSH_M, var_frame + 2, NULL, NULL)); + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_PUSH_M, var_frame + 2, NULL, NULL)); - jmp_offset = \ - compiler->loop[compiler->loop_index].start_ref.offset - - yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION); + jmp_offset = compiler->loop[compiler->loop_index].start_ref.offset - + yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION); - fail_if_error(yr_parser_emit_with_arg_int32( - yyscanner, - OP_JUNDEF_P, - jmp_offset, - NULL, - NULL)); + fail_if_error(yr_parser_emit_with_arg_int32( + yyscanner, OP_JUNDEF_P, jmp_offset, NULL, NULL)); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_PUSH_M, var_frame + 0, NULL, NULL)); + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_PUSH_M, var_frame + 0, NULL, NULL)); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_PUSH_M, var_frame + 2, NULL, NULL)); + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_PUSH_M, var_frame + 2, NULL, NULL)); - jmp_offset = \ - compiler->loop[compiler->loop_index].start_ref.offset - - yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION); + jmp_offset = compiler->loop[compiler->loop_index].start_ref.offset - + yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION); - fail_if_error(yr_parser_emit_with_arg_int32( - yyscanner, - OP_JL_P, - jmp_offset, - NULL, - NULL)); + fail_if_error(yr_parser_emit_with_arg_int32( + yyscanner, OP_JL_P, jmp_offset, NULL, NULL)); - fail_if_error(yr_parser_emit( - yyscanner, OP_POP, &pop_ref)); + fail_if_error(yr_parser_emit(yyscanner, OP_POP, &pop_ref)); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_PUSH_M, var_frame + 1, NULL, NULL)); + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_PUSH_M, var_frame + 1, NULL, NULL)); - fail_if_error(yr_parser_emit_with_arg_int32( - yyscanner, - OP_JZ, - 0, // still don't know the jump offset, use 0 for now. - NULL, - &jmp_offset_ref)); + fail_if_error(yr_parser_emit_with_arg_int32( + yyscanner, + OP_JZ, + 0, // still don't know the jump offset, use 0 for now. + NULL, + &jmp_offset_ref)); - fail_if_error(yr_parser_emit( - yyscanner, OP_POP, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_POP, NULL)); - // Pop from the stack the fixup entry containing the reference to - // the jump offset that needs to be fixed. + // Pop from the stack the fixup entry containing the reference to + // the jump offset that needs to be fixed. - fixup = compiler->fixup_stack_head; - compiler->fixup_stack_head = fixup->next; + fixup = compiler->fixup_stack_head; + compiler->fixup_stack_head = fixup->next; - // The fixup entry has a reference to the jump offset that need - // to be fixed, convert the address into a pointer. - int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr( - compiler->arena, &fixup->ref); + // The fixup entry has a reference to the jump offset that need + // to be fixed, convert the address into a pointer. + int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr( + compiler->arena, &fixup->ref); - // The reference in the fixup entry points to the jump's offset - // but the jump instruction is one byte before, that's why we add - // one to the offset. - jmp_offset = pop_ref.offset - fixup->ref.offset + 1; + // The reference in the fixup entry points to the jump's offset + // but the jump instruction is one byte before, that's why we add + // one to the offset. + jmp_offset = pop_ref.offset - fixup->ref.offset + 1; - // Fix the jump's offset. - *jmp_offset_addr = jmp_offset; + // Fix the jump's offset. + *jmp_offset_addr = jmp_offset; - yr_free(fixup); + yr_free(fixup); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_PUSH_M, var_frame + 0, NULL, NULL)); + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_PUSH_M, var_frame + 0, NULL, NULL)); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_PUSH_M, var_frame + 2, NULL, NULL)); + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_PUSH_M, var_frame + 2, NULL, NULL)); - fail_if_error(yr_parser_emit_with_arg( - yyscanner, OP_SWAPUNDEF, var_frame + 1, NULL, NULL)); + fail_if_error(yr_parser_emit_with_arg( + yyscanner, OP_SWAPUNDEF, var_frame + 1, NULL, NULL)); - fail_if_error(yr_parser_emit( - yyscanner, OP_INT_GE, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_INT_GE, NULL)); - jmp_offset = \ - yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION) - - jmp_offset_ref.offset + 1; + jmp_offset = yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION) - + jmp_offset_ref.offset + 1; - jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr( - compiler->arena, &jmp_offset_ref); + jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr( + compiler->arena, &jmp_offset_ref); - *jmp_offset_addr = jmp_offset; + *jmp_offset_addr = jmp_offset; - loop_vars_cleanup(compiler->loop_index); + loop_vars_cleanup(compiler->loop_index); - compiler->loop_index--; + compiler->loop_index--; - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3330 "grammar.c" /* yacc.c:1663 */ - break; + break; case 91: #line 1683 "grammar.y" /* yacc.c:1663 */ - { - YR_ARENA_REF ref; + { + YR_ARENA_REF ref; - int result = ERROR_SUCCESS; - int var_frame; + int result = ERROR_SUCCESS; + int var_frame; - if (compiler->loop_index + 1 == YR_MAX_LOOP_NESTING) - result = ERROR_LOOP_NESTING_LIMIT_EXCEEDED; + if (compiler->loop_index + 1 == YR_MAX_LOOP_NESTING) + result = ERROR_LOOP_NESTING_LIMIT_EXCEEDED; - if (compiler->loop_for_of_var_index != -1) - result = ERROR_NESTED_FOR_OF_LOOP; + if (compiler->loop_for_of_var_index != -1) + result = ERROR_NESTED_FOR_OF_LOOP; - fail_if_error(result); + fail_if_error(result); - compiler->loop_index++; + compiler->loop_index++; - var_frame = _yr_compiler_get_var_frame(compiler); + var_frame = _yr_compiler_get_var_frame(compiler); - yr_parser_emit_with_arg( - yyscanner, OP_CLEAR_M, var_frame + 1, NULL, NULL); + yr_parser_emit_with_arg(yyscanner, OP_CLEAR_M, var_frame + 1, NULL, NULL); - yr_parser_emit_with_arg( - yyscanner, OP_CLEAR_M, var_frame + 2, NULL, NULL); + yr_parser_emit_with_arg(yyscanner, OP_CLEAR_M, var_frame + 2, NULL, NULL); - // Pop the first string. - yr_parser_emit_with_arg( - yyscanner, OP_POP_M, var_frame, &ref, NULL); + // Pop the first string. + yr_parser_emit_with_arg(yyscanner, OP_POP_M, var_frame, &ref, NULL); - compiler->loop_for_of_var_index = var_frame; - compiler->loop[compiler->loop_index].start_ref = ref; - compiler->loop[compiler->loop_index].vars_count = 0; - compiler->loop[compiler->loop_index].vars_internal_count = \ - YR_INTERNAL_LOOP_VARS; - } + compiler->loop_for_of_var_index = var_frame; + compiler->loop[compiler->loop_index].start_ref = ref; + compiler->loop[compiler->loop_index].vars_count = 0; + compiler->loop[compiler->loop_index].vars_internal_count = + YR_INTERNAL_LOOP_VARS; + } #line 3369 "grammar.c" /* yacc.c:1663 */ - break; + break; case 92: #line 1718 "grammar.y" /* yacc.c:1663 */ - { - int var_frame = 0; + { + int var_frame = 0; - compiler->loop_for_of_var_index = -1; + compiler->loop_for_of_var_index = -1; - var_frame = _yr_compiler_get_var_frame(compiler); + var_frame = _yr_compiler_get_var_frame(compiler); - // Increment counter by the value returned by the - // boolean expression (0 or 1). If the boolean expression - // returned YR_UNDEFINED the OP_ADD_M won't do anything. + // Increment counter by the value returned by the + // boolean expression (0 or 1). If the boolean expression + // returned YR_UNDEFINED the OP_ADD_M won't do anything. - yr_parser_emit_with_arg( - yyscanner, OP_ADD_M, var_frame + 1, NULL, NULL); + yr_parser_emit_with_arg(yyscanner, OP_ADD_M, var_frame + 1, NULL, NULL); - // Increment iterations counter. - yr_parser_emit_with_arg( - yyscanner, OP_INCR_M, var_frame + 2, NULL, NULL); + // Increment iterations counter. + yr_parser_emit_with_arg(yyscanner, OP_INCR_M, var_frame + 2, NULL, NULL); - int32_t jmp_offset = \ - compiler->loop[compiler->loop_index].start_ref.offset - - yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION); + int32_t jmp_offset = compiler->loop[compiler->loop_index].start_ref.offset - + yr_arena_get_current_offset( + compiler->arena, YR_CODE_SECTION); - // If next string is not undefined, go back to the - // beginning of the loop. - yr_parser_emit_with_arg_int32( - yyscanner, - OP_JNUNDEF, - jmp_offset, - NULL, - NULL); + // If next string is not undefined, go back to the + // beginning of the loop. + yr_parser_emit_with_arg_int32( + yyscanner, OP_JNUNDEF, jmp_offset, NULL, NULL); - // Pop end-of-list marker. - yr_parser_emit(yyscanner, OP_POP, NULL); + // Pop end-of-list marker. + yr_parser_emit(yyscanner, OP_POP, NULL); - // At this point the loop quantifier (any, all, 1, 2,..) - // is at top of the stack. Check if the quantifier is - // undefined (meaning "all") and replace it with the - // iterations counter in that case. - yr_parser_emit_with_arg( - yyscanner, OP_SWAPUNDEF, var_frame + 2, NULL, NULL); + // At this point the loop quantifier (any, all, 1, 2,..) + // is at top of the stack. Check if the quantifier is + // undefined (meaning "all") and replace it with the + // iterations counter in that case. + yr_parser_emit_with_arg(yyscanner, OP_SWAPUNDEF, var_frame + 2, NULL, NULL); - // Compare the loop quantifier with the number of - // expressions evaluating to true. - yr_parser_emit_with_arg( - yyscanner, OP_PUSH_M, var_frame + 1, NULL, NULL); + // Compare the loop quantifier with the number of + // expressions evaluating to true. + yr_parser_emit_with_arg(yyscanner, OP_PUSH_M, var_frame + 1, NULL, NULL); - yr_parser_emit(yyscanner, OP_INT_LE, NULL); + yr_parser_emit(yyscanner, OP_INT_LE, NULL); - loop_vars_cleanup(compiler->loop_index); + loop_vars_cleanup(compiler->loop_index); - compiler->loop_index--; + compiler->loop_index--; - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3428 "grammar.c" /* yacc.c:1663 */ - break; + break; case 93: #line 1773 "grammar.y" /* yacc.c:1663 */ - { - yr_parser_emit(yyscanner, OP_OF, NULL); + { + yr_parser_emit(yyscanner, OP_OF, NULL); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3438 "grammar.c" /* yacc.c:1663 */ - break; + break; case 94: #line 1779 "grammar.y" /* yacc.c:1663 */ - { - yr_parser_emit(yyscanner, OP_NOT, NULL); + { + yr_parser_emit(yyscanner, OP_NOT, NULL); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3448 "grammar.c" /* yacc.c:1663 */ - break; + break; case 95: #line 1785 "grammar.y" /* yacc.c:1663 */ - { - YR_FIXUP* fixup; - YR_ARENA_REF jmp_offset_ref; + { + YR_FIXUP* fixup; + YR_ARENA_REF jmp_offset_ref; - fail_if_error(yr_parser_emit_with_arg_int32( - yyscanner, - OP_JFALSE, - 0, // still don't know the jump offset, use 0 for now. - NULL, - &jmp_offset_ref)); + fail_if_error(yr_parser_emit_with_arg_int32( + yyscanner, + OP_JFALSE, + 0, // still don't know the jump offset, use 0 for now. + NULL, + &jmp_offset_ref)); - // Create a fixup entry for the jump and push it in the stack. - fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP)); + // Create a fixup entry for the jump and push it in the stack. + fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP)); - if (fixup == NULL) - fail_with_error(ERROR_INSUFFICIENT_MEMORY); + if (fixup == NULL) + fail_with_error(ERROR_INSUFFICIENT_MEMORY); - fixup->ref = jmp_offset_ref; - fixup->next = compiler->fixup_stack_head; - compiler->fixup_stack_head = fixup; - } + fixup->ref = jmp_offset_ref; + fixup->next = compiler->fixup_stack_head; + compiler->fixup_stack_head = fixup; + } #line 3474 "grammar.c" /* yacc.c:1663 */ - break; + break; case 96: #line 1807 "grammar.y" /* yacc.c:1663 */ - { - YR_FIXUP* fixup; + { + YR_FIXUP* fixup; - fail_if_error(yr_parser_emit(yyscanner, OP_AND, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_AND, NULL)); - fixup = compiler->fixup_stack_head; + fixup = compiler->fixup_stack_head; - int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr( - compiler->arena, &fixup->ref); + int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr( + compiler->arena, &fixup->ref); - int32_t jmp_offset = \ - yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION) - - fixup->ref.offset + 1; + int32_t jmp_offset = yr_arena_get_current_offset( + compiler->arena, YR_CODE_SECTION) - + fixup->ref.offset + 1; - *jmp_offset_addr = jmp_offset; + *jmp_offset_addr = jmp_offset; - // Remove fixup from the stack. - compiler->fixup_stack_head = fixup->next; - yr_free(fixup); + // Remove fixup from the stack. + compiler->fixup_stack_head = fixup->next; + yr_free(fixup); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3501 "grammar.c" /* yacc.c:1663 */ - break; + break; case 97: #line 1830 "grammar.y" /* yacc.c:1663 */ - { - YR_FIXUP* fixup; - YR_ARENA_REF jmp_offset_ref; + { + YR_FIXUP* fixup; + YR_ARENA_REF jmp_offset_ref; - fail_if_error(yr_parser_emit_with_arg_int32( - yyscanner, - OP_JTRUE, - 0, // still don't know the jump destination, use 0 for now. - NULL, - &jmp_offset_ref)); + fail_if_error(yr_parser_emit_with_arg_int32( + yyscanner, + OP_JTRUE, + 0, // still don't know the jump destination, use 0 for now. + NULL, + &jmp_offset_ref)); - fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP)); + fixup = (YR_FIXUP*) yr_malloc(sizeof(YR_FIXUP)); - if (fixup == NULL) - fail_with_error(ERROR_INSUFFICIENT_MEMORY); + if (fixup == NULL) + fail_with_error(ERROR_INSUFFICIENT_MEMORY); - fixup->ref = jmp_offset_ref; - fixup->next = compiler->fixup_stack_head; - compiler->fixup_stack_head = fixup; - } + fixup->ref = jmp_offset_ref; + fixup->next = compiler->fixup_stack_head; + compiler->fixup_stack_head = fixup; + } #line 3526 "grammar.c" /* yacc.c:1663 */ - break; + break; case 98: #line 1851 "grammar.y" /* yacc.c:1663 */ - { - YR_FIXUP* fixup; + { + YR_FIXUP* fixup; - fail_if_error(yr_parser_emit(yyscanner, OP_OR, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_OR, NULL)); - fixup = compiler->fixup_stack_head; + fixup = compiler->fixup_stack_head; - int32_t jmp_offset = \ - yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION) - - fixup->ref.offset + 1; + int32_t jmp_offset = yr_arena_get_current_offset( + compiler->arena, YR_CODE_SECTION) - + fixup->ref.offset + 1; - int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr( - compiler->arena, &fixup->ref); + int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr( + compiler->arena, &fixup->ref); - *jmp_offset_addr = jmp_offset; + *jmp_offset_addr = jmp_offset; - // Remove fixup from the stack. - compiler->fixup_stack_head = fixup->next; - yr_free(fixup); + // Remove fixup from the stack. + compiler->fixup_stack_head = fixup->next; + yr_free(fixup); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3553 "grammar.c" /* yacc.c:1663 */ - break; + break; case 99: #line 1874 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_reduce_operation( - yyscanner, "<", (yyvsp[-2].expression), (yyvsp[0].expression))); + { + fail_if_error(yr_parser_reduce_operation( + yyscanner, "<", (yyvsp[-2].expression), (yyvsp[0].expression))); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3564 "grammar.c" /* yacc.c:1663 */ - break; + break; case 100: #line 1881 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_reduce_operation( - yyscanner, ">", (yyvsp[-2].expression), (yyvsp[0].expression))); + { + fail_if_error(yr_parser_reduce_operation( + yyscanner, ">", (yyvsp[-2].expression), (yyvsp[0].expression))); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3575 "grammar.c" /* yacc.c:1663 */ - break; + break; case 101: #line 1888 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_reduce_operation( - yyscanner, "<=", (yyvsp[-2].expression), (yyvsp[0].expression))); + { + fail_if_error(yr_parser_reduce_operation( + yyscanner, "<=", (yyvsp[-2].expression), (yyvsp[0].expression))); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3586 "grammar.c" /* yacc.c:1663 */ - break; + break; case 102: #line 1895 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_reduce_operation( - yyscanner, ">=", (yyvsp[-2].expression), (yyvsp[0].expression))); + { + fail_if_error(yr_parser_reduce_operation( + yyscanner, ">=", (yyvsp[-2].expression), (yyvsp[0].expression))); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3597 "grammar.c" /* yacc.c:1663 */ - break; + break; case 103: #line 1902 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_reduce_operation( - yyscanner, "==", (yyvsp[-2].expression), (yyvsp[0].expression))); + { + fail_if_error(yr_parser_reduce_operation( + yyscanner, "==", (yyvsp[-2].expression), (yyvsp[0].expression))); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3608 "grammar.c" /* yacc.c:1663 */ - break; + break; case 104: #line 1909 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_reduce_operation( - yyscanner, "!=", (yyvsp[-2].expression), (yyvsp[0].expression))); + { + fail_if_error(yr_parser_reduce_operation( + yyscanner, "!=", (yyvsp[-2].expression), (yyvsp[0].expression))); - (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; - } + (yyval.expression).type = EXPRESSION_TYPE_BOOLEAN; + } #line 3619 "grammar.c" /* yacc.c:1663 */ - break; + break; case 105: #line 1916 "grammar.y" /* yacc.c:1663 */ - { - (yyval.expression) = (yyvsp[0].expression); - } + { + (yyval.expression) = (yyvsp[0].expression); + } #line 3627 "grammar.c" /* yacc.c:1663 */ - break; + break; case 106: #line 1920 "grammar.y" /* yacc.c:1663 */ - { - (yyval.expression) = (yyvsp[-1].expression); - } + { + (yyval.expression) = (yyvsp[-1].expression); + } #line 3635 "grammar.c" /* yacc.c:1663 */ - break; + break; case 107: #line 1928 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + { + int result = ERROR_SUCCESS; - YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index]; + YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index]; - if (yr_parser_lookup_loop_variable(yyscanner, (yyvsp[0].c_string), NULL) >= 0) - { - yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string)); - yr_free((yyvsp[0].c_string)); + if (yr_parser_lookup_loop_variable(yyscanner, (yyvsp[0].c_string), NULL) >= + 0) + { + yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string)); + yr_free((yyvsp[0].c_string)); - result = ERROR_DUPLICATED_LOOP_IDENTIFIER; - } + result = ERROR_DUPLICATED_LOOP_IDENTIFIER; + } - fail_if_error(result); + fail_if_error(result); - loop_ctx->vars[loop_ctx->vars_count++].identifier.ptr = (yyvsp[0].c_string); + loop_ctx->vars[loop_ctx->vars_count++].identifier.ptr = (yyvsp[0].c_string); - assert(loop_ctx->vars_count <= YR_MAX_LOOP_VARS); - } + assert(loop_ctx->vars_count <= YR_MAX_LOOP_VARS); + } #line 3659 "grammar.c" /* yacc.c:1663 */ - break; + break; case 108: #line 1948 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + { + int result = ERROR_SUCCESS; - YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index]; + YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index]; - if (loop_ctx->vars_count == YR_MAX_LOOP_VARS) - { - yr_compiler_set_error_extra_info(compiler, "too many loop variables"); - yr_free((yyvsp[0].c_string)); + if (loop_ctx->vars_count == YR_MAX_LOOP_VARS) + { + yr_compiler_set_error_extra_info(compiler, "too many loop variables"); + yr_free((yyvsp[0].c_string)); - result = ERROR_SYNTAX_ERROR; - } - else if (yr_parser_lookup_loop_variable(yyscanner, (yyvsp[0].c_string), NULL) >= 0) - { - yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string)); - yr_free((yyvsp[0].c_string)); + result = ERROR_SYNTAX_ERROR; + } + else if ( + yr_parser_lookup_loop_variable(yyscanner, (yyvsp[0].c_string), NULL) >= + 0) + { + yr_compiler_set_error_extra_info(compiler, (yyvsp[0].c_string)); + yr_free((yyvsp[0].c_string)); - result = ERROR_DUPLICATED_LOOP_IDENTIFIER; - } + result = ERROR_DUPLICATED_LOOP_IDENTIFIER; + } - fail_if_error(result); + fail_if_error(result); - loop_ctx->vars[loop_ctx->vars_count++].identifier.ptr = (yyvsp[0].c_string); - } + loop_ctx->vars[loop_ctx->vars_count++].identifier.ptr = (yyvsp[0].c_string); + } #line 3688 "grammar.c" /* yacc.c:1663 */ - break; + break; case 109: #line 1976 "grammar.y" /* yacc.c:1663 */ - { - YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index]; + { + YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index]; - // Initially we assume that the identifier is from a non-iterable type, - // this will change later if it's iterable. - int result = ERROR_WRONG_TYPE; + // Initially we assume that the identifier is from a non-iterable type, + // this will change later if it's iterable. + int result = ERROR_WRONG_TYPE; - if ((yyvsp[0].expression).type == EXPRESSION_TYPE_OBJECT) + if ((yyvsp[0].expression).type == EXPRESSION_TYPE_OBJECT) + { + switch ((yyvsp[0].expression).value.object->type) + { + case OBJECT_TYPE_ARRAY: + // If iterating an array the loop must define a single variable + // that will hold the current item. If a different number of + // variables were defined that's an error. + if (loop_ctx->vars_count == 1) { - switch((yyvsp[0].expression).value.object->type) - { - case OBJECT_TYPE_ARRAY: - // If iterating an array the loop must define a single variable - // that will hold the current item. If a different number of - // variables were defined that's an error. - if (loop_ctx->vars_count == 1) - { - loop_ctx->vars[0].type = EXPRESSION_TYPE_OBJECT; - loop_ctx->vars[0].value.object = \ - object_as_array((yyvsp[0].expression).value.object)->prototype_item; - - result = yr_parser_emit(yyscanner, OP_ITER_START_ARRAY, NULL); - } - else - { - yr_compiler_set_error_extra_info_fmt( - compiler, - "iterator for \"%s\" yields a single item on each iteration" - ", but the loop expects %d", - expression_identifier((yyvsp[0].expression)), - loop_ctx->vars_count); - - result = ERROR_SYNTAX_ERROR; - } - break; - - case OBJECT_TYPE_DICTIONARY: - // If iterating a dictionary the loop must define exactly two - // variables, one for the key and another for the value . If a - // different number of variables were defined that's an error. - if (loop_ctx->vars_count == 2) - { - loop_ctx->vars[0].type = EXPRESSION_TYPE_STRING; - loop_ctx->vars[0].value.sized_string_ref = YR_ARENA_NULL_REF; - loop_ctx->vars[1].type = EXPRESSION_TYPE_OBJECT; - loop_ctx->vars[1].value.object = \ - object_as_array((yyvsp[0].expression).value.object)->prototype_item; - - result = yr_parser_emit(yyscanner, OP_ITER_START_DICT, NULL); - } - else - { - yr_compiler_set_error_extra_info_fmt( - compiler, - "iterator for \"%s\" yields a key,value pair item on each iteration", - expression_identifier((yyvsp[0].expression))); - - result = ERROR_SYNTAX_ERROR; - } - break; - } - } + loop_ctx->vars[0].type = EXPRESSION_TYPE_OBJECT; + loop_ctx->vars[0].value.object = + object_as_array((yyvsp[0].expression).value.object) + ->prototype_item; - if (result == ERROR_WRONG_TYPE) + result = yr_parser_emit(yyscanner, OP_ITER_START_ARRAY, NULL); + } + else { yr_compiler_set_error_extra_info_fmt( compiler, - "identifier \"%s\" is not iterable", - expression_identifier((yyvsp[0].expression))); - } - - fail_if_error(result); - } -#line 3766 "grammar.c" /* yacc.c:1663 */ - break; - - case 110: -#line 2050 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + "iterator for \"%s\" yields a single item on each iteration" + ", but the loop expects %d", + expression_identifier((yyvsp[0].expression)), + loop_ctx->vars_count); - YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index]; + result = ERROR_SYNTAX_ERROR; + } + break; - if (loop_ctx->vars_count == 1) + case OBJECT_TYPE_DICTIONARY: + // If iterating a dictionary the loop must define exactly two + // variables, one for the key and another for the value . If a + // different number of variables were defined that's an error. + if (loop_ctx->vars_count == 2) { - loop_ctx->vars[0].type = EXPRESSION_TYPE_INTEGER; - loop_ctx->vars[0].value.integer = YR_UNDEFINED; + loop_ctx->vars[0].type = EXPRESSION_TYPE_STRING; + loop_ctx->vars[0].value.sized_string_ref = YR_ARENA_NULL_REF; + loop_ctx->vars[1].type = EXPRESSION_TYPE_OBJECT; + loop_ctx->vars[1].value.object = + object_as_array((yyvsp[0].expression).value.object) + ->prototype_item; + + result = yr_parser_emit(yyscanner, OP_ITER_START_DICT, NULL); } else { yr_compiler_set_error_extra_info_fmt( compiler, - "iterator yields an integer on each iteration " - ", but the loop expects %d", - loop_ctx->vars_count); + "iterator for \"%s\" yields a key,value pair item on each " + "iteration", + expression_identifier((yyvsp[0].expression))); result = ERROR_SYNTAX_ERROR; } - - fail_if_error(result); + break; } + } + + if (result == ERROR_WRONG_TYPE) + { + yr_compiler_set_error_extra_info_fmt( + compiler, + "identifier \"%s\" is not iterable", + expression_identifier((yyvsp[0].expression))); + } + + fail_if_error(result); + } +#line 3766 "grammar.c" /* yacc.c:1663 */ + break; + + case 110: +#line 2050 "grammar.y" /* yacc.c:1663 */ + { + int result = ERROR_SUCCESS; + + YR_LOOP_CONTEXT* loop_ctx = &compiler->loop[compiler->loop_index]; + + if (loop_ctx->vars_count == 1) + { + loop_ctx->vars[0].type = EXPRESSION_TYPE_INTEGER; + loop_ctx->vars[0].value.integer = YR_UNDEFINED; + } + else + { + yr_compiler_set_error_extra_info_fmt( + compiler, + "iterator yields an integer on each iteration " + ", but the loop expects %d", + loop_ctx->vars_count); + + result = ERROR_SYNTAX_ERROR; + } + + fail_if_error(result); + } #line 3794 "grammar.c" /* yacc.c:1663 */ - break; + break; case 111: #line 2078 "grammar.y" /* yacc.c:1663 */ - { - // $2 contains the number of integers in the enumeration - fail_if_error(yr_parser_emit_push_const(yyscanner, (yyvsp[-1].integer))); + { + // $2 contains the number of integers in the enumeration + fail_if_error(yr_parser_emit_push_const(yyscanner, (yyvsp[-1].integer))); - fail_if_error(yr_parser_emit( - yyscanner, OP_ITER_START_INT_ENUM, NULL)); - } + fail_if_error(yr_parser_emit(yyscanner, OP_ITER_START_INT_ENUM, NULL)); + } #line 3806 "grammar.c" /* yacc.c:1663 */ - break; + break; case 112: #line 2086 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_emit( - yyscanner, OP_ITER_START_INT_RANGE, NULL)); - } + { + fail_if_error(yr_parser_emit(yyscanner, OP_ITER_START_INT_RANGE, NULL)); + } #line 3815 "grammar.c" /* yacc.c:1663 */ - break; + break; case 113: #line 2095 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + { + int result = ERROR_SUCCESS; - if ((yyvsp[-3].expression).type != EXPRESSION_TYPE_INTEGER) - { - yr_compiler_set_error_extra_info( - compiler, "wrong type for range's lower bound"); - result = ERROR_WRONG_TYPE; - } + if ((yyvsp[-3].expression).type != EXPRESSION_TYPE_INTEGER) + { + yr_compiler_set_error_extra_info( + compiler, "wrong type for range's lower bound"); + result = ERROR_WRONG_TYPE; + } - if ((yyvsp[-1].expression).type != EXPRESSION_TYPE_INTEGER) - { - yr_compiler_set_error_extra_info( - compiler, "wrong type for range's upper bound"); - result = ERROR_WRONG_TYPE; - } + if ((yyvsp[-1].expression).type != EXPRESSION_TYPE_INTEGER) + { + yr_compiler_set_error_extra_info( + compiler, "wrong type for range's upper bound"); + result = ERROR_WRONG_TYPE; + } - fail_if_error(result); - } + fail_if_error(result); + } #line 3839 "grammar.c" /* yacc.c:1663 */ - break; + break; case 114: #line 2119 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + { + int result = ERROR_SUCCESS; - if ((yyvsp[0].expression).type != EXPRESSION_TYPE_INTEGER) - { - yr_compiler_set_error_extra_info( - compiler, "wrong type for enumeration item"); - result = ERROR_WRONG_TYPE; - } + if ((yyvsp[0].expression).type != EXPRESSION_TYPE_INTEGER) + { + yr_compiler_set_error_extra_info( + compiler, "wrong type for enumeration item"); + result = ERROR_WRONG_TYPE; + } - fail_if_error(result); + fail_if_error(result); - (yyval.integer) = 1; - } + (yyval.integer) = 1; + } #line 3858 "grammar.c" /* yacc.c:1663 */ - break; + break; case 115: #line 2134 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + { + int result = ERROR_SUCCESS; - if ((yyvsp[0].expression).type != EXPRESSION_TYPE_INTEGER) - { - yr_compiler_set_error_extra_info( - compiler, "wrong type for enumeration item"); - result = ERROR_WRONG_TYPE; - } + if ((yyvsp[0].expression).type != EXPRESSION_TYPE_INTEGER) + { + yr_compiler_set_error_extra_info( + compiler, "wrong type for enumeration item"); + result = ERROR_WRONG_TYPE; + } - fail_if_error(result); + fail_if_error(result); - (yyval.integer) = (yyvsp[-2].integer) + 1; - } + (yyval.integer) = (yyvsp[-2].integer) + 1; + } #line 3877 "grammar.c" /* yacc.c:1663 */ - break; + break; case 116: #line 2153 "grammar.y" /* yacc.c:1663 */ - { - // Push end-of-list marker - yr_parser_emit_push_const(yyscanner, YR_UNDEFINED); - } + { + // Push end-of-list marker + yr_parser_emit_push_const(yyscanner, YR_UNDEFINED); + } #line 3886 "grammar.c" /* yacc.c:1663 */ - break; + break; case 118: #line 2159 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_emit_push_const(yyscanner, YR_UNDEFINED)); + { + fail_if_error(yr_parser_emit_push_const(yyscanner, YR_UNDEFINED)); - fail_if_error(yr_parser_emit_pushes_for_strings( - yyscanner, "$*")); - } + fail_if_error(yr_parser_emit_pushes_for_strings(yyscanner, "$*")); + } #line 3897 "grammar.c" /* yacc.c:1663 */ - break; + break; case 121: #line 2176 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_emit_pushes_for_strings(yyscanner, (yyvsp[0].c_string)); - yr_free((yyvsp[0].c_string)); + { + int result = yr_parser_emit_pushes_for_strings( + yyscanner, (yyvsp[0].c_string)); + yr_free((yyvsp[0].c_string)); - fail_if_error(result); - } + fail_if_error(result); + } #line 3908 "grammar.c" /* yacc.c:1663 */ - break; + break; case 122: #line 2183 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_emit_pushes_for_strings(yyscanner, (yyvsp[0].c_string)); - yr_free((yyvsp[0].c_string)); + { + int result = yr_parser_emit_pushes_for_strings( + yyscanner, (yyvsp[0].c_string)); + yr_free((yyvsp[0].c_string)); - fail_if_error(result); - } + fail_if_error(result); + } #line 3919 "grammar.c" /* yacc.c:1663 */ - break; + break; case 123: #line 2194 "grammar.y" /* yacc.c:1663 */ - { - (yyval.integer) = FOR_EXPRESSION_ANY; - } + { + (yyval.integer) = FOR_EXPRESSION_ANY; + } #line 3927 "grammar.c" /* yacc.c:1663 */ - break; + break; case 124: #line 2198 "grammar.y" /* yacc.c:1663 */ - { - yr_parser_emit_push_const(yyscanner, YR_UNDEFINED); - (yyval.integer) = FOR_EXPRESSION_ALL; - } + { + yr_parser_emit_push_const(yyscanner, YR_UNDEFINED); + (yyval.integer) = FOR_EXPRESSION_ALL; + } #line 3936 "grammar.c" /* yacc.c:1663 */ - break; + break; case 125: #line 2203 "grammar.y" /* yacc.c:1663 */ - { - yr_parser_emit_push_const(yyscanner, 1); - (yyval.integer) = FOR_EXPRESSION_ANY; - } + { + yr_parser_emit_push_const(yyscanner, 1); + (yyval.integer) = FOR_EXPRESSION_ANY; + } #line 3945 "grammar.c" /* yacc.c:1663 */ - break; + break; case 126: #line 2212 "grammar.y" /* yacc.c:1663 */ - { - (yyval.expression) = (yyvsp[-1].expression); - } + { + (yyval.expression) = (yyvsp[-1].expression); + } #line 3953 "grammar.c" /* yacc.c:1663 */ - break; + break; case 127: #line 2216 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_emit( - yyscanner, OP_FILESIZE, NULL)); + { + fail_if_error(yr_parser_emit(yyscanner, OP_FILESIZE, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = YR_UNDEFINED; - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = YR_UNDEFINED; + } #line 3965 "grammar.c" /* yacc.c:1663 */ - break; + break; case 128: #line 2224 "grammar.y" /* yacc.c:1663 */ - { - yywarning(yyscanner, - "Using deprecated \"entrypoint\" keyword. Use the \"entry_point\" " - "function from PE module instead."); + { + yywarning( + yyscanner, + "Using deprecated \"entrypoint\" keyword. Use the \"entry_point\" " + "function from PE module instead."); - fail_if_error(yr_parser_emit( - yyscanner, OP_ENTRYPOINT, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_ENTRYPOINT, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = YR_UNDEFINED; - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = YR_UNDEFINED; + } #line 3981 "grammar.c" /* yacc.c:1663 */ - break; + break; case 129: #line 2236 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-1].expression), EXPRESSION_TYPE_INTEGER, "intXXXX or uintXXXX"); + { + check_type( + (yyvsp[-1].expression), EXPRESSION_TYPE_INTEGER, "intXXXX or uintXXXX"); - // _INTEGER_FUNCTION_ could be any of int8, int16, int32, uint8, - // uint32, etc. $1 contains an index that added to OP_READ_INT results - // in the proper OP_INTXX opcode. + // _INTEGER_FUNCTION_ could be any of int8, int16, int32, uint8, + // uint32, etc. $1 contains an index that added to OP_READ_INT results + // in the proper OP_INTXX opcode. - fail_if_error(yr_parser_emit( - yyscanner, (uint8_t) (OP_READ_INT + (yyvsp[-3].integer)), NULL)); + fail_if_error(yr_parser_emit( + yyscanner, (uint8_t)(OP_READ_INT + (yyvsp[-3].integer)), NULL)); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = YR_UNDEFINED; - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = YR_UNDEFINED; + } #line 3999 "grammar.c" /* yacc.c:1663 */ - break; + break; case 130: #line 2250 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_emit_push_const(yyscanner, (yyvsp[0].integer))); + { + fail_if_error(yr_parser_emit_push_const(yyscanner, (yyvsp[0].integer))); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = (yyvsp[0].integer); - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = (yyvsp[0].integer); + } #line 4010 "grammar.c" /* yacc.c:1663 */ - break; + break; case 131: #line 2257 "grammar.y" /* yacc.c:1663 */ - { - fail_if_error(yr_parser_emit_with_arg_double( - yyscanner, OP_PUSH, (yyvsp[0].double_), NULL, NULL)); + { + fail_if_error(yr_parser_emit_with_arg_double( + yyscanner, OP_PUSH, (yyvsp[0].double_), NULL, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_FLOAT; - } + (yyval.expression).type = EXPRESSION_TYPE_FLOAT; + } #line 4021 "grammar.c" /* yacc.c:1663 */ - break; + break; case 132: #line 2264 "grammar.y" /* yacc.c:1663 */ - { - YR_ARENA_REF ref; + { + YR_ARENA_REF ref; - int result = _yr_compiler_store_data( - compiler, - (yyvsp[0].sized_string), - (yyvsp[0].sized_string)->length + sizeof(SIZED_STRING), - &ref); + int result = _yr_compiler_store_data( + compiler, + (yyvsp[0].sized_string), + (yyvsp[0].sized_string)->length + sizeof(SIZED_STRING), + &ref); - yr_free((yyvsp[0].sized_string)); + yr_free((yyvsp[0].sized_string)); - if (result == ERROR_SUCCESS) - result = yr_parser_emit_with_arg_reloc( - yyscanner, - OP_PUSH, - yr_arena_ref_to_ptr(compiler->arena, &ref), - NULL, - NULL); + if (result == ERROR_SUCCESS) + result = yr_parser_emit_with_arg_reloc( + yyscanner, + OP_PUSH, + yr_arena_ref_to_ptr(compiler->arena, &ref), + NULL, + NULL); - fail_if_error(result); + fail_if_error(result); - (yyval.expression).type = EXPRESSION_TYPE_STRING; - (yyval.expression).value.sized_string_ref = ref; - } + (yyval.expression).type = EXPRESSION_TYPE_STRING; + (yyval.expression).value.sized_string_ref = ref; + } #line 4050 "grammar.c" /* yacc.c:1663 */ - break; + break; case 133: #line 2289 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_string_identifier( - yyscanner, (yyvsp[0].c_string), OP_COUNT, YR_UNDEFINED); + { + int result = yr_parser_reduce_string_identifier( + yyscanner, (yyvsp[0].c_string), OP_COUNT, YR_UNDEFINED); - yr_free((yyvsp[0].c_string)); + yr_free((yyvsp[0].c_string)); - fail_if_error(result); + fail_if_error(result); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = YR_UNDEFINED; - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = YR_UNDEFINED; + } #line 4066 "grammar.c" /* yacc.c:1663 */ - break; + break; case 134: #line 2301 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_string_identifier( - yyscanner, (yyvsp[-3].c_string), OP_OFFSET, YR_UNDEFINED); + { + int result = yr_parser_reduce_string_identifier( + yyscanner, (yyvsp[-3].c_string), OP_OFFSET, YR_UNDEFINED); - yr_free((yyvsp[-3].c_string)); + yr_free((yyvsp[-3].c_string)); - fail_if_error(result); + fail_if_error(result); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = YR_UNDEFINED; - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = YR_UNDEFINED; + } #line 4082 "grammar.c" /* yacc.c:1663 */ - break; + break; case 135: #line 2313 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_emit_push_const(yyscanner, 1); - - if (result == ERROR_SUCCESS) - result = yr_parser_reduce_string_identifier( - yyscanner, (yyvsp[0].c_string), OP_OFFSET, YR_UNDEFINED); - - yr_free((yyvsp[0].c_string)); + { + int result = yr_parser_emit_push_const(yyscanner, 1); - fail_if_error(result); + if (result == ERROR_SUCCESS) + result = yr_parser_reduce_string_identifier( + yyscanner, (yyvsp[0].c_string), OP_OFFSET, YR_UNDEFINED); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = YR_UNDEFINED; - } + yr_free((yyvsp[0].c_string)); + + fail_if_error(result); + + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = YR_UNDEFINED; + } #line 4101 "grammar.c" /* yacc.c:1663 */ - break; + break; case 136: #line 2328 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_string_identifier( - yyscanner, (yyvsp[-3].c_string), OP_LENGTH, YR_UNDEFINED); + { + int result = yr_parser_reduce_string_identifier( + yyscanner, (yyvsp[-3].c_string), OP_LENGTH, YR_UNDEFINED); - yr_free((yyvsp[-3].c_string)); + yr_free((yyvsp[-3].c_string)); - fail_if_error(result); + fail_if_error(result); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = YR_UNDEFINED; - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = YR_UNDEFINED; + } #line 4117 "grammar.c" /* yacc.c:1663 */ - break; + break; case 137: #line 2340 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_emit_push_const(yyscanner, 1); + { + int result = yr_parser_emit_push_const(yyscanner, 1); - if (result == ERROR_SUCCESS) - result = yr_parser_reduce_string_identifier( - yyscanner, (yyvsp[0].c_string), OP_LENGTH, YR_UNDEFINED); + if (result == ERROR_SUCCESS) + result = yr_parser_reduce_string_identifier( + yyscanner, (yyvsp[0].c_string), OP_LENGTH, YR_UNDEFINED); - yr_free((yyvsp[0].c_string)); + yr_free((yyvsp[0].c_string)); - fail_if_error(result); + fail_if_error(result); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = YR_UNDEFINED; - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = YR_UNDEFINED; + } #line 4136 "grammar.c" /* yacc.c:1663 */ - break; + break; case 138: #line 2355 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + { + int result = ERROR_SUCCESS; - if ((yyvsp[0].expression).type == EXPRESSION_TYPE_OBJECT) - { - result = yr_parser_emit( - yyscanner, OP_OBJ_VALUE, NULL); + if ((yyvsp[0].expression).type == EXPRESSION_TYPE_OBJECT) + { + result = yr_parser_emit(yyscanner, OP_OBJ_VALUE, NULL); - switch((yyvsp[0].expression).value.object->type) - { - case OBJECT_TYPE_INTEGER: - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = YR_UNDEFINED; - break; - case OBJECT_TYPE_FLOAT: - (yyval.expression).type = EXPRESSION_TYPE_FLOAT; - break; - case OBJECT_TYPE_STRING: - (yyval.expression).type = EXPRESSION_TYPE_STRING; - (yyval.expression).value.sized_string_ref = YR_ARENA_NULL_REF; - break; - default: - // In a primary expression any identifier that corresponds to an - // object must be of type integer, float or string. If "foobar" is - // either a function, structure, dictionary or array you can not - // use it as: - // condition: foobar - yr_compiler_set_error_extra_info_fmt( - compiler, - "wrong usage of identifier \"%s\"", - expression_identifier((yyvsp[0].expression))); - - result = ERROR_WRONG_TYPE; - } - } - else - { - (yyval.expression) = (yyvsp[0].expression); - } + switch ((yyvsp[0].expression).value.object->type) + { + case OBJECT_TYPE_INTEGER: + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = YR_UNDEFINED; + break; + case OBJECT_TYPE_FLOAT: + (yyval.expression).type = EXPRESSION_TYPE_FLOAT; + break; + case OBJECT_TYPE_STRING: + (yyval.expression).type = EXPRESSION_TYPE_STRING; + (yyval.expression).value.sized_string_ref = YR_ARENA_NULL_REF; + break; + default: + // In a primary expression any identifier that corresponds to an + // object must be of type integer, float or string. If "foobar" is + // either a function, structure, dictionary or array you can not + // use it as: + // condition: foobar + yr_compiler_set_error_extra_info_fmt( + compiler, + "wrong usage of identifier \"%s\"", + expression_identifier((yyvsp[0].expression))); - fail_if_error(result); + result = ERROR_WRONG_TYPE; } + } + else + { + (yyval.expression) = (yyvsp[0].expression); + } + + fail_if_error(result); + } #line 4183 "grammar.c" /* yacc.c:1663 */ - break; + break; case 139: #line 2398 "grammar.y" /* yacc.c:1663 */ - { - int result = ERROR_SUCCESS; + { + int result = ERROR_SUCCESS; - check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER | EXPRESSION_TYPE_FLOAT, "-"); + check_type( + (yyvsp[0].expression), + EXPRESSION_TYPE_INTEGER | EXPRESSION_TYPE_FLOAT, + "-"); - if ((yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER) - { - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = ((yyvsp[0].expression).value.integer == YR_UNDEFINED) ? - YR_UNDEFINED : -((yyvsp[0].expression).value.integer); - result = yr_parser_emit(yyscanner, OP_INT_MINUS, NULL); - } - else if ((yyvsp[0].expression).type == EXPRESSION_TYPE_FLOAT) - { - (yyval.expression).type = EXPRESSION_TYPE_FLOAT; - result = yr_parser_emit(yyscanner, OP_DBL_MINUS, NULL); - } + if ((yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER) + { + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = + ((yyvsp[0].expression).value.integer == YR_UNDEFINED) + ? YR_UNDEFINED + : -((yyvsp[0].expression).value.integer); + result = yr_parser_emit(yyscanner, OP_INT_MINUS, NULL); + } + else if ((yyvsp[0].expression).type == EXPRESSION_TYPE_FLOAT) + { + (yyval.expression).type = EXPRESSION_TYPE_FLOAT; + result = yr_parser_emit(yyscanner, OP_DBL_MINUS, NULL); + } - fail_if_error(result); - } + fail_if_error(result); + } #line 4208 "grammar.c" /* yacc.c:1663 */ - break; + break; case 140: #line 2419 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_operation( - yyscanner, "+", (yyvsp[-2].expression), (yyvsp[0].expression)); + { + int result = yr_parser_reduce_operation( + yyscanner, "+", (yyvsp[-2].expression), (yyvsp[0].expression)); - if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && - (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER) - { - int64_t i1 = (yyvsp[-2].expression).value.integer; - int64_t i2 = (yyvsp[0].expression).value.integer; - - if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) && - ( - (i2 > 0 && i1 > INT64_MAX - i2) || - (i2 < 0 && i1 < INT64_MIN - i2) - )) - { - yr_compiler_set_error_extra_info_fmt( - compiler, "%" PRId64 " + %" PRId64, i1, i2); + if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && + (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER) + { + int64_t i1 = (yyvsp[-2].expression).value.integer; + int64_t i2 = (yyvsp[0].expression).value.integer; - result = ERROR_INTEGER_OVERFLOW; - } - else - { - (yyval.expression).value.integer = OPERATION(+, i1, i2); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - } - } - else - { - (yyval.expression).type = EXPRESSION_TYPE_FLOAT; - } + if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) && + ((i2 > 0 && i1 > INT64_MAX - i2) || (i2 < 0 && i1 < INT64_MIN - i2))) + { + yr_compiler_set_error_extra_info_fmt( + compiler, "%" PRId64 " + %" PRId64, i1, i2); - fail_if_error(result); + result = ERROR_INTEGER_OVERFLOW; + } + else + { + (yyval.expression).value.integer = OPERATION(+, i1, i2); + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; } + } + else + { + (yyval.expression).type = EXPRESSION_TYPE_FLOAT; + } + + fail_if_error(result); + } #line 4247 "grammar.c" /* yacc.c:1663 */ - break; + break; case 141: #line 2454 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_operation( - yyscanner, "-", (yyvsp[-2].expression), (yyvsp[0].expression)); + { + int result = yr_parser_reduce_operation( + yyscanner, "-", (yyvsp[-2].expression), (yyvsp[0].expression)); - if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && - (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER) - { - int64_t i1 = (yyvsp[-2].expression).value.integer; - int64_t i2 = (yyvsp[0].expression).value.integer; - - if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) && - ( - (i2 < 0 && i1 > INT64_MAX + i2) || - (i2 > 0 && i1 < INT64_MIN + i2) - )) - { - yr_compiler_set_error_extra_info_fmt( - compiler, "%" PRId64 " - %" PRId64, i1, i2); + if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && + (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER) + { + int64_t i1 = (yyvsp[-2].expression).value.integer; + int64_t i2 = (yyvsp[0].expression).value.integer; - result = ERROR_INTEGER_OVERFLOW; - } - else - { - (yyval.expression).value.integer = OPERATION(-, i1, i2); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - } - } - else - { - (yyval.expression).type = EXPRESSION_TYPE_FLOAT; - } + if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) && + ((i2 < 0 && i1 > INT64_MAX + i2) || (i2 > 0 && i1 < INT64_MIN + i2))) + { + yr_compiler_set_error_extra_info_fmt( + compiler, "%" PRId64 " - %" PRId64, i1, i2); - fail_if_error(result); + result = ERROR_INTEGER_OVERFLOW; + } + else + { + (yyval.expression).value.integer = OPERATION(-, i1, i2); + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; } + } + else + { + (yyval.expression).type = EXPRESSION_TYPE_FLOAT; + } + + fail_if_error(result); + } #line 4286 "grammar.c" /* yacc.c:1663 */ - break; + break; case 142: #line 2489 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_operation( - yyscanner, "*", (yyvsp[-2].expression), (yyvsp[0].expression)); - - if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && - (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER) - { - int64_t i1 = (yyvsp[-2].expression).value.integer; - int64_t i2 = (yyvsp[0].expression).value.integer; + { + int result = yr_parser_reduce_operation( + yyscanner, "*", (yyvsp[-2].expression), (yyvsp[0].expression)); - if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) && - ( - i2 != 0 && llabs(i1) > INT64_MAX / llabs(i2) - )) - { - yr_compiler_set_error_extra_info_fmt( - compiler, "%" PRId64 " * %" PRId64, i1, i2); + if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && + (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER) + { + int64_t i1 = (yyvsp[-2].expression).value.integer; + int64_t i2 = (yyvsp[0].expression).value.integer; - result = ERROR_INTEGER_OVERFLOW; - } - else - { - (yyval.expression).value.integer = OPERATION(*, i1, i2); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - } - } - else - { - (yyval.expression).type = EXPRESSION_TYPE_FLOAT; - } + if (!IS_UNDEFINED(i1) && !IS_UNDEFINED(i2) && + (i2 != 0 && llabs(i1) > INT64_MAX / llabs(i2))) + { + yr_compiler_set_error_extra_info_fmt( + compiler, "%" PRId64 " * %" PRId64, i1, i2); - fail_if_error(result); + result = ERROR_INTEGER_OVERFLOW; + } + else + { + (yyval.expression).value.integer = OPERATION(*, i1, i2); + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; } + } + else + { + (yyval.expression).type = EXPRESSION_TYPE_FLOAT; + } + + fail_if_error(result); + } #line 4324 "grammar.c" /* yacc.c:1663 */ - break; + break; case 143: #line 2523 "grammar.y" /* yacc.c:1663 */ - { - int result = yr_parser_reduce_operation( - yyscanner, "\\", (yyvsp[-2].expression), (yyvsp[0].expression)); - - if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && - (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER) - { - if ((yyvsp[0].expression).value.integer != 0) - { - (yyval.expression).value.integer = OPERATION(/, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - } - else - { - result = ERROR_DIVISION_BY_ZERO; - } - } - else - { - (yyval.expression).type = EXPRESSION_TYPE_FLOAT; - } + { + int result = yr_parser_reduce_operation( + yyscanner, "\\", (yyvsp[-2].expression), (yyvsp[0].expression)); - fail_if_error(result); + if ((yyvsp[-2].expression).type == EXPRESSION_TYPE_INTEGER && + (yyvsp[0].expression).type == EXPRESSION_TYPE_INTEGER) + { + if ((yyvsp[0].expression).value.integer != 0) + { + (yyval.expression).value.integer = OPERATION( + /, + (yyvsp[-2].expression).value.integer, + (yyvsp[0].expression).value.integer); + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + } + else + { + result = ERROR_DIVISION_BY_ZERO; } + } + else + { + (yyval.expression).type = EXPRESSION_TYPE_FLOAT; + } + + fail_if_error(result); + } #line 4353 "grammar.c" /* yacc.c:1663 */ - break; + break; case 144: #line 2548 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "%"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "%"); + { + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "%"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "%"); - fail_if_error(yr_parser_emit(yyscanner, OP_MOD, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_MOD, NULL)); - if ((yyvsp[0].expression).value.integer != 0) - { - (yyval.expression).value.integer = OPERATION(%, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - } - else - { - fail_if_error(ERROR_DIVISION_BY_ZERO); - } - } + if ((yyvsp[0].expression).value.integer != 0) + { + (yyval.expression).value.integer = OPERATION( + %, + (yyvsp[-2].expression).value.integer, + (yyvsp[0].expression).value.integer); + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + } + else + { + fail_if_error(ERROR_DIVISION_BY_ZERO); + } + } #line 4374 "grammar.c" /* yacc.c:1663 */ - break; + break; case 145: #line 2565 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "^"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "^"); + { + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "^"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "^"); - fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_XOR, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_XOR, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = OPERATION(^, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer); - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = OPERATION( + ^, + (yyvsp[-2].expression).value.integer, + (yyvsp[0].expression).value.integer); + } #line 4388 "grammar.c" /* yacc.c:1663 */ - break; + break; case 146: #line 2575 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "^"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "^"); + { + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "^"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "^"); - fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_AND, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_AND, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = OPERATION(&, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer); - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = OPERATION(&, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer); + } #line 4402 "grammar.c" /* yacc.c:1663 */ - break; + break; case 147: #line 2585 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "|"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "|"); + { + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "|"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "|"); - fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_OR, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_OR, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = OPERATION(|, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer); - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = OPERATION( + |, + (yyvsp[-2].expression).value.integer, + (yyvsp[0].expression).value.integer); + } #line 4416 "grammar.c" /* yacc.c:1663 */ - break; + break; case 148: #line 2595 "grammar.y" /* yacc.c:1663 */ - { - check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "~"); + { + check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "~"); - fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_NOT, NULL)); + fail_if_error(yr_parser_emit(yyscanner, OP_BITWISE_NOT, NULL)); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - (yyval.expression).value.integer = ((yyvsp[0].expression).value.integer == YR_UNDEFINED) ? - YR_UNDEFINED : ~((yyvsp[0].expression).value.integer); - } + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).value.integer = + ((yyvsp[0].expression).value.integer == YR_UNDEFINED) + ? YR_UNDEFINED + : ~((yyvsp[0].expression).value.integer); + } #line 4430 "grammar.c" /* yacc.c:1663 */ - break; + break; case 149: #line 2605 "grammar.y" /* yacc.c:1663 */ - { - int result; + { + int result; - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "<<"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "<<"); + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, "<<"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, "<<"); - result = yr_parser_emit(yyscanner, OP_SHL, NULL); + result = yr_parser_emit(yyscanner, OP_SHL, NULL); - if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer < 0) - result = ERROR_INVALID_OPERAND; - else if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer >= 64) - (yyval.expression).value.integer = 0; - else - (yyval.expression).value.integer = OPERATION(<<, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer); + if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && + (yyvsp[0].expression).value.integer < 0) + result = ERROR_INVALID_OPERAND; + else if ( + !IS_UNDEFINED((yyvsp[0].expression).value.integer) && + (yyvsp[0].expression).value.integer >= 64) + (yyval.expression).value.integer = 0; + else + (yyval.expression).value.integer = OPERATION( + <<, + (yyvsp[-2].expression).value.integer, + (yyvsp[0].expression).value.integer); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - fail_if_error(result); - } + fail_if_error(result); + } #line 4454 "grammar.c" /* yacc.c:1663 */ - break; + break; case 150: #line 2625 "grammar.y" /* yacc.c:1663 */ - { - int result; + { + int result; - check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, ">>"); - check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, ">>"); + check_type((yyvsp[-2].expression), EXPRESSION_TYPE_INTEGER, ">>"); + check_type((yyvsp[0].expression), EXPRESSION_TYPE_INTEGER, ">>"); - result = yr_parser_emit(yyscanner, OP_SHR, NULL); + result = yr_parser_emit(yyscanner, OP_SHR, NULL); - if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer < 0) - result = ERROR_INVALID_OPERAND; - else if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && (yyvsp[0].expression).value.integer >= 64) - (yyval.expression).value.integer = 0; - else - (yyval.expression).value.integer = OPERATION(<<, (yyvsp[-2].expression).value.integer, (yyvsp[0].expression).value.integer); + if (!IS_UNDEFINED((yyvsp[0].expression).value.integer) && + (yyvsp[0].expression).value.integer < 0) + result = ERROR_INVALID_OPERAND; + else if ( + !IS_UNDEFINED((yyvsp[0].expression).value.integer) && + (yyvsp[0].expression).value.integer >= 64) + (yyval.expression).value.integer = 0; + else + (yyval.expression).value.integer = OPERATION( + <<, + (yyvsp[-2].expression).value.integer, + (yyvsp[0].expression).value.integer); - (yyval.expression).type = EXPRESSION_TYPE_INTEGER; + (yyval.expression).type = EXPRESSION_TYPE_INTEGER; - fail_if_error(result); - } + fail_if_error(result); + } #line 4478 "grammar.c" /* yacc.c:1663 */ - break; + break; case 151: #line 2645 "grammar.y" /* yacc.c:1663 */ - { - (yyval.expression) = (yyvsp[0].expression); - } + { + (yyval.expression) = (yyvsp[0].expression); + } #line 4486 "grammar.c" /* yacc.c:1663 */ - break; + break; #line 4490 "grammar.c" /* yacc.c:1663 */ - default: break; - } + default: + break; + } /* User semantic actions sometimes alter yychar, and that requires that yytoken be updated with the new translation. We take the approach of translating immediately before every use of yytoken. @@ -4500,11 +4594,11 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT("-> $$ =", yyr1[yyn], &yyval, &yyloc); - YYPOPSTACK (yylen); + YYPOPSTACK(yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT(yyss, yyssp); *++yyvsp = yyval; @@ -4529,68 +4623,65 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE(yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) - { - ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (yyscanner, compiler, YY_("syntax error")); + { + ++yynerrs; +#if !YYERROR_VERBOSE + yyerror(yyscanner, compiler, YY_("syntax error")); #else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) +#define YYSYNTAX_ERROR yysyntax_error(&yymsg_alloc, &yymsg, yyssp, yytoken) + { + char const* yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) + if (yymsg != yymsgbuf) + YYSTACK_FREE(yymsg); + yymsg = (char*) YYSTACK_ALLOC(yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (yyscanner, compiler, yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; + } } -# undef YYSYNTAX_ERROR -#endif + yyerror(yyscanner, compiler, yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } - +#undef YYSYNTAX_ERROR +#endif + } if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ - if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } - else - { - yydestruct ("Error: discarding", - yytoken, &yylval, yyscanner, compiler); - yychar = YYEMPTY; - } + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct("Error: discarding", yytoken, &yylval, yyscanner, compiler); + yychar = YYEMPTY; } + } /* Else will try to reuse lookahead token after shifting the error token. */ @@ -4606,13 +4697,13 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); YYERROR and the label yyerrorlab therefore never appears in user code. */ if (/*CONSTCOND*/ 0) - goto yyerrorlab; + goto yyerrorlab; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ - YYPOPSTACK (yylen); + YYPOPSTACK(yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT(yyss, yyssp); yystate = *yyssp; goto yyerrlab1; @@ -4621,33 +4712,32 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ + yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default(yyn)) { - yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; - yydestruct ("Error: popping", - yystos[yystate], yyvsp, yyscanner, compiler); - YYPOPSTACK (1); - yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); - } + yydestruct("Error: popping", yystos[yystate], yyvsp, yyscanner, compiler); + YYPOPSTACK(1); + yystate = *yyssp; + YY_STACK_PRINT(yyss, yyssp); + } YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; @@ -4655,7 +4745,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -4680,39 +4770,37 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (yyscanner, compiler, YY_("memory exhausted")); + yyerror(yyscanner, compiler, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: if (yychar != YYEMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, yyscanner, compiler); - } + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE(yychar); + yydestruct( + "Cleanup: discarding lookahead", yytoken, &yylval, yyscanner, compiler); + } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); + YYPOPSTACK(yylen); + YY_STACK_PRINT(yyss, yyssp); while (yyssp != yyss) - { - yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yyscanner, compiler); - YYPOPSTACK (1); - } + { + yydestruct("Cleanup: popping", yystos[*yyssp], yyvsp, yyscanner, compiler); + YYPOPSTACK(1); + } #ifndef yyoverflow if (yyss != yyssa) - YYSTACK_FREE (yyss); + YYSTACK_FREE(yyss); #endif #if YYERROR_VERBOSE if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); + YYSTACK_FREE(yymsg); #endif return yyresult; } #line 2650 "grammar.y" /* yacc.c:1907 */ - diff --git a/libyara/grammar.h b/libyara/grammar.h index c9f9a3d975..b7a45faf9d 100644 --- a/libyara/grammar.h +++ b/libyara/grammar.h @@ -31,10 +31,10 @@ version 2.2 of Bison. */ #ifndef YY_YARA_YY_GRAMMAR_H_INCLUDED -# define YY_YARA_YY_GRAMMAR_H_INCLUDED +#define YY_YARA_YY_GRAMMAR_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG -# define YYDEBUG 0 +#define YYDEBUG 0 #endif #if YYDEBUG extern int yara_yydebug; @@ -42,144 +42,144 @@ extern int yara_yydebug; /* Token type. */ #ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - _END_OF_FILE_ = 0, - _END_OF_INCLUDED_FILE_ = 258, - _DOT_DOT_ = 259, - _RULE_ = 260, - _PRIVATE_ = 261, - _GLOBAL_ = 262, - _META_ = 263, - _STRINGS_ = 264, - _CONDITION_ = 265, - _IDENTIFIER_ = 266, - _STRING_IDENTIFIER_ = 267, - _STRING_COUNT_ = 268, - _STRING_OFFSET_ = 269, - _STRING_LENGTH_ = 270, - _STRING_IDENTIFIER_WITH_WILDCARD_ = 271, - _NUMBER_ = 272, - _DOUBLE_ = 273, - _INTEGER_FUNCTION_ = 274, - _TEXT_STRING_ = 275, - _HEX_STRING_ = 276, - _REGEXP_ = 277, - _ASCII_ = 278, - _WIDE_ = 279, - _XOR_ = 280, - _BASE64_ = 281, - _BASE64_WIDE_ = 282, - _NOCASE_ = 283, - _FULLWORD_ = 284, - _AT_ = 285, - _FILESIZE_ = 286, - _ENTRYPOINT_ = 287, - _ALL_ = 288, - _ANY_ = 289, - _IN_ = 290, - _OF_ = 291, - _FOR_ = 292, - _THEM_ = 293, - _MATCHES_ = 294, - _CONTAINS_ = 295, - _STARTSWITH_ = 296, - _ENDSWITH_ = 297, - _ICONTAINS_ = 298, - _ISTARTSWITH_ = 299, - _IENDSWITH_ = 300, - _IMPORT_ = 301, - _TRUE_ = 302, - _FALSE_ = 303, - _OR_ = 304, - _AND_ = 305, - _NOT_ = 306, - _EQ_ = 307, - _NEQ_ = 308, - _LT_ = 309, - _LE_ = 310, - _GT_ = 311, - _GE_ = 312, - _SHIFT_LEFT_ = 313, - _SHIFT_RIGHT_ = 314, - UNARY_MINUS = 315 - }; +#define YYTOKENTYPE +enum yytokentype +{ + _END_OF_FILE_ = 0, + _END_OF_INCLUDED_FILE_ = 258, + _DOT_DOT_ = 259, + _RULE_ = 260, + _PRIVATE_ = 261, + _GLOBAL_ = 262, + _META_ = 263, + _STRINGS_ = 264, + _CONDITION_ = 265, + _IDENTIFIER_ = 266, + _STRING_IDENTIFIER_ = 267, + _STRING_COUNT_ = 268, + _STRING_OFFSET_ = 269, + _STRING_LENGTH_ = 270, + _STRING_IDENTIFIER_WITH_WILDCARD_ = 271, + _NUMBER_ = 272, + _DOUBLE_ = 273, + _INTEGER_FUNCTION_ = 274, + _TEXT_STRING_ = 275, + _HEX_STRING_ = 276, + _REGEXP_ = 277, + _ASCII_ = 278, + _WIDE_ = 279, + _XOR_ = 280, + _BASE64_ = 281, + _BASE64_WIDE_ = 282, + _NOCASE_ = 283, + _FULLWORD_ = 284, + _AT_ = 285, + _FILESIZE_ = 286, + _ENTRYPOINT_ = 287, + _ALL_ = 288, + _ANY_ = 289, + _IN_ = 290, + _OF_ = 291, + _FOR_ = 292, + _THEM_ = 293, + _MATCHES_ = 294, + _CONTAINS_ = 295, + _STARTSWITH_ = 296, + _ENDSWITH_ = 297, + _ICONTAINS_ = 298, + _ISTARTSWITH_ = 299, + _IENDSWITH_ = 300, + _IMPORT_ = 301, + _TRUE_ = 302, + _FALSE_ = 303, + _OR_ = 304, + _AND_ = 305, + _NOT_ = 306, + _EQ_ = 307, + _NEQ_ = 308, + _LT_ = 309, + _LE_ = 310, + _GT_ = 311, + _GE_ = 312, + _SHIFT_LEFT_ = 313, + _SHIFT_RIGHT_ = 314, + UNARY_MINUS = 315 +}; #endif /* Tokens. */ -#define _END_OF_FILE_ 0 -#define _END_OF_INCLUDED_FILE_ 258 -#define _DOT_DOT_ 259 -#define _RULE_ 260 -#define _PRIVATE_ 261 -#define _GLOBAL_ 262 -#define _META_ 263 -#define _STRINGS_ 264 -#define _CONDITION_ 265 -#define _IDENTIFIER_ 266 -#define _STRING_IDENTIFIER_ 267 -#define _STRING_COUNT_ 268 -#define _STRING_OFFSET_ 269 -#define _STRING_LENGTH_ 270 +#define _END_OF_FILE_ 0 +#define _END_OF_INCLUDED_FILE_ 258 +#define _DOT_DOT_ 259 +#define _RULE_ 260 +#define _PRIVATE_ 261 +#define _GLOBAL_ 262 +#define _META_ 263 +#define _STRINGS_ 264 +#define _CONDITION_ 265 +#define _IDENTIFIER_ 266 +#define _STRING_IDENTIFIER_ 267 +#define _STRING_COUNT_ 268 +#define _STRING_OFFSET_ 269 +#define _STRING_LENGTH_ 270 #define _STRING_IDENTIFIER_WITH_WILDCARD_ 271 -#define _NUMBER_ 272 -#define _DOUBLE_ 273 -#define _INTEGER_FUNCTION_ 274 -#define _TEXT_STRING_ 275 -#define _HEX_STRING_ 276 -#define _REGEXP_ 277 -#define _ASCII_ 278 -#define _WIDE_ 279 -#define _XOR_ 280 -#define _BASE64_ 281 -#define _BASE64_WIDE_ 282 -#define _NOCASE_ 283 -#define _FULLWORD_ 284 -#define _AT_ 285 -#define _FILESIZE_ 286 -#define _ENTRYPOINT_ 287 -#define _ALL_ 288 -#define _ANY_ 289 -#define _IN_ 290 -#define _OF_ 291 -#define _FOR_ 292 -#define _THEM_ 293 -#define _MATCHES_ 294 -#define _CONTAINS_ 295 -#define _STARTSWITH_ 296 -#define _ENDSWITH_ 297 -#define _ICONTAINS_ 298 -#define _ISTARTSWITH_ 299 -#define _IENDSWITH_ 300 -#define _IMPORT_ 301 -#define _TRUE_ 302 -#define _FALSE_ 303 -#define _OR_ 304 -#define _AND_ 305 -#define _NOT_ 306 -#define _EQ_ 307 -#define _NEQ_ 308 -#define _LT_ 309 -#define _LE_ 310 -#define _GT_ 311 -#define _GE_ 312 -#define _SHIFT_LEFT_ 313 -#define _SHIFT_RIGHT_ 314 -#define UNARY_MINUS 315 +#define _NUMBER_ 272 +#define _DOUBLE_ 273 +#define _INTEGER_FUNCTION_ 274 +#define _TEXT_STRING_ 275 +#define _HEX_STRING_ 276 +#define _REGEXP_ 277 +#define _ASCII_ 278 +#define _WIDE_ 279 +#define _XOR_ 280 +#define _BASE64_ 281 +#define _BASE64_WIDE_ 282 +#define _NOCASE_ 283 +#define _FULLWORD_ 284 +#define _AT_ 285 +#define _FILESIZE_ 286 +#define _ENTRYPOINT_ 287 +#define _ALL_ 288 +#define _ANY_ 289 +#define _IN_ 290 +#define _OF_ 291 +#define _FOR_ 292 +#define _THEM_ 293 +#define _MATCHES_ 294 +#define _CONTAINS_ 295 +#define _STARTSWITH_ 296 +#define _ENDSWITH_ 297 +#define _ICONTAINS_ 298 +#define _ISTARTSWITH_ 299 +#define _IENDSWITH_ 300 +#define _IMPORT_ 301 +#define _TRUE_ 302 +#define _FALSE_ 303 +#define _OR_ 304 +#define _AND_ 305 +#define _NOT_ 306 +#define _EQ_ 307 +#define _NEQ_ 308 +#define _LT_ 309 +#define _LE_ 310 +#define _GT_ 311 +#define _GE_ 312 +#define _SHIFT_LEFT_ 313 +#define _SHIFT_RIGHT_ 314 +#define UNARY_MINUS 315 /* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED union YYSTYPE { #line 302 "grammar.y" /* yacc.c:1916 */ - YR_EXPRESSION expression; - SIZED_STRING* sized_string; - char* c_string; - int64_t integer; - double double_; - YR_MODIFIER modifier; + YR_EXPRESSION expression; + SIZED_STRING* sized_string; + char* c_string; + int64_t integer; + double double_; + YR_MODIFIER modifier; YR_ARENA_REF tag; YR_ARENA_REF rule; @@ -190,12 +190,11 @@ union YYSTYPE }; typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 +#define YYSTYPE_IS_TRIVIAL 1 +#define YYSTYPE_IS_DECLARED 1 #endif - -int yara_yyparse (void *yyscanner, YR_COMPILER* compiler); +int yara_yyparse(void* yyscanner, YR_COMPILER* compiler); #endif /* !YY_YARA_YY_GRAMMAR_H_INCLUDED */ diff --git a/libyara/hash.c b/libyara/hash.c index a7898be974..e6e37c0b6e 100644 --- a/libyara/hash.c +++ b/libyara/hash.c @@ -29,69 +29,69 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include - -#include -#include +#include #include +#include #include -#include +#include // Constant-time left rotate that does not invoke undefined behavior. // http://blog.regehr.org/archives/1063 -static uint32_t rotl32(uint32_t x, uint32_t shift) { +static uint32_t rotl32(uint32_t x, uint32_t shift) +{ assert(shift < 32); return (x << shift) | (x >> (-shift & 31)); } -#define ROTATE_INT32(x, shift) \ - rotl32(x, shift % 32) - -uint32_t byte_to_int32[] = -{ - 0xC3113E7F,0x4C353C5F,0x7423810B,0x258D264E,0xDAD39DED,0x75D0B694,0x98CE1216, - 0x93334482,0xC5C48EA5,0xF57E0E8B,0x5D7F3723,0x396B1B24,0xA8883D9F,0xB2A74A00, - 0xF8E171AE,0x3F01FBAB,0x5C1840CB,0xDDD833C4,0x8D8CCA34,0x32EF223A,0x1A05B871, - 0x9A9B6BFC,0x50406A0C,0xE7E1FC04,0x5E07D7F6,0x80B83660,0x20892A62,0xB2C6FEA6, - 0x6CEC7CAA,0x182F764B,0x3B0353E7,0x57FC2520,0x4B6812D4,0xACB654E4,0x23C75C04, - 0xB1DCD731,0xE3AF0733,0xF2366D39,0xC729671B,0xFF3BE6F2,0xABA37E34,0x3CDAFA38, - 0xAAD18D03,0xA8D35345,0x08E9A92C,0xF9324059,0x42D821BE,0x1BC152DD,0x5588811C, - 0x874A1F9A,0x6E83E9CD,0xDA6F3AF8,0x965D4670,0xA7A565C0,0x68D8A9AF,0xFC8FD8FD, - 0x8FF99FF9,0x4C9B42AE,0x2D066A8D,0x4D1802F7,0x557032B2,0x12BCF371,0xDC29D5AE, - 0x72EA361F,0xE2835B0B,0xDFC58966,0x13B0F34D,0x3FA02BCD,0xBF282E3D,0x7DC877F5, - 0xF4848A32,0x861E35F5,0x7FFA0D7F,0x515F2E4E,0x6B235D5C,0x55F46E24,0x35AD2C99, - 0x072654A8,0x05163F0F,0x9317B11A,0xAED1FC10,0x989444F0,0xDB3E1814,0x446C0CF1, - 0x660BF511,0x2F227D3A,0xFDBA0539,0xC649E621,0x5204D7CE,0x5FA386D0,0xE5F22005, - 0x97B6C8A1,0x4AB69EC2,0x5C7CA70D,0x39A48EC6,0x7BACF378,0x8D0ED3D1,0xE39DE582, - 0xC5FBE2AB,0x37E3D2D0,0x06F44724,0x73144144,0xBA57E905,0xB05B4307,0xAEED8D97, - 0xA68CCAC4,0xE30DA57E,0xED0F194B,0x8C2B9B7A,0x814575D5,0x79588493,0x81D3712A, - 0x3FA892F2,0x80F0BB94,0x44EAF51A,0x4E05F1D4,0xFC69F858,0x775E8D60,0x22B20DD7, - 0x170A87EA,0x1077DE52,0x3D5EC9FB,0x0B6EB1E5,0xF2F9CCAF,0xA76C7DEB,0xD8C2D873, - 0xF438C592,0x6239FEEC,0x26D3D2A9,0x30F6FADF,0x4B2984CC,0x6257F3DA,0x0E0583E2, - 0x143E5E61,0xBB2732BF,0x9653217A,0x027A84EA,0x95C9AE8B,0x89B8B82B,0x9F286485, - 0x29F622FE,0x52A3196B,0x8392D95F,0x33A79167,0xF5DEE92A,0x6E397DB9,0x11931C01, - 0x8DD2CD3B,0xF9E6003D,0xAB955AF4,0xD38725F9,0xDCF6F8AE,0x7667A958,0xE67AD995, - 0xB7CF979A,0xD88EBE5B,0x5BA889F0,0x078BDD90,0x447238F9,0x3135F672,0x187B95A8, - 0x0B7D5751,0xACD59D2A,0x9C5D1929,0x579E5022,0xEA90499B,0x59901800,0x82237DB5, - 0x7A375509,0xACA9A22A,0xEC96E649,0x69339DB0,0x081D0D9B,0xD72FB8B9,0xA4184653, - 0xC057321D,0xED19CAB9,0xB48F1E3E,0xB9DAC51E,0xDAED2FC7,0x7598CBBD,0x208DF346, - 0x044BE6EC,0x1C63E6EB,0xA15F64C1,0xE024A061,0x68309584,0x0758A68D,0xF274E9AE, - 0x0ABEA0CC,0xED4FB267,0x63D6EC46,0x9F28E026,0xF0694A17,0x9D6E9115,0xC4600FAD, - 0x5B121E99,0xD6B4A13B,0xF5364B8A,0x8514B254,0x0182F8DD,0xDB09F90B,0x78C70B32, - 0xD8EC3B02,0x8CD7084D,0xA4439838,0x72F35A3D,0x200B48A5,0xE2351444,0xA5552F5F, - 0xD8C1E746,0x0FE5EF3C,0xB6A47063,0x61F4E68B,0x08FED99B,0x7E461445,0x43CB8380, - 0x28BA03C8,0x21A7A2E2,0x43437ED6,0x2A9E6670,0x89B4A106,0xC6C2F4EE,0x9C4063CC, - 0x2FA0DF6C,0xB54DC409,0xCF01538F,0x616431D7,0x02CB0E4D,0x44FFF425,0xAAD5188E, - 0x0742E9BC,0xFFF41353,0x130F0A15,0x787BDC10,0x4A327B72,0x702989F7,0x5F704798, - 0x8156A1BB,0x2BCA3E74,0x1911A8C4,0x5E1F27D3,0x07949DC7,0xF24C2056,0xB4299EE6, - 0x9C7045D9,0xA8BF6307,0x7454AAD2,0x256425E5,0xD87DEF67,0xCFE95452,0xE7548DF7, - 0xA84956C7,0xD8402C60,0xCFBD0373,0x6B6CDAFE -}; - - -uint32_t yr_hash( - uint32_t seed, - const void* buffer, - size_t len) +#define ROTATE_INT32(x, shift) rotl32(x, shift % 32) + +uint32_t byte_to_int32[] = { + 0xC3113E7F, 0x4C353C5F, 0x7423810B, 0x258D264E, 0xDAD39DED, 0x75D0B694, + 0x98CE1216, 0x93334482, 0xC5C48EA5, 0xF57E0E8B, 0x5D7F3723, 0x396B1B24, + 0xA8883D9F, 0xB2A74A00, 0xF8E171AE, 0x3F01FBAB, 0x5C1840CB, 0xDDD833C4, + 0x8D8CCA34, 0x32EF223A, 0x1A05B871, 0x9A9B6BFC, 0x50406A0C, 0xE7E1FC04, + 0x5E07D7F6, 0x80B83660, 0x20892A62, 0xB2C6FEA6, 0x6CEC7CAA, 0x182F764B, + 0x3B0353E7, 0x57FC2520, 0x4B6812D4, 0xACB654E4, 0x23C75C04, 0xB1DCD731, + 0xE3AF0733, 0xF2366D39, 0xC729671B, 0xFF3BE6F2, 0xABA37E34, 0x3CDAFA38, + 0xAAD18D03, 0xA8D35345, 0x08E9A92C, 0xF9324059, 0x42D821BE, 0x1BC152DD, + 0x5588811C, 0x874A1F9A, 0x6E83E9CD, 0xDA6F3AF8, 0x965D4670, 0xA7A565C0, + 0x68D8A9AF, 0xFC8FD8FD, 0x8FF99FF9, 0x4C9B42AE, 0x2D066A8D, 0x4D1802F7, + 0x557032B2, 0x12BCF371, 0xDC29D5AE, 0x72EA361F, 0xE2835B0B, 0xDFC58966, + 0x13B0F34D, 0x3FA02BCD, 0xBF282E3D, 0x7DC877F5, 0xF4848A32, 0x861E35F5, + 0x7FFA0D7F, 0x515F2E4E, 0x6B235D5C, 0x55F46E24, 0x35AD2C99, 0x072654A8, + 0x05163F0F, 0x9317B11A, 0xAED1FC10, 0x989444F0, 0xDB3E1814, 0x446C0CF1, + 0x660BF511, 0x2F227D3A, 0xFDBA0539, 0xC649E621, 0x5204D7CE, 0x5FA386D0, + 0xE5F22005, 0x97B6C8A1, 0x4AB69EC2, 0x5C7CA70D, 0x39A48EC6, 0x7BACF378, + 0x8D0ED3D1, 0xE39DE582, 0xC5FBE2AB, 0x37E3D2D0, 0x06F44724, 0x73144144, + 0xBA57E905, 0xB05B4307, 0xAEED8D97, 0xA68CCAC4, 0xE30DA57E, 0xED0F194B, + 0x8C2B9B7A, 0x814575D5, 0x79588493, 0x81D3712A, 0x3FA892F2, 0x80F0BB94, + 0x44EAF51A, 0x4E05F1D4, 0xFC69F858, 0x775E8D60, 0x22B20DD7, 0x170A87EA, + 0x1077DE52, 0x3D5EC9FB, 0x0B6EB1E5, 0xF2F9CCAF, 0xA76C7DEB, 0xD8C2D873, + 0xF438C592, 0x6239FEEC, 0x26D3D2A9, 0x30F6FADF, 0x4B2984CC, 0x6257F3DA, + 0x0E0583E2, 0x143E5E61, 0xBB2732BF, 0x9653217A, 0x027A84EA, 0x95C9AE8B, + 0x89B8B82B, 0x9F286485, 0x29F622FE, 0x52A3196B, 0x8392D95F, 0x33A79167, + 0xF5DEE92A, 0x6E397DB9, 0x11931C01, 0x8DD2CD3B, 0xF9E6003D, 0xAB955AF4, + 0xD38725F9, 0xDCF6F8AE, 0x7667A958, 0xE67AD995, 0xB7CF979A, 0xD88EBE5B, + 0x5BA889F0, 0x078BDD90, 0x447238F9, 0x3135F672, 0x187B95A8, 0x0B7D5751, + 0xACD59D2A, 0x9C5D1929, 0x579E5022, 0xEA90499B, 0x59901800, 0x82237DB5, + 0x7A375509, 0xACA9A22A, 0xEC96E649, 0x69339DB0, 0x081D0D9B, 0xD72FB8B9, + 0xA4184653, 0xC057321D, 0xED19CAB9, 0xB48F1E3E, 0xB9DAC51E, 0xDAED2FC7, + 0x7598CBBD, 0x208DF346, 0x044BE6EC, 0x1C63E6EB, 0xA15F64C1, 0xE024A061, + 0x68309584, 0x0758A68D, 0xF274E9AE, 0x0ABEA0CC, 0xED4FB267, 0x63D6EC46, + 0x9F28E026, 0xF0694A17, 0x9D6E9115, 0xC4600FAD, 0x5B121E99, 0xD6B4A13B, + 0xF5364B8A, 0x8514B254, 0x0182F8DD, 0xDB09F90B, 0x78C70B32, 0xD8EC3B02, + 0x8CD7084D, 0xA4439838, 0x72F35A3D, 0x200B48A5, 0xE2351444, 0xA5552F5F, + 0xD8C1E746, 0x0FE5EF3C, 0xB6A47063, 0x61F4E68B, 0x08FED99B, 0x7E461445, + 0x43CB8380, 0x28BA03C8, 0x21A7A2E2, 0x43437ED6, 0x2A9E6670, 0x89B4A106, + 0xC6C2F4EE, 0x9C4063CC, 0x2FA0DF6C, 0xB54DC409, 0xCF01538F, 0x616431D7, + 0x02CB0E4D, 0x44FFF425, 0xAAD5188E, 0x0742E9BC, 0xFFF41353, 0x130F0A15, + 0x787BDC10, 0x4A327B72, 0x702989F7, 0x5F704798, 0x8156A1BB, 0x2BCA3E74, + 0x1911A8C4, 0x5E1F27D3, 0x07949DC7, 0xF24C2056, 0xB4299EE6, 0x9C7045D9, + 0xA8BF6307, 0x7454AAD2, 0x256425E5, 0xD87DEF67, 0xCFE95452, 0xE7548DF7, + 0xA84956C7, 0xD8402C60, 0xCFBD0373, 0x6B6CDAFE}; + + +uint32_t yr_hash(uint32_t seed, const void* buffer, size_t len) { const uint8_t* b = (uint8_t*) buffer; @@ -140,13 +140,13 @@ static void* _yr_hash_table_lookup( while (entry != NULL) { - int key_match = ( - (entry->key_length == key_length) && - (memcmp(entry->key, key, key_length) == 0)); + int key_match = + ((entry->key_length == key_length) && + (memcmp(entry->key, key, key_length) == 0)); - int ns_match = ( - (entry->ns == ns) || - (entry->ns != NULL && ns != NULL && strcmp(entry->ns, ns) == 0)); + int ns_match = + ((entry->ns == ns) || + (entry->ns != NULL && ns != NULL && strcmp(entry->ns, ns) == 0)); if (key_match && ns_match) { @@ -177,9 +177,7 @@ static void* _yr_hash_table_lookup( } -YR_API int yr_hash_table_create( - int size, - YR_HASH_TABLE** table) +YR_API int yr_hash_table_create(int size, YR_HASH_TABLE** table) { YR_HASH_TABLE* new_table; int i; @@ -192,8 +190,7 @@ YR_API int yr_hash_table_create( new_table->size = size; - for (i = 0; i < size; i++) - new_table->buckets[i] = NULL; + for (i = 0; i < size; i++) new_table->buckets[i] = NULL; *table = new_table; @@ -331,11 +328,7 @@ YR_API void* yr_hash_table_lookup( const char* key, const char* ns) { - return yr_hash_table_lookup_raw_key( - table, - (void*) key, - strlen(key), - ns); + return yr_hash_table_lookup_raw_key(table, (void*) key, strlen(key), ns); } @@ -344,11 +337,7 @@ YR_API void* yr_hash_table_remove( const char* key, const char* ns) { - return yr_hash_table_remove_raw_key( - table, - (void*) key, - strlen(key), - ns); + return yr_hash_table_remove_raw_key(table, (void*) key, strlen(key), ns); } @@ -358,12 +347,7 @@ YR_API int yr_hash_table_add( const char* ns, void* value) { - return yr_hash_table_add_raw_key( - table, - (void*) key, - strlen(key), - ns, - value); + return yr_hash_table_add_raw_key(table, (void*) key, strlen(key), ns, value); } @@ -374,11 +358,7 @@ YR_API int yr_hash_table_add_uint32( uint32_t value) { return yr_hash_table_add_uint32_raw_key( - table, - (void*) key, - strlen(key), - ns, - value); + table, (void*) key, strlen(key), ns, value); } @@ -388,10 +368,7 @@ YR_API uint32_t yr_hash_table_lookup_uint32( const char* ns) { return yr_hash_table_lookup_uint32_raw_key( - table, - (void*) key, - strlen(key), - ns); + table, (void*) key, strlen(key), ns); } @@ -410,7 +387,7 @@ YR_API int yr_hash_table_add_uint32_raw_key( // hash table once the integer is casted to a pointer. This is undone // by yr_hash_table_lookup_uint32. return yr_hash_table_add_raw_key( - table, key, key_length, ns, (void*) (size_t) (value + 1)); + table, key, key_length, ns, (void*) (size_t)(value + 1)); } @@ -427,5 +404,5 @@ YR_API uint32_t yr_hash_table_lookup_uint32_raw_key( // Remove one from the pointer before converting back to integer, see // comment in yr_hash_table_add_uint32. - return (uint32_t) (size_t) ((uint8_t*) ptr - 1); + return (uint32_t)(size_t)((uint8_t*) ptr - 1); } diff --git a/libyara/hex_grammar.c b/libyara/hex_grammar.c index 5c15f07887..9201bc79d1 100644 --- a/libyara/hex_grammar.c +++ b/libyara/hex_grammar.c @@ -60,78 +60,77 @@ /* Substitute the variable and function names. */ -#define yyparse hex_yyparse -#define yylex hex_yylex -#define yyerror hex_yyerror -#define yydebug hex_yydebug -#define yynerrs hex_yynerrs +#define yyparse hex_yyparse +#define yylex hex_yylex +#define yyerror hex_yyerror +#define yydebug hex_yydebug +#define yynerrs hex_yynerrs /* Copy the first part of user declarations. */ #line 30 "hex_grammar.y" /* yacc.c:339 */ -#include #include - -#include -#include +#include +#include #include +#include #include #include -#include +#include #define STR_EXPAND(tok) #tok -#define STR(tok) STR_EXPAND(tok) +#define STR(tok) STR_EXPAND(tok) #define YYERROR_VERBOSE #define YYMALLOC yr_malloc -#define YYFREE yr_free +#define YYFREE yr_free #define mark_as_not_fast_regexp() \ - ((RE_AST*) yyget_extra(yyscanner))->flags &= ~RE_FLAGS_FAST_REGEXP + ((RE_AST *) yyget_extra(yyscanner))->flags &= ~RE_FLAGS_FAST_REGEXP -#define fail_if(x, error) \ - if (x) \ - { \ - lex_env->last_error = error; \ - YYABORT; \ - } \ +#define fail_if(x, error) \ + if (x) \ + { \ + lex_env->last_error = error; \ + YYABORT; \ + } #define destroy_node_if(x, node) \ - if (x) \ - { \ - yr_re_node_destroy(node); \ - } \ + if (x) \ + { \ + yr_re_node_destroy(node); \ + } #line 111 "hex_grammar.c" /* yacc.c:339 */ -# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# endif +#ifndef YY_NULLPTR +#if defined __cplusplus && 201103L <= __cplusplus +#define YY_NULLPTR nullptr +#else +#define YY_NULLPTR 0 +#endif +#endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 +#undef YYERROR_VERBOSE +#define YYERROR_VERBOSE 1 #else -# define YYERROR_VERBOSE 0 +#define YYERROR_VERBOSE 0 #endif /* In a future release of Bison, this section will be replaced by #include "y.tab.h". */ #ifndef YY_HEX_YY_HEX_GRAMMAR_H_INCLUDED -# define YY_HEX_YY_HEX_GRAMMAR_H_INCLUDED +#define YY_HEX_YY_HEX_GRAMMAR_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG -# define YYDEBUG 0 +#define YYDEBUG 0 #endif #if YYDEBUG extern int hex_yydebug; @@ -139,21 +138,21 @@ extern int hex_yydebug; /* Token type. */ #ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - _BYTE_ = 258, - _MASKED_BYTE_ = 259, - _NUMBER_ = 260 - }; +#define YYTOKENTYPE +enum yytokentype +{ + _BYTE_ = 258, + _MASKED_BYTE_ = 259, + _NUMBER_ = 260 +}; #endif /* Tokens. */ -#define _BYTE_ 258 +#define _BYTE_ 258 #define _MASKED_BYTE_ 259 -#define _NUMBER_ 260 +#define _NUMBER_ 260 /* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED union YYSTYPE { @@ -166,13 +165,12 @@ union YYSTYPE }; typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 +#define YYSTYPE_IS_TRIVIAL 1 +#define YYSTYPE_IS_DECLARED 1 #endif - -int hex_yyparse (void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env); +int hex_yyparse(void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env); #endif /* !YY_HEX_YY_HEX_GRAMMAR_H_INCLUDED */ @@ -181,7 +179,7 @@ int hex_yyparse (void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env); #line 182 "hex_grammar.c" /* yacc.c:358 */ #ifdef short -# undef short +#undef short #endif #ifdef YYTYPE_UINT8 @@ -209,157 +207,163 @@ typedef short int yytype_int16; #endif #ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif ! defined YYSIZE_T -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned int -# endif +#ifdef __SIZE_TYPE__ +#define YYSIZE_T __SIZE_TYPE__ +#elif defined size_t +#define YYSIZE_T size_t +#elif !defined YYSIZE_T +#include /* INFRINGES ON USER NAME SPACE */ +#define YYSIZE_T size_t +#else +#define YYSIZE_T unsigned int +#endif #endif #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) -# endif -# endif -# ifndef YY_ -# define YY_(Msgid) Msgid -# endif +#if defined YYENABLE_NLS && YYENABLE_NLS +#if ENABLE_NLS +#include /* INFRINGES ON USER NAME SPACE */ +#define YY_(Msgid) dgettext("bison-runtime", Msgid) +#endif +#endif +#ifndef YY_ +#define YY_(Msgid) Msgid +#endif #endif #ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif +#if ( \ + defined __GNUC__ && \ + (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) || \ + defined __SUNPRO_C && 0x5110 <= __SUNPRO_C +#define YY_ATTRIBUTE(Spec) __attribute__(Spec) +#else +#define YY_ATTRIBUTE(Spec) /* empty */ +#endif #endif #ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#define YY_ATTRIBUTE_PURE YY_ATTRIBUTE((__pure__)) #endif #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +#define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE((__unused__)) #endif -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) -# endif +#if !defined _Noreturn && \ + (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) +#if defined _MSC_VER && 1200 <= _MSC_VER +#define _Noreturn __declspec(noreturn) +#else +#define _Noreturn YY_ATTRIBUTE((__noreturn__)) +#endif #endif /* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +#if !defined lint || defined __GNUC__ +#define YYUSE(E) ((void) (E)) #else -# define YYUSE(E) /* empty */ +#define YYUSE(E) /* empty */ #endif #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") +#define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +#define YY_IGNORE_MAYBE_UNINITIALIZED_END _Pragma("GCC diagnostic pop") #else -# define YY_INITIAL_VALUE(Value) Value +#define YY_INITIAL_VALUE(Value) Value #endif #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +#define YY_IGNORE_MAYBE_UNINITIALIZED_END #endif #ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif -#if ! defined yyoverflow || YYERROR_VERBOSE +#if !defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ -# ifdef YYSTACK_USE_ALLOCA -# if YYSTACK_USE_ALLOCA -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# elif defined __BUILTIN_VA_ARG_INCR -# include /* INFRINGES ON USER NAME SPACE */ -# elif defined _AIX -# define YYSTACK_ALLOC __alloca -# elif defined _MSC_VER -# include /* INFRINGES ON USER NAME SPACE */ -# define alloca _alloca -# else -# define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS -# include /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's 'empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# ifndef YYSTACK_ALLOC_MAXIMUM - /* The OS might guarantee only one guard page at the bottom of the stack, - and a page size can be as small as 4096 bytes. So we cannot safely - invoke alloca (N) if N exceeds 4096. Use a slightly smaller number - to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ -# endif -# else -# define YYSTACK_ALLOC YYMALLOC -# define YYSTACK_FREE YYFREE -# ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM -# endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) -# include /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# ifndef YYMALLOC -# define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS -void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# ifndef YYFREE -# define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS -void free (void *); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# endif +#ifdef YYSTACK_USE_ALLOCA +#if YYSTACK_USE_ALLOCA +#ifdef __GNUC__ +#define YYSTACK_ALLOC __builtin_alloca +#elif defined __BUILTIN_VA_ARG_INCR +#include /* INFRINGES ON USER NAME SPACE */ +#elif defined _AIX +#define YYSTACK_ALLOC __alloca +#elif defined _MSC_VER +#include /* INFRINGES ON USER NAME SPACE */ +#define alloca _alloca +#else +#define YYSTACK_ALLOC alloca +#if !defined _ALLOCA_H && !defined EXIT_SUCCESS +#include /* INFRINGES ON USER NAME SPACE */ +/* Use EXIT_SUCCESS as a witness for stdlib.h. */ +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#endif +#endif +#endif +#endif + +#ifdef YYSTACK_ALLOC +/* Pacify GCC's 'empty if-body' warning. */ +#define YYSTACK_FREE(Ptr) \ + do \ + { /* empty */ \ + ; \ + } while (0) +#ifndef YYSTACK_ALLOC_MAXIMUM +/* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +#define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +#endif +#else +#define YYSTACK_ALLOC YYMALLOC +#define YYSTACK_FREE YYFREE +#ifndef YYSTACK_ALLOC_MAXIMUM +#define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +#endif +#if ( \ + defined __cplusplus && !defined EXIT_SUCCESS && \ + !((defined YYMALLOC || defined malloc) && \ + (defined YYFREE || defined free))) +#include /* INFRINGES ON USER NAME SPACE */ +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#endif +#ifndef YYMALLOC +#define YYMALLOC malloc +#if !defined malloc && !defined EXIT_SUCCESS +void *malloc(YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +#endif +#endif +#ifndef YYFREE +#define YYFREE free +#if !defined free && !defined EXIT_SUCCESS +void free(void *); /* INFRINGES ON USER NAME SPACE */ +#endif +#endif +#endif #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ -#if (! defined yyoverflow \ - && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) +#if ( \ + !defined yyoverflow && \ + (!defined __cplusplus || \ + (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc @@ -369,315 +373,275 @@ union yyalloc }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +#define YYSTACK_GAP_MAXIMUM (sizeof(union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) +#define YYSTACK_BYTES(N) \ + ((N) * (sizeof(yytype_int16) + sizeof(YYSTYPE)) + YYSTACK_GAP_MAXIMUM) -# define YYCOPY_NEEDED 1 +#define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (0) +#define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY(&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof(*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof(*yyptr); \ + } while (0) #endif #if defined YYCOPY_NEEDED && YYCOPY_NEEDED /* Copy COUNT objects from SRC to DST. The source and destination do not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) -# else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ - while (0) -# endif -# endif +#ifndef YYCOPY +#if defined __GNUC__ && 1 < __GNUC__ +#define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy(Dst, Src, (Count) * sizeof(*(Src))) +#else +#define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) (Dst)[yyi] = (Src)[yyi]; \ + } while (0) +#endif +#endif #endif /* !YYCOPY_NEEDED */ /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 9 +#define YYFINAL 9 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 30 +#define YYLAST 30 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 14 +#define YYNTOKENS 14 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 10 +#define YYNNTS 10 /* YYNRULES -- Number of rules. */ -#define YYNRULES 20 +#define YYNRULES 20 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 32 +#define YYNSTATES 32 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned by yylex, with out-of-bounds checking. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 260 +#define YYUNDEFTOK 2 +#define YYMAXUTOK 260 -#define YYTRANSLATE(YYX) \ +#define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex, without out-of-bounds checking. */ -static const yytype_uint8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 8, 9, 2, 2, 2, 12, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 10, 2, 11, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 6, 13, 7, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5 -}; +static const yytype_uint8 yytranslate[] = { + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8, 9, 2, 2, 2, 12, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10, 2, 11, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 6, 13, 7, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5}; #if YYDEBUG - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = -{ - 0, 105, 105, 114, 118, 130, 141, 150, 159, 163, - 172, 177, 176, 189, 225, 257, 279, 299, 303, 320, - 329 -}; +/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = {0, 105, 105, 114, 118, 130, 141, + 150, 159, 163, 172, 177, 176, 189, + 225, 257, 279, 299, 303, 320, 329}; #endif #if YYDEBUG || YYERROR_VERBOSE || 0 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "$end", "error", "$undefined", "_BYTE_", "_MASKED_BYTE_", "_NUMBER_", - "'{'", "'}'", "'('", "')'", "'['", "']'", "'-'", "'|'", "$accept", - "hex_string", "tokens", "token_sequence", "token_or_range", "token", - "$@1", "range", "alternatives", "byte", YY_NULLPTR -}; +static const char *const yytname[] = { + "$end", + "error", + "$undefined", + "_BYTE_", + "_MASKED_BYTE_", + "_NUMBER_", + "'{'", + "'}'", + "'('", + "')'", + "'['", + "']'", + "'-'", + "'|'", + "$accept", + "hex_string", + "tokens", + "token_sequence", + "token_or_range", + "token", + "$@1", + "range", + "alternatives", + "byte", + YY_NULLPTR}; #endif -# ifdef YYPRINT +#ifdef YYPRINT /* YYTOKNUM[NUM] -- (External) token number corresponding to the (internal) symbol number NUM (which must be that of a token). */ static const yytype_uint16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 123, 125, 40, 41, - 91, 93, 45, 124 -}; -# endif + {0, 256, 257, 258, 259, 260, 123, 125, 40, 41, 91, 93, 45, 124}; +#endif #define YYPACT_NINF -11 -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-11))) +#define yypact_value_is_default(Yystate) (!!((Yystate) == (-11))) #define YYTABLE_NINF -6 -#define yytable_value_is_error(Yytable_value) \ - 0 +#define yytable_value_is_error(Yytable_value) 0 - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -static const yytype_int8 yypact[] = -{ - 20, 14, 27, -11, -11, -11, 21, -2, -11, -11, - 14, -11, -1, -2, -11, -4, -11, -11, 10, 13, - 9, -11, 3, -11, 14, -11, 2, -11, -11, 18, - -11, -11 -}; +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int8 yypact[] = { + 20, 14, 27, -11, -11, -11, 21, -2, -11, -11, 14, -11, -1, -2, -11, -4, + -11, -11, 10, 13, 9, -11, 3, -11, 14, -11, 2, -11, -11, 18, -11, -11}; - /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 0, 0, 0, 19, 20, 11, 0, 3, 10, 1, - 0, 2, 0, 0, 6, 8, 9, 17, 0, 0, - 0, 7, 8, 12, 0, 13, 0, 16, 18, 0, - 15, 14 -}; +/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = {0, 0, 0, 19, 20, 11, 0, 3, 10, 1, 0, + 2, 0, 0, 6, 8, 9, 17, 0, 0, 0, 7, + 8, 12, 0, 13, 0, 16, 18, 0, 15, 14}; - /* YYPGOTO[NTERM-NUM]. */ +/* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = -{ - -11, -11, -10, -11, 17, 8, -11, -11, -11, -11 -}; - - /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int8 yydefgoto[] = -{ - -1, 2, 6, 13, 14, 7, 10, 16, 18, 8 -}; - - /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_int8 yytable[] = -{ - 17, 3, 4, -4, 19, -4, 5, 29, 12, -4, - -5, 20, -5, 30, 28, 15, -5, 3, 4, 23, - 27, 22, 5, 24, 25, 26, 1, 9, 11, 31, - 21 -}; - -static const yytype_uint8 yycheck[] = -{ - 10, 3, 4, 7, 5, 9, 8, 5, 10, 13, - 7, 12, 9, 11, 24, 7, 13, 3, 4, 9, - 11, 13, 8, 13, 11, 12, 6, 0, 7, 11, - 13 -}; - - /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = -{ - 0, 6, 15, 3, 4, 8, 16, 19, 23, 0, - 20, 7, 10, 17, 18, 19, 21, 16, 22, 5, - 12, 18, 19, 9, 13, 11, 12, 11, 16, 5, - 11, 11 -}; - - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 14, 15, 16, 16, 16, 17, 17, 18, 18, - 19, 20, 19, 21, 21, 21, 21, 22, 22, 23, - 23 -}; - - /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 3, 1, 2, 3, 1, 2, 1, 1, - 1, 0, 4, 3, 5, 4, 3, 1, 3, 1, - 1 -}; - - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab - - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (yyscanner, lex_env, YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (0) + {-11, -11, -10, -11, 17, 8, -11, -11, -11, -11}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = {-1, 2, 6, 13, 14, 7, 10, 16, 18, 8}; + +/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_int8 yytable[] = { + 17, 3, 4, -4, 19, -4, 5, 29, 12, -4, -5, 20, -5, 30, 28, 15, + -5, 3, 4, 23, 27, 22, 5, 24, 25, 26, 1, 9, 11, 31, 21}; + +static const yytype_uint8 yycheck[] = {10, 3, 4, 7, 5, 9, 8, 5, 10, 13, 7, + 12, 9, 11, 24, 7, 13, 3, 4, 9, 11, 13, + 8, 13, 11, 12, 6, 0, 7, 11, 13}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = { + 0, 6, 15, 3, 4, 8, 16, 19, 23, 0, 20, 7, 10, 17, 18, 19, + 21, 16, 22, 5, 12, 18, 19, 9, 13, 11, 12, 11, 16, 5, 11, 11}; + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = {0, 14, 15, 16, 16, 16, 17, 17, 18, 18, 19, + 20, 19, 21, 21, 21, 21, 22, 22, 23, 23}; + +/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = {0, 2, 3, 1, 2, 3, 1, 2, 1, 1, 1, + 0, 4, 3, 5, 4, 3, 1, 3, 1, 1}; + + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK(yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror(yyscanner, lex_env, YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) /* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - +#define YYTERROR 1 +#define YYERRCODE 256 /* Enable debugging if requested. */ #if YYDEBUG -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif +#ifndef YYFPRINTF +#include /* INFRINGES ON USER NAME SPACE */ +#define YYFPRINTF fprintf +#endif -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) +#define YYDPRINTF(Args) \ + do \ + { \ + if (yydebug) \ + YYFPRINTF Args; \ + } while (0) /* This macro is provided for backward compatibility. */ #ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#define YY_LOCATION_PRINT(File, Loc) ((void) 0) #endif -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value, yyscanner, lex_env); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) +#define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ + do \ + { \ + if (yydebug) \ + { \ + YYFPRINTF(stderr, "%s ", Title); \ + yy_symbol_print(stderr, Type, Value, yyscanner, lex_env); \ + YYFPRINTF(stderr, "\n"); \ + } \ + } while (0) /*----------------------------------------. | Print this symbol's value on YYOUTPUT. | `----------------------------------------*/ -static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env) +static void yy_symbol_value_print( + FILE *yyoutput, + int yytype, + YYSTYPE const *const yyvaluep, + void *yyscanner, + HEX_LEX_ENVIRONMENT *lex_env) { FILE *yyo = yyoutput; - YYUSE (yyo); - YYUSE (yyscanner); - YYUSE (lex_env); + YYUSE(yyo); + YYUSE(yyscanner); + YYUSE(lex_env); if (!yyvaluep) return; -# ifdef YYPRINT +#ifdef YYPRINT if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - YYUSE (yytype); + YYPRINT(yyoutput, yytoknum[yytype], *yyvaluep); +#endif + YYUSE(yytype); } @@ -685,14 +649,21 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue | Print this symbol on YYOUTPUT. | `--------------------------------*/ -static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env) +static void yy_symbol_print( + FILE *yyoutput, + int yytype, + YYSTYPE const *const yyvaluep, + void *yyscanner, + HEX_LEX_ENVIRONMENT *lex_env) { - YYFPRINTF (yyoutput, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); - - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yyscanner, lex_env); - YYFPRINTF (yyoutput, ")"); + YYFPRINTF( + yyoutput, + "%s %s (", + yytype < YYNTOKENS ? "token" : "nterm", + yytname[yytype]); + + yy_symbol_value_print(yyoutput, yytype, yyvaluep, yyscanner, lex_env); + YYFPRINTF(yyoutput, ")"); } /*------------------------------------------------------------------. @@ -700,69 +671,76 @@ yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, voi | TOP (included). | `------------------------------------------------------------------*/ -static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +static void yy_stack_print(yytype_int16 *yybottom, yytype_int16 *yytop) { - YYFPRINTF (stderr, "Stack now"); + YYFPRINTF(stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) - { - int yybot = *yybottom; - YYFPRINTF (stderr, " %d", yybot); - } - YYFPRINTF (stderr, "\n"); + { + int yybot = *yybottom; + YYFPRINTF(stderr, " %d", yybot); + } + YYFPRINTF(stderr, "\n"); } -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (0) +#define YY_STACK_PRINT(Bottom, Top) \ + do \ + { \ + if (yydebug) \ + yy_stack_print((Bottom), (Top)); \ + } while (0) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env) +static void yy_reduce_print( + yytype_int16 *yyssp, + YYSTYPE *yyvsp, + int yyrule, + void *yyscanner, + HEX_LEX_ENVIRONMENT *lex_env) { unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); + YYFPRINTF( + stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) - { - YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &(yyvsp[(yyi + 1) - (yynrhs)]) - , yyscanner, lex_env); - YYFPRINTF (stderr, "\n"); - } + { + YYFPRINTF(stderr, " $%d = ", yyi + 1); + yy_symbol_print( + stderr, + yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)]), + yyscanner, + lex_env); + YYFPRINTF(stderr, "\n"); + } } -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, Rule, yyscanner, lex_env); \ -} while (0) +#define YY_REDUCE_PRINT(Rule) \ + do \ + { \ + if (yydebug) \ + yy_reduce_print(yyssp, yyvsp, Rule, yyscanner, lex_env); \ + } while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) +#define YYDPRINTF(Args) +#define YY_SYMBOL_PRINT(Title, Type, Value, Location) +#define YY_STACK_PRINT(Bottom, Top) +#define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH -# define YYINITDEPTH 200 +#define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only @@ -773,49 +751,45 @@ int yydebug; evaluated with infinite-precision integer arithmetic. */ #ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 +#define YYMAXDEPTH 10000 #endif #if YYERROR_VERBOSE -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else +#ifndef yystrlen +#if defined __GLIBC__ && defined _STRING_H +#define yystrlen strlen +#else /* Return the length of YYSTR. */ -static YYSIZE_T -yystrlen (const char *yystr) +static YYSIZE_T yystrlen(const char *yystr) { YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; + for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; } -# endif -# endif +#endif +#endif -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else +#ifndef yystpcpy +#if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +#define yystpcpy stpcpy +#else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ -static char * -yystpcpy (char *yydest, const char *yysrc) +static char *yystpcpy(char *yydest, const char *yysrc) { char *yyd = yydest; const char *yys = yysrc; - while ((*yyd++ = *yys++) != '\0') - continue; + while ((*yyd++ = *yys++) != '\0') continue; return yyd - 1; } -# endif -# endif +#endif +#endif -# ifndef yytnamerr +#ifndef yytnamerr /* Copy to YYRES the contents of YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is that double-quoting is unnecessary unless the string @@ -823,45 +797,43 @@ yystpcpy (char *yydest, const char *yysrc) backslash-backslash). YYSTR is taken from yytname. If YYRES is null, do not copy; instead, return the length of what the result would have been. */ -static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) +static YYSIZE_T yytnamerr(char *yyres, const char *yystr) { if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; + for (;;) switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes:; + } - if (! yyres) - return yystrlen (yystr); + if (!yyres) + return yystrlen(yystr); - return yystpcpy (yyres, yystr) - yyres; + return yystpcpy(yyres, yystr) - yyres; } -# endif +#endif /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message about the unexpected token YYTOKEN for the state stack whose top is @@ -871,13 +843,18 @@ yytnamerr (char *yyres, const char *yystr) not large enough to hold the message. In that case, also set *YYMSG_ALLOC to the required number of bytes. Return 2 if the required number of bytes is too large to store. */ -static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) +static int yysyntax_error( + YYSIZE_T *yymsg_alloc, + char **yymsg, + yytype_int16 *yyssp, + int yytoken) { - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + YYSIZE_T yysize0 = yytnamerr(YY_NULLPTR, yytname[yytoken]); YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + enum + { + YYERROR_VERBOSE_ARGS_MAXIMUM = 5 + }; /* Internationalized format string. */ const char *yyformat = YY_NULLPTR; /* Arguments of yyformat. */ @@ -910,73 +887,72 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, accepted due to an error action in a later state. */ if (yytoken != YYEMPTY) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default(yyn)) { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR && + !yytable_value_is_error(yytable[yyx + yyn])) { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = yysize + yytnamerr(YY_NULLPTR, yytname[yyx]); + if (!(yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } } } + } switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - default: /* Avoid compiler warnings. */ - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: /* Avoid compiler warnings. */ + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_( + 5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + YYSIZE_T yysize1 = yysize + yystrlen(yyformat); + if (!(yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) return 2; yysize = yysize1; } if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } + { + *yymsg_alloc = 2 * yysize; + if (!(yysize <= *yymsg_alloc && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } /* Avoid sprintf, as that infringes on the user's name space. Don't have undefined behavior even if the translation @@ -986,15 +962,15 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, int yyi = 0; while ((*yyp = *yyformat) != '\0') if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } + { + yyp += yytnamerr(yyp, yyarg[yyi++]); + yyformat += 2; + } else - { - yyp++; - yyformat++; - } + { + yyp++; + yyformat++; + } } return 0; } @@ -1004,113 +980,135 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, | Release the memory associated to this symbol. | `-----------------------------------------------*/ -static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env) +static void yydestruct( + const char *yymsg, + int yytype, + YYSTYPE *yyvaluep, + void *yyscanner, + HEX_LEX_ENVIRONMENT *lex_env) { - YYUSE (yyvaluep); - YYUSE (yyscanner); - YYUSE (lex_env); + YYUSE(yyvaluep); + YYUSE(yyscanner); + YYUSE(lex_env); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT(yymsg, yytype, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN switch (yytype) - { - case 16: /* tokens */ + { + case 16: /* tokens */ #line 94 "hex_grammar.y" /* yacc.c:1258 */ - { yr_re_node_destroy(((*yyvaluep).re_node)); ((*yyvaluep).re_node) = NULL; } + { + yr_re_node_destroy(((*yyvaluep).re_node)); + ((*yyvaluep).re_node) = NULL; + } #line 1024 "hex_grammar.c" /* yacc.c:1258 */ - break; + break; - case 17: /* token_sequence */ + case 17: /* token_sequence */ #line 95 "hex_grammar.y" /* yacc.c:1258 */ - { yr_re_node_destroy(((*yyvaluep).re_node)); ((*yyvaluep).re_node) = NULL; } + { + yr_re_node_destroy(((*yyvaluep).re_node)); + ((*yyvaluep).re_node) = NULL; + } #line 1030 "hex_grammar.c" /* yacc.c:1258 */ - break; + break; - case 18: /* token_or_range */ + case 18: /* token_or_range */ #line 96 "hex_grammar.y" /* yacc.c:1258 */ - { yr_re_node_destroy(((*yyvaluep).re_node)); ((*yyvaluep).re_node) = NULL; } + { + yr_re_node_destroy(((*yyvaluep).re_node)); + ((*yyvaluep).re_node) = NULL; + } #line 1036 "hex_grammar.c" /* yacc.c:1258 */ - break; + break; - case 19: /* token */ + case 19: /* token */ #line 97 "hex_grammar.y" /* yacc.c:1258 */ - { yr_re_node_destroy(((*yyvaluep).re_node)); ((*yyvaluep).re_node) = NULL; } + { + yr_re_node_destroy(((*yyvaluep).re_node)); + ((*yyvaluep).re_node) = NULL; + } #line 1042 "hex_grammar.c" /* yacc.c:1258 */ - break; + break; - case 21: /* range */ + case 21: /* range */ #line 100 "hex_grammar.y" /* yacc.c:1258 */ - { yr_re_node_destroy(((*yyvaluep).re_node)); ((*yyvaluep).re_node) = NULL; } + { + yr_re_node_destroy(((*yyvaluep).re_node)); + ((*yyvaluep).re_node) = NULL; + } #line 1048 "hex_grammar.c" /* yacc.c:1258 */ - break; + break; - case 22: /* alternatives */ + case 22: /* alternatives */ #line 99 "hex_grammar.y" /* yacc.c:1258 */ - { yr_re_node_destroy(((*yyvaluep).re_node)); ((*yyvaluep).re_node) = NULL; } + { + yr_re_node_destroy(((*yyvaluep).re_node)); + ((*yyvaluep).re_node) = NULL; + } #line 1054 "hex_grammar.c" /* yacc.c:1258 */ - break; + break; - case 23: /* byte */ + case 23: /* byte */ #line 98 "hex_grammar.y" /* yacc.c:1258 */ - { yr_re_node_destroy(((*yyvaluep).re_node)); ((*yyvaluep).re_node) = NULL; } + { + yr_re_node_destroy(((*yyvaluep).re_node)); + ((*yyvaluep).re_node) = NULL; + } #line 1060 "hex_grammar.c" /* yacc.c:1258 */ - break; + break; - default: - break; - } + default: + break; + } YY_IGNORE_MAYBE_UNINITIALIZED_END } - - /*----------. | yyparse. | `----------*/ -int -yyparse (void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env) +int yyparse(void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env) { -/* The lookahead symbol. */ -int yychar; + /* The lookahead symbol. */ + int yychar; -/* The semantic value of the lookahead symbol. */ -/* Default value used for initialization, for pacifying older GCCs - or non-GCC compilers. */ -YY_INITIAL_VALUE (static YYSTYPE yyval_default;) -YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); + /* The semantic value of the lookahead symbol. */ + /* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ + YY_INITIAL_VALUE(static YYSTYPE yyval_default;) + YYSTYPE yylval YY_INITIAL_VALUE(= yyval_default); - /* Number of syntax errors so far. */ - int yynerrs; + /* Number of syntax errors so far. */ + int yynerrs; - int yystate; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. + /* The stacks and their tools: + 'yyss': related to states. + 'yyvs': related to semantic values. - Refer to the stacks through separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; - YYSIZE_T yystacksize; + YYSIZE_T yystacksize; int yyn; int yyresult; @@ -1127,7 +1125,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ @@ -1137,7 +1135,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yyvsp = yyvs = yyvsa; yystacksize = YYINITDEPTH; - YYDPRINTF ((stderr, "Starting parse\n")); + YYDPRINTF((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; @@ -1145,79 +1143,84 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; -/*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | -`------------------------------------------------------------*/ - yynewstate: + /*------------------------------------------------------------. + | yynewstate -- Push a new state, which is found in yystate. | + `------------------------------------------------------------*/ +yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; - yysetstate: +yysetstate: *yyssp = yystate; if (yyss + yystacksize - 1 <= yyssp) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; - } + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow( + YY_("memory exhausted"), + &yyss1, + yysize * sizeof(*yyssp), + &yyvs1, + yysize * sizeof(*yyvsp), + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } #else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE +#ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +#else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; -# else - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; - { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC( + YYSTACK_BYTES(yystacksize)); + if (!yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE(yyss_alloc, yyss); + YYSTACK_RELOCATE(yyvs_alloc, yyvs); +#undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE(yyss1); + } +#endif #endif /* no yyoverflow */ - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); + YYDPRINTF( + (stderr, + "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YYDPRINTF((stderr, "Entering state %d\n", yystate)); if (yystate == YYFINAL) YYACCEPT; @@ -1234,28 +1237,28 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) + if (yypact_value_is_default(yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (&yylval, yyscanner, lex_env); - } + { + YYDPRINTF((stderr, "Reading a token: ")); + yychar = yylex(&yylval, yyscanner, lex_env); + } if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } + { + yychar = yytoken = YYEOF; + YYDPRINTF((stderr, "Now at end of input.\n")); + } else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } + { + yytoken = YYTRANSLATE(yychar); + YY_SYMBOL_PRINT("Next token is", yytoken, &yylval, &yylloc); + } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ @@ -1264,12 +1267,12 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) - { - if (yytable_value_is_error (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } + { + if (yytable_value_is_error(yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } /* Count tokens shifted since error; after three, turn off error status. */ @@ -1277,7 +1280,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yyerrstatus--; /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + YY_SYMBOL_PRINT("Shifting", yytoken, &yylval, &yylloc); /* Discard the shifted token. */ yychar = YYEMPTY; @@ -1315,312 +1318,322 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; + yyval = yyvsp[1 - yylen]; - YY_REDUCE_PRINT (yyn); + YY_REDUCE_PRINT(yyn); switch (yyn) - { - case 2: + { + case 2: #line 106 "hex_grammar.y" /* yacc.c:1663 */ - { - RE_AST* re_ast = yyget_extra(yyscanner); - re_ast->root_node = (yyvsp[-1].re_node); - } + { + RE_AST *re_ast = yyget_extra(yyscanner); + re_ast->root_node = (yyvsp[-1].re_node); + } #line 1331 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 3: #line 115 "hex_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = (yyvsp[0].re_node); - } + { + (yyval.re_node) = (yyvsp[0].re_node); + } #line 1339 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 4: #line 119 "hex_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_CONCAT); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_CONCAT); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[0].re_node)); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[0].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); - yr_re_node_append_child((yyval.re_node), (yyvsp[0].re_node)); - } + yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); + yr_re_node_append_child((yyval.re_node), (yyvsp[0].re_node)); + } #line 1355 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 5: #line 131 "hex_grammar.y" /* yacc.c:1663 */ - { - yr_re_node_append_child((yyvsp[-1].re_node), (yyvsp[0].re_node)); - yr_re_node_prepend_child((yyvsp[-1].re_node), (yyvsp[-2].re_node)); + { + yr_re_node_append_child((yyvsp[-1].re_node), (yyvsp[0].re_node)); + yr_re_node_prepend_child((yyvsp[-1].re_node), (yyvsp[-2].re_node)); - (yyval.re_node) = (yyvsp[-1].re_node); - } + (yyval.re_node) = (yyvsp[-1].re_node); + } #line 1366 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 6: #line 142 "hex_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_CONCAT); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_CONCAT); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[0].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[0].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[0].re_node)); - } + yr_re_node_append_child((yyval.re_node), (yyvsp[0].re_node)); + } #line 1379 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 7: #line 151 "hex_grammar.y" /* yacc.c:1663 */ - { - yr_re_node_append_child((yyvsp[-1].re_node), (yyvsp[0].re_node)); - (yyval.re_node) = (yyvsp[-1].re_node); - } + { + yr_re_node_append_child((yyvsp[-1].re_node), (yyvsp[0].re_node)); + (yyval.re_node) = (yyvsp[-1].re_node); + } #line 1388 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 8: #line 160 "hex_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = (yyvsp[0].re_node); - } + { + (yyval.re_node) = (yyvsp[0].re_node); + } #line 1396 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 9: #line 164 "hex_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = (yyvsp[0].re_node); - (yyval.re_node)->greedy = false; - } + { + (yyval.re_node) = (yyvsp[0].re_node); + (yyval.re_node)->greedy = false; + } #line 1405 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 10: #line 173 "hex_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = (yyvsp[0].re_node); - } + { + (yyval.re_node) = (yyvsp[0].re_node); + } #line 1413 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 11: #line 177 "hex_grammar.y" /* yacc.c:1663 */ - { - lex_env->inside_or++; - } + { + lex_env->inside_or++; + } #line 1421 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 12: #line 181 "hex_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = (yyvsp[-1].re_node); - lex_env->inside_or--; - } + { + (yyval.re_node) = (yyvsp[-1].re_node); + lex_env->inside_or--; + } #line 1430 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 13: #line 190 "hex_grammar.y" /* yacc.c:1663 */ + { + if ((yyvsp[-1].integer) <= 0) { - if ((yyvsp[-1].integer) <= 0) - { - yyerror(yyscanner, lex_env, "invalid jump length"); - YYABORT; - } + yyerror(yyscanner, lex_env, "invalid jump length"); + YYABORT; + } - if (lex_env->inside_or && (yyvsp[-1].integer) > YR_STRING_CHAINING_THRESHOLD) - { - yyerror(yyscanner, lex_env, "jumps over " - STR(YR_STRING_CHAINING_THRESHOLD) - " not allowed inside alternation (|)"); - YYABORT; - } + if (lex_env->inside_or && + (yyvsp[-1].integer) > YR_STRING_CHAINING_THRESHOLD) + { + yyerror( + yyscanner, + lex_env, + "jumps over " STR(YR_STRING_CHAINING_THRESHOLD) " not allowed inside " + "alternation (|)"); + YYABORT; + } - // A jump of one is equivalent to ?? - if ((yyvsp[-1].integer) == 1) - { - (yyval.re_node) = yr_re_node_create(RE_NODE_MASKED_LITERAL); + // A jump of one is equivalent to ?? + if ((yyvsp[-1].integer) == 1) + { + (yyval.re_node) = yr_re_node_create(RE_NODE_MASKED_LITERAL); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node)->value = 0x00; - (yyval.re_node)->mask = 0x00; - } - else - { - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); + (yyval.re_node)->value = 0x00; + (yyval.re_node)->mask = 0x00; + } + else + { + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node)->start = (int) (yyvsp[-1].integer); - (yyval.re_node)->end = (int) (yyvsp[-1].integer); - } - } + (yyval.re_node)->start = (int) (yyvsp[-1].integer); + (yyval.re_node)->end = (int) (yyvsp[-1].integer); + } + } #line 1470 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 14: #line 226 "hex_grammar.y" /* yacc.c:1663 */ + { + if (lex_env->inside_or && + ((yyvsp[-3].integer) > YR_STRING_CHAINING_THRESHOLD || + (yyvsp[-1].integer) > YR_STRING_CHAINING_THRESHOLD)) { - if (lex_env->inside_or && - ((yyvsp[-3].integer) > YR_STRING_CHAINING_THRESHOLD || - (yyvsp[-1].integer) > YR_STRING_CHAINING_THRESHOLD) ) - { - yyerror(yyscanner, lex_env, "jumps over " - STR(YR_STRING_CHAINING_THRESHOLD) - " not allowed inside alternation (|)"); + yyerror( + yyscanner, + lex_env, + "jumps over " STR(YR_STRING_CHAINING_THRESHOLD) " not allowed inside " + "alternation (|)"); - YYABORT; - } + YYABORT; + } - if ((yyvsp[-3].integer) < 0 || (yyvsp[-1].integer) < 0) - { - yyerror(yyscanner, lex_env, "invalid negative jump length"); - YYABORT; - } + if ((yyvsp[-3].integer) < 0 || (yyvsp[-1].integer) < 0) + { + yyerror(yyscanner, lex_env, "invalid negative jump length"); + YYABORT; + } - if ((yyvsp[-3].integer) > (yyvsp[-1].integer)) - { - yyerror(yyscanner, lex_env, "invalid jump range"); - YYABORT; - } + if ((yyvsp[-3].integer) > (yyvsp[-1].integer)) + { + yyerror(yyscanner, lex_env, "invalid jump range"); + YYABORT; + } - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node)->start = (int) (yyvsp[-3].integer); - (yyval.re_node)->end = (int) (yyvsp[-1].integer); - } + (yyval.re_node)->start = (int) (yyvsp[-3].integer); + (yyval.re_node)->end = (int) (yyvsp[-1].integer); + } #line 1506 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 15: #line 258 "hex_grammar.y" /* yacc.c:1663 */ + { + if (lex_env->inside_or) { - if (lex_env->inside_or) - { - yyerror(yyscanner, lex_env, - "unbounded jumps not allowed inside alternation (|)"); - YYABORT; - } + yyerror( + yyscanner, + lex_env, + "unbounded jumps not allowed inside alternation (|)"); + YYABORT; + } - if ((yyvsp[-2].integer) < 0) - { - yyerror(yyscanner, lex_env, "invalid negative jump length"); - YYABORT; - } + if ((yyvsp[-2].integer) < 0) + { + yyerror(yyscanner, lex_env, "invalid negative jump length"); + YYABORT; + } - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node)->start = (int) (yyvsp[-2].integer); - (yyval.re_node)->end = INT_MAX; - } + (yyval.re_node)->start = (int) (yyvsp[-2].integer); + (yyval.re_node)->end = INT_MAX; + } #line 1532 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 16: #line 280 "hex_grammar.y" /* yacc.c:1663 */ + { + if (lex_env->inside_or) { - if (lex_env->inside_or) - { - yyerror(yyscanner, lex_env, - "unbounded jumps not allowed inside alternation (|)"); - YYABORT; - } + yyerror( + yyscanner, + lex_env, + "unbounded jumps not allowed inside alternation (|)"); + YYABORT; + } - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node)->start = 0; - (yyval.re_node)->end = INT_MAX; - } + (yyval.re_node)->start = 0; + (yyval.re_node)->end = INT_MAX; + } #line 1552 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 17: #line 300 "hex_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = (yyvsp[0].re_node); - } + { + (yyval.re_node) = (yyvsp[0].re_node); + } #line 1560 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 18: #line 304 "hex_grammar.y" /* yacc.c:1663 */ - { - mark_as_not_fast_regexp(); + { + mark_as_not_fast_regexp(); - (yyval.re_node) = yr_re_node_create(RE_NODE_ALT); + (yyval.re_node) = yr_re_node_create(RE_NODE_ALT); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[0].re_node)); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[0].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); - yr_re_node_append_child((yyval.re_node), (yyvsp[0].re_node)); - } + yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); + yr_re_node_append_child((yyval.re_node), (yyvsp[0].re_node)); + } #line 1578 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 19: #line 321 "hex_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_LITERAL); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_LITERAL); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node)->value = (int) (yyvsp[0].integer); - (yyval.re_node)->mask = 0xFF; - } + (yyval.re_node)->value = (int) (yyvsp[0].integer); + (yyval.re_node)->mask = 0xFF; + } #line 1591 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; case 20: #line 330 "hex_grammar.y" /* yacc.c:1663 */ - { - uint8_t mask = (uint8_t) ((yyvsp[0].integer) >> 8); + { + uint8_t mask = (uint8_t)((yyvsp[0].integer) >> 8); - if (mask == 0x00) - { - (yyval.re_node) = yr_re_node_create(RE_NODE_ANY); + if (mask == 0x00) + { + (yyval.re_node) = yr_re_node_create(RE_NODE_ANY); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node)->value = 0x00; - (yyval.re_node)->mask = 0x00; - } - else - { - (yyval.re_node) = yr_re_node_create(RE_NODE_MASKED_LITERAL); + (yyval.re_node)->value = 0x00; + (yyval.re_node)->mask = 0x00; + } + else + { + (yyval.re_node) = yr_re_node_create(RE_NODE_MASKED_LITERAL); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node)->value = (yyvsp[0].integer) & 0xFF; - (yyval.re_node)->mask = mask; - } - } + (yyval.re_node)->value = (yyvsp[0].integer) & 0xFF; + (yyval.re_node)->mask = mask; + } + } #line 1618 "hex_grammar.c" /* yacc.c:1663 */ - break; + break; #line 1622 "hex_grammar.c" /* yacc.c:1663 */ - default: break; - } + default: + break; + } /* User semantic actions sometimes alter yychar, and that requires that yytoken be updated with the new translation. We take the approach of translating immediately before every use of yytoken. @@ -1632,11 +1645,11 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT("-> $$ =", yyr1[yyn], &yyval, &yyloc); - YYPOPSTACK (yylen); + YYPOPSTACK(yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT(yyss, yyssp); *++yyvsp = yyval; @@ -1661,68 +1674,65 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE(yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) - { - ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (yyscanner, lex_env, YY_("syntax error")); + { + ++yynerrs; +#if !YYERROR_VERBOSE + yyerror(yyscanner, lex_env, YY_("syntax error")); #else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) +#define YYSYNTAX_ERROR yysyntax_error(&yymsg_alloc, &yymsg, yyssp, yytoken) + { + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) + if (yymsg != yymsgbuf) + YYSTACK_FREE(yymsg); + yymsg = (char *) YYSTACK_ALLOC(yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (yyscanner, lex_env, yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; + } } -# undef YYSYNTAX_ERROR -#endif + yyerror(yyscanner, lex_env, yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } - +#undef YYSYNTAX_ERROR +#endif + } if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ - if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } - else - { - yydestruct ("Error: discarding", - yytoken, &yylval, yyscanner, lex_env); - yychar = YYEMPTY; - } + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct("Error: discarding", yytoken, &yylval, yyscanner, lex_env); + yychar = YYEMPTY; } + } /* Else will try to reuse lookahead token after shifting the error token. */ @@ -1738,13 +1748,13 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); YYERROR and the label yyerrorlab therefore never appears in user code. */ if (/*CONSTCOND*/ 0) - goto yyerrorlab; + goto yyerrorlab; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ - YYPOPSTACK (yylen); + YYPOPSTACK(yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT(yyss, yyssp); yystate = *yyssp; goto yyerrlab1; @@ -1753,33 +1763,32 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ + yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default(yyn)) { - yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; - yydestruct ("Error: popping", - yystos[yystate], yyvsp, yyscanner, lex_env); - YYPOPSTACK (1); - yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); - } + yydestruct("Error: popping", yystos[yystate], yyvsp, yyscanner, lex_env); + YYPOPSTACK(1); + yystate = *yyssp; + YY_STACK_PRINT(yyss, yyssp); + } YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; @@ -1787,7 +1796,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -1812,37 +1821,36 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (yyscanner, lex_env, YY_("memory exhausted")); + yyerror(yyscanner, lex_env, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: if (yychar != YYEMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, yyscanner, lex_env); - } + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE(yychar); + yydestruct( + "Cleanup: discarding lookahead", yytoken, &yylval, yyscanner, lex_env); + } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); + YYPOPSTACK(yylen); + YY_STACK_PRINT(yyss, yyssp); while (yyssp != yyss) - { - yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yyscanner, lex_env); - YYPOPSTACK (1); - } + { + yydestruct("Cleanup: popping", yystos[*yyssp], yyvsp, yyscanner, lex_env); + YYPOPSTACK(1); + } #ifndef yyoverflow if (yyss != yyssa) - YYSTACK_FREE (yyss); + YYSTACK_FREE(yyss); #endif #if YYERROR_VERBOSE if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); + YYSTACK_FREE(yymsg); #endif return yyresult; } diff --git a/libyara/hex_grammar.h b/libyara/hex_grammar.h index 86d6ad07b6..5d6fae2372 100644 --- a/libyara/hex_grammar.h +++ b/libyara/hex_grammar.h @@ -31,10 +31,10 @@ version 2.2 of Bison. */ #ifndef YY_HEX_YY_HEX_GRAMMAR_H_INCLUDED -# define YY_HEX_YY_HEX_GRAMMAR_H_INCLUDED +#define YY_HEX_YY_HEX_GRAMMAR_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG -# define YYDEBUG 0 +#define YYDEBUG 0 #endif #if YYDEBUG extern int hex_yydebug; @@ -42,21 +42,21 @@ extern int hex_yydebug; /* Token type. */ #ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - _BYTE_ = 258, - _MASKED_BYTE_ = 259, - _NUMBER_ = 260 - }; +#define YYTOKENTYPE +enum yytokentype +{ + _BYTE_ = 258, + _MASKED_BYTE_ = 259, + _NUMBER_ = 260 +}; #endif /* Tokens. */ -#define _BYTE_ 258 +#define _BYTE_ 258 #define _MASKED_BYTE_ 259 -#define _NUMBER_ 260 +#define _NUMBER_ 260 /* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED union YYSTYPE { @@ -69,12 +69,11 @@ union YYSTYPE }; typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 +#define YYSTYPE_IS_TRIVIAL 1 +#define YYSTYPE_IS_DECLARED 1 #endif - -int hex_yyparse (void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env); +int hex_yyparse(void *yyscanner, HEX_LEX_ENVIRONMENT *lex_env); #endif /* !YY_HEX_YY_HEX_GRAMMAR_H_INCLUDED */ diff --git a/libyara/hex_lexer.c b/libyara/hex_lexer.c index 87ad87314b..9479bb3a77 100644 --- a/libyara/hex_lexer.c +++ b/libyara/hex_lexer.c @@ -2,13 +2,13 @@ #line 4 "hex_lexer.c" -#define YY_INT_ALIGNED short int +#define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ #define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 #define YY_FLEX_SUBMINOR_VERSION 0 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA @@ -17,10 +17,10 @@ /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ -#include -#include #include +#include #include +#include /* end standard C headers. */ @@ -31,10 +31,10 @@ /* C99 systems have . Non-C99 systems may or may not. */ -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. + * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 @@ -51,37 +51,37 @@ typedef uint32_t flex_uint32_t; typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; +typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; /* Limits of integral types. */ #ifndef INT8_MIN -#define INT8_MIN (-128) +#define INT8_MIN (-128) #endif #ifndef INT16_MIN -#define INT16_MIN (-32767-1) +#define INT16_MIN (-32767 - 1) #endif #ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) +#define INT32_MIN (-2147483647 - 1) #endif #ifndef INT8_MAX -#define INT8_MAX (127) +#define INT8_MAX (127) #endif #ifndef INT16_MAX -#define INT16_MAX (32767) +#define INT16_MAX (32767) #endif #ifndef INT32_MAX -#define INT32_MAX (2147483647) +#define INT32_MAX (2147483647) #endif #ifndef UINT8_MAX -#define UINT8_MAX (255U) +#define UINT8_MAX (255U) #endif #ifndef UINT16_MAX -#define UINT16_MAX (65535U) +#define UINT16_MAX (65535U) #endif #ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) +#define UINT32_MAX (4294967295U) #endif #endif /* ! C99 */ @@ -93,15 +93,15 @@ typedef unsigned int flex_uint32_t; /* The "const" storage-class-modifier is valid. */ #define YY_USE_CONST -#else /* ! __cplusplus */ +#else /* ! __cplusplus */ /* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) +#if defined(__STDC__) #define YY_USE_CONST -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ #ifdef YY_USE_CONST #define yyconst const @@ -122,18 +122,18 @@ typedef unsigned int flex_uint32_t; /* An opaque pointer. */ #ifndef YY_TYPEDEF_YY_SCANNER_T #define YY_TYPEDEF_YY_SCANNER_T -typedef void* yyscan_t; +typedef void *yyscan_t; #endif /* For convenience, these vars (plus the bison vars far below) are macros in the reentrant scanner. */ -#define yyin yyg->yyin_r -#define yyout yyg->yyout_r -#define yyextra yyg->yyextra_r -#define yyleng yyg->yyleng_r -#define yytext yyg->yytext_r -#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) -#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) #define yy_flex_debug yyg->yy_flex_debug_r /* Enter a start condition. This macro really ought to take a parameter, @@ -147,13 +147,13 @@ typedef void* yyscan_t; * compatibility. */ #define YY_START ((yyg->yy_start - 1) / 2) -#define YYSTATE YY_START +#define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE hex_yyrestart(yyin ,yyscanner ) +#define YY_NEW_FILE hex_yyrestart(yyin, yyscanner) #define YY_END_OF_BUFFER_CHAR 0 @@ -170,9 +170,10 @@ typedef void* yyscan_t; #endif /* __ia64__ */ #endif -/* The state buf must be large enough to hold one state per character in the main buffer. +/* The state buf must be large enough to hold one state per character in the + * main buffer. */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE @@ -185,110 +186,110 @@ typedef size_t yy_size_t; #endif #define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires - * access to the local variable yy_act. Since yyless() is a macro, it would break - * existing scanners that call yyless() from OUTSIDE hex_yylex. - * One obvious solution it to make yy_act a global. I tried that, and saw - * a 5% performance hit in a non-yylineno scanner, because yy_act is - * normally declared as a register variable-- so it is not worth it. - */ - #define YY_LESS_LINENO(n) \ - do { \ - int yyl;\ - for ( yyl = n; yyl < yyleng; ++yyl )\ - if ( yytext[yyl] == '\n' )\ - --yylineno;\ - }while(0) - #define YY_LINENO_REWIND_TO(dst) \ - do {\ - const char *p;\ - for ( p = yy_cp-1; p >= (dst); --p)\ - if ( *p == '\n' )\ - --yylineno;\ - }while(0) - +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* Note: We specifically omit the test for yy_rule_can_match_eol because it + * requires access to the local variable yy_act. Since yyless() is a macro, it + * would break existing scanners that call yyless() from OUTSIDE hex_yylex. One + * obvious solution it to make yy_act a global. I tried that, and saw a 5% + * performance hit in a non-yylineno scanner, because yy_act is normally + * declared as a register variable-- so it is not worth it. + */ +#define YY_LESS_LINENO(n) \ + do \ + { \ + int yyl; \ + for (yyl = n; yyl < yyleng; ++yyl) \ + if (yytext[yyl] == '\n') \ + --yylineno; \ + } while (0) +#define YY_LINENO_REWIND_TO(dst) \ + do \ + { \ + const char *p; \ + for (p = yy_cp - 1; p >= (dst); --p) \ + if (*p == '\n') \ + --yylineno; \ + } while (0) + /* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = yyg->yy_hold_char; \ - YY_RESTORE_YY_MORE_OFFSET \ - yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg); \ + *yy_cp = yyg->yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } while (0) + +#define unput(c) yyunput(c, yyg->yytext_ptr, yyscanner) #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - yy_size_t yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 +{ + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + yy_size_t yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via hex_yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via hex_yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ #define YY_BUFFER_EOF_PENDING 2 - - }; +}; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ /* We provide macros for accessing buffer states in case in the @@ -297,64 +298,74 @@ struct yy_buffer_state * * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ - ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ - : NULL) +#define YY_CURRENT_BUFFER \ + (yyg->yy_buffer_stack ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ #define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] -void hex_yyrestart (FILE *input_file ,yyscan_t yyscanner ); -void hex_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); -YY_BUFFER_STATE hex_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner ); -void hex_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); -void hex_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); -void hex_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); -void hex_yypop_buffer_state (yyscan_t yyscanner ); - -static void hex_yyensure_buffer_stack (yyscan_t yyscanner ); -static void hex_yy_load_buffer_state (yyscan_t yyscanner ); -static void hex_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner ); - -#define YY_FLUSH_BUFFER hex_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner) - -YY_BUFFER_STATE hex_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); -YY_BUFFER_STATE hex_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); -YY_BUFFER_STATE hex_yy_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner ); - -void *hex_yyalloc (yy_size_t ,yyscan_t yyscanner ); -void *hex_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner ); -void hex_yyfree (void * ,yyscan_t yyscanner ); +void hex_yyrestart(FILE *input_file, yyscan_t yyscanner); +void hex_yy_switch_to_buffer(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner); +YY_BUFFER_STATE hex_yy_create_buffer(FILE *file, int size, yyscan_t yyscanner); +void hex_yy_delete_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner); +void hex_yy_flush_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner); +void hex_yypush_buffer_state(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner); +void hex_yypop_buffer_state(yyscan_t yyscanner); + +static void hex_yyensure_buffer_stack(yyscan_t yyscanner); +static void hex_yy_load_buffer_state(yyscan_t yyscanner); +static void hex_yy_init_buffer( + YY_BUFFER_STATE b, + FILE *file, + yyscan_t yyscanner); + +#define YY_FLUSH_BUFFER hex_yy_flush_buffer(YY_CURRENT_BUFFER, yyscanner) + +YY_BUFFER_STATE hex_yy_scan_buffer( + char *base, + yy_size_t size, + yyscan_t yyscanner); +YY_BUFFER_STATE hex_yy_scan_string(yyconst char *yy_str, yyscan_t yyscanner); +YY_BUFFER_STATE hex_yy_scan_bytes( + yyconst char *bytes, + yy_size_t len, + yyscan_t yyscanner); + +void *hex_yyalloc(yy_size_t, yyscan_t yyscanner); +void *hex_yyrealloc(void *, yy_size_t, yyscan_t yyscanner); +void hex_yyfree(void *, yyscan_t yyscanner); #define yy_new_buffer hex_yy_create_buffer -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - hex_yyensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - hex_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - hex_yyensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - hex_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } +#define yy_set_interactive(is_interactive) \ + { \ + if (!YY_CURRENT_BUFFER) \ + { \ + hex_yyensure_buffer_stack(yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = hex_yy_create_buffer( \ + yyin, YY_BUF_SIZE, yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if (!YY_CURRENT_BUFFER) \ + { \ + hex_yyensure_buffer_stack(yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = hex_yy_create_buffer( \ + yyin, YY_BUF_SIZE, yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) /* Begin user sect3 */ -#define hex_yywrap(yyscanner) (/*CONSTCOND*/1) +#define hex_yywrap(yyscanner) (/*CONSTCOND*/ 1) #define YY_SKIP_YYWRAP typedef unsigned char YY_CHAR; @@ -363,125 +374,87 @@ typedef int yy_state_type; #define yytext_ptr yytext_r -static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); -static int yy_get_next_buffer (yyscan_t yyscanner ); +static yy_state_type yy_get_previous_state(yyscan_t yyscanner); +static yy_state_type yy_try_NUL_trans( + yy_state_type current_state, + yyscan_t yyscanner); +static int yy_get_next_buffer(yyscan_t yyscanner); #if defined(__GNUC__) && __GNUC__ >= 3 __attribute__((__noreturn__)) #endif -static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); +static void +yy_fatal_error(yyconst char msg[], yyscan_t yyscanner); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ -#define YY_DO_BEFORE_ACTION \ - yyg->yytext_ptr = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - yyg->yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - yyg->yy_c_buf_p = yy_cp; - -#define YY_NUM_RULES 18 +#define YY_DO_BEFORE_ACTION \ + yyg->yytext_ptr = yy_bp; \ + yyleng = (size_t)(yy_cp - yy_bp); \ + yyg->yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yyg->yy_c_buf_p = yy_cp; + +#define YY_NUM_RULES 18 #define YY_END_OF_BUFFER 19 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[34] = - { 0, - 0, 0, 0, 0, 0, 0, 19, 17, 15, 15, - 16, 17, 17, 17, 5, 8, 8, 14, 13, 13, - 10, 11, 12, 6, 9, 1, 2, 3, 4, 7, - 11, 9, 0 - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 1, 1, 1, 1, 1, 1, 4, - 4, 5, 1, 1, 6, 1, 7, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, - 1, 1, 9, 1, 10, 10, 10, 10, 10, 10, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 11, 1, 12, 1, 1, 1, 10, 10, 10, 10, - - 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 4, 4, 4, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst YY_CHAR yy_meta[13] = - { 0, - 1, 1, 2, 1, 1, 1, 1, 3, 3, 3, - 1, 1 - } ; - -static yyconst flex_uint16_t yy_base[38] = - { 0, - 0, 0, 36, 35, 12, 0, 39, 42, 42, 42, - 42, 20, 29, 28, 42, 42, 29, 42, 42, 42, - 42, 27, 42, 42, 0, 42, 42, 42, 42, 42, - 26, 0, 42, 27, 29, 23, 30 - } ; - -static yyconst flex_int16_t yy_def[38] = - { 0, - 33, 1, 34, 34, 33, 5, 33, 33, 33, 33, - 33, 33, 35, 36, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33, 37, 33, 33, 33, 33, 33, - 33, 37, 0, 33, 33, 33, 33 - } ; - -static yyconst flex_uint16_t yy_nxt[55] = - { 0, - 8, 9, 10, 11, 8, 8, 12, 13, 14, 13, - 15, 8, 18, 19, 20, 18, 18, 21, 18, 22, - 18, 18, 18, 23, 24, 28, 25, 16, 16, 16, - 32, 26, 32, 31, 31, 30, 29, 27, 33, 17, - 17, 7, 33, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33 - } ; - -static yyconst flex_int16_t yy_chk[55] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 12, 36, 12, 34, 34, 34, - 37, 35, 37, 31, 22, 17, 14, 13, 7, 4, - 3, 33, 33, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33 - } ; +{ + flex_int32_t yy_verify; + flex_int32_t yy_nxt; +}; +static yyconst flex_int16_t yy_accept[34] = { + 0, 0, 0, 0, 0, 0, 0, 19, 17, 15, 15, 16, 17, 17, 17, 5, 8, + 8, 14, 13, 13, 10, 11, 12, 6, 9, 1, 2, 3, 4, 7, 11, 9, 0}; + +static yyconst YY_CHAR yy_ec[256] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 4, 4, + 5, 1, 1, 6, 1, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, + 9, 1, 10, 10, 10, 10, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 11, 1, 12, 1, 1, 1, 10, 10, 10, 10, + + 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + +static yyconst YY_CHAR yy_meta[13] = {0, 1, 1, 2, 1, 1, 1, 1, 3, 3, 3, 1, 1}; + +static yyconst flex_uint16_t yy_base[38] = { + 0, 0, 0, 36, 35, 12, 0, 39, 42, 42, 42, 42, 20, 29, 28, 42, 42, 29, 42, + 42, 42, 42, 27, 42, 42, 0, 42, 42, 42, 42, 42, 26, 0, 42, 27, 29, 23, 30}; + +static yyconst flex_int16_t yy_def[38] = { + 0, 33, 1, 34, 34, 33, 5, 33, 33, 33, 33, 33, 33, 35, 36, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 37, 33, 33, 33, 33, 33, 33, 37, 0, 33, 33, 33, 33}; + +static yyconst flex_uint16_t yy_nxt[55] = { + 0, 8, 9, 10, 11, 8, 8, 12, 13, 14, 13, 15, 8, 18, 19, 20, 18, 18, 21, + 18, 22, 18, 18, 18, 23, 24, 28, 25, 16, 16, 16, 32, 26, 32, 31, 31, 30, 29, + 27, 33, 17, 17, 7, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33}; + +static yyconst flex_int16_t yy_chk[55] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 12, 36, 12, 34, 34, 34, 37, 35, 37, 31, 22, 17, 14, + 13, 7, 4, 3, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33}; /* Table of booleans, true if rule could match eol. */ -static yyconst flex_int32_t yy_rule_can_match_eol[19] = - { 0, -0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, }; +static yyconst flex_int32_t yy_rule_can_match_eol[19] = { + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, +}; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET #line 1 "hex_lexer.l" @@ -530,15 +503,14 @@ with noyywrap then we can remove this pragma. #endif #include - +#include #include +#include #include -#include #include #include -#include #include -#include +#include #include "hex_grammar.h" @@ -546,23 +518,23 @@ with noyywrap then we can remove this pragma. #define snprintf _snprintf #endif -#define ERROR_IF(x, error) \ - if (x) \ - { \ - RE_AST* re_ast = hex_yyget_extra(yyscanner); \ - re_ast->error_code = error; \ - YYABORT; \ - } \ +#define ERROR_IF(x, error) \ + if (x) \ + { \ + RE_AST *re_ast = hex_yyget_extra(yyscanner); \ + re_ast->error_code = error; \ + YYABORT; \ + } #define YY_NO_UNISTD_H 1 -#define YY_NO_INPUT 1 +#define YY_NO_INPUT 1 #line 562 "hex_lexer.c" #define INITIAL 0 #define comment 1 -#define range 2 +#define range 2 #ifndef YY_NO_UNISTD_H /* Special case for "unistd.h", since it is non-ANSI. We include it way @@ -578,86 +550,86 @@ with noyywrap then we can remove this pragma. /* Holds the entire state of the reentrant scanner. */ struct yyguts_t - { +{ + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; - /* User-defined. Not touched by flex. */ - YY_EXTRA_TYPE yyextra_r; + /* The rest are the same as the globals declared in the non-reentrant scanner. + */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE *yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + yy_size_t yy_n_chars; + yy_size_t yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char *yy_last_accepting_cpos; - /* The rest are the same as the globals declared in the non-reentrant scanner. */ - FILE *yyin_r, *yyout_r; - size_t yy_buffer_stack_top; /**< index of top of stack. */ - size_t yy_buffer_stack_max; /**< capacity of stack. */ - YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ - char yy_hold_char; - yy_size_t yy_n_chars; - yy_size_t yyleng_r; - char *yy_c_buf_p; - int yy_init; - int yy_start; - int yy_did_buffer_switch_on_eof; - int yy_start_stack_ptr; - int yy_start_stack_depth; - int *yy_start_stack; - yy_state_type yy_last_accepting_state; - char* yy_last_accepting_cpos; + int yylineno_r; + int yy_flex_debug_r; - int yylineno_r; - int yy_flex_debug_r; + char *yytext_r; + int yy_more_flag; + int yy_more_len; - char *yytext_r; - int yy_more_flag; - int yy_more_len; + YYSTYPE *yylval_r; - YYSTYPE * yylval_r; +}; /* end struct yyguts_t */ - }; /* end struct yyguts_t */ +static int yy_init_globals(yyscan_t yyscanner); -static int yy_init_globals (yyscan_t yyscanner ); +/* This must go here because YYSTYPE and YYLTYPE are included + * from bison output in section 1.*/ +#define yylval yyg->yylval_r - /* This must go here because YYSTYPE and YYLTYPE are included - * from bison output in section 1.*/ - # define yylval yyg->yylval_r - -int hex_yylex_init (yyscan_t* scanner); +int hex_yylex_init(yyscan_t *scanner); -int hex_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); +int hex_yylex_init_extra(YY_EXTRA_TYPE user_defined, yyscan_t *scanner); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int hex_yylex_destroy (yyscan_t yyscanner ); +int hex_yylex_destroy(yyscan_t yyscanner); -int hex_yyget_debug (yyscan_t yyscanner ); +int hex_yyget_debug(yyscan_t yyscanner); -void hex_yyset_debug (int debug_flag ,yyscan_t yyscanner ); +void hex_yyset_debug(int debug_flag, yyscan_t yyscanner); -YY_EXTRA_TYPE hex_yyget_extra (yyscan_t yyscanner ); +YY_EXTRA_TYPE hex_yyget_extra(yyscan_t yyscanner); -void hex_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); +void hex_yyset_extra(YY_EXTRA_TYPE user_defined, yyscan_t yyscanner); -FILE *hex_yyget_in (yyscan_t yyscanner ); +FILE *hex_yyget_in(yyscan_t yyscanner); -void hex_yyset_in (FILE * _in_str ,yyscan_t yyscanner ); +void hex_yyset_in(FILE *_in_str, yyscan_t yyscanner); -FILE *hex_yyget_out (yyscan_t yyscanner ); +FILE *hex_yyget_out(yyscan_t yyscanner); -void hex_yyset_out (FILE * _out_str ,yyscan_t yyscanner ); +void hex_yyset_out(FILE *_out_str, yyscan_t yyscanner); -yy_size_t hex_yyget_leng (yyscan_t yyscanner ); +yy_size_t hex_yyget_leng(yyscan_t yyscanner); -char *hex_yyget_text (yyscan_t yyscanner ); +char *hex_yyget_text(yyscan_t yyscanner); -int hex_yyget_lineno (yyscan_t yyscanner ); +int hex_yyget_lineno(yyscan_t yyscanner); -void hex_yyset_lineno (int _line_number ,yyscan_t yyscanner ); +void hex_yyset_lineno(int _line_number, yyscan_t yyscanner); -int hex_yyget_column (yyscan_t yyscanner ); +int hex_yyget_column(yyscan_t yyscanner); -void hex_yyset_column (int _column_no ,yyscan_t yyscanner ); +void hex_yyset_column(int _column_no, yyscan_t yyscanner); -YYSTYPE * hex_yyget_lval (yyscan_t yyscanner ); +YYSTYPE *hex_yyget_lval(yyscan_t yyscanner); -void hex_yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); +void hex_yyset_lval(YYSTYPE *yylval_param, yyscan_t yyscanner); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -665,30 +637,30 @@ void hex_yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int hex_yywrap (yyscan_t yyscanner ); +extern "C" int hex_yywrap(yyscan_t yyscanner); #else -extern int hex_yywrap (yyscan_t yyscanner ); +extern int hex_yywrap(yyscan_t yyscanner); #endif #endif #ifndef YY_NO_UNPUT - + #endif #ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); +static void yy_flex_strncpy(char *, yyconst char *, int, yyscan_t yyscanner); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner); +static int yy_flex_strlen(yyconst char *, yyscan_t yyscanner); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput (yyscan_t yyscanner ); +static int yyinput(yyscan_t yyscanner); #else -static int input (yyscan_t yyscanner ); +static int input(yyscan_t yyscanner); #endif #endif @@ -708,42 +680,47 @@ static int input (yyscan_t yyscanner ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#define ECHO \ + do \ + { \ + if (fwrite(yytext, yyleng, 1, yyout)) \ + { \ + } \ + } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, * is returned in "result". */ #ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ +#define YY_INPUT(buf, result, max_size) \ + if (YY_CURRENT_BUFFER_LVALUE->yy_is_interactive) \ + { \ + int c = '*'; \ + size_t n; \ + for (n = 0; n < max_size && (c = getc(yyin)) != EOF && c != '\n'; ++n) \ + buf[n] = (char) c; \ + if (c == '\n') \ + buf[n++] = (char) c; \ + if (c == EOF && ferror(yyin)) \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + result = n; \ + } \ + else \ + { \ + errno = 0; \ + while ((result = fread(buf, 1, max_size, yyin)) == 0 && ferror(yyin)) \ + { \ + if (errno != EINTR) \ + { \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + break; \ + } \ + errno = 0; \ + clearerr(yyin); \ + } \ + } + #endif @@ -762,7 +739,7 @@ static int input (yyscan_t yyscanner ); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) +#define YY_FATAL_ERROR(msg) yy_fatal_error(msg, yyscanner) #endif /* end tables serialization structures and prototypes */ @@ -773,11 +750,9 @@ static int input (yyscan_t yyscanner ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int hex_yylex \ - (YYSTYPE * yylval_param ,yyscan_t yyscanner); +extern int hex_yylex(YYSTYPE *yylval_param, yyscan_t yyscanner); -#define YY_DECL int hex_yylex \ - (YYSTYPE * yylval_param , yyscan_t yyscanner) +#define YY_DECL int hex_yylex(YYSTYPE *yylval_param, yyscan_t yyscanner) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -789,397 +764,386 @@ extern int hex_yylex \ /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; +#define YY_BREAK /*LINTED*/ break; #endif -#define YY_RULE_SETUP \ - YY_USER_ACTION +#define YY_RULE_SETUP YY_USER_ACTION /** The main scanner function which does all the work. */ YY_DECL { - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - yylval = yylval_param; + yylval = yylval_param; - if ( !yyg->yy_init ) - { - yyg->yy_init = 1; + if (!yyg->yy_init) + { + yyg->yy_init = 1; #ifdef YY_USER_INIT - YY_USER_INIT; + YY_USER_INIT; #endif - if ( ! yyg->yy_start ) - yyg->yy_start = 1; /* first start state */ + if (!yyg->yy_start) + yyg->yy_start = 1; /* first start state */ - if ( ! yyin ) - yyin = stdin; + if (!yyin) + yyin = stdin; - if ( ! yyout ) - yyout = stdout; + if (!yyout) + yyout = stdout; - if ( ! YY_CURRENT_BUFFER ) { - hex_yyensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - hex_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); - } + if (!YY_CURRENT_BUFFER) + { + hex_yyensure_buffer_stack(yyscanner); + YY_CURRENT_BUFFER_LVALUE = hex_yy_create_buffer( + yyin, YY_BUF_SIZE, yyscanner); + } - hex_yy_load_buffer_state(yyscanner ); - } + hex_yy_load_buffer_state(yyscanner); + } - { + { #line 95 "hex_lexer.l" - #line 841 "hex_lexer.c" - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = yyg->yy_c_buf_p; - - /* Support of yytext. */ - *yy_cp = yyg->yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = yyg->yy_start; -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 34 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_current_state != 33 ); - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - - YY_DO_BEFORE_ACTION; - - if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) - { - yy_size_t yyl; - for ( yyl = 0; yyl < yyleng; ++yyl ) - if ( yytext[yyl] == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; - } - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = yyg->yy_hold_char; - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - goto yy_find_action; - -case 1: -YY_RULE_SETUP + while (/*CONSTCOND*/ 1) /* loops until end-of-file is reached */ + { + yy_cp = yyg->yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yyg->yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yyg->yy_start; + yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if (yy_accept[yy_current_state]) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) + { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 34) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = + yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } while (yy_current_state != 33); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + + yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + + if (yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act]) + { + yy_size_t yyl; + for (yyl = 0; yyl < yyleng; ++yyl) + if (yytext[yyl] == '\n') + + do + { + yylineno++; + yycolumn = 0; + } while (0); + } + + do_action: /* This label is used only to access EOF actions. */ + + switch (yy_act) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yyg->yy_hold_char; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + goto yy_find_action; + + case 1: + YY_RULE_SETUP #line 98 "hex_lexer.l" -{ - - yylval->integer = xtoi(yytext); - return _BYTE_; -} - YY_BREAK -case 2: -YY_RULE_SETUP + { + yylval->integer = xtoi(yytext); + return _BYTE_; + } + YY_BREAK + case 2: + YY_RULE_SETUP #line 104 "hex_lexer.l" -{ - - yytext[1] = '0'; // replace ? by 0 - yylval->integer = xtoi(yytext) | 0xF000 ; - return _MASKED_BYTE_; -} - YY_BREAK -case 3: -YY_RULE_SETUP + { + yytext[1] = '0'; // replace ? by 0 + yylval->integer = xtoi(yytext) | 0xF000; + return _MASKED_BYTE_; + } + YY_BREAK + case 3: + YY_RULE_SETUP #line 111 "hex_lexer.l" -{ - - yytext[0] = '0'; // replace ? by 0 - yylval->integer = xtoi(yytext) | 0x0F00 ; - return _MASKED_BYTE_; -} - YY_BREAK -case 4: -YY_RULE_SETUP + { + yytext[0] = '0'; // replace ? by 0 + yylval->integer = xtoi(yytext) | 0x0F00; + return _MASKED_BYTE_; + } + YY_BREAK + case 4: + YY_RULE_SETUP #line 118 "hex_lexer.l" -{ - - yylval->integer = 0x0000; - return _MASKED_BYTE_; -} - YY_BREAK -case 5: -YY_RULE_SETUP + { + yylval->integer = 0x0000; + return _MASKED_BYTE_; + } + YY_BREAK + case 5: + YY_RULE_SETUP #line 124 "hex_lexer.l" -{ - - BEGIN(range); - return yytext[0]; -} - YY_BREAK -case 6: -YY_RULE_SETUP + { + BEGIN(range); + return yytext[0]; + } + YY_BREAK + case 6: + YY_RULE_SETUP #line 130 "hex_lexer.l" -{ - - BEGIN(comment); -} - YY_BREAK -case 7: -YY_RULE_SETUP + { + BEGIN(comment); + } + YY_BREAK + case 7: + YY_RULE_SETUP #line 135 "hex_lexer.l" -{ - - BEGIN(INITIAL); -} - YY_BREAK -case 8: -/* rule 8 can match eol */ -YY_RULE_SETUP + { + BEGIN(INITIAL); + } + YY_BREAK + case 8: + /* rule 8 can match eol */ + YY_RULE_SETUP #line 140 "hex_lexer.l" -// skip comments - YY_BREAK -case 9: -YY_RULE_SETUP + // skip comments + YY_BREAK + case 9: + YY_RULE_SETUP #line 142 "hex_lexer.l" -// skip single-line comments - YY_BREAK -case 10: -YY_RULE_SETUP + // skip single-line comments + YY_BREAK + case 10: + YY_RULE_SETUP #line 144 "hex_lexer.l" -{ - - return yytext[0]; -} - YY_BREAK -case 11: -YY_RULE_SETUP + { + return yytext[0]; + } + YY_BREAK + case 11: + YY_RULE_SETUP #line 149 "hex_lexer.l" -{ - - yylval->integer = atoi(yytext); - return _NUMBER_; -} - YY_BREAK -case 12: -YY_RULE_SETUP + { + yylval->integer = atoi(yytext); + return _NUMBER_; + } + YY_BREAK + case 12: + YY_RULE_SETUP #line 155 "hex_lexer.l" -{ - - BEGIN(INITIAL); - return yytext[0]; -} - YY_BREAK -case 13: -/* rule 13 can match eol */ -YY_RULE_SETUP + { + BEGIN(INITIAL); + return yytext[0]; + } + YY_BREAK + case 13: + /* rule 13 can match eol */ + YY_RULE_SETUP #line 161 "hex_lexer.l" -// skip whitespaces - YY_BREAK -case 14: -YY_RULE_SETUP + // skip whitespaces + YY_BREAK + case 14: + YY_RULE_SETUP #line 163 "hex_lexer.l" -{ - - yyerror(yyscanner, lex_env, "invalid character in hex string jump"); - yyterminate(); -} - YY_BREAK -case 15: -/* rule 15 can match eol */ -YY_RULE_SETUP + { + yyerror(yyscanner, lex_env, "invalid character in hex string jump"); + yyterminate(); + } + YY_BREAK + case 15: + /* rule 15 can match eol */ + YY_RULE_SETUP #line 169 "hex_lexer.l" -// skip whitespaces - YY_BREAK -case 16: -YY_RULE_SETUP + // skip whitespaces + YY_BREAK + case 16: + YY_RULE_SETUP #line 171 "hex_lexer.l" -{ // pass valid characters to the parser + { // pass valid characters to the parser - return yytext[0]; -} - YY_BREAK -case 17: -YY_RULE_SETUP + return yytext[0]; + } + YY_BREAK + case 17: + YY_RULE_SETUP #line 176 "hex_lexer.l" -{ // reject all other characters - - yyerror(yyscanner, lex_env, "invalid character in hex string"); - yyterminate(); -} - YY_BREAK -case 18: -YY_RULE_SETUP + { // reject all other characters + + yyerror(yyscanner, lex_env, "invalid character in hex string"); + yyterminate(); + } + YY_BREAK + case 18: + YY_RULE_SETUP #line 182 "hex_lexer.l" -ECHO; - YY_BREAK + ECHO; + YY_BREAK #line 1049 "hex_lexer.c" -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(comment): -case YY_STATE_EOF(range): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yyg->yy_hold_char; - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * hex_yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yyg->yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_END_OF_FILE: - { - yyg->yy_did_buffer_switch_on_eof = 0; - - if ( hex_yywrap(yyscanner ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = - yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - yyg->yy_c_buf_p = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ + case YY_STATE_EOF(INITIAL): + case YY_STATE_EOF(comment): + case YY_STATE_EOF(range): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yyg->yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * hex_yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if (yyg->yy_c_buf_p <= + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(yyscanner); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans(yy_current_state, yyscanner); + + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + + if (yy_next_state) + { + /* Consume the NUL. */ + yy_cp = ++yyg->yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + goto yy_find_action; + } + } + + else + switch (yy_get_next_buffer(yyscanner)) + { + case EOB_ACT_END_OF_FILE: + { + yyg->yy_did_buffer_switch_on_eof = 0; + + if (hex_yywrap(yyscanner)) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if (!yyg->yy_did_buffer_switch_on_eof) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(yyscanner); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; + + yy_current_state = yy_get_previous_state(yyscanner); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR("fatal flex scanner internal error--no action found"); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ } /* end of hex_yylex */ /* yy_get_next_buffer - try to read in a new buffer @@ -1189,167 +1153,168 @@ case YY_STATE_EOF(range): * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ -static int yy_get_next_buffer (yyscan_t yyscanner) +static int yy_get_next_buffer(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = yyg->yytext_ptr; - yy_size_t number_to_move, i; - int ret_val; - - if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; - - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) (yyg->yy_c_buf_p - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - hex_yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - if ( yyg->yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - hex_yyrestart(yyin ,yyscanner); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) hex_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - yyg->yy_n_chars += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = yyg->yytext_ptr; + yy_size_t number_to_move, i; + int ret_val; + + if (yyg->yy_c_buf_p > + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1]) + YY_FATAL_ERROR("fatal flex scanner internal error--end of buffer missed"); + + if (YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0) + { /* Don't try to fill the buffer, so this is an EOF. */ + if (yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (yy_size_t)(yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; + + for (i = 0; i < number_to_move; ++i) *(dest++) = *(source++); + + if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; + + else + { + yy_size_t num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; - return ret_val; + while (num_to_read <= 0) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = (int) (yyg->yy_c_buf_p - b->yy_ch_buf); + + if (b->yy_is_our_buffer) + { + yy_size_t new_size = b->yy_buf_size * 2; + + if (new_size <= 0) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + hex_yyrealloc((void *) b->yy_ch_buf, b->yy_buf_size + 2, yyscanner); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if (!b->yy_ch_buf) + YY_FATAL_ERROR("fatal error - scanner input buffer overflow"); + + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + } + + if (num_to_read > YY_READ_BUF_SIZE) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( + (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + yyg->yy_n_chars, + num_to_read); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + if (yyg->yy_n_chars == 0) + { + if (number_to_move == YY_MORE_ADJ) + { + ret_val = EOB_ACT_END_OF_FILE; + hex_yyrestart(yyin, yyscanner); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t)(yyg->yy_n_chars + number_to_move) > + YY_CURRENT_BUFFER_LVALUE->yy_buf_size) + { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = yyg->yy_n_chars + number_to_move + + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) hex_yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, new_size, yyscanner); + if (!YY_CURRENT_BUFFER_LVALUE->yy_ch_buf) + YY_FATAL_ERROR("out of dynamic memory in yy_get_next_buffer()"); + } + + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = + YY_END_OF_BUFFER_CHAR; + + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ - static yy_state_type yy_get_previous_state (yyscan_t yyscanner) +static yy_state_type yy_get_previous_state(yyscan_t yyscanner) { - yy_state_type yy_current_state; - char *yy_cp; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - yy_current_state = yyg->yy_start; - - for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 34 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; + yy_state_type yy_current_state; + char *yy_cp; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + yy_current_state = yyg->yy_start; + + for (yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if (yy_accept[yy_current_state]) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) + { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 34) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; } /* yy_try_NUL_trans - try to make a transition on the NUL character @@ -1357,29 +1322,32 @@ static int yy_get_next_buffer (yyscan_t yyscanner) * synopsis * next_state = yy_try_NUL_trans( current_state ); */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) +static yy_state_type yy_try_NUL_trans( + yy_state_type yy_current_state, + yyscan_t yyscanner) { - int yy_is_jam; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ - char *yy_cp = yyg->yy_c_buf_p; - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 34 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 33); - - (void)yyg; - return yy_is_jam ? 0 : yy_current_state; + int yy_is_jam; + struct yyguts_t *yyg = (struct yyguts_t *) + yyscanner; /* This var may be unused depending upon options. */ + char *yy_cp = yyg->yy_c_buf_p; + + YY_CHAR yy_c = 1; + if (yy_accept[yy_current_state]) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) + { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 34) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 33); + + (void) yyg; + return yy_is_jam ? 0 : yy_current_state; } #ifndef YY_NO_UNPUT @@ -1388,255 +1356,262 @@ static int yy_get_next_buffer (yyscan_t yyscanner) #ifndef YY_NO_INPUT #ifdef __cplusplus - static int yyinput (yyscan_t yyscanner) +static int yyinput(yyscan_t yyscanner) #else - static int input (yyscan_t yyscanner) +static int input(yyscan_t yyscanner) #endif { - int c; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - *yyg->yy_c_buf_p = yyg->yy_hold_char; - - if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - /* This was really a NUL. */ - *yyg->yy_c_buf_p = '\0'; - - else - { /* need more input */ - yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr; - ++yyg->yy_c_buf_p; - - switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - hex_yyrestart(yyin ,yyscanner); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( hex_yywrap(yyscanner ) ) - return EOF; - - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; + int c; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + *yyg->yy_c_buf_p = yyg->yy_hold_char; + + if (*yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if (yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]) + /* This was really a NUL. */ + *yyg->yy_c_buf_p = '\0'; + + else + { /* need more input */ + yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr; + ++yyg->yy_c_buf_p; + + switch (yy_get_next_buffer(yyscanner)) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + hex_yyrestart(yyin, yyscanner); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if (hex_yywrap(yyscanner)) + return EOF; + + if (!yyg->yy_did_buffer_switch_on_eof) + YY_NEW_FILE; #ifdef __cplusplus - return yyinput(yyscanner); + return yyinput(yyscanner); #else - return input(yyscanner); + return input(yyscanner); #endif - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = yyg->yytext_ptr + offset; - break; - } - } - } - - c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ - *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ - yyg->yy_hold_char = *++yyg->yy_c_buf_p; - - if ( c == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; - - return c; + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; + break; + } + } + } + + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; + + if (c == '\n') + + do + { + yylineno++; + yycolumn = 0; + } while (0); + + return c; } -#endif /* ifndef YY_NO_INPUT */ +#endif /* ifndef YY_NO_INPUT */ /** Immediately switch to a different input stream. * @param input_file A readable stream. * @param yyscanner The scanner object. * @note This function does not reset the start condition to @c INITIAL . */ - void hex_yyrestart (FILE * input_file , yyscan_t yyscanner) +void hex_yyrestart(FILE *input_file, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - if ( ! YY_CURRENT_BUFFER ){ - hex_yyensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - hex_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); - } + if (!YY_CURRENT_BUFFER) + { + hex_yyensure_buffer_stack(yyscanner); + YY_CURRENT_BUFFER_LVALUE = hex_yy_create_buffer( + yyin, YY_BUF_SIZE, yyscanner); + } - hex_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner); - hex_yy_load_buffer_state(yyscanner ); + hex_yy_init_buffer(YY_CURRENT_BUFFER, input_file, yyscanner); + hex_yy_load_buffer_state(yyscanner); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. * @param yyscanner The scanner object. */ - void hex_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +void hex_yy_switch_to_buffer(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + /* TODO. We should be able to replace this entire function body + * with + * hex_yypop_buffer_state(); + * hex_yypush_buffer_state(new_buffer); + */ + hex_yyensure_buffer_stack(yyscanner); + if (YY_CURRENT_BUFFER == new_buffer) + return; + + if (YY_CURRENT_BUFFER) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } - /* TODO. We should be able to replace this entire function body - * with - * hex_yypop_buffer_state(); - * hex_yypush_buffer_state(new_buffer); - */ - hex_yyensure_buffer_stack (yyscanner); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - hex_yy_load_buffer_state(yyscanner ); - - /* We don't actually know whether we did this switch during - * EOF (hex_yywrap()) processing, but the only time this flag - * is looked at is after hex_yywrap() is called, so it's safe - * to go ahead and always set it. - */ - yyg->yy_did_buffer_switch_on_eof = 1; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + hex_yy_load_buffer_state(yyscanner); + + /* We don't actually know whether we did this switch during + * EOF (hex_yywrap()) processing, but the only time this flag + * is looked at is after hex_yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yyg->yy_did_buffer_switch_on_eof = 1; } -static void hex_yy_load_buffer_state (yyscan_t yyscanner) +static void hex_yy_load_buffer_state(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - yyg->yy_hold_char = *yyg->yy_c_buf_p; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + yyg->yy_hold_char = *yyg->yy_c_buf_p; } /** Allocate and initialize an input buffer state. * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * @param size The character buffer size in bytes. When in doubt, use @c + * YY_BUF_SIZE. * @param yyscanner The scanner object. * @return the allocated buffer state. */ - YY_BUFFER_STATE hex_yy_create_buffer (FILE * file, int size , yyscan_t yyscanner) +YY_BUFFER_STATE hex_yy_create_buffer(FILE *file, int size, yyscan_t yyscanner) { - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) hex_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in hex_yy_create_buffer()" ); + YY_BUFFER_STATE b; - b->yy_buf_size = (yy_size_t)size; + b = (YY_BUFFER_STATE) hex_yyalloc(sizeof(struct yy_buffer_state), yyscanner); + if (!b) + YY_FATAL_ERROR("out of dynamic memory in hex_yy_create_buffer()"); - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) hex_yyalloc(b->yy_buf_size + 2 ,yyscanner ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in hex_yy_create_buffer()" ); + b->yy_buf_size = (yy_size_t) size; - b->yy_is_our_buffer = 1; + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) hex_yyalloc(b->yy_buf_size + 2, yyscanner); + if (!b->yy_ch_buf) + YY_FATAL_ERROR("out of dynamic memory in hex_yy_create_buffer()"); - hex_yy_init_buffer(b,file ,yyscanner); + b->yy_is_our_buffer = 1; - return b; + hex_yy_init_buffer(b, file, yyscanner); + + return b; } /** Destroy the buffer. * @param b a buffer created with hex_yy_create_buffer() * @param yyscanner The scanner object. */ - void hex_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +void hex_yy_delete_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - if ( ! b ) - return; + if (!b) + return; - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + if (b == YY_CURRENT_BUFFER) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - if ( b->yy_is_our_buffer ) - hex_yyfree((void *) b->yy_ch_buf ,yyscanner ); + if (b->yy_is_our_buffer) + hex_yyfree((void *) b->yy_ch_buf, yyscanner); - hex_yyfree((void *) b ,yyscanner ); + hex_yyfree((void *) b, yyscanner); } /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a hex_yyrestart() or at EOF. */ - static void hex_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) +static void hex_yy_init_buffer( + YY_BUFFER_STATE b, + FILE *file, + yyscan_t yyscanner) { - int oerrno = errno; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + int oerrno = errno; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - hex_yy_flush_buffer(b ,yyscanner); + hex_yy_flush_buffer(b, yyscanner); - b->yy_input_file = file; - b->yy_fill_buffer = 1; + b->yy_input_file = file; + b->yy_fill_buffer = 1; - /* If b is the current buffer, then hex_yy_init_buffer was _probably_ - * called from hex_yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } + /* If b is the current buffer, then hex_yy_init_buffer was _probably_ + * called from hex_yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER) + { + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = 0; - b->yy_is_interactive = 0; - - errno = oerrno; + errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. * @param yyscanner The scanner object. */ - void hex_yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +void hex_yy_flush_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if ( ! b ) - return; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + if (!b) + return; - b->yy_n_chars = 0; + b->yy_n_chars = 0; - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - b->yy_buf_pos = &b->yy_ch_buf[0]; + b->yy_buf_pos = &b->yy_ch_buf[0]; - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; - if ( b == YY_CURRENT_BUFFER ) - hex_yy_load_buffer_state(yyscanner ); + if (b == YY_CURRENT_BUFFER) + hex_yy_load_buffer_state(yyscanner); } /** Pushes the new state onto the stack. The new state becomes @@ -1645,328 +1620,337 @@ static void hex_yy_load_buffer_state (yyscan_t yyscanner) * @param new_buffer The new state. * @param yyscanner The scanner object. */ -void hex_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +void hex_yypush_buffer_state(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (new_buffer == NULL) - return; - - hex_yyensure_buffer_stack(yyscanner); - - /* This block is copied from hex_yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - yyg->yy_buffer_stack_top++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from hex_yy_switch_to_buffer. */ - hex_yy_load_buffer_state(yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + if (new_buffer == NULL) + return; + + hex_yyensure_buffer_stack(yyscanner); + + /* This block is copied from hex_yy_switch_to_buffer. */ + if (YY_CURRENT_BUFFER) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + yyg->yy_buffer_stack_top++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from hex_yy_switch_to_buffer. */ + hex_yy_load_buffer_state(yyscanner); + yyg->yy_did_buffer_switch_on_eof = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. * @param yyscanner The scanner object. */ -void hex_yypop_buffer_state (yyscan_t yyscanner) +void hex_yypop_buffer_state(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (!YY_CURRENT_BUFFER) - return; - - hex_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner); - YY_CURRENT_BUFFER_LVALUE = NULL; - if (yyg->yy_buffer_stack_top > 0) - --yyg->yy_buffer_stack_top; - - if (YY_CURRENT_BUFFER) { - hex_yy_load_buffer_state(yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; - } + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + if (!YY_CURRENT_BUFFER) + return; + + hex_yy_delete_buffer(YY_CURRENT_BUFFER, yyscanner); + YY_CURRENT_BUFFER_LVALUE = NULL; + if (yyg->yy_buffer_stack_top > 0) + --yyg->yy_buffer_stack_top; + + if (YY_CURRENT_BUFFER) + { + hex_yy_load_buffer_state(yyscanner); + yyg->yy_did_buffer_switch_on_eof = 1; + } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ -static void hex_yyensure_buffer_stack (yyscan_t yyscanner) +static void hex_yyensure_buffer_stack(yyscan_t yyscanner) { - yy_size_t num_to_alloc; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_size_t num_to_alloc; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - if (!yyg->yy_buffer_stack) { + if (!yyg->yy_buffer_stack) + { + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; // After all that talk, this was set to 1 anyways... + yyg->yy_buffer_stack = (struct yy_buffer_state **) hex_yyalloc( + num_to_alloc * sizeof(struct yy_buffer_state *), yyscanner); + if (!yyg->yy_buffer_stack) + YY_FATAL_ERROR("out of dynamic memory in hex_yyensure_buffer_stack()"); + + memset( + yyg->yy_buffer_stack, + 0, + num_to_alloc * sizeof(struct yy_buffer_state *)); + + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; + return; + } - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; // After all that talk, this was set to 1 anyways... - yyg->yy_buffer_stack = (struct yy_buffer_state**)hex_yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in hex_yyensure_buffer_stack()" ); - - memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - yyg->yy_buffer_stack_max = num_to_alloc; - yyg->yy_buffer_stack_top = 0; - return; - } - - if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = yyg->yy_buffer_stack_max + grow_size; - yyg->yy_buffer_stack = (struct yy_buffer_state**)hex_yyrealloc - (yyg->yy_buffer_stack, - num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in hex_yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); - yyg->yy_buffer_stack_max = num_to_alloc; - } + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1) + { + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state **) hex_yyrealloc( + yyg->yy_buffer_stack, + num_to_alloc * sizeof(struct yy_buffer_state *), + yyscanner); + if (!yyg->yy_buffer_stack) + YY_FATAL_ERROR("out of dynamic memory in hex_yyensure_buffer_stack()"); + + /* zero only the new slots.*/ + memset( + yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, + 0, + grow_size * sizeof(struct yy_buffer_state *)); + yyg->yy_buffer_stack_max = num_to_alloc; + } } -/** Setup the input buffer state to scan directly from a user-specified character buffer. +/** Setup the input buffer state to scan directly from a user-specified + * character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. + * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE hex_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) +YY_BUFFER_STATE hex_yy_scan_buffer( + char *base, + yy_size_t size, + yyscan_t yyscanner) { - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) hex_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in hex_yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - hex_yy_switch_to_buffer(b ,yyscanner ); - - return b; + YY_BUFFER_STATE b; + + if (size < 2 || base[size - 2] != YY_END_OF_BUFFER_CHAR || + base[size - 1] != YY_END_OF_BUFFER_CHAR) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) hex_yyalloc(sizeof(struct yy_buffer_state), yyscanner); + if (!b) + YY_FATAL_ERROR("out of dynamic memory in hex_yy_scan_buffer()"); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + hex_yy_switch_to_buffer(b, yyscanner); + + return b; } -/** Setup the input buffer state to scan a string. The next call to hex_yylex() will - * scan from a @e copy of @a str. +/** Setup the input buffer state to scan a string. The next call to hex_yylex() + * will scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan * @param yyscanner The scanner object. * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * hex_yy_scan_bytes() instead. */ -YY_BUFFER_STATE hex_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner) +YY_BUFFER_STATE hex_yy_scan_string(yyconst char *yystr, yyscan_t yyscanner) { - - return hex_yy_scan_bytes(yystr,strlen(yystr) ,yyscanner); + return hex_yy_scan_bytes(yystr, strlen(yystr), yyscanner); } -/** Setup the input buffer state to scan the given bytes. The next call to hex_yylex() will - * scan from a @e copy of @a bytes. +/** Setup the input buffer state to scan the given bytes. The next call to + * hex_yylex() will scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE hex_yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner) +YY_BUFFER_STATE hex_yy_scan_bytes( + yyconst char *yybytes, + yy_size_t _yybytes_len, + yyscan_t yyscanner) { - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - yy_size_t i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) hex_yyalloc(n ,yyscanner ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in hex_yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = hex_yy_scan_buffer(buf,n ,yyscanner); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in hex_yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + yy_size_t i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) hex_yyalloc(n, yyscanner); + if (!buf) + YY_FATAL_ERROR("out of dynamic memory in hex_yy_scan_bytes()"); + + for (i = 0; i < _yybytes_len; ++i) buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len + 1] = YY_END_OF_BUFFER_CHAR; + + b = hex_yy_scan_buffer(buf, n, yyscanner); + if (!b) + YY_FATAL_ERROR("bad buffer in hex_yy_scan_bytes()"); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; } #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif -static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) +static void yy_fatal_error(yyconst char *msg, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + (void) fprintf(stderr, "%s\n", msg); + exit(YY_EXIT_FAILURE); } /* Redefine yyless() so it works in section 3 code. */ #undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = yyg->yy_hold_char; \ - yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ - yyg->yy_hold_char = *yyg->yy_c_buf_p; \ - *yyg->yy_c_buf_p = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg); \ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ + yyleng = yyless_macro_arg; \ + } while (0) /* Accessor methods (get/set functions) to struct members. */ /** Get the user-defined data for this scanner. * @param yyscanner The scanner object. */ -YY_EXTRA_TYPE hex_yyget_extra (yyscan_t yyscanner) +YY_EXTRA_TYPE hex_yyget_extra(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyextra; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyextra; } /** Get the current line number. * @param yyscanner The scanner object. */ -int hex_yyget_lineno (yyscan_t yyscanner) +int hex_yyget_lineno(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (! YY_CURRENT_BUFFER) - return 0; - - return yylineno; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + if (!YY_CURRENT_BUFFER) + return 0; + + return yylineno; } /** Get the current column number. * @param yyscanner The scanner object. */ -int hex_yyget_column (yyscan_t yyscanner) +int hex_yyget_column(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (! YY_CURRENT_BUFFER) - return 0; - - return yycolumn; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + if (!YY_CURRENT_BUFFER) + return 0; + + return yycolumn; } /** Get the input stream. * @param yyscanner The scanner object. */ -FILE *hex_yyget_in (yyscan_t yyscanner) +FILE *hex_yyget_in(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyin; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyin; } /** Get the output stream. * @param yyscanner The scanner object. */ -FILE *hex_yyget_out (yyscan_t yyscanner) +FILE *hex_yyget_out(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyout; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyout; } /** Get the length of the current token. * @param yyscanner The scanner object. */ -yy_size_t hex_yyget_leng (yyscan_t yyscanner) +yy_size_t hex_yyget_leng(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyleng; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyleng; } /** Get the current token. * @param yyscanner The scanner object. */ -char *hex_yyget_text (yyscan_t yyscanner) +char *hex_yyget_text(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yytext; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yytext; } /** Set the user-defined data. This data is never touched by the scanner. * @param user_defined The data to be associated with this scanner. * @param yyscanner The scanner object. */ -void hex_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) +void hex_yyset_extra(YY_EXTRA_TYPE user_defined, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyextra = user_defined ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyextra = user_defined; } /** Set the current line number. * @param _line_number line number * @param yyscanner The scanner object. */ -void hex_yyset_lineno (int _line_number , yyscan_t yyscanner) +void hex_yyset_lineno(int _line_number, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + /* lineno is only valid if an input buffer exists. */ + if (!YY_CURRENT_BUFFER) + YY_FATAL_ERROR("hex_yyset_lineno called with no buffer"); - /* lineno is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "hex_yyset_lineno called with no buffer" ); - - yylineno = _line_number; + yylineno = _line_number; } /** Set the current column. * @param _column_no column number * @param yyscanner The scanner object. */ -void hex_yyset_column (int _column_no , yyscan_t yyscanner) +void hex_yyset_column(int _column_no, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - /* column is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "hex_yyset_column called with no buffer" ); - - yycolumn = _column_no; + /* column is only valid if an input buffer exists. */ + if (!YY_CURRENT_BUFFER) + YY_FATAL_ERROR("hex_yyset_column called with no buffer"); + + yycolumn = _column_no; } /** Set the input stream. This does not discard the current @@ -1975,169 +1959,179 @@ void hex_yyset_column (int _column_no , yyscan_t yyscanner) * @param yyscanner The scanner object. * @see hex_yy_switch_to_buffer */ -void hex_yyset_in (FILE * _in_str , yyscan_t yyscanner) +void hex_yyset_in(FILE *_in_str, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyin = _in_str ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyin = _in_str; } -void hex_yyset_out (FILE * _out_str , yyscan_t yyscanner) +void hex_yyset_out(FILE *_out_str, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyout = _out_str ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyout = _out_str; } -int hex_yyget_debug (yyscan_t yyscanner) +int hex_yyget_debug(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yy_flex_debug; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yy_flex_debug; } -void hex_yyset_debug (int _bdebug , yyscan_t yyscanner) +void hex_yyset_debug(int _bdebug, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yy_flex_debug = _bdebug ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yy_flex_debug = _bdebug; } /* Accessor methods for yylval and yylloc */ -YYSTYPE * hex_yyget_lval (yyscan_t yyscanner) +YYSTYPE *hex_yyget_lval(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yylval; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yylval; } -void hex_yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) +void hex_yyset_lval(YYSTYPE *yylval_param, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yylval = yylval_param; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yylval = yylval_param; } /* User-visible API */ /* hex_yylex_init is special because it creates the scanner itself, so it is - * the ONLY reentrant function that doesn't take the scanner as the last argument. - * That's why we explicitly handle the declaration, instead of using our macros. + * the ONLY reentrant function that doesn't take the scanner as the last + * argument. That's why we explicitly handle the declaration, instead of using + * our macros. */ -int hex_yylex_init(yyscan_t* ptr_yy_globals) +int hex_yylex_init(yyscan_t *ptr_yy_globals) { - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } + if (ptr_yy_globals == NULL) + { + errno = EINVAL; + return 1; + } - *ptr_yy_globals = (yyscan_t) hex_yyalloc ( sizeof( struct yyguts_t ), NULL ); + *ptr_yy_globals = (yyscan_t) hex_yyalloc(sizeof(struct yyguts_t), NULL); - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } + if (*ptr_yy_globals == NULL) + { + errno = ENOMEM; + return 1; + } - /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for + * releases. */ + memset(*ptr_yy_globals, 0x00, sizeof(struct yyguts_t)); - return yy_init_globals ( *ptr_yy_globals ); + return yy_init_globals(*ptr_yy_globals); } -/* hex_yylex_init_extra has the same functionality as hex_yylex_init, but follows the - * convention of taking the scanner as the last argument. Note however, that - * this is a *pointer* to a scanner, as it will be allocated by this call (and - * is the reason, too, why this function also must handle its own declaration). - * The user defined value in the first argument will be available to hex_yyalloc in - * the yyextra field. +/* hex_yylex_init_extra has the same functionality as hex_yylex_init, but + * follows the convention of taking the scanner as the last argument. Note + * however, that this is a *pointer* to a scanner, as it will be allocated by + * this call (and is the reason, too, why this function also must handle its own + * declaration). The user defined value in the first argument will be available + * to hex_yyalloc in the yyextra field. */ -int hex_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) +int hex_yylex_init_extra( + YY_EXTRA_TYPE yy_user_defined, + yyscan_t *ptr_yy_globals) { - struct yyguts_t dummy_yyguts; + struct yyguts_t dummy_yyguts; - hex_yyset_extra (yy_user_defined, &dummy_yyguts); + hex_yyset_extra(yy_user_defined, &dummy_yyguts); - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } - - *ptr_yy_globals = (yyscan_t) hex_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); - - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } - - /* By setting to 0xAA, we expose bugs in - yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); - - hex_yyset_extra (yy_user_defined, *ptr_yy_globals); - - return yy_init_globals ( *ptr_yy_globals ); -} + if (ptr_yy_globals == NULL) + { + errno = EINVAL; + return 1; + } -static int yy_init_globals (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from hex_yylex_destroy(), so don't allocate here. - */ + *ptr_yy_globals = (yyscan_t) hex_yyalloc( + sizeof(struct yyguts_t), &dummy_yyguts); - yyg->yy_buffer_stack = 0; - yyg->yy_buffer_stack_top = 0; - yyg->yy_buffer_stack_max = 0; - yyg->yy_c_buf_p = (char *) 0; - yyg->yy_init = 0; - yyg->yy_start = 0; + if (*ptr_yy_globals == NULL) + { + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals, 0x00, sizeof(struct yyguts_t)); + + hex_yyset_extra(yy_user_defined, *ptr_yy_globals); - yyg->yy_start_stack_ptr = 0; - yyg->yy_start_stack_depth = 0; - yyg->yy_start_stack = NULL; + return yy_init_globals(*ptr_yy_globals); +} + +static int yy_init_globals(yyscan_t yyscanner) +{ + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from hex_yylex_destroy(), so don't allocate here. + */ + + yyg->yy_buffer_stack = 0; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = (char *) 0; + yyg->yy_init = 0; + yyg->yy_start = 0; + + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; /* Defined in main.c */ #ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; + yyin = stdin; + yyout = stdout; #else - yyin = (FILE *) 0; - yyout = (FILE *) 0; + yyin = (FILE *) 0; + yyout = (FILE *) 0; #endif - /* For future reference: Set errno on error, since we are called by - * hex_yylex_init() - */ - return 0; + /* For future reference: Set errno on error, since we are called by + * hex_yylex_init() + */ + return 0; } /* hex_yylex_destroy is for both reentrant and non-reentrant scanners. */ -int hex_yylex_destroy (yyscan_t yyscanner) +int hex_yylex_destroy(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - hex_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner ); - YY_CURRENT_BUFFER_LVALUE = NULL; - hex_yypop_buffer_state(yyscanner); - } - - /* Destroy the stack itself. */ - hex_yyfree(yyg->yy_buffer_stack ,yyscanner); - yyg->yy_buffer_stack = NULL; - - /* Destroy the start condition stack. */ - hex_yyfree(yyg->yy_start_stack ,yyscanner ); - yyg->yy_start_stack = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * hex_yylex() is called, initialization will occur. */ - yy_init_globals( yyscanner); - - /* Destroy the main struct (reentrant only). */ - hex_yyfree ( yyscanner , yyscanner ); - yyscanner = NULL; - return 0; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + /* Pop the buffer stack, destroying each element. */ + while (YY_CURRENT_BUFFER) + { + hex_yy_delete_buffer(YY_CURRENT_BUFFER, yyscanner); + YY_CURRENT_BUFFER_LVALUE = NULL; + hex_yypop_buffer_state(yyscanner); + } + + /* Destroy the stack itself. */ + hex_yyfree(yyg->yy_buffer_stack, yyscanner); + yyg->yy_buffer_stack = NULL; + + /* Destroy the start condition stack. */ + hex_yyfree(yyg->yy_start_stack, yyscanner); + yyg->yy_start_stack = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next + * time hex_yylex() is called, initialization will occur. */ + yy_init_globals(yyscanner); + + /* Destroy the main struct (reentrant only). */ + hex_yyfree(yyscanner, yyscanner); + yyscanner = NULL; + return 0; } /* @@ -2145,55 +2139,58 @@ int hex_yylex_destroy (yyscan_t yyscanner) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) +static void yy_flex_strncpy( + char *s1, + yyconst char *s2, + int n, + yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; + int i; + for (i = 0; i < n; ++i) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) +static int yy_flex_strlen(yyconst char *s, yyscan_t yyscanner) { - int n; - for ( n = 0; s[n]; ++n ) - ; + int n; + for (n = 0; s[n]; ++n) + ; - return n; + return n; } #endif -void *hex_yyalloc (yy_size_t size , yyscan_t yyscanner) +void *hex_yyalloc(yy_size_t size, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - return (void *) malloc( size ); + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + return (void *) malloc(size); } -void *hex_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner) +void *hex_yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc((char *) ptr, size); } -void hex_yyfree (void * ptr , yyscan_t yyscanner) +void hex_yyfree(void *ptr, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - free( (char *) ptr ); /* see hex_yyrealloc() for (char *) cast */ + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + free((char *) ptr); /* see hex_yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" @@ -2201,18 +2198,15 @@ void hex_yyfree (void * ptr , yyscan_t yyscanner) #line 182 "hex_lexer.l" - // // yyfatal (actually named hex_yyfatal because of the '%option prefix="hex_yy"' // directive) is called when a fatal error occurs in the parser. When this // happens we are deep inside the parsing logic generated by flex/bison and // the only way to exit gracefully from there is using setjmp/longjmp. // -void yyfatal( - yyscan_t yyscanner, - const char *error_message) +void yyfatal(yyscan_t yyscanner, const char *error_message) { - jmp_buf* recovery_trampoline = (jmp_buf*) yr_thread_storage_get_value( + jmp_buf *recovery_trampoline = (jmp_buf *) yr_thread_storage_get_value( &yr_yyfatal_trampoline_tls); // Never returns. @@ -2221,7 +2215,7 @@ void yyfatal( void yyerror( yyscan_t yyscanner, - HEX_LEX_ENVIRONMENT* lex_env, + HEX_LEX_ENVIRONMENT *lex_env, const char *error_message) { // if lex_env->last_error was set to some error code before @@ -2242,9 +2236,9 @@ void yyerror( int yr_parse_hex_string( - const char* hex_string, - RE_AST** re_ast, - RE_ERROR* error) + const char *hex_string, + RE_AST **re_ast, + RE_ERROR *error) { yyscan_t yyscanner; jmp_buf recovery_trampoline; @@ -2253,9 +2247,7 @@ int yr_parse_hex_string( lex_env.last_error = ERROR_SUCCESS; lex_env.inside_or = 0; - yr_thread_storage_set_value( - &yr_yyfatal_trampoline_tls, - &recovery_trampoline); + yr_thread_storage_set_value(&yr_yyfatal_trampoline_tls, &recovery_trampoline); if (setjmp(recovery_trampoline) != 0) return ERROR_INTERNAL_FATAL_ERROR; @@ -2278,8 +2270,8 @@ int yr_parse_hex_string( (*re_ast)->flags |= RE_FLAGS_DOT_ALL; hex_yylex_init(&yyscanner); - hex_yyset_extra(*re_ast,yyscanner); - hex_yy_scan_string(hex_string,yyscanner); + hex_yyset_extra(*re_ast, yyscanner); + hex_yy_scan_string(hex_string, yyscanner); yyparse(yyscanner, &lex_env); hex_yylex_destroy(yyscanner); @@ -2291,4 +2283,3 @@ int yr_parse_hex_string( return ERROR_SUCCESS; } - diff --git a/libyara/include/yara.h b/libyara/include/yara.h index c52d25a8d2..812b51cd1a 100644 --- a/libyara/include/yara.h +++ b/libyara/include/yara.h @@ -30,16 +30,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef YR_YARA_H #define YR_YARA_H -#include "yara/utils.h" -#include "yara/filemap.h" #include "yara/compiler.h" -#include "yara/modules.h" -#include "yara/object.h" -#include "yara/libyara.h" #include "yara/error.h" -#include "yara/stream.h" +#include "yara/filemap.h" #include "yara/hash.h" -#include "yara/scanner.h" +#include "yara/libyara.h" #include "yara/mem.h" +#include "yara/modules.h" +#include "yara/object.h" +#include "yara/scanner.h" +#include "yara/stream.h" +#include "yara/utils.h" #endif diff --git a/libyara/include/yara/ahocorasick.h b/libyara/include/yara/ahocorasick.h index c409d97692..9620d2ee61 100644 --- a/libyara/include/yara/ahocorasick.h +++ b/libyara/include/yara/ahocorasick.h @@ -30,34 +30,31 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef _AHOCORASICK_H #define _AHOCORASICK_H -#include #include +#include #include // Number of bits dedicated to store the offset of the slot relative to its // own state. -#define YR_AC_SLOT_OFFSET_BITS 9 +#define YR_AC_SLOT_OFFSET_BITS 9 // Max number of slots in the transition table. This is the maximum number of // slots that can be addressed with 23-bit indexes. -#define YR_AC_MAX_TRANSITION_TABLE_SIZE 0x800000 +#define YR_AC_MAX_TRANSITION_TABLE_SIZE 0x800000 -#define YR_AC_ROOT_STATE 0 -#define YR_AC_NEXT_STATE(t) (t >> YR_AC_SLOT_OFFSET_BITS) -#define YR_AC_INVALID_TRANSITION(t, c) (((t) & 0x1FF) != c) +#define YR_AC_ROOT_STATE 0 +#define YR_AC_NEXT_STATE(t) (t >> YR_AC_SLOT_OFFSET_BITS) +#define YR_AC_INVALID_TRANSITION(t, c) (((t) &0x1FF) != c) #define YR_AC_MAKE_TRANSITION(state, code) \ - ((YR_AC_TRANSITION) \ - ((((YR_AC_TRANSITION) state) << YR_AC_SLOT_OFFSET_BITS) | (code))) + ((YR_AC_TRANSITION)( \ + (((YR_AC_TRANSITION) state) << YR_AC_SLOT_OFFSET_BITS) | (code))) -int yr_ac_automaton_create( - YR_ARENA* arena, - YR_AC_AUTOMATON** automaton); +int yr_ac_automaton_create(YR_ARENA* arena, YR_AC_AUTOMATON** automaton); -int yr_ac_automaton_destroy( - YR_AC_AUTOMATON* automaton); +int yr_ac_automaton_destroy(YR_AC_AUTOMATON* automaton); int yr_ac_add_string( @@ -68,12 +65,9 @@ int yr_ac_add_string( YR_ARENA* arena); -int yr_ac_compile( - YR_AC_AUTOMATON* automaton, - YR_ARENA* arena); +int yr_ac_compile(YR_AC_AUTOMATON* automaton, YR_ARENA* arena); -void yr_ac_print_automaton( - YR_AC_AUTOMATON* automaton); +void yr_ac_print_automaton(YR_AC_AUTOMATON* automaton); #endif diff --git a/libyara/include/yara/arena.h b/libyara/include/yara/arena.h index f66d249508..69e7bfd1cf 100644 --- a/libyara/include/yara/arena.h +++ b/libyara/include/yara/arena.h @@ -31,19 +31,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define YR_ARENA_H #include -#include #include +#include #include #define EOL ((uint32_t) -1) -#define YR_ARENA_FILE_VERSION 18 +#define YR_ARENA_FILE_VERSION 18 -#define YR_ARENA_NULL_REF \ - (YR_ARENA_REF){ UINT32_MAX, UINT32_MAX } +#define YR_ARENA_NULL_REF \ + (YR_ARENA_REF) { UINT32_MAX, UINT32_MAX } #define YR_ARENA_IS_NULL_REF(ref) \ - (memcmp(&(ref), &YR_ARENA_NULL_REF, sizeof(YR_ARENA_NULL_REF)) == 0) + (memcmp(&(ref), &YR_ARENA_NULL_REF, sizeof(YR_ARENA_NULL_REF)) == 0) typedef uint32_t yr_arena_off_t; @@ -140,8 +140,8 @@ in the structure are relocatable pointers. struct YR_ARENA { - // Number of users of this arena. This is set to one when the arena is created, - // and can be incremented by calling yr_arena_acquire. On each call + // Number of users of this arena. This is set to one when the arena is + // created, and can be incremented by calling yr_arena_acquire. On each call // to yr_arena_release it gets decremented by one, if xrefs reaches zero // the buffers and the YR_ARENA structures are freed. int xrefs; @@ -173,14 +173,12 @@ int yr_arena_create( // Takes ownership of the arena. -void yr_arena_acquire( - YR_ARENA* arena); +void yr_arena_acquire(YR_ARENA* arena); // Release ownership of the arena. If the number of owners drops to zero the // arena is destroyed and all its resources are freed. -int yr_arena_release( - YR_ARENA* arena); +int yr_arena_release(YR_ARENA* arena); // Given a reference to some data within the arena, it returns a pointer to @@ -189,9 +187,7 @@ int yr_arena_release( // yr_arena_allocate_xxx and yr_arena_write_xxx. These functions can cause // the buffer to be moved to different memory location and the pointer won't // valid any longer. -void* yr_arena_ref_to_ptr( - YR_ARENA* arena, - YR_ARENA_REF* ref); +void* yr_arena_ref_to_ptr(YR_ARENA* arena, YR_ARENA_REF* ref); // Given a pointer into the arena, it returns a reference to it. The reference @@ -213,9 +209,7 @@ void* yr_arena_get_ptr( yr_arena_off_t offset); -yr_arena_off_t yr_arena_get_current_offset( - YR_ARENA* arena, - uint32_t buffer_id); +yr_arena_off_t yr_arena_get_current_offset(YR_ARENA* arena, uint32_t buffer_id); int yr_arena_allocate_memory( @@ -240,10 +234,7 @@ int yr_arena_allocate_struct( ...); -int yr_arena_make_ptr_relocatable( - YR_ARENA* arena, - uint32_t buffer_id, - ...); +int yr_arena_make_ptr_relocatable(YR_ARENA* arena, uint32_t buffer_id, ...); int yr_arena_write_data( @@ -268,13 +259,9 @@ int yr_arena_write_uint32( YR_ARENA_REF* ref); -int yr_arena_load_stream( - YR_STREAM* stream, - YR_ARENA** arena); +int yr_arena_load_stream(YR_STREAM* stream, YR_ARENA** arena); -int yr_arena_save_stream( - YR_ARENA* arena, - YR_STREAM* stream); +int yr_arena_save_stream(YR_ARENA* arena, YR_STREAM* stream); -#endif // YR_ARENA_H +#endif // YR_ARENA_H diff --git a/libyara/include/yara/atoms.h b/libyara/include/yara/atoms.h index 1cb3d8d0fb..f82d2ac4c5 100644 --- a/libyara/include/yara/atoms.h +++ b/libyara/include/yara/atoms.h @@ -33,9 +33,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#define ATOM_TREE_LEAF 1 -#define ATOM_TREE_AND 2 -#define ATOM_TREE_OR 3 +#define ATOM_TREE_LEAF 1 +#define ATOM_TREE_AND 2 +#define ATOM_TREE_OR 3 typedef struct YR_ATOM YR_ATOM; typedef struct YR_ATOM_TREE_NODE YR_ATOM_TREE_NODE; @@ -100,9 +100,7 @@ struct YR_ATOM_QUALITY_TABLE_ENTRY #pragma pack(pop) -typedef int (*YR_ATOMS_QUALITY_FUNC)( - YR_ATOMS_CONFIG* config, - YR_ATOM* atom); +typedef int (*YR_ATOMS_QUALITY_FUNC)(YR_ATOMS_CONFIG* config, YR_ATOM* atom); struct YR_ATOMS_CONFIG @@ -133,27 +131,18 @@ int yr_atoms_extract_from_string( int* min_atom_quality); -int yr_atoms_extract_triplets( - RE_NODE* re_node, - YR_ATOM_LIST_ITEM** atoms); +int yr_atoms_extract_triplets(RE_NODE* re_node, YR_ATOM_LIST_ITEM** atoms); -int yr_atoms_heuristic_quality( - YR_ATOMS_CONFIG* config, - YR_ATOM* atom); +int yr_atoms_heuristic_quality(YR_ATOMS_CONFIG* config, YR_ATOM* atom); -int yr_atoms_table_quality( - YR_ATOMS_CONFIG* config, - YR_ATOM* atom); +int yr_atoms_table_quality(YR_ATOMS_CONFIG* config, YR_ATOM* atom); -int yr_atoms_min_quality( - YR_ATOMS_CONFIG* config, - YR_ATOM_LIST_ITEM* atom_list); +int yr_atoms_min_quality(YR_ATOMS_CONFIG* config, YR_ATOM_LIST_ITEM* atom_list); -void yr_atoms_list_destroy( - YR_ATOM_LIST_ITEM* list_head); +void yr_atoms_list_destroy(YR_ATOM_LIST_ITEM* list_head); #endif diff --git a/libyara/include/yara/base64.h b/libyara/include/yara/base64.h index 6c02a64a42..7ebb2991f1 100644 --- a/libyara/include/yara/base64.h +++ b/libyara/include/yara/base64.h @@ -30,18 +30,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef YR_BASE64_H #define YR_BASE64_H -#include #include #include +#include typedef struct BASE64_NODE BASE64_NODE; -struct BASE64_NODE { - +struct BASE64_NODE +{ SIZED_STRING* str; int escaped; BASE64_NODE* next; - }; int yr_base64_ast_from_string( diff --git a/libyara/include/yara/bitmask.h b/libyara/include/yara/bitmask.h index 92fd3fbca0..5e8d0eb41e 100644 --- a/libyara/include/yara/bitmask.h +++ b/libyara/include/yara/bitmask.h @@ -53,40 +53,41 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define YR_BITMASK unsigned long -#define YR_BITMASK_SLOT_BITS (sizeof(YR_BITMASK) * 8) -#define YR_BITMASK_SIZE(n) (((n) / (YR_BITMASK_SLOT_BITS)) + 1) +#define YR_BITMASK_SLOT_BITS (sizeof(YR_BITMASK) * 8) +#define YR_BITMASK_SIZE(n) (((n) / (YR_BITMASK_SLOT_BITS)) + 1) -#define yr_bitmask_set(bm, i) \ - do { \ +#define yr_bitmask_set(bm, i) \ + do \ + { \ (bm)[(i) / YR_BITMASK_SLOT_BITS] |= 1UL << ((i) % YR_BITMASK_SLOT_BITS); \ - } while(0) + } while (0) -#define yr_bitmask_clear(bm, i) \ - do { \ - (bm)[(i) / YR_BITMASK_SLOT_BITS] &= ~(1UL << ((i) % YR_BITMASK_SLOT_BITS)); \ - } while(0) +#define yr_bitmask_clear(bm, i) \ + do \ + { \ + (bm)[(i) / YR_BITMASK_SLOT_BITS] &= \ + ~(1UL << ((i) % YR_BITMASK_SLOT_BITS)); \ + } while (0) -#define yr_bitmask_clear_all(bm) \ - memset(bm, 0, sizeof(bm)) +#define yr_bitmask_clear_all(bm) memset(bm, 0, sizeof(bm)) #define yr_bitmask_is_set(bm, i) \ - ( \ - (bm)[(i) / YR_BITMASK_SLOT_BITS] & (1UL << ((i) % YR_BITMASK_SLOT_BITS)) \ - ) + ((bm)[(i) / YR_BITMASK_SLOT_BITS] & (1UL << ((i) % YR_BITMASK_SLOT_BITS))) #define yr_bitmask_is_not_set(bm, i) (!yr_bitmask_is_set(bm, i)) -#define yr_bitmask_print(bm) \ - { \ - int i; \ - for (i = 0; i < sizeof(bm) / sizeof(bm[0]); i++) { \ - printf("%016lX\n", bm[i]); \ - } \ +#define yr_bitmask_print(bm) \ + { \ + int i; \ + for (i = 0; i < sizeof(bm) / sizeof(bm[0]); i++) \ + { \ + printf("%016lX\n", bm[i]); \ + } \ } diff --git a/libyara/include/yara/compiler.h b/libyara/include/yara/compiler.h index c7d9e55d7d..38aa5b2f24 100644 --- a/libyara/include/yara/compiler.h +++ b/libyara/include/yara/compiler.h @@ -30,14 +30,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef YR_COMPILER_H #define YR_COMPILER_H -#include #include - +#include #include #include +#include #include #include -#include #define YARA_ERROR_LEVEL_ERROR 0 @@ -45,47 +44,48 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Expression type constants are powers of two because they are used as flags. -#define EXPRESSION_TYPE_UNKNOWN 0 -#define EXPRESSION_TYPE_BOOLEAN 1 -#define EXPRESSION_TYPE_INTEGER 2 -#define EXPRESSION_TYPE_STRING 4 -#define EXPRESSION_TYPE_REGEXP 8 -#define EXPRESSION_TYPE_OBJECT 16 -#define EXPRESSION_TYPE_FLOAT 32 +#define EXPRESSION_TYPE_UNKNOWN 0 +#define EXPRESSION_TYPE_BOOLEAN 1 +#define EXPRESSION_TYPE_INTEGER 2 +#define EXPRESSION_TYPE_STRING 4 +#define EXPRESSION_TYPE_REGEXP 8 +#define EXPRESSION_TYPE_OBJECT 16 +#define EXPRESSION_TYPE_FLOAT 32 // The compiler uses an arena to store the data it generates during the // compilation. Each buffer in the arena is used for storing a different type // of data. The following identifiers indicate the purpose of each buffer. -#define YR_NAMESPACES_TABLE 0 -#define YR_RULES_TABLE 1 -#define YR_METAS_TABLE 2 -#define YR_STRINGS_TABLE 3 -#define YR_EXTERNAL_VARIABLES_TABLE 4 -#define YR_SZ_POOL 5 -#define YR_CODE_SECTION 6 -#define YR_RE_CODE_SECTION 7 -#define YR_AC_TRANSITION_TABLE 8 -#define YR_AC_STATE_MATCHES_TABLE 9 -#define YR_AC_STATE_MATCHES_POOL 10 -#define YR_SUMMARY_SECTION 11 +#define YR_NAMESPACES_TABLE 0 +#define YR_RULES_TABLE 1 +#define YR_METAS_TABLE 2 +#define YR_STRINGS_TABLE 3 +#define YR_EXTERNAL_VARIABLES_TABLE 4 +#define YR_SZ_POOL 5 +#define YR_CODE_SECTION 6 +#define YR_RE_CODE_SECTION 7 +#define YR_AC_TRANSITION_TABLE 8 +#define YR_AC_STATE_MATCHES_TABLE 9 +#define YR_AC_STATE_MATCHES_POOL 10 +#define YR_SUMMARY_SECTION 11 // This is the number of buffers used by the compiler, should match the number // of items in the list above. -#define YR_NUM_SECTIONS 12 +#define YR_NUM_SECTIONS 12 // Number of variables used by loops. This doesn't include user defined // variables. -#define YR_INTERNAL_LOOP_VARS 3 +#define YR_INTERNAL_LOOP_VARS 3 typedef struct _YR_EXPRESSION { int type; - union { + union + { int64_t integer; YR_OBJECT* object; YR_ARENA_REF sized_string_ref; @@ -96,10 +96,11 @@ typedef struct _YR_EXPRESSION // to the identifier within YR_SZ_POOL. When the identifier is in YR_SZ_POOL // a pointer can't be used as the YR_SZ_POOL can be moved to a different // memory location. - struct { + struct + { const char* ptr; YR_ARENA_REF ref; - } identifier ; + } identifier; } YR_EXPRESSION; @@ -154,13 +155,13 @@ typedef struct _YR_LOOP_CONTEXT // vars_count is the number of local variables defined by the loop, and vars // is an array of expressions with the identifier and type for each of those // local variables. - int vars_count; - YR_EXPRESSION vars[YR_MAX_LOOP_VARS]; + int vars_count; + YR_EXPRESSION vars[YR_MAX_LOOP_VARS]; // vars_internal_count is the number of variables used by the loop which are // not defined by the rule itself but that are necessary for keeping the // loop's state. One example is the iteration counter. - int vars_internal_count; + int vars_internal_count; } YR_LOOP_CONTEXT; @@ -229,83 +230,80 @@ typedef struct _YR_COMPILER // Pointer to a YR_RULES structure that represents the compiled rules. This // is what yr_compiler_get_rules returns. Once these rules are generated you // can't call any of the yr_compiler_add_xxx functions. - YR_RULES* rules; + YR_RULES* rules; - int errors; - int current_line; - int last_error; - int last_error_line; + int errors; + int current_line; + int last_error; + int last_error_line; - jmp_buf error_recovery; + jmp_buf error_recovery; - YR_AC_AUTOMATON* automaton; - YR_HASH_TABLE* rules_table; - YR_HASH_TABLE* objects_table; - YR_HASH_TABLE* strings_table; + YR_AC_AUTOMATON* automaton; + YR_HASH_TABLE* rules_table; + YR_HASH_TABLE* objects_table; + YR_HASH_TABLE* strings_table; // Hash table that contains all the strings that has been written to the // YR_SZ_POOL buffer in the compiler's arena. Values in the hash table are // the offset within the YR_SZ_POOL where the string resides. This allows to // know is some string has already been written in order to reuse instead of // writting it again. - YR_HASH_TABLE* sz_table; + YR_HASH_TABLE* sz_table; - YR_FIXUP* fixup_stack_head; + YR_FIXUP* fixup_stack_head; - int num_namespaces; + int num_namespaces; - YR_LOOP_CONTEXT loop[YR_MAX_LOOP_NESTING]; - int loop_index; - int loop_for_of_var_index; + YR_LOOP_CONTEXT loop[YR_MAX_LOOP_NESTING]; + int loop_index; + int loop_for_of_var_index; - char* file_name_stack[YR_MAX_INCLUDE_DEPTH]; - int file_name_stack_ptr; + char* file_name_stack[YR_MAX_INCLUDE_DEPTH]; + int file_name_stack_ptr; - char last_error_extra_info[YR_MAX_COMPILER_ERROR_EXTRA_INFO]; + char last_error_extra_info[YR_MAX_COMPILER_ERROR_EXTRA_INFO]; - char lex_buf[YR_LEX_BUF_SIZE]; - char* lex_buf_ptr; - unsigned short lex_buf_len; + char lex_buf[YR_LEX_BUF_SIZE]; + char* lex_buf_ptr; + unsigned short lex_buf_len; - char include_base_dir[MAX_PATH]; - void* user_data; - void* incl_clbk_user_data; - void* re_ast_clbk_user_data; + char include_base_dir[MAX_PATH]; + void* user_data; + void* incl_clbk_user_data; + void* re_ast_clbk_user_data; - YR_COMPILER_CALLBACK_FUNC callback; - YR_COMPILER_INCLUDE_CALLBACK_FUNC include_callback; - YR_COMPILER_INCLUDE_FREE_FUNC include_free; - YR_COMPILER_RE_AST_CALLBACK_FUNC re_ast_callback; - YR_ATOMS_CONFIG atoms_config; + YR_COMPILER_CALLBACK_FUNC callback; + YR_COMPILER_INCLUDE_CALLBACK_FUNC include_callback; + YR_COMPILER_INCLUDE_FREE_FUNC include_free; + YR_COMPILER_RE_AST_CALLBACK_FUNC re_ast_callback; + YR_ATOMS_CONFIG atoms_config; } YR_COMPILER; #define yr_compiler_set_error_extra_info(compiler, info) \ - strlcpy( \ - compiler->last_error_extra_info, \ - info, \ - sizeof(compiler->last_error_extra_info)); \ + strlcpy( \ + compiler->last_error_extra_info, \ + info, \ + sizeof(compiler->last_error_extra_info)); #define yr_compiler_set_error_extra_info_fmt(compiler, fmt, ...) \ - snprintf( \ - compiler->last_error_extra_info, \ - sizeof(compiler->last_error_extra_info), \ - fmt, __VA_ARGS__); + snprintf( \ + compiler->last_error_extra_info, \ + sizeof(compiler->last_error_extra_info), \ + fmt, \ + __VA_ARGS__); -int _yr_compiler_push_file_name( - YR_COMPILER* compiler, - const char* file_name); +int _yr_compiler_push_file_name(YR_COMPILER* compiler, const char* file_name); -void _yr_compiler_pop_file_name( - YR_COMPILER* compiler); +void _yr_compiler_pop_file_name(YR_COMPILER* compiler); -int _yr_compiler_get_var_frame( - YR_COMPILER* compiler); +int _yr_compiler_get_var_frame(YR_COMPILER* compiler); const char* _yr_compiler_default_include_callback( @@ -315,8 +313,7 @@ const char* _yr_compiler_default_include_callback( void* user_data); -YR_RULE* _yr_compiler_get_rule_by_idx( - YR_COMPILER* compiler, uint32_t rule_idx); +YR_RULE* _yr_compiler_get_rule_by_idx(YR_COMPILER* compiler, uint32_t rule_idx); int _yr_compiler_store_string( @@ -332,12 +329,10 @@ int _yr_compiler_store_data( YR_ARENA_REF* ref); -YR_API int yr_compiler_create( - YR_COMPILER** compiler); +YR_API int yr_compiler_create(YR_COMPILER** compiler); -YR_API void yr_compiler_destroy( - YR_COMPILER* compiler); +YR_API void yr_compiler_destroy(YR_COMPILER* compiler); YR_API void yr_compiler_set_callback( @@ -398,8 +393,7 @@ YR_API char* yr_compiler_get_error_message( int buffer_size); -YR_API char* yr_compiler_get_current_file_name( - YR_COMPILER* compiler); +YR_API char* yr_compiler_get_current_file_name(YR_COMPILER* compiler); YR_API int yr_compiler_define_integer_variable( @@ -426,9 +420,7 @@ YR_API int yr_compiler_define_string_variable( const char* value); -YR_API int yr_compiler_get_rules( - YR_COMPILER* compiler, - YR_RULES** rules); +YR_API int yr_compiler_get_rules(YR_COMPILER* compiler, YR_RULES** rules); #endif diff --git a/libyara/include/yara/dex.h b/libyara/include/yara/dex.h index bbb7b4c940..035e7b252e 100644 --- a/libyara/include/yara/dex.h +++ b/libyara/include/yara/dex.h @@ -2,7 +2,6 @@ #define _DEX_H #include - #include #include @@ -12,123 +11,134 @@ #define DEX_FILE_MAGIC_038 "dex\n038\x00" #define DEX_FILE_MAGIC_039 "dex\n039\x00" -#pragma pack(push,1) +#pragma pack(push, 1) typedef struct { - uint8_t magic[8]; - uint32_t checksum; - uint8_t signature[20]; - uint32_t file_size; - uint32_t header_size; - uint32_t endian_tag; - uint32_t link_size; - uint32_t link_offset; - uint32_t map_offset; - uint32_t string_ids_size; - uint32_t string_ids_offset; - uint32_t type_ids_size; - uint32_t type_ids_offset; - uint32_t proto_ids_size; - uint32_t proto_ids_offset; - uint32_t field_ids_size; - uint32_t field_ids_offset; - uint32_t method_ids_size; - uint32_t method_ids_offset; - uint32_t class_defs_size; - uint32_t class_defs_offset; - uint32_t data_size; - uint32_t data_offset; + uint8_t magic[8]; + uint32_t checksum; + uint8_t signature[20]; + uint32_t file_size; + uint32_t header_size; + uint32_t endian_tag; + uint32_t link_size; + uint32_t link_offset; + uint32_t map_offset; + uint32_t string_ids_size; + uint32_t string_ids_offset; + uint32_t type_ids_size; + uint32_t type_ids_offset; + uint32_t proto_ids_size; + uint32_t proto_ids_offset; + uint32_t field_ids_size; + uint32_t field_ids_offset; + uint32_t method_ids_size; + uint32_t method_ids_offset; + uint32_t class_defs_size; + uint32_t class_defs_offset; + uint32_t data_size; + uint32_t data_offset; } dex_header_t; -typedef struct { - uint32_t string_data_offset; +typedef struct +{ + uint32_t string_data_offset; } string_id_item_t; -typedef struct { - uint32_t utf16_size; +typedef struct +{ + uint32_t utf16_size; } string_data_item_t; -typedef struct { - uint32_t descriptor_idx; +typedef struct +{ + uint32_t descriptor_idx; } type_id_item_t; -typedef struct { - uint32_t shorty_idx; - uint32_t return_type_idx; - uint32_t parameters_offset; +typedef struct +{ + uint32_t shorty_idx; + uint32_t return_type_idx; + uint32_t parameters_offset; } proto_id_item_t; -typedef struct { - uint16_t class_idx; - uint16_t type_idx; - uint32_t name_idx; +typedef struct +{ + uint16_t class_idx; + uint16_t type_idx; + uint32_t name_idx; } field_id_item_t; -typedef struct { - uint16_t class_idx; - uint16_t proto_idx; - uint32_t name_idx; +typedef struct +{ + uint16_t class_idx; + uint16_t proto_idx; + uint32_t name_idx; } method_id_item_t; -typedef struct { - uint32_t class_idx; - uint32_t access_flags; - uint32_t super_class_idx; - uint32_t interfaces_offset; - uint32_t source_file_idx; - uint32_t annotations_offset; - uint32_t class_data_offset; - uint32_t static_values_offset; +typedef struct +{ + uint32_t class_idx; + uint32_t access_flags; + uint32_t super_class_idx; + uint32_t interfaces_offset; + uint32_t source_file_idx; + uint32_t annotations_offset; + uint32_t class_data_offset; + uint32_t static_values_offset; } class_id_item_t; -typedef struct { - uint32_t static_fields_size; - uint32_t instance_fields_size; - uint32_t direct_methods_size; - uint32_t virtual_methods_size; +typedef struct +{ + uint32_t static_fields_size; + uint32_t instance_fields_size; + uint32_t direct_methods_size; + uint32_t virtual_methods_size; } class_data_item_t; -typedef struct { - uint32_t field_idx_diff; - uint32_t access_flags; +typedef struct +{ + uint32_t field_idx_diff; + uint32_t access_flags; } encoded_field_t; -typedef struct { - uint32_t method_idx_diff; - uint32_t access_flags; - uint32_t code_off; +typedef struct +{ + uint32_t method_idx_diff; + uint32_t access_flags; + uint32_t code_off; } encoded_method_t; -typedef struct { - uint16_t registers_size; - uint16_t ins_size; - uint16_t outs_size; - uint16_t tries_size; - uint32_t debug_info_off; - uint32_t insns_size; +typedef struct +{ + uint16_t registers_size; + uint16_t ins_size; + uint16_t outs_size; + uint16_t tries_size; + uint32_t debug_info_off; + uint32_t insns_size; } code_item_t; -typedef struct { - uint16_t type; - uint16_t unused; - uint32_t size; - uint32_t offset; +typedef struct +{ + uint16_t type; + uint16_t unused; + uint32_t size; + uint32_t offset; } map_item_t; typedef struct _DEX { const uint8_t* data; size_t data_size; - dex_header_t *header; + dex_header_t* header; YR_OBJECT* object; } DEX; -#define fits_in_dex(dex, pointer, size) \ - ((size_t) size <= dex->data_size && \ - (uint8_t*) (pointer) >= dex->data && \ +#define fits_in_dex(dex, pointer, size) \ + ((size_t) size <= dex->data_size && (uint8_t*) (pointer) >= dex->data && \ (uint8_t*) (pointer) <= dex->data + dex->data_size - size) #define struct_fits_in_dex(dex, pointer, struct_type) \ @@ -136,4 +146,4 @@ typedef struct _DEX #pragma pack(pop) -#endif \ No newline at end of file +#endif diff --git a/libyara/include/yara/dotnet.h b/libyara/include/yara/dotnet.h index 15f03c2103..9061c51297 100644 --- a/libyara/include/yara/dotnet.h +++ b/libyara/include/yara/dotnet.h @@ -1,25 +1,28 @@ #ifndef YR_DOTNET_H #define YR_DOTNET_H +#include + #pragma pack(push, 1) // // CLI header. // ECMA-335 Section II.25.3.3 // -typedef struct _CLI_HEADER { - DWORD Size; // Called "Cb" in documentation. - WORD MajorRuntimeVersion; - WORD MinorRuntimeVersion; - IMAGE_DATA_DIRECTORY MetaData; - DWORD Flags; - DWORD EntryPointToken; - IMAGE_DATA_DIRECTORY Resources; - IMAGE_DATA_DIRECTORY StrongNameSignature; - ULONGLONG CodeManagerTable; - IMAGE_DATA_DIRECTORY VTableFixups; - ULONGLONG ExportAddressTableJumps; - ULONGLONG ManagedNativeHeader; +typedef struct _CLI_HEADER +{ + DWORD Size; // Called "Cb" in documentation. + WORD MajorRuntimeVersion; + WORD MinorRuntimeVersion; + IMAGE_DATA_DIRECTORY MetaData; + DWORD Flags; + DWORD EntryPointToken; + IMAGE_DATA_DIRECTORY Resources; + IMAGE_DATA_DIRECTORY StrongNameSignature; + ULONGLONG CodeManagerTable; + IMAGE_DATA_DIRECTORY VTableFixups; + ULONGLONG ExportAddressTableJumps; + ULONGLONG ManagedNativeHeader; } CLI_HEADER, *PCLI_HEADER; #define NET_METADATA_MAGIC 0x424a5342 @@ -30,13 +33,14 @@ typedef struct _CLI_HEADER { // // Note: This is only part of the struct, as the rest of it is variable length. // -typedef struct _NET_METADATA { - DWORD Magic; - WORD MajorVersion; - WORD MinorVersion; - DWORD Reserved; - DWORD Length; - char Version[0]; +typedef struct _NET_METADATA +{ + DWORD Magic; + WORD MajorVersion; + WORD MinorVersion; + DWORD Reserved; + DWORD Length; + char Version[0]; } NET_METADATA, *PNET_METADATA; #define DOTNET_STREAM_NAME_SIZE 32 @@ -45,10 +49,11 @@ typedef struct _NET_METADATA { // CLI Stream Header // ECMA-335 Section II.24.2.2 // -typedef struct _STREAM_HEADER { - DWORD Offset; - DWORD Size; - char Name[0]; +typedef struct _STREAM_HEADER +{ + DWORD Offset; + DWORD Size; + char Name[0]; } STREAM_HEADER, *PSTREAM_HEADER; @@ -56,63 +61,64 @@ typedef struct _STREAM_HEADER { // CLI #~ Stream Header // ECMA-335 Section II.24.2.6 // -typedef struct _TILDE_HEADER { - DWORD Reserved1; - BYTE MajorVersion; - BYTE MinorVersion; - BYTE HeapSizes; - BYTE Reserved2; - ULONGLONG Valid; - ULONGLONG Sorted; +typedef struct _TILDE_HEADER +{ + DWORD Reserved1; + BYTE MajorVersion; + BYTE MinorVersion; + BYTE HeapSizes; + BYTE Reserved2; + ULONGLONG Valid; + ULONGLONG Sorted; } TILDE_HEADER, *PTILDE_HEADER; // These are the bit positions in Valid which will be set if the table // exists. -#define BIT_MODULE 0x00 -#define BIT_TYPEREF 0x01 -#define BIT_TYPEDEF 0x02 -#define BIT_FIELDPTR 0x03 // Not documented in ECMA-335 -#define BIT_FIELD 0x04 -#define BIT_METHODDEFPTR 0x05 // Not documented in ECMA-335 -#define BIT_METHODDEF 0x06 -#define BIT_PARAMPTR 0x07 // Not documented in ECMA-335 -#define BIT_PARAM 0x08 -#define BIT_INTERFACEIMPL 0x09 -#define BIT_MEMBERREF 0x0A -#define BIT_CONSTANT 0x0B -#define BIT_CUSTOMATTRIBUTE 0x0C -#define BIT_FIELDMARSHAL 0x0D -#define BIT_DECLSECURITY 0x0E -#define BIT_CLASSLAYOUT 0x0F -#define BIT_FIELDLAYOUT 0x10 -#define BIT_STANDALONESIG 0x11 -#define BIT_EVENTMAP 0x12 -#define BIT_EVENTPTR 0x13 // Not documented in ECMA-335 -#define BIT_EVENT 0x14 -#define BIT_PROPERTYMAP 0x15 -#define BIT_PROPERTYPTR 0x16 // Not documented in ECMA-335 -#define BIT_PROPERTY 0x17 -#define BIT_METHODSEMANTICS 0x18 -#define BIT_METHODIMPL 0x19 -#define BIT_MODULEREF 0x1A -#define BIT_TYPESPEC 0x1B -#define BIT_IMPLMAP 0x1C -#define BIT_FIELDRVA 0x1D -#define BIT_ENCLOG 0x1E // Not documented in ECMA-335 -#define BIT_ENCMAP 0x1F // Not documented in ECMA-335 -#define BIT_ASSEMBLY 0x20 -#define BIT_ASSEMBLYPROCESSOR 0x21 -#define BIT_ASSEMBLYOS 0x22 -#define BIT_ASSEMBLYREF 0x23 -#define BIT_ASSEMBLYREFPROCESSOR 0x24 -#define BIT_ASSEMBLYREFOS 0x25 -#define BIT_FILE 0x26 -#define BIT_EXPORTEDTYPE 0x27 -#define BIT_MANIFESTRESOURCE 0x28 -#define BIT_NESTEDCLASS 0x29 -#define BIT_GENERICPARAM 0x2A -#define BIT_METHODSPEC 0x2B -#define BIT_GENERICPARAMCONSTRAINT 0x2C +#define BIT_MODULE 0x00 +#define BIT_TYPEREF 0x01 +#define BIT_TYPEDEF 0x02 +#define BIT_FIELDPTR 0x03 // Not documented in ECMA-335 +#define BIT_FIELD 0x04 +#define BIT_METHODDEFPTR 0x05 // Not documented in ECMA-335 +#define BIT_METHODDEF 0x06 +#define BIT_PARAMPTR 0x07 // Not documented in ECMA-335 +#define BIT_PARAM 0x08 +#define BIT_INTERFACEIMPL 0x09 +#define BIT_MEMBERREF 0x0A +#define BIT_CONSTANT 0x0B +#define BIT_CUSTOMATTRIBUTE 0x0C +#define BIT_FIELDMARSHAL 0x0D +#define BIT_DECLSECURITY 0x0E +#define BIT_CLASSLAYOUT 0x0F +#define BIT_FIELDLAYOUT 0x10 +#define BIT_STANDALONESIG 0x11 +#define BIT_EVENTMAP 0x12 +#define BIT_EVENTPTR 0x13 // Not documented in ECMA-335 +#define BIT_EVENT 0x14 +#define BIT_PROPERTYMAP 0x15 +#define BIT_PROPERTYPTR 0x16 // Not documented in ECMA-335 +#define BIT_PROPERTY 0x17 +#define BIT_METHODSEMANTICS 0x18 +#define BIT_METHODIMPL 0x19 +#define BIT_MODULEREF 0x1A +#define BIT_TYPESPEC 0x1B +#define BIT_IMPLMAP 0x1C +#define BIT_FIELDRVA 0x1D +#define BIT_ENCLOG 0x1E // Not documented in ECMA-335 +#define BIT_ENCMAP 0x1F // Not documented in ECMA-335 +#define BIT_ASSEMBLY 0x20 +#define BIT_ASSEMBLYPROCESSOR 0x21 +#define BIT_ASSEMBLYOS 0x22 +#define BIT_ASSEMBLYREF 0x23 +#define BIT_ASSEMBLYREFPROCESSOR 0x24 +#define BIT_ASSEMBLYREFOS 0x25 +#define BIT_FILE 0x26 +#define BIT_EXPORTEDTYPE 0x27 +#define BIT_MANIFESTRESOURCE 0x28 +#define BIT_NESTEDCLASS 0x29 +#define BIT_GENERICPARAM 0x2A +#define BIT_METHODSPEC 0x2B +#define BIT_GENERICPARAMCONSTRAINT 0x2C // These are not documented in ECMA-335 nor is it clear what the format is. // They are for debugging information as far as I can tell. //#define BIT_DOCUMENT 0x30 @@ -139,45 +145,53 @@ typedef struct _TILDE_HEADER { // Module table // ECMA-335 Section II.22.30 // -typedef struct _MODULE_TABLE { - WORD Generation; - union { - WORD Name_Short; - DWORD Name_Long; - } Name; - union { - WORD Mvid_Short; - DWORD Mvid_Long; - } Mvid; - union { - WORD EncId_Short; - DWORD EncId_Long; - } EncId; - union { - WORD EncBaseId_Short; - DWORD EncBaseId_Long; - } EncBaseId; +typedef struct _MODULE_TABLE +{ + WORD Generation; + union + { + WORD Name_Short; + DWORD Name_Long; + } Name; + union + { + WORD Mvid_Short; + DWORD Mvid_Long; + } Mvid; + union + { + WORD EncId_Short; + DWORD EncId_Long; + } EncId; + union + { + WORD EncBaseId_Short; + DWORD EncBaseId_Long; + } EncBaseId; } MODULE_TABLE, *PMODULE_TABLE; // // Assembly Table // ECMA-335 Section II.22.2 // -typedef struct _ASSEMBLY_TABLE { - DWORD HashAlgId; - WORD MajorVersion; - WORD MinorVersion; - WORD BuildNumber; - WORD RevisionNumber; - DWORD Flags; - union { - WORD PublicKey_Short; - DWORD PublicKey_Long; - } PublicKey; - union { - WORD Name_Short; - DWORD Name_Long; - } Name; +typedef struct _ASSEMBLY_TABLE +{ + DWORD HashAlgId; + WORD MajorVersion; + WORD MinorVersion; + WORD BuildNumber; + WORD RevisionNumber; + DWORD Flags; + union + { + WORD PublicKey_Short; + DWORD PublicKey_Long; + } PublicKey; + union + { + WORD Name_Short; + DWORD Name_Long; + } Name; } ASSEMBLY_TABLE, *PASSEMBLY_TABLE; @@ -185,20 +199,23 @@ typedef struct _ASSEMBLY_TABLE { // Assembly Reference Table // ECMA-335 Section II.22.5 // -typedef struct _ASSEMBLYREF_TABLE { - WORD MajorVersion; - WORD MinorVersion; - WORD BuildNumber; - WORD RevisionNumber; - DWORD Flags; - union { - WORD PublicKeyOrToken_Short; - DWORD PublicKeyOrToken_Long; - } PublicKeyOrToken; - union { - WORD Name_Short; - DWORD Name_Long; - } Name; +typedef struct _ASSEMBLYREF_TABLE +{ + WORD MajorVersion; + WORD MinorVersion; + WORD BuildNumber; + WORD RevisionNumber; + DWORD Flags; + union + { + WORD PublicKeyOrToken_Short; + DWORD PublicKeyOrToken_Long; + } PublicKeyOrToken; + union + { + WORD Name_Short; + DWORD Name_Long; + } Name; } ASSEMBLYREF_TABLE, *PASSEMBLYREF_TABLE; @@ -206,17 +223,20 @@ typedef struct _ASSEMBLYREF_TABLE { // Manifest Resource Table // ECMA-335 Section II.22.24 // -typedef struct _MANIFESTRESOURCE_TABLE { - DWORD Offset; - DWORD Flags; - union { - WORD Name_Short; - DWORD Name_Long; - } Name; - union { - WORD Implementation_Short; - DWORD Implementation_Long; - } Implementation; +typedef struct _MANIFESTRESOURCE_TABLE +{ + DWORD Offset; + DWORD Flags; + union + { + WORD Name_Short; + DWORD Name_Long; + } Name; + union + { + WORD Implementation_Short; + DWORD Implementation_Long; + } Implementation; } MANIFESTRESOURCE_TABLE, *PMANIFESTRESOURCE_TABLE; // @@ -225,10 +245,12 @@ typedef struct _MANIFESTRESOURCE_TABLE { // // This is a short table, but necessary because the field size can change. // -typedef struct _MODULEREF_TABLE { - union { - WORD Name_Short; - DWORD Name_Long; +typedef struct _MODULEREF_TABLE +{ + union + { + WORD Name_Short; + DWORD Name_Long; } Name; } MODULEREF_TABLE, *PMODULEREF_TABLE; @@ -236,28 +258,34 @@ typedef struct _MODULEREF_TABLE { // FieldRVA Table // ECMA-335 Section II.22.18 // -typedef struct _FIELDRVA_TABLE { - DWORD RVA; - union { - WORD Field_Short; - DWORD Field_LONG; - } Field; +typedef struct _FIELDRVA_TABLE +{ + DWORD RVA; + union + { + WORD Field_Short; + DWORD Field_LONG; + } Field; } FIELDRVA_TABLE, *PFIELDRVA_TABLE; // // CustomAttribute Table // ECMA-335 Section II.22.10 // -typedef struct _CUSTOMATTRIBUTE_TABLE { - union { +typedef struct _CUSTOMATTRIBUTE_TABLE +{ + union + { WORD Parent_Short; DWORD Parent_Long; } Parent; - union { + union + { WORD Type_Short; DWORD Type_Long; } Type; - union { + union + { WORD Value_Short; DWORD Value_Long; } Value; @@ -268,13 +296,16 @@ typedef struct _CUSTOMATTRIBUTE_TABLE { // Constant TAble // ECMA-335 Section II.22.9 // -typedef struct _CONSTANT_TABLE { +typedef struct _CONSTANT_TABLE +{ WORD Type; - union { + union + { WORD Parent_Short; DWORD Parent_Long; } Parent; - union { + union + { WORD Value_Short; DWORD Value_Long; } Value; @@ -282,66 +313,70 @@ typedef struct _CONSTANT_TABLE { // Used to return offsets to the various headers. -typedef struct _STREAMS { - PSTREAM_HEADER guid; - PSTREAM_HEADER tilde; - PSTREAM_HEADER string; - PSTREAM_HEADER blob; - PSTREAM_HEADER us; +typedef struct _STREAMS +{ + PSTREAM_HEADER guid; + PSTREAM_HEADER tilde; + PSTREAM_HEADER string; + PSTREAM_HEADER blob; + PSTREAM_HEADER us; } STREAMS, *PSTREAMS; // Used to return the value of parsing a #US or #Blob entry. // ECMA-335 Section II.24.2.4 -typedef struct _BLOB_PARSE_RESULT { - uint8_t size; // Number of bytes parsed. This is the new offset. - DWORD length; // Value of the bytes parsed. This is the blob length. +typedef struct _BLOB_PARSE_RESULT +{ + uint8_t size; // Number of bytes parsed. This is the new offset. + DWORD length; // Value of the bytes parsed. This is the blob length. } BLOB_PARSE_RESULT, *PBLOB_PARSE_RESULT; // Used to store the number of rows of each table. -typedef struct _ROWS { - uint32_t module; - uint32_t moduleref; - uint32_t assemblyref; - uint32_t typeref; - uint32_t methoddef; - uint32_t memberref; - uint32_t typedef_; - uint32_t typespec; - uint32_t field; - uint32_t param; - uint32_t property; - uint32_t interfaceimpl; - uint32_t event; - uint32_t standalonesig; - uint32_t assembly; - uint32_t file; - uint32_t exportedtype; - uint32_t manifestresource; - uint32_t genericparam; - uint32_t genericparamconstraint; - uint32_t methodspec; - uint32_t assemblyrefprocessor; +typedef struct _ROWS +{ + uint32_t module; + uint32_t moduleref; + uint32_t assemblyref; + uint32_t typeref; + uint32_t methoddef; + uint32_t memberref; + uint32_t typedef_; + uint32_t typespec; + uint32_t field; + uint32_t param; + uint32_t property; + uint32_t interfaceimpl; + uint32_t event; + uint32_t standalonesig; + uint32_t assembly; + uint32_t file; + uint32_t exportedtype; + uint32_t manifestresource; + uint32_t genericparam; + uint32_t genericparamconstraint; + uint32_t methodspec; + uint32_t assemblyrefprocessor; } ROWS, *PROWS; // Used to store the index sizes for the various tables. -typedef struct _INDEX_SIZES { - uint8_t string; - uint8_t guid; - uint8_t blob; - uint8_t field; - uint8_t methoddef; - uint8_t memberref; - uint8_t param; - uint8_t event; - uint8_t typedef_; - uint8_t property; - uint8_t moduleref; - uint8_t assemblyrefprocessor; - uint8_t assemblyref; - uint8_t genericparam; +typedef struct _INDEX_SIZES +{ + uint8_t string; + uint8_t guid; + uint8_t blob; + uint8_t field; + uint8_t methoddef; + uint8_t memberref; + uint8_t param; + uint8_t event; + uint8_t typedef_; + uint8_t property; + uint8_t moduleref; + uint8_t assemblyrefprocessor; + uint8_t assemblyref; + uint8_t genericparam; } INDEX_SIZES, *PINDEX_SIZES; #pragma pack(pop) diff --git a/libyara/include/yara/elf.h b/libyara/include/yara/elf.h index 1ff2b8c0ae..227b533cb6 100644 --- a/libyara/include/yara/elf.h +++ b/libyara/include/yara/elf.h @@ -48,123 +48,123 @@ typedef uint64_t elf64_off_t; typedef uint32_t elf64_word_t; typedef uint64_t elf64_xword_t; -#define ELF_MAGIC 0x464C457F - -#define ELF_ET_NONE 0x0000 // no type -#define ELF_ET_REL 0x0001 // relocatable -#define ELF_ET_EXEC 0x0002 // executable -#define ELF_ET_DYN 0x0003 // Shared-Object-File -#define ELF_ET_CORE 0x0004 // Corefile -#define ELF_ET_LOPROC 0xFF00 // Processor-specific -#define ELF_ET_HIPROC 0x00FF // Processor-specific - -#define ELF_EM_NONE 0x0000 // no type -#define ELF_EM_M32 0x0001 // AT&T WE 32100 -#define ELF_EM_SPARC 0x0002 // SPARC -#define ELF_EM_386 0x0003 // Intel 80386 -#define ELF_EM_68K 0x0004 // Motorola 68000 -#define ELF_EM_88K 0x0005 // Motorola 88000 -#define ELF_EM_860 0x0007 // Intel 80860 -#define ELF_EM_MIPS 0x0008 // MIPS I Architecture -#define ELF_EM_MIPS_RS3_LE 0x000A // MIPS RS3000 Little-endian -#define ELF_EM_PPC 0x0014 // PowerPC -#define ELF_EM_PPC64 0x0015 // 64-bit PowerPC -#define ELF_EM_ARM 0x0028 // ARM -#define ELF_EM_X86_64 0x003E // AMD/Intel x86_64 -#define ELF_EM_AARCH64 0x00B7 // 64-bit ARM - -#define ELF_CLASS_NONE 0x0000 -#define ELF_CLASS_32 0x0001 // 32bit file -#define ELF_CLASS_64 0x0002 // 64bit file - -#define ELF_DATA_NONE 0x0000 -#define ELF_DATA_2LSB 0x0001 -#define ELF_DATA_2MSB 0x002 - - -#define ELF_SHT_NULL 0 // Section header table entry unused -#define ELF_SHT_PROGBITS 1 // Program data -#define ELF_SHT_SYMTAB 2 // Symbol table -#define ELF_SHT_STRTAB 3 // String table -#define ELF_SHT_RELA 4 // Relocation entries with addends -#define ELF_SHT_HASH 5 // Symbol hash table -#define ELF_SHT_DYNAMIC 6 // Dynamic linking information -#define ELF_SHT_NOTE 7 // Notes -#define ELF_SHT_NOBITS 8 // Program space with no data (bss) -#define ELF_SHT_REL 9 // Relocation entries, no addends -#define ELF_SHT_SHLIB 10 // Reserved -#define ELF_SHT_DYNSYM 11 // Dynamic linker symbol table -#define ELF_SHT_NUM 12 // Number of defined types - -#define ELF_SHF_WRITE 0x1 // Section is writable -#define ELF_SHF_ALLOC 0x2 // Section is present during execution -#define ELF_SHF_EXECINSTR 0x4 // Section contains executable instructions - -#define ELF_SHN_LORESERVE 0xFF00 - -#define ELF_PT_NULL 0 // The array element is unused -#define ELF_PT_LOAD 1 // Loadable segment -#define ELF_PT_DYNAMIC 2 // Segment contains dynamic linking info -#define ELF_PT_INTERP 3 // Contains interpreter pathname -#define ELF_PT_NOTE 4 // Location & size of auxiliary info -#define ELF_PT_SHLIB 5 // Reserved, unspecified semantics -#define ELF_PT_PHDR 6 // Location and size of program header table -#define ELF_PT_TLS 7 // Thread-Local Storage -#define ELF_PT_GNU_EH_FRAME 0x6474e550 -#define ELF_PT_GNU_STACK 0x6474e551 - -#define ELF_DT_NULL 0 // End of the dynamic entries -#define ELF_DT_NEEDED 1 // Name of needed library -#define ELF_DT_PLTRELSZ 2 // Size in bytes of PLT relocs -#define ELF_DT_PLTGOT 3 // Processor defined value */ -#define ELF_DT_HASH 4 // Address of symbol hash table -#define ELF_DT_STRTAB 5 // Address of string table -#define ELF_DT_SYMTAB 6 // Address of symbol table -#define ELF_DT_RELA 7 // Address of Rela relocs -#define ELF_DT_RELASZ 8 // Total size of Rela relocs -#define ELF_DT_RELAENT 9 // Size of one Rela reloc -#define ELF_DT_STRSZ 10 // Size of string table -#define ELF_DT_SYMENT 11 // Size of one symbol table entry -#define ELF_DT_INIT 12 // Address of init function -#define ELF_DT_FINI 13 // Address of termination function -#define ELF_DT_SONAME 14 // Name of shared object -#define ELF_DT_RPATH 15 // Library search path (deprecated) -#define ELF_DT_SYMBOLIC 16 // Start symbol search here -#define ELF_DT_REL 17 // Address of Rel relocs -#define ELF_DT_RELSZ 18 // Total size of Rel relocs -#define ELF_DT_RELENT 19 // Size of one Rel reloc -#define ELF_DT_PLTREL 20 // Type of reloc in PLT -#define ELF_DT_DEBUG 21 // For debugging; unspecified -#define ELF_DT_TEXTREL 22 // Reloc might modify .text -#define ELF_DT_JMPREL 23 // Address of PLT relocs -#define ELF_DT_BIND_NOW 24 // Process relocations of object -#define ELF_DT_INIT_ARRAY 25 // Array with addresses of init fct -#define ELF_DT_FINI_ARRAY 26 // Array with addresses of fini fct -#define ELF_DT_INIT_ARRAYSZ 27 // Size in bytes of DT_INIT_ARRAY -#define ELF_DT_FINI_ARRAYSZ 28 // Size in bytes of DT_FINI_ARRAY -#define ELF_DT_RUNPATH 29 // Library search path -#define ELF_DT_FLAGS 30 // Flags for the object being loaded -#define ELF_DT_ENCODING 32 // Start of encoded range - -#define ELF_STT_NOTYPE 0 // Symbol type is unspecified -#define ELF_STT_OBJECT 1 // Symbol is a data object -#define ELF_STT_FUNC 2 // Symbol is a code object -#define ELF_STT_SECTION 3 // Symbol associated with a section -#define ELF_STT_FILE 4 // Symbol's name is file name -#define ELF_STT_COMMON 5 // Symbol is a common data object -#define ELF_STT_TLS 6 // Symbol is thread-local data object - -#define ELF_STB_LOCAL 0 // Local symbol -#define ELF_STB_GLOBAL 1 // Global symbol -#define ELF_STB_WEAK 2 // Weak symbol - -#define ELF_PF_X 0x1 // Segment is executable -#define ELF_PF_W 0x2 // Segment is writable -#define ELF_PF_R 0x4 // Segment is readable - -#define ELF_PN_XNUM 0xffff - -#pragma pack(push,1) +#define ELF_MAGIC 0x464C457F + +#define ELF_ET_NONE 0x0000 // no type +#define ELF_ET_REL 0x0001 // relocatable +#define ELF_ET_EXEC 0x0002 // executable +#define ELF_ET_DYN 0x0003 // Shared-Object-File +#define ELF_ET_CORE 0x0004 // Corefile +#define ELF_ET_LOPROC 0xFF00 // Processor-specific +#define ELF_ET_HIPROC 0x00FF // Processor-specific + +#define ELF_EM_NONE 0x0000 // no type +#define ELF_EM_M32 0x0001 // AT&T WE 32100 +#define ELF_EM_SPARC 0x0002 // SPARC +#define ELF_EM_386 0x0003 // Intel 80386 +#define ELF_EM_68K 0x0004 // Motorola 68000 +#define ELF_EM_88K 0x0005 // Motorola 88000 +#define ELF_EM_860 0x0007 // Intel 80860 +#define ELF_EM_MIPS 0x0008 // MIPS I Architecture +#define ELF_EM_MIPS_RS3_LE 0x000A // MIPS RS3000 Little-endian +#define ELF_EM_PPC 0x0014 // PowerPC +#define ELF_EM_PPC64 0x0015 // 64-bit PowerPC +#define ELF_EM_ARM 0x0028 // ARM +#define ELF_EM_X86_64 0x003E // AMD/Intel x86_64 +#define ELF_EM_AARCH64 0x00B7 // 64-bit ARM + +#define ELF_CLASS_NONE 0x0000 +#define ELF_CLASS_32 0x0001 // 32bit file +#define ELF_CLASS_64 0x0002 // 64bit file + +#define ELF_DATA_NONE 0x0000 +#define ELF_DATA_2LSB 0x0001 +#define ELF_DATA_2MSB 0x002 + + +#define ELF_SHT_NULL 0 // Section header table entry unused +#define ELF_SHT_PROGBITS 1 // Program data +#define ELF_SHT_SYMTAB 2 // Symbol table +#define ELF_SHT_STRTAB 3 // String table +#define ELF_SHT_RELA 4 // Relocation entries with addends +#define ELF_SHT_HASH 5 // Symbol hash table +#define ELF_SHT_DYNAMIC 6 // Dynamic linking information +#define ELF_SHT_NOTE 7 // Notes +#define ELF_SHT_NOBITS 8 // Program space with no data (bss) +#define ELF_SHT_REL 9 // Relocation entries, no addends +#define ELF_SHT_SHLIB 10 // Reserved +#define ELF_SHT_DYNSYM 11 // Dynamic linker symbol table +#define ELF_SHT_NUM 12 // Number of defined types + +#define ELF_SHF_WRITE 0x1 // Section is writable +#define ELF_SHF_ALLOC 0x2 // Section is present during execution +#define ELF_SHF_EXECINSTR 0x4 // Section contains executable instructions + +#define ELF_SHN_LORESERVE 0xFF00 + +#define ELF_PT_NULL 0 // The array element is unused +#define ELF_PT_LOAD 1 // Loadable segment +#define ELF_PT_DYNAMIC 2 // Segment contains dynamic linking info +#define ELF_PT_INTERP 3 // Contains interpreter pathname +#define ELF_PT_NOTE 4 // Location & size of auxiliary info +#define ELF_PT_SHLIB 5 // Reserved, unspecified semantics +#define ELF_PT_PHDR 6 // Location and size of program header table +#define ELF_PT_TLS 7 // Thread-Local Storage +#define ELF_PT_GNU_EH_FRAME 0x6474e550 +#define ELF_PT_GNU_STACK 0x6474e551 + +#define ELF_DT_NULL 0 // End of the dynamic entries +#define ELF_DT_NEEDED 1 // Name of needed library +#define ELF_DT_PLTRELSZ 2 // Size in bytes of PLT relocs +#define ELF_DT_PLTGOT 3 // Processor defined value */ +#define ELF_DT_HASH 4 // Address of symbol hash table +#define ELF_DT_STRTAB 5 // Address of string table +#define ELF_DT_SYMTAB 6 // Address of symbol table +#define ELF_DT_RELA 7 // Address of Rela relocs +#define ELF_DT_RELASZ 8 // Total size of Rela relocs +#define ELF_DT_RELAENT 9 // Size of one Rela reloc +#define ELF_DT_STRSZ 10 // Size of string table +#define ELF_DT_SYMENT 11 // Size of one symbol table entry +#define ELF_DT_INIT 12 // Address of init function +#define ELF_DT_FINI 13 // Address of termination function +#define ELF_DT_SONAME 14 // Name of shared object +#define ELF_DT_RPATH 15 // Library search path (deprecated) +#define ELF_DT_SYMBOLIC 16 // Start symbol search here +#define ELF_DT_REL 17 // Address of Rel relocs +#define ELF_DT_RELSZ 18 // Total size of Rel relocs +#define ELF_DT_RELENT 19 // Size of one Rel reloc +#define ELF_DT_PLTREL 20 // Type of reloc in PLT +#define ELF_DT_DEBUG 21 // For debugging; unspecified +#define ELF_DT_TEXTREL 22 // Reloc might modify .text +#define ELF_DT_JMPREL 23 // Address of PLT relocs +#define ELF_DT_BIND_NOW 24 // Process relocations of object +#define ELF_DT_INIT_ARRAY 25 // Array with addresses of init fct +#define ELF_DT_FINI_ARRAY 26 // Array with addresses of fini fct +#define ELF_DT_INIT_ARRAYSZ 27 // Size in bytes of DT_INIT_ARRAY +#define ELF_DT_FINI_ARRAYSZ 28 // Size in bytes of DT_FINI_ARRAY +#define ELF_DT_RUNPATH 29 // Library search path +#define ELF_DT_FLAGS 30 // Flags for the object being loaded +#define ELF_DT_ENCODING 32 // Start of encoded range + +#define ELF_STT_NOTYPE 0 // Symbol type is unspecified +#define ELF_STT_OBJECT 1 // Symbol is a data object +#define ELF_STT_FUNC 2 // Symbol is a code object +#define ELF_STT_SECTION 3 // Symbol associated with a section +#define ELF_STT_FILE 4 // Symbol's name is file name +#define ELF_STT_COMMON 5 // Symbol is a common data object +#define ELF_STT_TLS 6 // Symbol is thread-local data object + +#define ELF_STB_LOCAL 0 // Local symbol +#define ELF_STB_GLOBAL 1 // Global symbol +#define ELF_STB_WEAK 2 // Weak symbol + +#define ELF_PF_X 0x1 // Segment is executable +#define ELF_PF_W 0x2 // Segment is writable +#define ELF_PF_R 0x4 // Segment is readable + +#define ELF_PN_XNUM 0xffff + +#pragma pack(push, 1) typedef struct { @@ -180,140 +180,140 @@ typedef struct typedef struct { - elf_ident_t ident; - elf32_half_t type; - elf32_half_t machine; - elf32_word_t version; - elf32_addr_t entry; - elf32_off_t ph_offset; - elf32_off_t sh_offset; - elf32_word_t flags; - elf32_half_t header_size; - elf32_half_t ph_entry_size; - elf32_half_t ph_entry_count; - elf32_half_t sh_entry_size; - elf32_half_t sh_entry_count; - elf32_half_t sh_str_table_index; + elf_ident_t ident; + elf32_half_t type; + elf32_half_t machine; + elf32_word_t version; + elf32_addr_t entry; + elf32_off_t ph_offset; + elf32_off_t sh_offset; + elf32_word_t flags; + elf32_half_t header_size; + elf32_half_t ph_entry_size; + elf32_half_t ph_entry_count; + elf32_half_t sh_entry_size; + elf32_half_t sh_entry_count; + elf32_half_t sh_str_table_index; } elf32_header_t; typedef struct { - elf_ident_t ident; - elf64_half_t type; - elf64_half_t machine; - elf64_word_t version; - elf64_addr_t entry; - elf64_off_t ph_offset; - elf64_off_t sh_offset; - elf64_word_t flags; - elf64_half_t header_size; - elf64_half_t ph_entry_size; - elf64_half_t ph_entry_count; - elf64_half_t sh_entry_size; - elf64_half_t sh_entry_count; - elf64_half_t sh_str_table_index; + elf_ident_t ident; + elf64_half_t type; + elf64_half_t machine; + elf64_word_t version; + elf64_addr_t entry; + elf64_off_t ph_offset; + elf64_off_t sh_offset; + elf64_word_t flags; + elf64_half_t header_size; + elf64_half_t ph_entry_size; + elf64_half_t ph_entry_count; + elf64_half_t sh_entry_size; + elf64_half_t sh_entry_count; + elf64_half_t sh_str_table_index; } elf64_header_t; typedef struct { - elf32_word_t type; - elf32_off_t offset; - elf32_addr_t virt_addr; - elf32_addr_t phys_addr; - elf32_word_t file_size; - elf32_word_t mem_size; - elf32_word_t flags; - elf32_word_t alignment; + elf32_word_t type; + elf32_off_t offset; + elf32_addr_t virt_addr; + elf32_addr_t phys_addr; + elf32_word_t file_size; + elf32_word_t mem_size; + elf32_word_t flags; + elf32_word_t alignment; } elf32_program_header_t; typedef struct { - elf64_word_t type; - elf64_word_t flags; - elf64_off_t offset; - elf64_addr_t virt_addr; - elf64_addr_t phys_addr; - elf64_xword_t file_size; - elf64_xword_t mem_size; - elf64_xword_t alignment; + elf64_word_t type; + elf64_word_t flags; + elf64_off_t offset; + elf64_addr_t virt_addr; + elf64_addr_t phys_addr; + elf64_xword_t file_size; + elf64_xword_t mem_size; + elf64_xword_t alignment; } elf64_program_header_t; typedef struct { - elf32_word_t name; - elf32_word_t type; - elf32_word_t flags; - elf32_addr_t addr; - elf32_off_t offset; - elf32_word_t size; - elf32_word_t link; - elf32_word_t info; - elf32_word_t align; - elf32_word_t entry_size; + elf32_word_t name; + elf32_word_t type; + elf32_word_t flags; + elf32_addr_t addr; + elf32_off_t offset; + elf32_word_t size; + elf32_word_t link; + elf32_word_t info; + elf32_word_t align; + elf32_word_t entry_size; } elf32_section_header_t; typedef struct { - elf64_word_t name; - elf64_word_t type; - elf64_xword_t flags; - elf64_addr_t addr; - elf64_off_t offset; - elf64_xword_t size; - elf64_word_t link; - elf64_word_t info; - elf64_xword_t align; - elf64_xword_t entry_size; + elf64_word_t name; + elf64_word_t type; + elf64_xword_t flags; + elf64_addr_t addr; + elf64_off_t offset; + elf64_xword_t size; + elf64_word_t link; + elf64_word_t info; + elf64_xword_t align; + elf64_xword_t entry_size; } elf64_section_header_t; typedef struct { - elf32_word_t tag; - elf32_word_t val; + elf32_word_t tag; + elf32_word_t val; } elf32_dyn_t; typedef struct { - elf64_xword_t tag; - elf64_xword_t val; + elf64_xword_t tag; + elf64_xword_t val; } elf64_dyn_t; typedef struct { - elf32_word_t name; - elf32_addr_t value; - elf32_word_t size; - unsigned char info; - unsigned char other; - elf32_half_t shndx; + elf32_word_t name; + elf32_addr_t value; + elf32_word_t size; + unsigned char info; + unsigned char other; + elf32_half_t shndx; } elf32_sym_t; typedef struct { - elf32_word_t name; - unsigned char info; - unsigned char other; - elf32_half_t shndx; - elf64_addr_t value; - elf64_xword_t size; + elf32_word_t name; + unsigned char info; + unsigned char other; + elf32_half_t shndx; + elf64_addr_t value; + elf64_xword_t size; } elf64_sym_t; diff --git a/libyara/include/yara/endian.h b/libyara/include/yara/endian.h index 42c76a1e8f..0fd6e6bd2a 100644 --- a/libyara/include/yara/endian.h +++ b/libyara/include/yara/endian.h @@ -34,29 +34,29 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(__has_builtin) -# if __has_builtin(__builtin_bswap16) -# define yr_bswap16(x) __builtin_bswap16(x) -# endif +#if __has_builtin(__builtin_bswap16) +#define yr_bswap16(x) __builtin_bswap16(x) +#endif #endif #if !defined(yr_bswap16) && defined(_MSC_VER) -# define yr_bswap16(x) _byteswap_ushort(x) +#define yr_bswap16(x) _byteswap_ushort(x) #endif #if !defined(yr_bswap16) uint16_t _yr_bswap16(uint16_t x); -# define yr_bswap16(x) _yr_bswap16(x) +#define yr_bswap16(x) _yr_bswap16(x) #endif #if defined(__has_builtin) -# if __has_builtin(__builtin_bswap32) -# define yr_bswap32(x) __builtin_bswap32(x) -# endif +#if __has_builtin(__builtin_bswap32) +#define yr_bswap32(x) __builtin_bswap32(x) +#endif #endif #if !defined(yr_bswap32) && defined(_MSC_VER) -# define yr_bswap32(x) _byteswap_ulong(x) +#define yr_bswap32(x) _byteswap_ulong(x) #endif #if !defined(yr_bswap32) @@ -66,13 +66,13 @@ uint32_t _yr_bswap32(uint32_t x); #if defined(__has_builtin) -# if __has_builtin(__builtin_bswap64) -# define yr_bswap64(x) __builtin_bswap64(x) -# endif +#if __has_builtin(__builtin_bswap64) +#define yr_bswap64(x) __builtin_bswap64(x) +#endif #endif #if !defined(yr_bswap64) && defined(_MSC_VER) -# define yr_bswap64(x) _byteswap_uint64(x) +#define yr_bswap64(x) _byteswap_uint64(x) #endif #if !defined(yr_bswap64) diff --git a/libyara/include/yara/error.h b/libyara/include/yara/error.h index a79be26a31..ed511edfc6 100644 --- a/libyara/include/yara/error.h +++ b/libyara/include/yara/error.h @@ -37,104 +37,110 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif #ifndef ERROR_SUCCESS -#define ERROR_SUCCESS 0 +#define ERROR_SUCCESS 0 #endif // ERROR_INSUFICIENT_MEMORY is misspelled but it's kept for backward // compatibility, as some other programs can be using it in this form. -#define ERROR_INSUFICIENT_MEMORY 1 - -#define ERROR_INSUFFICIENT_MEMORY 1 -#define ERROR_COULD_NOT_ATTACH_TO_PROCESS 2 -#define ERROR_COULD_NOT_OPEN_FILE 3 -#define ERROR_COULD_NOT_MAP_FILE 4 -#define ERROR_INVALID_FILE 6 -#define ERROR_CORRUPT_FILE 7 -#define ERROR_UNSUPPORTED_FILE_VERSION 8 -#define ERROR_INVALID_REGULAR_EXPRESSION 9 -#define ERROR_INVALID_HEX_STRING 10 -#define ERROR_SYNTAX_ERROR 11 -#define ERROR_LOOP_NESTING_LIMIT_EXCEEDED 12 -#define ERROR_DUPLICATED_LOOP_IDENTIFIER 13 -#define ERROR_DUPLICATED_IDENTIFIER 14 -#define ERROR_DUPLICATED_TAG_IDENTIFIER 15 -#define ERROR_DUPLICATED_META_IDENTIFIER 16 -#define ERROR_DUPLICATED_STRING_IDENTIFIER 17 -#define ERROR_UNREFERENCED_STRING 18 -#define ERROR_UNDEFINED_STRING 19 -#define ERROR_UNDEFINED_IDENTIFIER 20 -#define ERROR_MISPLACED_ANONYMOUS_STRING 21 -#define ERROR_INCLUDES_CIRCULAR_REFERENCE 22 -#define ERROR_INCLUDE_DEPTH_EXCEEDED 23 -#define ERROR_WRONG_TYPE 24 -#define ERROR_EXEC_STACK_OVERFLOW 25 -#define ERROR_SCAN_TIMEOUT 26 -#define ERROR_TOO_MANY_SCAN_THREADS 27 -#define ERROR_CALLBACK_ERROR 28 -#define ERROR_INVALID_ARGUMENT 29 -#define ERROR_TOO_MANY_MATCHES 30 -#define ERROR_INTERNAL_FATAL_ERROR 31 -#define ERROR_NESTED_FOR_OF_LOOP 32 -#define ERROR_INVALID_FIELD_NAME 33 -#define ERROR_UNKNOWN_MODULE 34 -#define ERROR_NOT_A_STRUCTURE 35 -#define ERROR_NOT_INDEXABLE 36 -#define ERROR_NOT_A_FUNCTION 37 -#define ERROR_INVALID_FORMAT 38 -#define ERROR_TOO_MANY_ARGUMENTS 39 -#define ERROR_WRONG_ARGUMENTS 40 -#define ERROR_WRONG_RETURN_TYPE 41 -#define ERROR_DUPLICATED_STRUCTURE_MEMBER 42 -#define ERROR_EMPTY_STRING 43 -#define ERROR_DIVISION_BY_ZERO 44 -#define ERROR_REGULAR_EXPRESSION_TOO_LARGE 45 -#define ERROR_TOO_MANY_RE_FIBERS 46 -#define ERROR_COULD_NOT_READ_PROCESS_MEMORY 47 -#define ERROR_INVALID_EXTERNAL_VARIABLE_TYPE 48 -#define ERROR_REGULAR_EXPRESSION_TOO_COMPLEX 49 -#define ERROR_INVALID_MODULE_NAME 50 -#define ERROR_TOO_MANY_STRINGS 51 -#define ERROR_INTEGER_OVERFLOW 52 -#define ERROR_CALLBACK_REQUIRED 53 -#define ERROR_INVALID_OPERAND 54 -#define ERROR_COULD_NOT_READ_FILE 55 -#define ERROR_DUPLICATED_EXTERNAL_VARIABLE 56 -#define ERROR_INVALID_MODULE_DATA 57 -#define ERROR_WRITING_FILE 58 -#define ERROR_INVALID_MODIFIER 59 -#define ERROR_DUPLICATED_MODIFIER 60 - - -#define FAIL_ON_ERROR(x) { \ - int result = (x); \ - if (result != ERROR_SUCCESS) \ - return result; \ -} - -#define FAIL_ON_ERROR_WITH_CLEANUP(x, cleanup) { \ - int result = (x); \ - if (result != ERROR_SUCCESS) { \ - cleanup; \ - return result; \ - } \ -} - -#define FAIL_ON_NULL_WITH_CLEANUP(x, cleanup) { \ - if ((x) == NULL) { \ - cleanup; \ - return ERROR_INSUFFICIENT_MEMORY; \ - } \ -} +#define ERROR_INSUFICIENT_MEMORY 1 + +#define ERROR_INSUFFICIENT_MEMORY 1 +#define ERROR_COULD_NOT_ATTACH_TO_PROCESS 2 +#define ERROR_COULD_NOT_OPEN_FILE 3 +#define ERROR_COULD_NOT_MAP_FILE 4 +#define ERROR_INVALID_FILE 6 +#define ERROR_CORRUPT_FILE 7 +#define ERROR_UNSUPPORTED_FILE_VERSION 8 +#define ERROR_INVALID_REGULAR_EXPRESSION 9 +#define ERROR_INVALID_HEX_STRING 10 +#define ERROR_SYNTAX_ERROR 11 +#define ERROR_LOOP_NESTING_LIMIT_EXCEEDED 12 +#define ERROR_DUPLICATED_LOOP_IDENTIFIER 13 +#define ERROR_DUPLICATED_IDENTIFIER 14 +#define ERROR_DUPLICATED_TAG_IDENTIFIER 15 +#define ERROR_DUPLICATED_META_IDENTIFIER 16 +#define ERROR_DUPLICATED_STRING_IDENTIFIER 17 +#define ERROR_UNREFERENCED_STRING 18 +#define ERROR_UNDEFINED_STRING 19 +#define ERROR_UNDEFINED_IDENTIFIER 20 +#define ERROR_MISPLACED_ANONYMOUS_STRING 21 +#define ERROR_INCLUDES_CIRCULAR_REFERENCE 22 +#define ERROR_INCLUDE_DEPTH_EXCEEDED 23 +#define ERROR_WRONG_TYPE 24 +#define ERROR_EXEC_STACK_OVERFLOW 25 +#define ERROR_SCAN_TIMEOUT 26 +#define ERROR_TOO_MANY_SCAN_THREADS 27 +#define ERROR_CALLBACK_ERROR 28 +#define ERROR_INVALID_ARGUMENT 29 +#define ERROR_TOO_MANY_MATCHES 30 +#define ERROR_INTERNAL_FATAL_ERROR 31 +#define ERROR_NESTED_FOR_OF_LOOP 32 +#define ERROR_INVALID_FIELD_NAME 33 +#define ERROR_UNKNOWN_MODULE 34 +#define ERROR_NOT_A_STRUCTURE 35 +#define ERROR_NOT_INDEXABLE 36 +#define ERROR_NOT_A_FUNCTION 37 +#define ERROR_INVALID_FORMAT 38 +#define ERROR_TOO_MANY_ARGUMENTS 39 +#define ERROR_WRONG_ARGUMENTS 40 +#define ERROR_WRONG_RETURN_TYPE 41 +#define ERROR_DUPLICATED_STRUCTURE_MEMBER 42 +#define ERROR_EMPTY_STRING 43 +#define ERROR_DIVISION_BY_ZERO 44 +#define ERROR_REGULAR_EXPRESSION_TOO_LARGE 45 +#define ERROR_TOO_MANY_RE_FIBERS 46 +#define ERROR_COULD_NOT_READ_PROCESS_MEMORY 47 +#define ERROR_INVALID_EXTERNAL_VARIABLE_TYPE 48 +#define ERROR_REGULAR_EXPRESSION_TOO_COMPLEX 49 +#define ERROR_INVALID_MODULE_NAME 50 +#define ERROR_TOO_MANY_STRINGS 51 +#define ERROR_INTEGER_OVERFLOW 52 +#define ERROR_CALLBACK_REQUIRED 53 +#define ERROR_INVALID_OPERAND 54 +#define ERROR_COULD_NOT_READ_FILE 55 +#define ERROR_DUPLICATED_EXTERNAL_VARIABLE 56 +#define ERROR_INVALID_MODULE_DATA 57 +#define ERROR_WRITING_FILE 58 +#define ERROR_INVALID_MODIFIER 59 +#define ERROR_DUPLICATED_MODIFIER 60 + + +#define FAIL_ON_ERROR(x) \ + { \ + int result = (x); \ + if (result != ERROR_SUCCESS) \ + return result; \ + } + +#define FAIL_ON_ERROR_WITH_CLEANUP(x, cleanup) \ + { \ + int result = (x); \ + if (result != ERROR_SUCCESS) \ + { \ + cleanup; \ + return result; \ + } \ + } + +#define FAIL_ON_NULL_WITH_CLEANUP(x, cleanup) \ + { \ + if ((x) == NULL) \ + { \ + cleanup; \ + return ERROR_INSUFFICIENT_MEMORY; \ + } \ + } #ifdef NDEBUG -#define assertf(expr, msg, ...) ((void)0) +#define assertf(expr, msg, ...) ((void) 0) #else -#define assertf(expr, msg, ...) \ - if(!(expr)) { \ - fprintf(stderr, "%s:%d: " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__); \ - abort(); \ - } +#define assertf(expr, msg, ...) \ + if (!(expr)) \ + { \ + fprintf(stderr, "%s:%d: " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__); \ + abort(); \ + } #endif #endif diff --git a/libyara/include/yara/exec.h b/libyara/include/yara/exec.h index 17863a1feb..00160b649f 100644 --- a/libyara/include/yara/exec.h +++ b/libyara/include/yara/exec.h @@ -31,166 +31,165 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define YR_EXEC_H #include +#include #include #include -#include -#define YR_UNDEFINED 0xFFFABADAFABADAFFLL -#define IS_UNDEFINED(x) ((size_t)(x) == (size_t) YR_UNDEFINED) - -#define OP_ERROR 0 -#define OP_HALT 255 -#define OP_NOP 254 - -#define OP_AND 1 -#define OP_OR 2 -#define OP_NOT 3 -#define OP_BITWISE_NOT 4 -#define OP_BITWISE_AND 5 -#define OP_BITWISE_OR 6 -#define OP_BITWISE_XOR 7 -#define OP_SHL 8 -#define OP_SHR 9 -#define OP_MOD 10 -#define OP_INT_TO_DBL 11 -#define OP_STR_TO_BOOL 12 -#define OP_PUSH 13 -#define OP_POP 14 -#define OP_CALL 15 -#define OP_OBJ_LOAD 16 -#define OP_OBJ_VALUE 17 -#define OP_OBJ_FIELD 18 -#define OP_INDEX_ARRAY 19 -#define OP_COUNT 20 -#define OP_LENGTH 21 -#define OP_FOUND 22 -#define OP_FOUND_AT 23 -#define OP_FOUND_IN 24 -#define OP_OFFSET 25 -#define OP_OF 26 -#define OP_PUSH_RULE 27 -#define OP_INIT_RULE 28 -#define OP_MATCH_RULE 29 -#define OP_INCR_M 30 -#define OP_CLEAR_M 31 -#define OP_ADD_M 32 -#define OP_POP_M 33 -#define OP_PUSH_M 34 -#define OP_SET_M 35 -#define OP_SWAPUNDEF 36 -#define OP_FILESIZE 37 -#define OP_ENTRYPOINT 38 -// Unused opcode 39 -#define OP_MATCHES 40 -#define OP_IMPORT 41 -#define OP_LOOKUP_DICT 42 -#define OP_JUNDEF 43 /* Not used */ -#define OP_JUNDEF_P 44 -#define OP_JNUNDEF 45 -#define OP_JNUNDEF_P 46 /* Not used */ -#define OP_JFALSE 47 -#define OP_JFALSE_P 48 -#define OP_JTRUE 49 -#define OP_JTRUE_P 50 -#define OP_JL_P 51 -#define OP_JLE_P 52 -#define OP_ITER_NEXT 53 -#define OP_ITER_START_ARRAY 54 -#define OP_ITER_START_DICT 55 -#define OP_ITER_START_INT_RANGE 56 -#define OP_ITER_START_INT_ENUM 57 -#define OP_JZ 58 -#define OP_JZ_P 59 -#define OP_PUSH_8 60 -#define OP_PUSH_16 61 -#define OP_PUSH_32 62 -#define OP_PUSH_U 63 -#define OP_CONTAINS 64 -#define OP_STARTSWITH 65 -#define OP_ENDSWITH 66 -#define OP_ICONTAINS 67 -#define OP_ISTARTSWITH 68 -#define OP_IENDSWITH 69 - -#define _OP_EQ 0 -#define _OP_NEQ 1 -#define _OP_LT 2 -#define _OP_GT 3 -#define _OP_LE 4 -#define _OP_GE 5 -#define _OP_ADD 6 -#define _OP_SUB 7 -#define _OP_MUL 8 -#define _OP_DIV 9 -#define _OP_MINUS 10 - - -#define OP_INT_BEGIN 100 -#define OP_INT_EQ (OP_INT_BEGIN + _OP_EQ) -#define OP_INT_NEQ (OP_INT_BEGIN + _OP_NEQ) -#define OP_INT_LT (OP_INT_BEGIN + _OP_LT) -#define OP_INT_GT (OP_INT_BEGIN + _OP_GT) -#define OP_INT_LE (OP_INT_BEGIN + _OP_LE) -#define OP_INT_GE (OP_INT_BEGIN + _OP_GE) -#define OP_INT_ADD (OP_INT_BEGIN + _OP_ADD) -#define OP_INT_SUB (OP_INT_BEGIN + _OP_SUB) -#define OP_INT_MUL (OP_INT_BEGIN + _OP_MUL) -#define OP_INT_DIV (OP_INT_BEGIN + _OP_DIV) -#define OP_INT_MINUS (OP_INT_BEGIN + _OP_MINUS) -#define OP_INT_END OP_INT_MINUS - -#define OP_DBL_BEGIN 120 -#define OP_DBL_EQ (OP_DBL_BEGIN + _OP_EQ) -#define OP_DBL_NEQ (OP_DBL_BEGIN + _OP_NEQ) -#define OP_DBL_LT (OP_DBL_BEGIN + _OP_LT) -#define OP_DBL_GT (OP_DBL_BEGIN + _OP_GT) -#define OP_DBL_LE (OP_DBL_BEGIN + _OP_LE) -#define OP_DBL_GE (OP_DBL_BEGIN + _OP_GE) -#define OP_DBL_ADD (OP_DBL_BEGIN + _OP_ADD) -#define OP_DBL_SUB (OP_DBL_BEGIN + _OP_SUB) -#define OP_DBL_MUL (OP_DBL_BEGIN + _OP_MUL) -#define OP_DBL_DIV (OP_DBL_BEGIN + _OP_DIV) -#define OP_DBL_MINUS (OP_DBL_BEGIN + _OP_MINUS) -#define OP_DBL_END OP_DBL_MINUS - -#define OP_STR_BEGIN 140 -#define OP_STR_EQ (OP_STR_BEGIN + _OP_EQ) -#define OP_STR_NEQ (OP_STR_BEGIN + _OP_NEQ) -#define OP_STR_LT (OP_STR_BEGIN + _OP_LT) -#define OP_STR_GT (OP_STR_BEGIN + _OP_GT) -#define OP_STR_LE (OP_STR_BEGIN + _OP_LE) -#define OP_STR_GE (OP_STR_BEGIN + _OP_GE) -#define OP_STR_END OP_STR_GE - -#define IS_INT_OP(x) ((x) >= OP_INT_BEGIN && (x) <= OP_INT_END) -#define IS_DBL_OP(x) ((x) >= OP_DBL_BEGIN && (x) <= OP_DBL_END) -#define IS_STR_OP(x) ((x) >= OP_STR_BEGIN && (x) <= OP_STR_END) - -#define OP_READ_INT 240 -#define OP_INT8 (OP_READ_INT + 0) -#define OP_INT16 (OP_READ_INT + 1) -#define OP_INT32 (OP_READ_INT + 2) -#define OP_UINT8 (OP_READ_INT + 3) -#define OP_UINT16 (OP_READ_INT + 4) -#define OP_UINT32 (OP_READ_INT + 5) -#define OP_INT8BE (OP_READ_INT + 6) -#define OP_INT16BE (OP_READ_INT + 7) -#define OP_INT32BE (OP_READ_INT + 8) -#define OP_UINT8BE (OP_READ_INT + 9) -#define OP_UINT16BE (OP_READ_INT + 10) -#define OP_UINT32BE (OP_READ_INT + 11) +#define YR_UNDEFINED 0xFFFABADAFABADAFFLL +#define IS_UNDEFINED(x) ((size_t)(x) == (size_t) YR_UNDEFINED) + +#define OP_ERROR 0 +#define OP_HALT 255 +#define OP_NOP 254 + +#define OP_AND 1 +#define OP_OR 2 +#define OP_NOT 3 +#define OP_BITWISE_NOT 4 +#define OP_BITWISE_AND 5 +#define OP_BITWISE_OR 6 +#define OP_BITWISE_XOR 7 +#define OP_SHL 8 +#define OP_SHR 9 +#define OP_MOD 10 +#define OP_INT_TO_DBL 11 +#define OP_STR_TO_BOOL 12 +#define OP_PUSH 13 +#define OP_POP 14 +#define OP_CALL 15 +#define OP_OBJ_LOAD 16 +#define OP_OBJ_VALUE 17 +#define OP_OBJ_FIELD 18 +#define OP_INDEX_ARRAY 19 +#define OP_COUNT 20 +#define OP_LENGTH 21 +#define OP_FOUND 22 +#define OP_FOUND_AT 23 +#define OP_FOUND_IN 24 +#define OP_OFFSET 25 +#define OP_OF 26 +#define OP_PUSH_RULE 27 +#define OP_INIT_RULE 28 +#define OP_MATCH_RULE 29 +#define OP_INCR_M 30 +#define OP_CLEAR_M 31 +#define OP_ADD_M 32 +#define OP_POP_M 33 +#define OP_PUSH_M 34 +#define OP_SET_M 35 +#define OP_SWAPUNDEF 36 +#define OP_FILESIZE 37 +#define OP_ENTRYPOINT 38 +#define OP_UNUSED 39 +#define OP_MATCHES 40 +#define OP_IMPORT 41 +#define OP_LOOKUP_DICT 42 +#define OP_JUNDEF 43 /* Not used */ +#define OP_JUNDEF_P 44 +#define OP_JNUNDEF 45 +#define OP_JNUNDEF_P 46 /* Not used */ +#define OP_JFALSE 47 +#define OP_JFALSE_P 48 +#define OP_JTRUE 49 +#define OP_JTRUE_P 50 +#define OP_JL_P 51 +#define OP_JLE_P 52 +#define OP_ITER_NEXT 53 +#define OP_ITER_START_ARRAY 54 +#define OP_ITER_START_DICT 55 +#define OP_ITER_START_INT_RANGE 56 +#define OP_ITER_START_INT_ENUM 57 +#define OP_JZ 58 +#define OP_JZ_P 59 +#define OP_PUSH_8 60 +#define OP_PUSH_16 61 +#define OP_PUSH_32 62 +#define OP_PUSH_U 63 +#define OP_CONTAINS 64 +#define OP_STARTSWITH 65 +#define OP_ENDSWITH 66 +#define OP_ICONTAINS 67 +#define OP_ISTARTSWITH 68 +#define OP_IENDSWITH 69 + +#define _OP_EQ 0 +#define _OP_NEQ 1 +#define _OP_LT 2 +#define _OP_GT 3 +#define _OP_LE 4 +#define _OP_GE 5 +#define _OP_ADD 6 +#define _OP_SUB 7 +#define _OP_MUL 8 +#define _OP_DIV 9 +#define _OP_MINUS 10 + + +#define OP_INT_BEGIN 100 +#define OP_INT_EQ (OP_INT_BEGIN + _OP_EQ) +#define OP_INT_NEQ (OP_INT_BEGIN + _OP_NEQ) +#define OP_INT_LT (OP_INT_BEGIN + _OP_LT) +#define OP_INT_GT (OP_INT_BEGIN + _OP_GT) +#define OP_INT_LE (OP_INT_BEGIN + _OP_LE) +#define OP_INT_GE (OP_INT_BEGIN + _OP_GE) +#define OP_INT_ADD (OP_INT_BEGIN + _OP_ADD) +#define OP_INT_SUB (OP_INT_BEGIN + _OP_SUB) +#define OP_INT_MUL (OP_INT_BEGIN + _OP_MUL) +#define OP_INT_DIV (OP_INT_BEGIN + _OP_DIV) +#define OP_INT_MINUS (OP_INT_BEGIN + _OP_MINUS) +#define OP_INT_END OP_INT_MINUS + +#define OP_DBL_BEGIN 120 +#define OP_DBL_EQ (OP_DBL_BEGIN + _OP_EQ) +#define OP_DBL_NEQ (OP_DBL_BEGIN + _OP_NEQ) +#define OP_DBL_LT (OP_DBL_BEGIN + _OP_LT) +#define OP_DBL_GT (OP_DBL_BEGIN + _OP_GT) +#define OP_DBL_LE (OP_DBL_BEGIN + _OP_LE) +#define OP_DBL_GE (OP_DBL_BEGIN + _OP_GE) +#define OP_DBL_ADD (OP_DBL_BEGIN + _OP_ADD) +#define OP_DBL_SUB (OP_DBL_BEGIN + _OP_SUB) +#define OP_DBL_MUL (OP_DBL_BEGIN + _OP_MUL) +#define OP_DBL_DIV (OP_DBL_BEGIN + _OP_DIV) +#define OP_DBL_MINUS (OP_DBL_BEGIN + _OP_MINUS) +#define OP_DBL_END OP_DBL_MINUS + +#define OP_STR_BEGIN 140 +#define OP_STR_EQ (OP_STR_BEGIN + _OP_EQ) +#define OP_STR_NEQ (OP_STR_BEGIN + _OP_NEQ) +#define OP_STR_LT (OP_STR_BEGIN + _OP_LT) +#define OP_STR_GT (OP_STR_BEGIN + _OP_GT) +#define OP_STR_LE (OP_STR_BEGIN + _OP_LE) +#define OP_STR_GE (OP_STR_BEGIN + _OP_GE) +#define OP_STR_END OP_STR_GE + +#define IS_INT_OP(x) ((x) >= OP_INT_BEGIN && (x) <= OP_INT_END) +#define IS_DBL_OP(x) ((x) >= OP_DBL_BEGIN && (x) <= OP_DBL_END) +#define IS_STR_OP(x) ((x) >= OP_STR_BEGIN && (x) <= OP_STR_END) + +#define OP_READ_INT 240 +#define OP_INT8 (OP_READ_INT + 0) +#define OP_INT16 (OP_READ_INT + 1) +#define OP_INT32 (OP_READ_INT + 2) +#define OP_UINT8 (OP_READ_INT + 3) +#define OP_UINT16 (OP_READ_INT + 4) +#define OP_UINT32 (OP_READ_INT + 5) +#define OP_INT8BE (OP_READ_INT + 6) +#define OP_INT16BE (OP_READ_INT + 7) +#define OP_INT32BE (OP_READ_INT + 8) +#define OP_UINT8BE (OP_READ_INT + 9) +#define OP_UINT16BE (OP_READ_INT + 10) +#define OP_UINT32BE (OP_READ_INT + 11) #define OPERATION(operator, op1, op2) \ - (IS_UNDEFINED(op1) || IS_UNDEFINED(op2)) ? (YR_UNDEFINED) : (op1 operator op2) + (IS_UNDEFINED(op1) || IS_UNDEFINED(op2)) ? (YR_UNDEFINED) : (op1 operator op2) #define COMPARISON(operator, op1, op2) \ - (IS_UNDEFINED(op1) || IS_UNDEFINED(op2)) ? (0) : (op1 operator op2) + (IS_UNDEFINED(op1) || IS_UNDEFINED(op2)) ? (0) : (op1 operator op2) -int yr_execute_code( - YR_SCAN_CONTEXT* context); +int yr_execute_code(YR_SCAN_CONTEXT* context); #endif diff --git a/libyara/include/yara/exefiles.h b/libyara/include/yara/exefiles.h index c8a6664b2f..5bce74dfd7 100644 --- a/libyara/include/yara/exefiles.h +++ b/libyara/include/yara/exefiles.h @@ -30,9 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef YR_EXEFILES_H #define YR_EXEFILES_H -uint64_t yr_get_entry_point_offset( - const uint8_t* buffer, - size_t buffer_length); +uint64_t yr_get_entry_point_offset(const uint8_t* buffer, size_t buffer_length); uint64_t yr_get_entry_point_address( diff --git a/libyara/include/yara/filemap.h b/libyara/include/yara/filemap.h index 68fb9ffeb2..eb458d2524 100644 --- a/libyara/include/yara/filemap.h +++ b/libyara/include/yara/filemap.h @@ -34,32 +34,29 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(_WIN32) || defined(__CYGWIN__) #include -#define YR_FILE_DESCRIPTOR HANDLE +#define YR_FILE_DESCRIPTOR HANDLE #else -#define YR_FILE_DESCRIPTOR int +#define YR_FILE_DESCRIPTOR int #endif #include - #include #include typedef struct _YR_MAPPED_FILE { - YR_FILE_DESCRIPTOR file; - size_t size; - const uint8_t* data; - #if defined(_WIN32) || defined(__CYGWIN__) - HANDLE mapping; - #endif + YR_FILE_DESCRIPTOR file; + size_t size; + const uint8_t* data; +#if defined(_WIN32) || defined(__CYGWIN__) + HANDLE mapping; +#endif } YR_MAPPED_FILE; -YR_API int yr_filemap_map( - const char* file_path, - YR_MAPPED_FILE* pmapped_file); +YR_API int yr_filemap_map(const char* file_path, YR_MAPPED_FILE* pmapped_file); YR_API int yr_filemap_map_fd( @@ -76,11 +73,9 @@ YR_API int yr_filemap_map_ex( YR_MAPPED_FILE* pmapped_file); -YR_API void yr_filemap_unmap( - YR_MAPPED_FILE* pmapped_file); +YR_API void yr_filemap_unmap(YR_MAPPED_FILE* pmapped_file); -YR_API void yr_filemap_unmap_fd( - YR_MAPPED_FILE* pmapped_file); +YR_API void yr_filemap_unmap_fd(YR_MAPPED_FILE* pmapped_file); #endif diff --git a/libyara/include/yara/globals.h b/libyara/include/yara/globals.h index d566098ecc..b231b124b1 100644 --- a/libyara/include/yara/globals.h +++ b/libyara/include/yara/globals.h @@ -46,9 +46,9 @@ extern uint8_t yr_altercase[256]; #else #define YR_DEBUG_FPRINTF(VERBOSITY, FORMAT, ...) \ - if (yr_debug_verbosity >= VERBOSITY) \ - { \ - fprintf(FORMAT, __VA_ARGS__); \ + if (yr_debug_verbosity >= VERBOSITY) \ + { \ + fprintf(FORMAT, __VA_ARGS__); \ } // Default is 0 for production, which means be silent, else verbose. diff --git a/libyara/include/yara/hash.h b/libyara/include/yara/hash.h index b5c3875580..1181c949aa 100644 --- a/libyara/include/yara/hash.h +++ b/libyara/include/yara/hash.h @@ -31,9 +31,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define YR_HASH_H #include - -#include #include +#include typedef struct _YR_HASH_TABLE_ENTRY { @@ -59,15 +58,10 @@ typedef struct _YR_HASH_TABLE typedef int (*YR_HASH_TABLE_FREE_VALUE_FUNC)(void* value); -uint32_t yr_hash( - uint32_t seed, - const void* buffer, - size_t len); +uint32_t yr_hash(uint32_t seed, const void* buffer, size_t len); -YR_API int yr_hash_table_create( - int size, - YR_HASH_TABLE** table); +YR_API int yr_hash_table_create(int size, YR_HASH_TABLE** table); YR_API void yr_hash_table_clean( diff --git a/libyara/include/yara/hex_lexer.h b/libyara/include/yara/hex_lexer.h index ed33791994..588adf384b 100644 --- a/libyara/include/yara/hex_lexer.h +++ b/libyara/include/yara/hex_lexer.h @@ -43,15 +43,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #undef YY_DECL #undef LEX_ENV -#define yyparse hex_yyparse -#define yylex hex_yylex -#define yyerror hex_yyerror -#define yyfatal hex_yyfatal -#define yychar hex_yychar -#define yydebug hex_yydebug -#define yynerrs hex_yynerrs -#define yyget_extra hex_yyget_extra -#define yyget_lineno hex_yyget_lineno +#define yyparse hex_yyparse +#define yylex hex_yylex +#define yyerror hex_yyerror +#define yyfatal hex_yyfatal +#define yychar hex_yychar +#define yydebug hex_yydebug +#define yynerrs hex_yynerrs +#define yyget_extra hex_yyget_extra +#define yyget_lineno hex_yyget_lineno #ifndef YY_TYPEDEF_YY_SCANNER_T @@ -79,36 +79,32 @@ typedef struct _HEX_LEX_ENVIRONMENT // own function instead of the one provided by default. #define YY_FATAL_ERROR(msg) hex_yyfatal(yyscanner, msg) -#define LEX_ENV ((HEX_LEX_ENVIRONMENT*) lex_env) +#define LEX_ENV ((HEX_LEX_ENVIRONMENT*) lex_env) #include -#define YY_DECL int hex_yylex \ - (YYSTYPE * yylval_param , yyscan_t yyscanner, HEX_LEX_ENVIRONMENT* lex_env) +#define YY_DECL \ + int hex_yylex( \ + YYSTYPE* yylval_param, yyscan_t yyscanner, HEX_LEX_ENVIRONMENT* lex_env) -YY_EXTRA_TYPE yyget_extra( - yyscan_t yyscanner); +YY_EXTRA_TYPE yyget_extra(yyscan_t yyscanner); int yylex( YYSTYPE* yylval_param, yyscan_t yyscanner, HEX_LEX_ENVIRONMENT* lex_env); -int yyparse( - void *yyscanner, - HEX_LEX_ENVIRONMENT *lex_env); +int yyparse(void* yyscanner, HEX_LEX_ENVIRONMENT* lex_env); void yyerror( yyscan_t yyscanner, HEX_LEX_ENVIRONMENT* lex_env, - const char *error_message); + const char* error_message); -void yyfatal( - yyscan_t yyscanner, - const char *error_message); +void yyfatal(yyscan_t yyscanner, const char* error_message); int yr_parse_hex_string( - const char* hex_string, - RE_AST** re_ast, - RE_ERROR* error); + const char* hex_string, + RE_AST** re_ast, + RE_ERROR* error); diff --git a/libyara/include/yara/integers.h b/libyara/include/yara/integers.h index 082c33d679..be9250890d 100644 --- a/libyara/include/yara/integers.h +++ b/libyara/include/yara/integers.h @@ -31,24 +31,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define YR_INTEGERS_H -#if ( defined( _MSC_VER ) && ( _MSC_VER < 1600 ) ) || ( defined( __BORLANDC__ ) && ( __BORLANDC__ <= 0x0560 ) ) +#if (defined(_MSC_VER) && (_MSC_VER < 1600)) || \ + (defined(__BORLANDC__) && (__BORLANDC__ <= 0x0560)) #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -// Microsoft Visual Studio C++ before Visual Studio 2010 or earlier versions of -// the Borland C++ Builder do not support the (u)int#_t type definitions but -// have __int# definitions instead + // Microsoft Visual Studio C++ before Visual Studio 2010 or earlier versions + // of the Borland C++ Builder do not support the (u)int#_t type definitions + // but have __int# definitions instead -typedef __int8 int8_t; -typedef unsigned __int8 uint8_t; -typedef __int16 int16_t; -typedef unsigned __int16 uint16_t; -typedef __int32 int32_t; -typedef unsigned __int32 uint32_t; -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; + typedef __int8 int8_t; + typedef unsigned __int8 uint8_t; + typedef __int16 int16_t; + typedef unsigned __int16 uint16_t; + typedef __int32 int32_t; + typedef unsigned __int32 uint32_t; + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; #ifdef __cplusplus } @@ -56,51 +58,51 @@ typedef unsigned __int64 uint64_t; #ifndef INT8_MIN -#define INT8_MIN (-127i8 - 1) +#define INT8_MIN (-127i8 - 1) #endif #ifndef INT8_MIN -#define INT16_MIN (-32767i16 - 1) +#define INT16_MIN (-32767i16 - 1) #endif #ifndef INT32_MIN -#define INT32_MIN (-2147483647i32 - 1) +#define INT32_MIN (-2147483647i32 - 1) #endif #ifndef INT64_MIN -#define INT64_MIN (-9223372036854775807i64 - 1) +#define INT64_MIN (-9223372036854775807i64 - 1) #endif #ifndef INT8_MAX -#define INT8_MAX 127i8 +#define INT8_MAX 127i8 #endif #ifndef INT16_MAX -#define INT16_MAX 32767i16 +#define INT16_MAX 32767i16 #endif #ifndef INT32_MAX -#define INT32_MAX 2147483647i32 +#define INT32_MAX 2147483647i32 #endif #ifndef INT64_MAX -#define INT64_MAX 9223372036854775807i64 +#define INT64_MAX 9223372036854775807i64 #endif #ifndef UINT8_MAX -#define UINT8_MAX 0xffui8 +#define UINT8_MAX 0xffui8 #endif #ifndef UINT16_MAX -#define UINT16_MAX 0xffffui16 +#define UINT16_MAX 0xffffui16 #endif #ifndef UINT32_MAX -#define UINT32_MAX 0xffffffffui32 +#define UINT32_MAX 0xffffffffui32 #endif #ifndef UINT64_MAX -#define UINT64_MAX 0xffffffffffffffffui64 +#define UINT64_MAX 0xffffffffffffffffui64 #endif #else diff --git a/libyara/include/yara/lexer.h b/libyara/include/yara/lexer.h index 9d7bc8ed0f..5146f56397 100644 --- a/libyara/include/yara/lexer.h +++ b/libyara/include/yara/lexer.h @@ -44,16 +44,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #undef YY_FATAL_ERROR #undef YY_EXTRA_TYPE -#define yyparse yara_yyparse -#define yylex yara_yylex -#define yyerror yara_yyerror -#define yyfatal yara_yyfatal -#define yywarning yara_yywarning -#define yychar yara_yychar -#define yydebug yara_yydebug -#define yynerrs yara_yynerrs -#define yyget_extra yara_yyget_extra -#define yyget_lineno yara_yyget_lineno +#define yyparse yara_yyparse +#define yylex yara_yylex +#define yyerror yara_yyerror +#define yyfatal yara_yyfatal +#define yywarning yara_yywarning +#define yychar yara_yychar +#define yydebug yara_yydebug +#define yynerrs yara_yynerrs +#define yyget_extra yara_yyget_extra +#define yyget_lineno yara_yyget_lineno #ifndef YY_TYPEDEF_YY_SCANNER_T @@ -63,8 +63,9 @@ typedef void* yyscan_t; union YYSTYPE; -#define YY_DECL int yylex( \ - union YYSTYPE* yylval_param, yyscan_t yyscanner, YR_COMPILER* compiler) +#define YY_DECL \ + int yylex( \ + union YYSTYPE* yylval_param, yyscan_t yyscanner, YR_COMPILER* compiler) #define YY_FATAL_ERROR(msg) yara_yyfatal(yyscanner, msg) @@ -81,35 +82,22 @@ int yylex( yyscan_t yyscanner, YR_COMPILER* compiler); -int yyparse( - void *yyscanner, - YR_COMPILER* compiler); +int yyparse(void* yyscanner, YR_COMPILER* compiler); void yyerror( yyscan_t yyscanner, YR_COMPILER* compiler, - const char *error_message); + const char* error_message); -void yywarning( - yyscan_t yyscanner, - const char *message_fmt, - ...) YR_PRINTF_LIKE(2, 3); +void yywarning(yyscan_t yyscanner, const char* message_fmt, ...) + YR_PRINTF_LIKE(2, 3); -void yyfatal( - yyscan_t yyscanner, - const char *error_message); +void yyfatal(yyscan_t yyscanner, const char* error_message); -YY_EXTRA_TYPE yyget_extra( - yyscan_t yyscanner); +YY_EXTRA_TYPE yyget_extra(yyscan_t yyscanner); -int yr_lex_parse_rules_string( - const char* rules_string, - YR_COMPILER* compiler); +int yr_lex_parse_rules_string(const char* rules_string, YR_COMPILER* compiler); -int yr_lex_parse_rules_file( - FILE* rules_file, - YR_COMPILER* compiler); +int yr_lex_parse_rules_file(FILE* rules_file, YR_COMPILER* compiler); -int yr_lex_parse_rules_fd( - YR_FILE_DESCRIPTOR rules_fd, - YR_COMPILER* compiler); +int yr_lex_parse_rules_fd(YR_FILE_DESCRIPTOR rules_fd, YR_COMPILER* compiler); diff --git a/libyara/include/yara/libyara.h b/libyara/include/yara/libyara.h index 933ad55d30..8bfd5af6d5 100644 --- a/libyara/include/yara/libyara.h +++ b/libyara/include/yara/libyara.h @@ -32,22 +32,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#define YR_MAJOR_VERSION 4 -#define YR_MINOR_VERSION 0 -#define YR_MICRO_VERSION 2 +#define YR_MAJOR_VERSION 4 +#define YR_MINOR_VERSION 0 +#define YR_MICRO_VERSION 2 -#define version_str(s) _version_str(s) +#define version_str(s) _version_str(s) #define _version_str(s) #s // Version as a string -#define YR_VERSION version_str(YR_MAJOR_VERSION) \ - "." version_str(YR_MINOR_VERSION) \ - "." version_str(YR_MICRO_VERSION) +#define YR_VERSION \ + version_str(YR_MAJOR_VERSION) "." version_str( \ + YR_MINOR_VERSION) "." version_str(YR_MICRO_VERSION) // Version as a single 4-byte hex number, e.g. 0x030401 == 3.4.1. -#define YR_VERSION_HEX ((YR_MAJOR_VERSION << 16) | \ - (YR_MINOR_VERSION << 8) | \ - (YR_MICRO_VERSION << 0)) +#define YR_VERSION_HEX \ + ((YR_MAJOR_VERSION << 16) | (YR_MINOR_VERSION << 8) | (YR_MICRO_VERSION << 0)) // Enumerated type listing configuration options @@ -62,9 +61,9 @@ typedef enum _YR_CONFIG_NAME } YR_CONFIG_NAME; -#define DEFAULT_STACK_SIZE 16384 -#define DEFAULT_MAX_STRINGS_PER_RULE 10000 -#define DEFAULT_MAX_MATCH_DATA 512 +#define DEFAULT_STACK_SIZE 16384 +#define DEFAULT_MAX_STRINGS_PER_RULE 10000 +#define DEFAULT_MAX_MATCH_DATA 512 YR_API int yr_initialize(void); diff --git a/libyara/include/yara/limits.h b/libyara/include/yara/limits.h index 8feffcdb6e..e57649ab5b 100644 --- a/libyara/include/yara/limits.h +++ b/libyara/include/yara/limits.h @@ -58,14 +58,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Capacity of the buffer used for storing compiler error messages. Messages // will be truncated at this size. #ifndef YR_MAX_COMPILER_ERROR_EXTRA_INFO -#define YR_MAX_COMPILER_ERROR_EXTRA_INFO 256 +#define YR_MAX_COMPILER_ERROR_EXTRA_INFO 256 #endif // Maximum size for the substring (atoms) extracted from strings and regular // expressions and put into the Aho-Corasick automaton. The maximum allows size // for this constant is 255. #ifndef YR_MAX_ATOM_LENGTH -#define YR_MAX_ATOM_LENGTH 4 +#define YR_MAX_ATOM_LENGTH 4 #endif #ifndef YR_MAX_ATOM_QUALITY @@ -82,12 +82,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // must specify the threshold when calling yr_compiler_set_atom_quality_table. #ifndef YR_ATOM_QUALITY_WARNING_THRESHOLD #define YR_ATOM_QUALITY_WARNING_THRESHOLD \ - YR_MAX_ATOM_QUALITY - 20 * YR_MAX_ATOM_LENGTH + 38 + YR_MAX_ATOM_QUALITY - 20 * YR_MAX_ATOM_LENGTH + 38 #endif // If a rule generates more than this number of atoms a warning is shown. #ifndef YR_ATOMS_PER_RULE_WARNING_THRESHOLD -#define YR_ATOMS_PER_RULE_WARNING_THRESHOLD 10000 +#define YR_ATOMS_PER_RULE_WARNING_THRESHOLD 10000 #endif // Maximum number of nested "for" loops in rule. Rules ith nested loops @@ -131,8 +131,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Regular expressions like /foo.{x,y}bar/ are split in two separate ones /foo/ -// and /bar/ if x is larger than YR_STRING_CHAINING_THRESHOLD. This also applies to -// hex strings like { 01 02 03 [x-y] 004 05 06 }. +// and /bar/ if x is larger than YR_STRING_CHAINING_THRESHOLD. This also applies +// to hex strings like { 01 02 03 [x-y] 004 05 06 }. #ifndef YR_STRING_CHAINING_THRESHOLD #define YR_STRING_CHAINING_THRESHOLD 200 #endif @@ -145,9 +145,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Each time an atom is found it means that we have a potential match for some // string, and that match must be verified. The time spent in verifying those -// matches is measured in one out of YR_MATCH_VERIFICATION_PROFILING_RATE matches. -// The time is not measured for all matches because measuring it is expensive -// by itself and match verification is a frequent operation. +// matches is measured in one out of YR_MATCH_VERIFICATION_PROFILING_RATE +// matches. The time is not measured for all matches because measuring it is +// expensive by itself and match verification is a frequent operation. #ifndef YR_MATCH_VERIFICATION_PROFILING_RATE #define YR_MATCH_VERIFICATION_PROFILING_RATE 1024 #endif diff --git a/libyara/include/yara/macho.h b/libyara/include/yara/macho.h index 7ef146bdae..790577a85f 100644 --- a/libyara/include/yara/macho.h +++ b/libyara/include/yara/macho.h @@ -34,255 +34,256 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Mach-O file format magic constants -#define MH_MAGIC 0xfeedface -#define MH_CIGAM 0xcefaedfe -#define MH_MAGIC_64 0xfeedfacf -#define MH_CIGAM_64 0xcffaedfe +#define MH_MAGIC 0xfeedface +#define MH_CIGAM 0xcefaedfe +#define MH_MAGIC_64 0xfeedfacf +#define MH_CIGAM_64 0xcffaedfe // Mach-O universal binary magic constants -#define FAT_MAGIC 0xcafebabe -#define FAT_CIGAM 0xbebafeca -#define FAT_MAGIC_64 0xcafebabf -#define FAT_CIGAM_64 0xbfbafeca +#define FAT_MAGIC 0xcafebabe +#define FAT_CIGAM 0xbebafeca +#define FAT_MAGIC_64 0xcafebabf +#define FAT_CIGAM_64 0xbfbafeca // Mach-O 64-bit masks -#define CPU_ARCH_ABI64 0x01000000 // 64-bit ABI mask (for cputype) -#define CPU_SUBTYPE_LIB64 0x80000000 // 64-bit library mask (for cpusubtype) +#define CPU_ARCH_ABI64 0x01000000 // 64-bit ABI mask (for cputype) +#define CPU_SUBTYPE_LIB64 0x80000000 // 64-bit library mask (for cpusubtype) // Mach-O CPU types -#define CPU_TYPE_MC680X0 0x00000006 // Motorola 68000 -#define CPU_TYPE_I386 0x00000007 // AMD/Intel x86 -#define CPU_TYPE_X86 0x00000007 // AMD/Intel x86 -#define CPU_TYPE_X86_64 0x01000007 // AMD/Intel x86-64 -#define CPU_TYPE_MIPS 0x00000008 // MIPS -#define CPU_TYPE_MC98000 0x0000000a // Motorola PowerPC -#define CPU_TYPE_HPPA 0x0000000b // HP PA-RISC -#define CPU_TYPE_ARM 0x0000000c // ARM -#define CPU_TYPE_ARM64 0x0100000c // ARM 64-bit -#define CPU_TYPE_MC88000 0x0000000d // Motorola 88000 -#define CPU_TYPE_SPARC 0x0000000e // SPARC -#define CPU_TYPE_I860 0x0000000f // Intel i860 -#define CPU_TYPE_ALPHA 0x00000010 // DEC Alpha -#define CPU_TYPE_POWERPC 0x00000012 // PowerPC -#define CPU_TYPE_POWERPC64 0x01000012 // PowerPC 64-bit +#define CPU_TYPE_MC680X0 0x00000006 // Motorola 68000 +#define CPU_TYPE_I386 0x00000007 // AMD/Intel x86 +#define CPU_TYPE_X86 0x00000007 // AMD/Intel x86 +#define CPU_TYPE_X86_64 0x01000007 // AMD/Intel x86-64 +#define CPU_TYPE_MIPS 0x00000008 // MIPS +#define CPU_TYPE_MC98000 0x0000000a // Motorola PowerPC +#define CPU_TYPE_HPPA 0x0000000b // HP PA-RISC +#define CPU_TYPE_ARM 0x0000000c // ARM +#define CPU_TYPE_ARM64 0x0100000c // ARM 64-bit +#define CPU_TYPE_MC88000 0x0000000d // Motorola 88000 +#define CPU_TYPE_SPARC 0x0000000e // SPARC +#define CPU_TYPE_I860 0x0000000f // Intel i860 +#define CPU_TYPE_ALPHA 0x00000010 // DEC Alpha +#define CPU_TYPE_POWERPC 0x00000012 // PowerPC +#define CPU_TYPE_POWERPC64 0x01000012 // PowerPC 64-bit // Mach-O Intel CPU sub-types -#define CPU_SUBTYPE_INTEL_MODEL_ALL 0x00 -#define CPU_SUBTYPE_386 0x03 -#define CPU_SUBTYPE_486 0x04 -#define CPU_SUBTYPE_486SX 0x84 -#define CPU_SUBTYPE_586 0x05 -#define CPU_SUBTYPE_PENT 0x05 -#define CPU_SUBTYPE_PENTPRO 0x16 -#define CPU_SUBTYPE_PENTII_M3 0x36 -#define CPU_SUBTYPE_PENTII_M5 0x56 -#define CPU_SUBTYPE_CELERON 0x67 -#define CPU_SUBTYPE_CELERON_MOBILE 0x77 -#define CPU_SUBTYPE_PENTIUM_3 0x08 -#define CPU_SUBTYPE_PENTIUM_3_M 0x18 -#define CPU_SUBTYPE_PENTIUM_3_XEON 0x28 -#define CPU_SUBTYPE_PENTIUM_M 0x09 -#define CPU_SUBTYPE_PENTIUM_4 0x0a -#define CPU_SUBTYPE_PENTIUM_4_M 0x1a -#define CPU_SUBTYPE_ITANIUM 0x0b -#define CPU_SUBTYPE_ITANIUM_2 0x1b -#define CPU_SUBTYPE_XEON 0x0c -#define CPU_SUBTYPE_XEON_MP 0x1c +#define CPU_SUBTYPE_INTEL_MODEL_ALL 0x00 +#define CPU_SUBTYPE_386 0x03 +#define CPU_SUBTYPE_486 0x04 +#define CPU_SUBTYPE_486SX 0x84 +#define CPU_SUBTYPE_586 0x05 +#define CPU_SUBTYPE_PENT 0x05 +#define CPU_SUBTYPE_PENTPRO 0x16 +#define CPU_SUBTYPE_PENTII_M3 0x36 +#define CPU_SUBTYPE_PENTII_M5 0x56 +#define CPU_SUBTYPE_CELERON 0x67 +#define CPU_SUBTYPE_CELERON_MOBILE 0x77 +#define CPU_SUBTYPE_PENTIUM_3 0x08 +#define CPU_SUBTYPE_PENTIUM_3_M 0x18 +#define CPU_SUBTYPE_PENTIUM_3_XEON 0x28 +#define CPU_SUBTYPE_PENTIUM_M 0x09 +#define CPU_SUBTYPE_PENTIUM_4 0x0a +#define CPU_SUBTYPE_PENTIUM_4_M 0x1a +#define CPU_SUBTYPE_ITANIUM 0x0b +#define CPU_SUBTYPE_ITANIUM_2 0x1b +#define CPU_SUBTYPE_XEON 0x0c +#define CPU_SUBTYPE_XEON_MP 0x1c // Mach-O ARM CPU sub-types -#define CPU_SUBTYPE_ARM_ALL 0x00 -#define CPU_SUBTYPE_ARM_V4T 0x05 -#define CPU_SUBTYPE_ARM_V6 0x06 -#define CPU_SUBTYPE_ARM_V5 0x07 -#define CPU_SUBTYPE_ARM_V5TEJ 0x07 -#define CPU_SUBTYPE_ARM_XSCALE 0x08 -#define CPU_SUBTYPE_ARM_V7 0x09 -#define CPU_SUBTYPE_ARM_V7F 0x0a -#define CPU_SUBTYPE_ARM_V7S 0x0b -#define CPU_SUBTYPE_ARM_V7K 0x0c -#define CPU_SUBTYPE_ARM_V6M 0x0e -#define CPU_SUBTYPE_ARM_V7M 0x0f -#define CPU_SUBTYPE_ARM_V7EM 0x10 +#define CPU_SUBTYPE_ARM_ALL 0x00 +#define CPU_SUBTYPE_ARM_V4T 0x05 +#define CPU_SUBTYPE_ARM_V6 0x06 +#define CPU_SUBTYPE_ARM_V5 0x07 +#define CPU_SUBTYPE_ARM_V5TEJ 0x07 +#define CPU_SUBTYPE_ARM_XSCALE 0x08 +#define CPU_SUBTYPE_ARM_V7 0x09 +#define CPU_SUBTYPE_ARM_V7F 0x0a +#define CPU_SUBTYPE_ARM_V7S 0x0b +#define CPU_SUBTYPE_ARM_V7K 0x0c +#define CPU_SUBTYPE_ARM_V6M 0x0e +#define CPU_SUBTYPE_ARM_V7M 0x0f +#define CPU_SUBTYPE_ARM_V7EM 0x10 // Mach-O ARM 64-bit CPU sub-types -#define CPU_SUBTYPE_ARM64_ALL 0x00 +#define CPU_SUBTYPE_ARM64_ALL 0x00 // Mach-O SPARC CPU sub-types -#define CPU_SUBTYPE_SPARC_ALL 0x00 +#define CPU_SUBTYPE_SPARC_ALL 0x00 // Mach-O PowerPC CPU sub-types -#define CPU_SUBTYPE_POWERPC_ALL 0x00 -#define CPU_SUBTYPE_MC980000_ALL 0x00 -#define CPU_SUBTYPE_POWERPC_601 0x01 -#define CPU_SUBTYPE_MC98601 0x01 -#define CPU_SUBTYPE_POWERPC_602 0x02 -#define CPU_SUBTYPE_POWERPC_603 0x03 -#define CPU_SUBTYPE_POWERPC_603e 0x04 -#define CPU_SUBTYPE_POWERPC_603ev 0x05 -#define CPU_SUBTYPE_POWERPC_604 0x06 -#define CPU_SUBTYPE_POWERPC_604e 0x07 -#define CPU_SUBTYPE_POWERPC_620 0x08 -#define CPU_SUBTYPE_POWERPC_750 0x09 -#define CPU_SUBTYPE_POWERPC_7400 0x0a -#define CPU_SUBTYPE_POWERPC_7450 0x0b -#define CPU_SUBTYPE_POWERPC_970 0x64 +#define CPU_SUBTYPE_POWERPC_ALL 0x00 +#define CPU_SUBTYPE_MC980000_ALL 0x00 +#define CPU_SUBTYPE_POWERPC_601 0x01 +#define CPU_SUBTYPE_MC98601 0x01 +#define CPU_SUBTYPE_POWERPC_602 0x02 +#define CPU_SUBTYPE_POWERPC_603 0x03 +#define CPU_SUBTYPE_POWERPC_603e 0x04 +#define CPU_SUBTYPE_POWERPC_603ev 0x05 +#define CPU_SUBTYPE_POWERPC_604 0x06 +#define CPU_SUBTYPE_POWERPC_604e 0x07 +#define CPU_SUBTYPE_POWERPC_620 0x08 +#define CPU_SUBTYPE_POWERPC_750 0x09 +#define CPU_SUBTYPE_POWERPC_7400 0x0a +#define CPU_SUBTYPE_POWERPC_7450 0x0b +#define CPU_SUBTYPE_POWERPC_970 0x64 // Mach-O file types -#define MH_OBJECT 0x01 // Object file -#define MH_EXECUTE 0x02 // Executable file -#define MH_FVMLIB 0x03 // Fixed VM shared library -#define MH_CORE 0x04 // Core dump file -#define MH_PRELOAD 0x05 // Preloaded executable file -#define MH_DYLIB 0x06 // Dynamic shared library -#define MH_DYLINKER 0x07 // Dynamic linker shared library -#define MH_BUNDLE 0x08 // Bundle file -#define MH_DYLIB_STUB 0x09 // Dynamic shared library stub -#define MH_DSYM 0x0a // Companion debug sections file -#define MH_KEXT_BUNDLE 0x0b // Kernel extension +#define MH_OBJECT 0x01 // Object file +#define MH_EXECUTE 0x02 // Executable file +#define MH_FVMLIB 0x03 // Fixed VM shared library +#define MH_CORE 0x04 // Core dump file +#define MH_PRELOAD 0x05 // Preloaded executable file +#define MH_DYLIB 0x06 // Dynamic shared library +#define MH_DYLINKER 0x07 // Dynamic linker shared library +#define MH_BUNDLE 0x08 // Bundle file +#define MH_DYLIB_STUB 0x09 // Dynamic shared library stub +#define MH_DSYM 0x0a // Companion debug sections file +#define MH_KEXT_BUNDLE 0x0b // Kernel extension // Mach-O file flags -#define MH_NOUNDEFS 0x00000001 -#define MH_INCRLINK 0x00000002 -#define MH_DYLDLINK 0x00000004 -#define MH_BINDATLOAD 0x00000008 -#define MH_PREBOUND 0x00000010 -#define MH_SPLIT_SEGS 0x00000020 -#define MH_LAZY_INIT 0x00000040 -#define MH_TWOLEVEL 0x00000080 -#define MH_FORCE_FLAT 0x00000100 -#define MH_NOMULTIDEFS 0x00000200 -#define MH_NOFIXPREBINDING 0x00000400 -#define MH_PREBINDABLE 0x00000800 -#define MH_ALLMODSBOUND 0x00001000 -#define MH_SUBSECTIONS_VIA_SYMBOLS 0x00002000 -#define MH_CANONICAL 0x00004000 -#define MH_WEAK_DEFINES 0x00008000 -#define MH_BINDS_TO_WEAK 0x00010000 -#define MH_ALLOW_STACK_EXECUTION 0x00020000 -#define MH_ROOT_SAFE 0x00040000 -#define MH_SETUID_SAFE 0x00080000 -#define MH_NO_REEXPORTED_DYLIBS 0x00100000 -#define MH_PIE 0x00200000 -#define MH_DEAD_STRIPPABLE_DYLIB 0x00400000 -#define MH_HAS_TLV_DESCRIPTORS 0x00800000 -#define MH_NO_HEAP_EXECUTION 0x01000000 -#define MH_APP_EXTENSION_SAFE 0x02000000 +#define MH_NOUNDEFS 0x00000001 +#define MH_INCRLINK 0x00000002 +#define MH_DYLDLINK 0x00000004 +#define MH_BINDATLOAD 0x00000008 +#define MH_PREBOUND 0x00000010 +#define MH_SPLIT_SEGS 0x00000020 +#define MH_LAZY_INIT 0x00000040 +#define MH_TWOLEVEL 0x00000080 +#define MH_FORCE_FLAT 0x00000100 +#define MH_NOMULTIDEFS 0x00000200 +#define MH_NOFIXPREBINDING 0x00000400 +#define MH_PREBINDABLE 0x00000800 +#define MH_ALLMODSBOUND 0x00001000 +#define MH_SUBSECTIONS_VIA_SYMBOLS 0x00002000 +#define MH_CANONICAL 0x00004000 +#define MH_WEAK_DEFINES 0x00008000 +#define MH_BINDS_TO_WEAK 0x00010000 +#define MH_ALLOW_STACK_EXECUTION 0x00020000 +#define MH_ROOT_SAFE 0x00040000 +#define MH_SETUID_SAFE 0x00080000 +#define MH_NO_REEXPORTED_DYLIBS 0x00100000 +#define MH_PIE 0x00200000 +#define MH_DEAD_STRIPPABLE_DYLIB 0x00400000 +#define MH_HAS_TLV_DESCRIPTORS 0x00800000 +#define MH_NO_HEAP_EXECUTION 0x01000000 +#define MH_APP_EXTENSION_SAFE 0x02000000 // Mach-O load commands -#define LC_SEGMENT 0x00000001 -#define LC_SYMTAB 0x00000002 -#define LC_SYMSEG 0x00000003 -#define LC_THREAD 0x00000004 -#define LC_UNIXTHREAD 0x00000005 -#define LC_LOADFVMLIB 0x00000006 -#define LC_IDFVMLIB 0x00000007 -#define LC_IDENT 0x00000008 -#define LC_FVMFILE 0x00000009 -#define LC_PREPAGE 0x0000000a -#define LC_DYSYMTAB 0x0000000b -#define LC_LOAD_DYLIB 0x0000000c -#define LC_ID_DYLIB 0x0000000d -#define LC_LOAD_DYLINKER 0x0000000e -#define LC_ID_DYLINKER 0x0000000f -#define LC_PREBOUND_DYLIB 0x00000010 -#define LC_ROUTINES 0x00000011 -#define LC_SUB_FRAMEWORK 0x00000012 -#define LC_SUB_UMBRELLA 0x00000013 -#define LC_SUB_CLIENT 0x00000014 -#define LC_SUB_LIBRARY 0x00000015 -#define LC_TWOLEVEL_HINTS 0x00000016 -#define LC_PREBIND_CKSUM 0x00000017 -#define LC_LOAD_WEAK_DYLIB 0x80000018 -#define LC_SEGMENT_64 0x00000019 -#define LC_ROUTINES_64 0x0000001A -#define LC_UUID 0x0000001B -#define LC_RPATH 0x8000001C -#define LC_CODE_SIGNATURE 0x0000001D -#define LC_SEGMENT_SPLIT_INFO 0x0000001E -#define LC_REEXPORT_DYLIB 0x8000001F -#define LC_LAZY_LOAD_DYLIB 0x00000020 -#define LC_ENCRYPTION_INFO 0x00000021 -#define LC_DYLD_INFO 0x00000022 -#define LC_DYLD_INFO_ONLY 0x80000022 -#define LC_LOAD_UPWARD_DYLIB 0x80000023 -#define LC_VERSION_MIN_MACOSX 0x00000024 -#define LC_VERSION_MIN_IPHONEOS 0x00000025 -#define LC_FUNCTION_STARTS 0x00000026 -#define LC_DYLD_ENVIRONMENT 0x00000027 -#define LC_MAIN 0x80000028 -#define LC_DATA_IN_CODE 0x00000029 -#define LC_SOURCE_VERSION 0x0000002A -#define LC_DYLIB_CODE_SIGN_DRS 0x0000002B -#define LC_ENCRYPTION_INFO_64 0x0000002C -#define LC_LINKER_OPTION 0x0000002D -#define LC_LINKER_OPTIMIZATION_HINT 0x0000002E -#define LC_VERSION_MIN_TVOS 0x0000002F -#define LC_VERSION_MIN_WATCHOS 0x00000030 +#define LC_SEGMENT 0x00000001 +#define LC_SYMTAB 0x00000002 +#define LC_SYMSEG 0x00000003 +#define LC_THREAD 0x00000004 +#define LC_UNIXTHREAD 0x00000005 +#define LC_LOADFVMLIB 0x00000006 +#define LC_IDFVMLIB 0x00000007 +#define LC_IDENT 0x00000008 +#define LC_FVMFILE 0x00000009 +#define LC_PREPAGE 0x0000000a +#define LC_DYSYMTAB 0x0000000b +#define LC_LOAD_DYLIB 0x0000000c +#define LC_ID_DYLIB 0x0000000d +#define LC_LOAD_DYLINKER 0x0000000e +#define LC_ID_DYLINKER 0x0000000f +#define LC_PREBOUND_DYLIB 0x00000010 +#define LC_ROUTINES 0x00000011 +#define LC_SUB_FRAMEWORK 0x00000012 +#define LC_SUB_UMBRELLA 0x00000013 +#define LC_SUB_CLIENT 0x00000014 +#define LC_SUB_LIBRARY 0x00000015 +#define LC_TWOLEVEL_HINTS 0x00000016 +#define LC_PREBIND_CKSUM 0x00000017 +#define LC_LOAD_WEAK_DYLIB 0x80000018 +#define LC_SEGMENT_64 0x00000019 +#define LC_ROUTINES_64 0x0000001A +#define LC_UUID 0x0000001B +#define LC_RPATH 0x8000001C +#define LC_CODE_SIGNATURE 0x0000001D +#define LC_SEGMENT_SPLIT_INFO 0x0000001E +#define LC_REEXPORT_DYLIB 0x8000001F +#define LC_LAZY_LOAD_DYLIB 0x00000020 +#define LC_ENCRYPTION_INFO 0x00000021 +#define LC_DYLD_INFO 0x00000022 +#define LC_DYLD_INFO_ONLY 0x80000022 +#define LC_LOAD_UPWARD_DYLIB 0x80000023 +#define LC_VERSION_MIN_MACOSX 0x00000024 +#define LC_VERSION_MIN_IPHONEOS 0x00000025 +#define LC_FUNCTION_STARTS 0x00000026 +#define LC_DYLD_ENVIRONMENT 0x00000027 +#define LC_MAIN 0x80000028 +#define LC_DATA_IN_CODE 0x00000029 +#define LC_SOURCE_VERSION 0x0000002A +#define LC_DYLIB_CODE_SIGN_DRS 0x0000002B +#define LC_ENCRYPTION_INFO_64 0x0000002C +#define LC_LINKER_OPTION 0x0000002D +#define LC_LINKER_OPTIMIZATION_HINT 0x0000002E +#define LC_VERSION_MIN_TVOS 0x0000002F +#define LC_VERSION_MIN_WATCHOS 0x00000030 // Segment flags -#define SG_HIGHVM 0x00000001 // Use high part of VM (stack) -#define SG_FVMLIB 0x00000002 // Allocated by a fixed VM library -#define SG_NORELOC 0x00000004 // No associated relocations -#define SG_PROTECTED_VERSION_1 0x00000008 // Segment is encryption protected +#define SG_HIGHVM 0x00000001 // Use high part of VM (stack) +#define SG_FVMLIB 0x00000002 // Allocated by a fixed VM library +#define SG_NORELOC 0x00000004 // No associated relocations +#define SG_PROTECTED_VERSION_1 0x00000008 // Segment is encryption protected // Section flag masks -#define SECTION_TYPE 0x000000ff // Section type mask -#define SECTION_ATTRIBUTES 0xffffff00 // Section attributes mask +#define SECTION_TYPE 0x000000ff // Section type mask +#define SECTION_ATTRIBUTES 0xffffff00 // Section attributes mask // Section type (use SECTION_TYPE mask) -#define S_REGULAR 0x00 -#define S_ZEROFILL 0x01 -#define S_CSTRING_LITERALS 0x02 -#define S_4BYTE_LITERALS 0x03 -#define S_8BYTE_LITERALS 0x04 -#define S_LITERAL_POINTERS 0x05 -#define S_NON_LAZY_SYMBOL_POINTERS 0x06 -#define S_LAZY_SYMBOL_POINTERS 0x07 -#define S_SYMBOL_STUBS 0x08 -#define S_MOD_INIT_FUNC_POINTERS 0x09 -#define S_MOD_TERM_FUNC_POINTERS 0x0a -#define S_COALESCED 0x0b -#define S_GB_ZEROFILL 0x0c -#define S_INTERPOSING 0x0d -#define S_16BYTE_LITERALS 0x0e -#define S_DTRACE_DOF 0x0f -#define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10 -#define S_THREAD_LOCAL_REGULAR 0x11 -#define S_THREAD_LOCAL_ZEROFILL 0x12 -#define S_THREAD_LOCAL_VARIABLES 0x13 -#define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14 -#define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15 +#define S_REGULAR 0x00 +#define S_ZEROFILL 0x01 +#define S_CSTRING_LITERALS 0x02 +#define S_4BYTE_LITERALS 0x03 +#define S_8BYTE_LITERALS 0x04 +#define S_LITERAL_POINTERS 0x05 +#define S_NON_LAZY_SYMBOL_POINTERS 0x06 +#define S_LAZY_SYMBOL_POINTERS 0x07 +#define S_SYMBOL_STUBS 0x08 +#define S_MOD_INIT_FUNC_POINTERS 0x09 +#define S_MOD_TERM_FUNC_POINTERS 0x0a +#define S_COALESCED 0x0b +#define S_GB_ZEROFILL 0x0c +#define S_INTERPOSING 0x0d +#define S_16BYTE_LITERALS 0x0e +#define S_DTRACE_DOF 0x0f +#define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10 +#define S_THREAD_LOCAL_REGULAR 0x11 +#define S_THREAD_LOCAL_ZEROFILL 0x12 +#define S_THREAD_LOCAL_VARIABLES 0x13 +#define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14 +#define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15 // Section attributes (use SECTION_ATTRIBUTES mask) -#define S_ATTR_PURE_INSTRUCTIONS 0x80000000 // Only pure instructions -#define S_ATTR_NO_TOC 0x40000000 // Contains coalesced symbols -#define S_ATTR_STRIP_STATIC_SYMS 0x20000000 // Can strip static symbols -#define S_ATTR_NO_DEAD_STRIP 0x10000000 // No dead stripping -#define S_ATTR_LIVE_SUPPORT 0x08000000 // Live blocks support -#define S_ATTR_SELF_MODIFYING_CODE 0x04000000 // Self modifying code -#define S_ATTR_DEBUG 0x02000000 // Debug section -#define S_ATTR_SOME_INSTRUCTIONS 0x00000400 // Some machine instructions -#define S_ATTR_EXT_RELOC 0x00000200 // Has external relocations -#define S_ATTR_LOC_RELOC 0x00000100 // Has local relocations - -#pragma pack(push,1) - -typedef struct { +#define S_ATTR_PURE_INSTRUCTIONS 0x80000000 // Only pure instructions +#define S_ATTR_NO_TOC 0x40000000 // Contains coalesced symbols +#define S_ATTR_STRIP_STATIC_SYMS 0x20000000 // Can strip static symbols +#define S_ATTR_NO_DEAD_STRIP 0x10000000 // No dead stripping +#define S_ATTR_LIVE_SUPPORT 0x08000000 // Live blocks support +#define S_ATTR_SELF_MODIFYING_CODE 0x04000000 // Self modifying code +#define S_ATTR_DEBUG 0x02000000 // Debug section +#define S_ATTR_SOME_INSTRUCTIONS 0x00000400 // Some machine instructions +#define S_ATTR_EXT_RELOC 0x00000200 // Has external relocations +#define S_ATTR_LOC_RELOC 0x00000100 // Has local relocations + +#pragma pack(push, 1) + +typedef struct +{ uint32_t magic; uint32_t cputype; uint32_t cpusubtype; @@ -293,7 +294,8 @@ typedef struct { } yr_mach_header_32_t; -typedef struct { +typedef struct +{ uint32_t magic; uint32_t cputype; uint32_t cpusubtype; @@ -305,13 +307,15 @@ typedef struct { } yr_mach_header_64_t; -typedef struct { +typedef struct +{ uint32_t cmd; uint32_t cmdsize; } yr_load_command_t; -typedef struct { +typedef struct +{ uint32_t cmd; uint32_t cmdsize; char segname[16]; @@ -326,7 +330,8 @@ typedef struct { } yr_segment_command_32_t; -typedef struct { +typedef struct +{ uint32_t cmd; uint32_t cmdsize; char segname[16]; @@ -341,7 +346,8 @@ typedef struct { } yr_segment_command_64_t; -typedef struct { +typedef struct +{ char sectname[16]; char segname[16]; uint32_t addr; @@ -356,7 +362,8 @@ typedef struct { } yr_section_32_t; -typedef struct { +typedef struct +{ char sectname[16]; char segname[16]; uint64_t addr; @@ -372,14 +379,16 @@ typedef struct { } yr_section_64_t; -typedef struct { +typedef struct +{ uint32_t cmd; uint32_t cmdsize; uint8_t uuid[16]; } yr_uuid_command_t; -typedef struct { +typedef struct +{ uint32_t cmd; uint32_t cmdsize; uint64_t entryoff; @@ -387,7 +396,8 @@ typedef struct { } yr_entry_point_command_t; -typedef struct { +typedef struct +{ uint32_t cmd; uint32_t cmdsize; uint32_t flavor; @@ -396,7 +406,8 @@ typedef struct { } yr_thread_command_t; -typedef struct { +typedef struct +{ uint32_t eax; uint32_t ebx; uint32_t ecx; @@ -416,7 +427,8 @@ typedef struct { } yr_x86_thread_state_t; -typedef struct { +typedef struct +{ uint32_t r[13]; uint32_t sp; uint32_t lr; @@ -425,7 +437,8 @@ typedef struct { } yr_arm_thread_state_t; -typedef struct { +typedef struct +{ uint32_t srr0; uint32_t srr1; uint32_t r[32]; @@ -438,7 +451,8 @@ typedef struct { } yr_ppc_thread_state_t; -typedef struct { +typedef struct +{ uint32_t psr; uint32_t pc; uint32_t npc; @@ -461,7 +475,8 @@ typedef struct { } yr_sparc_thread_state_t; -typedef struct { +typedef struct +{ uint32_t dreg[8]; uint32_t areg[8]; uint16_t pad; @@ -470,7 +485,8 @@ typedef struct { } yr_m68k_thread_state_t; -typedef struct { +typedef struct +{ uint32_t r1; uint32_t r2; uint32_t r3; @@ -508,7 +524,8 @@ typedef struct { } yr_m88k_thread_state_t; -typedef struct { +typedef struct +{ uint64_t rax; uint64_t rbx; uint64_t rcx; @@ -533,7 +550,8 @@ typedef struct { } yr_x86_thread_state64_t; -typedef struct { +typedef struct +{ uint64_t r[29]; uint64_t fp; uint64_t lr; @@ -543,7 +561,8 @@ typedef struct { } yr_arm_thread_state64_t; -typedef struct { +typedef struct +{ uint64_t srr0; uint64_t srr1; uint64_t r[32]; @@ -555,13 +574,15 @@ typedef struct { } yr_ppc_thread_state64_t; -typedef struct { +typedef struct +{ uint32_t magic; uint32_t nfat_arch; } yr_fat_header_t; -typedef struct { +typedef struct +{ uint32_t cputype; uint32_t cpusubtype; uint32_t offset; @@ -570,7 +591,8 @@ typedef struct { } yr_fat_arch_32_t; -typedef struct { +typedef struct +{ uint32_t cputype; uint32_t cpusubtype; uint64_t offset; diff --git a/libyara/include/yara/mem.h b/libyara/include/yara/mem.h index ff7dc3ec7e..76a6e55e5d 100644 --- a/libyara/include/yara/mem.h +++ b/libyara/include/yara/mem.h @@ -34,36 +34,28 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifdef DMALLOC -#define yr_malloc malloc -#define yr_calloc calloc +#define yr_malloc malloc +#define yr_calloc calloc #define yr_realloc realloc -#define yr_free free -#define yr_strdup strdup +#define yr_free free +#define yr_strdup strdup #define yr_strndup strndup #include #else -void* yr_calloc( - size_t count, - size_t size); +void* yr_calloc(size_t count, size_t size); -void* yr_malloc( - size_t size); +void* yr_malloc(size_t size); -void* yr_realloc( - void* ptr, - size_t size); +void* yr_realloc(void* ptr, size_t size); -void yr_free( - void *ptr); +void yr_free(void* ptr); -char* yr_strdup( - const char *str); +char* yr_strdup(const char* str); -char* yr_strndup( - const char *str, size_t n); +char* yr_strndup(const char* str, size_t n); #endif diff --git a/libyara/include/yara/modules.h b/libyara/include/yara/modules.h index 313c03f3ae..79919fc917 100644 --- a/libyara/include/yara/modules.h +++ b/libyara/include/yara/modules.h @@ -31,360 +31,287 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define YR_MODULES_H #include +#include #include #include -#include - -#include -#include #include #include -#include -#include -#include #include +#include +#include +#include +#include +#include // Concatenation that macro-expands its arguments. -#define YR_CONCAT(arg1, arg2) _YR_CONCAT(arg1, arg2) // expands the arguments. -#define _YR_CONCAT(arg1, arg2) arg1 ## arg2 // do the actual concatenation. +#define YR_CONCAT(arg1, arg2) _YR_CONCAT(arg1, arg2) // expands the arguments. +#define _YR_CONCAT(arg1, arg2) arg1##arg2 // do the actual concatenation. #define module_declarations YR_CONCAT(MODULE_NAME, __declarations) -#define module_load YR_CONCAT(MODULE_NAME, __load) -#define module_unload YR_CONCAT(MODULE_NAME, __unload) -#define module_initialize YR_CONCAT(MODULE_NAME, __initialize) -#define module_finalize YR_CONCAT(MODULE_NAME, __finalize) +#define module_load YR_CONCAT(MODULE_NAME, __load) +#define module_unload YR_CONCAT(MODULE_NAME, __unload) +#define module_initialize YR_CONCAT(MODULE_NAME, __initialize) +#define module_finalize YR_CONCAT(MODULE_NAME, __finalize) -#define begin_declarations \ - int module_declarations(YR_OBJECT* module) { \ - YR_OBJECT* stack[64]; \ - int stack_top = 0; \ - stack[stack_top] = module; +#define begin_declarations \ + int module_declarations(YR_OBJECT* module) \ + { \ + YR_OBJECT* stack[64]; \ + int stack_top = 0; \ + stack[stack_top] = module; #define end_declarations \ - return ERROR_SUCCESS; } - - -#define begin_struct(name) { \ - YR_OBJECT* structure; \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_STRUCTURE, \ - name, \ - stack[stack_top], \ - &structure)); \ - assertf( \ - stack_top < sizeof(stack)/sizeof(stack[0]) - 1, \ - "too many nested structures"); \ - stack[++stack_top] = structure; \ + return ERROR_SUCCESS; \ } -#define begin_struct_array(name) { \ - YR_OBJECT* structure; \ - YR_OBJECT* array; \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_ARRAY, \ - name, \ - stack[stack_top], \ - &array)); \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_STRUCTURE, \ - name, \ - array, \ - &structure)); \ - assertf( \ - stack_top < sizeof(stack)/sizeof(stack[0]) - 1, \ - "too many nested structures"); \ - stack[++stack_top] = structure; \ +#define begin_struct(name) \ + { \ + YR_OBJECT* structure; \ + FAIL_ON_ERROR(yr_object_create( \ + OBJECT_TYPE_STRUCTURE, name, stack[stack_top], &structure)); \ + assertf( \ + stack_top < sizeof(stack) / sizeof(stack[0]) - 1, \ + "too many nested structures"); \ + stack[++stack_top] = structure; \ } -#define begin_struct_dictionary(name) { \ - YR_OBJECT* structure; \ - YR_OBJECT* array; \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_DICTIONARY, \ - name, \ - stack[stack_top], \ - &array)); \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_STRUCTURE, \ - name, \ - array, \ - &structure)); \ - assertf( \ - stack_top < sizeof(stack)/sizeof(stack[0]) - 1, \ - "too many nested structures"); \ - stack[++stack_top] = structure; \ +#define begin_struct_array(name) \ + { \ + YR_OBJECT* structure; \ + YR_OBJECT* array; \ + FAIL_ON_ERROR( \ + yr_object_create(OBJECT_TYPE_ARRAY, name, stack[stack_top], &array)); \ + FAIL_ON_ERROR( \ + yr_object_create(OBJECT_TYPE_STRUCTURE, name, array, &structure)); \ + assertf( \ + stack_top < sizeof(stack) / sizeof(stack[0]) - 1, \ + "too many nested structures"); \ + stack[++stack_top] = structure; \ } -#define end_struct(name) { \ - assert(stack[stack_top]->type == OBJECT_TYPE_STRUCTURE); \ - assertf( \ - strcmp(stack[stack_top]->identifier, name) == 0, \ - "unbalanced begin_struct/end_struct"); \ - stack_top--; \ +#define begin_struct_dictionary(name) \ + { \ + YR_OBJECT* structure; \ + YR_OBJECT* array; \ + FAIL_ON_ERROR(yr_object_create( \ + OBJECT_TYPE_DICTIONARY, name, stack[stack_top], &array)); \ + FAIL_ON_ERROR( \ + yr_object_create(OBJECT_TYPE_STRUCTURE, name, array, &structure)); \ + assertf( \ + stack_top < sizeof(stack) / sizeof(stack[0]) - 1, \ + "too many nested structures"); \ + stack[++stack_top] = structure; \ } -#define end_struct_array(name) end_struct(name) +#define end_struct(name) \ + { \ + assert(stack[stack_top]->type == OBJECT_TYPE_STRUCTURE); \ + assertf( \ + strcmp(stack[stack_top]->identifier, name) == 0, \ + "unbalanced begin_struct/end_struct"); \ + stack_top--; \ + } -#define end_struct_dictionary(name) end_struct(name) +#define end_struct_array(name) \ + end_struct \ + (name) -#define declare_integer(name) { \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_INTEGER, \ - name, \ - stack[stack_top], \ - NULL)); \ - } +#define end_struct_dictionary(name) \ + end_struct \ + (name) -#define declare_integer_array(name) { \ - YR_OBJECT* array; \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_ARRAY, \ - name, \ - stack[stack_top], \ - &array)); \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_INTEGER, \ - name, \ - array, \ - NULL)); \ +#define declare_integer(name) \ + { \ + FAIL_ON_ERROR( \ + yr_object_create(OBJECT_TYPE_INTEGER, name, stack[stack_top], NULL)); \ } -#define declare_integer_dictionary(name) { \ - YR_OBJECT* dict; \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_DICTIONARY, \ - name, \ - stack[stack_top], \ - &dict)); \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_INTEGER, \ - name, \ - dict, \ - NULL)); \ +#define declare_integer_array(name) \ + { \ + YR_OBJECT* array; \ + FAIL_ON_ERROR( \ + yr_object_create(OBJECT_TYPE_ARRAY, name, stack[stack_top], &array)); \ + FAIL_ON_ERROR(yr_object_create(OBJECT_TYPE_INTEGER, name, array, NULL)); \ } -#define declare_float(name) { \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_FLOAT, \ - name, \ - stack[stack_top], \ - NULL)); \ +#define declare_integer_dictionary(name) \ + { \ + YR_OBJECT* dict; \ + FAIL_ON_ERROR(yr_object_create( \ + OBJECT_TYPE_DICTIONARY, name, stack[stack_top], &dict)); \ + FAIL_ON_ERROR(yr_object_create(OBJECT_TYPE_INTEGER, name, dict, NULL)); \ } -#define declare_float_array(name) { \ - YR_OBJECT* array; \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_ARRAY, \ - name, \ - stack[stack_top], \ - &array)); \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_FLOAT, \ - name, \ - array, \ - NULL)); \ +#define declare_float(name) \ + { \ + FAIL_ON_ERROR( \ + yr_object_create(OBJECT_TYPE_FLOAT, name, stack[stack_top], NULL)); \ } -#define declare_float_dictionary(name) { \ - YR_OBJECT* dict; \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_DICTIONARY, \ - name, \ - stack[stack_top], \ - &dict)); \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_FLOAT, \ - name, \ - dict, \ - NULL)); \ +#define declare_float_array(name) \ + { \ + YR_OBJECT* array; \ + FAIL_ON_ERROR( \ + yr_object_create(OBJECT_TYPE_ARRAY, name, stack[stack_top], &array)); \ + FAIL_ON_ERROR(yr_object_create(OBJECT_TYPE_FLOAT, name, array, NULL)); \ } -#define declare_string(name) { \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_STRING, \ - name, \ - stack[stack_top], \ - NULL)); \ +#define declare_float_dictionary(name) \ + { \ + YR_OBJECT* dict; \ + FAIL_ON_ERROR(yr_object_create( \ + OBJECT_TYPE_DICTIONARY, name, stack[stack_top], &dict)); \ + FAIL_ON_ERROR(yr_object_create(OBJECT_TYPE_FLOAT, name, dict, NULL)); \ } -#define declare_string_array(name) { \ - YR_OBJECT* array; \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_ARRAY, \ - name, \ - stack[stack_top], \ - &array)); \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_STRING, \ - name, \ - array, \ - NULL)); \ +#define declare_string(name) \ + { \ + FAIL_ON_ERROR( \ + yr_object_create(OBJECT_TYPE_STRING, name, stack[stack_top], NULL)); \ } -#define declare_string_dictionary(name) { \ - YR_OBJECT* dict; \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_DICTIONARY, \ - name, \ - stack[stack_top], \ - &dict)); \ - FAIL_ON_ERROR(yr_object_create( \ - OBJECT_TYPE_STRING, \ - name, \ - dict, \ - NULL)); \ +#define declare_string_array(name) \ + { \ + YR_OBJECT* array; \ + FAIL_ON_ERROR( \ + yr_object_create(OBJECT_TYPE_ARRAY, name, stack[stack_top], &array)); \ + FAIL_ON_ERROR(yr_object_create(OBJECT_TYPE_STRING, name, array, NULL)); \ } -#define declare_function(name, args_fmt, ret_fmt, func) { \ - YR_OBJECT* function; \ - FAIL_ON_ERROR(yr_object_function_create( \ - name, \ - args_fmt, \ - ret_fmt, \ - func, \ - stack[stack_top], \ - &function)); \ - } +#define declare_string_dictionary(name) \ + { \ + YR_OBJECT* dict; \ + FAIL_ON_ERROR(yr_object_create( \ + OBJECT_TYPE_DICTIONARY, name, stack[stack_top], &dict)); \ + FAIL_ON_ERROR(yr_object_create(OBJECT_TYPE_STRING, name, dict, NULL)); \ + } -#define define_function(func) \ - int func ( \ - YR_VALUE* __args, \ - YR_SCAN_CONTEXT* __context, \ - YR_OBJECT_FUNCTION* __function_obj) +#define declare_function(name, args_fmt, ret_fmt, func) \ + { \ + YR_OBJECT* function; \ + FAIL_ON_ERROR(yr_object_function_create( \ + name, args_fmt, ret_fmt, func, stack[stack_top], &function)); \ + } -#define sized_string_argument(n) \ - (__args[n-1].ss) +#define define_function(func) \ + int func( \ + YR_VALUE* __args, \ + YR_SCAN_CONTEXT* __context, \ + YR_OBJECT_FUNCTION* __function_obj) -#define string_argument(n) \ - (sized_string_argument(n)->c_string) -#define integer_argument(n) \ - (__args[n-1].i) +#define sized_string_argument(n) (__args[n - 1].ss) -#define float_argument(n) \ - (__args[n-1].d) +#define string_argument(n) (sized_string_argument(n)->c_string) -#define regexp_argument(n) \ - ((RE*)(__args[n-1].re)) +#define integer_argument(n) (__args[n - 1].i) +#define float_argument(n) (__args[n - 1].d) -#define module() yr_object_get_root((YR_OBJECT*) __function_obj) -#define parent() (__function_obj->parent) -#define scan_context() (__context) +#define regexp_argument(n) ((RE*) (__args[n - 1].re)) -#define foreach_memory_block(iterator, block) \ - for (block = iterator->first(iterator); \ - block != NULL; \ - block = iterator->next(iterator)) \ +#define module() yr_object_get_root((YR_OBJECT*) __function_obj) +#define parent() (__function_obj->parent) +#define scan_context() (__context) +#define foreach_memory_block(iterator, block) \ + for (block = iterator->first(iterator); block != NULL; \ + block = iterator->next(iterator)) #define first_memory_block(context) \ - (context)->iterator->first((context)->iterator) - + (context)->iterator->first((context)->iterator) #define is_undefined(object, ...) \ - yr_object_has_undefined_value(object, __VA_ARGS__) - - -#define get_object(object, ...) \ - yr_object_lookup(object, 0, __VA_ARGS__) - + yr_object_has_undefined_value(object, __VA_ARGS__) -#define get_integer(object, ...) \ - yr_object_get_integer(object, __VA_ARGS__) +#define get_object(object, ...) yr_object_lookup(object, 0, __VA_ARGS__) -#define get_float(object, ...) \ - yr_object_get_float(object, __VA_ARGS__) +#define get_integer(object, ...) yr_object_get_integer(object, __VA_ARGS__) +#define get_float(object, ...) yr_object_get_float(object, __VA_ARGS__) -#define get_string(object, ...) \ - yr_object_get_string(object, __VA_ARGS__) +#define get_string(object, ...) yr_object_get_string(object, __VA_ARGS__) #define set_integer(value, object, ...) \ - yr_object_set_integer(value, object, __VA_ARGS__) - + yr_object_set_integer(value, object, __VA_ARGS__) #define set_float(value, object, ...) \ - yr_object_set_float(value, object, __VA_ARGS__) - + yr_object_set_float(value, object, __VA_ARGS__) #define set_sized_string(value, len, object, ...) \ - yr_object_set_string(value, len, object, __VA_ARGS__) - + yr_object_set_string(value, len, object, __VA_ARGS__) #define set_string(value, object, ...) \ - set_sized_string(value, (value == NULL) ? 0 : strlen(value), object, __VA_ARGS__) + set_sized_string( \ + value, (value == NULL) ? 0 : strlen(value), object, __VA_ARGS__) -#define return_integer(integer) { \ - assertf( \ - __function_obj->return_obj->type == OBJECT_TYPE_INTEGER, \ - "return type differs from function declaration"); \ - return yr_object_set_integer( \ - (integer), \ - __function_obj->return_obj, \ - NULL); \ - } +#define return_integer(integer) \ + { \ + assertf( \ + __function_obj->return_obj->type == OBJECT_TYPE_INTEGER, \ + "return type differs from function declaration"); \ + return yr_object_set_integer((integer), __function_obj->return_obj, NULL); \ + } -#define return_float(double_) { \ - double d = (double) (double_); \ - assertf( \ - __function_obj->return_obj->type == OBJECT_TYPE_FLOAT, \ - "return type differs from function declaration"); \ - return yr_object_set_float( \ - (d != (double) YR_UNDEFINED) ? d : NAN, \ - __function_obj->return_obj, \ - NULL); \ - } +#define return_float(double_) \ + { \ + double d = (double) (double_); \ + assertf( \ + __function_obj->return_obj->type == OBJECT_TYPE_FLOAT, \ + "return type differs from function declaration"); \ + return yr_object_set_float( \ + (d != (double) YR_UNDEFINED) ? d : NAN, \ + __function_obj->return_obj, \ + NULL); \ + } -#define return_string(string) { \ - char* s = (char*) (string); \ - assertf( \ - __function_obj->return_obj->type == OBJECT_TYPE_STRING, \ - "return type differs from function declaration"); \ - return yr_object_set_string( \ - (s != (char*) YR_UNDEFINED) ? s : NULL, \ - (s != (char*) YR_UNDEFINED) ? strlen(s) : 0, \ - __function_obj->return_obj, \ - NULL); \ - } +#define return_string(string) \ + { \ + char* s = (char*) (string); \ + assertf( \ + __function_obj->return_obj->type == OBJECT_TYPE_STRING, \ + "return type differs from function declaration"); \ + return yr_object_set_string( \ + (s != (char*) YR_UNDEFINED) ? s : NULL, \ + (s != (char*) YR_UNDEFINED) ? strlen(s) : 0, \ + __function_obj->return_obj, \ + NULL); \ + } -typedef int (*YR_EXT_INITIALIZE_FUNC)( - YR_MODULE* module); +typedef int (*YR_EXT_INITIALIZE_FUNC)(YR_MODULE* module); -typedef int (*YR_EXT_FINALIZE_FUNC)( - YR_MODULE* module); +typedef int (*YR_EXT_FINALIZE_FUNC)(YR_MODULE* module); -typedef int (*YR_EXT_DECLARATIONS_FUNC)( - YR_OBJECT* module_object); +typedef int (*YR_EXT_DECLARATIONS_FUNC)(YR_OBJECT* module_object); typedef int (*YR_EXT_LOAD_FUNC)( @@ -394,8 +321,7 @@ typedef int (*YR_EXT_LOAD_FUNC)( size_t module_data_size); -typedef int (*YR_EXT_UNLOAD_FUNC)( - YR_OBJECT* module_object); +typedef int (*YR_EXT_UNLOAD_FUNC)(YR_OBJECT* module_object); struct YR_MODULE @@ -429,12 +355,9 @@ int yr_modules_do_declarations( YR_OBJECT* main_structure); -int yr_modules_load( - const char* module_name, - YR_SCAN_CONTEXT* context); +int yr_modules_load(const char* module_name, YR_SCAN_CONTEXT* context); -int yr_modules_unload_all( - YR_SCAN_CONTEXT* context); +int yr_modules_unload_all(YR_SCAN_CONTEXT* context); #endif diff --git a/libyara/include/yara/notebook.h b/libyara/include/yara/notebook.h index 90f7ec4cca..06b2938adc 100644 --- a/libyara/include/yara/notebook.h +++ b/libyara/include/yara/notebook.h @@ -10,18 +10,13 @@ typedef struct YR_NOTEBOOK YR_NOTEBOOK; -int yr_notebook_create( - size_t page_size, - YR_NOTEBOOK** pool); +int yr_notebook_create(size_t page_size, YR_NOTEBOOK** pool); -int yr_notebook_destroy( - YR_NOTEBOOK* pool); +int yr_notebook_destroy(YR_NOTEBOOK* pool); -void* yr_notebook_alloc( - YR_NOTEBOOK* notebook, - size_t size); +void* yr_notebook_alloc(YR_NOTEBOOK* notebook, size_t size); -#endif // YR_NOTEBOOK_H +#endif // YR_NOTEBOOK_H diff --git a/libyara/include/yara/object.h b/libyara/include/yara/object.h index f1d2a46f3b..e3a3d0fa71 100644 --- a/libyara/include/yara/object.h +++ b/libyara/include/yara/object.h @@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define YR_OBJECT_H #ifdef _MSC_VER - #include #ifndef isnan #define isnan _isnan @@ -42,24 +41,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif #ifndef NAN -#define NAN (INFINITY-INFINITY) +#define NAN (INFINITY - INFINITY) #endif - #endif -#include -#include #include +#include +#include -#define OBJECT_CREATE 1 +#define OBJECT_CREATE 1 -#define OBJECT_TYPE_INTEGER 1 -#define OBJECT_TYPE_STRING 2 -#define OBJECT_TYPE_STRUCTURE 3 -#define OBJECT_TYPE_ARRAY 4 -#define OBJECT_TYPE_FUNCTION 5 -#define OBJECT_TYPE_DICTIONARY 6 -#define OBJECT_TYPE_FLOAT 7 +#define OBJECT_TYPE_INTEGER 1 +#define OBJECT_TYPE_STRING 2 +#define OBJECT_TYPE_STRUCTURE 3 +#define OBJECT_TYPE_ARRAY 4 +#define OBJECT_TYPE_FUNCTION 5 +#define OBJECT_TYPE_DICTIONARY 6 +#define OBJECT_TYPE_FLOAT 7 int yr_object_create( @@ -69,9 +67,7 @@ int yr_object_create( YR_OBJECT** object); -void yr_object_set_canary( - YR_OBJECT* object, - int canary); +void yr_object_set_canary(YR_OBJECT* object, int canary); int yr_object_function_create( @@ -88,18 +84,13 @@ int yr_object_from_external_variable( YR_OBJECT** object); -void yr_object_destroy( - YR_OBJECT* object); +void yr_object_destroy(YR_OBJECT* object); -int yr_object_copy( - YR_OBJECT* object, - YR_OBJECT** object_copy); +int yr_object_copy(YR_OBJECT* object, YR_OBJECT** object_copy); -YR_OBJECT* yr_object_lookup_field( - YR_OBJECT* object, - const char* field_name); +YR_OBJECT* yr_object_lookup_field(YR_OBJECT* object, const char* field_name); YR_OBJECT* yr_object_lookup( @@ -109,26 +100,18 @@ YR_OBJECT* yr_object_lookup( ...) YR_PRINTF_LIKE(3, 4); -bool yr_object_has_undefined_value( - YR_OBJECT* object, - const char* field, - ...) YR_PRINTF_LIKE(2, 3); +bool yr_object_has_undefined_value(YR_OBJECT* object, const char* field, ...) + YR_PRINTF_LIKE(2, 3); -double yr_object_get_float( - YR_OBJECT* object, - const char* field, - ...) YR_PRINTF_LIKE(2, 3); +double yr_object_get_float(YR_OBJECT* object, const char* field, ...) + YR_PRINTF_LIKE(2, 3); -int64_t yr_object_get_integer( - YR_OBJECT* object, - const char* field, - ...) YR_PRINTF_LIKE(2, 3); +int64_t yr_object_get_integer(YR_OBJECT* object, const char* field, ...) + YR_PRINTF_LIKE(2, 3); -SIZED_STRING* yr_object_get_string( - YR_OBJECT* object, - const char* field, - ...) YR_PRINTF_LIKE(2, 3); +SIZED_STRING* yr_object_get_string(YR_OBJECT* object, const char* field, ...) + YR_PRINTF_LIKE(2, 3); int yr_object_set_integer( @@ -138,11 +121,8 @@ int yr_object_set_integer( ...) YR_PRINTF_LIKE(3, 4); -int yr_object_set_float( - double value, - YR_OBJECT* object, - const char* field, - ...) YR_PRINTF_LIKE(3, 4); +int yr_object_set_float(double value, YR_OBJECT* object, const char* field, ...) + YR_PRINTF_LIKE(3, 4); int yr_object_set_string( @@ -153,20 +133,13 @@ int yr_object_set_string( ...) YR_PRINTF_LIKE(4, 5); -int yr_object_array_length( - YR_OBJECT* object); +int yr_object_array_length(YR_OBJECT* object); -YR_OBJECT* yr_object_array_get_item( - YR_OBJECT* object, - int flags, - int index); +YR_OBJECT* yr_object_array_get_item(YR_OBJECT* object, int flags, int index); -int yr_object_array_set_item( - YR_OBJECT* object, - YR_OBJECT* item, - int index); +int yr_object_array_set_item(YR_OBJECT* object, YR_OBJECT* item, int index); YR_OBJECT* yr_object_dict_get_item( @@ -181,13 +154,10 @@ int yr_object_dict_set_item( const char* key); -int yr_object_structure_set_member( - YR_OBJECT* object, - YR_OBJECT* member); +int yr_object_structure_set_member(YR_OBJECT* object, YR_OBJECT* member); -YR_OBJECT* yr_object_get_root( - YR_OBJECT* object); +YR_OBJECT* yr_object_get_root(YR_OBJECT* object); YR_API void yr_object_print_data( diff --git a/libyara/include/yara/parser.h b/libyara/include/yara/parser.h index c873839369..e7a01cff13 100644 --- a/libyara/include/yara/parser.h +++ b/libyara/include/yara/parser.h @@ -72,9 +72,7 @@ int yr_parser_emit_with_arg_reloc( YR_ARENA_REF* argument_ref); -int yr_parser_emit_push_const( - yyscan_t yyscanner, - uint64_t argument); +int yr_parser_emit_push_const(yyscan_t yyscanner, uint64_t argument); int yr_parser_check_types( @@ -142,9 +140,7 @@ int yr_parser_reduce_external( uint8_t instruction); -int yr_parser_reduce_import( - yyscan_t yyscanner, - SIZED_STRING* module_name); +int yr_parser_reduce_import(yyscan_t yyscanner, SIZED_STRING* module_name); int yr_parser_reduce_operation( diff --git a/libyara/include/yara/pe.h b/libyara/include/yara/pe.h index 4e9b363925..68498164c4 100644 --- a/libyara/include/yara/pe.h +++ b/libyara/include/yara/pe.h @@ -45,68 +45,67 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // These definitions are not present in older Windows headers. #ifndef IMAGE_FILE_MACHINE_ARMNT -#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 +#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 #endif #ifndef IMAGE_FILE_MACHINE_ARM64 -#define IMAGE_FILE_MACHINE_ARM64 0xaa64 +#define IMAGE_FILE_MACHINE_ARM64 0xaa64 #endif - #else #include - #include -typedef uint8_t BYTE; -typedef uint16_t WORD; -typedef uint32_t DWORD; -typedef int32_t LONG; -typedef uint32_t ULONG; -typedef uint64_t ULONGLONG; +typedef uint8_t BYTE; +typedef uint16_t WORD; +typedef uint32_t DWORD; +typedef int32_t LONG; +typedef uint32_t ULONG; +typedef uint64_t ULONGLONG; #ifndef _MAC -#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ -#define IMAGE_OS2_SIGNATURE 0x454E // NE -#define IMAGE_OS2_SIGNATURE_LE 0x454C // LE -#define IMAGE_VXD_SIGNATURE 0x454C // LE -#define IMAGE_NT_SIGNATURE 0x00004550 // PE00 +#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ +#define IMAGE_OS2_SIGNATURE 0x454E // NE +#define IMAGE_OS2_SIGNATURE_LE 0x454C // LE +#define IMAGE_VXD_SIGNATURE 0x454C // LE +#define IMAGE_NT_SIGNATURE 0x00004550 // PE00 #else -#define IMAGE_DOS_SIGNATURE 0x4D5A // MZ -#define IMAGE_OS2_SIGNATURE 0x4E45 // NE -#define IMAGE_OS2_SIGNATURE_LE 0x4C45 // LE -#define IMAGE_NT_SIGNATURE 0x50450000 // PE00 +#define IMAGE_DOS_SIGNATURE 0x4D5A // MZ +#define IMAGE_OS2_SIGNATURE 0x4E45 // NE +#define IMAGE_OS2_SIGNATURE_LE 0x4C45 // LE +#define IMAGE_NT_SIGNATURE 0x50450000 // PE00 #endif #pragma pack(push, 2) -typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header - WORD e_magic; // Magic number - WORD e_cblp; // Bytes on last page of file - WORD e_cp; // Pages in file - WORD e_crlc; // Relocations - WORD e_cparhdr; // Size of header in paragraphs - WORD e_minalloc; // Minimum extra paragraphs needed - WORD e_maxalloc; // Maximum extra paragraphs needed - WORD e_ss; // Initial (relative) SS value - WORD e_sp; // Initial SP value - WORD e_csum; // Checksum - WORD e_ip; // Initial IP value - WORD e_cs; // Initial (relative) CS value - WORD e_lfarlc; // File address of relocation table - WORD e_ovno; // Overlay number - WORD e_res[4]; // Reserved words - WORD e_oemid; // OEM identifier (for e_oeminfo) - WORD e_oeminfo; // OEM information; e_oemid specific - WORD e_res2[10]; // Reserved words - LONG e_lfanew; // File address of new exe header - } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER; +typedef struct _IMAGE_DOS_HEADER +{ // DOS .EXE header + WORD e_magic; // Magic number + WORD e_cblp; // Bytes on last page of file + WORD e_cp; // Pages in file + WORD e_crlc; // Relocations + WORD e_cparhdr; // Size of header in paragraphs + WORD e_minalloc; // Minimum extra paragraphs needed + WORD e_maxalloc; // Maximum extra paragraphs needed + WORD e_ss; // Initial (relative) SS value + WORD e_sp; // Initial SP value + WORD e_csum; // Checksum + WORD e_ip; // Initial IP value + WORD e_cs; // Initial (relative) CS value + WORD e_lfarlc; // File address of relocation table + WORD e_ovno; // Overlay number + WORD e_res[4]; // Reserved words + WORD e_oemid; // OEM identifier (for e_oeminfo) + WORD e_oeminfo; // OEM information; e_oemid specific + WORD e_res2[10]; // Reserved words + LONG e_lfanew; // File address of new exe header +} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER; #pragma pack(pop) @@ -114,301 +113,328 @@ typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header // File header format. // -#pragma pack(push,4) - -typedef struct _IMAGE_FILE_HEADER { - WORD Machine; - WORD NumberOfSections; - DWORD TimeDateStamp; - DWORD PointerToSymbolTable; - DWORD NumberOfSymbols; - WORD SizeOfOptionalHeader; - WORD Characteristics; +#pragma pack(push, 4) + +typedef struct _IMAGE_FILE_HEADER +{ + WORD Machine; + WORD NumberOfSections; + DWORD TimeDateStamp; + DWORD PointerToSymbolTable; + DWORD NumberOfSymbols; + WORD SizeOfOptionalHeader; + WORD Characteristics; } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER; - -#define IMAGE_SIZEOF_FILE_HEADER 20 - - -#define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file. -#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved external references). -#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line numbers stripped from file. -#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file. -#define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010 // Aggressively trim working set -#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 // App can handle >2gb addresses -#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed. -#define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine. -#define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file -#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 // If Image is on removable media, copy and run from the swap file. -#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 // If Image is on Net, copy and run from the swap file. -#define IMAGE_FILE_SYSTEM 0x1000 // System File. -#define IMAGE_FILE_DLL 0x2000 // File is a DLL. -#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 // File should only be run on a UP machine -#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed. - - -#define IMAGE_FILE_MACHINE_UNKNOWN 0x0000 -#define IMAGE_FILE_MACHINE_AM33 0x01d3 -#define IMAGE_FILE_MACHINE_AMD64 0x8664 -#define IMAGE_FILE_MACHINE_ARM 0x01c0 -#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 -#define IMAGE_FILE_MACHINE_ARM64 0xaa64 -#define IMAGE_FILE_MACHINE_EBC 0x0ebc -#define IMAGE_FILE_MACHINE_I386 0x014c -#define IMAGE_FILE_MACHINE_IA64 0x0200 -#define IMAGE_FILE_MACHINE_M32R 0x9041 -#define IMAGE_FILE_MACHINE_MIPS16 0x0266 -#define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 -#define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 -#define IMAGE_FILE_MACHINE_POWERPC 0x01f0 -#define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 -#define IMAGE_FILE_MACHINE_R4000 0x0166 -#define IMAGE_FILE_MACHINE_SH3 0x01a2 -#define IMAGE_FILE_MACHINE_SH3DSP 0x01a3 -#define IMAGE_FILE_MACHINE_SH4 0x01a6 -#define IMAGE_FILE_MACHINE_SH5 0x01a8 -#define IMAGE_FILE_MACHINE_THUMB 0x01c2 -#define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 +#define IMAGE_SIZEOF_FILE_HEADER 20 + +// Relocation info stripped from file. +#define IMAGE_FILE_RELOCS_STRIPPED 0x0001 +// File is executable (i.e. no unresolved external references). +#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 +// Line numbers stripped from file. +#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 +// Local symbols stripped from file. +#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 +// Aggressively trim working set +#define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010 +// App can handle >2gb addresses +#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 +// Bytes of machine word are reversed. +#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 +// 32 bit word machine. +#define IMAGE_FILE_32BIT_MACHINE 0x0100 +// Debugging info stripped from file in .DBG file +#define IMAGE_FILE_DEBUG_STRIPPED 0x0200 +// If Image is on removable media, copy and run from the swap file. +#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 +// If Image is on Net, copy and run from the swap file. +#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800 +// System File. +#define IMAGE_FILE_SYSTEM 0x1000 +// File is a DLL.s +#define IMAGE_FILE_DLL 0x2000 +// File should only be run on a UP machine +#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 +// Bytes of machine word are reversed. +#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 + + +#define IMAGE_FILE_MACHINE_UNKNOWN 0x0000 +#define IMAGE_FILE_MACHINE_AM33 0x01d3 +#define IMAGE_FILE_MACHINE_AMD64 0x8664 +#define IMAGE_FILE_MACHINE_ARM 0x01c0 +#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 +#define IMAGE_FILE_MACHINE_ARM64 0xaa64 +#define IMAGE_FILE_MACHINE_EBC 0x0ebc +#define IMAGE_FILE_MACHINE_I386 0x014c +#define IMAGE_FILE_MACHINE_IA64 0x0200 +#define IMAGE_FILE_MACHINE_M32R 0x9041 +#define IMAGE_FILE_MACHINE_MIPS16 0x0266 +#define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 +#define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 +#define IMAGE_FILE_MACHINE_POWERPC 0x01f0 +#define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 +#define IMAGE_FILE_MACHINE_R4000 0x0166 +#define IMAGE_FILE_MACHINE_SH3 0x01a2 +#define IMAGE_FILE_MACHINE_SH3DSP 0x01a3 +#define IMAGE_FILE_MACHINE_SH4 0x01a6 +#define IMAGE_FILE_MACHINE_SH5 0x01a8 +#define IMAGE_FILE_MACHINE_THUMB 0x01c2 +#define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 // Section characteristics -#define IMAGE_SCN_CNT_CODE 0x00000020 -#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 -#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 -#define IMAGE_SCN_GPREL 0x00008000 -#define IMAGE_SCN_MEM_16BIT 0x00020000 -#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 -#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 -#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 -#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 -#define IMAGE_SCN_MEM_SHARED 0x10000000 -#define IMAGE_SCN_MEM_EXECUTE 0x20000000 -#define IMAGE_SCN_MEM_READ 0x40000000 -#define IMAGE_SCN_MEM_WRITE 0x80000000 +#define IMAGE_SCN_CNT_CODE 0x00000020 +#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 +#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 +#define IMAGE_SCN_GPREL 0x00008000 +#define IMAGE_SCN_MEM_16BIT 0x00020000 +#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 +#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 +#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 +#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 +#define IMAGE_SCN_MEM_SHARED 0x10000000 +#define IMAGE_SCN_MEM_EXECUTE 0x20000000 +#define IMAGE_SCN_MEM_READ 0x40000000 +#define IMAGE_SCN_MEM_WRITE 0x80000000 // // Directory format. // -typedef struct _IMAGE_DATA_DIRECTORY { - DWORD VirtualAddress; - DWORD Size; +typedef struct _IMAGE_DATA_DIRECTORY +{ + DWORD VirtualAddress; + DWORD Size; } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY; -#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16 +#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16 -#define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory -#define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory -#define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory -#define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory -#define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory -#define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table -#define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory -#define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // (X86 usage) -#define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 // Architecture Specific Data -#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // RVA of GP -#define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory -#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory -#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 // Bound Import Directory in headers -#define IMAGE_DIRECTORY_ENTRY_IAT 12 // Import Address Table -#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 // Delay Load Import Descriptors -#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 // COM Runtime descriptor +#define IMAGE_DIRECTORY_ENTRY_EXPORT 0 +#define IMAGE_DIRECTORY_ENTRY_IMPORT 1 +#define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 +#define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 +#define IMAGE_DIRECTORY_ENTRY_SECURITY 4 +#define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 +#define IMAGE_DIRECTORY_ENTRY_DEBUG 6 +#define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 +#define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 +#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 +#define IMAGE_DIRECTORY_ENTRY_TLS 9 +#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 +#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 +#define IMAGE_DIRECTORY_ENTRY_IAT 12 +#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 +#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 // // Optional header format. // -typedef struct _IMAGE_OPTIONAL_HEADER32 { - WORD Magic; - BYTE MajorLinkerVersion; - BYTE MinorLinkerVersion; - DWORD SizeOfCode; - DWORD SizeOfInitializedData; - DWORD SizeOfUninitializedData; - DWORD AddressOfEntryPoint; - DWORD BaseOfCode; - DWORD BaseOfData; - DWORD ImageBase; - DWORD SectionAlignment; - DWORD FileAlignment; - WORD MajorOperatingSystemVersion; - WORD MinorOperatingSystemVersion; - WORD MajorImageVersion; - WORD MinorImageVersion; - WORD MajorSubsystemVersion; - WORD MinorSubsystemVersion; - DWORD Win32VersionValue; - DWORD SizeOfImage; - DWORD SizeOfHeaders; - DWORD CheckSum; - WORD Subsystem; - WORD DllCharacteristics; - DWORD SizeOfStackReserve; - DWORD SizeOfStackCommit; - DWORD SizeOfHeapReserve; - DWORD SizeOfHeapCommit; - DWORD LoaderFlags; - DWORD NumberOfRvaAndSizes; - IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; +typedef struct _IMAGE_OPTIONAL_HEADER32 +{ + WORD Magic; + BYTE MajorLinkerVersion; + BYTE MinorLinkerVersion; + DWORD SizeOfCode; + DWORD SizeOfInitializedData; + DWORD SizeOfUninitializedData; + DWORD AddressOfEntryPoint; + DWORD BaseOfCode; + DWORD BaseOfData; + DWORD ImageBase; + DWORD SectionAlignment; + DWORD FileAlignment; + WORD MajorOperatingSystemVersion; + WORD MinorOperatingSystemVersion; + WORD MajorImageVersion; + WORD MinorImageVersion; + WORD MajorSubsystemVersion; + WORD MinorSubsystemVersion; + DWORD Win32VersionValue; + DWORD SizeOfImage; + DWORD SizeOfHeaders; + DWORD CheckSum; + WORD Subsystem; + WORD DllCharacteristics; + DWORD SizeOfStackReserve; + DWORD SizeOfStackCommit; + DWORD SizeOfHeapReserve; + DWORD SizeOfHeapCommit; + DWORD LoaderFlags; + DWORD NumberOfRvaAndSizes; + IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; } IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32; -typedef struct _IMAGE_OPTIONAL_HEADER64 { - WORD Magic; - BYTE MajorLinkerVersion; - BYTE MinorLinkerVersion; - DWORD SizeOfCode; - DWORD SizeOfInitializedData; - DWORD SizeOfUninitializedData; - DWORD AddressOfEntryPoint; - DWORD BaseOfCode; - ULONGLONG ImageBase; - DWORD SectionAlignment; - DWORD FileAlignment; - WORD MajorOperatingSystemVersion; - WORD MinorOperatingSystemVersion; - WORD MajorImageVersion; - WORD MinorImageVersion; - WORD MajorSubsystemVersion; - WORD MinorSubsystemVersion; - DWORD Win32VersionValue; - DWORD SizeOfImage; - DWORD SizeOfHeaders; - DWORD CheckSum; - WORD Subsystem; - WORD DllCharacteristics; - ULONGLONG SizeOfStackReserve; - ULONGLONG SizeOfStackCommit; - ULONGLONG SizeOfHeapReserve; - ULONGLONG SizeOfHeapCommit; - DWORD LoaderFlags; - DWORD NumberOfRvaAndSizes; - IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; +typedef struct _IMAGE_OPTIONAL_HEADER64 +{ + WORD Magic; + BYTE MajorLinkerVersion; + BYTE MinorLinkerVersion; + DWORD SizeOfCode; + DWORD SizeOfInitializedData; + DWORD SizeOfUninitializedData; + DWORD AddressOfEntryPoint; + DWORD BaseOfCode; + ULONGLONG ImageBase; + DWORD SectionAlignment; + DWORD FileAlignment; + WORD MajorOperatingSystemVersion; + WORD MinorOperatingSystemVersion; + WORD MajorImageVersion; + WORD MinorImageVersion; + WORD MajorSubsystemVersion; + WORD MinorSubsystemVersion; + DWORD Win32VersionValue; + DWORD SizeOfImage; + DWORD SizeOfHeaders; + DWORD CheckSum; + WORD Subsystem; + WORD DllCharacteristics; + ULONGLONG SizeOfStackReserve; + ULONGLONG SizeOfStackCommit; + ULONGLONG SizeOfHeapReserve; + ULONGLONG SizeOfHeapCommit; + DWORD LoaderFlags; + DWORD NumberOfRvaAndSizes; + IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; } IMAGE_OPTIONAL_HEADER64, *PIMAGE_OPTIONAL_HEADER64; -#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b -#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b +#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b +#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b -typedef struct _IMAGE_NT_HEADERS32 { - DWORD Signature; - IMAGE_FILE_HEADER FileHeader; - IMAGE_OPTIONAL_HEADER32 OptionalHeader; +typedef struct _IMAGE_NT_HEADERS32 +{ + DWORD Signature; + IMAGE_FILE_HEADER FileHeader; + IMAGE_OPTIONAL_HEADER32 OptionalHeader; } IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32; -typedef struct _IMAGE_NT_HEADERS64 { - DWORD Signature; - IMAGE_FILE_HEADER FileHeader; - IMAGE_OPTIONAL_HEADER64 OptionalHeader; +typedef struct _IMAGE_NT_HEADERS64 +{ + DWORD Signature; + IMAGE_FILE_HEADER FileHeader; + IMAGE_OPTIONAL_HEADER64 OptionalHeader; } IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64; // IMAGE_FIRST_SECTION doesn't need 32/64 versions since the file header is // the same either way. -#define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER) \ - ((BYTE*) ntheader + \ - offsetof(IMAGE_NT_HEADERS32, OptionalHeader) + \ - yr_le16toh(((PIMAGE_NT_HEADERS32)(ntheader))->FileHeader.SizeOfOptionalHeader) \ - )) +#define IMAGE_FIRST_SECTION(ntheader) \ + ((PIMAGE_SECTION_HEADER)( \ + (BYTE*) ntheader + offsetof(IMAGE_NT_HEADERS32, OptionalHeader) + \ + yr_le16toh(((PIMAGE_NT_HEADERS32)(ntheader)) \ + ->FileHeader.SizeOfOptionalHeader))) // Subsystem Values -#define IMAGE_SUBSYSTEM_UNKNOWN 0 -#define IMAGE_SUBSYSTEM_NATIVE 1 -#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 -#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 -#define IMAGE_SUBSYSTEM_OS2_CUI 5 -#define IMAGE_SUBSYSTEM_POSIX_CUI 7 -#define IMAGE_SUBSYSTEM_NATIVE_WINDOWS 8 -#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 -#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 -#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 -#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 -#define IMAGE_SUBSYSTEM_EFI_ROM_IMAGE 13 -#define IMAGE_SUBSYSTEM_XBOX 14 -#define IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION 16 +#define IMAGE_SUBSYSTEM_UNKNOWN 0 +#define IMAGE_SUBSYSTEM_NATIVE 1 +#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 +#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 +#define IMAGE_SUBSYSTEM_OS2_CUI 5 +#define IMAGE_SUBSYSTEM_POSIX_CUI 7 +#define IMAGE_SUBSYSTEM_NATIVE_WINDOWS 8 +#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9 +#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10 +#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 +#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 +#define IMAGE_SUBSYSTEM_EFI_ROM_IMAGE 13 +#define IMAGE_SUBSYSTEM_XBOX 14 +#define IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION 16 // DllCharacteristics values -#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040 -#define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY 0x0080 -#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100 -#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200 -#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400 -#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 -#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 -#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000 +#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040 +#define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY 0x0080 +#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100 +#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200 +#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400 +#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 +#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 +#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000 // // Section header format. // -#define IMAGE_SIZEOF_SHORT_NAME 8 - -typedef struct _IMAGE_SECTION_HEADER { - BYTE Name[IMAGE_SIZEOF_SHORT_NAME]; - union { - DWORD PhysicalAddress; - DWORD VirtualSize; - } Misc; - DWORD VirtualAddress; - DWORD SizeOfRawData; - DWORD PointerToRawData; - DWORD PointerToRelocations; - DWORD PointerToLinenumbers; - WORD NumberOfRelocations; - WORD NumberOfLinenumbers; - DWORD Characteristics; +#define IMAGE_SIZEOF_SHORT_NAME 8 + +typedef struct _IMAGE_SECTION_HEADER +{ + BYTE Name[IMAGE_SIZEOF_SHORT_NAME]; + union + { + DWORD PhysicalAddress; + DWORD VirtualSize; + } Misc; + DWORD VirtualAddress; + DWORD SizeOfRawData; + DWORD PointerToRawData; + DWORD PointerToRelocations; + DWORD PointerToLinenumbers; + WORD NumberOfRelocations; + WORD NumberOfLinenumbers; + DWORD Characteristics; } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER; -#define IMAGE_SIZEOF_SECTION_HEADER 40 - - -typedef struct _IMAGE_EXPORT_DIRECTORY { - DWORD Characteristics; - DWORD TimeDateStamp; - WORD MajorVersion; - WORD MinorVersion; - DWORD Name; - DWORD Base; - DWORD NumberOfFunctions; - DWORD NumberOfNames; - DWORD AddressOfFunctions; - DWORD AddressOfNames; - DWORD AddressOfNameOrdinals; +#define IMAGE_SIZEOF_SECTION_HEADER 40 + + +typedef struct _IMAGE_EXPORT_DIRECTORY +{ + DWORD Characteristics; + DWORD TimeDateStamp; + WORD MajorVersion; + WORD MinorVersion; + DWORD Name; + DWORD Base; + DWORD NumberOfFunctions; + DWORD NumberOfNames; + DWORD AddressOfFunctions; + DWORD AddressOfNames; + DWORD AddressOfNameOrdinals; } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY; -typedef struct _IMAGE_IMPORT_DESCRIPTOR { - union { - DWORD Characteristics; - DWORD OriginalFirstThunk; - } ; - DWORD TimeDateStamp; - DWORD ForwarderChain; - DWORD Name; - DWORD FirstThunk; +typedef struct _IMAGE_IMPORT_DESCRIPTOR +{ + union + { + DWORD Characteristics; + DWORD OriginalFirstThunk; + }; + DWORD TimeDateStamp; + DWORD ForwarderChain; + DWORD Name; + DWORD FirstThunk; } IMAGE_IMPORT_DESCRIPTOR, *PIMAGE_IMPORT_DESCRIPTOR; -typedef struct _IMAGE_IMPORT_BY_NAME { +typedef struct _IMAGE_IMPORT_BY_NAME +{ WORD Hint; BYTE Name[1]; } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME; -typedef struct _IMAGE_THUNK_DATA32 { - union { +typedef struct _IMAGE_THUNK_DATA32 +{ + union + { DWORD ForwarderString; DWORD Function; DWORD Ordinal; @@ -418,11 +444,13 @@ typedef struct _IMAGE_THUNK_DATA32 { } IMAGE_THUNK_DATA32, *PIMAGE_THUNK_DATA32; -#define IMAGE_ORDINAL_FLAG32 0x80000000 -#define IMAGE_ORDINAL_FLAG64 0x8000000000000000L +#define IMAGE_ORDINAL_FLAG32 0x80000000 +#define IMAGE_ORDINAL_FLAG64 0x8000000000000000L -typedef struct _IMAGE_THUNK_DATA64 { - union { +typedef struct _IMAGE_THUNK_DATA64 +{ + union + { ULONGLONG ForwarderString; ULONGLONG Function; ULONGLONG Ordinal; @@ -432,80 +460,88 @@ typedef struct _IMAGE_THUNK_DATA64 { } IMAGE_THUNK_DATA64, *PIMAGE_THUNK_DATA64; -typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY { - DWORD Name; - DWORD OffsetToData; +typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY +{ + DWORD Name; + DWORD OffsetToData; } IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY; - typedef struct _IMAGE_RESOURCE_DATA_ENTRY { - DWORD OffsetToData; - DWORD Size; - DWORD CodePage; - DWORD Reserved; - } IMAGE_RESOURCE_DATA_ENTRY,*PIMAGE_RESOURCE_DATA_ENTRY; +typedef struct _IMAGE_RESOURCE_DATA_ENTRY +{ + DWORD OffsetToData; + DWORD Size; + DWORD CodePage; + DWORD Reserved; +} IMAGE_RESOURCE_DATA_ENTRY, *PIMAGE_RESOURCE_DATA_ENTRY; -typedef struct _IMAGE_RESOURCE_DIRECTORY { - DWORD Characteristics; - DWORD TimeDateStamp; - WORD MajorVersion; - WORD MinorVersion; - WORD NumberOfNamedEntries; - WORD NumberOfIdEntries; +typedef struct _IMAGE_RESOURCE_DIRECTORY +{ + DWORD Characteristics; + DWORD TimeDateStamp; + WORD MajorVersion; + WORD MinorVersion; + WORD NumberOfNamedEntries; + WORD NumberOfIdEntries; } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY; -#define IMAGE_DEBUG_TYPE_UNKNOWN 0 -#define IMAGE_DEBUG_TYPE_COFF 1 -#define IMAGE_DEBUG_TYPE_CODEVIEW 2 -#define IMAGE_DEBUG_TYPE_FPO 3 -#define IMAGE_DEBUG_TYPE_MISC 4 -#define IMAGE_DEBUG_TYPE_EXCEPTION 5 -#define IMAGE_DEBUG_TYPE_FIXUP 6 -#define IMAGE_DEBUG_TYPE_BORLAND 9 - -typedef struct _IMAGE_DEBUG_DIRECTORY { - DWORD Characteristics; - DWORD TimeDateStamp; - WORD MajorVersion; - WORD MinorVersion; - DWORD Type; - DWORD SizeOfData; - DWORD AddressOfRawData; - DWORD PointerToRawData; +#define IMAGE_DEBUG_TYPE_UNKNOWN 0 +#define IMAGE_DEBUG_TYPE_COFF 1 +#define IMAGE_DEBUG_TYPE_CODEVIEW 2 +#define IMAGE_DEBUG_TYPE_FPO 3 +#define IMAGE_DEBUG_TYPE_MISC 4 +#define IMAGE_DEBUG_TYPE_EXCEPTION 5 +#define IMAGE_DEBUG_TYPE_FIXUP 6 +#define IMAGE_DEBUG_TYPE_BORLAND 9 + +typedef struct _IMAGE_DEBUG_DIRECTORY +{ + DWORD Characteristics; + DWORD TimeDateStamp; + WORD MajorVersion; + WORD MinorVersion; + DWORD Type; + DWORD SizeOfData; + DWORD AddressOfRawData; + DWORD PointerToRawData; } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY; #pragma pack(pop) #endif // _WIN32 -#define CVINFO_PDB70_CVSIGNATURE 0x53445352 // "RSDS" -#define CVINFO_PDB20_CVSIGNATURE 0x3031424e // "NB10" +#define CVINFO_PDB70_CVSIGNATURE 0x53445352 // "RSDS" +#define CVINFO_PDB20_CVSIGNATURE 0x3031424e // "NB10" -typedef struct _CV_HEADER { - DWORD dwSignature; - DWORD dwOffset; +typedef struct _CV_HEADER +{ + DWORD dwSignature; + DWORD dwOffset; } CV_HEADER, *PCV_HEADER; -typedef struct _CV_INFO_PDB20 { - CV_HEADER CvHeader; - DWORD dwSignature; - DWORD dwAge; - BYTE PdbFileName[1]; +typedef struct _CV_INFO_PDB20 +{ + CV_HEADER CvHeader; + DWORD dwSignature; + DWORD dwAge; + BYTE PdbFileName[1]; } CV_INFO_PDB20, *PCV_INFO_PDB20; -typedef struct _CV_INFO_PDB70 { - DWORD CvSignature; - DWORD Signature[4]; - DWORD Age; - BYTE PdbFileName[1]; +typedef struct _CV_INFO_PDB70 +{ + DWORD CvSignature; + DWORD Signature[4]; + DWORD Age; + BYTE PdbFileName[1]; } CV_INFO_PDB70, *PCV_INFO_PDB70; -typedef struct _VERSION_INFO { - WORD Length; - WORD ValueLength; - WORD Type; - char Key[0]; +typedef struct _VERSION_INFO +{ + WORD Length; + WORD ValueLength; + WORD Type; + char Key[0]; } VERSION_INFO, *PVERSION_INFO; @@ -519,16 +555,17 @@ typedef struct _VERSION_INFO { #define WIN_CERT_TYPE_RESERVED_1 0x0003 #define WIN_CERT_TYPE_TS_STACK_SIGNED 0x0004 -#define WIN_CERTIFICATE_HEADER_SIZE 8 +#define WIN_CERTIFICATE_HEADER_SIZE 8 -typedef struct _WIN_CERTIFICATE { - DWORD Length; - WORD Revision; - WORD CertificateType; - BYTE Certificate[0]; +typedef struct _WIN_CERTIFICATE +{ + DWORD Length; + WORD Revision; + WORD CertificateType; + BYTE Certificate[0]; } WIN_CERTIFICATE, *PWIN_CERTIFICATE; -#define SPC_NESTED_SIGNATURE_OBJID "1.3.6.1.4.1.311.2.4.1" +#define SPC_NESTED_SIGNATURE_OBJID "1.3.6.1.4.1.311.2.4.1" // @@ -536,24 +573,27 @@ typedef struct _WIN_CERTIFICATE { // http://www.ntcore.com/files/richsign.htm // -#define RICH_VERSION_ID(id_version) (id_version >> 16) +#define RICH_VERSION_ID(id_version) (id_version >> 16) #define RICH_VERSION_VERSION(id_version) (id_version & 0xFFFF) -typedef struct _RICH_VERSION_INFO { - DWORD id_version; //tool id and version (use RICH_VERSION_ID and RICH_VERSION_VERSION macros) - DWORD times; //number of times this tool was used +typedef struct _RICH_VERSION_INFO +{ + DWORD id_version; // tool id and version (use RICH_VERSION_ID and + // RICH_VERSION_VERSION macros) + DWORD times; // number of times this tool was used } RICH_VERSION_INFO, *PRICH_VERSION_INFO; -typedef struct _RICH_SIGNATURE { - DWORD dans; - DWORD key1; - DWORD key2; - DWORD key3; - RICH_VERSION_INFO versions[0]; +typedef struct _RICH_SIGNATURE +{ + DWORD dans; + DWORD key1; + DWORD key2; + DWORD key3; + RICH_VERSION_INFO versions[0]; } RICH_SIGNATURE, *PRICH_SIGNATURE; -#define RICH_DANS 0x536e6144 // "DanS" -#define RICH_RICH 0x68636952 // "Rich" +#define RICH_DANS 0x536e6144 // "DanS" +#define RICH_RICH 0x68636952 // "Rich" #pragma pack(pop) diff --git a/libyara/include/yara/pe_utils.h b/libyara/include/yara/pe_utils.h index 8ac46428e9..9ab7fa2f45 100644 --- a/libyara/include/yara/pe_utils.h +++ b/libyara/include/yara/pe_utils.h @@ -3,17 +3,17 @@ #include -#define MAX_PE_SECTIONS 96 +#define MAX_PE_SECTIONS 96 -#define IS_64BITS_PE(pe) \ - (yr_le16toh(pe->header64->OptionalHeader.Magic) == IMAGE_NT_OPTIONAL_HDR64_MAGIC) +#define IS_64BITS_PE(pe) \ + (yr_le16toh(pe->header64->OptionalHeader.Magic) == \ + IMAGE_NT_OPTIONAL_HDR64_MAGIC) -#define OptionalHeader(pe,field) \ - (IS_64BITS_PE(pe) ? \ - pe->header64->OptionalHeader.field : \ - pe->header->OptionalHeader.field) +#define OptionalHeader(pe, field) \ + (IS_64BITS_PE(pe) ? pe->header64->OptionalHeader.field \ + : pe->header->OptionalHeader.field) // @@ -25,10 +25,10 @@ typedef struct _IMPORTED_DLL { - char *name; + char* name; - struct _IMPORT_FUNCTION *functions; - struct _IMPORTED_DLL *next; + struct _IMPORT_FUNCTION* functions; + struct _IMPORTED_DLL* next; } IMPORTED_DLL, *PIMPORTED_DLL; @@ -43,11 +43,11 @@ typedef struct _IMPORTED_DLL typedef struct _IMPORT_FUNCTION { - char *name; + char* name; uint8_t has_ordinal; uint16_t ordinal; - struct _IMPORT_FUNCTION *next; + struct _IMPORT_FUNCTION* next; } IMPORT_FUNCTION, *PIMPORT_FUNCTION; @@ -57,7 +57,8 @@ typedef struct _PE const uint8_t* data; size_t data_size; - union { + union + { PIMAGE_NT_HEADERS32 header; PIMAGE_NT_HEADERS64 header64; }; @@ -71,33 +72,24 @@ typedef struct _PE } PE; -#define fits_in_pe(pe, pointer, size) \ - ((size_t) size <= pe->data_size && \ - (uint8_t*) (pointer) >= pe->data && \ - (uint8_t*) (pointer) <= pe->data + pe->data_size - size) +#define fits_in_pe(pe, pointer, size) \ + ((size_t) size <= pe->data_size && (uint8_t*) (pointer) >= pe->data && \ + (uint8_t*) (pointer) <= pe->data + pe->data_size - size) #define struct_fits_in_pe(pe, pointer, struct_type) \ - fits_in_pe(pe, pointer, sizeof(struct_type)) + fits_in_pe(pe, pointer, sizeof(struct_type)) -PIMAGE_NT_HEADERS32 pe_get_header( - const uint8_t* data, - size_t data_size); +PIMAGE_NT_HEADERS32 pe_get_header(const uint8_t* data, size_t data_size); -PIMAGE_DATA_DIRECTORY pe_get_directory_entry( - PE* pe, - int entry); +PIMAGE_DATA_DIRECTORY pe_get_directory_entry(PE* pe, int entry); -int64_t pe_rva_to_offset( - PE* pe, - uint64_t rva); +int64_t pe_rva_to_offset(PE* pe, uint64_t rva); -char *ord_lookup( - char *dll, - uint16_t ord); +char* ord_lookup(char* dll, uint16_t ord); #if HAVE_LIBCRYPTO diff --git a/libyara/include/yara/proc.h b/libyara/include/yara/proc.h index d408e70893..2e6486c29d 100644 --- a/libyara/include/yara/proc.h +++ b/libyara/include/yara/proc.h @@ -32,19 +32,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -typedef struct _YR_PROC_ITERATOR_CTX { - const uint8_t* buffer; - size_t buffer_size; +typedef struct _YR_PROC_ITERATOR_CTX +{ + const uint8_t* buffer; + size_t buffer_size; YR_MEMORY_BLOCK current_block; - void* proc_info; + void* proc_info; } YR_PROC_ITERATOR_CTX; YR_API int yr_process_open_iterator( int pid, YR_MEMORY_BLOCK_ITERATOR* iterator); -YR_API int yr_process_close_iterator( - YR_MEMORY_BLOCK_ITERATOR* iterator); +YR_API int yr_process_close_iterator(YR_MEMORY_BLOCK_ITERATOR* iterator); YR_API YR_MEMORY_BLOCK* yr_process_get_first_memory_block( YR_MEMORY_BLOCK_ITERATOR* iterator); diff --git a/libyara/include/yara/re.h b/libyara/include/yara/re.h index 050e4bd8ee..d956c2b231 100644 --- a/libyara/include/yara/re.h +++ b/libyara/include/yara/re.h @@ -31,53 +31,52 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define YR_RE_H #include - -#include -#include #include #include +#include +#include -#define RE_NODE_LITERAL 1 -#define RE_NODE_MASKED_LITERAL 2 -#define RE_NODE_ANY 3 -#define RE_NODE_CONCAT 4 -#define RE_NODE_ALT 5 -#define RE_NODE_RANGE 6 -#define RE_NODE_STAR 7 -#define RE_NODE_PLUS 8 -#define RE_NODE_CLASS 9 -#define RE_NODE_WORD_CHAR 10 -#define RE_NODE_NON_WORD_CHAR 11 -#define RE_NODE_SPACE 12 -#define RE_NODE_NON_SPACE 13 -#define RE_NODE_DIGIT 14 -#define RE_NODE_NON_DIGIT 15 -#define RE_NODE_EMPTY 16 -#define RE_NODE_ANCHOR_START 17 -#define RE_NODE_ANCHOR_END 18 -#define RE_NODE_WORD_BOUNDARY 19 -#define RE_NODE_NON_WORD_BOUNDARY 20 -#define RE_NODE_RANGE_ANY 21 - - -#define RE_OPCODE_ANY 0xA0 -#define RE_OPCODE_LITERAL 0xA2 -#define RE_OPCODE_MASKED_LITERAL 0xA4 -#define RE_OPCODE_CLASS 0xA5 -#define RE_OPCODE_WORD_CHAR 0xA7 -#define RE_OPCODE_NON_WORD_CHAR 0xA8 -#define RE_OPCODE_SPACE 0xA9 -#define RE_OPCODE_NON_SPACE 0xAA -#define RE_OPCODE_DIGIT 0xAB -#define RE_OPCODE_NON_DIGIT 0xAC -#define RE_OPCODE_MATCH 0xAD - -#define RE_OPCODE_MATCH_AT_END 0xB0 -#define RE_OPCODE_MATCH_AT_START 0xB1 -#define RE_OPCODE_WORD_BOUNDARY 0xB2 -#define RE_OPCODE_NON_WORD_BOUNDARY 0xB3 -#define RE_OPCODE_REPEAT_ANY_GREEDY 0xB4 -#define RE_OPCODE_REPEAT_ANY_UNGREEDY 0xB5 +#define RE_NODE_LITERAL 1 +#define RE_NODE_MASKED_LITERAL 2 +#define RE_NODE_ANY 3 +#define RE_NODE_CONCAT 4 +#define RE_NODE_ALT 5 +#define RE_NODE_RANGE 6 +#define RE_NODE_STAR 7 +#define RE_NODE_PLUS 8 +#define RE_NODE_CLASS 9 +#define RE_NODE_WORD_CHAR 10 +#define RE_NODE_NON_WORD_CHAR 11 +#define RE_NODE_SPACE 12 +#define RE_NODE_NON_SPACE 13 +#define RE_NODE_DIGIT 14 +#define RE_NODE_NON_DIGIT 15 +#define RE_NODE_EMPTY 16 +#define RE_NODE_ANCHOR_START 17 +#define RE_NODE_ANCHOR_END 18 +#define RE_NODE_WORD_BOUNDARY 19 +#define RE_NODE_NON_WORD_BOUNDARY 20 +#define RE_NODE_RANGE_ANY 21 + + +#define RE_OPCODE_ANY 0xA0 +#define RE_OPCODE_LITERAL 0xA2 +#define RE_OPCODE_MASKED_LITERAL 0xA4 +#define RE_OPCODE_CLASS 0xA5 +#define RE_OPCODE_WORD_CHAR 0xA7 +#define RE_OPCODE_NON_WORD_CHAR 0xA8 +#define RE_OPCODE_SPACE 0xA9 +#define RE_OPCODE_NON_SPACE 0xAA +#define RE_OPCODE_DIGIT 0xAB +#define RE_OPCODE_NON_DIGIT 0xAC +#define RE_OPCODE_MATCH 0xAD + +#define RE_OPCODE_MATCH_AT_END 0xB0 +#define RE_OPCODE_MATCH_AT_START 0xB1 +#define RE_OPCODE_WORD_BOUNDARY 0xB2 +#define RE_OPCODE_NON_WORD_BOUNDARY 0xB3 +#define RE_OPCODE_REPEAT_ANY_GREEDY 0xB4 +#define RE_OPCODE_REPEAT_ANY_UNGREEDY 0xB5 #define RE_OPCODE_SPLIT_A 0xC0 #define RE_OPCODE_SPLIT_B 0xC1 @@ -88,15 +87,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define RE_OPCODE_REPEAT_END_UNGREEDY 0xC6 -#define RE_FLAGS_FAST_REGEXP 0x02 -#define RE_FLAGS_BACKWARDS 0x04 -#define RE_FLAGS_EXHAUSTIVE 0x08 -#define RE_FLAGS_WIDE 0x10 -#define RE_FLAGS_NO_CASE 0x20 -#define RE_FLAGS_SCAN 0x40 -#define RE_FLAGS_DOT_ALL 0x80 -#define RE_FLAGS_GREEDY 0x400 -#define RE_FLAGS_UNGREEDY 0x800 +#define RE_FLAGS_FAST_REGEXP 0x02 +#define RE_FLAGS_BACKWARDS 0x04 +#define RE_FLAGS_EXHAUSTIVE 0x08 +#define RE_FLAGS_WIDE 0x10 +#define RE_FLAGS_NO_CASE 0x20 +#define RE_FLAGS_SCAN 0x40 +#define RE_FLAGS_DOT_ALL 0x80 +#define RE_FLAGS_GREEDY 0x400 +#define RE_FLAGS_UNGREEDY 0x800 typedef int RE_MATCH_CALLBACK_FUNC( @@ -105,21 +104,16 @@ typedef int RE_MATCH_CALLBACK_FUNC( int flags, void* args); -int yr_re_ast_create( - RE_AST** re_ast); +int yr_re_ast_create(RE_AST** re_ast); -void yr_re_ast_destroy( - RE_AST* re_ast); +void yr_re_ast_destroy(RE_AST* re_ast); -void yr_re_ast_print( - RE_AST* re_ast); +void yr_re_ast_print(RE_AST* re_ast); -SIZED_STRING* yr_re_ast_extract_literal( - RE_AST* re_ast); +SIZED_STRING* yr_re_ast_extract_literal(RE_AST* re_ast); -int yr_re_ast_contains_dot_star( - RE_AST* re_ast); +int yr_re_ast_contains_dot_star(RE_AST* re_ast); int yr_re_ast_split_at_chaining_point( @@ -129,28 +123,19 @@ int yr_re_ast_split_at_chaining_point( int32_t* max_gap); -int yr_re_ast_emit_code( - RE_AST* re_ast, - YR_ARENA* arena, - int backwards_code); +int yr_re_ast_emit_code(RE_AST* re_ast, YR_ARENA* arena, int backwards_code); -RE_NODE* yr_re_node_create( - int type); +RE_NODE* yr_re_node_create(int type); -void yr_re_node_destroy( - RE_NODE* node); +void yr_re_node_destroy(RE_NODE* node); -void yr_re_node_append_child( - RE_NODE* node, - RE_NODE* child); +void yr_re_node_append_child(RE_NODE* node, RE_NODE* child); -void yr_re_node_prepend_child( - RE_NODE* node, - RE_NODE* child); +void yr_re_node_prepend_child(RE_NODE* node, RE_NODE* child); int yr_re_exec( @@ -177,16 +162,10 @@ int yr_re_fast_exec( int* matches); -int yr_re_parse( - const char* re_string, - RE_AST** re_ast, - RE_ERROR* error); +int yr_re_parse(const char* re_string, RE_AST** re_ast, RE_ERROR* error); -int yr_re_parse_hex( - const char* hex_string, - RE_AST** re_ast, - RE_ERROR* error); +int yr_re_parse_hex(const char* hex_string, RE_AST** re_ast, RE_ERROR* error); int yr_re_compile( @@ -197,9 +176,6 @@ int yr_re_compile( RE_ERROR* error); -int yr_re_match( - YR_SCAN_CONTEXT* context, - RE* re, - const char* target); +int yr_re_match(YR_SCAN_CONTEXT* context, RE* re, const char* target); #endif diff --git a/libyara/include/yara/re_lexer.h b/libyara/include/yara/re_lexer.h index 853226ffe4..929379501f 100644 --- a/libyara/include/yara/re_lexer.h +++ b/libyara/include/yara/re_lexer.h @@ -1,4 +1,4 @@ - /* +/* Copyright (c) 2013. The YARA Authors. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, @@ -42,15 +42,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #undef LEX_ENV -#define yyparse re_yyparse -#define yylex re_yylex -#define yyerror re_yyerror -#define yyfatal re_yyfatal -#define yychar re_yychar -#define yydebug re_yydebug -#define yynerrs re_yynerrs -#define yyget_extra re_yyget_extra -#define yyget_lineno re_yyget_lineno +#define yyparse re_yyparse +#define yylex re_yylex +#define yyerror re_yyerror +#define yyfatal re_yyfatal +#define yychar re_yychar +#define yydebug re_yydebug +#define yynerrs re_yynerrs +#define yyget_extra re_yyget_extra +#define yyget_lineno re_yyget_lineno #ifndef YY_TYPEDEF_YY_SCANNER_T @@ -71,7 +71,7 @@ typedef struct _RE_LEX_ENVIRONMENT } RE_LEX_ENVIRONMENT; -#define LEX_ENV ((RE_LEX_ENVIRONMENT*) lex_env) +#define LEX_ENV ((RE_LEX_ENVIRONMENT*) lex_env) // The default behavior when a fatal error occurs in the parser is calling // exit(YY_EXIT_FAILURE) for terminating the process. This is not acceptable @@ -82,32 +82,25 @@ typedef struct _RE_LEX_ENVIRONMENT #include -#define YY_DECL int re_yylex \ - (YYSTYPE * yylval_param , yyscan_t yyscanner, RE_LEX_ENVIRONMENT* lex_env) +#define YY_DECL \ + int re_yylex( \ + YYSTYPE* yylval_param, yyscan_t yyscanner, RE_LEX_ENVIRONMENT* lex_env) -YY_EXTRA_TYPE yyget_extra( - yyscan_t yyscanner); +YY_EXTRA_TYPE yyget_extra(yyscan_t yyscanner); int yylex( YYSTYPE* yylval_param, yyscan_t yyscanner, RE_LEX_ENVIRONMENT* lex_env); -int yyparse( - void *yyscanner, - RE_LEX_ENVIRONMENT *lex_env); - void yyerror( yyscan_t yyscanner, RE_LEX_ENVIRONMENT* lex_env, - const char *error_message); + const char* error_message); -void yyfatal( - yyscan_t yyscanner, - const char *error_message); +void yyfatal(yyscan_t yyscanner, const char* error_message); + +int yyparse(void* yyscanner, RE_LEX_ENVIRONMENT* lex_env); -int yr_parse_re_string( - const char* re_string, - RE_AST** re_ast, - RE_ERROR* error); +int yr_parse_re_string(const char* re_string, RE_AST** re_ast, RE_ERROR* error); diff --git a/libyara/include/yara/rules.h b/libyara/include/yara/rules.h index 2bde811dfd..c6adbf63ed 100644 --- a/libyara/include/yara/rules.h +++ b/libyara/include/yara/rules.h @@ -30,51 +30,50 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef YR_RULES_H #define YR_RULES_H +#include #include #include -#include -#define CALLBACK_MSG_RULE_MATCHING 1 -#define CALLBACK_MSG_RULE_NOT_MATCHING 2 -#define CALLBACK_MSG_SCAN_FINISHED 3 -#define CALLBACK_MSG_IMPORT_MODULE 4 -#define CALLBACK_MSG_MODULE_IMPORTED 5 +#define CALLBACK_MSG_RULE_MATCHING 1 +#define CALLBACK_MSG_RULE_NOT_MATCHING 2 +#define CALLBACK_MSG_SCAN_FINISHED 3 +#define CALLBACK_MSG_IMPORT_MODULE 4 +#define CALLBACK_MSG_MODULE_IMPORTED 5 -#define CALLBACK_CONTINUE 0 -#define CALLBACK_ABORT 1 -#define CALLBACK_ERROR 2 +#define CALLBACK_CONTINUE 0 +#define CALLBACK_ABORT 1 +#define CALLBACK_ERROR 2 -#define yr_rule_tags_foreach(rule, tag_name) \ - for (tag_name = rule->tags; \ - tag_name != NULL && *tag_name != '\0'; \ - tag_name += strlen(tag_name) + 1) +#define yr_rule_tags_foreach(rule, tag_name) \ + for (tag_name = rule->tags; tag_name != NULL && *tag_name != '\0'; \ + tag_name += strlen(tag_name) + 1) #define yr_rule_metas_foreach(rule, meta) \ - for (meta = rule->metas; \ - meta != NULL; \ - meta = META_IS_LAST_IN_RULE(meta) ? NULL : meta + 1) + for (meta = rule->metas; meta != NULL; \ + meta = META_IS_LAST_IN_RULE(meta) ? NULL : meta + 1) -#define yr_rule_strings_foreach(rule, string) \ - for (string = rule->strings; \ - string != NULL; \ - string = STRING_IS_LAST_IN_RULE(string) ? NULL : string + 1) +#define yr_rule_strings_foreach(rule, string) \ + for (string = rule->strings; string != NULL; \ + string = STRING_IS_LAST_IN_RULE(string) ? NULL : string + 1) -#define yr_string_matches_foreach(context, string, match) \ - for (match = context->matches[string->idx].head; \ - match != NULL; \ - match = match->next) \ - /* private matches are skipped */ \ - if (match->is_private) { continue; } \ - else /* user code block goes here */ +#define yr_string_matches_foreach(context, string, match) \ + for (match = context->matches[string->idx].head; match != NULL; \ + match = match->next) \ + /* private matches are skipped */ \ + if (match->is_private) \ + { \ + continue; \ + } \ + else /* user code block goes here */ #define yr_rules_foreach(rules, rule) \ - for (rule = rules->rules_list_head; !RULE_IS_NULL(rule); rule++) + for (rule = rules->rules_list_head; !RULE_IS_NULL(rule); rule++) YR_API int yr_rules_scan_mem_blocks( @@ -123,28 +122,19 @@ YR_API int yr_rules_scan_proc( int timeout); -YR_API int yr_rules_save( - YR_RULES* rules, - const char* filename); +YR_API int yr_rules_save(YR_RULES* rules, const char* filename); -YR_API int yr_rules_save_stream( - YR_RULES* rules, - YR_STREAM* stream); +YR_API int yr_rules_save_stream(YR_RULES* rules, YR_STREAM* stream); -YR_API int yr_rules_load( - const char* filename, - YR_RULES** rules); +YR_API int yr_rules_load(const char* filename, YR_RULES** rules); -YR_API int yr_rules_load_stream( - YR_STREAM* stream, - YR_RULES** rules); +YR_API int yr_rules_load_stream(YR_STREAM* stream, YR_RULES** rules); -YR_API int yr_rules_destroy( - YR_RULES* rules); +YR_API int yr_rules_destroy(YR_RULES* rules); YR_API int yr_rules_define_integer_variable( @@ -171,21 +161,15 @@ YR_API int yr_rules_define_string_variable( const char* value); -YR_API int yr_rules_get_stats( - YR_RULES* rules, - YR_RULES_STATS *stats); +YR_API int yr_rules_get_stats(YR_RULES* rules, YR_RULES_STATS* stats); -YR_API void yr_rule_disable( - YR_RULE* rule); +YR_API void yr_rule_disable(YR_RULE* rule); -YR_API void yr_rule_enable( - YR_RULE* rule); +YR_API void yr_rule_enable(YR_RULE* rule); -int yr_rules_from_arena( - YR_ARENA* arena, - YR_RULES** rules); +int yr_rules_from_arena(YR_ARENA* arena, YR_RULES** rules); #endif diff --git a/libyara/include/yara/scan.h b/libyara/include/yara/scan.h index 5326efae13..987ca3358d 100644 --- a/libyara/include/yara/scan.h +++ b/libyara/include/yara/scan.h @@ -35,11 +35,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Flags used with yr_scanner_set_flags and yr_rules_scan_xxx functions. // -#define SCAN_FLAGS_FAST_MODE 1 -#define SCAN_FLAGS_PROCESS_MEMORY 2 -#define SCAN_FLAGS_NO_TRYCATCH 4 -#define SCAN_FLAGS_REPORT_RULES_MATCHING 8 -#define SCAN_FLAGS_REPORT_RULES_NOT_MATCHING 16 +#define SCAN_FLAGS_FAST_MODE 1 +#define SCAN_FLAGS_PROCESS_MEMORY 2 +#define SCAN_FLAGS_NO_TRYCATCH 4 +#define SCAN_FLAGS_REPORT_RULES_MATCHING 8 +#define SCAN_FLAGS_REPORT_RULES_NOT_MATCHING 16 int yr_scan_verify_match( diff --git a/libyara/include/yara/scanner.h b/libyara/include/yara/scanner.h index 05201802ca..fef75f49c0 100644 --- a/libyara/include/yara/scanner.h +++ b/libyara/include/yara/scanner.h @@ -38,13 +38,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. typedef YR_SCAN_CONTEXT YR_SCANNER; -YR_API int yr_scanner_create( - YR_RULES* rules, - YR_SCANNER** scanner); +YR_API int yr_scanner_create(YR_RULES* rules, YR_SCANNER** scanner); -YR_API void yr_scanner_destroy( - YR_SCANNER* scanner); +YR_API void yr_scanner_destroy(YR_SCANNER* scanner); YR_API void yr_scanner_set_callback( @@ -53,14 +50,10 @@ YR_API void yr_scanner_set_callback( void* user_data); -YR_API void yr_scanner_set_timeout( - YR_SCANNER* scanner, - int timeout); +YR_API void yr_scanner_set_timeout(YR_SCANNER* scanner, int timeout); -YR_API void yr_scanner_set_flags( - YR_SCANNER* scanner, - int flags); +YR_API void yr_scanner_set_flags(YR_SCANNER* scanner, int flags); YR_API int yr_scanner_define_integer_variable( @@ -104,39 +97,29 @@ YR_API int yr_scanner_scan_mem( size_t buffer_size); -YR_API int yr_scanner_scan_file( - YR_SCANNER* scanner, - const char* filename); +YR_API int yr_scanner_scan_file(YR_SCANNER* scanner, const char* filename); -YR_API int yr_scanner_scan_fd( - YR_SCANNER* scanner, - YR_FILE_DESCRIPTOR fd); +YR_API int yr_scanner_scan_fd(YR_SCANNER* scanner, YR_FILE_DESCRIPTOR fd); -YR_API int yr_scanner_scan_proc( - YR_SCANNER* scanner, - int pid); +YR_API int yr_scanner_scan_proc(YR_SCANNER* scanner, int pid); -YR_API YR_RULE* yr_scanner_last_error_rule( - YR_SCANNER* scanner); +YR_API YR_RULE* yr_scanner_last_error_rule(YR_SCANNER* scanner); -YR_API YR_STRING* yr_scanner_last_error_string( - YR_SCANNER* scanner); +YR_API YR_STRING* yr_scanner_last_error_string(YR_SCANNER* scanner); YR_API YR_RULE_PROFILING_INFO* yr_scanner_get_profiling_info( YR_SCANNER* scanner); -YR_API void yr_scanner_reset_profiling_info( - YR_SCANNER* scanner); +YR_API void yr_scanner_reset_profiling_info(YR_SCANNER* scanner); -YR_API int yr_scanner_print_profiling_info( - YR_SCANNER* scanner); +YR_API int yr_scanner_print_profiling_info(YR_SCANNER* scanner); #endif diff --git a/libyara/include/yara/sizedstr.h b/libyara/include/yara/sizedstr.h index c861cea252..5a6c372a92 100644 --- a/libyara/include/yara/sizedstr.h +++ b/libyara/include/yara/sizedstr.h @@ -32,11 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include - #include -#define SIZED_STRING_FLAGS_NO_CASE 1 -#define SIZED_STRING_FLAGS_DOT_ALL 2 +#define SIZED_STRING_FLAGS_NO_CASE 1 +#define SIZED_STRING_FLAGS_DOT_ALL 2 #pragma pack(push) #pragma pack(1) @@ -57,55 +56,26 @@ typedef struct _SIZED_STRING #pragma pack(pop) +int ss_compare(SIZED_STRING* s1, SIZED_STRING* s2); -int ss_compare( - SIZED_STRING* s1, - SIZED_STRING* s2); - - -int ss_icompare( - SIZED_STRING* s1, - SIZED_STRING* s2); - - -bool ss_contains( - SIZED_STRING* s1, - SIZED_STRING* s2); - - -bool ss_icontains( - SIZED_STRING* s1, - SIZED_STRING* s2); - - -bool ss_startswith( - SIZED_STRING* s1, - SIZED_STRING* s2); - - -bool ss_istartswith( - SIZED_STRING* s1, - SIZED_STRING* s2); +int ss_icompare(SIZED_STRING* s1, SIZED_STRING* s2); +bool ss_contains(SIZED_STRING* s1, SIZED_STRING* s2); -bool ss_endswith( - SIZED_STRING* s1, - SIZED_STRING* s2); +bool ss_icontains(SIZED_STRING* s1, SIZED_STRING* s2); +bool ss_startswith(SIZED_STRING* s1, SIZED_STRING* s2); -bool ss_iendswith( - SIZED_STRING* s1, - SIZED_STRING* s2); +bool ss_istartswith(SIZED_STRING* s1, SIZED_STRING* s2); +bool ss_endswith(SIZED_STRING* s1, SIZED_STRING* s2); -SIZED_STRING* ss_dup( - SIZED_STRING* s); +bool ss_iendswith(SIZED_STRING* s1, SIZED_STRING* s2); +SIZED_STRING* ss_dup(SIZED_STRING* s); -SIZED_STRING* ss_new( - const char* s); +SIZED_STRING* ss_new(const char* s); -SIZED_STRING* ss_convert_to_wide( - SIZED_STRING* s); +SIZED_STRING* ss_convert_to_wide(SIZED_STRING* s); #endif diff --git a/libyara/include/yara/stack.h b/libyara/include/yara/stack.h index a08ae1cea1..2397227a30 100644 --- a/libyara/include/yara/stack.h +++ b/libyara/include/yara/stack.h @@ -34,39 +34,31 @@ typedef struct YR_STACK YR_STACK; struct YR_STACK { - // Pointer to a heap-allocated array containing the void* values put in - // in the stack. This array starts with a fixed size and it's grown as - // required when new items are pushed into the stack. - void* items; + // Pointer to a heap-allocated array containing the void* values put in + // in the stack. This array starts with a fixed size and it's grown as + // required when new items are pushed into the stack. + void* items; - // Current capacity (i.e: the number of items that fit into the array) - int capacity; + // Current capacity (i.e: the number of items that fit into the array) + int capacity; - // Size of each individual item in the stack. - int item_size; + // Size of each individual item in the stack. + int item_size; - // Index of the stack's top in the items array. - int top; + // Index of the stack's top in the items array. + int top; }; -int yr_stack_create( - int initial_capacity, - int item_size, - YR_STACK** stack); +int yr_stack_create(int initial_capacity, int item_size, YR_STACK** stack); -void yr_stack_destroy( - YR_STACK* stack); +void yr_stack_destroy(YR_STACK* stack); -int yr_stack_push( - YR_STACK* stack, - void* item); +int yr_stack_push(YR_STACK* stack, void* item); -int yr_stack_pop( - YR_STACK* stack, - void* item); +int yr_stack_pop(YR_STACK* stack, void* item); -#endif \ No newline at end of file +#endif diff --git a/libyara/include/yara/stopwatch.h b/libyara/include/yara/stopwatch.h index 721b84e9ca..dc013d5883 100644 --- a/libyara/include/yara/stopwatch.h +++ b/libyara/include/yara/stopwatch.h @@ -61,7 +61,8 @@ typedef struct _YR_STOPWATCH typedef struct _YR_STOPWATCH { - union { + union + { struct timeval tv_start; struct timespec ts_start; }; @@ -72,12 +73,10 @@ typedef struct _YR_STOPWATCH // yr_stopwatch_start starts measuring time. -void yr_stopwatch_start( - YR_STOPWATCH* stopwatch); +void yr_stopwatch_start(YR_STOPWATCH* stopwatch); // yr_stopwatch_elapsed_ns returns the number of nanoseconds elapsed // since the last call to yr_stopwatch_start. -uint64_t yr_stopwatch_elapsed_ns( - YR_STOPWATCH* stopwatch); +uint64_t yr_stopwatch_elapsed_ns(YR_STOPWATCH* stopwatch); #endif diff --git a/libyara/include/yara/stream.h b/libyara/include/yara/stream.h index a84d8936a3..4fb190959c 100644 --- a/libyara/include/yara/stream.h +++ b/libyara/include/yara/stream.h @@ -56,11 +56,7 @@ typedef struct _YR_STREAM } YR_STREAM; -size_t yr_stream_read( - void* ptr, - size_t size, - size_t count, - YR_STREAM* stream); +size_t yr_stream_read(void* ptr, size_t size, size_t count, YR_STREAM* stream); size_t yr_stream_write( diff --git a/libyara/include/yara/strutils.h b/libyara/include/yara/strutils.h index d47afbaa83..743af5f000 100644 --- a/libyara/include/yara/strutils.h +++ b/libyara/include/yara/strutils.h @@ -33,7 +33,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include - #include @@ -55,7 +54,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define PRId64 "I64d" #endif -#if !defined (PRIi32) +#if !defined(PRIi32) #define PRIi32 "I32i" #endif @@ -73,52 +72,39 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif #endif -#define strcasecmp _stricmp +#define strcasecmp _stricmp #define strncasecmp _strnicmp #endif -uint64_t xtoi( - const char* hexstr); +uint64_t xtoi(const char* hexstr); #if !HAVE_STRLCPY && !defined(strlcpy) -size_t strlcpy( - char *dst, - const char *src, - size_t size); +size_t strlcpy(char* dst, const char* src, size_t size); #endif #if !HAVE_STRLCAT && !defined(strlcat) -size_t strlcat( - char *dst, - const char *src, - size_t size); +size_t strlcat(char* dst, const char* src, size_t size); #endif #if !HAVE_MEMMEM && !defined(memmem) void* memmem( - const void *haystack, + const void* haystack, size_t haystack_size, - const void *needle, + const void* needle, size_t needle_size); #endif -int strnlen_w( - const char* w_str); +int strnlen_w(const char* w_str); -int strcmp_w( - const char* w_str, - const char* str); +int strcmp_w(const char* w_str, const char* str); -size_t strlcpy_w( - char* dst, - const char* w_src, - size_t n); +size_t strlcpy_w(char* dst, const char* w_src, size_t n); #endif diff --git a/libyara/include/yara/threading.h b/libyara/include/yara/threading.h index d9c2fedda3..8045417a5e 100644 --- a/libyara/include/yara/threading.h +++ b/libyara/include/yara/threading.h @@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define YR_MUTEX_H - #if defined(_WIN32) || defined(__CYGWIN__) #include diff --git a/libyara/include/yara/types.h b/libyara/include/yara/types.h index e27263effb..50755e2ae0 100644 --- a/libyara/include/yara/types.h +++ b/libyara/include/yara/types.h @@ -31,159 +31,132 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define YR_TYPES_H #include - #include #include -#include #include -#include +#include #include #include #include +#include + #include "notebook.h" #define DECLARE_REFERENCE(type, name) \ - union { \ - type name; \ - YR_ARENA_REF name##_; \ - } YR_ALIGN(8) + union \ + { \ + type name; \ + YR_ARENA_REF name##_; \ + } YR_ALIGN(8) // Flags for YR_RULE -#define RULE_FLAGS_PRIVATE 0x01 -#define RULE_FLAGS_GLOBAL 0x02 -#define RULE_FLAGS_NULL 0x04 -#define RULE_FLAGS_DISABLED 0x08 +#define RULE_FLAGS_PRIVATE 0x01 +#define RULE_FLAGS_GLOBAL 0x02 +#define RULE_FLAGS_NULL 0x04 +#define RULE_FLAGS_DISABLED 0x08 -#define RULE_IS_PRIVATE(x) \ - (((x)->flags) & RULE_FLAGS_PRIVATE) +#define RULE_IS_PRIVATE(x) (((x)->flags) & RULE_FLAGS_PRIVATE) -#define RULE_IS_GLOBAL(x) \ - (((x)->flags) & RULE_FLAGS_GLOBAL) +#define RULE_IS_GLOBAL(x) (((x)->flags) & RULE_FLAGS_GLOBAL) -#define RULE_IS_NULL(x) \ - (((x)->flags) & RULE_FLAGS_NULL) +#define RULE_IS_NULL(x) (((x)->flags) & RULE_FLAGS_NULL) -#define RULE_IS_DISABLED(x) \ - (((x)->flags) & RULE_FLAGS_DISABLED) +#define RULE_IS_DISABLED(x) (((x)->flags) & RULE_FLAGS_DISABLED) // Flags for YR_STRING -#define STRING_FLAGS_REFERENCED 0x01 -#define STRING_FLAGS_HEXADECIMAL 0x02 -#define STRING_FLAGS_NO_CASE 0x04 -#define STRING_FLAGS_ASCII 0x08 -#define STRING_FLAGS_WIDE 0x10 -#define STRING_FLAGS_REGEXP 0x20 -#define STRING_FLAGS_FAST_REGEXP 0x40 -#define STRING_FLAGS_FULL_WORD 0x80 -#define STRING_FLAGS_ANONYMOUS 0x100 -#define STRING_FLAGS_SINGLE_MATCH 0x200 -#define STRING_FLAGS_LITERAL 0x400 -#define STRING_FLAGS_FITS_IN_ATOM 0x800 -#define STRING_FLAGS_LAST_IN_RULE 0x1000 -#define STRING_FLAGS_CHAIN_PART 0x2000 -#define STRING_FLAGS_CHAIN_TAIL 0x4000 -#define STRING_FLAGS_FIXED_OFFSET 0x8000 -#define STRING_FLAGS_GREEDY_REGEXP 0x10000 -#define STRING_FLAGS_DOT_ALL 0x20000 -#define STRING_FLAGS_DISABLED 0x40000 -#define STRING_FLAGS_XOR 0x80000 -#define STRING_FLAGS_PRIVATE 0x100000 -#define STRING_FLAGS_BASE64 0x200000 -#define STRING_FLAGS_BASE64_WIDE 0x400000 +#define STRING_FLAGS_REFERENCED 0x01 +#define STRING_FLAGS_HEXADECIMAL 0x02 +#define STRING_FLAGS_NO_CASE 0x04 +#define STRING_FLAGS_ASCII 0x08 +#define STRING_FLAGS_WIDE 0x10 +#define STRING_FLAGS_REGEXP 0x20 +#define STRING_FLAGS_FAST_REGEXP 0x40 +#define STRING_FLAGS_FULL_WORD 0x80 +#define STRING_FLAGS_ANONYMOUS 0x100 +#define STRING_FLAGS_SINGLE_MATCH 0x200 +#define STRING_FLAGS_LITERAL 0x400 +#define STRING_FLAGS_FITS_IN_ATOM 0x800 +#define STRING_FLAGS_LAST_IN_RULE 0x1000 +#define STRING_FLAGS_CHAIN_PART 0x2000 +#define STRING_FLAGS_CHAIN_TAIL 0x4000 +#define STRING_FLAGS_FIXED_OFFSET 0x8000 +#define STRING_FLAGS_GREEDY_REGEXP 0x10000 +#define STRING_FLAGS_DOT_ALL 0x20000 +#define STRING_FLAGS_DISABLED 0x40000 +#define STRING_FLAGS_XOR 0x80000 +#define STRING_FLAGS_PRIVATE 0x100000 +#define STRING_FLAGS_BASE64 0x200000 +#define STRING_FLAGS_BASE64_WIDE 0x400000 -#define STRING_IS_HEX(x) \ - (((x)->flags) & STRING_FLAGS_HEXADECIMAL) +#define STRING_IS_HEX(x) (((x)->flags) & STRING_FLAGS_HEXADECIMAL) -#define STRING_IS_NO_CASE(x) \ - (((x)->flags) & STRING_FLAGS_NO_CASE) +#define STRING_IS_NO_CASE(x) (((x)->flags) & STRING_FLAGS_NO_CASE) -#define STRING_IS_DOT_ALL(x) \ - (((x)->flags) & STRING_FLAGS_DOT_ALL) +#define STRING_IS_DOT_ALL(x) (((x)->flags) & STRING_FLAGS_DOT_ALL) -#define STRING_IS_ASCII(x) \ - (((x)->flags) & STRING_FLAGS_ASCII) +#define STRING_IS_ASCII(x) (((x)->flags) & STRING_FLAGS_ASCII) -#define STRING_IS_WIDE(x) \ - (((x)->flags) & STRING_FLAGS_WIDE) +#define STRING_IS_WIDE(x) (((x)->flags) & STRING_FLAGS_WIDE) -#define STRING_IS_REGEXP(x) \ - (((x)->flags) & STRING_FLAGS_REGEXP) +#define STRING_IS_REGEXP(x) (((x)->flags) & STRING_FLAGS_REGEXP) -#define STRING_IS_GREEDY_REGEXP(x) \ - (((x)->flags) & STRING_FLAGS_GREEDY_REGEXP) +#define STRING_IS_GREEDY_REGEXP(x) (((x)->flags) & STRING_FLAGS_GREEDY_REGEXP) -#define STRING_IS_FULL_WORD(x) \ - (((x)->flags) & STRING_FLAGS_FULL_WORD) +#define STRING_IS_FULL_WORD(x) (((x)->flags) & STRING_FLAGS_FULL_WORD) -#define STRING_IS_ANONYMOUS(x) \ - (((x)->flags) & STRING_FLAGS_ANONYMOUS) +#define STRING_IS_ANONYMOUS(x) (((x)->flags) & STRING_FLAGS_ANONYMOUS) -#define STRING_IS_REFERENCED(x) \ - (((x)->flags) & STRING_FLAGS_REFERENCED) +#define STRING_IS_REFERENCED(x) (((x)->flags) & STRING_FLAGS_REFERENCED) -#define STRING_IS_SINGLE_MATCH(x) \ - (((x)->flags) & STRING_FLAGS_SINGLE_MATCH) +#define STRING_IS_SINGLE_MATCH(x) (((x)->flags) & STRING_FLAGS_SINGLE_MATCH) -#define STRING_IS_FIXED_OFFSET(x) \ - (((x)->flags) & STRING_FLAGS_FIXED_OFFSET) +#define STRING_IS_FIXED_OFFSET(x) (((x)->flags) & STRING_FLAGS_FIXED_OFFSET) -#define STRING_IS_LITERAL(x) \ - (((x)->flags) & STRING_FLAGS_LITERAL) +#define STRING_IS_LITERAL(x) (((x)->flags) & STRING_FLAGS_LITERAL) -#define STRING_IS_FAST_REGEXP(x) \ - (((x)->flags) & STRING_FLAGS_FAST_REGEXP) +#define STRING_IS_FAST_REGEXP(x) (((x)->flags) & STRING_FLAGS_FAST_REGEXP) -#define STRING_IS_CHAIN_PART(x) \ - (((x)->flags) & STRING_FLAGS_CHAIN_PART) +#define STRING_IS_CHAIN_PART(x) (((x)->flags) & STRING_FLAGS_CHAIN_PART) -#define STRING_IS_CHAIN_TAIL(x) \ - (((x)->flags) & STRING_FLAGS_CHAIN_TAIL) +#define STRING_IS_CHAIN_TAIL(x) (((x)->flags) & STRING_FLAGS_CHAIN_TAIL) -#define STRING_IS_LAST_IN_RULE(x) \ - (((x)->flags) & STRING_FLAGS_LAST_IN_RULE) +#define STRING_IS_LAST_IN_RULE(x) (((x)->flags) & STRING_FLAGS_LAST_IN_RULE) -#define STRING_FITS_IN_ATOM(x) \ - (((x)->flags) & STRING_FLAGS_FITS_IN_ATOM) +#define STRING_FITS_IN_ATOM(x) (((x)->flags) & STRING_FLAGS_FITS_IN_ATOM) -#define STRING_IS_DISABLED(x) \ - (((x)->flags) & STRING_FLAGS_DISABLED) +#define STRING_IS_DISABLED(x) (((x)->flags) & STRING_FLAGS_DISABLED) -#define STRING_IS_XOR(x) \ - (((x)->flags) & STRING_FLAGS_XOR) +#define STRING_IS_XOR(x) (((x)->flags) & STRING_FLAGS_XOR) -#define STRING_IS_BASE64(x) \ - (((x)->flags) & STRING_FLAGS_BASE64) +#define STRING_IS_BASE64(x) (((x)->flags) & STRING_FLAGS_BASE64) -#define STRING_IS_BASE64_WIDE(x) \ - (((x)->flags) & STRING_FLAGS_BASE64_WIDE) +#define STRING_IS_BASE64_WIDE(x) (((x)->flags) & STRING_FLAGS_BASE64_WIDE) -#define STRING_IS_PRIVATE(x) \ - (((x)->flags) & STRING_FLAGS_PRIVATE) +#define STRING_IS_PRIVATE(x) (((x)->flags) & STRING_FLAGS_PRIVATE) -#define META_TYPE_INTEGER 1 -#define META_TYPE_STRING 2 -#define META_TYPE_BOOLEAN 3 +#define META_TYPE_INTEGER 1 +#define META_TYPE_STRING 2 +#define META_TYPE_BOOLEAN 3 -#define META_FLAGS_LAST_IN_RULE 1 +#define META_FLAGS_LAST_IN_RULE 1 -#define META_IS_LAST_IN_RULE(x) \ - (((x)->flags) & META_FLAGS_LAST_IN_RULE) +#define META_IS_LAST_IN_RULE(x) (((x)->flags) & META_FLAGS_LAST_IN_RULE) -#define EXTERNAL_VARIABLE_TYPE_NULL 0 -#define EXTERNAL_VARIABLE_TYPE_FLOAT 1 -#define EXTERNAL_VARIABLE_TYPE_INTEGER 2 -#define EXTERNAL_VARIABLE_TYPE_BOOLEAN 3 -#define EXTERNAL_VARIABLE_TYPE_STRING 4 -#define EXTERNAL_VARIABLE_TYPE_MALLOC_STRING 5 +#define EXTERNAL_VARIABLE_TYPE_NULL 0 +#define EXTERNAL_VARIABLE_TYPE_FLOAT 1 +#define EXTERNAL_VARIABLE_TYPE_INTEGER 2 +#define EXTERNAL_VARIABLE_TYPE_BOOLEAN 3 +#define EXTERNAL_VARIABLE_TYPE_STRING 4 +#define EXTERNAL_VARIABLE_TYPE_MALLOC_STRING 5 #define EXTERNAL_VARIABLE_IS_NULL(x) \ - ((x) != NULL ? (x)->type == EXTERNAL_VARIABLE_TYPE_NULL : true) + ((x) != NULL ? (x)->type == EXTERNAL_VARIABLE_TYPE_NULL : true) typedef struct RE RE; @@ -238,7 +211,7 @@ typedef struct YR_MODIFIER YR_MODIFIER; typedef struct YR_ITERATOR YR_ITERATOR; -typedef uint32_t YR_AC_TRANSITION; +typedef uint32_t YR_AC_TRANSITION; #pragma pack(push) #pragma pack(8) @@ -348,7 +321,8 @@ struct YR_EXTERNAL_VARIABLE { int32_t type; - YR_ALIGN(8) union { + YR_ALIGN(8) union + { int64_t i; double f; char* s; @@ -368,11 +342,11 @@ struct YR_AC_MATCH // When the Aho-Corasick automaton reaches some state that has associated // matches, the current position in the input buffer is a few bytes past // the point where the match actually occurs, for example, when looking for - // string "bar" in "foobarbaz", when the automaton reaches the state associated - // to the ending "r" in "bar, which is the one that has a match, the current - // position in the input is 6 (the "b" after the "r"), but the match is at - // position 3. The backtrack field indicates how many bytes the scanner has - // to go back to find the point where the match actually start. + // string "bar" in "foobarbaz", when the automaton reaches the state + // associated to the ending "r" in "bar, which is the one that has a match, + // the current position in the input is 6 (the "b" after the "r"), but the + // match is at position 3. The backtrack field indicates how many bytes the + // scanner has to go back to find the point where the match actually start. // // YR_ALIGN(8) forces the backtrack field to be treated as a 8-bytes field // and therefore the struct's size is 40 bytes. This is necessary only for @@ -391,13 +365,15 @@ struct RE_NODE { int type; - union { + union + { int value; int count; int start; }; - union { + union + { int mask; int end; }; @@ -431,10 +407,9 @@ struct RE_AST // Disable warning due to zero length array in Microsoft's compiler - #ifdef _MSC_VER #pragma warning(push) -#pragma warning(disable:4200) +#pragma warning(disable : 4200) #endif struct RE @@ -456,9 +431,9 @@ struct RE_ERROR struct RE_FIBER { - const uint8_t* ip; // instruction pointer - int32_t sp; // stack pointer - int32_t rc; // repeat counter + const uint8_t* ip; // instruction pointer + int32_t sp; // stack pointer + int32_t rc; // repeat counter RE_FIBER* prev; RE_FIBER* next; @@ -486,7 +461,7 @@ struct YR_MODIFIER int32_t flags; uint8_t xor_min; uint8_t xor_max; - SIZED_STRING *alphabet; + SIZED_STRING* alphabet; }; @@ -501,9 +476,9 @@ struct YR_MATCHES struct YR_MATCH { - int64_t base; // Base address for the match - int64_t offset; // Offset relative to base for the match - int32_t match_length; // Match length + int64_t base; // Base address for the match + int64_t offset; // Offset relative to base for the match + int32_t match_length; // Match length int32_t data_length; // Pointer to a buffer containing a portion of the matched data. The size of @@ -686,8 +661,8 @@ struct YR_MEMORY_BLOCK_ITERATOR { void* context; - YR_MEMORY_BLOCK_ITERATOR_FUNC first; - YR_MEMORY_BLOCK_ITERATOR_FUNC next; + YR_MEMORY_BLOCK_ITERATOR_FUNC first; + YR_MEMORY_BLOCK_ITERATOR_FUNC next; }; @@ -741,7 +716,7 @@ struct YR_SCAN_CONTEXT // Notebook used for storing YR_MATCH structures associated to the matches // found. - YR_NOTEBOOK * matches_notebook; + YR_NOTEBOOK* matches_notebook; // Stopwatch used for measuring the time elapsed during the scan. YR_STOPWATCH stopwatch; @@ -789,18 +764,18 @@ union YR_VALUE struct YR_VALUE_STACK { - int32_t sp; - int32_t capacity; + int32_t sp; + int32_t capacity; YR_VALUE* items; }; #define OBJECT_COMMON_FIELDS \ - int canary; \ - int8_t type; \ - const char* identifier; \ - YR_OBJECT* parent; \ - void* data; + int canary; \ + int8_t type; \ + const char* identifier; \ + YR_OBJECT* parent; \ + void* data; struct YR_OBJECT @@ -883,14 +858,14 @@ struct YR_DICTIONARY_ITEMS int used; int free; - struct { + struct + { SIZED_STRING* key; YR_OBJECT* obj; } objects[1]; }; - // Iterators are used in loops of the form: // // for in : ( ) @@ -923,15 +898,13 @@ struct YR_DICTIONARY_ITEMS // | . . . | // // We can't use the YR_UNDEFINED value in the stack as an indicator of the end -// of the iterator, because it's legitimate for an iterator to return YR_UNDEFINED -// items in the middle of the iteration. +// of the iterator, because it's legitimate for an iterator to return +// YR_UNDEFINED items in the middle of the iteration. // // The "next" function should return ERROR_SUCCESS if everything went fine or // an error code in case of error. -typedef int (*YR_ITERATOR_NEXT_FUNC)( - YR_ITERATOR* self, - YR_VALUE_STACK* stack); +typedef int (*YR_ITERATOR_NEXT_FUNC)(YR_ITERATOR* self, YR_VALUE_STACK* stack); struct YR_ARRAY_ITERATOR @@ -967,7 +940,8 @@ struct YR_ITERATOR { YR_ITERATOR_NEXT_FUNC next; - union { + union + { struct YR_ARRAY_ITERATOR array_it; struct YR_DICT_ITERATOR dict_it; struct YR_INT_RANGE_ITERATOR int_range_it; @@ -975,5 +949,4 @@ struct YR_ITERATOR }; }; - #endif diff --git a/libyara/include/yara/utils.h b/libyara/include/yara/utils.h index bb40140d10..05d75b8ed3 100644 --- a/libyara/include/yara/utils.h +++ b/libyara/include/yara/utils.h @@ -42,9 +42,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #else #ifndef __cplusplus -#define bool int -#define true 1 -#define false 0 +#define bool int +#define true 1 +#define false 0 #endif /* __cplusplus */ #endif @@ -56,34 +56,34 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(_WIN32) || defined(__CYGWIN__) - #ifdef YR_BUILDING_DLL - #ifdef __GNUC__ - #define YR_API EXTERNC __attribute__((dllexport)) - #define YR_DEPRECATED_API EXTERNC __attribute__((deprecated)) - #else - #define YR_API EXTERNC __declspec(dllexport) - #define YR_DEPRECATED_API EXTERNC __declspec(deprecated) - #endif - #elif defined(YR_IMPORTING_DLL) - #ifdef __GNUC__ - #define YR_API EXTERNC __attribute__((dllimport)) - #define YR_DEPRECATED_API EXTERNC __attribute__((deprecated)) - #else - #define YR_API EXTERNC __declspec(dllimport) - #define YR_DEPRECATED_API EXTERNC __declspec(deprecated) - #endif - #else - #define YR_API EXTERNC - #define YR_DEPRECATED_API EXTERNC - #endif +#ifdef YR_BUILDING_DLL +#ifdef __GNUC__ +#define YR_API EXTERNC __attribute__((dllexport)) +#define YR_DEPRECATED_API EXTERNC __attribute__((deprecated)) #else - #if __GNUC__ >= 4 - #define YR_API EXTERNC __attribute__((visibility ("default"))) - #define YR_DEPRECATED_API YR_API __attribute__((deprecated)) - #else - #define YR_API EXTERNC - #define YR_DEPRECATED_API EXTERNC - #endif +#define YR_API EXTERNC __declspec(dllexport) +#define YR_DEPRECATED_API EXTERNC __declspec(deprecated) +#endif +#elif defined(YR_IMPORTING_DLL) +#ifdef __GNUC__ +#define YR_API EXTERNC __attribute__((dllimport)) +#define YR_DEPRECATED_API EXTERNC __attribute__((deprecated)) +#else +#define YR_API EXTERNC __declspec(dllimport) +#define YR_DEPRECATED_API EXTERNC __declspec(deprecated) +#endif +#else +#define YR_API EXTERNC +#define YR_DEPRECATED_API EXTERNC +#endif +#else +#if __GNUC__ >= 4 +#define YR_API EXTERNC __attribute__((visibility("default"))) +#define YR_DEPRECATED_API YR_API __attribute__((deprecated)) +#else +#define YR_API EXTERNC +#define YR_DEPRECATED_API EXTERNC +#endif #endif @@ -104,21 +104,28 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define yr_min(x, y) (((x) < (y)) ? (x) : (y)) #define yr_max(x, y) (((x) > (y)) ? (x) : (y)) -#define yr_swap(x, y, T) do { T temp = x; x = y; y = temp; } while (0) +#define yr_swap(x, y, T) \ + do \ + { \ + T temp = x; \ + x = y; \ + y = temp; \ + } while (0) #ifdef NDEBUG -#define assertf(expr, msg, ...) ((void)0) +#define assertf(expr, msg, ...) ((void) 0) #else #include -#define assertf(expr, msg, ...) \ - if(!(expr)) { \ - fprintf(stderr, "%s:%d: " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__); \ - abort(); \ - } +#define assertf(expr, msg, ...) \ + if (!(expr)) \ + { \ + fprintf(stderr, "%s:%d: " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__); \ + abort(); \ + } #endif @@ -127,17 +134,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ensure compatibility with the CHAR_BIT constant used in these definitions. #define YR_BITARRAY_SET(uchar_array_base, bitnum) \ - (((uchar_array_base)[(bitnum)/CHAR_BIT]) = \ - ((uchar_array_base)[(bitnum)/CHAR_BIT] | (1 << ((bitnum) % CHAR_BIT)))) + (((uchar_array_base)[(bitnum) / CHAR_BIT]) = \ + ((uchar_array_base)[(bitnum) / CHAR_BIT] | \ + (1 << ((bitnum) % CHAR_BIT)))) #define YR_BITARRAY_UNSET(uchar_array_base, bitnum) \ - (((uchar_array_base)[(bitnum)/CHAR_BIT]) = \ - ((uchar_array_base)[(bitnum)/CHAR_BIT] & (~(1 << ((bitnum) % CHAR_BIT))))) + (((uchar_array_base)[(bitnum) / CHAR_BIT]) = \ + ((uchar_array_base)[(bitnum) / CHAR_BIT] & \ + (~(1 << ((bitnum) % CHAR_BIT))))) -#define YR_BITARRAY_TEST(uchar_array_base, bitnum) \ - (((uchar_array_base)[(bitnum)/CHAR_BIT] & (1 << ((bitnum) % CHAR_BIT))) != 0) +#define YR_BITARRAY_TEST(uchar_array_base, bitnum) \ + (((uchar_array_base)[(bitnum) / CHAR_BIT] & (1 << ((bitnum) % CHAR_BIT))) != \ + 0) -#define YR_BITARRAY_NCHARS(bitnum) \ - (((bitnum)+(CHAR_BIT-1))/CHAR_BIT) +#define YR_BITARRAY_NCHARS(bitnum) (((bitnum) + (CHAR_BIT - 1)) / CHAR_BIT) #endif diff --git a/libyara/lexer.c b/libyara/lexer.c index 3cfe3f42cf..7cecf738e6 100644 --- a/libyara/lexer.c +++ b/libyara/lexer.c @@ -2,13 +2,13 @@ #line 3 "lexer.c" -#define YY_INT_ALIGNED short int +#define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ #define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 #define YY_FLEX_SUBMINOR_VERSION 4 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA @@ -239,10 +239,10 @@ /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ -#include -#include #include +#include #include +#include /* end standard C headers. */ @@ -253,10 +253,10 @@ /* C99 systems have . Non-C99 systems may or may not. */ -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. + * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 @@ -273,41 +273,41 @@ typedef uint32_t flex_uint32_t; typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; +typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; /* Limits of integral types. */ #ifndef INT8_MIN -#define INT8_MIN (-128) +#define INT8_MIN (-128) #endif #ifndef INT16_MIN -#define INT16_MIN (-32767-1) +#define INT16_MIN (-32767 - 1) #endif #ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) +#define INT32_MIN (-2147483647 - 1) #endif #ifndef INT8_MAX -#define INT8_MAX (127) +#define INT8_MAX (127) #endif #ifndef INT16_MAX -#define INT16_MAX (32767) +#define INT16_MAX (32767) #endif #ifndef INT32_MAX -#define INT32_MAX (2147483647) +#define INT32_MAX (2147483647) #endif #ifndef UINT8_MAX -#define UINT8_MAX (255U) +#define UINT8_MAX (255U) #endif #ifndef UINT16_MAX -#define UINT16_MAX (65535U) +#define UINT16_MAX (65535U) #endif #ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) +#define UINT32_MAX (4294967295U) #endif #ifndef SIZE_MAX -#define SIZE_MAX (~(size_t)0) +#define SIZE_MAX (~(size_t) 0) #endif #endif /* ! C99 */ @@ -331,23 +331,23 @@ typedef unsigned int flex_uint32_t; /* Promotes a possibly negative, possibly signed char to an * integer in range [0..255] for use as an array index. */ -#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) +#define YY_SC_TO_UI(c) ((YY_CHAR)(c)) /* An opaque pointer. */ #ifndef YY_TYPEDEF_YY_SCANNER_T #define YY_TYPEDEF_YY_SCANNER_T -typedef void* yyscan_t; +typedef void *yyscan_t; #endif /* For convenience, these vars (plus the bison vars far below) are macros in the reentrant scanner. */ -#define yyin yyg->yyin_r -#define yyout yyg->yyout_r -#define yyextra yyg->yyextra_r -#define yyleng yyg->yyleng_r -#define yytext yyg->yytext_r -#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) -#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) #define yy_flex_debug yyg->yy_flex_debug_r /* Enter a start condition. This macro really ought to take a parameter, @@ -360,11 +360,11 @@ typedef void* yyscan_t; * compatibility. */ #define YY_START ((yyg->yy_start - 1) / 2) -#define YYSTATE YY_START +#define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin , yyscanner ) +#define YY_NEW_FILE yyrestart(yyin, yyscanner) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ @@ -380,9 +380,10 @@ typedef void* yyscan_t; #endif /* __ia64__ */ #endif -/* The state buf must be large enough to hold one state per character in the main buffer. +/* The state buf must be large enough to hold one state per character in the + * main buffer. */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE @@ -395,109 +396,109 @@ typedef size_t yy_size_t; #endif #define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires - * access to the local variable yy_act. Since yyless() is a macro, it would break - * existing scanners that call yyless() from OUTSIDE yylex. - * One obvious solution it to make yy_act a global. I tried that, and saw - * a 5% performance hit in a non-yylineno scanner, because yy_act is - * normally declared as a register variable-- so it is not worth it. - */ - #define YY_LESS_LINENO(n) \ - do { \ - int yyl;\ - for ( yyl = n; yyl < yyleng; ++yyl )\ - if ( yytext[yyl] == '\n' )\ - --yylineno;\ - }while(0) - #define YY_LINENO_REWIND_TO(dst) \ - do {\ - const char *p;\ - for ( p = yy_cp-1; p >= (dst); --p)\ - if ( *p == '\n' )\ - --yylineno;\ - }while(0) - +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* Note: We specifically omit the test for yy_rule_can_match_eol because it + * requires access to the local variable yy_act. Since yyless() is a macro, it + * would break existing scanners that call yyless() from OUTSIDE yylex. One + * obvious solution it to make yy_act a global. I tried that, and saw a 5% + * performance hit in a non-yylineno scanner, because yy_act is normally + * declared as a register variable-- so it is not worth it. + */ +#define YY_LESS_LINENO(n) \ + do \ + { \ + int yyl; \ + for (yyl = n; yyl < yyleng; ++yyl) \ + if (yytext[yyl] == '\n') \ + --yylineno; \ + } while (0) +#define YY_LINENO_REWIND_TO(dst) \ + do \ + { \ + const char *p; \ + for (p = yy_cp - 1; p >= (dst); --p) \ + if (*p == '\n') \ + --yylineno; \ + } while (0) + /* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = yyg->yy_hold_char; \ - YY_RESTORE_YY_MORE_OFFSET \ - yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) -#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg); \ + *yy_cp = yyg->yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } while (0) +#define unput(c) yyunput(c, yyg->yytext_ptr, yyscanner) #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 +{ + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ #define YY_BUFFER_EOF_PENDING 2 - - }; +}; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ /* We provide macros for accessing buffer states in case in the @@ -506,59 +507,60 @@ struct yy_buffer_state * * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ - ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ - : NULL) +#define YY_CURRENT_BUFFER \ + (yyg->yy_buffer_stack ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ #define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] -void yyrestart ( FILE *input_file , yyscan_t yyscanner ); -void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner ); -void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); -void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); -void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -void yypop_buffer_state ( yyscan_t yyscanner ); +void yyrestart(FILE *input_file, yyscan_t yyscanner); +void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner); +YY_BUFFER_STATE yy_create_buffer(FILE *file, int size, yyscan_t yyscanner); +void yy_delete_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner); +void yy_flush_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner); +void yypush_buffer_state(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner); +void yypop_buffer_state(yyscan_t yyscanner); -static void yyensure_buffer_stack ( yyscan_t yyscanner ); -static void yy_load_buffer_state ( yyscan_t yyscanner ); -static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner ); -#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , yyscanner) +static void yyensure_buffer_stack(yyscan_t yyscanner); +static void yy_load_buffer_state(yyscan_t yyscanner); +static void yy_init_buffer(YY_BUFFER_STATE b, FILE *file, yyscan_t yyscanner); +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER, yyscanner) -YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner ); -YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_buffer(char *base, yy_size_t size, yyscan_t yyscanner); +YY_BUFFER_STATE yy_scan_string(const char *yy_str, yyscan_t yyscanner); +YY_BUFFER_STATE yy_scan_bytes(const char *bytes, int len, yyscan_t yyscanner); -void *yyalloc ( yy_size_t , yyscan_t yyscanner ); -void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner ); -void yyfree ( void * , yyscan_t yyscanner ); +void *yyalloc(yy_size_t, yyscan_t yyscanner); +void *yyrealloc(void *, yy_size_t, yyscan_t yyscanner); +void yyfree(void *, yyscan_t yyscanner); #define yy_new_buffer yy_create_buffer -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } +#define yy_set_interactive(is_interactive) \ + { \ + if (!YY_CURRENT_BUFFER) \ + { \ + yyensure_buffer_stack(yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer( \ + yyin, YY_BUF_SIZE, yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } +#define yy_set_bol(at_bol) \ + { \ + if (!YY_CURRENT_BUFFER) \ + { \ + yyensure_buffer_stack(yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer( \ + yyin, YY_BUF_SIZE, yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) /* Begin user sect3 */ -#define yara_yywrap(yyscanner) (/*CONSTCOND*/1) +#define yara_yywrap(yyscanner) (/*CONSTCOND*/ 1) #define YY_SKIP_YYWRAP typedef flex_uint8_t YY_CHAR; @@ -566,362 +568,267 @@ typedef int yy_state_type; #define yytext_ptr yytext_r -static yy_state_type yy_get_previous_state ( yyscan_t yyscanner ); -static yy_state_type yy_try_NUL_trans ( yy_state_type current_state , yyscan_t yyscanner); -static int yy_get_next_buffer ( yyscan_t yyscanner ); -static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner ); +static yy_state_type yy_get_previous_state(yyscan_t yyscanner); +static yy_state_type yy_try_NUL_trans( + yy_state_type current_state, + yyscan_t yyscanner); +static int yy_get_next_buffer(yyscan_t yyscanner); +static void yynoreturn yy_fatal_error(const char *msg, yyscan_t yyscanner); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ -#define YY_DO_BEFORE_ACTION \ - yyg->yytext_ptr = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ - yyg->yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - yyg->yy_c_buf_p = yy_cp; -#define YY_NUM_RULES 83 +#define YY_DO_BEFORE_ACTION \ + yyg->yytext_ptr = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + yyg->yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yyg->yy_c_buf_p = yy_cp; +#define YY_NUM_RULES 83 #define YY_END_OF_BUFFER 84 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static const flex_int16_t yy_accept[299] = - { 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 84, 82, 81, 81, 56, 78, 54, 53, 82, 79, - 59, 59, 2, 82, 3, 55, 58, 58, 58, 58, - 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, - 58, 58, 58, 58, 82, 70, 71, 63, 83, 76, - 77, 73, 83, 50, 51, 47, 47, 56, 7, 54, - 52, 53, 1, 45, 48, 0, 59, 0, 0, 0, - 0, 8, 4, 6, 5, 9, 55, 58, 58, 58, - 58, 28, 58, 58, 58, 58, 58, 58, 58, 58, - 58, 58, 58, 29, 58, 58, 58, 58, 30, 27, - - 58, 58, 58, 58, 58, 58, 58, 58, 0, 0, - 70, 72, 67, 68, 66, 65, 64, 72, 76, 73, - 73, 75, 74, 50, 46, 48, 60, 59, 62, 61, - 33, 26, 34, 58, 58, 58, 58, 58, 58, 58, - 32, 58, 58, 58, 58, 58, 58, 58, 58, 58, - 58, 58, 25, 58, 58, 58, 58, 58, 58, 58, - 58, 17, 80, 0, 0, 0, 58, 58, 58, 58, - 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, - 58, 58, 57, 58, 58, 13, 58, 58, 12, 58, - 58, 31, 23, 16, 0, 0, 0, 0, 0, 80, - - 69, 15, 58, 58, 58, 58, 58, 24, 58, 58, - 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, - 58, 58, 0, 0, 18, 58, 58, 58, 58, 58, - 58, 11, 58, 58, 44, 58, 57, 58, 58, 21, - 58, 58, 58, 0, 0, 0, 0, 0, 80, 58, - 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, - 37, 10, 58, 14, 0, 80, 0, 0, 0, 58, - 58, 38, 40, 58, 36, 20, 58, 58, 0, 58, - 58, 0, 0, 0, 58, 22, 58, 41, 43, 49, - 58, 58, 19, 35, 58, 39, 42, 0 - - } ; - -static const YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 5, 6, 7, 8, 1, 1, 1, 9, - 9, 10, 1, 1, 9, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 18, 20, 21, 1, 1, 22, - 23, 24, 9, 25, 26, 27, 26, 26, 26, 26, - 28, 28, 28, 28, 29, 28, 30, 28, 28, 28, - 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, - 9, 31, 9, 1, 32, 1, 33, 34, 35, 36, - - 37, 38, 39, 40, 41, 28, 28, 42, 43, 44, - 45, 46, 28, 47, 48, 49, 50, 51, 52, 53, - 54, 55, 56, 9, 57, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static const YY_CHAR yy_meta[58] = - { 0, - 1, 2, 3, 2, 1, 4, 1, 1, 2, 5, - 6, 7, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 1, 9, 1, 1, 10, 10, 11, 12, 12, - 13, 11, 10, 10, 10, 10, 10, 10, 11, 11, - 11, 11, 11, 11, 12, 11, 11, 11, 11, 11, - 11, 11, 12, 11, 11, 1, 1 - } ; - -static const flex_int16_t yy_base[321] = - { 0, - 0, 0, 55, 56, 57, 60, 628, 627, 622, 621, - 630, 635, 635, 635, 606, 635, 0, 618, 616, 54, - 54, 60, 45, 603, 50, 0, 0, 33, 592, 579, - 579, 52, 580, 66, 43, 576, 32, 573, 569, 569, - 64, 576, 575, 570, 602, 0, 635, 635, 86, 0, - 635, 67, 601, 0, 635, 635, 600, 588, 635, 0, - 635, 600, 635, 635, 0, 0, 0, 582, 581, 105, - 0, 635, 635, 635, 635, 635, 0, 0, 565, 42, - 571, 0, 557, 560, 76, 561, 560, 554, 558, 554, - 553, 553, 550, 91, 546, 545, 544, 92, 0, 0, - - 551, 549, 95, 553, 539, 544, 551, 539, 86, 119, - 0, 635, 635, 635, 635, 635, 635, 0, 0, 537, - 635, 635, 635, 0, 635, 0, 0, 635, 131, 0, - 0, 0, 0, 543, 546, 102, 534, 534, 532, 542, - 0, 536, 543, 532, 539, 529, 531, 138, 539, 536, - 537, 536, 0, 517, 530, 519, 524, 521, 526, 513, - 524, 0, 635, 550, 158, 0, 518, 539, 516, 523, - 503, 500, 516, 504, 499, 517, 500, 500, 500, 496, - 526, 529, 509, 495, 501, 0, 492, 506, 0, 489, - 493, 0, 0, 0, 526, 122, 0, 0, 143, 0, - - 635, 0, 518, 485, 492, 491, 485, 0, 489, 484, - 486, 494, 474, 475, 472, 468, 444, 444, 430, 410, - 407, 392, 215, 263, 378, 385, 379, 373, 376, 360, - 363, 0, 366, 365, 0, 368, 0, 355, 350, 0, - 359, 343, 342, 0, 0, 274, 318, 269, 0, 288, - 283, 279, 286, 284, 287, 287, 278, 272, 318, 267, - 0, 0, 277, 0, 270, 307, 286, 304, 287, 278, - 260, 0, 0, 241, 0, 0, 226, 117, 300, 115, - 88, 293, 0, 303, 99, 0, 67, 0, 0, 635, - 57, 60, 0, 0, 55, 0, 0, 635, 331, 344, - - 357, 370, 376, 381, 389, 396, 401, 406, 417, 427, - 439, 452, 464, 477, 490, 86, 496, 499, 509, 515 - } ; - -static const flex_int16_t yy_def[321] = - { 0, - 298, 1, 299, 299, 300, 300, 301, 301, 302, 302, - 298, 298, 298, 298, 303, 298, 304, 305, 298, 298, - 306, 306, 298, 298, 298, 307, 308, 308, 308, 308, - 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, - 308, 308, 308, 308, 309, 310, 298, 298, 311, 312, - 298, 298, 313, 314, 298, 298, 298, 303, 298, 304, - 298, 305, 298, 298, 315, 316, 22, 298, 298, 298, - 317, 298, 298, 298, 298, 298, 307, 308, 308, 308, - 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, - 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, - - 308, 308, 308, 308, 308, 308, 308, 308, 309, 298, - 310, 298, 298, 298, 298, 298, 298, 318, 312, 298, - 298, 298, 298, 314, 298, 315, 316, 298, 298, 317, - 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, - 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, - 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, - 308, 308, 298, 319, 298, 320, 308, 308, 308, 308, - 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, - 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, - 308, 308, 308, 308, 319, 319, 165, 165, 165, 165, - - 298, 308, 308, 308, 308, 308, 308, 308, 308, 308, - 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, - 308, 308, 298, 165, 308, 308, 308, 308, 308, 308, - 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, - 308, 308, 308, 223, 223, 319, 223, 223, 223, 308, - 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, - 308, 308, 308, 308, 319, 319, 165, 223, 223, 308, - 308, 308, 308, 308, 308, 308, 308, 308, 298, 308, - 308, 319, 223, 223, 308, 308, 308, 308, 308, 298, - 308, 308, 308, 308, 308, 308, 308, 0, 298, 298, - - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298 - } ; - -static const flex_int16_t yy_nxt[693] = - { 0, - 12, 13, 14, 13, 15, 16, 17, 18, 12, 12, - 19, 20, 21, 22, 22, 22, 22, 22, 22, 22, - 22, 23, 24, 25, 26, 27, 27, 27, 27, 27, - 12, 27, 28, 29, 30, 27, 31, 32, 33, 27, - 34, 27, 35, 36, 37, 38, 39, 40, 41, 42, - 27, 43, 44, 27, 27, 45, 12, 47, 47, 51, - 48, 48, 51, 64, 66, 65, 72, 73, 52, 99, - 66, 52, 75, 76, 79, 96, 80, 132, 100, 97, - 81, 82, 68, 69, 86, 49, 49, 53, 68, 69, - 53, 113, 87, 127, 297, 133, 88, 110, 70, 296, - - 91, 89, 92, 104, 298, 295, 71, 120, 93, 94, - 105, 137, 298, 95, 121, 294, 114, 129, 129, 129, - 129, 129, 129, 129, 138, 147, 152, 156, 164, 115, - 165, 196, 116, 109, 117, 293, 292, 169, 118, 148, - 153, 157, 163, 129, 129, 129, 129, 129, 129, 129, - 170, 181, 223, 182, 224, 291, 289, 183, 197, 198, - 109, 198, 197, 197, 197, 197, 198, 197, 197, 199, - 198, 198, 198, 198, 198, 198, 198, 198, 198, 197, - 197, 197, 197, 198, 198, 197, 197, 197, 197, 197, - 198, 198, 198, 198, 198, 198, 197, 197, 197, 197, - - 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, - 197, 197, 197, 197, 200, 244, 245, 246, 245, 244, - 244, 244, 244, 245, 247, 244, 248, 245, 245, 245, - 245, 245, 245, 245, 245, 245, 244, 244, 244, 244, - 245, 245, 244, 244, 244, 244, 244, 245, 245, 245, - 245, 245, 245, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 249, 223, 288, 224, 246, 246, 246, 268, 282, - 269, 283, 246, 196, 287, 265, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 223, 268, 224, 269, 246, - - 246, 279, 196, 286, 246, 290, 246, 246, 246, 246, - 246, 246, 268, 285, 269, 284, 196, 281, 280, 279, - 278, 277, 276, 275, 274, 273, 272, 271, 270, 267, - 266, 46, 46, 46, 46, 46, 46, 46, 46, 46, - 46, 46, 46, 46, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 54, 54, 54, - 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, - 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, - 56, 56, 56, 58, 58, 58, 58, 58, 60, 264, - 60, 60, 60, 62, 263, 262, 62, 261, 62, 62, - - 62, 67, 260, 67, 259, 258, 257, 67, 77, 256, - 77, 77, 77, 78, 255, 78, 78, 78, 109, 109, - 254, 253, 252, 109, 109, 251, 109, 111, 111, 250, - 243, 111, 111, 111, 111, 111, 111, 111, 111, 112, - 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, - 112, 112, 119, 119, 242, 119, 119, 119, 241, 119, - 119, 119, 119, 119, 122, 122, 240, 122, 122, 122, - 122, 122, 122, 122, 122, 122, 122, 124, 124, 124, - 239, 124, 124, 124, 124, 124, 124, 124, 124, 124, - 126, 126, 238, 126, 126, 126, 126, 126, 126, 126, - - 126, 126, 126, 130, 237, 130, 166, 236, 166, 195, - 195, 195, 195, 195, 195, 195, 195, 195, 195, 195, - 195, 195, 201, 235, 201, 234, 233, 232, 231, 230, - 229, 228, 227, 226, 225, 196, 222, 221, 220, 219, - 218, 217, 216, 183, 183, 215, 214, 213, 212, 211, - 210, 209, 208, 207, 206, 205, 204, 203, 202, 196, - 194, 148, 193, 192, 191, 190, 189, 188, 187, 186, - 185, 184, 180, 179, 178, 177, 176, 175, 174, 173, - 172, 171, 168, 167, 121, 162, 161, 160, 159, 158, - 155, 154, 151, 150, 149, 146, 145, 144, 143, 142, - - 141, 140, 139, 136, 135, 134, 131, 128, 128, 61, - 298, 125, 123, 110, 108, 107, 106, 103, 102, 101, - 98, 90, 85, 84, 83, 74, 63, 61, 59, 298, - 57, 57, 55, 55, 11, 298, 298, 298, 298, 298, - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, - 298, 298 - - } ; - -static const flex_int16_t yy_chk[693] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 3, 4, 5, - 3, 4, 6, 20, 21, 20, 23, 23, 5, 37, - 22, 6, 25, 25, 28, 35, 28, 80, 37, 35, - 28, 28, 21, 21, 32, 3, 4, 5, 22, 22, - 6, 49, 32, 316, 295, 80, 32, 109, 21, 292, - - 34, 32, 34, 41, 22, 291, 21, 52, 34, 34, - 41, 85, 22, 34, 52, 287, 49, 70, 70, 70, - 70, 70, 70, 70, 85, 94, 98, 103, 110, 49, - 110, 196, 49, 196, 49, 285, 281, 136, 49, 94, - 98, 103, 109, 129, 129, 129, 129, 129, 129, 129, - 136, 148, 199, 148, 199, 280, 278, 148, 165, 165, - 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, - 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, - 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, - 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, - - 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, - 165, 165, 165, 165, 165, 223, 223, 223, 223, 223, - 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, - 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, - 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, - 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, - 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, - 223, 223, 224, 277, 224, 246, 246, 246, 248, 265, - 248, 265, 246, 246, 274, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 267, 269, 267, 269, 246, - - 246, 279, 282, 271, 282, 279, 246, 246, 246, 246, - 246, 246, 284, 270, 284, 268, 266, 263, 260, 259, - 258, 257, 256, 255, 254, 253, 252, 251, 250, 247, - 246, 299, 299, 299, 299, 299, 299, 299, 299, 299, - 299, 299, 299, 299, 300, 300, 300, 300, 300, 300, - 300, 300, 300, 300, 300, 300, 300, 301, 301, 301, - 301, 301, 301, 301, 301, 301, 301, 301, 301, 301, - 302, 302, 302, 302, 302, 302, 302, 302, 302, 302, - 302, 302, 302, 303, 303, 303, 303, 303, 304, 243, - 304, 304, 304, 305, 242, 241, 305, 239, 305, 305, - - 305, 306, 238, 306, 236, 234, 233, 306, 307, 231, - 307, 307, 307, 308, 230, 308, 308, 308, 309, 309, - 229, 228, 227, 309, 309, 226, 309, 310, 310, 225, - 222, 310, 310, 310, 310, 310, 310, 310, 310, 311, - 311, 311, 311, 311, 311, 311, 311, 311, 311, 311, - 311, 311, 312, 312, 221, 312, 312, 312, 220, 312, - 312, 312, 312, 312, 313, 313, 219, 313, 313, 313, - 313, 313, 313, 313, 313, 313, 313, 314, 314, 314, - 218, 314, 314, 314, 314, 314, 314, 314, 314, 314, - 315, 315, 217, 315, 315, 315, 315, 315, 315, 315, - - 315, 315, 315, 317, 216, 317, 318, 215, 318, 319, - 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - 319, 319, 320, 214, 320, 213, 212, 211, 210, 209, - 207, 206, 205, 204, 203, 195, 191, 190, 188, 187, - 185, 184, 183, 182, 181, 180, 179, 178, 177, 176, - 175, 174, 173, 172, 171, 170, 169, 168, 167, 164, - 161, 160, 159, 158, 157, 156, 155, 154, 152, 151, - 150, 149, 147, 146, 145, 144, 143, 142, 140, 139, - 138, 137, 135, 134, 120, 108, 107, 106, 105, 104, - 102, 101, 97, 96, 95, 93, 92, 91, 90, 89, - - 88, 87, 86, 84, 83, 81, 79, 69, 68, 62, - 58, 57, 53, 45, 44, 43, 42, 40, 39, 38, - 36, 33, 31, 30, 29, 24, 19, 18, 15, 11, - 10, 9, 8, 7, 298, 298, 298, 298, 298, 298, - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, - 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, - 298, 298 - - } ; +{ + flex_int32_t yy_verify; + flex_int32_t yy_nxt; +}; +static const flex_int16_t yy_accept[299] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 82, 81, 81, 56, 78, + 54, 53, 82, 79, 59, 59, 2, 82, 3, 55, 58, 58, 58, 58, 58, 58, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 82, 70, 71, 63, 83, 76, + 77, 73, 83, 50, 51, 47, 47, 56, 7, 54, 52, 53, 1, 45, 48, 0, 59, + 0, 0, 0, 0, 8, 4, 6, 5, 9, 55, 58, 58, 58, 58, 28, 58, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 29, 58, 58, 58, 58, 30, 27, + + 58, 58, 58, 58, 58, 58, 58, 58, 0, 0, 70, 72, 67, 68, 66, 65, 64, + 72, 76, 73, 73, 75, 74, 50, 46, 48, 60, 59, 62, 61, 33, 26, 34, 58, + 58, 58, 58, 58, 58, 58, 32, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, + 58, 25, 58, 58, 58, 58, 58, 58, 58, 58, 17, 80, 0, 0, 0, 58, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 57, 58, 58, + 13, 58, 58, 12, 58, 58, 31, 23, 16, 0, 0, 0, 0, 0, 80, + + 69, 15, 58, 58, 58, 58, 58, 24, 58, 58, 58, 58, 58, 58, 58, 58, 58, + 58, 58, 58, 58, 58, 0, 0, 18, 58, 58, 58, 58, 58, 58, 11, 58, 58, + 44, 58, 57, 58, 58, 21, 58, 58, 58, 0, 0, 0, 0, 0, 80, 58, 58, + 58, 58, 58, 58, 58, 58, 58, 58, 58, 37, 10, 58, 14, 0, 80, 0, 0, + 0, 58, 58, 38, 40, 58, 36, 20, 58, 58, 0, 58, 58, 0, 0, 0, 58, + 22, 58, 41, 43, 49, 58, 58, 19, 35, 58, 39, 42, 0 + +}; + +static const YY_CHAR yy_ec[256] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 4, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 5, 6, 7, 8, 1, + 1, 1, 9, 9, 10, 1, 1, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 18, 20, + 21, 1, 1, 22, 23, 24, 9, 25, 26, 27, 26, 26, 26, 26, 28, 28, 28, 28, 29, + 28, 30, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 9, 31, 9, 1, + 32, 1, 33, 34, 35, 36, + + 37, 38, 39, 40, 41, 28, 28, 42, 43, 44, 45, 46, 28, 47, 48, 49, 50, 51, 52, + 53, 54, 55, 56, 9, 57, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + +static const YY_CHAR yy_meta[58] = { + 0, 1, 2, 3, 2, 1, 4, 1, 1, 2, 5, 6, 7, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 1, 9, 1, 1, 10, 10, 11, 12, + 12, 13, 11, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, + 12, 11, 11, 11, 11, 11, 11, 11, 12, 11, 11, 1, 1}; + +static const flex_int16_t yy_base[321] = { + 0, 0, 0, 55, 56, 57, 60, 628, 627, 622, 621, 630, 635, 635, 635, + 606, 635, 0, 618, 616, 54, 54, 60, 45, 603, 50, 0, 0, 33, 592, + 579, 579, 52, 580, 66, 43, 576, 32, 573, 569, 569, 64, 576, 575, 570, + 602, 0, 635, 635, 86, 0, 635, 67, 601, 0, 635, 635, 600, 588, 635, + 0, 635, 600, 635, 635, 0, 0, 0, 582, 581, 105, 0, 635, 635, 635, + 635, 635, 0, 0, 565, 42, 571, 0, 557, 560, 76, 561, 560, 554, 558, + 554, 553, 553, 550, 91, 546, 545, 544, 92, 0, 0, + + 551, 549, 95, 553, 539, 544, 551, 539, 86, 119, 0, 635, 635, 635, 635, + 635, 635, 0, 0, 537, 635, 635, 635, 0, 635, 0, 0, 635, 131, 0, + 0, 0, 0, 543, 546, 102, 534, 534, 532, 542, 0, 536, 543, 532, 539, + 529, 531, 138, 539, 536, 537, 536, 0, 517, 530, 519, 524, 521, 526, 513, + 524, 0, 635, 550, 158, 0, 518, 539, 516, 523, 503, 500, 516, 504, 499, + 517, 500, 500, 500, 496, 526, 529, 509, 495, 501, 0, 492, 506, 0, 489, + 493, 0, 0, 0, 526, 122, 0, 0, 143, 0, + + 635, 0, 518, 485, 492, 491, 485, 0, 489, 484, 486, 494, 474, 475, 472, + 468, 444, 444, 430, 410, 407, 392, 215, 263, 378, 385, 379, 373, 376, 360, + 363, 0, 366, 365, 0, 368, 0, 355, 350, 0, 359, 343, 342, 0, 0, + 274, 318, 269, 0, 288, 283, 279, 286, 284, 287, 287, 278, 272, 318, 267, + 0, 0, 277, 0, 270, 307, 286, 304, 287, 278, 260, 0, 0, 241, 0, + 0, 226, 117, 300, 115, 88, 293, 0, 303, 99, 0, 67, 0, 0, 635, + 57, 60, 0, 0, 55, 0, 0, 635, 331, 344, + + 357, 370, 376, 381, 389, 396, 401, 406, 417, 427, 439, 452, 464, 477, 490, + 86, 496, 499, 509, 515}; + +static const flex_int16_t yy_def[321] = { + 0, 298, 1, 299, 299, 300, 300, 301, 301, 302, 302, 298, 298, 298, 298, + 303, 298, 304, 305, 298, 298, 306, 306, 298, 298, 298, 307, 308, 308, 308, + 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, + 309, 310, 298, 298, 311, 312, 298, 298, 313, 314, 298, 298, 298, 303, 298, + 304, 298, 305, 298, 298, 315, 316, 22, 298, 298, 298, 317, 298, 298, 298, + 298, 298, 307, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, + 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, + + 308, 308, 308, 308, 308, 308, 308, 308, 309, 298, 310, 298, 298, 298, 298, + 298, 298, 318, 312, 298, 298, 298, 298, 314, 298, 315, 316, 298, 298, 317, + 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, + 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, + 308, 308, 298, 319, 298, 320, 308, 308, 308, 308, 308, 308, 308, 308, 308, + 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, + 308, 308, 308, 308, 319, 319, 165, 165, 165, 165, + + 298, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, + 308, 308, 308, 308, 308, 308, 308, 298, 165, 308, 308, 308, 308, 308, 308, + 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 223, 223, + 319, 223, 223, 223, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, 308, + 308, 308, 308, 308, 319, 319, 165, 223, 223, 308, 308, 308, 308, 308, 308, + 308, 308, 308, 298, 308, 308, 319, 223, 223, 308, 308, 308, 308, 308, 298, + 308, 308, 308, 308, 308, 308, 308, 0, 298, 298, + + 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, + 298, 298, 298, 298, 298}; + +static const flex_int16_t yy_nxt[693] = { + 0, 12, 13, 14, 13, 15, 16, 17, 18, 12, 12, 19, 20, 21, 22, + 22, 22, 22, 22, 22, 22, 22, 23, 24, 25, 26, 27, 27, 27, 27, + 27, 12, 27, 28, 29, 30, 27, 31, 32, 33, 27, 34, 27, 35, 36, + 37, 38, 39, 40, 41, 42, 27, 43, 44, 27, 27, 45, 12, 47, 47, + 51, 48, 48, 51, 64, 66, 65, 72, 73, 52, 99, 66, 52, 75, 76, + 79, 96, 80, 132, 100, 97, 81, 82, 68, 69, 86, 49, 49, 53, 68, + 69, 53, 113, 87, 127, 297, 133, 88, 110, 70, 296, + + 91, 89, 92, 104, 298, 295, 71, 120, 93, 94, 105, 137, 298, 95, 121, + 294, 114, 129, 129, 129, 129, 129, 129, 129, 138, 147, 152, 156, 164, 115, + 165, 196, 116, 109, 117, 293, 292, 169, 118, 148, 153, 157, 163, 129, 129, + 129, 129, 129, 129, 129, 170, 181, 223, 182, 224, 291, 289, 183, 197, 198, + 109, 198, 197, 197, 197, 197, 198, 197, 197, 199, 198, 198, 198, 198, 198, + 198, 198, 198, 198, 197, 197, 197, 197, 198, 198, 197, 197, 197, 197, 197, + 198, 198, 198, 198, 198, 198, 197, 197, 197, 197, + + 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, 200, + 244, 245, 246, 245, 244, 244, 244, 244, 245, 247, 244, 248, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 244, 244, 244, 244, 245, 245, 244, 244, 244, + 244, 244, 245, 245, 245, 245, 245, 245, 244, 244, 244, 244, 244, 244, 244, + 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, 249, 223, 288, 224, + 246, 246, 246, 268, 282, 269, 283, 246, 196, 287, 265, 246, 246, 246, 246, + 246, 246, 246, 246, 246, 223, 268, 224, 269, 246, + + 246, 279, 196, 286, 246, 290, 246, 246, 246, 246, 246, 246, 268, 285, 269, + 284, 196, 281, 280, 279, 278, 277, 276, 275, 274, 273, 272, 271, 270, 267, + 266, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 54, 54, 54, + 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 58, 58, 58, 58, 58, 60, 264, + 60, 60, 60, 62, 263, 262, 62, 261, 62, 62, + + 62, 67, 260, 67, 259, 258, 257, 67, 77, 256, 77, 77, 77, 78, 255, + 78, 78, 78, 109, 109, 254, 253, 252, 109, 109, 251, 109, 111, 111, 250, + 243, 111, 111, 111, 111, 111, 111, 111, 111, 112, 112, 112, 112, 112, 112, + 112, 112, 112, 112, 112, 112, 112, 119, 119, 242, 119, 119, 119, 241, 119, + 119, 119, 119, 119, 122, 122, 240, 122, 122, 122, 122, 122, 122, 122, 122, + 122, 122, 124, 124, 124, 239, 124, 124, 124, 124, 124, 124, 124, 124, 124, + 126, 126, 238, 126, 126, 126, 126, 126, 126, 126, + + 126, 126, 126, 130, 237, 130, 166, 236, 166, 195, 195, 195, 195, 195, 195, + 195, 195, 195, 195, 195, 195, 195, 201, 235, 201, 234, 233, 232, 231, 230, + 229, 228, 227, 226, 225, 196, 222, 221, 220, 219, 218, 217, 216, 183, 183, + 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, 196, + 194, 148, 193, 192, 191, 190, 189, 188, 187, 186, 185, 184, 180, 179, 178, + 177, 176, 175, 174, 173, 172, 171, 168, 167, 121, 162, 161, 160, 159, 158, + 155, 154, 151, 150, 149, 146, 145, 144, 143, 142, + + 141, 140, 139, 136, 135, 134, 131, 128, 128, 61, 298, 125, 123, 110, 108, + 107, 106, 103, 102, 101, 98, 90, 85, 84, 83, 74, 63, 61, 59, 298, + 57, 57, 55, 55, 11, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, + 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, + 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, + 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, + 298, 298 + +}; + +static const flex_int16_t yy_chk[693] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4, + 5, 3, 4, 6, 20, 21, 20, 23, 23, 5, 37, 22, 6, 25, 25, + 28, 35, 28, 80, 37, 35, 28, 28, 21, 21, 32, 3, 4, 5, 22, + 22, 6, 49, 32, 316, 295, 80, 32, 109, 21, 292, + + 34, 32, 34, 41, 22, 291, 21, 52, 34, 34, 41, 85, 22, 34, 52, + 287, 49, 70, 70, 70, 70, 70, 70, 70, 85, 94, 98, 103, 110, 49, + 110, 196, 49, 196, 49, 285, 281, 136, 49, 94, 98, 103, 109, 129, 129, + 129, 129, 129, 129, 129, 136, 148, 199, 148, 199, 280, 278, 148, 165, 165, + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, + + 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, 165, + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, + 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 223, 224, 277, 224, + 246, 246, 246, 248, 265, 248, 265, 246, 246, 274, 246, 246, 246, 246, 246, + 246, 246, 246, 246, 246, 267, 269, 267, 269, 246, + + 246, 279, 282, 271, 282, 279, 246, 246, 246, 246, 246, 246, 284, 270, 284, + 268, 266, 263, 260, 259, 258, 257, 256, 255, 254, 253, 252, 251, 250, 247, + 246, 299, 299, 299, 299, 299, 299, 299, 299, 299, 299, 299, 299, 299, 300, + 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 301, 301, 301, + 301, 301, 301, 301, 301, 301, 301, 301, 301, 301, 302, 302, 302, 302, 302, + 302, 302, 302, 302, 302, 302, 302, 302, 303, 303, 303, 303, 303, 304, 243, + 304, 304, 304, 305, 242, 241, 305, 239, 305, 305, + + 305, 306, 238, 306, 236, 234, 233, 306, 307, 231, 307, 307, 307, 308, 230, + 308, 308, 308, 309, 309, 229, 228, 227, 309, 309, 226, 309, 310, 310, 225, + 222, 310, 310, 310, 310, 310, 310, 310, 310, 311, 311, 311, 311, 311, 311, + 311, 311, 311, 311, 311, 311, 311, 312, 312, 221, 312, 312, 312, 220, 312, + 312, 312, 312, 312, 313, 313, 219, 313, 313, 313, 313, 313, 313, 313, 313, + 313, 313, 314, 314, 314, 218, 314, 314, 314, 314, 314, 314, 314, 314, 314, + 315, 315, 217, 315, 315, 315, 315, 315, 315, 315, + + 315, 315, 315, 317, 216, 317, 318, 215, 318, 319, 319, 319, 319, 319, 319, + 319, 319, 319, 319, 319, 319, 319, 320, 214, 320, 213, 212, 211, 210, 209, + 207, 206, 205, 204, 203, 195, 191, 190, 188, 187, 185, 184, 183, 182, 181, + 180, 179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 164, + 161, 160, 159, 158, 157, 156, 155, 154, 152, 151, 150, 149, 147, 146, 145, + 144, 143, 142, 140, 139, 138, 137, 135, 134, 120, 108, 107, 106, 105, 104, + 102, 101, 97, 96, 95, 93, 92, 91, 90, 89, + + 88, 87, 86, 84, 83, 81, 79, 69, 68, 62, 58, 57, 53, 45, 44, + 43, 42, 40, 39, 38, 36, 33, 31, 30, 29, 24, 19, 18, 15, 11, + 10, 9, 8, 7, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, + 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, + 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, + 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, + 298, 298 + +}; /* Table of booleans, true if rule could match eol. */ -static const flex_int32_t yy_rule_can_match_eol[84] = - { 0, -0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, - 1, 1, 0, 0, }; +static const flex_int32_t yy_rule_can_match_eol[84] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, +}; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET #line 1 "lexer.l" @@ -970,11 +877,11 @@ with noyywrap then we can remove this pragma. #endif #include +#include #include #include #include #include -#include #if defined(_WIN32) || defined(__CYGWIN__) #include @@ -987,88 +894,87 @@ with noyywrap then we can remove this pragma. #define strtoll _strtoi64 #endif +#include #include #include -#include -#include #include -#include +#include #include +#include #include "grammar.h" -#define error(error_code) \ - { \ - compiler->last_error = error_code; \ - yyerror(yyscanner, compiler, NULL); \ - yyterminate(); \ - } +#define error(error_code) \ + { \ + compiler->last_error = error_code; \ + yyerror(yyscanner, compiler, NULL); \ + yyterminate(); \ + } -#define syntax_error(error_msg) \ - { \ - yr_compiler_set_error_extra_info(compiler, error_msg); \ - error(ERROR_SYNTAX_ERROR); \ - } +#define syntax_error(error_msg) \ + { \ + yr_compiler_set_error_extra_info(compiler, error_msg); \ + error(ERROR_SYNTAX_ERROR); \ + } -#define lex_check_space_ok(data, current_size, max_length) \ - if (strlen(data) + current_size >= max_length - 1) \ - { \ - yyerror(yyscanner, compiler, "out of space in lex_buf"); \ - yyterminate(); \ - } +#define lex_check_space_ok(data, current_size, max_length) \ + if (strlen(data) + current_size >= max_length - 1) \ + { \ + yyerror(yyscanner, compiler, "out of space in lex_buf"); \ + yyterminate(); \ + } -#define yytext_to_buffer \ - { \ - char *yptr = yytext; \ - lex_check_space_ok(yptr, yyextra->lex_buf_len, YR_LEX_BUF_SIZE); \ - while(*yptr) \ - { \ - *yyextra->lex_buf_ptr++ = *yptr++; \ - yyextra->lex_buf_len++; \ - } \ - } +#define yytext_to_buffer \ + { \ + char *yptr = yytext; \ + lex_check_space_ok(yptr, yyextra->lex_buf_len, YR_LEX_BUF_SIZE); \ + while (*yptr) \ + { \ + *yyextra->lex_buf_ptr++ = *yptr++; \ + yyextra->lex_buf_len++; \ + } \ + } -#define alloc_sized_string(str, str_len) \ - SIZED_STRING* str = (SIZED_STRING*) yr_malloc( \ - str_len + sizeof(SIZED_STRING)); \ - if (str == NULL) \ - { \ +#define alloc_sized_string(str, str_len) \ + SIZED_STRING *str = (SIZED_STRING *) yr_malloc( \ + str_len + sizeof(SIZED_STRING)); \ + if (str == NULL) \ + { \ yyerror(yyscanner, compiler, "not enough memory"); \ - yyterminate(); \ - } \ - else \ - { \ - str->length = (uint32_t) (str_len); \ - str->flags = 0; \ - } \ + yyterminate(); \ + } \ + else \ + { \ + str->length = (uint32_t)(str_len); \ + str->flags = 0; \ + } #ifdef _WIN32 #define snprintf _snprintf #endif -static bool is_absolute_path( - char* path) +static bool is_absolute_path(char *path) { if (path == NULL) return false; - #if defined(_WIN32) || defined(__CYGWIN__) - return strlen(path) > 2 && - path[1] == ':' && (path[2] == '/' || path[2] == '\\'); - #else +#if defined(_WIN32) || defined(__CYGWIN__) + return strlen(path) > 2 && path[1] == ':' && + (path[2] == '/' || path[2] == '\\'); +#else return strlen(path) > 0 && path[0] == '/'; - #endif +#endif } #line 1063 "lexer.c" #define YY_NO_UNISTD_H 1 -#define YY_NO_INPUT 1 +#define YY_NO_INPUT 1 #line 1067 "lexer.c" #define INITIAL 0 -#define str 1 -#define regexp 2 +#define str 1 +#define regexp 2 #define include 3 #define comment 4 @@ -1086,86 +992,86 @@ static bool is_absolute_path( /* Holds the entire state of the reentrant scanner. */ struct yyguts_t - { +{ + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; - /* User-defined. Not touched by flex. */ - YY_EXTRA_TYPE yyextra_r; + /* The rest are the same as the globals declared in the non-reentrant scanner. + */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE *yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + int yy_n_chars; + int yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char *yy_last_accepting_cpos; - /* The rest are the same as the globals declared in the non-reentrant scanner. */ - FILE *yyin_r, *yyout_r; - size_t yy_buffer_stack_top; /**< index of top of stack. */ - size_t yy_buffer_stack_max; /**< capacity of stack. */ - YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ - char yy_hold_char; - int yy_n_chars; - int yyleng_r; - char *yy_c_buf_p; - int yy_init; - int yy_start; - int yy_did_buffer_switch_on_eof; - int yy_start_stack_ptr; - int yy_start_stack_depth; - int *yy_start_stack; - yy_state_type yy_last_accepting_state; - char* yy_last_accepting_cpos; + int yylineno_r; + int yy_flex_debug_r; - int yylineno_r; - int yy_flex_debug_r; + char *yytext_r; + int yy_more_flag; + int yy_more_len; - char *yytext_r; - int yy_more_flag; - int yy_more_len; + YYSTYPE *yylval_r; - YYSTYPE * yylval_r; +}; /* end struct yyguts_t */ - }; /* end struct yyguts_t */ +static int yy_init_globals(yyscan_t yyscanner); -static int yy_init_globals ( yyscan_t yyscanner ); +/* This must go here because YYSTYPE and YYLTYPE are included + * from bison output in section 1.*/ +#define yylval yyg->yylval_r - /* This must go here because YYSTYPE and YYLTYPE are included - * from bison output in section 1.*/ - # define yylval yyg->yylval_r - -int yylex_init (yyscan_t* scanner); +int yylex_init(yyscan_t *scanner); -int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner); +int yylex_init_extra(YY_EXTRA_TYPE user_defined, yyscan_t *scanner); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int yylex_destroy ( yyscan_t yyscanner ); +int yylex_destroy(yyscan_t yyscanner); -int yyget_debug ( yyscan_t yyscanner ); +int yyget_debug(yyscan_t yyscanner); -void yyset_debug ( int debug_flag , yyscan_t yyscanner ); +void yyset_debug(int debug_flag, yyscan_t yyscanner); -YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner ); +YY_EXTRA_TYPE yyget_extra(yyscan_t yyscanner); -void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); +void yyset_extra(YY_EXTRA_TYPE user_defined, yyscan_t yyscanner); -FILE *yyget_in ( yyscan_t yyscanner ); +FILE *yyget_in(yyscan_t yyscanner); -void yyset_in ( FILE * _in_str , yyscan_t yyscanner ); +void yyset_in(FILE *_in_str, yyscan_t yyscanner); -FILE *yyget_out ( yyscan_t yyscanner ); +FILE *yyget_out(yyscan_t yyscanner); -void yyset_out ( FILE * _out_str , yyscan_t yyscanner ); +void yyset_out(FILE *_out_str, yyscan_t yyscanner); - int yyget_leng ( yyscan_t yyscanner ); +int yyget_leng(yyscan_t yyscanner); -char *yyget_text ( yyscan_t yyscanner ); +char *yyget_text(yyscan_t yyscanner); -int yyget_lineno ( yyscan_t yyscanner ); +int yyget_lineno(yyscan_t yyscanner); -void yyset_lineno ( int _line_number , yyscan_t yyscanner ); +void yyset_lineno(int _line_number, yyscan_t yyscanner); -int yyget_column ( yyscan_t yyscanner ); +int yyget_column(yyscan_t yyscanner); -void yyset_column ( int _column_no , yyscan_t yyscanner ); +void yyset_column(int _column_no, yyscan_t yyscanner); -YYSTYPE * yyget_lval ( yyscan_t yyscanner ); +YYSTYPE *yyget_lval(yyscan_t yyscanner); -void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner ); +void yyset_lval(YYSTYPE *yylval_param, yyscan_t yyscanner); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -1173,29 +1079,29 @@ void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap ( yyscan_t yyscanner ); +extern "C" int yywrap(yyscan_t yyscanner); #else -extern int yywrap ( yyscan_t yyscanner ); +extern int yywrap(yyscan_t yyscanner); #endif #endif #ifndef YY_NO_UNPUT - + #endif #ifndef yytext_ptr -static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner); +static void yy_flex_strncpy(char *, const char *, int, yyscan_t yyscanner); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen ( const char * , yyscan_t yyscanner); +static int yy_flex_strlen(const char *, yyscan_t yyscanner); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput ( yyscan_t yyscanner ); +static int yyinput(yyscan_t yyscanner); #else -static int input ( yyscan_t yyscanner ); +static int input(yyscan_t yyscanner); #endif #endif @@ -1215,42 +1121,48 @@ static int input ( yyscan_t yyscanner ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) +#define ECHO \ + do \ + { \ + if (fwrite(yytext, (size_t) yyleng, 1, yyout)) \ + { \ + } \ + } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, * is returned in "result". */ #ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - int n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ +#define YY_INPUT(buf, result, max_size) \ + if (YY_CURRENT_BUFFER_LVALUE->yy_is_interactive) \ + { \ + int c = '*'; \ + int n; \ + for (n = 0; n < max_size && (c = getc(yyin)) != EOF && c != '\n'; ++n) \ + buf[n] = (char) c; \ + if (c == '\n') \ + buf[n++] = (char) c; \ + if (c == EOF && ferror(yyin)) \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + result = n; \ + } \ + else \ + { \ + errno = 0; \ + while ((result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && \ + ferror(yyin)) \ + { \ + if (errno != EINTR) \ + { \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + break; \ + } \ + errno = 0; \ + clearerr(yyin); \ + } \ + } + #endif @@ -1269,7 +1181,7 @@ static int input ( yyscan_t yyscanner ); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) +#define YY_FATAL_ERROR(msg) yy_fatal_error(msg, yyscanner) #endif /* end tables serialization structures and prototypes */ @@ -1280,11 +1192,9 @@ static int input ( yyscan_t yyscanner ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int yylex \ - (YYSTYPE * yylval_param , yyscan_t yyscanner); +extern int yylex(YYSTYPE *yylval_param, yyscan_t yyscanner); -#define YY_DECL int yylex \ - (YYSTYPE * yylval_param , yyscan_t yyscanner) +#define YY_DECL int yylex(YYSTYPE *yylval_param, yyscan_t yyscanner) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -1296,1292 +1206,1373 @@ extern int yylex \ /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; +#define YY_BREAK /*LINTED*/ break; #endif -#define YY_RULE_SETUP \ - YY_USER_ACTION +#define YY_RULE_SETUP YY_USER_ACTION /** The main scanner function which does all the work. */ YY_DECL { - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - yylval = yylval_param; + yylval = yylval_param; - if ( !yyg->yy_init ) - { - yyg->yy_init = 1; + if (!yyg->yy_init) + { + yyg->yy_init = 1; #ifdef YY_USER_INIT - YY_USER_INIT; + YY_USER_INIT; #endif - if ( ! yyg->yy_start ) - yyg->yy_start = 1; /* first start state */ + if (!yyg->yy_start) + yyg->yy_start = 1; /* first start state */ - if ( ! yyin ) - yyin = stdin; + if (!yyin) + yyin = stdin; - if ( ! yyout ) - yyout = stdout; + if (!yyout) + yyout = stdout; - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); - } + if (!YY_CURRENT_BUFFER) + { + yyensure_buffer_stack(yyscanner); + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE, yyscanner); + } - yy_load_buffer_state( yyscanner ); - } + yy_load_buffer_state(yyscanner); + } - { + { #line 163 "lexer.l" #line 1346 "lexer.c" - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = yyg->yy_c_buf_p; - - /* Support of yytext. */ - *yy_cp = yyg->yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = yyg->yy_start; -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 299 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - ++yy_cp; - } - while ( yy_current_state != 298 ); - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - - YY_DO_BEFORE_ACTION; - - if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) - { - int yyl; - for ( yyl = 0; yyl < yyleng; ++yyl ) - if ( yytext[yyl] == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; - } - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = yyg->yy_hold_char; - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - goto yy_find_action; - -case 1: -YY_RULE_SETUP + while (/*CONSTCOND*/ 1) /* loops until end-of-file is reached */ + { + yy_cp = yyg->yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yyg->yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yyg->yy_start; + yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if (yy_accept[yy_current_state]) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) + { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 299) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } while (yy_current_state != 298); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + + yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + + if (yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act]) + { + int yyl; + for (yyl = 0; yyl < yyleng; ++yyl) + if (yytext[yyl] == '\n') + + do + { + yylineno++; + yycolumn = 0; + } while (0); + } + + do_action: /* This label is used only to access EOF actions. */ + + switch (yy_act) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yyg->yy_hold_char; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + goto yy_find_action; + + case 1: + YY_RULE_SETUP #line 165 "lexer.l" -{ return _DOT_DOT_; } - YY_BREAK -case 2: -YY_RULE_SETUP + { + return _DOT_DOT_; + } + YY_BREAK + case 2: + YY_RULE_SETUP #line 166 "lexer.l" -{ return _LT_; } - YY_BREAK -case 3: -YY_RULE_SETUP + { + return _LT_; + } + YY_BREAK + case 3: + YY_RULE_SETUP #line 167 "lexer.l" -{ return _GT_; } - YY_BREAK -case 4: -YY_RULE_SETUP + { + return _GT_; + } + YY_BREAK + case 4: + YY_RULE_SETUP #line 168 "lexer.l" -{ return _LE_; } - YY_BREAK -case 5: -YY_RULE_SETUP + { + return _LE_; + } + YY_BREAK + case 5: + YY_RULE_SETUP #line 169 "lexer.l" -{ return _GE_; } - YY_BREAK -case 6: -YY_RULE_SETUP + { + return _GE_; + } + YY_BREAK + case 6: + YY_RULE_SETUP #line 170 "lexer.l" -{ return _EQ_; } - YY_BREAK -case 7: -YY_RULE_SETUP + { + return _EQ_; + } + YY_BREAK + case 7: + YY_RULE_SETUP #line 171 "lexer.l" -{ return _NEQ_; } - YY_BREAK -case 8: -YY_RULE_SETUP + { + return _NEQ_; + } + YY_BREAK + case 8: + YY_RULE_SETUP #line 172 "lexer.l" -{ return _SHIFT_LEFT_; } - YY_BREAK -case 9: -YY_RULE_SETUP + { + return _SHIFT_LEFT_; + } + YY_BREAK + case 9: + YY_RULE_SETUP #line 173 "lexer.l" -{ return _SHIFT_RIGHT_; } - YY_BREAK -case 10: -YY_RULE_SETUP + { + return _SHIFT_RIGHT_; + } + YY_BREAK + case 10: + YY_RULE_SETUP #line 174 "lexer.l" -{ return _PRIVATE_; } - YY_BREAK -case 11: -YY_RULE_SETUP + { + return _PRIVATE_; + } + YY_BREAK + case 11: + YY_RULE_SETUP #line 175 "lexer.l" -{ return _GLOBAL_; } - YY_BREAK -case 12: -YY_RULE_SETUP + { + return _GLOBAL_; + } + YY_BREAK + case 12: + YY_RULE_SETUP #line 176 "lexer.l" -{ return _RULE_; } - YY_BREAK -case 13: -YY_RULE_SETUP + { + return _RULE_; + } + YY_BREAK + case 13: + YY_RULE_SETUP #line 177 "lexer.l" -{ return _META_; } - YY_BREAK -case 14: -YY_RULE_SETUP + { + return _META_; + } + YY_BREAK + case 14: + YY_RULE_SETUP #line 178 "lexer.l" -{ return _STRINGS_; } - YY_BREAK -case 15: -YY_RULE_SETUP + { + return _STRINGS_; + } + YY_BREAK + case 15: + YY_RULE_SETUP #line 179 "lexer.l" -{ return _ASCII_; } - YY_BREAK -case 16: -YY_RULE_SETUP + { + return _ASCII_; + } + YY_BREAK + case 16: + YY_RULE_SETUP #line 180 "lexer.l" -{ return _WIDE_; } - YY_BREAK -case 17: -YY_RULE_SETUP + { + return _WIDE_; + } + YY_BREAK + case 17: + YY_RULE_SETUP #line 181 "lexer.l" -{ return _XOR_; } - YY_BREAK -case 18: -YY_RULE_SETUP + { + return _XOR_; + } + YY_BREAK + case 18: + YY_RULE_SETUP #line 182 "lexer.l" -{ return _BASE64_; } - YY_BREAK -case 19: -YY_RULE_SETUP + { + return _BASE64_; + } + YY_BREAK + case 19: + YY_RULE_SETUP #line 183 "lexer.l" -{ return _BASE64_WIDE_; } - YY_BREAK -case 20: -YY_RULE_SETUP + { + return _BASE64_WIDE_; + } + YY_BREAK + case 20: + YY_RULE_SETUP #line 184 "lexer.l" -{ return _FULLWORD_; } - YY_BREAK -case 21: -YY_RULE_SETUP + { + return _FULLWORD_; + } + YY_BREAK + case 21: + YY_RULE_SETUP #line 185 "lexer.l" -{ return _NOCASE_; } - YY_BREAK -case 22: -YY_RULE_SETUP + { + return _NOCASE_; + } + YY_BREAK + case 22: + YY_RULE_SETUP #line 186 "lexer.l" -{ return _CONDITION_; } - YY_BREAK -case 23: -YY_RULE_SETUP + { + return _CONDITION_; + } + YY_BREAK + case 23: + YY_RULE_SETUP #line 187 "lexer.l" -{ return _TRUE_; } - YY_BREAK -case 24: -YY_RULE_SETUP + { + return _TRUE_; + } + YY_BREAK + case 24: + YY_RULE_SETUP #line 188 "lexer.l" -{ return _FALSE_; } - YY_BREAK -case 25: -YY_RULE_SETUP + { + return _FALSE_; + } + YY_BREAK + case 25: + YY_RULE_SETUP #line 189 "lexer.l" -{ return _NOT_; } - YY_BREAK -case 26: -YY_RULE_SETUP + { + return _NOT_; + } + YY_BREAK + case 26: + YY_RULE_SETUP #line 190 "lexer.l" -{ return _AND_; } - YY_BREAK -case 27: -YY_RULE_SETUP + { + return _AND_; + } + YY_BREAK + case 27: + YY_RULE_SETUP #line 191 "lexer.l" -{ return _OR_; } - YY_BREAK -case 28: -YY_RULE_SETUP + { + return _OR_; + } + YY_BREAK + case 28: + YY_RULE_SETUP #line 192 "lexer.l" -{ return _AT_; } - YY_BREAK -case 29: -YY_RULE_SETUP + { + return _AT_; + } + YY_BREAK + case 29: + YY_RULE_SETUP #line 193 "lexer.l" -{ return _IN_; } - YY_BREAK -case 30: -YY_RULE_SETUP + { + return _IN_; + } + YY_BREAK + case 30: + YY_RULE_SETUP #line 194 "lexer.l" -{ return _OF_; } - YY_BREAK -case 31: -YY_RULE_SETUP + { + return _OF_; + } + YY_BREAK + case 31: + YY_RULE_SETUP #line 195 "lexer.l" -{ return _THEM_; } - YY_BREAK -case 32: -YY_RULE_SETUP + { + return _THEM_; + } + YY_BREAK + case 32: + YY_RULE_SETUP #line 196 "lexer.l" -{ return _FOR_; } - YY_BREAK -case 33: -YY_RULE_SETUP + { + return _FOR_; + } + YY_BREAK + case 33: + YY_RULE_SETUP #line 197 "lexer.l" -{ return _ALL_; } - YY_BREAK -case 34: -YY_RULE_SETUP + { + return _ALL_; + } + YY_BREAK + case 34: + YY_RULE_SETUP #line 198 "lexer.l" -{ return _ANY_; } - YY_BREAK -case 35: -YY_RULE_SETUP + { + return _ANY_; + } + YY_BREAK + case 35: + YY_RULE_SETUP #line 199 "lexer.l" -{ return _ENTRYPOINT_; } - YY_BREAK -case 36: -YY_RULE_SETUP + { + return _ENTRYPOINT_; + } + YY_BREAK + case 36: + YY_RULE_SETUP #line 200 "lexer.l" -{ return _FILESIZE_; } - YY_BREAK -case 37: -YY_RULE_SETUP + { + return _FILESIZE_; + } + YY_BREAK + case 37: + YY_RULE_SETUP #line 201 "lexer.l" -{ return _MATCHES_; } - YY_BREAK -case 38: -YY_RULE_SETUP + { + return _MATCHES_; + } + YY_BREAK + case 38: + YY_RULE_SETUP #line 202 "lexer.l" -{ return _CONTAINS_; } - YY_BREAK -case 39: -YY_RULE_SETUP + { + return _CONTAINS_; + } + YY_BREAK + case 39: + YY_RULE_SETUP #line 203 "lexer.l" -{ return _STARTSWITH_; } - YY_BREAK -case 40: -YY_RULE_SETUP + { + return _STARTSWITH_; + } + YY_BREAK + case 40: + YY_RULE_SETUP #line 204 "lexer.l" -{ return _ENDSWITH_; } - YY_BREAK -case 41: -YY_RULE_SETUP + { + return _ENDSWITH_; + } + YY_BREAK + case 41: + YY_RULE_SETUP #line 205 "lexer.l" -{ return _ICONTAINS_; } - YY_BREAK -case 42: -YY_RULE_SETUP + { + return _ICONTAINS_; + } + YY_BREAK + case 42: + YY_RULE_SETUP #line 206 "lexer.l" -{ return _ISTARTSWITH_; } - YY_BREAK -case 43: -YY_RULE_SETUP + { + return _ISTARTSWITH_; + } + YY_BREAK + case 43: + YY_RULE_SETUP #line 207 "lexer.l" -{ return _IENDSWITH_; } - YY_BREAK -case 44: -YY_RULE_SETUP + { + return _IENDSWITH_; + } + YY_BREAK + case 44: + YY_RULE_SETUP #line 208 "lexer.l" -{ return _IMPORT_; } - YY_BREAK -case 45: -YY_RULE_SETUP + { + return _IMPORT_; + } + YY_BREAK + case 45: + YY_RULE_SETUP #line 211 "lexer.l" -{ BEGIN(comment); } - YY_BREAK -case 46: -YY_RULE_SETUP + { + BEGIN(comment); + } + YY_BREAK + case 46: + YY_RULE_SETUP #line 212 "lexer.l" -{ BEGIN(INITIAL); } - YY_BREAK -case 47: -/* rule 47 can match eol */ -YY_RULE_SETUP + { + BEGIN(INITIAL); + } + YY_BREAK + case 47: + /* rule 47 can match eol */ + YY_RULE_SETUP #line 213 "lexer.l" -{ /* skip comments */ } - YY_BREAK -case 48: -YY_RULE_SETUP + { /* skip comments */ + } + YY_BREAK + case 48: + YY_RULE_SETUP #line 216 "lexer.l" -{ /* skip single-line comments */ } - YY_BREAK -case 49: -YY_RULE_SETUP + { /* skip single-line comments */ + } + YY_BREAK + case 49: + YY_RULE_SETUP #line 219 "lexer.l" -{ - yyextra->lex_buf_ptr = yyextra->lex_buf; - yyextra->lex_buf_len = 0; - BEGIN(include); - } - YY_BREAK -case 50: -/* rule 50 can match eol */ -YY_RULE_SETUP -#line 226 "lexer.l" -{ yytext_to_buffer; } - YY_BREAK -case 51: -YY_RULE_SETUP -#line 229 "lexer.l" -{ - - if (compiler->include_callback != NULL) - { - #ifdef _MSC_VER - char* b = NULL; - #endif - char* s = NULL; - char* f; - - char buffer[1024]; - const char* included_rules; - char* current_file_name; - char* include_path; - - *yyextra->lex_buf_ptr = '\0'; // null-terminate included file path - - current_file_name = yr_compiler_get_current_file_name(compiler); - - if (current_file_name == NULL || - compiler->include_callback != _yr_compiler_default_include_callback || - is_absolute_path(yyextra->lex_buf)) - { - include_path = yyextra->lex_buf; - } - else - { - strlcpy(buffer, current_file_name, sizeof(buffer)); - s = strrchr(buffer, '/'); - - #ifdef _MSC_VER - b = strrchr(buffer, '\\'); // in Windows both path delimiters are accepted - #endif - - #ifdef _MSC_VER - if (s != NULL || b != NULL) - #else - if (s != NULL) - #endif - { - #ifdef _MSC_VER - f = (b > s) ? (b + 1) : (s + 1); - #else - f = s + 1; - #endif - - strlcpy(f, yyextra->lex_buf, sizeof(buffer) - (f - buffer)); - include_path = buffer; - } - else - { - include_path = yyextra->lex_buf; - } - } - - YR_NAMESPACE* ns = (YR_NAMESPACE*) yr_arena_get_ptr( - compiler->arena, - YR_NAMESPACES_TABLE, - compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE)); - - included_rules = compiler->include_callback( - include_path, - current_file_name, - ns->name, - compiler->incl_clbk_user_data); - - if (included_rules != NULL) - { - int error_code = _yr_compiler_push_file_name(compiler, include_path); - - if (error_code != ERROR_SUCCESS) - { - if (error_code == ERROR_INCLUDES_CIRCULAR_REFERENCE) { - yyerror(yyscanner, compiler, "includes circular reference"); + yyextra->lex_buf_ptr = yyextra->lex_buf; + yyextra->lex_buf_len = 0; + BEGIN(include); } - else if (error_code == ERROR_INCLUDE_DEPTH_EXCEEDED) + YY_BREAK + case 50: + /* rule 50 can match eol */ + YY_RULE_SETUP +#line 226 "lexer.l" { - yyerror(yyscanner, compiler, "includes depth exceeded"); + yytext_to_buffer; } - - if (compiler->include_free != NULL) + YY_BREAK + case 51: + YY_RULE_SETUP +#line 229 "lexer.l" { - compiler->include_free(included_rules, compiler->incl_clbk_user_data); + if (compiler->include_callback != NULL) + { +#ifdef _MSC_VER + char *b = NULL; +#endif + char *s = NULL; + char *f; + + char buffer[1024]; + const char *included_rules; + char *current_file_name; + char *include_path; + + *yyextra->lex_buf_ptr = '\0'; // null-terminate included file path + + current_file_name = yr_compiler_get_current_file_name(compiler); + + if (current_file_name == NULL || + compiler->include_callback != + _yr_compiler_default_include_callback || + is_absolute_path(yyextra->lex_buf)) + { + include_path = yyextra->lex_buf; + } + else + { + strlcpy(buffer, current_file_name, sizeof(buffer)); + s = strrchr(buffer, '/'); + +#ifdef _MSC_VER + b = strrchr( + buffer, + '\\'); // in Windows both path delimiters are accepted +#endif + +#ifdef _MSC_VER + if (s != NULL || b != NULL) +#else + if (s != NULL) +#endif + { +#ifdef _MSC_VER + f = (b > s) ? (b + 1) : (s + 1); +#else + f = s + 1; +#endif + + strlcpy(f, yyextra->lex_buf, sizeof(buffer) - (f - buffer)); + include_path = buffer; + } + else + { + include_path = yyextra->lex_buf; + } + } + + YR_NAMESPACE *ns = (YR_NAMESPACE *) yr_arena_get_ptr( + compiler->arena, + YR_NAMESPACES_TABLE, + compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE)); + + included_rules = compiler->include_callback( + include_path, + current_file_name, + ns->name, + compiler->incl_clbk_user_data); + + if (included_rules != NULL) + { + int error_code = _yr_compiler_push_file_name( + compiler, include_path); + + if (error_code != ERROR_SUCCESS) + { + if (error_code == ERROR_INCLUDES_CIRCULAR_REFERENCE) + { + yyerror(yyscanner, compiler, "includes circular reference"); + } + else if (error_code == ERROR_INCLUDE_DEPTH_EXCEEDED) + { + yyerror(yyscanner, compiler, "includes depth exceeded"); + } + + if (compiler->include_free != NULL) + { + compiler->include_free( + included_rules, compiler->incl_clbk_user_data); + } + + yyterminate(); + } + + // Workaround for flex issue: + // https://github.com/westes/flex/issues/58 + yypush_buffer_state(YY_CURRENT_BUFFER, yyscanner); + yy_scan_string(included_rules, yyscanner); + yyset_lineno(1, yyscanner); + + if (compiler->include_free != NULL) + { + compiler->include_free( + included_rules, compiler->incl_clbk_user_data); + } + } + else + { + char *err_msg_fmt; + char err_msg[512]; + + if (compiler->include_callback == + _yr_compiler_default_include_callback) + { + err_msg_fmt = "can't open include file: %s"; + } + else + { + err_msg_fmt = "callback failed to provide include resource: %s"; + } + + snprintf(err_msg, sizeof(err_msg), err_msg_fmt, yyextra->lex_buf); + + yyerror(yyscanner, compiler, err_msg); + } + } + else // not allowing includes + { + yyerror(yyscanner, compiler, "includes are disabled"); + } + + BEGIN(INITIAL); } - - yyterminate(); - } - - // Workaround for flex issue: https://github.com/westes/flex/issues/58 - yypush_buffer_state(YY_CURRENT_BUFFER, yyscanner); - yy_scan_string(included_rules, yyscanner); - yyset_lineno(1, yyscanner); - - if (compiler->include_free != NULL) - { - compiler->include_free(included_rules, compiler->incl_clbk_user_data); - } - } - else - { - char* err_msg_fmt; - char err_msg[512]; - - if (compiler->include_callback == _yr_compiler_default_include_callback) - { - err_msg_fmt = "can't open include file: %s"; - } - else - { - err_msg_fmt = "callback failed to provide include resource: %s"; - } - - snprintf( - err_msg, - sizeof(err_msg), - err_msg_fmt, - yyextra->lex_buf); - - yyerror(yyscanner, compiler, err_msg); - } - - } - else // not allowing includes - { - yyerror(yyscanner, compiler, "includes are disabled"); - } - - BEGIN(INITIAL); -} - YY_BREAK -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(str): -case YY_STATE_EOF(regexp): -case YY_STATE_EOF(include): -case YY_STATE_EOF(comment): + YY_BREAK + case YY_STATE_EOF(INITIAL): + case YY_STATE_EOF(str): + case YY_STATE_EOF(regexp): + case YY_STATE_EOF(include): + case YY_STATE_EOF(comment): #line 361 "lexer.l" -{ - - yypop_buffer_state(yyscanner); + { + yypop_buffer_state(yyscanner); - if (!YY_CURRENT_BUFFER) - yyterminate(); + if (!YY_CURRENT_BUFFER) + yyterminate(); - return _END_OF_INCLUDED_FILE_; -} - YY_BREAK -case 52: -YY_RULE_SETUP + return _END_OF_INCLUDED_FILE_; + } + YY_BREAK + case 52: + YY_RULE_SETUP #line 372 "lexer.l" -{ - - yylval->c_string = yr_strdup(yytext); + { + yylval->c_string = yr_strdup(yytext); - if (yylval->c_string == NULL) - error(ERROR_INSUFFICIENT_MEMORY); + if (yylval->c_string == NULL) + error(ERROR_INSUFFICIENT_MEMORY); - return _STRING_IDENTIFIER_WITH_WILDCARD_; -} - YY_BREAK -case 53: -YY_RULE_SETUP + return _STRING_IDENTIFIER_WITH_WILDCARD_; + } + YY_BREAK + case 53: + YY_RULE_SETUP #line 383 "lexer.l" -{ - - yylval->c_string = yr_strdup(yytext); + { + yylval->c_string = yr_strdup(yytext); - if (yylval->c_string == NULL) - error(ERROR_INSUFFICIENT_MEMORY); + if (yylval->c_string == NULL) + error(ERROR_INSUFFICIENT_MEMORY); - return _STRING_IDENTIFIER_; -} - YY_BREAK -case 54: -YY_RULE_SETUP + return _STRING_IDENTIFIER_; + } + YY_BREAK + case 54: + YY_RULE_SETUP #line 394 "lexer.l" -{ - - yylval->c_string = yr_strdup(yytext); - - if (yylval->c_string == NULL) - { - error(ERROR_INSUFFICIENT_MEMORY); - } - else - { - yylval->c_string[0] = '$'; /* replace # by $*/ - } - - return _STRING_COUNT_; -} - YY_BREAK -case 55: -YY_RULE_SETUP + { + yylval->c_string = yr_strdup(yytext); + + if (yylval->c_string == NULL) + { + error(ERROR_INSUFFICIENT_MEMORY); + } + else + { + yylval->c_string[0] = '$'; /* replace # by $*/ + } + + return _STRING_COUNT_; + } + YY_BREAK + case 55: + YY_RULE_SETUP #line 411 "lexer.l" -{ - - yylval->c_string = yr_strdup(yytext); - - if (yylval->c_string == NULL) - { - error(ERROR_INSUFFICIENT_MEMORY); - } - else - { - yylval->c_string[0] = '$'; /* replace @ by $*/ - } - - return _STRING_OFFSET_; -} - YY_BREAK -case 56: -YY_RULE_SETUP + { + yylval->c_string = yr_strdup(yytext); + + if (yylval->c_string == NULL) + { + error(ERROR_INSUFFICIENT_MEMORY); + } + else + { + yylval->c_string[0] = '$'; /* replace @ by $*/ + } + + return _STRING_OFFSET_; + } + YY_BREAK + case 56: + YY_RULE_SETUP #line 428 "lexer.l" -{ - - yylval->c_string = yr_strdup(yytext); - - if (yylval->c_string == NULL) - { - error(ERROR_INSUFFICIENT_MEMORY); - } - else - { - yylval->c_string[0] = '$'; /* replace ! by $*/ - } - - return _STRING_LENGTH_; -} - YY_BREAK -case 57: -YY_RULE_SETUP + { + yylval->c_string = yr_strdup(yytext); + + if (yylval->c_string == NULL) + { + error(ERROR_INSUFFICIENT_MEMORY); + } + else + { + yylval->c_string[0] = '$'; /* replace ! by $*/ + } + + return _STRING_LENGTH_; + } + YY_BREAK + case 57: + YY_RULE_SETUP #line 445 "lexer.l" -{ - - char* text = yytext; - - if (*text == 'u') - { - yylval->integer = 3; - text++; - } - else - { - yylval->integer = 0; - } + { + char *text = yytext; + + if (*text == 'u') + { + yylval->integer = 3; + text++; + } + else + { + yylval->integer = 0; + } + + if (strstr(text, "int8") == text) + { + yylval->integer += 0; + text += 4; + } + else if (strstr(text, "int16") == text) + { + yylval->integer += 1; + text += 5; + } + else if (strstr(text, "int32") == text) + { + yylval->integer += 2; + text += 5; + } + + if (strcmp(text, "be") == 0) + { + yylval->integer += 6; + } + + return _INTEGER_FUNCTION_; + } + YY_BREAK + case 58: + YY_RULE_SETUP +#line 484 "lexer.l" + { + if (strlen(yytext) > 128) + syntax_error("identifier too long"); - if (strstr(text, "int8") == text) - { - yylval->integer += 0; - text += 4; - } - else if (strstr(text, "int16") == text) - { - yylval->integer += 1; - text += 5; - } - else if (strstr(text, "int32") == text) - { - yylval->integer += 2; - text += 5; - } + yylval->c_string = yr_strdup(yytext); - if (strcmp(text, "be") == 0) - { - yylval->integer += 6; - } + if (yylval->c_string == NULL) + error(ERROR_INSUFFICIENT_MEMORY); - return _INTEGER_FUNCTION_; -} - YY_BREAK -case 58: -YY_RULE_SETUP -#line 484 "lexer.l" -{ + return _IDENTIFIER_; + } + YY_BREAK + case 59: + YY_RULE_SETUP +#line 498 "lexer.l" + { + char *endptr; + + errno = 0; + yylval->integer = strtoll(yytext, &endptr, 10); + + if (yylval->integer == LLONG_MAX && errno == ERANGE) + { + yr_compiler_set_error_extra_info(compiler, yytext); + error(ERROR_INTEGER_OVERFLOW); + } + else if (strstr(yytext, "KB") != NULL) + { + if (yylval->integer > LLONG_MAX / 1024) + { + yr_compiler_set_error_extra_info(compiler, yytext); + error(ERROR_INTEGER_OVERFLOW); + } + else + { + yylval->integer *= 1024; + } + } + else if (strstr(yytext, "MB") != NULL) + { + if (yylval->integer > LLONG_MAX / 1048576) + { + yr_compiler_set_error_extra_info(compiler, yytext); + error(ERROR_INTEGER_OVERFLOW); + } + else + { + yylval->integer *= 1048576; + } + } + + return _NUMBER_; + } + YY_BREAK + case 60: + YY_RULE_SETUP +#line 538 "lexer.l" + { + yylval->double_ = atof(yytext); + return _DOUBLE_; + } + YY_BREAK + case 61: + YY_RULE_SETUP +#line 543 "lexer.l" + { + char *endptr; - if (strlen(yytext) > 128) - syntax_error("identifier too long"); + errno = 0; + yylval->integer = strtoll(yytext, &endptr, 16); - yylval->c_string = yr_strdup(yytext); + if (yylval->integer == LLONG_MAX && errno == ERANGE) + { + yr_compiler_set_error_extra_info(compiler, yytext); + error(ERROR_INTEGER_OVERFLOW); + } - if (yylval->c_string == NULL) - error(ERROR_INSUFFICIENT_MEMORY); + return _NUMBER_; + } + YY_BREAK + case 62: + YY_RULE_SETUP +#line 559 "lexer.l" + { + char *endptr; - return _IDENTIFIER_; -} - YY_BREAK -case 59: -YY_RULE_SETUP -#line 498 "lexer.l" -{ + errno = 0; + yylval->integer = strtoll(yytext + 2, &endptr, 8); - char *endptr; + if (yylval->integer == LLONG_MAX && errno == ERANGE) + { + yr_compiler_set_error_extra_info(compiler, yytext); + error(ERROR_INTEGER_OVERFLOW); + } - errno = 0; - yylval->integer = strtoll(yytext, &endptr, 10); + return _NUMBER_; + } + YY_BREAK + case 63: + YY_RULE_SETUP +#line 576 "lexer.l" + { /* saw closing quote - all done */ - if (yylval->integer == LLONG_MAX && errno == ERANGE) - { - yr_compiler_set_error_extra_info(compiler, yytext); - error(ERROR_INTEGER_OVERFLOW); - } - else if (strstr(yytext, "KB") != NULL) - { - if (yylval->integer > LLONG_MAX / 1024) - { - yr_compiler_set_error_extra_info(compiler, yytext); - error(ERROR_INTEGER_OVERFLOW); - } - else - { - yylval->integer *= 1024; - } - } - else if (strstr(yytext, "MB") != NULL) - { - if (yylval->integer > LLONG_MAX / 1048576) - { - yr_compiler_set_error_extra_info(compiler, yytext); - error(ERROR_INTEGER_OVERFLOW); - } - else - { - yylval->integer *= 1048576; - } - } + alloc_sized_string(s, yyextra->lex_buf_len); - return _NUMBER_; -} - YY_BREAK -case 60: -YY_RULE_SETUP -#line 538 "lexer.l" -{ - yylval->double_ = atof(yytext); - return _DOUBLE_; -} - YY_BREAK -case 61: -YY_RULE_SETUP -#line 543 "lexer.l" -{ + *yyextra->lex_buf_ptr = '\0'; + memcpy(s->c_string, yyextra->lex_buf, yyextra->lex_buf_len + 1); + yylval->sized_string = s; - char *endptr; + BEGIN(INITIAL); - errno = 0; - yylval->integer = strtoll(yytext, &endptr, 16); + return _TEXT_STRING_; + } + YY_BREAK + case 64: + YY_RULE_SETUP +#line 590 "lexer.l" + { + lex_check_space_ok("\t", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); + *yyextra->lex_buf_ptr++ = '\t'; + yyextra->lex_buf_len++; + } + YY_BREAK + case 65: + YY_RULE_SETUP +#line 598 "lexer.l" + { + lex_check_space_ok("\t", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); + *yyextra->lex_buf_ptr++ = '\r'; + yyextra->lex_buf_len++; + } + YY_BREAK + case 66: + YY_RULE_SETUP +#line 606 "lexer.l" + { + lex_check_space_ok("\n", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); + *yyextra->lex_buf_ptr++ = '\n'; + yyextra->lex_buf_len++; + } + YY_BREAK + case 67: + YY_RULE_SETUP +#line 614 "lexer.l" + { + lex_check_space_ok("\"", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); + *yyextra->lex_buf_ptr++ = '\"'; + yyextra->lex_buf_len++; + } + YY_BREAK + case 68: + YY_RULE_SETUP +#line 622 "lexer.l" + { + lex_check_space_ok("\\", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); + *yyextra->lex_buf_ptr++ = '\\'; + yyextra->lex_buf_len++; + } + YY_BREAK + case 69: + YY_RULE_SETUP +#line 630 "lexer.l" + { + int result; - if (yylval->integer == LLONG_MAX && errno == ERANGE) - { - yr_compiler_set_error_extra_info(compiler, yytext); - error(ERROR_INTEGER_OVERFLOW); - } + sscanf(yytext + 2, "%x", &result); + lex_check_space_ok("X", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); + *yyextra->lex_buf_ptr++ = result; + yyextra->lex_buf_len++; + } + YY_BREAK + case 70: + YY_RULE_SETUP +#line 641 "lexer.l" + { + yytext_to_buffer; + } + YY_BREAK + case 71: + /* rule 71 can match eol */ + YY_RULE_SETUP +#line 644 "lexer.l" + { + syntax_error("unterminated string"); + } + YY_BREAK + case 72: + /* rule 72 can match eol */ + YY_RULE_SETUP +#line 649 "lexer.l" + { + syntax_error("illegal escape sequence"); + } + YY_BREAK + case 73: + YY_RULE_SETUP +#line 654 "lexer.l" + { + if (yyextra->lex_buf_len > 0) + { + alloc_sized_string(s, yyextra->lex_buf_len); + + if (yytext[1] == 'i') + s->flags |= SIZED_STRING_FLAGS_NO_CASE; + + if (yytext[1] == 's' || yytext[2] == 's') + s->flags |= SIZED_STRING_FLAGS_DOT_ALL; + + *yyextra->lex_buf_ptr = '\0'; + strlcpy(s->c_string, yyextra->lex_buf, s->length + 1); + yylval->sized_string = s; + } + else + { + syntax_error("empty regular expression"); + } + + BEGIN(INITIAL); + return _REGEXP_; + } + YY_BREAK + case 74: + YY_RULE_SETUP +#line 680 "lexer.l" + { + lex_check_space_ok("/", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); + *yyextra->lex_buf_ptr++ = '/'; + yyextra->lex_buf_len++; + } + YY_BREAK + case 75: + YY_RULE_SETUP +#line 688 "lexer.l" + { + lex_check_space_ok("\\.", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); - return _NUMBER_; -} - YY_BREAK -case 62: -YY_RULE_SETUP -#line 559 "lexer.l" -{ + if (yytext[1] == 0) + syntax_error("malformed regular expression"); - char *endptr; + *yyextra->lex_buf_ptr++ = yytext[0]; + *yyextra->lex_buf_ptr++ = yytext[1]; + yyextra->lex_buf_len += 2; + } + YY_BREAK + case 76: + YY_RULE_SETUP +#line 701 "lexer.l" + { + yytext_to_buffer; + } + YY_BREAK + case 77: + /* rule 77 can match eol */ + YY_RULE_SETUP +#line 704 "lexer.l" + { + syntax_error("unterminated regular expression"); + } + YY_BREAK + case 78: + YY_RULE_SETUP +#line 709 "lexer.l" + { + yylval->sized_string = NULL; + yyextra->lex_buf_ptr = yyextra->lex_buf; + yyextra->lex_buf_len = 0; + BEGIN(str); + } + YY_BREAK + case 79: + YY_RULE_SETUP +#line 718 "lexer.l" + { + yylval->sized_string = NULL; + yyextra->lex_buf_ptr = yyextra->lex_buf; + yyextra->lex_buf_len = 0; + BEGIN(regexp); + } + YY_BREAK + case 80: + /* rule 80 can match eol */ + YY_RULE_SETUP +#line 727 "lexer.l" + { + // Match hex-digits with whitespace or comments. The latter are + // stripped out by hex_lexer.l + // TODO(vmalvarez): Integrate the hex string lexer and parser into + // this one, by having a single lexer/parser instead of two different + // ones we can avoid complex regular expressions like the one above, + // which is actually trying to do some parsing in the lexer. - errno = 0; - yylval->integer = strtoll(yytext + 2, &endptr, 8); + alloc_sized_string(s, strlen(yytext)); - if (yylval->integer == LLONG_MAX && errno == ERANGE) - { - yr_compiler_set_error_extra_info(compiler, yytext); - error(ERROR_INTEGER_OVERFLOW); - } + strlcpy(s->c_string, yytext, s->length + 1); + yylval->sized_string = s; - return _NUMBER_; -} - YY_BREAK -case 63: -YY_RULE_SETUP -#line 576 "lexer.l" -{ /* saw closing quote - all done */ + return _HEX_STRING_; + } + YY_BREAK + case 81: + /* rule 81 can match eol */ + YY_RULE_SETUP +#line 744 "lexer.l" + /* skip whitespace */ + YY_BREAK + case 82: + YY_RULE_SETUP +#line 746 "lexer.l" + { + if (yytext[0] >= 32 && yytext[0] < 127) + { + return yytext[0]; + } + else + { + syntax_error("non-ascii character"); + } + } + YY_BREAK + case 83: + YY_RULE_SETUP +#line 758 "lexer.l" + ECHO; + YY_BREAK +#line 2280 "lexer.c" - alloc_sized_string(s, yyextra->lex_buf_len); + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; - *yyextra->lex_buf_ptr = '\0'; - memcpy(s->c_string, yyextra->lex_buf, yyextra->lex_buf_len + 1); - yylval->sized_string = s; + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yyg->yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET - BEGIN(INITIAL); + if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } - return _TEXT_STRING_; -} - YY_BREAK -case 64: -YY_RULE_SETUP -#line 590 "lexer.l" -{ + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if (yyg->yy_c_buf_p <= + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(yyscanner); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans(yy_current_state, yyscanner); + + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + + if (yy_next_state) + { + /* Consume the NUL. */ + yy_cp = ++yyg->yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + goto yy_find_action; + } + } - lex_check_space_ok("\t", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); - *yyextra->lex_buf_ptr++ = '\t'; - yyextra->lex_buf_len++; -} - YY_BREAK -case 65: -YY_RULE_SETUP -#line 598 "lexer.l" -{ + else + switch (yy_get_next_buffer(yyscanner)) + { + case EOB_ACT_END_OF_FILE: + { + yyg->yy_did_buffer_switch_on_eof = 0; + + if (yywrap(yyscanner)) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if (!yyg->yy_did_buffer_switch_on_eof) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(yyscanner); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; + + yy_current_state = yy_get_previous_state(yyscanner); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } - lex_check_space_ok("\t", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); - *yyextra->lex_buf_ptr++ = '\r'; - yyextra->lex_buf_len++; -} - YY_BREAK -case 66: -YY_RULE_SETUP -#line 606 "lexer.l" -{ + default: + YY_FATAL_ERROR("fatal flex scanner internal error--no action found"); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of yylex */ - lex_check_space_ok("\n", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); - *yyextra->lex_buf_ptr++ = '\n'; - yyextra->lex_buf_len++; -} - YY_BREAK -case 67: -YY_RULE_SETUP -#line 614 "lexer.l" +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = yyg->yytext_ptr; + int number_to_move, i; + int ret_val; - lex_check_space_ok("\"", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); - *yyextra->lex_buf_ptr++ = '\"'; - yyextra->lex_buf_len++; -} - YY_BREAK -case 68: -YY_RULE_SETUP -#line 622 "lexer.l" -{ + if (yyg->yy_c_buf_p > + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1]) + YY_FATAL_ERROR("fatal flex scanner internal error--end of buffer missed"); - lex_check_space_ok("\\", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); - *yyextra->lex_buf_ptr++ = '\\'; - yyextra->lex_buf_len++; -} - YY_BREAK -case 69: -YY_RULE_SETUP -#line 630 "lexer.l" -{ + if (YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0) + { /* Don't try to fill the buffer, so this is an EOF. */ + if (yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } - int result; + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } - sscanf( yytext + 2, "%x", &result ); - lex_check_space_ok("X", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); - *yyextra->lex_buf_ptr++ = result; - yyextra->lex_buf_len++; -} - YY_BREAK -case 70: -YY_RULE_SETUP -#line 641 "lexer.l" -{ yytext_to_buffer; } - YY_BREAK -case 71: -/* rule 71 can match eol */ -YY_RULE_SETUP -#line 644 "lexer.l" -{ - syntax_error("unterminated string"); -} - YY_BREAK -case 72: -/* rule 72 can match eol */ -YY_RULE_SETUP -#line 649 "lexer.l" -{ - syntax_error("illegal escape sequence"); -} - YY_BREAK -case 73: -YY_RULE_SETUP -#line 654 "lexer.l" -{ + /* Try to read more data. */ - if (yyextra->lex_buf_len > 0) - { - alloc_sized_string(s, yyextra->lex_buf_len); + /* First move last chars to start of buffer. */ + number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1); - if (yytext[1] == 'i') - s->flags |= SIZED_STRING_FLAGS_NO_CASE; + for (i = 0; i < number_to_move; ++i) *(dest++) = *(source++); - if (yytext[1] == 's' || yytext[2] == 's') - s->flags |= SIZED_STRING_FLAGS_DOT_ALL; + if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; - *yyextra->lex_buf_ptr = '\0'; - strlcpy(s->c_string, yyextra->lex_buf, s->length + 1); - yylval->sized_string = s; - } else { - syntax_error("empty regular expression"); - } + int num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - + 1; - BEGIN(INITIAL); - return _REGEXP_; -} - YY_BREAK -case 74: -YY_RULE_SETUP -#line 680 "lexer.l" -{ + while (num_to_read <= 0) + { /* Not enough room in the buffer - grow it. */ - lex_check_space_ok("/", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); - *yyextra->lex_buf_ptr++ = '/'; - yyextra->lex_buf_len++ ; -} - YY_BREAK -case 75: -YY_RULE_SETUP -#line 688 "lexer.l" -{ + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - lex_check_space_ok("\\.", yyextra->lex_buf_len, YR_LEX_BUF_SIZE); + int yy_c_buf_p_offset = (int) (yyg->yy_c_buf_p - b->yy_ch_buf); - if (yytext[1] == 0) - syntax_error("malformed regular expression"); + if (b->yy_is_our_buffer) + { + int new_size = b->yy_buf_size * 2; + + if (new_size <= 0) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc( + (void *) b->yy_ch_buf, + (yy_size_t)(b->yy_buf_size + 2), + yyscanner); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; - *yyextra->lex_buf_ptr++ = yytext[0]; - *yyextra->lex_buf_ptr++ = yytext[1]; - yyextra->lex_buf_len += 2; -} - YY_BREAK -case 76: -YY_RULE_SETUP -#line 701 "lexer.l" -{ yytext_to_buffer; } - YY_BREAK -case 77: -/* rule 77 can match eol */ -YY_RULE_SETUP -#line 704 "lexer.l" -{ - syntax_error("unterminated regular expression"); -} - YY_BREAK -case 78: -YY_RULE_SETUP -#line 709 "lexer.l" -{ + if (!b->yy_ch_buf) + YY_FATAL_ERROR("fatal error - scanner input buffer overflow"); - yylval->sized_string = NULL; - yyextra->lex_buf_ptr = yyextra->lex_buf; - yyextra->lex_buf_len = 0; - BEGIN(str); -} - YY_BREAK -case 79: -YY_RULE_SETUP -#line 718 "lexer.l" -{ + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - yylval->sized_string = NULL; - yyextra->lex_buf_ptr = yyextra->lex_buf; - yyextra->lex_buf_len = 0; - BEGIN(regexp); -} - YY_BREAK -case 80: -/* rule 80 can match eol */ -YY_RULE_SETUP -#line 727 "lexer.l" -{ - // Match hex-digits with whitespace or comments. The latter are stripped - // out by hex_lexer.l - // TODO(vmalvarez): Integrate the hex string lexer and parser into this one, - // by having a single lexer/parser instead of two different ones we can avoid - // complex regular expressions like the one above, which is actually trying to - // do some parsing in the lexer. + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + } - alloc_sized_string(s, strlen(yytext)); + if (num_to_read > YY_READ_BUF_SIZE) + num_to_read = YY_READ_BUF_SIZE; - strlcpy(s->c_string, yytext, s->length + 1); - yylval->sized_string = s; + /* Read in more data. */ + YY_INPUT( + (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + yyg->yy_n_chars, + num_to_read); - return _HEX_STRING_; -} - YY_BREAK -case 81: -/* rule 81 can match eol */ -YY_RULE_SETUP -#line 744 "lexer.l" -/* skip whitespace */ - YY_BREAK -case 82: -YY_RULE_SETUP -#line 746 "lexer.l" -{ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } - if (yytext[0] >= 32 && yytext[0] < 127) + if (yyg->yy_n_chars == 0) { - return yytext[0]; + if (number_to_move == YY_MORE_ADJ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin, yyscanner); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING; + } } + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yyg->yy_n_chars + number_to_move) > + YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - syntax_error("non-ascii character"); + /* Extend the array by 50%, plus the number we really need. */ + int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, + (yy_size_t) new_size, + yyscanner); + if (!YY_CURRENT_BUFFER_LVALUE->yy_ch_buf) + YY_FATAL_ERROR("out of dynamic memory in yy_get_next_buffer()"); + /* "- 2" to take care of EOB's */ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); } -} - YY_BREAK -case 83: -YY_RULE_SETUP -#line 758 "lexer.l" -ECHO; - YY_BREAK -#line 2280 "lexer.c" - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yyg->yy_hold_char; - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yyg->yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_END_OF_FILE: - { - yyg->yy_did_buffer_switch_on_eof = 0; - - if ( yywrap( yyscanner ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = - yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - yyg->yy_c_buf_p = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = + YY_END_OF_BUFFER_CHAR; -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = yyg->yytext_ptr; - int number_to_move, i; - int ret_val; - - if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1); - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; - - else - { - int num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) (yyg->yy_c_buf_p - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc( (void *) b->yy_ch_buf, - (yy_size_t) (b->yy_buf_size + 2) , yyscanner ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = NULL; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - if ( yyg->yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin , yyscanner); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( - (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - /* "- 2" to take care of EOB's */ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); - } - - yyg->yy_n_chars += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ - static yy_state_type yy_get_previous_state (yyscan_t yyscanner) +static yy_state_type yy_get_previous_state(yyscan_t yyscanner) { - yy_state_type yy_current_state; - char *yy_cp; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - yy_current_state = yyg->yy_start; - - for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 299 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - } - - return yy_current_state; + yy_state_type yy_current_state; + char *yy_cp; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + yy_current_state = yyg->yy_start; + + for (yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if (yy_accept[yy_current_state]) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) + { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 299) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return yy_current_state; } /* yy_try_NUL_trans - try to make a transition on the NUL character @@ -2589,29 +2580,32 @@ static int yy_get_next_buffer (yyscan_t yyscanner) * synopsis * next_state = yy_try_NUL_trans( current_state ); */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) +static yy_state_type yy_try_NUL_trans( + yy_state_type yy_current_state, + yyscan_t yyscanner) { - int yy_is_jam; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ - char *yy_cp = yyg->yy_c_buf_p; - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 299 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 298); - - (void)yyg; - return yy_is_jam ? 0 : yy_current_state; + int yy_is_jam; + struct yyguts_t *yyg = (struct yyguts_t *) + yyscanner; /* This var may be unused depending upon options. */ + char *yy_cp = yyg->yy_c_buf_p; + + YY_CHAR yy_c = 1; + if (yy_accept[yy_current_state]) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) + { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 299) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 298); + + (void) yyg; + return yy_is_jam ? 0 : yy_current_state; } #ifndef YY_NO_UNPUT @@ -2620,255 +2614,258 @@ static int yy_get_next_buffer (yyscan_t yyscanner) #ifndef YY_NO_INPUT #ifdef __cplusplus - static int yyinput (yyscan_t yyscanner) +static int yyinput(yyscan_t yyscanner) #else - static int input (yyscan_t yyscanner) +static int input(yyscan_t yyscanner) #endif { - int c; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - *yyg->yy_c_buf_p = yyg->yy_hold_char; - - if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - /* This was really a NUL. */ - *yyg->yy_c_buf_p = '\0'; - - else - { /* need more input */ - int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr); - ++yyg->yy_c_buf_p; - - switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart( yyin , yyscanner); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( yyscanner ) ) - return 0; - - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; + int c; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + *yyg->yy_c_buf_p = yyg->yy_hold_char; + + if (*yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if (yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]) + /* This was really a NUL. */ + *yyg->yy_c_buf_p = '\0'; + + else + { /* need more input */ + int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr); + ++yyg->yy_c_buf_p; + + switch (yy_get_next_buffer(yyscanner)) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin, yyscanner); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if (yywrap(yyscanner)) + return 0; + + if (!yyg->yy_did_buffer_switch_on_eof) + YY_NEW_FILE; #ifdef __cplusplus - return yyinput(yyscanner); + return yyinput(yyscanner); #else - return input(yyscanner); + return input(yyscanner); #endif - } + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; + break; + } + } + } - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = yyg->yytext_ptr + offset; - break; - } - } - } + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; - c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ - *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ - yyg->yy_hold_char = *++yyg->yy_c_buf_p; + if (c == '\n') - if ( c == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; + do + { + yylineno++; + yycolumn = 0; + } while (0); - return c; + return c; } -#endif /* ifndef YY_NO_INPUT */ +#endif /* ifndef YY_NO_INPUT */ /** Immediately switch to a different input stream. * @param input_file A readable stream. * @param yyscanner The scanner object. * @note This function does not reset the start condition to @c INITIAL . */ - void yyrestart (FILE * input_file , yyscan_t yyscanner) +void yyrestart(FILE *input_file, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); - } + if (!YY_CURRENT_BUFFER) + { + yyensure_buffer_stack(yyscanner); + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE, yyscanner); + } - yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner); - yy_load_buffer_state( yyscanner ); + yy_init_buffer(YY_CURRENT_BUFFER, input_file, yyscanner); + yy_load_buffer_state(yyscanner); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. * @param yyscanner The scanner object. */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (yyscanner); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( yyscanner ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - yyg->yy_did_buffer_switch_on_eof = 1; + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack(yyscanner); + if (YY_CURRENT_BUFFER == new_buffer) + return; + + if (YY_CURRENT_BUFFER) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state(yyscanner); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yyg->yy_did_buffer_switch_on_eof = 1; } -static void yy_load_buffer_state (yyscan_t yyscanner) +static void yy_load_buffer_state(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - yyg->yy_hold_char = *yyg->yy_c_buf_p; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + yyg->yy_hold_char = *yyg->yy_c_buf_p; } /** Allocate and initialize an input buffer state. * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * @param size The character buffer size in bytes. When in doubt, use @c + * YY_BUF_SIZE. * @param yyscanner The scanner object. * @return the allocated buffer state. */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner) +YY_BUFFER_STATE yy_create_buffer(FILE *file, int size, yyscan_t yyscanner) { - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof(struct yy_buffer_state), yyscanner); + if (!b) + YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); - b->yy_buf_size = size; + b->yy_buf_size = size; - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc((yy_size_t)(b->yy_buf_size + 2), yyscanner); + if (!b->yy_ch_buf) + YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); - b->yy_is_our_buffer = 1; + b->yy_is_our_buffer = 1; - yy_init_buffer( b, file , yyscanner); + yy_init_buffer(b, file, yyscanner); - return b; + return b; } /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() * @param yyscanner The scanner object. */ - void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +void yy_delete_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - if ( ! b ) - return; + if (!b) + return; - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + if (b == YY_CURRENT_BUFFER) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - if ( b->yy_is_our_buffer ) - yyfree( (void *) b->yy_ch_buf , yyscanner ); + if (b->yy_is_our_buffer) + yyfree((void *) b->yy_ch_buf, yyscanner); - yyfree( (void *) b , yyscanner ); + yyfree((void *) b, yyscanner); } /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) +static void yy_init_buffer(YY_BUFFER_STATE b, FILE *file, yyscan_t yyscanner) { - int oerrno = errno; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + int oerrno = errno; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - yy_flush_buffer( b , yyscanner); + yy_flush_buffer(b, yyscanner); - b->yy_input_file = file; - b->yy_fill_buffer = 1; + b->yy_input_file = file; + b->yy_fill_buffer = 1; - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER) + { + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = 0; - b->yy_is_interactive = 0; - - errno = oerrno; + errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. * @param yyscanner The scanner object. */ - void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +void yy_flush_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if ( ! b ) - return; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + if (!b) + return; - b->yy_n_chars = 0; + b->yy_n_chars = 0; - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - b->yy_buf_pos = &b->yy_ch_buf[0]; + b->yy_buf_pos = &b->yy_ch_buf[0]; - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( yyscanner ); + if (b == YY_CURRENT_BUFFER) + yy_load_buffer_state(yyscanner); } /** Pushes the new state onto the stack. The new state becomes @@ -2877,134 +2874,140 @@ static void yy_load_buffer_state (yyscan_t yyscanner) * @param new_buffer The new state. * @param yyscanner The scanner object. */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +void yypush_buffer_state(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(yyscanner); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - yyg->yy_buffer_stack_top++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(yyscanner); + + /* This block is copied from yy_switch_to_buffer. */ + if (YY_CURRENT_BUFFER) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + yyg->yy_buffer_stack_top++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state(yyscanner); + yyg->yy_did_buffer_switch_on_eof = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. * @param yyscanner The scanner object. */ -void yypop_buffer_state (yyscan_t yyscanner) +void yypop_buffer_state(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER , yyscanner); - YY_CURRENT_BUFFER_LVALUE = NULL; - if (yyg->yy_buffer_stack_top > 0) - --yyg->yy_buffer_stack_top; - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; - } + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER, yyscanner); + YY_CURRENT_BUFFER_LVALUE = NULL; + if (yyg->yy_buffer_stack_top > 0) + --yyg->yy_buffer_stack_top; + + if (YY_CURRENT_BUFFER) + { + yy_load_buffer_state(yyscanner); + yyg->yy_did_buffer_switch_on_eof = 1; + } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ -static void yyensure_buffer_stack (yyscan_t yyscanner) +static void yyensure_buffer_stack(yyscan_t yyscanner) { - yy_size_t num_to_alloc; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_size_t num_to_alloc; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - if (!yyg->yy_buffer_stack) { + if (!yyg->yy_buffer_stack) + { + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + yyg->yy_buffer_stack = (struct yy_buffer_state **) yyalloc( + num_to_alloc * sizeof(struct yy_buffer_state *), yyscanner); + if (!yyg->yy_buffer_stack) + YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()"); + + memset( + yyg->yy_buffer_stack, + 0, + num_to_alloc * sizeof(struct yy_buffer_state *)); + + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; + return; + } - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - yyg->yy_buffer_stack_max = num_to_alloc; - yyg->yy_buffer_stack_top = 0; - return; - } - - if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = yyg->yy_buffer_stack_max + grow_size; - yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc - (yyg->yy_buffer_stack, - num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); - yyg->yy_buffer_stack_max = num_to_alloc; - } + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1) + { + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state **) yyrealloc( + yyg->yy_buffer_stack, + num_to_alloc * sizeof(struct yy_buffer_state *), + yyscanner); + if (!yyg->yy_buffer_stack) + YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()"); + + /* zero only the new slots.*/ + memset( + yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, + 0, + grow_size * sizeof(struct yy_buffer_state *)); + yyg->yy_buffer_stack_max = num_to_alloc; + } } -/** Setup the input buffer state to scan directly from a user-specified character buffer. +/** Setup the input buffer state to scan directly from a user-specified + * character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) +YY_BUFFER_STATE yy_scan_buffer(char *base, yy_size_t size, yyscan_t yyscanner) { - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return NULL; - - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = NULL; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer( b , yyscanner ); - - return b; + YY_BUFFER_STATE b; + + if (size < 2 || base[size - 2] != YY_END_OF_BUFFER_CHAR || + base[size - 1] != YY_END_OF_BUFFER_CHAR) + /* They forgot to leave room for the EOB's. */ + return NULL; + + b = (YY_BUFFER_STATE) yyalloc(sizeof(struct yy_buffer_state), yyscanner); + if (!b) + YY_FATAL_ERROR("out of dynamic memory in yy_scan_buffer()"); + + b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = NULL; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer(b, yyscanner); + + return b; } /** Setup the input buffer state to scan a string. The next call to yylex() will @@ -3015,190 +3018,190 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscann * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ -YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner) +YY_BUFFER_STATE yy_scan_string(const char *yystr, yyscan_t yyscanner) { - - return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner); + return yy_scan_bytes(yystr, (int) strlen(yystr), yyscanner); } -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. +/** Setup the input buffer state to scan the given bytes. The next call to + * yylex() will scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner) +YY_BUFFER_STATE yy_scan_bytes( + const char *yybytes, + int _yybytes_len, + yyscan_t yyscanner) { - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = (yy_size_t) (_yybytes_len + 2); - buf = (char *) yyalloc( n , yyscanner ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer( buf, n , yyscanner); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = (yy_size_t)(_yybytes_len + 2); + buf = (char *) yyalloc(n, yyscanner); + if (!buf) + YY_FATAL_ERROR("out of dynamic memory in yy_scan_bytes()"); + + for (i = 0; i < _yybytes_len; ++i) buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len + 1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer(buf, n, yyscanner); + if (!b) + YY_FATAL_ERROR("bad buffer in yy_scan_bytes()"); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; } #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif -static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner) +static void yynoreturn yy_fatal_error(const char *msg, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + fprintf(stderr, "%s\n", msg); + exit(YY_EXIT_FAILURE); } /* Redefine yyless() so it works in section 3 code. */ #undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = yyg->yy_hold_char; \ - yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ - yyg->yy_hold_char = *yyg->yy_c_buf_p; \ - *yyg->yy_c_buf_p = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg); \ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ + yyleng = yyless_macro_arg; \ + } while (0) /* Accessor methods (get/set functions) to struct members. */ /** Get the user-defined data for this scanner. * @param yyscanner The scanner object. */ -YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner) +YY_EXTRA_TYPE yyget_extra(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyextra; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyextra; } /** Get the current line number. * @param yyscanner The scanner object. */ -int yyget_lineno (yyscan_t yyscanner) +int yyget_lineno(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + if (!YY_CURRENT_BUFFER) + return 0; - if (! YY_CURRENT_BUFFER) - return 0; - - return yylineno; + return yylineno; } /** Get the current column number. * @param yyscanner The scanner object. */ -int yyget_column (yyscan_t yyscanner) +int yyget_column(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - if (! YY_CURRENT_BUFFER) - return 0; - - return yycolumn; + if (!YY_CURRENT_BUFFER) + return 0; + + return yycolumn; } /** Get the input stream. * @param yyscanner The scanner object. */ -FILE *yyget_in (yyscan_t yyscanner) +FILE *yyget_in(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyin; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyin; } /** Get the output stream. * @param yyscanner The scanner object. */ -FILE *yyget_out (yyscan_t yyscanner) +FILE *yyget_out(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyout; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyout; } /** Get the length of the current token. * @param yyscanner The scanner object. */ -int yyget_leng (yyscan_t yyscanner) +int yyget_leng(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyleng; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyleng; } /** Get the current token. * @param yyscanner The scanner object. */ -char *yyget_text (yyscan_t yyscanner) +char *yyget_text(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yytext; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yytext; } /** Set the user-defined data. This data is never touched by the scanner. * @param user_defined The data to be associated with this scanner. * @param yyscanner The scanner object. */ -void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) +void yyset_extra(YY_EXTRA_TYPE user_defined, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyextra = user_defined ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyextra = user_defined; } /** Set the current line number. * @param _line_number line number * @param yyscanner The scanner object. */ -void yyset_lineno (int _line_number , yyscan_t yyscanner) +void yyset_lineno(int _line_number, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + /* lineno is only valid if an input buffer exists. */ + if (!YY_CURRENT_BUFFER) + YY_FATAL_ERROR("yyset_lineno called with no buffer"); - /* lineno is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "yyset_lineno called with no buffer" ); - - yylineno = _line_number; + yylineno = _line_number; } /** Set the current column. * @param _column_no column number * @param yyscanner The scanner object. */ -void yyset_column (int _column_no , yyscan_t yyscanner) +void yyset_column(int _column_no, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + /* column is only valid if an input buffer exists. */ + if (!YY_CURRENT_BUFFER) + YY_FATAL_ERROR("yyset_column called with no buffer"); - /* column is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "yyset_column called with no buffer" ); - - yycolumn = _column_no; + yycolumn = _column_no; } /** Set the input stream. This does not discard the current @@ -3207,68 +3210,72 @@ void yyset_column (int _column_no , yyscan_t yyscanner) * @param yyscanner The scanner object. * @see yy_switch_to_buffer */ -void yyset_in (FILE * _in_str , yyscan_t yyscanner) +void yyset_in(FILE *_in_str, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyin = _in_str ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyin = _in_str; } -void yyset_out (FILE * _out_str , yyscan_t yyscanner) +void yyset_out(FILE *_out_str, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyout = _out_str ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyout = _out_str; } -int yyget_debug (yyscan_t yyscanner) +int yyget_debug(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yy_flex_debug; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yy_flex_debug; } -void yyset_debug (int _bdebug , yyscan_t yyscanner) +void yyset_debug(int _bdebug, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yy_flex_debug = _bdebug ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yy_flex_debug = _bdebug; } /* Accessor methods for yylval and yylloc */ -YYSTYPE * yyget_lval (yyscan_t yyscanner) +YYSTYPE *yyget_lval(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yylval; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yylval; } -void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) +void yyset_lval(YYSTYPE *yylval_param, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yylval = yylval_param; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yylval = yylval_param; } /* User-visible API */ /* yylex_init is special because it creates the scanner itself, so it is - * the ONLY reentrant function that doesn't take the scanner as the last argument. - * That's why we explicitly handle the declaration, instead of using our macros. + * the ONLY reentrant function that doesn't take the scanner as the last + * argument. That's why we explicitly handle the declaration, instead of using + * our macros. */ -int yylex_init(yyscan_t* ptr_yy_globals) +int yylex_init(yyscan_t *ptr_yy_globals) { - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } + if (ptr_yy_globals == NULL) + { + errno = EINVAL; + return 1; + } - *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL ); + *ptr_yy_globals = (yyscan_t) yyalloc(sizeof(struct yyguts_t), NULL); - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } + if (*ptr_yy_globals == NULL) + { + errno = ENOMEM; + return 1; + } - /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for + * releases. */ + memset(*ptr_yy_globals, 0x00, sizeof(struct yyguts_t)); - return yy_init_globals ( *ptr_yy_globals ); + return yy_init_globals(*ptr_yy_globals); } /* yylex_init_extra has the same functionality as yylex_init, but follows the @@ -3278,94 +3285,97 @@ int yylex_init(yyscan_t* ptr_yy_globals) * The user defined value in the first argument will be available to yyalloc in * the yyextra field. */ -int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals ) +int yylex_init_extra(YY_EXTRA_TYPE yy_user_defined, yyscan_t *ptr_yy_globals) { - struct yyguts_t dummy_yyguts; + struct yyguts_t dummy_yyguts; - yyset_extra (yy_user_defined, &dummy_yyguts); + yyset_extra(yy_user_defined, &dummy_yyguts); - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } + if (ptr_yy_globals == NULL) + { + errno = EINVAL; + return 1; + } - *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + *ptr_yy_globals = (yyscan_t) yyalloc(sizeof(struct yyguts_t), &dummy_yyguts); - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } + if (*ptr_yy_globals == NULL) + { + errno = ENOMEM; + return 1; + } - /* By setting to 0xAA, we expose bugs in - yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals, 0x00, sizeof(struct yyguts_t)); - yyset_extra (yy_user_defined, *ptr_yy_globals); + yyset_extra(yy_user_defined, *ptr_yy_globals); - return yy_init_globals ( *ptr_yy_globals ); + return yy_init_globals(*ptr_yy_globals); } -static int yy_init_globals (yyscan_t yyscanner) +static int yy_init_globals(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ - yyg->yy_buffer_stack = NULL; - yyg->yy_buffer_stack_top = 0; - yyg->yy_buffer_stack_max = 0; - yyg->yy_c_buf_p = NULL; - yyg->yy_init = 0; - yyg->yy_start = 0; + yyg->yy_buffer_stack = NULL; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = NULL; + yyg->yy_init = 0; + yyg->yy_start = 0; - yyg->yy_start_stack_ptr = 0; - yyg->yy_start_stack_depth = 0; - yyg->yy_start_stack = NULL; + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; /* Defined in main.c */ #ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; + yyin = stdin; + yyout = stdout; #else - yyin = NULL; - yyout = NULL; + yyin = NULL; + yyout = NULL; #endif - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; } /* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (yyscan_t yyscanner) +int yylex_destroy(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(yyscanner); - } - - /* Destroy the stack itself. */ - yyfree(yyg->yy_buffer_stack , yyscanner); - yyg->yy_buffer_stack = NULL; - - /* Destroy the start condition stack. */ - yyfree( yyg->yy_start_stack , yyscanner ); - yyg->yy_start_stack = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( yyscanner); - - /* Destroy the main struct (reentrant only). */ - yyfree ( yyscanner , yyscanner ); - yyscanner = NULL; - return 0; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + /* Pop the buffer stack, destroying each element. */ + while (YY_CURRENT_BUFFER) + { + yy_delete_buffer(YY_CURRENT_BUFFER, yyscanner); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(yyscanner); + } + + /* Destroy the stack itself. */ + yyfree(yyg->yy_buffer_stack, yyscanner); + yyg->yy_buffer_stack = NULL; + + /* Destroy the start condition stack. */ + yyfree(yyg->yy_start_stack, yyscanner); + yyg->yy_start_stack = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next + * time yylex() is called, initialization will occur. */ + yy_init_globals(yyscanner); + + /* Destroy the main struct (reentrant only). */ + yyfree(yyscanner, yyscanner); + yyscanner = NULL; + return 0; } /* @@ -3373,55 +3383,54 @@ int yylex_destroy (yyscan_t yyscanner) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner) +static void yy_flex_strncpy(char *s1, const char *s2, int n, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; + int i; + for (i = 0; i < n; ++i) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (const char * s , yyscan_t yyscanner) +static int yy_flex_strlen(const char *s, yyscan_t yyscanner) { - int n; - for ( n = 0; s[n]; ++n ) - ; + int n; + for (n = 0; s[n]; ++n) + ; - return n; + return n; } #endif -void *yyalloc (yy_size_t size , yyscan_t yyscanner) +void *yyalloc(yy_size_t size, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - return malloc(size); + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + return malloc(size); } -void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner) +void *yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return realloc(ptr, size); + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return realloc(ptr, size); } -void yyfree (void * ptr , yyscan_t yyscanner) +void yyfree(void *ptr, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + free((char *) ptr); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" @@ -3429,15 +3438,11 @@ void yyfree (void * ptr , yyscan_t yyscanner) #line 758 "lexer.l" - -void yywarning( - yyscan_t yyscanner, - const char *message_fmt, - ...) +void yywarning(yyscan_t yyscanner, const char *message_fmt, ...) { - YR_COMPILER* compiler = yyget_extra(yyscanner); + YR_COMPILER *compiler = yyget_extra(yyscanner); - char* file_name; + char *file_name; char message[512]; va_list message_args; @@ -3453,7 +3458,7 @@ void yywarning( vsnprintf(message, sizeof(message), message_fmt, message_args); - YR_RULE* current_rule = NULL; + YR_RULE *current_rule = NULL; if (compiler->current_rule_idx != UINT32_MAX) current_rule = yr_arena_get_ptr( @@ -3473,11 +3478,9 @@ void yywarning( } -void yyfatal( - yyscan_t yyscanner, - const char *error_message) +void yyfatal(yyscan_t yyscanner, const char *error_message) { - YR_COMPILER* compiler = yyget_extra(yyscanner); + YR_COMPILER *compiler = yyget_extra(yyscanner); yyerror(yyscanner, compiler, error_message); longjmp(compiler->error_recovery, 1); @@ -3486,11 +3489,11 @@ void yyfatal( void yyerror( yyscan_t yyscanner, - YR_COMPILER* compiler, + YR_COMPILER *compiler, const char *error_message) { char message[512] = {'\0'}; - char* file_name = NULL; + char *file_name = NULL; /* if error_message != NULL the error comes from yyparse internal code @@ -3516,7 +3519,7 @@ void yyerror( file_name = NULL; } - YR_RULE* current_rule = NULL; + YR_RULE *current_rule = NULL; if (compiler->current_rule_idx != UINT32_MAX) current_rule = yr_arena_get_ptr( @@ -3555,9 +3558,7 @@ void yyerror( } -int yr_lex_parse_rules_string( - const char* rules_string, - YR_COMPILER* compiler) +int yr_lex_parse_rules_string(const char *rules_string, YR_COMPILER *compiler) { yyscan_t yyscanner; @@ -3568,9 +3569,9 @@ int yr_lex_parse_rules_string( yylex_init(&yyscanner); - #if YYDEBUG +#if YYDEBUG yydebug = 1; - #endif +#endif yyset_extra(compiler, yyscanner); yy_scan_string(rules_string, yyscanner); @@ -3582,9 +3583,7 @@ int yr_lex_parse_rules_string( } -int yr_lex_parse_rules_file( - FILE* rules_file, - YR_COMPILER* compiler) +int yr_lex_parse_rules_file(FILE *rules_file, YR_COMPILER *compiler) { yyscan_t yyscanner; @@ -3595,9 +3594,9 @@ int yr_lex_parse_rules_file( yylex_init(&yyscanner); - #if YYDEBUG +#if YYDEBUG yydebug = 1; - #endif +#endif yyset_in(rules_file, yyscanner); yyset_extra(compiler, yyscanner); @@ -3608,26 +3607,24 @@ int yr_lex_parse_rules_file( } -int yr_lex_parse_rules_fd( - YR_FILE_DESCRIPTOR rules_fd, - YR_COMPILER* compiler) +int yr_lex_parse_rules_fd(YR_FILE_DESCRIPTOR rules_fd, YR_COMPILER *compiler) { yyscan_t yyscanner; size_t file_size; - void* buffer; + void *buffer; - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) DWORD bytes_read; - #endif +#endif compiler->errors = 0; if (setjmp(compiler->error_recovery) != 0) return compiler->errors; - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) file_size = (size_t) GetFileSize(rules_fd, NULL); - #else +#else struct stat fs; if (fstat(rules_fd, &fs) != 0) { @@ -3636,7 +3633,7 @@ int yr_lex_parse_rules_fd( return compiler->errors; } file_size = (size_t) fs.st_size; - #endif +#endif buffer = yr_malloc(file_size); @@ -3647,11 +3644,11 @@ int yr_lex_parse_rules_fd( return compiler->errors; } - #if defined(_WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) if (!ReadFile(rules_fd, buffer, file_size, &bytes_read, NULL)) - #else +#else if (read(rules_fd, buffer, file_size) != file_size) - #endif +#endif { yr_free(buffer); compiler->errors = 1; @@ -3661,12 +3658,12 @@ int yr_lex_parse_rules_fd( yylex_init(&yyscanner); - #if YYDEBUG +#if YYDEBUG yydebug = 1; - #endif +#endif yyset_extra(compiler, yyscanner); - yy_scan_bytes((const char*) buffer, (int) file_size, yyscanner); + yy_scan_bytes((const char *) buffer, (int) file_size, yyscanner); yyset_lineno(1, yyscanner); yyparse(yyscanner, compiler); yylex_destroy(yyscanner); @@ -3675,4 +3672,3 @@ int yr_lex_parse_rules_fd( return compiler->errors; } - diff --git a/libyara/libyara.c b/libyara/libyara.c index 062c77081b..560e59991e 100644 --- a/libyara/libyara.c +++ b/libyara/libyara.c @@ -31,15 +31,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #endif -#include -#include #include - -#include +#include +#include #include -#include -#include +#include #include +#include +#include #include #include "crypto.h" @@ -59,10 +58,10 @@ static struct yr_config_var { union { - size_t sz; + size_t sz; uint32_t ui32; uint64_t ui64; - char* str; + char *str; }; } yr_cfgs[YR_CONFIG_LAST]; @@ -96,11 +95,7 @@ static void _thread_id(CRYPTO_THREADID *id) } -static void _locking_function( - int mode, - int n, - const char *file, - int line) +static void _locking_function(int mode, int n, const char *file, int line) { if (mode & CRYPTO_LOCK) yr_mutex_lock(&openssl_locks[n]); @@ -150,40 +145,40 @@ YR_API int yr_initialize(void) FAIL_ON_ERROR(yr_thread_storage_create(&yr_yyfatal_trampoline_tls)); FAIL_ON_ERROR(yr_thread_storage_create(&yr_trycatch_trampoline_tls)); - #if defined HAVE_LIBCRYPTO && OPENSSL_VERSION_NUMBER < 0x10100000L +#if defined HAVE_LIBCRYPTO && OPENSSL_VERSION_NUMBER < 0x10100000L - openssl_locks = (YR_MUTEX*) OPENSSL_malloc( + openssl_locks = (YR_MUTEX *) OPENSSL_malloc( CRYPTO_num_locks() * sizeof(YR_MUTEX)); - for (i = 0; i < CRYPTO_num_locks(); i++) - yr_mutex_create(&openssl_locks[i]); + for (i = 0; i < CRYPTO_num_locks(); i++) yr_mutex_create(&openssl_locks[i]); CRYPTO_THREADID_set_callback(_thread_id); CRYPTO_set_locking_callback(_locking_function); - #elif defined(HAVE_WINCRYPT_H) +#elif defined(HAVE_WINCRYPT_H) - if (!CryptAcquireContext(&yr_cryptprov, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) { + if (!CryptAcquireContext( + &yr_cryptprov, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) + { return ERROR_INTERNAL_FATAL_ERROR; } - #elif defined(HAVE_COMMON_CRYPTO) +#elif defined(HAVE_COMMON_CRYPTO) ... - #endif +#endif FAIL_ON_ERROR(yr_modules_initialize()); // Initialize default configuration options - FAIL_ON_ERROR(yr_set_configuration( - YR_CONFIG_STACK_SIZE, &def_stack_size)); + FAIL_ON_ERROR(yr_set_configuration(YR_CONFIG_STACK_SIZE, &def_stack_size)); FAIL_ON_ERROR(yr_set_configuration( YR_CONFIG_MAX_STRINGS_PER_RULE, &def_max_strings_per_rule)); - FAIL_ON_ERROR(yr_set_configuration( - YR_CONFIG_MAX_MATCH_DATA, &def_max_match_data)); + FAIL_ON_ERROR( + yr_set_configuration(YR_CONFIG_MAX_MATCH_DATA, &def_max_match_data)); return ERROR_SUCCESS; } @@ -197,9 +192,9 @@ YR_API int yr_initialize(void) YR_API int yr_finalize(void) { - #if defined HAVE_LIBCRYPTO && OPENSSL_VERSION_NUMBER < 0x10100000L +#if defined HAVE_LIBCRYPTO && OPENSSL_VERSION_NUMBER < 0x10100000L int i; - #endif +#endif // yr_finalize shouldn't be called without calling yr_initialize first @@ -211,36 +206,34 @@ YR_API int yr_finalize(void) if (init_count > 0) return ERROR_SUCCESS; - #if defined HAVE_LIBCRYPTO && OPENSSL_VERSION_NUMBER < 0x10100000L +#if defined HAVE_LIBCRYPTO && OPENSSL_VERSION_NUMBER < 0x10100000L - for (i = 0; i < CRYPTO_num_locks(); i ++) - yr_mutex_destroy(&openssl_locks[i]); + for (i = 0; i < CRYPTO_num_locks(); i++) yr_mutex_destroy(&openssl_locks[i]); OPENSSL_free(openssl_locks); CRYPTO_THREADID_set_callback(NULL); CRYPTO_set_locking_callback(NULL); - #elif defined(HAVE_WINCRYPT_H) +#elif defined(HAVE_WINCRYPT_H) CryptReleaseContext(yr_cryptprov, 0); - #endif +#endif FAIL_ON_ERROR(yr_thread_storage_destroy(&yr_yyfatal_trampoline_tls)); FAIL_ON_ERROR(yr_thread_storage_destroy(&yr_trycatch_trampoline_tls)); FAIL_ON_ERROR(yr_modules_finalize()); FAIL_ON_ERROR(yr_heap_free()); - #if defined(JEMALLOC) +#if defined(JEMALLOC) malloc_stats_print(NULL, NULL, NULL); mallctl("prof.dump", NULL, NULL, NULL, 0); - #endif +#endif return ERROR_SUCCESS; } - // // yr_set_configuration // @@ -261,46 +254,42 @@ YR_API int yr_finalize(void) // Returns: // An error code. -YR_API int yr_set_configuration( - YR_CONFIG_NAME name, - void *src) +YR_API int yr_set_configuration(YR_CONFIG_NAME name, void *src) { if (src == NULL) return ERROR_INTERNAL_FATAL_ERROR; switch (name) - { // lump all the cases using same types together in one cascade - case YR_CONFIG_STACK_SIZE: - case YR_CONFIG_MAX_STRINGS_PER_RULE: - case YR_CONFIG_MAX_MATCH_DATA: - yr_cfgs[name].ui32 = *(uint32_t*) src; - break; - - default: - return ERROR_INTERNAL_FATAL_ERROR; + { // lump all the cases using same types together in one cascade + case YR_CONFIG_STACK_SIZE: + case YR_CONFIG_MAX_STRINGS_PER_RULE: + case YR_CONFIG_MAX_MATCH_DATA: + yr_cfgs[name].ui32 = *(uint32_t *) src; + break; + + default: + return ERROR_INTERNAL_FATAL_ERROR; } return ERROR_SUCCESS; } -YR_API int yr_get_configuration( - YR_CONFIG_NAME name, - void *dest) +YR_API int yr_get_configuration(YR_CONFIG_NAME name, void *dest) { if (dest == NULL) return ERROR_INTERNAL_FATAL_ERROR; switch (name) - { // lump all the cases using same types together in one cascade - case YR_CONFIG_STACK_SIZE: - case YR_CONFIG_MAX_STRINGS_PER_RULE: - case YR_CONFIG_MAX_MATCH_DATA: - *(uint32_t*) dest = yr_cfgs[name].ui32; - break; - - default: - return ERROR_INTERNAL_FATAL_ERROR; + { // lump all the cases using same types together in one cascade + case YR_CONFIG_STACK_SIZE: + case YR_CONFIG_MAX_STRINGS_PER_RULE: + case YR_CONFIG_MAX_MATCH_DATA: + *(uint32_t *) dest = yr_cfgs[name].ui32; + break; + + default: + return ERROR_INTERNAL_FATAL_ERROR; } return ERROR_SUCCESS; diff --git a/libyara/mem.c b/libyara/mem.c index 1a87c3a776..2601d88f6c 100644 --- a/libyara/mem.c +++ b/libyara/mem.c @@ -27,13 +27,13 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include #if defined(_WIN32) || defined(__CYGWIN__) -#include #include +#include static HANDLE hHeap; @@ -84,10 +84,10 @@ void yr_free(void* ptr) } -char* yr_strdup(const char *str) +char* yr_strdup(const char* str) { size_t len = strlen(str); - char *dup = (char*) yr_malloc(len + 1); + char* dup = (char*) yr_malloc(len + 1); if (dup == NULL) return NULL; @@ -99,10 +99,10 @@ char* yr_strdup(const char *str) } -char* yr_strndup(const char *str, size_t n) +char* yr_strndup(const char* str, size_t n) { size_t len = strnlen(str, n); - char *dup = (char*) yr_malloc(len + 1); + char* dup = (char*) yr_malloc(len + 1); if (dup == NULL) return NULL; @@ -110,14 +110,14 @@ char* yr_strndup(const char *str, size_t n) memcpy(dup, str, len); dup[len] = '\0'; - return (char *) dup; + return (char*) dup; } #else +#include #include #include -#include int yr_heap_alloc(void) { @@ -149,19 +149,19 @@ void* yr_realloc(void* ptr, size_t size) } -void yr_free(void *ptr) +void yr_free(void* ptr) { free(ptr); } -char* yr_strdup(const char *str) +char* yr_strdup(const char* str) { return strdup(str); } -char* yr_strndup(const char *str, size_t n) +char* yr_strndup(const char* str, size_t n) { return strndup(str, n); } diff --git a/libyara/modules.c b/libyara/modules.c index 76812f3dc7..5d864933f4 100644 --- a/libyara/modules.c +++ b/libyara/modules.c @@ -28,19 +28,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include #include +#include -#define MODULE(name) \ - int name ## __declarations(YR_OBJECT* module); \ - int name ## __load(YR_SCAN_CONTEXT* context, \ - YR_OBJECT* module, \ - void* module_data, \ - size_t module_data_size); \ - int name ## __unload(YR_OBJECT* main_structure); \ - int name ## __initialize(YR_MODULE* module); \ - int name ## __finalize(YR_MODULE* module); +#define MODULE(name) \ + int name##__declarations(YR_OBJECT* module); \ + int name##__load( \ + YR_SCAN_CONTEXT* context, \ + YR_OBJECT* module, \ + void* module_data, \ + size_t module_data_size); \ + int name##__unload(YR_OBJECT* main_structure); \ + int name##__initialize(YR_MODULE* module); \ + int name##__finalize(YR_MODULE* module); #include @@ -48,19 +49,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #undef MODULE -#define MODULE(name) \ - { \ - #name, \ - name##__declarations, \ - name##__load, \ - name##__unload, \ - name##__initialize, \ - name##__finalize \ - }, +#define MODULE(name) \ + {#name, \ + name##__declarations, \ + name##__load, \ + name##__unload, \ + name##__initialize, \ + name##__finalize}, -YR_MODULE yr_modules_table[] = -{ - #include +YR_MODULE yr_modules_table[] = { +#include }; #undef MODULE @@ -114,18 +112,14 @@ int yr_modules_do_declarations( } -int yr_modules_load( - const char* module_name, - YR_SCAN_CONTEXT* context) +int yr_modules_load(const char* module_name, YR_SCAN_CONTEXT* context) { int i, result; YR_MODULE_IMPORT mi; YR_OBJECT* module_structure = (YR_OBJECT*) yr_hash_table_lookup( - context->objects_table, - module_name, - NULL); + context->objects_table, module_name, NULL); // if module_structure != NULL, the module was already // loaded, return successfully without doing nothing. @@ -136,10 +130,7 @@ int yr_modules_load( // not loaded yet FAIL_ON_ERROR(yr_object_create( - OBJECT_TYPE_STRUCTURE, - module_name, - NULL, - &module_structure)); + OBJECT_TYPE_STRUCTURE, module_name, NULL, &module_structure)); // initialize canary for module's top-level structure, every other object // within the module inherits the same canary. @@ -150,10 +141,7 @@ int yr_modules_load( mi.module_data_size = 0; result = context->callback( - context, - CALLBACK_MSG_IMPORT_MODULE, - &mi, - context->user_data); + context, CALLBACK_MSG_IMPORT_MODULE, &mi, context->user_data); if (result == CALLBACK_ERROR) { @@ -167,10 +155,7 @@ int yr_modules_load( FAIL_ON_ERROR_WITH_CLEANUP( yr_hash_table_add( - context->objects_table, - module_name, - NULL, - module_structure), + context->objects_table, module_name, NULL, module_structure), yr_object_destroy(module_structure)); for (i = 0; i < sizeof(yr_modules_table) / sizeof(YR_MODULE); i++) @@ -178,10 +163,7 @@ int yr_modules_load( if (strcmp(yr_modules_table[i].name, module_name) == 0) { result = yr_modules_table[i].load( - context, - module_structure, - mi.module_data, - mi.module_data_size); + context, module_structure, mi.module_data, mi.module_data_size); if (result != ERROR_SUCCESS) return result; @@ -201,17 +183,14 @@ int yr_modules_load( } -int yr_modules_unload_all( - YR_SCAN_CONTEXT* context) +int yr_modules_unload_all(YR_SCAN_CONTEXT* context) { int i; for (i = 0; i < sizeof(yr_modules_table) / sizeof(YR_MODULE); i++) { YR_OBJECT* module_structure = (YR_OBJECT*) yr_hash_table_remove( - context->objects_table, - yr_modules_table[i].name, - NULL); + context->objects_table, yr_modules_table[i].name, NULL); if (module_structure != NULL) { diff --git a/libyara/modules/cuckoo/cuckoo.c b/libyara/modules/cuckoo/cuckoo.c index 1793cf4c69..c3df0b4666 100644 --- a/libyara/modules/cuckoo/cuckoo.c +++ b/libyara/modules/cuckoo/cuckoo.c @@ -28,12 +28,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include - - -#include +#include #include +#include #if defined(_WIN32) || defined(__CYGWIN__) @@ -105,8 +103,8 @@ define_function(network_dns_lookup) } -#define METHOD_GET 0x01 -#define METHOD_POST 0x02 +#define METHOD_GET 0x01 +#define METHOD_POST 0x02 uint64_t http_request( @@ -131,7 +129,7 @@ uint64_t http_request( { if (((methods & METHOD_GET && strcasecmp(method, "get") == 0) || (methods & METHOD_POST && strcasecmp(method, "post") == 0)) && - yr_re_match(context, uri_regexp, uri) > 0) + yr_re_match(context, uri_regexp, uri) > 0) { result = 1; break; @@ -145,34 +143,22 @@ uint64_t http_request( define_function(network_http_request) { - return_integer( - http_request( - scan_context(), - parent(), - regexp_argument(1), - METHOD_GET | METHOD_POST)); + return_integer(http_request( + scan_context(), parent(), regexp_argument(1), METHOD_GET | METHOD_POST)); } define_function(network_http_get) { return_integer( - http_request( - scan_context(), - parent(), - regexp_argument(1), - METHOD_GET)); + http_request(scan_context(), parent(), regexp_argument(1), METHOD_GET)); } define_function(network_http_post) { return_integer( - http_request( - scan_context(), - parent(), - regexp_argument(1), - METHOD_POST)); + http_request(scan_context(), parent(), regexp_argument(1), METHOD_POST)); } @@ -227,7 +213,8 @@ define_function(network_tcp) { if (yr_re_match(context, regexp_argument(1), dst) > 0) { - if ((int64_t)dport == integer_argument(2)) { + if ((int64_t) dport == integer_argument(2)) + { result = 1; break; } @@ -263,7 +250,8 @@ define_function(network_udp) { if (yr_re_match(context, regexp_argument(1), dst) > 0) { - if ((int64_t)dport == integer_argument(2)) { + if ((int64_t) dport == integer_argument(2)) + { result = 1; break; } @@ -279,7 +267,6 @@ define_function(network_udp) // checks for regex match on user-agent define_function(network_http_user_agent) { - YR_SCAN_CONTEXT* context = scan_context(); YR_OBJECT* network_obj = parent(); @@ -356,7 +343,6 @@ define_function(filesystem_file_access) } - define_function(sync_mutex) { YR_SCAN_CONTEXT* context = scan_context(); @@ -381,9 +367,11 @@ define_function(sync_mutex) } -begin_declarations; +begin_declarations + ; - begin_struct("network"); + begin_struct("network") + ; declare_function("dns_lookup", "r", "i", network_dns_lookup); declare_function("http_get", "r", "i", network_http_get); declare_function("http_post", "r", "i", network_http_post); @@ -394,30 +382,31 @@ begin_declarations; declare_function("udp", "ri", "i", network_udp); end_struct("network"); - begin_struct("registry"); + begin_struct("registry") + ; declare_function("key_access", "r", "i", registry_key_access); end_struct("registry"); - begin_struct("filesystem"); + begin_struct("filesystem") + ; declare_function("file_access", "r", "i", filesystem_file_access); end_struct("filesystem"); - begin_struct("sync"); + begin_struct("sync") + ; declare_function("mutex", "r", "i", sync_mutex); end_struct("sync"); end_declarations; -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { return ERROR_SUCCESS; } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { return ERROR_SUCCESS; } @@ -445,11 +434,11 @@ int module_load( json = json_loadb( (const char*) module_data, module_data_size, - #if JANSSON_VERSION_HEX >= 0x020600 +#if JANSSON_VERSION_HEX >= 0x020600 JSON_ALLOW_NUL, - #else +#else 0, - #endif +#endif &json_error); if (json == NULL) @@ -482,4 +471,3 @@ int module_unload(YR_OBJECT* module) return ERROR_SUCCESS; } - diff --git a/libyara/modules/demo/demo.c b/libyara/modules/demo/demo.c index af8a8e72e4..1a5ac3ef03 100644 --- a/libyara/modules/demo/demo.c +++ b/libyara/modules/demo/demo.c @@ -31,22 +31,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define MODULE_NAME demo -begin_declarations; +begin_declarations + ; declare_string("greeting"); end_declarations; -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { return ERROR_SUCCESS; } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { return ERROR_SUCCESS; } @@ -64,8 +63,7 @@ int module_load( } -int module_unload( - YR_OBJECT* module_object) +int module_unload(YR_OBJECT* module_object) { return ERROR_SUCCESS; } diff --git a/libyara/modules/dex/dex.c b/libyara/modules/dex/dex.c index 1135ed928f..11e58ca467 100644 --- a/libyara/modules/dex/dex.c +++ b/libyara/modules/dex/dex.c @@ -28,18 +28,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include - -#include #include -#include #include +#include #define MODULE_NAME dex // DEX File layout information: // https://source.android.com/devices/tech/dalvik/dex-format -begin_declarations; +begin_declarations + ; declare_string("DEX_FILE_MAGIC_035"); declare_string("DEX_FILE_MAGIC_036"); @@ -91,7 +90,8 @@ begin_declarations; declare_integer("TYPE_ENCODED_ARRAY_ITEM"); declare_integer("TYPE_ANNOTATIONS_DIRECTORY_ITEM"); - begin_struct("header"); + begin_struct("header") + ; declare_string("magic"); declare_integer("checksum"); declare_string("signature"); @@ -117,35 +117,41 @@ begin_declarations; declare_integer("data_offset"); end_struct("header"); - begin_struct_array("string_ids"); + begin_struct_array("string_ids") + ; declare_integer("offset"); declare_integer("size"); declare_string("value"); end_struct_array("string_ids"); - begin_struct_array("type_ids"); + begin_struct_array("type_ids") + ; declare_integer("descriptor_idx"); end_struct_array("type_ids"); - begin_struct_array("proto_ids"); + begin_struct_array("proto_ids") + ; declare_integer("shorty_idx"); declare_integer("return_type_idx"); declare_integer("parameters_offset"); end_struct_array("proto_ids"); - begin_struct_array("field_ids"); + begin_struct_array("field_ids") + ; declare_integer("class_idx"); declare_integer("type_idx"); declare_integer("name_idx"); end_struct_array("field_ids"); - begin_struct_array("method_ids"); + begin_struct_array("method_ids") + ; declare_integer("class_idx"); declare_integer("proto_idx"); declare_integer("name_idx"); end_struct_array("method_ids"); - begin_struct_array("class_defs"); + begin_struct_array("class_defs") + ; declare_integer("class_idx"); declare_integer("access_flags"); declare_integer("super_class_idx"); @@ -156,16 +162,19 @@ begin_declarations; declare_integer("static_values_offset"); end_struct_array("class_defs"); - begin_struct_array("class_data_item"); - declare_integer("static_fields_size"); - declare_integer("instance_fields_size"); - declare_integer("direct_methods_size"); - declare_integer("virtual_methods_size"); + begin_struct_array("class_data_item") + ; + declare_integer("static_fields_size"); + declare_integer("instance_fields_size"); + declare_integer("direct_methods_size"); + declare_integer("virtual_methods_size"); end_struct_array("class_data_item"); - begin_struct("map_list"); + begin_struct("map_list") + ; declare_integer("size"); - begin_struct_array("map_item"); + begin_struct_array("map_item") + ; declare_integer("type"); declare_integer("unused"); declare_integer("size"); @@ -174,7 +183,8 @@ begin_declarations; end_struct("map_list"); declare_integer("number_of_fields"); - begin_struct_array("field"); + begin_struct_array("field") + ; declare_string("class_name"); declare_string("name"); declare_string("proto"); @@ -184,7 +194,8 @@ begin_declarations; end_struct_array("field"); declare_integer("number_of_methods"); - begin_struct_array("method"); + begin_struct_array("method") + ; declare_string("class_name"); declare_string("name"); declare_string("proto"); @@ -194,7 +205,8 @@ begin_declarations; declare_integer("method_idx_diff"); declare_integer("access_flags"); declare_integer("code_off"); - begin_struct("code_item"); + begin_struct("code_item") + ; declare_integer("registers_size"); declare_integer("ins_size"); declare_integer("outs_size"); @@ -203,9 +215,11 @@ begin_declarations; declare_integer("insns_size"); declare_string("insns"); declare_integer("padding"); - begin_struct("tries"); + begin_struct("tries") + ; end_struct("tries"); - begin_struct_array("handlers"); + begin_struct_array("handlers") + ; end_struct_array("handlers"); end_struct("code_item"); end_struct_array("method"); @@ -214,9 +228,7 @@ end_declarations; // https://android.googlesource.com/platform/dalvik/+/android-4.4.2_r2/libdex/Leb128.cpp -static int32_t read_uleb128( - const uint8_t* pStream, - uint32_t *size) +static int32_t read_uleb128(const uint8_t* pStream, uint32_t* size) { const uint8_t* ptr = pStream; @@ -261,9 +273,9 @@ static int32_t read_uleb128( static int64_t dex_get_integer( - YR_OBJECT* object, - const char* pattern, - int64_t index) + YR_OBJECT* object, + const char* pattern, + int64_t index) { if (index == YR_UNDEFINED) return YR_UNDEFINED; @@ -277,9 +289,9 @@ static int64_t dex_get_integer( static SIZED_STRING* dex_get_string( - YR_OBJECT* object, - const char* pattern, - int64_t index) + YR_OBJECT* object, + const char* pattern, + int64_t index) { if (index == YR_UNDEFINED) return NULL; @@ -292,9 +304,7 @@ static SIZED_STRING* dex_get_string( } -dex_header_t* dex_get_header( - const uint8_t* data, - size_t data_size) +dex_header_t* dex_get_header(const uint8_t* data, size_t data_size) { dex_header_t* dex_header; @@ -317,9 +327,7 @@ dex_header_t* dex_get_header( } -void dex_parse_header( - dex_header_t* dex_header, - YR_OBJECT* module_object) +void dex_parse_header(dex_header_t* dex_header, YR_OBJECT* module_object) { set_sized_string( (char*) dex_header->magic, @@ -328,70 +336,92 @@ void dex_parse_header( "header.magic"); set_integer( - yr_le32toh(dex_header->checksum), - module_object, - "header.checksum"); + yr_le32toh(dex_header->checksum), module_object, "header.checksum"); set_sized_string( (char*) dex_header->signature, - strnlen((char *) dex_header->signature, 20 * sizeof(char)), + strnlen((char*) dex_header->signature, 20 * sizeof(char)), module_object, "header.signature"); - set_integer(yr_le32toh(dex_header->file_size), module_object, - "header.file_size"); - set_integer(yr_le32toh(dex_header->header_size), module_object, - "header.header_size"); - set_integer(yr_le32toh(dex_header->endian_tag), module_object, - "header.endian_tag"); - set_integer(yr_le32toh(dex_header->link_size), module_object, - "header.link_size"); - set_integer(yr_le32toh(dex_header->link_offset), module_object, - "header.link_offset"); - set_integer(yr_le32toh(dex_header->map_offset), module_object, - "header.map_offset"); - set_integer(yr_le32toh(dex_header->string_ids_size), module_object, - "header.string_ids_size"); - set_integer(yr_le32toh(dex_header->string_ids_offset), module_object, - "header.string_ids_offset"); - set_integer(yr_le32toh(dex_header->type_ids_size), module_object, - "header.type_ids_size"); - set_integer(yr_le32toh(dex_header->type_ids_offset), module_object, - "header.type_ids_offset"); - set_integer(yr_le32toh(dex_header->proto_ids_size), module_object, - "header.proto_ids_size"); - set_integer(yr_le32toh(dex_header->proto_ids_offset), module_object, - "header.proto_ids_offset"); - set_integer(yr_le32toh(dex_header->field_ids_size), module_object, - "header.field_ids_size"); - set_integer(yr_le32toh(dex_header->field_ids_offset), module_object, - "header.field_ids_offset"); - set_integer(yr_le32toh(dex_header->method_ids_size), module_object, - "header.method_ids_size"); - set_integer(yr_le32toh(dex_header->method_ids_offset), module_object, - "header.method_ids_offset"); - set_integer(yr_le32toh(dex_header->class_defs_size), module_object, - "header.class_defs_size"); - set_integer(yr_le32toh(dex_header->class_defs_offset), module_object, - "header.class_defs_offset"); - set_integer(yr_le32toh(dex_header->data_size), module_object, - "header.data_size"); - set_integer(yr_le32toh(dex_header->data_offset), module_object, - "header.data_offset"); + set_integer( + yr_le32toh(dex_header->file_size), module_object, "header.file_size"); + set_integer( + yr_le32toh(dex_header->header_size), module_object, "header.header_size"); + set_integer( + yr_le32toh(dex_header->endian_tag), module_object, "header.endian_tag"); + set_integer( + yr_le32toh(dex_header->link_size), module_object, "header.link_size"); + set_integer( + yr_le32toh(dex_header->link_offset), module_object, "header.link_offset"); + set_integer( + yr_le32toh(dex_header->map_offset), module_object, "header.map_offset"); + set_integer( + yr_le32toh(dex_header->string_ids_size), + module_object, + "header.string_ids_size"); + set_integer( + yr_le32toh(dex_header->string_ids_offset), + module_object, + "header.string_ids_offset"); + set_integer( + yr_le32toh(dex_header->type_ids_size), + module_object, + "header.type_ids_size"); + set_integer( + yr_le32toh(dex_header->type_ids_offset), + module_object, + "header.type_ids_offset"); + set_integer( + yr_le32toh(dex_header->proto_ids_size), + module_object, + "header.proto_ids_size"); + set_integer( + yr_le32toh(dex_header->proto_ids_offset), + module_object, + "header.proto_ids_offset"); + set_integer( + yr_le32toh(dex_header->field_ids_size), + module_object, + "header.field_ids_size"); + set_integer( + yr_le32toh(dex_header->field_ids_offset), + module_object, + "header.field_ids_offset"); + set_integer( + yr_le32toh(dex_header->method_ids_size), + module_object, + "header.method_ids_size"); + set_integer( + yr_le32toh(dex_header->method_ids_offset), + module_object, + "header.method_ids_offset"); + set_integer( + yr_le32toh(dex_header->class_defs_size), + module_object, + "header.class_defs_size"); + set_integer( + yr_le32toh(dex_header->class_defs_offset), + module_object, + "header.class_defs_offset"); + set_integer( + yr_le32toh(dex_header->data_size), module_object, "header.data_size"); + set_integer( + yr_le32toh(dex_header->data_offset), module_object, "header.data_offset"); } uint32_t load_encoded_field( DEX* dex, size_t start_offset, - uint32_t *previous_field_idx, + uint32_t* previous_field_idx, int index_encoded_field, int static_field, int instance_field) { - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] Parse encoded field start_offset:0x%zx\n", start_offset); - #endif +#endif if (!fits_in_dex(dex, dex->data + start_offset, sizeof(uint32_t) * 2)) return 0; @@ -414,30 +444,26 @@ uint32_t load_encoded_field( set_integer( encoded_field.access_flags, - dex->object, + dex->object, "field[%i].access_flags", index_encoded_field); set_integer( - static_field, - dex->object, - "field[%i].static", - index_encoded_field); + static_field, dex->object, "field[%i].static", index_encoded_field); set_integer( - instance_field, - dex->object, - "field[%i].instance", - index_encoded_field); + instance_field, dex->object, "field[%i].instance", index_encoded_field); *previous_field_idx = encoded_field.field_idx_diff + *previous_field_idx; - #ifdef DEBUG_DEX_MODULE - printf("[DEX]\tEncoded field field_idx:0x%x field_idx_diff:0x%x access_flags:0x%x\n", +#ifdef DEBUG_DEX_MODULE + printf( + "[DEX]\tEncoded field field_idx:0x%x field_idx_diff:0x%x " + "access_flags:0x%x\n", *previous_field_idx, encoded_field.field_idx_diff, encoded_field.access_flags); - #endif +#endif int64_t name_idx = dex_get_integer( dex->object, "field_ids[%i].name_idx", *previous_field_idx); @@ -450,11 +476,10 @@ uint32_t load_encoded_field( if (field_name != NULL) { - #ifdef DEBUG_DEX_MODULE - printf("[DEX]\tFIELD_NAME %s NAME_IDX 0x%x\n", - field_name->c_string, - name_idx); - #endif +#ifdef DEBUG_DEX_MODULE + printf( + "[DEX]\tFIELD_NAME %s NAME_IDX 0x%x\n", field_name->c_string, name_idx); +#endif set_sized_string( field_name->c_string, @@ -475,12 +500,13 @@ uint32_t load_encoded_field( if (class_name != NULL) { - #ifdef DEBUG_DEX_MODULE - printf("[DEX]\tCLASS_NAME %s CLASS_IDX 0x%x DESCRIPTOR_IDX 0x%x\n", +#ifdef DEBUG_DEX_MODULE + printf( + "[DEX]\tCLASS_NAME %s CLASS_IDX 0x%x DESCRIPTOR_IDX 0x%x\n", class_name->c_string, class_idx, descriptor_idx); - #endif +#endif set_sized_string( class_name->c_string, @@ -490,23 +516,24 @@ uint32_t load_encoded_field( index_encoded_field); } - int type_idx = dex_get_integer(dex->object, - "field_ids[%i].type_idx", *previous_field_idx); + int type_idx = dex_get_integer( + dex->object, "field_ids[%i].type_idx", *previous_field_idx); - int shorty_idx = dex_get_integer(dex->object, - "type_ids[%i].descriptor_idx", type_idx); + int shorty_idx = dex_get_integer( + dex->object, "type_ids[%i].descriptor_idx", type_idx); - SIZED_STRING* proto_name = dex_get_string(dex->object, - "string_ids[%i].value", shorty_idx); + SIZED_STRING* proto_name = dex_get_string( + dex->object, "string_ids[%i].value", shorty_idx); if (proto_name != NULL) { - #ifdef DEBUG_DEX_MODULE - printf("[DEX]\tPROTO_NAME %s TYPE_IDX 0x%x SHORTY_IDX 0x%x\n", +#ifdef DEBUG_DEX_MODULE + printf( + "[DEX]\tPROTO_NAME %s TYPE_IDX 0x%x SHORTY_IDX 0x%x\n", proto_name->c_string, type_idx, shorty_idx); - #endif +#endif set_sized_string( proto_name->c_string, @@ -523,14 +550,14 @@ uint32_t load_encoded_field( uint32_t load_encoded_method( DEX* dex, size_t start_offset, - uint32_t *previous_method_idx, + uint32_t* previous_method_idx, int index_encoded_method, int direct_method, int virtual_method) { - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] Parse encoded method start_offset:0x%zx\n", start_offset); - #endif +#endif if (!fits_in_dex(dex, dex->data + start_offset, sizeof(uint32_t) * 3)) return 0; @@ -566,16 +593,10 @@ uint32_t load_encoded_method( index_encoded_method); set_integer( - direct_method, - dex->object, - "method[%i].direct", - index_encoded_method); + direct_method, dex->object, "method[%i].direct", index_encoded_method); set_integer( - virtual_method, - dex->object, - "method[%i].virtual", - index_encoded_method); + virtual_method, dex->object, "method[%i].virtual", index_encoded_method); *previous_method_idx = encoded_method.method_idx_diff + *previous_method_idx; @@ -585,28 +606,31 @@ uint32_t load_encoded_method( if (name_idx == YR_UNDEFINED) return 0; - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX]\tNAME_IDX 0x%x\n", name_idx); - #endif +#endif - #ifdef DEBUG_DEX_MODULE - printf("[DEX]\tEncoded method method_idx:0x%x method_idx_diff:0x%x access_flags:0x%x code_off:0x%x\n", +#ifdef DEBUG_DEX_MODULE + printf( + "[DEX]\tEncoded method method_idx:0x%x method_idx_diff:0x%x " + "access_flags:0x%x code_off:0x%x\n", *previous_method_idx, encoded_method.method_idx_diff, encoded_method.access_flags, encoded_method.code_off); - #endif +#endif SIZED_STRING* method_name = dex_get_string( - dex->object, "string_ids[%i].value", name_idx); + dex->object, "string_ids[%i].value", name_idx); if (method_name != NULL) { - #ifdef DEBUG_DEX_MODULE - printf("[DEX]\tMETHOD_NAME %s NAME_IDX 0x%x\n", +#ifdef DEBUG_DEX_MODULE + printf( + "[DEX]\tMETHOD_NAME %s NAME_IDX 0x%x\n", method_name->c_string, name_idx); - #endif +#endif set_sized_string( method_name->c_string, @@ -627,12 +651,13 @@ uint32_t load_encoded_method( if (class_name != NULL) { - #ifdef DEBUG_DEX_MODULE - printf("[DEX]\tCLASS_NAME %s CLASS_IDX 0x%x DESCRIPTOR_IDX:0x%x\n", +#ifdef DEBUG_DEX_MODULE + printf( + "[DEX]\tCLASS_NAME %s CLASS_IDX 0x%x DESCRIPTOR_IDX:0x%x\n", class_name->c_string, class_idx, descriptor_idx); - #endif +#endif set_sized_string( class_name->c_string, @@ -653,54 +678,76 @@ uint32_t load_encoded_method( if (proto_name != NULL) { - #ifdef DEBUG_DEX_MODULE - printf("[DEX]\tPROTO_NAME %s CLASS_IDX 0x%x DESCRIPTOR_IDX:0x%x\n", +#ifdef DEBUG_DEX_MODULE + printf( + "[DEX]\tPROTO_NAME %s CLASS_IDX 0x%x DESCRIPTOR_IDX:0x%x\n", proto_name->c_string, class_idx, descriptor_idx); - #endif +#endif set_sized_string( proto_name->c_string, - proto_name->length, dex->object, + proto_name->length, + dex->object, "method[%i].proto", index_encoded_method); } if (encoded_method.code_off != 0) { - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX]\t\tParse CODE item\n"); - #endif +#endif if (struct_fits_in_dex( - dex, dex->data + encoded_method.code_off, sizeof(code_item_t))) + dex, dex->data + encoded_method.code_off, sizeof(code_item_t))) { - code_item_t* code_item = (code_item_t*) ( - dex->data + encoded_method.code_off); - - set_integer(code_item->registers_size, dex->object, - "method[%i].code_item.registers_size", index_encoded_method); - set_integer(code_item->ins_size, dex->object, - "method[%i].code_item.ins_size", index_encoded_method); - set_integer(code_item->outs_size, dex->object, - "method[%i].code_item.outs_size", index_encoded_method); - set_integer(code_item->tries_size, dex->object, - "method[%i].code_item.tries_size", index_encoded_method); - set_integer(code_item->debug_info_off, dex->object, - "method[%i].code_item.debug_info_off", index_encoded_method); - set_integer(code_item->insns_size, dex->object, - "method[%i].code_item.insns_size", index_encoded_method); + code_item_t* code_item = + (code_item_t*) (dex->data + encoded_method.code_off); + + set_integer( + code_item->registers_size, + dex->object, + "method[%i].code_item.registers_size", + index_encoded_method); + set_integer( + code_item->ins_size, + dex->object, + "method[%i].code_item.ins_size", + index_encoded_method); + set_integer( + code_item->outs_size, + dex->object, + "method[%i].code_item.outs_size", + index_encoded_method); + set_integer( + code_item->tries_size, + dex->object, + "method[%i].code_item.tries_size", + index_encoded_method); + set_integer( + code_item->debug_info_off, + dex->object, + "method[%i].code_item.debug_info_off", + index_encoded_method); + set_integer( + code_item->insns_size, + dex->object, + "method[%i].code_item.insns_size", + index_encoded_method); if (fits_in_dex( - dex, - dex->data + encoded_method.code_off + sizeof(code_item_t), - code_item->insns_size * 2)) + dex, + dex->data + encoded_method.code_off + sizeof(code_item_t), + code_item->insns_size * 2)) { set_sized_string( - (const char *)(dex->data + encoded_method.code_off + sizeof(code_item_t)), - code_item->insns_size * 2, - dex->object, "method[%i].code_item.insns", index_encoded_method); + (const char*) (dex->data + encoded_method.code_off + sizeof(code_item_t)), + code_item->insns_size * 2, + dex->object, + "method[%i].code_item.insns", + index_encoded_method); } } } @@ -709,9 +756,7 @@ uint32_t load_encoded_method( } -void dex_parse( - DEX* dex, - uint64_t base_address) +void dex_parse(DEX* dex, uint64_t base_address) { dex_header_t* dex_header; @@ -731,55 +776,58 @@ void dex_parse( dex_header = dex->header; if (!fits_in_dex( - dex, dex->data + yr_le32toh(dex_header->string_ids_offset), - yr_le32toh(dex_header->string_ids_size) * sizeof(string_id_item_t))) + dex, + dex->data + yr_le32toh(dex_header->string_ids_offset), + yr_le32toh(dex_header->string_ids_size) * sizeof(string_id_item_t))) return; - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] Parse STRING ID section\n"); - #endif +#endif // Get information about the String ID section for (i = 0; i < yr_le32toh(dex_header->string_ids_size); i++) { - string_id_item_t* string_id_item = (string_id_item_t*) ( - dex->data + - yr_le32toh(dex_header->string_ids_offset) + - i * sizeof(string_id_item_t)); + string_id_item_t* string_id_item = + (string_id_item_t*) (dex->data + yr_le32toh(dex_header->string_ids_offset) + i * sizeof(string_id_item_t)); - #ifdef DEBUG_DEX_MODULE - printf("[DEX] STRING ID item data_offset:0x%x\n", +#ifdef DEBUG_DEX_MODULE + printf( + "[DEX] STRING ID item data_offset:0x%x\n", yr_le32toh(string_id_item->string_data_offset)); - #endif +#endif if (!fits_in_dex( - dex, dex->data + yr_le32toh(string_id_item->string_data_offset), - sizeof(uint32_t))) + dex, + dex->data + yr_le32toh(string_id_item->string_data_offset), + sizeof(uint32_t))) continue; uint32_t value = (uint32_t) read_uleb128( (dex->data + yr_le32toh(string_id_item->string_data_offset)), &uleb128_size); - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] STRING ID item size:0x%x\n", value); - #endif +#endif if (!fits_in_dex( - dex, dex->data + yr_le32toh(string_id_item->string_data_offset), - value)) + dex, + dex->data + yr_le32toh(string_id_item->string_data_offset), + value)) continue; set_integer( - yr_le32toh(string_id_item->string_data_offset), dex->object, - "string_ids[%i].offset", i); + yr_le32toh(string_id_item->string_data_offset), + dex->object, + "string_ids[%i].offset", + i); - set_integer( - value, dex->object, - "string_ids[%i].size", i); + set_integer(value, dex->object, "string_ids[%i].size", i); set_sized_string( - (const char*) ((dex->data + yr_le32toh(string_id_item->string_data_offset) + 1)), + (const char*) (( + dex->data + yr_le32toh(string_id_item->string_data_offset) + 1)), value, dex->object, "string_ids[%i].value", @@ -787,21 +835,20 @@ void dex_parse( } if (!fits_in_dex( - dex, dex->data + yr_le32toh(dex_header->type_ids_offset), - yr_le32toh(dex_header->type_ids_size) * sizeof(type_id_item_t))) + dex, + dex->data + yr_le32toh(dex_header->type_ids_offset), + yr_le32toh(dex_header->type_ids_size) * sizeof(type_id_item_t))) return; - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] Parse TYPE ID section\n"); - #endif +#endif // Get information about the Type ID section for (i = 0; i < yr_le32toh(dex_header->type_ids_size); i++) { - type_id_item_t* type_id_item = (type_id_item_t*) ( - dex->data + - yr_le32toh(dex_header->type_ids_offset) + - i * sizeof(type_id_item_t)); + type_id_item_t* type_id_item = + (type_id_item_t*) (dex->data + yr_le32toh(dex_header->type_ids_offset) + i * sizeof(type_id_item_t)); set_integer( yr_le32toh(type_id_item->descriptor_idx), @@ -811,173 +858,235 @@ void dex_parse( } if (!fits_in_dex( - dex, dex->data + yr_le32toh(dex_header->proto_ids_offset), - yr_le32toh(dex_header->proto_ids_size) * sizeof(proto_id_item_t))) + dex, + dex->data + yr_le32toh(dex_header->proto_ids_offset), + yr_le32toh(dex_header->proto_ids_size) * sizeof(proto_id_item_t))) return; - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] Parse PROTO ID section\n"); - #endif +#endif // Get information about the Proto ID section for (i = 0; i < yr_le32toh(dex_header->proto_ids_size); i++) { - proto_id_item_t* proto_id_item = (proto_id_item_t*) ( - dex->data + - yr_le32toh(dex_header->proto_ids_offset) + - i * sizeof(proto_id_item_t)); - - set_integer(yr_le32toh(proto_id_item->shorty_idx), dex->object, - "proto_ids[%i].shorty_idx", i); - set_integer(yr_le32toh(proto_id_item->return_type_idx), dex->object, - "proto_ids[%i].return_type_idx", i); - set_integer(yr_le32toh(proto_id_item->parameters_offset), dex->object, - "proto_ids[%i].parameters_offset", i); + proto_id_item_t* proto_id_item = + (proto_id_item_t*) (dex->data + yr_le32toh(dex_header->proto_ids_offset) + i * sizeof(proto_id_item_t)); + + set_integer( + yr_le32toh(proto_id_item->shorty_idx), + dex->object, + "proto_ids[%i].shorty_idx", + i); + set_integer( + yr_le32toh(proto_id_item->return_type_idx), + dex->object, + "proto_ids[%i].return_type_idx", + i); + set_integer( + yr_le32toh(proto_id_item->parameters_offset), + dex->object, + "proto_ids[%i].parameters_offset", + i); } if (!fits_in_dex( - dex, dex->data + yr_le32toh(dex_header->field_ids_offset), - yr_le32toh(dex_header->field_ids_size) * sizeof(field_id_item_t))) + dex, + dex->data + yr_le32toh(dex_header->field_ids_offset), + yr_le32toh(dex_header->field_ids_size) * sizeof(field_id_item_t))) return; - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] Parse FIELD ID section\n"); - #endif +#endif // Get information about the Field ID section for (i = 0; i < yr_le32toh(dex_header->field_ids_size); i++) { - field_id_item_t* field_id_item = (field_id_item_t*) ( - dex->data + - yr_le32toh(dex_header->field_ids_offset) + - i * sizeof(field_id_item_t)); - - set_integer(yr_le16toh(field_id_item->class_idx), dex->object, - "field_ids[%i].class_idx", i); - set_integer(yr_le16toh(field_id_item->type_idx), dex->object, - "field_ids[%i].type_idx", i); - set_integer(yr_le32toh(field_id_item->name_idx), dex->object, - "field_ids[%i].name_idx", i); + field_id_item_t* field_id_item = + (field_id_item_t*) (dex->data + yr_le32toh(dex_header->field_ids_offset) + i * sizeof(field_id_item_t)); + + set_integer( + yr_le16toh(field_id_item->class_idx), + dex->object, + "field_ids[%i].class_idx", + i); + set_integer( + yr_le16toh(field_id_item->type_idx), + dex->object, + "field_ids[%i].type_idx", + i); + set_integer( + yr_le32toh(field_id_item->name_idx), + dex->object, + "field_ids[%i].name_idx", + i); } if (!fits_in_dex( - dex, dex->data + yr_le32toh(dex_header->method_ids_offset), - yr_le32toh(dex_header->method_ids_size) * sizeof(method_id_item_t))) + dex, + dex->data + yr_le32toh(dex_header->method_ids_offset), + yr_le32toh(dex_header->method_ids_size) * sizeof(method_id_item_t))) return; - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] Parse METHOD ID section\n"); - #endif +#endif // Get information about the Method ID section for (i = 0; i < yr_le32toh(dex_header->method_ids_size); i++) { - method_id_item_t* method_id_item = (method_id_item_t*) ( - dex->data + - yr_le32toh(dex_header->method_ids_offset) + - i * sizeof(method_id_item_t)); - - set_integer(yr_le16toh(method_id_item->class_idx), dex->object, - "method_ids[%i].class_idx", i); - set_integer(yr_le16toh(method_id_item->proto_idx), dex->object, - "method_ids[%i].proto_idx", i); - set_integer(yr_le32toh(method_id_item->name_idx), dex->object, - "method_ids[%i].name_idx", i); + method_id_item_t* method_id_item = + (method_id_item_t*) (dex->data + yr_le32toh(dex_header->method_ids_offset) + i * sizeof(method_id_item_t)); + + set_integer( + yr_le16toh(method_id_item->class_idx), + dex->object, + "method_ids[%i].class_idx", + i); + set_integer( + yr_le16toh(method_id_item->proto_idx), + dex->object, + "method_ids[%i].proto_idx", + i); + set_integer( + yr_le32toh(method_id_item->name_idx), + dex->object, + "method_ids[%i].name_idx", + i); } - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] Parse MAP List ID section\n"); - #endif +#endif // Get information about the Map List ID section if (yr_le32toh(dex_header->map_offset) != 0 && - fits_in_dex(dex, dex->data + yr_le32toh(dex_header->map_offset), sizeof(uint32_t))) + fits_in_dex( + dex, + dex->data + yr_le32toh(dex_header->map_offset), + sizeof(uint32_t))) { - uint32_t* map_list_size = (uint32_t *) ( - dex->data + yr_le32toh(dex_header->map_offset)); + uint32_t* map_list_size = + (uint32_t*) (dex->data + yr_le32toh(dex_header->map_offset)); set_integer(yr_le32toh(*map_list_size), dex->object, "map_list.size"); if (!fits_in_dex( - dex, dex->data + yr_le32toh(dex_header->map_offset), - sizeof(uint32_t) + yr_le32toh(*map_list_size) * sizeof(map_item_t))) + dex, + dex->data + yr_le32toh(dex_header->map_offset), + sizeof(uint32_t) + yr_le32toh(*map_list_size) * sizeof(map_item_t))) return; for (i = 0; i < yr_le32toh(*map_list_size); i++) { - map_item_t* map_item = (map_item_t*) ( - dex->data + - yr_le32toh(dex_header->map_offset) + - sizeof(uint32_t) + - i * sizeof(map_item_t)); - - set_integer(yr_le16toh(map_item->type), dex->object, - "map_list.map_item[%i].type", i); - set_integer(yr_le16toh(map_item->unused), dex->object, - "map_list.map_item[%i].unused", i); - set_integer(yr_le32toh(map_item->size), dex->object, - "map_list.map_item[%i].size", i); - set_integer(yr_le32toh(map_item->offset), dex->object, - "map_list.map_item[%i].offset", i); + map_item_t* map_item = + (map_item_t*) (dex->data + yr_le32toh(dex_header->map_offset) + sizeof(uint32_t) + i * sizeof(map_item_t)); + + set_integer( + yr_le16toh(map_item->type), + dex->object, + "map_list.map_item[%i].type", + i); + set_integer( + yr_le16toh(map_item->unused), + dex->object, + "map_list.map_item[%i].unused", + i); + set_integer( + yr_le32toh(map_item->size), + dex->object, + "map_list.map_item[%i].size", + i); + set_integer( + yr_le32toh(map_item->offset), + dex->object, + "map_list.map_item[%i].offset", + i); } } if (!fits_in_dex( - dex, dex->data + yr_le32toh(dex_header->class_defs_offset), - yr_le32toh(dex_header->class_defs_size) * sizeof(class_id_item_t))) + dex, + dex->data + yr_le32toh(dex_header->class_defs_offset), + yr_le32toh(dex_header->class_defs_size) * sizeof(class_id_item_t))) return; - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] Parse CLASS ID section\n"); - #endif +#endif // Get information about the Class ID section for (i = 0; i < yr_le32toh(dex_header->class_defs_size); i++) { - class_id_item_t* class_id_item = (class_id_item_t*) ( - dex->data + - yr_le32toh(dex_header->class_defs_offset) + - i * sizeof(class_id_item_t)); - - #ifdef DEBUG_DEX_MODULE - printf("[DEX] CLASS ID item class_idx:0x%x access_flags:0x%x " \ - "super_class_idx:0x%x interfaces_offset:0x%x source_file_idx:0x%x "\ - "annotations_offset:0x%x class_data_offset:0x%x "\ - "static_values_offset:0x%x\n", - yr_le32toh(class_id_item->class_idx), - yr_le32toh(class_id_item->access_flags), - yr_le32toh(class_id_item->super_class_idx), - yr_le32toh(class_id_item->interfaces_offset), - yr_le32toh(class_id_item->source_file_idx), - yr_le32toh(class_id_item->annotations_offset), - yr_le32toh(class_id_item->class_data_offset), - yr_le32toh(class_id_item->static_values_offset)); - #endif - - set_integer(yr_le32toh(class_id_item->class_idx), dex->object, - "class_defs[%i].class_idx", i); - set_integer(yr_le32toh(class_id_item->access_flags), dex->object, - "class_defs[%i].access_flags", i); - set_integer(yr_le32toh(class_id_item->super_class_idx), dex->object, - "class_defs[%i].super_class_idx", i); - set_integer(yr_le32toh(class_id_item->interfaces_offset), dex->object, - "class_defs[%i].interfaces_offset", i); - set_integer(yr_le32toh(class_id_item->source_file_idx), dex->object, - "class_defs[%i].source_file_idx", i); - set_integer(yr_le32toh(class_id_item->annotations_offset), dex->object, - "class_defs[%i].annotations_offset", i); - set_integer(yr_le32toh(class_id_item->class_data_offset), dex->object, - "class_defs[%i].class_data_offset", i); - set_integer(yr_le32toh(class_id_item->static_values_offset), dex->object, - "class_defs[%i].static_values_offset", i); + class_id_item_t* class_id_item = + (class_id_item_t*) (dex->data + yr_le32toh(dex_header->class_defs_offset) + i * sizeof(class_id_item_t)); + +#ifdef DEBUG_DEX_MODULE + printf( + "[DEX] CLASS ID item class_idx:0x%x access_flags:0x%x " + "super_class_idx:0x%x interfaces_offset:0x%x source_file_idx:0x%x " + "annotations_offset:0x%x class_data_offset:0x%x " + "static_values_offset:0x%x\n", + yr_le32toh(class_id_item->class_idx), + yr_le32toh(class_id_item->access_flags), + yr_le32toh(class_id_item->super_class_idx), + yr_le32toh(class_id_item->interfaces_offset), + yr_le32toh(class_id_item->source_file_idx), + yr_le32toh(class_id_item->annotations_offset), + yr_le32toh(class_id_item->class_data_offset), + yr_le32toh(class_id_item->static_values_offset)); +#endif + + set_integer( + yr_le32toh(class_id_item->class_idx), + dex->object, + "class_defs[%i].class_idx", + i); + set_integer( + yr_le32toh(class_id_item->access_flags), + dex->object, + "class_defs[%i].access_flags", + i); + set_integer( + yr_le32toh(class_id_item->super_class_idx), + dex->object, + "class_defs[%i].super_class_idx", + i); + set_integer( + yr_le32toh(class_id_item->interfaces_offset), + dex->object, + "class_defs[%i].interfaces_offset", + i); + set_integer( + yr_le32toh(class_id_item->source_file_idx), + dex->object, + "class_defs[%i].source_file_idx", + i); + set_integer( + yr_le32toh(class_id_item->annotations_offset), + dex->object, + "class_defs[%i].annotations_offset", + i); + set_integer( + yr_le32toh(class_id_item->class_data_offset), + dex->object, + "class_defs[%i].class_data_offset", + i); + set_integer( + yr_le32toh(class_id_item->static_values_offset), + dex->object, + "class_defs[%i].static_values_offset", + i); if (yr_le32toh(class_id_item->class_data_offset) != 0) { class_data_item_t class_data_item; if (!fits_in_dex( - dex, dex->data + yr_le32toh(class_id_item->class_data_offset), - 4 * sizeof(uint32_t))) + dex, + dex->data + yr_le32toh(class_id_item->class_data_offset), + 4 * sizeof(uint32_t))) return; uleb128_size = 0; @@ -987,36 +1096,47 @@ void dex_parse( &uleb128_size); class_data_item.instance_fields_size = (uint32_t) read_uleb128( - (dex->data + yr_le32toh(class_id_item->class_data_offset) + uleb128_size), + (dex->data + yr_le32toh(class_id_item->class_data_offset) + + uleb128_size), &uleb128_size); class_data_item.direct_methods_size = (uint32_t) read_uleb128( - (dex->data + yr_le32toh(class_id_item->class_data_offset) + uleb128_size), + (dex->data + yr_le32toh(class_id_item->class_data_offset) + + uleb128_size), &uleb128_size); class_data_item.virtual_methods_size = (uint32_t) read_uleb128( - (dex->data + yr_le32toh(class_id_item->class_data_offset) + uleb128_size), + (dex->data + yr_le32toh(class_id_item->class_data_offset) + + uleb128_size), &uleb128_size); set_integer( - class_data_item.static_fields_size, dex->object, - "class_data_item[%i].static_fields_size", index_class_data_item); + class_data_item.static_fields_size, + dex->object, + "class_data_item[%i].static_fields_size", + index_class_data_item); set_integer( - class_data_item.instance_fields_size, dex->object, - "class_data_item[%i].instance_fields_size", index_class_data_item); + class_data_item.instance_fields_size, + dex->object, + "class_data_item[%i].instance_fields_size", + index_class_data_item); set_integer( - class_data_item.direct_methods_size, dex->object, - "class_data_item[%i].direct_methods_size", index_class_data_item); + class_data_item.direct_methods_size, + dex->object, + "class_data_item[%i].direct_methods_size", + index_class_data_item); set_integer( - class_data_item.virtual_methods_size, dex->object, - "class_data_item[%i].virtual_methods_size", index_class_data_item); + class_data_item.virtual_methods_size, + dex->object, + "class_data_item[%i].virtual_methods_size", + index_class_data_item); - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] CLASS DATA item static fields\n"); - #endif +#endif uint32_t previous_field_idx = 0; for (j = 0; j < class_data_item.static_fields_size; j++) @@ -1026,7 +1146,8 @@ void dex_parse( yr_le32toh(class_id_item->class_data_offset) + uleb128_size, &previous_field_idx, index_encoded_field, - 1,0); + 1, + 0); // If the current field isn't parsed the other fields aren't likely to // parse. @@ -1037,9 +1158,9 @@ void dex_parse( index_encoded_field += 1; } - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] CLASS DATA item instance fields\n"); - #endif +#endif previous_field_idx = 0; @@ -1050,7 +1171,8 @@ void dex_parse( yr_le32toh(class_id_item->class_data_offset) + uleb128_size, &previous_field_idx, index_encoded_field, - 0, 1); + 0, + 1); // If the current field isn't parsed the other fields aren't likely to // parse. @@ -1061,9 +1183,9 @@ void dex_parse( index_encoded_field += 1; } - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] CLASS DATA item direct methods\n"); - #endif +#endif uint32_t previous_method_idx = 0; @@ -1074,7 +1196,8 @@ void dex_parse( yr_le32toh(class_id_item->class_data_offset) + uleb128_size, &previous_method_idx, index_encoded_method, - 1, 0); + 1, + 0); // If the current field isn't parsed the other fields aren't likely to // parse. @@ -1085,9 +1208,9 @@ void dex_parse( index_encoded_method += 1; } - #ifdef DEBUG_DEX_MODULE +#ifdef DEBUG_DEX_MODULE printf("[DEX] CLASS DATA item virtual methods\n"); - #endif +#endif previous_method_idx = 0; @@ -1098,7 +1221,8 @@ void dex_parse( yr_le32toh(class_id_item->class_data_offset) + uleb128_size, &previous_method_idx, index_encoded_method, - 0, 1); + 0, + 1); // If the current field isn't parsed the other fields aren't likely to // parse. diff --git a/libyara/modules/dotnet/dotnet.c b/libyara/modules/dotnet/dotnet.c index 24587087b1..4ea181b16d 100644 --- a/libyara/modules/dotnet/dotnet.c +++ b/libyara/modules/dotnet/dotnet.c @@ -14,18 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -#include -#include + #include +#include +#include #include - -#include #include -#include #include -#include - +#include +#include #include +#include #define MODULE_NAME dotnet @@ -92,18 +91,20 @@ void dotnet_parse_guid( char guid[37]; int i = 0; - const uint8_t* guid_offset = pe->data + \ - metadata_root + yr_le32toh(guid_header->Offset); + const uint8_t* guid_offset = pe->data + metadata_root + + yr_le32toh(guid_header->Offset); DWORD guid_size = yr_le32toh(guid_header->Size); // Limit the number of GUIDs to 16. - guid_size = yr_min(guid_size, 256); + guid_size = yr_min(guid_size, 256); // Parse GUIDs if we have them. GUIDs are 16 bytes each. while (guid_size >= 16 && fits_in_pe(pe, guid_offset, 16)) { - sprintf(guid, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + sprintf( + guid, + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", yr_le32toh(*(uint32_t*) guid_offset), yr_le16toh(*(uint16_t*) (guid_offset + 4)), yr_le16toh(*(uint16_t*) (guid_offset + 6)), @@ -131,9 +132,7 @@ void dotnet_parse_guid( // Given an offset into a #US or #Blob stream, parse the entry at that position. // The offset is relative to the start of the PE file. -BLOB_PARSE_RESULT dotnet_parse_blob_entry( - PE* pe, - const uint8_t* offset) +BLOB_PARSE_RESULT dotnet_parse_blob_entry(PE* pe, const uint8_t* offset) { BLOB_PARSE_RESULT result; @@ -184,10 +183,8 @@ BLOB_PARSE_RESULT dotnet_parse_blob_entry( return result; } - result.length = ((*offset & 0x1F) << 24) | - (*(offset + 1) << 16) | - (*(offset + 2) << 8) | - *(offset + 3); + result.length = ((*offset & 0x1F) << 24) | (*(offset + 1) << 16) | + (*(offset + 2) << 8) | *(offset + 3); result.size = 4; } else @@ -207,17 +204,15 @@ BLOB_PARSE_RESULT dotnet_parse_blob_entry( } -void dotnet_parse_us( - PE* pe, - int64_t metadata_root, - PSTREAM_HEADER us_header) +void dotnet_parse_us(PE* pe, int64_t metadata_root, PSTREAM_HEADER us_header) { BLOB_PARSE_RESULT blob_result; int i = 0; const uint32_t ush_sz = yr_le32toh(us_header->Size); - const uint8_t* offset = pe->data + metadata_root + yr_le32toh(us_header->Offset); + const uint8_t* offset = pe->data + metadata_root + + yr_le32toh(us_header->Offset); const uint8_t* end_of_header = offset + ush_sz; // Make sure the header size is larger than 0 and its end is not past the @@ -245,11 +240,11 @@ void dotnet_parse_us( if (blob_result.length > 0 && fits_in_pe(pe, offset, blob_result.length)) { set_sized_string( - (char*) offset, - blob_result.length, - pe->object, - "user_strings[%i]", - i); + (char*) offset, + blob_result.length, + pe->object, + "user_strings[%i]", + i); offset += blob_result.length; i++; @@ -269,14 +264,14 @@ STREAMS dotnet_parse_stream_headers( PSTREAM_HEADER stream_header; STREAMS headers; - char *start; - char *eos; + char* start; + char* eos; char stream_name[DOTNET_STREAM_NAME_SIZE + 1]; unsigned int i; memset(&headers, '\0', sizeof(STREAMS)); - stream_header = (PSTREAM_HEADER) (pe->data + offset); + stream_header = (PSTREAM_HEADER)(pe->data + offset); for (i = 0; i < num_streams; i++) { @@ -296,13 +291,15 @@ STREAMS dotnet_parse_stream_headers( strncpy(stream_name, stream_header->Name, DOTNET_STREAM_NAME_SIZE); stream_name[DOTNET_STREAM_NAME_SIZE] = '\0'; - set_string(stream_name, - pe->object, "streams[%i].name", i); + set_string(stream_name, pe->object, "streams[%i].name", i); // Offset is relative to metadata_root. - set_integer(metadata_root + yr_le32toh(stream_header->Offset), - pe->object, "streams[%i].offset", i); - set_integer(yr_le32toh(stream_header->Size), - pe->object, "streams[%i].size", i); + set_integer( + metadata_root + yr_le32toh(stream_header->Offset), + pe->object, + "streams[%i].offset", + i); + set_integer( + yr_le32toh(stream_header->Size), pe->object, "streams[%i].size", i); // Store necessary bits to parse these later. Not all tables will be // parsed, but are referenced from others. For example, the #Strings @@ -314,7 +311,8 @@ STREAMS dotnet_parse_stream_headers( // tables and they do not interfere with anything we parse in this module. if ((strncmp(stream_name, "#~", 2) == 0 || - strncmp(stream_name, "#-", 2) == 0) && headers.tilde == NULL) + strncmp(stream_name, "#-", 2) == 0) && + headers.tilde == NULL) headers.tilde = stream_header; else if (strncmp(stream_name, "#GUID", 5) == 0) headers.guid = stream_header; @@ -326,9 +324,8 @@ STREAMS dotnet_parse_stream_headers( headers.us = stream_header; // Stream name is padded to a multiple of 4. - stream_header = (PSTREAM_HEADER) ((uint8_t*) stream_header + - sizeof(STREAM_HEADER) + - strlen(stream_name) + + stream_header = (PSTREAM_HEADER)( + (uint8_t*) stream_header + sizeof(STREAM_HEADER) + strlen(stream_name) + 4 - (strlen(stream_name) % 4)); } @@ -367,7 +364,7 @@ void dotnet_parse_tilde_2( PCONSTANT_TABLE constant_table; DWORD resource_size, implementation; - char *name; + char* name; char typelib[MAX_TYPELIB_SIZE + 1]; unsigned int i; int bit_check; @@ -432,10 +429,12 @@ void dotnet_parse_tilde_2( table_offset = (uint8_t*) row_offset; table_offset += sizeof(uint32_t) * valid_rows; -#define DOTNET_STRING_INDEX(Name) \ - index_sizes.string == 2 ? yr_le16toh(Name.Name_Short) : yr_le32toh(Name.Name_Long) +#define DOTNET_STRING_INDEX(Name) \ + index_sizes.string == 2 ? yr_le16toh(Name.Name_Short) \ + : yr_le32toh(Name.Name_Long) - string_offset = pe->data + metadata_root + yr_le32toh(streams->string->Offset); + string_offset = pe->data + metadata_root + + yr_le32toh(streams->string->Offset); // Now walk again this time parsing out what we care about. for (bit_check = 0; bit_check < 64; bit_check++) @@ -464,129 +463,237 @@ void dotnet_parse_tilde_2( switch (bit_check) { - case BIT_MODULE: - module_table = (PMODULE_TABLE) table_offset; + case BIT_MODULE: + module_table = (PMODULE_TABLE) table_offset; - name = pe_get_dotnet_string(pe, - string_offset, - DOTNET_STRING_INDEX(module_table->Name)); + name = pe_get_dotnet_string( + pe, string_offset, DOTNET_STRING_INDEX(module_table->Name)); - if (name != NULL) - set_string(name, pe->object, "module_name"); + if (name != NULL) + set_string(name, pe->object, "module_name"); - table_offset += ( - 2 + index_sizes.string + (index_sizes.guid * 3)) * num_rows; + table_offset += (2 + index_sizes.string + (index_sizes.guid * 3)) * + num_rows; - break; + break; - case BIT_TYPEREF: - row_count = max_rows(4, - yr_le32toh(rows.module), - yr_le32toh(rows.moduleref), - yr_le32toh(rows.assemblyref), - yr_le32toh(rows.typeref)); + case BIT_TYPEREF: + row_count = max_rows( + 4, + yr_le32toh(rows.module), + yr_le32toh(rows.moduleref), + yr_le32toh(rows.assemblyref), + yr_le32toh(rows.typeref)); + + if (row_count > (0xFFFF >> 0x02)) + index_size = 4; + else + index_size = 2; + + row_size = (index_size + (index_sizes.string * 2)); + typeref_row_size = row_size; + typeref_ptr = table_offset; + table_offset += row_size * num_rows; + break; - if (row_count > (0xFFFF >> 0x02)) - index_size = 4; - else - index_size = 2; + case BIT_TYPEDEF: + row_count = max_rows( + 3, + yr_le32toh(rows.typedef_), + yr_le32toh(rows.typeref), + yr_le32toh(rows.typespec)); + + if (row_count > (0xFFFF >> 0x02)) + index_size = 4; + else + index_size = 2; + + table_offset += (4 + (index_sizes.string * 2) + index_size + + index_sizes.field + index_sizes.methoddef) * + num_rows; + break; - row_size = (index_size + (index_sizes.string * 2)); - typeref_row_size = row_size; - typeref_ptr = table_offset; - table_offset += row_size * num_rows; - break; + case BIT_FIELDPTR: + // This one is not documented in ECMA-335. + table_offset += (index_sizes.field) * num_rows; + break; - case BIT_TYPEDEF: - row_count = max_rows(3, - yr_le32toh(rows.typedef_), - yr_le32toh(rows.typeref), - yr_le32toh(rows.typespec)); + case BIT_FIELD: + table_offset += (2 + (index_sizes.string) + index_sizes.blob) * num_rows; + break; - if (row_count > (0xFFFF >> 0x02)) - index_size = 4; - else - index_size = 2; + case BIT_METHODDEFPTR: + // This one is not documented in ECMA-335. + table_offset += (index_sizes.methoddef) * num_rows; + break; - table_offset += ( - 4 + (index_sizes.string * 2) + index_size + - index_sizes.field + index_sizes.methoddef) * num_rows; - break; + case BIT_METHODDEF: + table_offset += (4 + 2 + 2 + index_sizes.string + index_sizes.blob + + index_sizes.param) * + num_rows; + break; - case BIT_FIELDPTR: - // This one is not documented in ECMA-335. - table_offset += (index_sizes.field) * num_rows; - break; + case BIT_PARAM: + table_offset += (2 + 2 + index_sizes.string) * num_rows; + break; - case BIT_FIELD: - table_offset += ( - 2 + (index_sizes.string) + index_sizes.blob) * num_rows; - break; + case BIT_INTERFACEIMPL: + row_count = max_rows( + 3, + yr_le32toh(rows.typedef_), + yr_le32toh(rows.typeref), + yr_le32toh(rows.typespec)); - case BIT_METHODDEFPTR: - // This one is not documented in ECMA-335. - table_offset += (index_sizes.methoddef) * num_rows; - break; + if (row_count > (0xFFFF >> 0x02)) + index_size = 4; + else + index_size = 2; - case BIT_METHODDEF: - table_offset += ( - 4 + 2 + 2 + - index_sizes.string + - index_sizes.blob + - index_sizes.param) * num_rows; - break; + table_offset += (index_sizes.typedef_ + index_size) * num_rows; + break; - case BIT_PARAM: - table_offset += (2 + 2 + index_sizes.string) * num_rows; - break; + case BIT_MEMBERREF: + row_count = max_rows( + 4, + yr_le32toh(rows.methoddef), + yr_le32toh(rows.moduleref), + yr_le32toh(rows.typeref), + yr_le32toh(rows.typespec)); + + if (row_count > (0xFFFF >> 0x03)) + index_size = 4; + else + index_size = 2; + + row_size = (index_size + index_sizes.string + index_sizes.blob); + memberref_row_size = row_size; + memberref_ptr = table_offset; + table_offset += row_size * num_rows; + break; - case BIT_INTERFACEIMPL: - row_count = max_rows(3, - yr_le32toh(rows.typedef_), - yr_le32toh(rows.typeref), - yr_le32toh(rows.typespec)); + case BIT_CONSTANT: + row_count = max_rows( + 3, + yr_le32toh(rows.param), + yr_le32toh(rows.field), + yr_le32toh(rows.property)); + + if (row_count > (0xFFFF >> 0x02)) + index_size = 4; + else + index_size = 2; + + // Using 'i' is insufficent since we may skip certain constants and + // it would give an inaccurate count in that case. + counter = 0; + row_size = (1 + 1 + index_size + index_sizes.blob); + row_ptr = table_offset; + + for (i = 0; i < num_rows; i++) + { + if (!fits_in_pe(pe, row_ptr, row_size)) + break; - if (row_count > (0xFFFF >> 0x02)) - index_size = 4; - else - index_size = 2; + constant_table = (PCONSTANT_TABLE) row_ptr; - table_offset += (index_sizes.typedef_ + index_size) * num_rows; - break; + // Only look for constants of type string. + if (yr_le32toh(constant_table->Type) != ELEMENT_TYPE_STRING) + { + row_ptr += row_size; + continue; + } - case BIT_MEMBERREF: - row_count = max_rows(4, - yr_le32toh(rows.methoddef), - yr_le32toh(rows.moduleref), - yr_le32toh(rows.typeref), - yr_le32toh(rows.typespec)); + // Get the blob offset and pull it out of the blob table. + blob_offset = ((uint8_t*) constant_table) + 2 + index_size; - if (row_count > (0xFFFF >> 0x03)) - index_size = 4; + if (index_sizes.blob == 4) + blob_index = *(DWORD*) blob_offset; else - index_size = 2; + // Cast the value (index into blob table) to a 32bit value. + blob_index = (DWORD)(*(WORD*) blob_offset); - row_size = (index_size + index_sizes.string + index_sizes.blob); - memberref_row_size = row_size; - memberref_ptr = table_offset; - table_offset += row_size * num_rows; - break; + // Everything checks out. Make sure the index into the blob field + // is valid (non-null and within range). + blob_offset = pe->data + metadata_root + + yr_le32toh(streams->blob->Offset) + blob_index; - case BIT_CONSTANT: - row_count = max_rows(3, - yr_le32toh(rows.param), - yr_le32toh(rows.field), - yr_le32toh(rows.property)); + blob_result = dotnet_parse_blob_entry(pe, blob_offset); - if (row_count > (0xFFFF >> 0x02)) - index_size = 4; - else - index_size = 2; + if (blob_result.size == 0) + { + row_ptr += row_size; + continue; + } + + blob_length = blob_result.length; + blob_offset += blob_result.size; + + // Quick sanity check to make sure the blob entry is within bounds. + if (blob_offset + blob_length >= pe->data + pe->data_size) + { + row_ptr += row_size; + continue; + } + + set_sized_string( + (char*) blob_offset, + blob_result.length, + pe->object, + "constants[%i]", + counter); + + counter++; + row_ptr += row_size; + } + + set_integer(counter, pe->object, "number_of_constants"); + table_offset += row_size * num_rows; + break; - // Using 'i' is insufficent since we may skip certain constants and - // it would give an inaccurate count in that case. - counter = 0; - row_size = (1 + 1 + index_size + index_sizes.blob); + case BIT_CUSTOMATTRIBUTE: + // index_size is size of the parent column. + row_count = max_rows( + 21, + yr_le32toh(rows.methoddef), + yr_le32toh(rows.field), + yr_le32toh(rows.typeref), + yr_le32toh(rows.typedef_), + yr_le32toh(rows.param), + yr_le32toh(rows.interfaceimpl), + yr_le32toh(rows.memberref), + yr_le32toh(rows.module), + yr_le32toh(rows.property), + yr_le32toh(rows.event), + yr_le32toh(rows.standalonesig), + yr_le32toh(rows.moduleref), + yr_le32toh(rows.typespec), + yr_le32toh(rows.assembly), + yr_le32toh(rows.assemblyref), + yr_le32toh(rows.file), + yr_le32toh(rows.exportedtype), + yr_le32toh(rows.manifestresource), + yr_le32toh(rows.genericparam), + yr_le32toh(rows.genericparamconstraint), + yr_le32toh(rows.methodspec)); + + if (row_count > (0xFFFF >> 0x05)) + index_size = 4; + else + index_size = 2; + + // index_size2 is size of the type column. + row_count = max_rows( + 2, yr_le32toh(rows.methoddef), yr_le32toh(rows.memberref)); + + if (row_count > (0xFFFF >> 0x03)) + index_size2 = 4; + else + index_size2 = 2; + + row_size = (index_size + index_size2 + index_sizes.blob); + + if (typeref_ptr != NULL && memberref_ptr != NULL) + { row_ptr = table_offset; for (i = 0; i < num_rows; i++) @@ -594,826 +701,742 @@ void dotnet_parse_tilde_2( if (!fits_in_pe(pe, row_ptr, row_size)) break; - constant_table = (PCONSTANT_TABLE) row_ptr; + // Check the Parent field. + customattribute_table = (PCUSTOMATTRIBUTE_TABLE) row_ptr; - // Only look for constants of type string. - if (yr_le32toh(constant_table->Type) != ELEMENT_TYPE_STRING) + if (index_size == 4) { - row_ptr += row_size; - continue; + // Low 5 bits tell us what this is an index into. Remaining bits + // tell us the index value. + // Parent must be an index into the Assembly (0x0E) table. + if ((*(DWORD*) customattribute_table & 0x1F) != 0x0E) + { + row_ptr += row_size; + continue; + } } - - // Get the blob offset and pull it out of the blob table. - blob_offset = ((uint8_t*) constant_table) + 2 + index_size; - - if (index_sizes.blob == 4) - blob_index = *(DWORD*) blob_offset; else - // Cast the value (index into blob table) to a 32bit value. - blob_index = (DWORD) (*(WORD*) blob_offset); - - // Everything checks out. Make sure the index into the blob field - // is valid (non-null and within range). - blob_offset = \ - pe->data + metadata_root + - yr_le32toh(streams->blob->Offset) + blob_index; - - blob_result = dotnet_parse_blob_entry(pe, blob_offset); - - if (blob_result.size == 0) { - row_ptr += row_size; - continue; + // Low 5 bits tell us what this is an index into. Remaining bits + // tell us the index value. + // Parent must be an index into the Assembly (0x0E) table. + if ((*(WORD*) customattribute_table & 0x1F) != 0x0E) + { + row_ptr += row_size; + continue; + } } - blob_length = blob_result.length; - blob_offset += blob_result.size; + // Check the Type field. + customattribute_table = (PCUSTOMATTRIBUTE_TABLE)( + row_ptr + index_size); - // Quick sanity check to make sure the blob entry is within bounds. - if (blob_offset + blob_length >= pe->data + pe->data_size) + if (index_size2 == 4) { - row_ptr += row_size; - continue; - } - - set_sized_string( - (char*) blob_offset, - blob_result.length, - pe->object, - "constants[%i]", - counter); - - counter++; - row_ptr += row_size; - } - - set_integer(counter, pe->object, "number_of_constants"); - table_offset += row_size * num_rows; - break; + // Low 3 bits tell us what this is an index into. Remaining bits + // tell us the index value. Only values 2 and 3 are defined. + // Type must be an index into the MemberRef table. + if ((*(DWORD*) customattribute_table & 0x07) != 0x03) + { + row_ptr += row_size; + continue; + } - case BIT_CUSTOMATTRIBUTE: - // index_size is size of the parent column. - row_count = max_rows(21, - yr_le32toh(rows.methoddef), - yr_le32toh(rows.field), - yr_le32toh(rows.typeref), - yr_le32toh(rows.typedef_), - yr_le32toh(rows.param), - yr_le32toh(rows.interfaceimpl), - yr_le32toh(rows.memberref), - yr_le32toh(rows.module), - yr_le32toh(rows.property), - yr_le32toh(rows.event), - yr_le32toh(rows.standalonesig), - yr_le32toh(rows.moduleref), - yr_le32toh(rows.typespec), - yr_le32toh(rows.assembly), - yr_le32toh(rows.assemblyref), - yr_le32toh(rows.file), - yr_le32toh(rows.exportedtype), - yr_le32toh(rows.manifestresource), - yr_le32toh(rows.genericparam), - yr_le32toh(rows.genericparamconstraint), - yr_le32toh(rows.methodspec)); - - if (row_count > (0xFFFF >> 0x05)) - index_size = 4; - else - index_size = 2; + type_index = *(DWORD*) customattribute_table >> 3; + } + else + { + // Low 3 bits tell us what this is an index into. Remaining bits + // tell us the index value. Only values 2 and 3 are defined. + // Type must be an index into the MemberRef table. + if ((*(WORD*) customattribute_table & 0x07) != 0x03) + { + row_ptr += row_size; + continue; + } - // index_size2 is size of the type column. - row_count = max_rows(2, - yr_le32toh(rows.methoddef), - yr_le32toh(rows.memberref)); + // Cast the index to a 32bit value. + type_index = (DWORD)((*(WORD*) customattribute_table >> 3)); + } - if (row_count > (0xFFFF >> 0x03)) - index_size2 = 4; - else - index_size2 = 2; + if (type_index > 0) + type_index--; - row_size = (index_size + index_size2 + index_sizes.blob); + // Now follow the Type index into the MemberRef table. + memberref_row = memberref_ptr + (memberref_row_size * type_index); - if (typeref_ptr != NULL && memberref_ptr != NULL) - { - row_ptr = table_offset; + if (!fits_in_pe(pe, memberref_row, memberref_row_size)) + break; - for (i = 0; i < num_rows; i++) + if (index_sizes.memberref == 4) { - if (!fits_in_pe(pe, row_ptr, row_size)) - break; - - // Check the Parent field. - customattribute_table = (PCUSTOMATTRIBUTE_TABLE) row_ptr; - - if (index_size == 4) + // Low 3 bits tell us what this is an index into. Remaining bits + // tell us the index value. Class must be an index into the + // TypeRef table. + if ((*(DWORD*) memberref_row & 0x07) != 0x01) { - // Low 5 bits tell us what this is an index into. Remaining bits - // tell us the index value. - // Parent must be an index into the Assembly (0x0E) table. - if ((*(DWORD*) customattribute_table & 0x1F) != 0x0E) - { - row_ptr += row_size; - continue; - } + row_ptr += row_size; + continue; } - else + + class_index = *(DWORD*) memberref_row >> 3; + } + else + { + // Low 3 bits tell us what this is an index into. Remaining bits + // tell us the index value. Class must be an index into the + // TypeRef table. + if ((*(WORD*) memberref_row & 0x07) != 0x01) { - // Low 5 bits tell us what this is an index into. Remaining bits - // tell us the index value. - // Parent must be an index into the Assembly (0x0E) table. - if ((*(WORD*) customattribute_table & 0x1F) != 0x0E) - { - row_ptr += row_size; - continue; - } + row_ptr += row_size; + continue; } - // Check the Type field. - customattribute_table = (PCUSTOMATTRIBUTE_TABLE) \ - (row_ptr + index_size); + // Cast the index to a 32bit value. + class_index = (DWORD)(*(WORD*) memberref_row >> 3); + } - if (index_size2 == 4) - { - // Low 3 bits tell us what this is an index into. Remaining bits - // tell us the index value. Only values 2 and 3 are defined. - // Type must be an index into the MemberRef table. - if ((*(DWORD*) customattribute_table & 0x07) != 0x03) - { - row_ptr += row_size; - continue; - } - - type_index = *(DWORD*) customattribute_table >> 3; - } - else - { - // Low 3 bits tell us what this is an index into. Remaining bits - // tell us the index value. Only values 2 and 3 are defined. - // Type must be an index into the MemberRef table. - if ((*(WORD*) customattribute_table & 0x07) != 0x03) - { - row_ptr += row_size; - continue; - } - - // Cast the index to a 32bit value. - type_index = (DWORD) ((*(WORD*) customattribute_table >> 3)); - } + if (class_index > 0) + class_index--; - if (type_index > 0) - type_index--; + // Now follow the Class index into the TypeRef table. + typeref_row = typeref_ptr + (typeref_row_size * class_index); - // Now follow the Type index into the MemberRef table. - memberref_row = memberref_ptr + (memberref_row_size * type_index); + if (!fits_in_pe(pe, typeref_row, typeref_row_size)) + break; - if (!fits_in_pe(pe, memberref_row, memberref_row_size)) - break; + // Skip over the ResolutionScope and check the Name field, + // which is an index into the Strings heap. + row_count = max_rows( + 4, + yr_le32toh(rows.module), + yr_le32toh(rows.moduleref), + yr_le32toh(rows.assemblyref), + yr_le32toh(rows.typeref)); + + if (row_count > (0xFFFF >> 0x02)) + typeref_row += 4; + else + typeref_row += 2; - if (index_sizes.memberref == 4) - { - // Low 3 bits tell us what this is an index into. Remaining bits - // tell us the index value. Class must be an index into the - // TypeRef table. - if ((*(DWORD*) memberref_row & 0x07) != 0x01) - { - row_ptr += row_size; - continue; - } - - class_index = *(DWORD*) memberref_row >> 3; - } - else - { - // Low 3 bits tell us what this is an index into. Remaining bits - // tell us the index value. Class must be an index into the - // TypeRef table. - if ((*(WORD*) memberref_row & 0x07) != 0x01) - { - row_ptr += row_size; - continue; - } - - // Cast the index to a 32bit value. - class_index = (DWORD) (*(WORD*) memberref_row >> 3); - } + if (index_sizes.string == 4) + { + name = pe_get_dotnet_string( + pe, string_offset, *(DWORD*) typeref_row); + } + else + { + name = pe_get_dotnet_string( + pe, string_offset, *(WORD*) typeref_row); + } - if (class_index > 0) - class_index--; + if (name != NULL && strncmp(name, "GuidAttribute", 13) != 0) + { + row_ptr += row_size; + continue; + } - // Now follow the Class index into the TypeRef table. - typeref_row = typeref_ptr + (typeref_row_size * class_index); + // Get the Value field. + customattribute_table = (PCUSTOMATTRIBUTE_TABLE)( + row_ptr + index_size + index_size2); - if (!fits_in_pe(pe, typeref_row, typeref_row_size)) - break; + if (index_sizes.blob == 4) + blob_index = *(DWORD*) customattribute_table; + else + // Cast the value (index into blob table) to a 32bit value. + blob_index = (DWORD)(*(WORD*) customattribute_table); - // Skip over the ResolutionScope and check the Name field, - // which is an index into the Strings heap. - row_count = max_rows(4, - yr_le32toh(rows.module), - yr_le32toh(rows.moduleref), - yr_le32toh(rows.assemblyref), - yr_le32toh(rows.typeref)); + // Everything checks out. Make sure the index into the blob field + // is valid (non-null and within range). + blob_offset = pe->data + metadata_root + + yr_le32toh(streams->blob->Offset) + blob_index; - if (row_count > (0xFFFF >> 0x02)) - typeref_row += 4; - else - typeref_row += 2; + // If index into blob is 0 or past the end of the blob stream, skip + // it. We don't know the size of the blob entry yet because that is + // encoded in the start. + if (blob_index == 0x00 || blob_offset >= pe->data + pe->data_size) + { + row_ptr += row_size; + continue; + } - if (index_sizes.string == 4) - { - name = pe_get_dotnet_string( - pe, string_offset, *(DWORD*) typeref_row); - } - else - { - name = pe_get_dotnet_string( - pe, string_offset, *(WORD*) typeref_row); - } + blob_result = dotnet_parse_blob_entry(pe, blob_offset); - if (name != NULL && strncmp(name, "GuidAttribute", 13) != 0) - { - row_ptr += row_size; - continue; - } + if (blob_result.size == 0) + { + row_ptr += row_size; + continue; + } - // Get the Value field. - customattribute_table = (PCUSTOMATTRIBUTE_TABLE) \ - (row_ptr + index_size + index_size2); - - if (index_sizes.blob == 4) - blob_index = *(DWORD*) customattribute_table; - else - // Cast the value (index into blob table) to a 32bit value. - blob_index = (DWORD) (*(WORD*) customattribute_table); - - // Everything checks out. Make sure the index into the blob field - // is valid (non-null and within range). - blob_offset = \ - pe->data + metadata_root + yr_le32toh(streams->blob->Offset) + blob_index; - - // If index into blob is 0 or past the end of the blob stream, skip - // it. We don't know the size of the blob entry yet because that is - // encoded in the start. - if (blob_index == 0x00 || blob_offset >= pe->data + pe->data_size) - { - row_ptr += row_size; - continue; - } + blob_length = blob_result.length; + blob_offset += blob_result.size; - blob_result = dotnet_parse_blob_entry(pe, blob_offset); + // Quick sanity check to make sure the blob entry is within bounds. + if (blob_offset + blob_length >= pe->data + pe->data_size) + { + row_ptr += row_size; + continue; + } - if (blob_result.size == 0) - { - row_ptr += row_size; - continue; - } + // Custom attributes MUST have a 16 bit prolog of 0x0001 + if (*(WORD*) blob_offset != 0x0001) + { + row_ptr += row_size; + continue; + } - blob_length = blob_result.length; - blob_offset += blob_result.size; + // The next byte is the length of the string. + blob_offset += 2; - // Quick sanity check to make sure the blob entry is within bounds. - if (blob_offset + blob_length >= pe->data + pe->data_size) - { - row_ptr += row_size; - continue; - } + if (blob_offset + *blob_offset >= pe->data + pe->data_size) + { + row_ptr += row_size; + continue; + } - // Custom attributes MUST have a 16 bit prolog of 0x0001 - if (*(WORD*) blob_offset != 0x0001) - { - row_ptr += row_size; - continue; - } + blob_offset += 1; - // The next byte is the length of the string. - blob_offset += 2; + if (*blob_offset == 0xFF || *blob_offset == 0x00) + { + typelib[0] = '\0'; + } + else + { + strncpy(typelib, (char*) blob_offset, MAX_TYPELIB_SIZE); + typelib[MAX_TYPELIB_SIZE] = '\0'; + } - if (blob_offset + *blob_offset >= pe->data + pe->data_size) - { - row_ptr += row_size; - continue; - } + set_string(typelib, pe->object, "typelib"); - blob_offset += 1; + row_ptr += row_size; + } + } - if (*blob_offset == 0xFF || *blob_offset == 0x00) - { - typelib[0] = '\0'; - } - else - { - strncpy(typelib, (char*) blob_offset, MAX_TYPELIB_SIZE); - typelib[MAX_TYPELIB_SIZE] = '\0'; - } + table_offset += row_size * num_rows; + break; - set_string(typelib, pe->object, "typelib"); + case BIT_FIELDMARSHAL: + row_count = max_rows(2, yr_le32toh(rows.field), yr_le32toh(rows.param)); - row_ptr += row_size; - } - } + if (row_count > (0xFFFF >> 0x01)) + index_size = 4; + else + index_size = 2; - table_offset += row_size * num_rows; - break; + table_offset += (index_size + index_sizes.blob) * num_rows; + break; - case BIT_FIELDMARSHAL: - row_count = max_rows(2, - yr_le32toh(rows.field), - yr_le32toh(rows.param)); + case BIT_DECLSECURITY: + row_count = max_rows( + 3, + yr_le32toh(rows.typedef_), + yr_le32toh(rows.methoddef), + yr_le32toh(rows.assembly)); - if (row_count > (0xFFFF >> 0x01)) - index_size = 4; - else - index_size = 2; + if (row_count > (0xFFFF >> 0x02)) + index_size = 4; + else + index_size = 2; - table_offset += (index_size + index_sizes.blob) * num_rows; - break; + table_offset += (2 + index_size + index_sizes.blob) * num_rows; + break; - case BIT_DECLSECURITY: - row_count = max_rows(3, - yr_le32toh(rows.typedef_), - yr_le32toh(rows.methoddef), - yr_le32toh(rows.assembly)); + case BIT_CLASSLAYOUT: + table_offset += (2 + 4 + index_sizes.typedef_) * num_rows; + break; - if (row_count > (0xFFFF >> 0x02)) - index_size = 4; - else - index_size = 2; + case BIT_FIELDLAYOUT: + table_offset += (4 + index_sizes.field) * num_rows; + break; - table_offset += (2 + index_size + index_sizes.blob) * num_rows; - break; + case BIT_STANDALONESIG: + table_offset += (index_sizes.blob) * num_rows; + break; - case BIT_CLASSLAYOUT: - table_offset += (2 + 4 + index_sizes.typedef_) * num_rows; - break; + case BIT_EVENTMAP: + table_offset += (index_sizes.typedef_ + index_sizes.event) * num_rows; + break; - case BIT_FIELDLAYOUT: - table_offset += (4 + index_sizes.field) * num_rows; - break; + case BIT_EVENTPTR: + // This one is not documented in ECMA-335. + table_offset += (index_sizes.event) * num_rows; + break; - case BIT_STANDALONESIG: - table_offset += (index_sizes.blob) * num_rows; - break; + case BIT_EVENT: + row_count = max_rows( + 3, + yr_le32toh(rows.typedef_), + yr_le32toh(rows.typeref), + yr_le32toh(rows.typespec)); - case BIT_EVENTMAP: - table_offset += (index_sizes.typedef_ + index_sizes.event) * num_rows; - break; + if (row_count > (0xFFFF >> 0x02)) + index_size = 4; + else + index_size = 2; - case BIT_EVENTPTR: - // This one is not documented in ECMA-335. - table_offset += (index_sizes.event) * num_rows; - break; + table_offset += (2 + index_sizes.string + index_size) * num_rows; + break; - case BIT_EVENT: - row_count = max_rows(3, - yr_le32toh(rows.typedef_), - yr_le32toh(rows.typeref), - yr_le32toh(rows.typespec)); + case BIT_PROPERTYMAP: + table_offset += (index_sizes.typedef_ + index_sizes.property) * num_rows; + break; - if (row_count > (0xFFFF >> 0x02)) - index_size = 4; - else - index_size = 2; + case BIT_PROPERTYPTR: + // This one is not documented in ECMA-335. + table_offset += (index_sizes.property) * num_rows; + break; - table_offset += (2 + index_sizes.string + index_size) * num_rows; - break; + case BIT_PROPERTY: + table_offset += (2 + index_sizes.string + index_sizes.blob) * num_rows; + break; - case BIT_PROPERTYMAP: - table_offset += (index_sizes.typedef_ + index_sizes.property) * num_rows; - break; + case BIT_METHODSEMANTICS: + row_count = max_rows( + 2, yr_le32toh(rows.event), yr_le32toh(rows.property)); - case BIT_PROPERTYPTR: - // This one is not documented in ECMA-335. - table_offset += (index_sizes.property) * num_rows; - break; + if (row_count > (0xFFFF >> 0x01)) + index_size = 4; + else + index_size = 2; - case BIT_PROPERTY: - table_offset += (2 + index_sizes.string + index_sizes.blob) * num_rows; - break; + table_offset += (2 + index_sizes.methoddef + index_size) * num_rows; + break; - case BIT_METHODSEMANTICS: - row_count = max_rows(2, - yr_le32toh(rows.event), - yr_le32toh(rows.property)); + case BIT_METHODIMPL: + row_count = max_rows( + 2, yr_le32toh(rows.methoddef), yr_le32toh(rows.memberref)); - if (row_count > (0xFFFF >> 0x01)) - index_size = 4; - else - index_size = 2; + if (row_count > (0xFFFF >> 0x01)) + index_size = 4; + else + index_size = 2; - table_offset += (2 + index_sizes.methoddef + index_size) * num_rows; - break; + table_offset += (index_sizes.typedef_ + (index_size * 2)) * num_rows; + break; - case BIT_METHODIMPL: - row_count = max_rows(2, - yr_le32toh(rows.methoddef), - yr_le32toh(rows.memberref)); + case BIT_MODULEREF: + row_ptr = table_offset; - if (row_count > (0xFFFF >> 0x01)) - index_size = 4; - else - index_size = 2; + // Can't use 'i' here because we only set the string if it is not + // NULL. Instead use 'counter'. + counter = 0; - table_offset += (index_sizes.typedef_ + (index_size * 2)) * num_rows; - break; + for (i = 0; i < num_rows; i++) + { + moduleref_table = (PMODULEREF_TABLE) row_ptr; - case BIT_MODULEREF: - row_ptr = table_offset; + if (!struct_fits_in_pe(pe, moduleref_table, MODULEREF_TABLE)) + break; - // Can't use 'i' here because we only set the string if it is not - // NULL. Instead use 'counter'. - counter = 0; + name = pe_get_dotnet_string( + pe, string_offset, DOTNET_STRING_INDEX(moduleref_table->Name)); - for (i = 0; i < num_rows; i++) + if (name != NULL) { - moduleref_table = (PMODULEREF_TABLE) row_ptr; + set_string(name, pe->object, "modulerefs[%i]", counter); + counter++; + } - if (!struct_fits_in_pe(pe, moduleref_table, MODULEREF_TABLE)) - break; + row_ptr += index_sizes.string; + } - name = pe_get_dotnet_string(pe, - string_offset, - DOTNET_STRING_INDEX(moduleref_table->Name)); + set_integer(counter, pe->object, "number_of_modulerefs"); - if (name != NULL) - { - set_string(name, pe->object, "modulerefs[%i]", counter); - counter++; - } + table_offset += (index_sizes.string) * num_rows; + break; - row_ptr += index_sizes.string; - } + case BIT_TYPESPEC: + table_offset += (index_sizes.blob) * num_rows; + break; - set_integer(counter, pe->object, "number_of_modulerefs"); + case BIT_IMPLMAP: + row_count = max_rows( + 2, yr_le32toh(rows.field), yr_le32toh(rows.methoddef)); - table_offset += (index_sizes.string) * num_rows; - break; + if (row_count > (0xFFFF >> 0x01)) + index_size = 4; + else + index_size = 2; - case BIT_TYPESPEC: - table_offset += (index_sizes.blob) * num_rows; - break; + table_offset += (2 + index_size + index_sizes.string + + index_sizes.moduleref) * + num_rows; + break; - case BIT_IMPLMAP: - row_count = max_rows(2, - yr_le32toh(rows.field), - yr_le32toh(rows.methoddef)); + case BIT_FIELDRVA: + row_size = 4 + index_sizes.field; + row_ptr = table_offset; - if (row_count > (0xFFFF >> 0x01)) - index_size = 4; - else - index_size = 2; + // Can't use 'i' here because we only set the field offset if it is + // valid. Instead use 'counter'. + counter = 0; - table_offset += ( - 2 + index_size + index_sizes.string + - index_sizes.moduleref) * num_rows; - break; + for (i = 0; i < num_rows; i++) + { + fieldrva_table = (PFIELDRVA_TABLE) row_ptr; - case BIT_FIELDRVA: - row_size = 4 + index_sizes.field; - row_ptr = table_offset; + if (!struct_fits_in_pe(pe, fieldrva_table, FIELDRVA_TABLE)) + break; - // Can't use 'i' here because we only set the field offset if it is - // valid. Instead use 'counter'. - counter = 0; + field_offset = pe_rva_to_offset(pe, fieldrva_table->RVA); - for (i = 0; i < num_rows; i++) + if (field_offset >= 0) { - fieldrva_table = (PFIELDRVA_TABLE) row_ptr; - - if (!struct_fits_in_pe(pe, fieldrva_table, FIELDRVA_TABLE)) - break; + set_integer(field_offset, pe->object, "field_offsets[%i]", counter); + counter++; + } - field_offset = pe_rva_to_offset(pe, fieldrva_table->RVA); + row_ptr += row_size; + } - if (field_offset >= 0) - { - set_integer(field_offset, pe->object, "field_offsets[%i]", counter); - counter++; - } + set_integer(counter, pe->object, "number_of_field_offsets"); - row_ptr += row_size; - } + table_offset += row_size * num_rows; + break; - set_integer(counter, pe->object, "number_of_field_offsets"); + case BIT_ENCLOG: + table_offset += (4 + 4) * num_rows; + break; - table_offset += row_size * num_rows; - break; + case BIT_ENCMAP: + table_offset += (4) * num_rows; + break; - case BIT_ENCLOG: - table_offset += (4 + 4) * num_rows; - break; + case BIT_ASSEMBLY: + row_size = + (4 + 2 + 2 + 2 + 2 + 4 + index_sizes.blob + (index_sizes.string * 2)); - case BIT_ENCMAP: - table_offset += (4) * num_rows; + if (!fits_in_pe(pe, table_offset, row_size)) break; - case BIT_ASSEMBLY: - row_size = ( - 4 + 2 + 2 + 2 + 2 + 4 + index_sizes.blob + - (index_sizes.string * 2)); + row_ptr = table_offset; + assembly_table = (PASSEMBLY_TABLE) table_offset; - if (!fits_in_pe(pe, table_offset, row_size)) - break; + set_integer( + yr_le16toh(assembly_table->MajorVersion), + pe->object, + "assembly.version.major"); + set_integer( + yr_le16toh(assembly_table->MinorVersion), + pe->object, + "assembly.version.minor"); + set_integer( + yr_le16toh(assembly_table->BuildNumber), + pe->object, + "assembly.version.build_number"); + set_integer( + yr_le16toh(assembly_table->RevisionNumber), + pe->object, + "assembly.version.revision_number"); - row_ptr = table_offset; - assembly_table = (PASSEMBLY_TABLE) table_offset; - - set_integer(yr_le16toh(assembly_table->MajorVersion), - pe->object, "assembly.version.major"); - set_integer(yr_le16toh(assembly_table->MinorVersion), - pe->object, "assembly.version.minor"); - set_integer(yr_le16toh(assembly_table->BuildNumber), - pe->object, "assembly.version.build_number"); - set_integer(yr_le16toh(assembly_table->RevisionNumber), - pe->object, "assembly.version.revision_number"); - - // Can't use assembly_table here because the PublicKey comes before - // Name and is a variable length field. + // Can't use assembly_table here because the PublicKey comes before + // Name and is a variable length field. - if (index_sizes.string == 4) - name = pe_get_dotnet_string( - pe, - string_offset, - yr_le32toh(*(DWORD*) ( - row_ptr + 4 + 2 + 2 + 2 + 2 + 4 + - index_sizes.blob))); - else - name = pe_get_dotnet_string( - pe, - string_offset, - yr_le16toh(*(WORD*) ( - row_ptr + 4 + 2 + 2 + 2 + 2 + 4 + - index_sizes.blob))); + if (index_sizes.string == 4) + name = pe_get_dotnet_string( + pe, + string_offset, + yr_le32toh(*( + DWORD*) (row_ptr + 4 + 2 + 2 + 2 + 2 + 4 + index_sizes.blob))); + else + name = pe_get_dotnet_string( + pe, + string_offset, + yr_le16toh( + *(WORD*) (row_ptr + 4 + 2 + 2 + 2 + 2 + 4 + index_sizes.blob))); - if (name != NULL) - set_string(name, pe->object, "assembly.name"); + if (name != NULL) + set_string(name, pe->object, "assembly.name"); - // Culture comes after Name. - if (index_sizes.string == 4) - { - name = pe_get_dotnet_string( + // Culture comes after Name. + if (index_sizes.string == 4) + { + name = pe_get_dotnet_string( pe, string_offset, yr_le32toh(*(DWORD*) ( row_ptr + 4 + 2 + 2 + 2 + 2 + 4 + index_sizes.blob + index_sizes.string))); - } - else - { - name = pe_get_dotnet_string( + } + else + { + name = pe_get_dotnet_string( pe, string_offset, yr_le16toh(*(WORD*) ( row_ptr + 4 + 2 + 2 + 2 + 2 + 4 + index_sizes.blob + index_sizes.string))); - } + } - // Sometimes it will be a zero length string. This is technically - // against the specification but happens from time to time. - if (name != NULL && strlen(name) > 0) - set_string(name, pe->object, "assembly.culture"); + // Sometimes it will be a zero length string. This is technically + // against the specification but happens from time to time. + if (name != NULL && strlen(name) > 0) + set_string(name, pe->object, "assembly.culture"); - table_offset += row_size * num_rows; - break; + table_offset += row_size * num_rows; + break; - case BIT_ASSEMBLYPROCESSOR: - table_offset += (4) * num_rows; - break; + case BIT_ASSEMBLYPROCESSOR: + table_offset += (4) * num_rows; + break; - case BIT_ASSEMBLYOS: - table_offset += (4 + 4 + 4) * num_rows; - break; + case BIT_ASSEMBLYOS: + table_offset += (4 + 4 + 4) * num_rows; + break; - case BIT_ASSEMBLYREF: - row_size = (2 + 2 + 2 + 2 + 4 + - (index_sizes.blob * 2) + - (index_sizes.string * 2)); + case BIT_ASSEMBLYREF: + row_size = + (2 + 2 + 2 + 2 + 4 + (index_sizes.blob * 2) + + (index_sizes.string * 2)); - row_ptr = table_offset; + row_ptr = table_offset; - for (i = 0; i < num_rows; i++) - { - if (!fits_in_pe(pe, row_ptr, row_size)) - break; + for (i = 0; i < num_rows; i++) + { + if (!fits_in_pe(pe, row_ptr, row_size)) + break; - assemblyref_table = (PASSEMBLYREF_TABLE) row_ptr; + assemblyref_table = (PASSEMBLYREF_TABLE) row_ptr; + + set_integer( + yr_le16toh(assemblyref_table->MajorVersion), + pe->object, + "assembly_refs[%i].version.major", + i); + set_integer( + yr_le16toh(assemblyref_table->MinorVersion), + pe->object, + "assembly_refs[%i].version.minor", + i); + set_integer( + yr_le16toh(assemblyref_table->BuildNumber), + pe->object, + "assembly_refs[%i].version.build_number", + i); + set_integer( + yr_le16toh(assemblyref_table->RevisionNumber), + pe->object, + "assembly_refs[%i].version.revision_number", + i); + + blob_offset = pe->data + metadata_root + + yr_le32toh(streams->blob->Offset); + + if (index_sizes.blob == 4) + blob_offset += yr_le32toh( + assemblyref_table->PublicKeyOrToken.PublicKeyOrToken_Long); + else + blob_offset += yr_le16toh( + assemblyref_table->PublicKeyOrToken.PublicKeyOrToken_Short); - set_integer(yr_le16toh(assemblyref_table->MajorVersion), - pe->object, "assembly_refs[%i].version.major", i); - set_integer(yr_le16toh(assemblyref_table->MinorVersion), - pe->object, "assembly_refs[%i].version.minor", i); - set_integer(yr_le16toh(assemblyref_table->BuildNumber), - pe->object, "assembly_refs[%i].version.build_number", i); - set_integer(yr_le16toh(assemblyref_table->RevisionNumber), - pe->object, "assembly_refs[%i].version.revision_number", i); + blob_result = dotnet_parse_blob_entry(pe, blob_offset); + blob_offset += blob_result.size; - blob_offset = pe->data + metadata_root + yr_le32toh(streams->blob->Offset); + if (blob_result.size == 0 || + !fits_in_pe(pe, blob_offset, blob_result.length)) + { + row_ptr += row_size; + continue; + } - if (index_sizes.blob == 4) - blob_offset += \ - yr_le32toh(assemblyref_table->PublicKeyOrToken.PublicKeyOrToken_Long); - else - blob_offset += \ - yr_le16toh(assemblyref_table->PublicKeyOrToken.PublicKeyOrToken_Short); + // Avoid empty strings. + if (blob_result.length > 0) + { + set_sized_string( + (char*) blob_offset, + blob_result.length, + pe->object, + "assembly_refs[%i].public_key_or_token", + i); + } - blob_result = dotnet_parse_blob_entry(pe, blob_offset); - blob_offset += blob_result.size; + // Can't use assemblyref_table here because the PublicKey comes before + // Name and is a variable length field. - if (blob_result.size == 0 || - !fits_in_pe(pe, blob_offset, blob_result.length)) - { - row_ptr += row_size; - continue; - } + if (index_sizes.string == 4) + name = pe_get_dotnet_string( + pe, + string_offset, + yr_le32toh( + *(DWORD*) (row_ptr + 2 + 2 + 2 + 2 + 4 + index_sizes.blob))); + else + name = pe_get_dotnet_string( + pe, + string_offset, + yr_le16toh( + *(WORD*) (row_ptr + 2 + 2 + 2 + 2 + 4 + index_sizes.blob))); - // Avoid empty strings. - if (blob_result.length > 0) - { - set_sized_string((char*) blob_offset, - blob_result.length, pe->object, - "assembly_refs[%i].public_key_or_token", i); - } + if (name != NULL) + set_string(name, pe->object, "assembly_refs[%i].name", i); - // Can't use assemblyref_table here because the PublicKey comes before - // Name and is a variable length field. + row_ptr += row_size; + } - if (index_sizes.string == 4) - name = pe_get_dotnet_string(pe, - string_offset, - yr_le32toh(*(DWORD*) (row_ptr + 2 + 2 + 2 + 2 + 4 + index_sizes.blob))); - else - name = pe_get_dotnet_string(pe, - string_offset, - yr_le16toh(*(WORD*) (row_ptr + 2 + 2 + 2 + 2 + 4 + index_sizes.blob))); + set_integer(i, pe->object, "number_of_assembly_refs"); + table_offset += row_size * num_rows; + break; - if (name != NULL) - set_string(name, pe->object, "assembly_refs[%i].name", i); + case BIT_ASSEMBLYREFPROCESSOR: + table_offset += (4 + index_sizes.assemblyrefprocessor) * num_rows; + break; - row_ptr += row_size; - } + case BIT_ASSEMBLYREFOS: + table_offset += (4 + 4 + 4 + index_sizes.assemblyref) * num_rows; + break; - set_integer(i, pe->object, "number_of_assembly_refs"); - table_offset += row_size * num_rows; - break; + case BIT_FILE: + table_offset += (4 + index_sizes.string + index_sizes.blob) * num_rows; + break; - case BIT_ASSEMBLYREFPROCESSOR: - table_offset += (4 + index_sizes.assemblyrefprocessor) * num_rows; - break; + case BIT_EXPORTEDTYPE: + row_count = max_rows( + 3, + yr_le32toh(rows.file), + yr_le32toh(rows.assemblyref), + yr_le32toh(rows.exportedtype)); - case BIT_ASSEMBLYREFOS: - table_offset += (4 + 4 + 4 + index_sizes.assemblyref) * num_rows; - break; + if (row_count > (0xFFFF >> 0x02)) + index_size = 4; + else + index_size = 2; - case BIT_FILE: - table_offset += (4 + index_sizes.string + index_sizes.blob) * num_rows; - break; + table_offset += (4 + 4 + (index_sizes.string * 2) + index_size) * + num_rows; + break; - case BIT_EXPORTEDTYPE: - row_count = max_rows(3, - yr_le32toh(rows.file), - yr_le32toh(rows.assemblyref), - yr_le32toh(rows.exportedtype)); + case BIT_MANIFESTRESOURCE: + // This is an Implementation coded index with no 3rd bit specified. + row_count = max_rows( + 2, yr_le32toh(rows.file), yr_le32toh(rows.assemblyref)); - if (row_count > (0xFFFF >> 0x02)) - index_size = 4; - else - index_size = 2; + if (row_count > (0xFFFF >> 0x02)) + index_size = 4; + else + index_size = 2; - table_offset += (4 + 4 + (index_sizes.string * 2) + index_size) * num_rows; - break; + row_size = (4 + 4 + index_sizes.string + index_size); - case BIT_MANIFESTRESOURCE: - // This is an Implementation coded index with no 3rd bit specified. - row_count = max_rows(2, - yr_le32toh(rows.file), - yr_le32toh(rows.assemblyref)); + // Using 'i' is insufficent since we may skip certain resources and + // it would give an inaccurate count in that case. + counter = 0; + row_ptr = table_offset; - if (row_count > (0xFFFF >> 0x02)) - index_size = 4; - else - index_size = 2; + // First DWORD is the offset. + for (i = 0; i < num_rows; i++) + { + if (!fits_in_pe(pe, row_ptr, row_size)) + break; - row_size = (4 + 4 + index_sizes.string + index_size); + manifestresource_table = (PMANIFESTRESOURCE_TABLE) row_ptr; + resource_offset = yr_le32toh(manifestresource_table->Offset); - // Using 'i' is insufficent since we may skip certain resources and - // it would give an inaccurate count in that case. - counter = 0; - row_ptr = table_offset; + // Only set offset if it is in this file (implementation != 0). + // Can't use manifestresource_table here because the Name and + // Implementation fields are variable size. + if (index_size == 4) + implementation = yr_le32toh( + *(DWORD*) (row_ptr + 4 + 4 + index_sizes.string)); + else + implementation = yr_le16toh( + *(WORD*) (row_ptr + 4 + 4 + index_sizes.string)); - // First DWORD is the offset. - for (i = 0; i < num_rows; i++) + if (implementation != 0) { - if (!fits_in_pe(pe, row_ptr, row_size)) - break; - - manifestresource_table = (PMANIFESTRESOURCE_TABLE) row_ptr; - resource_offset = yr_le32toh(manifestresource_table->Offset); - - // Only set offset if it is in this file (implementation != 0). - // Can't use manifestresource_table here because the Name and - // Implementation fields are variable size. - if (index_size == 4) - implementation = yr_le32toh(*(DWORD*) (row_ptr + 4 + 4 + index_sizes.string)); - else - implementation = yr_le16toh(*(WORD*) (row_ptr + 4 + 4 + index_sizes.string)); - - if (implementation != 0) - { - row_ptr += row_size; - continue; - } + row_ptr += row_size; + continue; + } - if (!fits_in_pe( - pe, - pe->data + resource_base + resource_offset, - sizeof(DWORD))) - { - row_ptr += row_size; - continue; - } + if (!fits_in_pe( + pe, pe->data + resource_base + resource_offset, sizeof(DWORD))) + { + row_ptr += row_size; + continue; + } - resource_size = yr_le32toh(*(DWORD*)(pe->data + resource_base + resource_offset)); + resource_size = yr_le32toh( + *(DWORD*) (pe->data + resource_base + resource_offset)); - if (!fits_in_pe( - pe, pe->data + resource_base + - resource_offset, - resource_size)) - { - row_ptr += row_size; - continue; - } + if (!fits_in_pe( + pe, pe->data + resource_base + resource_offset, resource_size)) + { + row_ptr += row_size; + continue; + } - // Add 4 to skip the size. - set_integer(resource_base + resource_offset + 4, - pe->object, "resources[%i].offset", counter); + // Add 4 to skip the size. + set_integer( + resource_base + resource_offset + 4, + pe->object, + "resources[%i].offset", + counter); - set_integer(resource_size, - pe->object, "resources[%i].length", counter); + set_integer(resource_size, pe->object, "resources[%i].length", counter); - name = pe_get_dotnet_string(pe, - string_offset, - DOTNET_STRING_INDEX(manifestresource_table->Name)); + name = pe_get_dotnet_string( + pe, + string_offset, + DOTNET_STRING_INDEX(manifestresource_table->Name)); - if (name != NULL) - set_string(name, pe->object, "resources[%i].name", counter); + if (name != NULL) + set_string(name, pe->object, "resources[%i].name", counter); - row_ptr += row_size; - counter++; - } + row_ptr += row_size; + counter++; + } - set_integer(counter, pe->object, "number_of_resources"); + set_integer(counter, pe->object, "number_of_resources"); - table_offset += row_size * num_rows; - break; + table_offset += row_size * num_rows; + break; - case BIT_NESTEDCLASS: - table_offset += (index_sizes.typedef_ * 2) * num_rows; - break; + case BIT_NESTEDCLASS: + table_offset += (index_sizes.typedef_ * 2) * num_rows; + break; - case BIT_GENERICPARAM: - row_count = max_rows(2, - yr_le32toh(rows.typedef_), - yr_le32toh(rows.methoddef)); + case BIT_GENERICPARAM: + row_count = max_rows( + 2, yr_le32toh(rows.typedef_), yr_le32toh(rows.methoddef)); - if (row_count > (0xFFFF >> 0x01)) - index_size = 4; - else - index_size = 2; + if (row_count > (0xFFFF >> 0x01)) + index_size = 4; + else + index_size = 2; - table_offset += (2 + 2 + index_size + index_sizes.string) * num_rows; - break; + table_offset += (2 + 2 + index_size + index_sizes.string) * num_rows; + break; - case BIT_METHODSPEC: - row_count = max_rows(2, - yr_le32toh(rows.methoddef), - yr_le32toh(rows.memberref)); + case BIT_METHODSPEC: + row_count = max_rows( + 2, yr_le32toh(rows.methoddef), yr_le32toh(rows.memberref)); - if (row_count > (0xFFFF >> 0x01)) - index_size = 4; - else - index_size = 2; + if (row_count > (0xFFFF >> 0x01)) + index_size = 4; + else + index_size = 2; - table_offset += (index_size + index_sizes.blob) * num_rows; - break; + table_offset += (index_size + index_sizes.blob) * num_rows; + break; - case BIT_GENERICPARAMCONSTRAINT: - row_count = max_rows(3, - yr_le32toh(rows.typedef_), - yr_le32toh(rows.typeref), - yr_le32toh(rows.typespec)); + case BIT_GENERICPARAMCONSTRAINT: + row_count = max_rows( + 3, + yr_le32toh(rows.typedef_), + yr_le32toh(rows.typeref), + yr_le32toh(rows.typespec)); - if (row_count > (0xFFFF >> 0x02)) - index_size = 4; - else - index_size = 2; + if (row_count > (0xFFFF >> 0x02)) + index_size = 4; + else + index_size = 2; - table_offset += (index_sizes.genericparam + index_size) * num_rows; - break; + table_offset += (index_sizes.genericparam + index_size) * num_rows; + break; - default: - //printf("Unknown bit: %i\n", bit_check); - return; + default: + // printf("Unknown bit: %i\n", bit_check); + return; } matched_bits++; @@ -1458,10 +1481,8 @@ void dotnet_parse_tilde( // Default index sizes are 2. Will be bumped to 4 if necessary. memset(&index_sizes, 2, sizeof(index_sizes)); - tilde_header = (PTILDE_HEADER) ( - pe->data + - metadata_root + - yr_le32toh(streams->tilde->Offset)); + tilde_header = (PTILDE_HEADER)( + pe->data + metadata_root + yr_le32toh(streams->tilde->Offset)); if (!struct_fits_in_pe(pe, tilde_header, TILDE_HEADER)) return; @@ -1493,92 +1514,93 @@ void dotnet_parse_tilde( if (!((yr_le64toh(tilde_header->Valid) >> bit_check) & 0x01)) continue; -#define ROW_CHECK(name) \ - if (fits_in_pe(pe, row_offset, (matched_bits + 1) * sizeof(uint32_t))) \ - rows.name = *(row_offset + matched_bits); +#define ROW_CHECK(name) \ + if (fits_in_pe(pe, row_offset, (matched_bits + 1) * sizeof(uint32_t))) \ + rows.name = *(row_offset + matched_bits); -#define ROW_CHECK_WITH_INDEX(name) \ - ROW_CHECK(name); \ - if (yr_le32toh(rows.name) > 0xFFFF) \ - index_sizes.name = 4; +#define ROW_CHECK_WITH_INDEX(name) \ + ROW_CHECK(name); \ + if (yr_le32toh(rows.name) > 0xFFFF) \ + index_sizes.name = 4; switch (bit_check) { - case BIT_MODULE: - ROW_CHECK(module); - break; - case BIT_MODULEREF: - ROW_CHECK_WITH_INDEX(moduleref); - break; - case BIT_ASSEMBLYREF: - ROW_CHECK_WITH_INDEX(assemblyref); - break; - case BIT_ASSEMBLYREFPROCESSOR: - ROW_CHECK_WITH_INDEX(assemblyrefprocessor); - break; - case BIT_TYPEREF: - ROW_CHECK(typeref); - break; - case BIT_METHODDEF: - ROW_CHECK_WITH_INDEX(methoddef); - break; - case BIT_MEMBERREF: - ROW_CHECK_WITH_INDEX(memberref); - break; - case BIT_TYPEDEF: - ROW_CHECK_WITH_INDEX(typedef_); - break; - case BIT_TYPESPEC: - ROW_CHECK(typespec); - break; - case BIT_FIELD: - ROW_CHECK_WITH_INDEX(field); - break; - case BIT_PARAM: - ROW_CHECK_WITH_INDEX(param); - break; - case BIT_PROPERTY: - ROW_CHECK_WITH_INDEX(property); - break; - case BIT_INTERFACEIMPL: - ROW_CHECK(interfaceimpl); - break; - case BIT_EVENT: - ROW_CHECK_WITH_INDEX(event); - break; - case BIT_STANDALONESIG: - ROW_CHECK(standalonesig); - break; - case BIT_ASSEMBLY: - ROW_CHECK(assembly); - break; - case BIT_FILE: - ROW_CHECK(file); - break; - case BIT_EXPORTEDTYPE: - ROW_CHECK(exportedtype); - break; - case BIT_MANIFESTRESOURCE: - ROW_CHECK(manifestresource); - break; - case BIT_GENERICPARAM: - ROW_CHECK_WITH_INDEX(genericparam); - break; - case BIT_GENERICPARAMCONSTRAINT: - ROW_CHECK(genericparamconstraint); - break; - case BIT_METHODSPEC: - ROW_CHECK(methodspec); - break; - default: - break; + case BIT_MODULE: + ROW_CHECK(module); + break; + case BIT_MODULEREF: + ROW_CHECK_WITH_INDEX(moduleref); + break; + case BIT_ASSEMBLYREF: + ROW_CHECK_WITH_INDEX(assemblyref); + break; + case BIT_ASSEMBLYREFPROCESSOR: + ROW_CHECK_WITH_INDEX(assemblyrefprocessor); + break; + case BIT_TYPEREF: + ROW_CHECK(typeref); + break; + case BIT_METHODDEF: + ROW_CHECK_WITH_INDEX(methoddef); + break; + case BIT_MEMBERREF: + ROW_CHECK_WITH_INDEX(memberref); + break; + case BIT_TYPEDEF: + ROW_CHECK_WITH_INDEX(typedef_); + break; + case BIT_TYPESPEC: + ROW_CHECK(typespec); + break; + case BIT_FIELD: + ROW_CHECK_WITH_INDEX(field); + break; + case BIT_PARAM: + ROW_CHECK_WITH_INDEX(param); + break; + case BIT_PROPERTY: + ROW_CHECK_WITH_INDEX(property); + break; + case BIT_INTERFACEIMPL: + ROW_CHECK(interfaceimpl); + break; + case BIT_EVENT: + ROW_CHECK_WITH_INDEX(event); + break; + case BIT_STANDALONESIG: + ROW_CHECK(standalonesig); + break; + case BIT_ASSEMBLY: + ROW_CHECK(assembly); + break; + case BIT_FILE: + ROW_CHECK(file); + break; + case BIT_EXPORTEDTYPE: + ROW_CHECK(exportedtype); + break; + case BIT_MANIFESTRESOURCE: + ROW_CHECK(manifestresource); + break; + case BIT_GENERICPARAM: + ROW_CHECK_WITH_INDEX(genericparam); + break; + case BIT_GENERICPARAMCONSTRAINT: + ROW_CHECK(genericparamconstraint); + break; + case BIT_METHODSPEC: + ROW_CHECK(methodspec); + break; + default: + break; } matched_bits++; } // This is used when parsing the MANIFEST RESOURCE table. - resource_base = pe_rva_to_offset(pe, yr_le32toh(cli_header->Resources.VirtualAddress)); + resource_base = pe_rva_to_offset( + pe, yr_le32toh(cli_header->Resources.VirtualAddress)); dotnet_parse_tilde_2( pe, @@ -1591,9 +1613,7 @@ void dotnet_parse_tilde( } -void dotnet_parse_com( - PE* pe, - size_t base_address) +void dotnet_parse_com(PE* pe, size_t base_address) { PIMAGE_DATA_DIRECTORY directory; PCLI_HEADER cli_header; @@ -1613,7 +1633,7 @@ void dotnet_parse_com( if (offset < 0 || !struct_fits_in_pe(pe, pe->data + offset, CLI_HEADER)) return; - cli_header = (PCLI_HEADER) (pe->data + offset); + cli_header = (PCLI_HEADER)(pe->data + offset); offset = metadata_root = pe_rva_to_offset( pe, yr_le32toh(cli_header->MetaData.VirtualAddress)); @@ -1621,7 +1641,7 @@ void dotnet_parse_com( if (!struct_fits_in_pe(pe, pe->data + offset, NET_METADATA)) return; - metadata = (PNET_METADATA) (pe->data + offset); + metadata = (PNET_METADATA)(pe->data + offset); if (yr_le32toh(metadata->Magic) != NET_METADATA_MAGIC) return; @@ -1629,9 +1649,7 @@ void dotnet_parse_com( // Version length must be between 1 and 255, and be a multiple of 4. // Also make sure it fits in pe. md_len = yr_le32toh(metadata->Length); - if (md_len == 0 || - md_len > 255 || - md_len % 4 != 0 || + if (md_len == 0 || md_len > 255 || md_len % 4 != 0 || !fits_in_pe(pe, pe->data + offset, md_len)) { return; @@ -1642,10 +1660,8 @@ void dotnet_parse_com( // first NULL byte. end = (char*) memmem((void*) metadata->Version, md_len, "\0", 1); if (end != NULL) - set_sized_string(metadata->Version, - (end - metadata->Version), - pe->object, - "version"); + set_sized_string( + metadata->Version, (end - metadata->Version), pe->object, "version"); // The metadata structure has some variable length records after the version. // We must manually parse things from here on out. @@ -1657,7 +1673,7 @@ void dotnet_parse_com( if (!fits_in_pe(pe, pe->data + offset, 2)) return; - num_streams = (WORD) *(pe->data + offset); + num_streams = (WORD) * (pe->data + offset); offset += 2; headers = dotnet_parse_stream_headers(pe, offset, metadata_root, num_streams); @@ -1676,32 +1692,32 @@ void dotnet_parse_com( } -begin_declarations; +begin_declarations declare_string("version"); declare_string("module_name"); - begin_struct_array("streams"); + begin_struct_array("streams") declare_string("name"); declare_integer("offset"); declare_integer("size"); - end_struct_array("streams"); + end_struct_array("streams") declare_integer("number_of_streams"); declare_string_array("guids"); declare_integer("number_of_guids"); - begin_struct_array("resources"); + begin_struct_array("resources") declare_integer("offset"); declare_integer("length"); declare_string("name"); - end_struct_array("resources"); + end_struct_array("resources") declare_integer("number_of_resources"); - begin_struct_array("assembly_refs"); - begin_struct("version"); + begin_struct_array("assembly_refs") + begin_struct("version") declare_integer("major"); declare_integer("minor"); declare_integer("build_number"); @@ -1709,12 +1725,12 @@ begin_declarations; end_struct("version"); declare_string("public_key_or_token"); declare_string("name"); - end_struct_array("assembly_refs"); + end_struct_array("assembly_refs") declare_integer("number_of_assembly_refs"); - begin_struct("assembly"); - begin_struct("version"); + begin_struct("assembly") + begin_struct("version") declare_integer("major"); declare_integer("minor"); declare_integer("build_number"); @@ -1735,18 +1751,16 @@ begin_declarations; declare_integer_array("field_offsets"); declare_integer("number_of_field_offsets"); -end_declarations; +end_declarations -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { return ERROR_SUCCESS; } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { return ERROR_SUCCESS; } @@ -1803,10 +1817,9 @@ int module_load( } -int module_unload( - YR_OBJECT* module_object) +int module_unload(YR_OBJECT* module_object) { - PE* pe = (PE *) module_object->data; + PE* pe = (PE*) module_object->data; if (pe == NULL) return ERROR_SUCCESS; diff --git a/libyara/modules/elf/elf.c b/libyara/modules/elf/elf.c index bc23d41828..f17e8d36bb 100644 --- a/libyara/modules/elf/elf.c +++ b/libyara/modules/elf/elf.c @@ -29,21 +29,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include - #include #include -#include #include +#include #include #define MODULE_NAME elf -#define CLASS_DATA(c,d) ((c << 8) | d) +#define CLASS_DATA(c, d) ((c << 8) | d) -int get_elf_class_data( - const uint8_t* buffer, - size_t buffer_length) +int get_elf_class_data(const uint8_t* buffer, size_t buffer_length) { elf_ident_t* elf_ident; @@ -69,11 +66,11 @@ static bool is_valid_ptr( uint64_t ptr_size) // ptr_size can be 64bit even in 32bit systems. { return ptr >= base && ptr_size <= size && - ((char*) ptr) + ptr_size <= ((char*) base) + size; + ((char*) ptr) + ptr_size <= ((char*) base) + size; } #define IS_VALID_PTR(base, size, ptr) \ - is_valid_ptr(base, size, ptr, sizeof(*ptr)) + is_valid_ptr(base, size, ptr, sizeof(*ptr)) // // Returns a string table entry for the index or NULL if the entry is out @@ -112,311 +109,337 @@ static const char* str_table_entry( return str_entry; } -#define ELF_SIZE_OF_SECTION_TABLE(bits,bo,h) \ +#define ELF_SIZE_OF_SECTION_TABLE(bits, bo, h) \ (sizeof(elf##bits##_section_header_t) * yr_##bo##16toh(h->sh_entry_count)) -#define ELF_SIZE_OF_PROGRAM_TABLE(bits,bo,h) \ +#define ELF_SIZE_OF_PROGRAM_TABLE(bits, bo, h) \ (sizeof(elf##bits##_program_header_t) * yr_##bo##16toh(h->ph_entry_count)) -#define ELF_RVA_TO_OFFSET(bits,bo) \ -uint64_t elf_rva_to_offset_##bits##_##bo( \ - elf##bits##_header_t* elf_header, \ - uint64_t rva, \ - size_t elf_size) \ -{ \ - if (yr_##bo##16toh(elf_header->type) == ELF_ET_EXEC) \ - { \ - int i; \ - \ - elf##bits##_program_header_t* program; \ - \ - /* check that ph_offset doesn't wrap when added to SIZE_OF_PROGRAM_TABLE */\ - \ - if(ULONG_MAX - yr_##bo##bits##toh(elf_header->ph_offset) < \ - ELF_SIZE_OF_PROGRAM_TABLE(bits,bo,elf_header)) \ - { \ - return YR_UNDEFINED; \ - } \ - \ - if (yr_##bo##bits##toh(elf_header->ph_offset) == 0 || \ - yr_##bo##bits##toh(elf_header->ph_offset) > elf_size || \ - yr_##bo##bits##toh(elf_header->ph_offset) + \ - ELF_SIZE_OF_PROGRAM_TABLE(bits,bo,elf_header) > elf_size || \ - yr_##bo##16toh(elf_header->ph_entry_count) == 0) \ - { \ - return YR_UNDEFINED; \ - } \ - \ - program = (elf##bits##_program_header_t*) \ - ((uint8_t*) elf_header + yr_##bo##bits##toh(elf_header->ph_offset)); \ - \ - for (i = 0; i < yr_##bo##16toh(elf_header->ph_entry_count); i++) \ - { \ - if (rva >= yr_##bo##bits##toh(program->virt_addr) && \ - rva < yr_##bo##bits##toh(program->virt_addr) + \ - yr_##bo##bits##toh(program->mem_size)) \ - { \ - return yr_##bo##bits##toh(program->offset) + \ - (rva - yr_##bo##bits##toh(program->virt_addr)); \ - } \ - \ - program++; \ - } \ - } \ - else \ - { \ - int i; \ - \ - elf##bits##_section_header_t* section; \ - \ - /* check that sh_offset doesn't wrap when added to SIZE_OF_SECTION_TABLE */\ - \ - if(ULONG_MAX - yr_##bo##bits##toh(elf_header->sh_offset) < \ - ELF_SIZE_OF_SECTION_TABLE(bits,bo,elf_header)) \ - { \ - return YR_UNDEFINED; \ - } \ - \ - if (yr_##bo##bits##toh(elf_header->sh_offset) == 0 || \ - yr_##bo##bits##toh(elf_header->sh_offset) > elf_size || \ - yr_##bo##bits##toh(elf_header->sh_offset) + \ - ELF_SIZE_OF_SECTION_TABLE(bits,bo,elf_header) > elf_size || \ - yr_##bo##16toh(elf_header->sh_entry_count) == 0) \ - { \ - return YR_UNDEFINED; \ - } \ - \ - section = (elf##bits##_section_header_t*) \ - ((uint8_t*) elf_header + yr_##bo##bits##toh(elf_header->sh_offset)); \ - \ - for (i = 0; i < yr_##bo##16toh(elf_header->sh_entry_count); i++) \ - { \ - if (yr_##bo##32toh(section->type) != ELF_SHT_NULL && \ - yr_##bo##32toh(section->type) != ELF_SHT_NOBITS && \ - rva >= yr_##bo##bits##toh(section->addr) && \ - rva < yr_##bo##bits##toh(section->addr) + \ - yr_##bo##bits##toh(section->size)) \ - { \ - return yr_##bo##bits##toh(section->offset) + \ - (rva - yr_##bo##bits##toh(section->addr)); \ - } \ - \ - section++; \ - } \ - } \ - return YR_UNDEFINED; \ -} +#define ELF_RVA_TO_OFFSET(bits, bo) \ + uint64_t elf_rva_to_offset_##bits##_##bo( \ + elf##bits##_header_t* elf_header, uint64_t rva, size_t elf_size) \ + { \ + if (yr_##bo##16toh(elf_header->type) == ELF_ET_EXEC) \ + { \ + int i; \ + \ + elf##bits##_program_header_t* program; \ + \ + /* check that ph_offset doesn't wrap when added to SIZE_OF_PROGRAM_TABLE \ + */ \ + \ + if (ULONG_MAX - yr_##bo##bits##toh(elf_header->ph_offset) < \ + ELF_SIZE_OF_PROGRAM_TABLE(bits, bo, elf_header)) \ + { \ + return YR_UNDEFINED; \ + } \ + \ + if (yr_##bo##bits##toh(elf_header->ph_offset) == 0 || \ + yr_##bo##bits##toh(elf_header->ph_offset) > elf_size || \ + yr_##bo##bits##toh(elf_header->ph_offset) + \ + ELF_SIZE_OF_PROGRAM_TABLE(bits, bo, elf_header) > \ + elf_size || \ + yr_##bo##16toh(elf_header->ph_entry_count) == 0) \ + { \ + return YR_UNDEFINED; \ + } \ + \ + program = (elf##bits##_program_header_t*) \ + ((uint8_t*) elf_header + yr_##bo##bits##toh(elf_header->ph_offset)); \ + \ + for (i = 0; i < yr_##bo##16toh(elf_header->ph_entry_count); i++) \ + { \ + if (rva >= yr_##bo##bits##toh(program->virt_addr) && \ + rva < yr_##bo##bits##toh(program->virt_addr) + \ + yr_##bo##bits##toh(program->mem_size)) \ + { \ + return yr_##bo##bits##toh(program->offset) + \ + (rva - yr_##bo##bits##toh(program->virt_addr)); \ + } \ + \ + program++; \ + } \ + } \ + else \ + { \ + int i; \ + \ + elf##bits##_section_header_t* section; \ + \ + /* check that sh_offset doesn't wrap when added to SIZE_OF_SECTION_TABLE \ + */ \ + \ + if (ULONG_MAX - yr_##bo##bits##toh(elf_header->sh_offset) < \ + ELF_SIZE_OF_SECTION_TABLE(bits, bo, elf_header)) \ + { \ + return YR_UNDEFINED; \ + } \ + \ + if (yr_##bo##bits##toh(elf_header->sh_offset) == 0 || \ + yr_##bo##bits##toh(elf_header->sh_offset) > elf_size || \ + yr_##bo##bits##toh(elf_header->sh_offset) + \ + ELF_SIZE_OF_SECTION_TABLE(bits, bo, elf_header) > \ + elf_size || \ + yr_##bo##16toh(elf_header->sh_entry_count) == 0) \ + { \ + return YR_UNDEFINED; \ + } \ + \ + section = (elf##bits##_section_header_t*) \ + ((uint8_t*) elf_header + yr_##bo##bits##toh(elf_header->sh_offset)); \ + \ + for (i = 0; i < yr_##bo##16toh(elf_header->sh_entry_count); i++) \ + { \ + if (yr_##bo##32toh(section->type) != ELF_SHT_NULL && \ + yr_##bo##32toh(section->type) != ELF_SHT_NOBITS && \ + rva >= yr_##bo##bits##toh(section->addr) && \ + rva < yr_##bo##bits##toh(section->addr) + \ + yr_##bo##bits##toh(section->size)) \ + { \ + return yr_##bo##bits##toh(section->offset) + \ + (rva - yr_##bo##bits##toh(section->addr)); \ + } \ + \ + section++; \ + } \ + } \ + return YR_UNDEFINED; \ + } -#define PARSE_ELF_HEADER(bits,bo) \ -void parse_elf_header_##bits##_##bo( \ - elf##bits##_header_t* elf, \ - uint64_t base_address, \ - size_t elf_size, \ - int flags, \ - YR_OBJECT* elf_obj) \ -{ \ - unsigned int i, j; \ - const char* elf_raw = (const char*) elf; \ - uint16_t str_table_index = yr_##bo##16toh(elf->sh_str_table_index); \ - \ - const char* sym_table = NULL; \ - const char* sym_str_table = NULL; \ - \ - uint##bits##_t sym_table_size = 0; \ - uint##bits##_t sym_str_table_size = 0; \ - \ - elf##bits##_section_header_t* section_table; \ - elf##bits##_section_header_t* section; \ - elf##bits##_program_header_t* segment; \ - \ - set_integer(yr_##bo##16toh(elf->type), elf_obj, "type"); \ - set_integer(yr_##bo##16toh(elf->machine), elf_obj, "machine"); \ - set_integer(yr_##bo##bits##toh(elf->sh_offset), elf_obj, \ - "sh_offset"); \ - set_integer(yr_##bo##16toh(elf->sh_entry_size), elf_obj, \ - "sh_entry_size"); \ - set_integer(yr_##bo##16toh(elf->sh_entry_count), elf_obj, \ - "number_of_sections"); \ - set_integer(yr_##bo##bits##toh(elf->ph_offset), elf_obj, \ - "ph_offset"); \ - set_integer(yr_##bo##16toh(elf->ph_entry_size), elf_obj, \ - "ph_entry_size"); \ - set_integer(yr_##bo##16toh(elf->ph_entry_count), elf_obj, \ - "number_of_segments"); \ - \ - if (yr_##bo##bits##toh(elf->entry) != 0) \ - { \ - set_integer( \ - flags & SCAN_FLAGS_PROCESS_MEMORY ? \ - base_address + yr_##bo##bits##toh(elf->entry) : \ - elf_rva_to_offset_##bits##_##bo( \ - elf, yr_##bo##bits##toh(elf->entry), elf_size), \ - elf_obj, "entry_point"); \ - } \ - \ - if (yr_##bo##16toh(elf->sh_entry_count) < ELF_SHN_LORESERVE && \ - str_table_index < yr_##bo##16toh(elf->sh_entry_count) && \ - yr_##bo##bits##toh(elf->sh_offset) < elf_size && \ - yr_##bo##bits##toh(elf->sh_offset) + \ - yr_##bo##16toh(elf->sh_entry_count) * \ - sizeof(elf##bits##_section_header_t) <= elf_size) \ - { \ - const char* str_table = NULL; \ - \ - section_table = (elf##bits##_section_header_t*) \ - (elf_raw + yr_##bo##bits##toh(elf->sh_offset)); \ - \ - if (yr_##bo##bits##toh(section_table[str_table_index].offset) < elf_size) \ - { \ - str_table = elf_raw + yr_##bo##bits##toh( \ - section_table[str_table_index].offset); \ - } \ - \ - section = section_table; \ - \ - for (i = 0; i < yr_##bo##16toh(elf->sh_entry_count); i++, section++) \ - { \ - set_integer(yr_##bo##32toh(section->type), elf_obj, \ - "sections[%i].type", i); \ - set_integer(yr_##bo##bits##toh(section->flags), elf_obj, \ - "sections[%i].flags", i); \ - set_integer(yr_##bo##bits##toh(section->addr), elf_obj, \ - "sections[%i].address", i); \ - set_integer(yr_##bo##bits##toh(section->size), elf_obj, \ - "sections[%i].size", i); \ - set_integer(yr_##bo##bits##toh(section->offset), elf_obj, \ - "sections[%i].offset", i); \ - \ - if (yr_##bo##32toh(section->name) < elf_size && str_table > elf_raw) \ - { \ - const char* section_name = str_table_entry( \ - str_table, \ - elf_raw + elf_size, \ - yr_##bo##32toh(section->name)); \ - \ - if (section_name) \ - set_string(section_name, elf_obj, "sections[%i].name", i); \ - } \ - \ - if (yr_##bo##32toh(section->type) == ELF_SHT_SYMTAB && \ - yr_##bo##32toh(section->link) < elf->sh_entry_count) \ - { \ - elf##bits##_section_header_t* string_section = \ - section_table + yr_##bo##32toh(section->link); \ - \ - if (IS_VALID_PTR(elf, elf_size, string_section) && \ - yr_##bo##32toh(string_section->type) == ELF_SHT_STRTAB) \ - { \ - sym_table = elf_raw + yr_##bo##bits##toh(section->offset); \ - sym_str_table = elf_raw + yr_##bo##bits##toh(string_section->offset);\ - sym_table_size = yr_##bo##bits##toh(section->size); \ - sym_str_table_size = yr_##bo##bits##toh(string_section->size); \ - } \ - } \ - } \ - \ - if (is_valid_ptr(elf, elf_size, sym_str_table, sym_str_table_size) && \ - is_valid_ptr(elf, elf_size, sym_table, sym_table_size)) \ - { \ - elf##bits##_sym_t* sym = (elf##bits##_sym_t*) sym_table; \ - \ - for (j = 0; j < sym_table_size / sizeof(elf##bits##_sym_t); j++, sym++) \ - { \ - const char* sym_name = str_table_entry( \ - sym_str_table, \ - sym_str_table + sym_str_table_size, \ - yr_##bo##32toh(sym->name)); \ - \ - if (sym_name) \ - set_string(sym_name, elf_obj, "symtab[%i].name", j); \ - \ - set_integer(sym->info >> 4, elf_obj, \ - "symtab[%i].bind", j); \ - set_integer(sym->info & 0xf, elf_obj, \ - "symtab[%i].type", j); \ - set_integer(yr_##bo##16toh(sym->shndx), elf_obj, \ - "symtab[%i].shndx", j); \ - set_integer(yr_##bo##bits##toh(sym->value), elf_obj, \ - "symtab[%i].value", j); \ - set_integer(yr_##bo##bits##toh(sym->size), elf_obj, \ - "symtab[%i].size", j); \ - } \ - \ - set_integer(j, elf_obj, "symtab_entries"); \ - } \ - } \ - \ - if (yr_##bo##16toh(elf->ph_entry_count) > 0 && \ - yr_##bo##16toh(elf->ph_entry_count) < ELF_PN_XNUM && \ - yr_##bo##bits##toh(elf->ph_offset) < elf_size && \ - yr_##bo##bits##toh(elf->ph_offset) + \ - yr_##bo##16toh(elf->ph_entry_count) * \ - sizeof(elf##bits##_program_header_t) <= elf_size) \ - { \ - segment = (elf##bits##_program_header_t*) \ - (elf_raw + yr_##bo##bits##toh(elf->ph_offset)); \ - \ - for (i = 0; i < yr_##bo##16toh(elf->ph_entry_count); i++, segment++) \ - { \ - set_integer( \ - yr_##bo##32toh(segment->type), elf_obj, "segments[%i].type", i); \ - set_integer( \ - yr_##bo##32toh(segment->flags), elf_obj, "segments[%i].flags", i); \ - set_integer( \ - yr_##bo##bits##toh(segment->offset), elf_obj, \ - "segments[%i].offset", i); \ - set_integer( \ - yr_##bo##bits##toh(segment->virt_addr), elf_obj, \ - "segments[%i].virtual_address", i); \ - set_integer( \ - yr_##bo##bits##toh(segment->phys_addr), elf_obj, \ - "segments[%i].physical_address", i); \ - set_integer( \ - yr_##bo##bits##toh(segment->file_size), elf_obj, \ - "segments[%i].file_size", i); \ - set_integer( \ - yr_##bo##bits##toh(segment->mem_size), elf_obj, \ - "segments[%i].memory_size", i); \ - set_integer( \ - yr_##bo##bits##toh(segment->alignment), elf_obj, \ - "segments[%i].alignment", i); \ - \ - if (yr_##bo##32toh(segment->type) == ELF_PT_DYNAMIC) \ - { \ - elf##bits##_dyn_t* dyn = (elf##bits##_dyn_t*) \ - (elf_raw + yr_##bo##bits##toh(segment->offset)); \ - \ - for (j = 0; IS_VALID_PTR(elf, elf_size, dyn); dyn++, j++) \ - { \ - set_integer( \ - yr_##bo##bits##toh(dyn->tag), elf_obj, "dynamic[%i].type", j); \ - set_integer( \ - yr_##bo##bits##toh(dyn->val), elf_obj, "dynamic[%i].val", j); \ - \ - if (dyn->tag == ELF_DT_NULL) \ - { \ - j++; \ - break; \ - } \ - } \ - set_integer(j, elf_obj, "dynamic_section_entries"); \ - } \ - } \ - } \ -} +#define PARSE_ELF_HEADER(bits, bo) \ + void parse_elf_header_##bits##_##bo( \ + elf##bits##_header_t* elf, \ + uint64_t base_address, \ + size_t elf_size, \ + int flags, \ + YR_OBJECT* elf_obj) \ + { \ + unsigned int i, j; \ + const char* elf_raw = (const char*) elf; \ + uint16_t str_table_index = yr_##bo##16toh(elf->sh_str_table_index); \ + \ + const char* sym_table = NULL; \ + const char* sym_str_table = NULL; \ + \ + uint##bits##_t sym_table_size = 0; \ + uint##bits##_t sym_str_table_size = 0; \ + \ + elf##bits##_section_header_t* section_table; \ + elf##bits##_section_header_t* section; \ + elf##bits##_program_header_t* segment; \ + \ + set_integer(yr_##bo##16toh(elf->type), elf_obj, "type"); \ + set_integer(yr_##bo##16toh(elf->machine), elf_obj, "machine"); \ + set_integer(yr_##bo##bits##toh(elf->sh_offset), elf_obj, "sh_offset"); \ + set_integer(yr_##bo##16toh(elf->sh_entry_size), elf_obj, "sh_entry_size"); \ + set_integer( \ + yr_##bo##16toh(elf->sh_entry_count), elf_obj, "number_of_sections"); \ + set_integer(yr_##bo##bits##toh(elf->ph_offset), elf_obj, "ph_offset"); \ + set_integer(yr_##bo##16toh(elf->ph_entry_size), elf_obj, "ph_entry_size"); \ + set_integer( \ + yr_##bo##16toh(elf->ph_entry_count), elf_obj, "number_of_segments"); \ + \ + if (yr_##bo##bits##toh(elf->entry) != 0) \ + { \ + set_integer( \ + flags& SCAN_FLAGS_PROCESS_MEMORY \ + ? base_address + yr_##bo##bits##toh(elf->entry) \ + : elf_rva_to_offset_##bits##_##bo( \ + elf, yr_##bo##bits##toh(elf->entry), elf_size), \ + elf_obj, \ + "entry_point"); \ + } \ + \ + if (yr_##bo##16toh(elf->sh_entry_count) < ELF_SHN_LORESERVE && \ + str_table_index < yr_##bo##16toh(elf->sh_entry_count) && \ + yr_##bo##bits##toh(elf->sh_offset) < elf_size && \ + yr_##bo##bits##toh(elf->sh_offset) + \ + yr_##bo##16toh(elf->sh_entry_count) * \ + sizeof(elf##bits##_section_header_t) <= \ + elf_size) \ + { \ + const char* str_table = NULL; \ + \ + section_table = \ + (elf##bits##_section_header_t*) (elf_raw + yr_##bo##bits##toh(elf->sh_offset)); \ + \ + if (yr_##bo##bits##toh(section_table[str_table_index].offset) < \ + elf_size) \ + { \ + str_table = elf_raw + \ + yr_##bo##bits##toh(section_table[str_table_index].offset); \ + } \ + \ + section = section_table; \ + \ + for (i = 0; i < yr_##bo##16toh(elf->sh_entry_count); i++, section++) \ + { \ + set_integer( \ + yr_##bo##32toh(section->type), elf_obj, "sections[%i].type", i); \ + set_integer( \ + yr_##bo##bits##toh(section->flags), \ + elf_obj, \ + "sections[%i].flags", \ + i); \ + set_integer( \ + yr_##bo##bits##toh(section->addr), \ + elf_obj, \ + "sections[%i].address", \ + i); \ + set_integer( \ + yr_##bo##bits##toh(section->size), \ + elf_obj, \ + "sections[%i].size", \ + i); \ + set_integer( \ + yr_##bo##bits##toh(section->offset), \ + elf_obj, \ + "sections[%i].offset", \ + i); \ + \ + if (yr_##bo##32toh(section->name) < elf_size && str_table > elf_raw) \ + { \ + const char* section_name = str_table_entry( \ + str_table, elf_raw + elf_size, yr_##bo##32toh(section->name)); \ + \ + if (section_name) \ + set_string(section_name, elf_obj, "sections[%i].name", i); \ + } \ + \ + if (yr_##bo##32toh(section->type) == ELF_SHT_SYMTAB && \ + yr_##bo##32toh(section->link) < elf->sh_entry_count) \ + { \ + elf##bits##_section_header_t* string_section = section_table + \ + yr_##bo##32toh( \ + section->link); \ + \ + if (IS_VALID_PTR(elf, elf_size, string_section) && \ + yr_##bo##32toh(string_section->type) == ELF_SHT_STRTAB) \ + { \ + sym_table = elf_raw + yr_##bo##bits##toh(section->offset); \ + sym_str_table = elf_raw + \ + yr_##bo##bits##toh(string_section->offset); \ + sym_table_size = yr_##bo##bits##toh(section->size); \ + sym_str_table_size = yr_##bo##bits##toh(string_section->size); \ + } \ + } \ + } \ + \ + if (is_valid_ptr(elf, elf_size, sym_str_table, sym_str_table_size) && \ + is_valid_ptr(elf, elf_size, sym_table, sym_table_size)) \ + { \ + elf##bits##_sym_t* sym = (elf##bits##_sym_t*) sym_table; \ + \ + for (j = 0; j < sym_table_size / sizeof(elf##bits##_sym_t); \ + j++, sym++) \ + { \ + const char* sym_name = str_table_entry( \ + sym_str_table, \ + sym_str_table + sym_str_table_size, \ + yr_##bo##32toh(sym->name)); \ + \ + if (sym_name) \ + set_string(sym_name, elf_obj, "symtab[%i].name", j); \ + \ + set_integer(sym->info >> 4, elf_obj, "symtab[%i].bind", j); \ + set_integer(sym->info & 0xf, elf_obj, "symtab[%i].type", j); \ + set_integer( \ + yr_##bo##16toh(sym->shndx), elf_obj, "symtab[%i].shndx", j); \ + set_integer( \ + yr_##bo##bits##toh(sym->value), elf_obj, "symtab[%i].value", j); \ + set_integer( \ + yr_##bo##bits##toh(sym->size), elf_obj, "symtab[%i].size", j); \ + } \ + \ + set_integer(j, elf_obj, "symtab_entries"); \ + } \ + } \ + \ + if (yr_##bo##16toh(elf->ph_entry_count) > 0 && \ + yr_##bo##16toh(elf->ph_entry_count) < ELF_PN_XNUM && \ + yr_##bo##bits##toh(elf->ph_offset) < elf_size && \ + yr_##bo##bits##toh(elf->ph_offset) + \ + yr_##bo##16toh(elf->ph_entry_count) * \ + sizeof(elf##bits##_program_header_t) <= \ + elf_size) \ + { \ + segment = \ + (elf##bits##_program_header_t*) (elf_raw + yr_##bo##bits##toh(elf->ph_offset)); \ + \ + for (i = 0; i < yr_##bo##16toh(elf->ph_entry_count); i++, segment++) \ + { \ + set_integer( \ + yr_##bo##32toh(segment->type), elf_obj, "segments[%i].type", i); \ + set_integer( \ + yr_##bo##32toh(segment->flags), elf_obj, "segments[%i].flags", i); \ + set_integer( \ + yr_##bo##bits##toh(segment->offset), \ + elf_obj, \ + "segments[%i].offset", \ + i); \ + set_integer( \ + yr_##bo##bits##toh(segment->virt_addr), \ + elf_obj, \ + "segments[%i].virtual_address", \ + i); \ + set_integer( \ + yr_##bo##bits##toh(segment->phys_addr), \ + elf_obj, \ + "segments[%i].physical_address", \ + i); \ + set_integer( \ + yr_##bo##bits##toh(segment->file_size), \ + elf_obj, \ + "segments[%i].file_size", \ + i); \ + set_integer( \ + yr_##bo##bits##toh(segment->mem_size), \ + elf_obj, \ + "segments[%i].memory_size", \ + i); \ + set_integer( \ + yr_##bo##bits##toh(segment->alignment), \ + elf_obj, \ + "segments[%i].alignment", \ + i); \ + \ + if (yr_##bo##32toh(segment->type) == ELF_PT_DYNAMIC) \ + { \ + elf##bits##_dyn_t* dyn = \ + (elf##bits##_dyn_t*) (elf_raw + yr_##bo##bits##toh(segment->offset)); \ + \ + for (j = 0; IS_VALID_PTR(elf, elf_size, dyn); dyn++, j++) \ + { \ + set_integer( \ + yr_##bo##bits##toh(dyn->tag), elf_obj, "dynamic[%i].type", j); \ + set_integer( \ + yr_##bo##bits##toh(dyn->val), elf_obj, "dynamic[%i].val", j); \ + \ + if (dyn->tag == ELF_DT_NULL) \ + { \ + j++; \ + break; \ + } \ + } \ + set_integer(j, elf_obj, "dynamic_section_entries"); \ + } \ + } \ + } \ + } -ELF_RVA_TO_OFFSET(32,le); -ELF_RVA_TO_OFFSET(64,le); -ELF_RVA_TO_OFFSET(32,be); -ELF_RVA_TO_OFFSET(64,be); +ELF_RVA_TO_OFFSET(32, le); +ELF_RVA_TO_OFFSET(64, le); +ELF_RVA_TO_OFFSET(32, be); +ELF_RVA_TO_OFFSET(64, be); -PARSE_ELF_HEADER(32,le); -PARSE_ELF_HEADER(64,le); -PARSE_ELF_HEADER(32,be); -PARSE_ELF_HEADER(64,be); +PARSE_ELF_HEADER(32, le); +PARSE_ELF_HEADER(64, le); +PARSE_ELF_HEADER(32, be); +PARSE_ELF_HEADER(64, be); -begin_declarations; +begin_declarations + ; declare_integer("ET_NONE"); declare_integer("ET_REL"); @@ -468,7 +491,8 @@ begin_declarations; declare_integer("ph_offset"); declare_integer("ph_entry_size"); - begin_struct_array("sections"); + begin_struct_array("sections") + ; declare_integer("type"); declare_integer("flags"); declare_integer("address"); @@ -537,7 +561,8 @@ begin_declarations; declare_integer("PF_W"); declare_integer("PF_R"); - begin_struct_array("segments"); + begin_struct_array("segments") + ; declare_integer("type"); declare_integer("flags"); declare_integer("offset"); @@ -549,13 +574,15 @@ begin_declarations; end_struct_array("segments"); declare_integer("dynamic_section_entries"); - begin_struct_array("dynamic"); + begin_struct_array("dynamic") + ; declare_integer("type"); declare_integer("val"); end_struct_array("dynamic"); declare_integer("symtab_entries"); - begin_struct_array("symtab"); + begin_struct_array("symtab") + ; declare_string("name"); declare_integer("value"); declare_integer("size"); @@ -567,15 +594,13 @@ begin_declarations; end_declarations; -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { return ERROR_SUCCESS; } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { return ERROR_SUCCESS; } @@ -698,87 +723,87 @@ int module_load( if (block_data == NULL) continue; - switch(get_elf_class_data(block_data, block->size)) + switch (get_elf_class_data(block_data, block->size)) { - case CLASS_DATA(ELF_CLASS_32, ELF_DATA_2LSB): + case CLASS_DATA(ELF_CLASS_32, ELF_DATA_2LSB): + + if (block->size > sizeof(elf32_header_t)) + { + elf_header32 = (elf32_header_t*) block_data; - if (block->size > sizeof(elf32_header_t)) + if (!(context->flags & SCAN_FLAGS_PROCESS_MEMORY) || + yr_le16toh(elf_header32->type) == ELF_ET_EXEC) { - elf_header32 = (elf32_header_t*) block_data; - - if (!(context->flags & SCAN_FLAGS_PROCESS_MEMORY) || - yr_le16toh(elf_header32->type) == ELF_ET_EXEC) - { - parse_elf_header_32_le( - elf_header32, - block->base, - block->size, - context->flags, - module_object); - } + parse_elf_header_32_le( + elf_header32, + block->base, + block->size, + context->flags, + module_object); } + } + + break; - break; + case CLASS_DATA(ELF_CLASS_32, ELF_DATA_2MSB): - case CLASS_DATA(ELF_CLASS_32, ELF_DATA_2MSB): + if (block->size > sizeof(elf32_header_t)) + { + elf_header32 = (elf32_header_t*) block_data; - if (block->size > sizeof(elf32_header_t)) + if (!(context->flags & SCAN_FLAGS_PROCESS_MEMORY) || + yr_be16toh(elf_header32->type) == ELF_ET_EXEC) { - elf_header32 = (elf32_header_t*) block_data; - - if (!(context->flags & SCAN_FLAGS_PROCESS_MEMORY) || - yr_be16toh(elf_header32->type) == ELF_ET_EXEC) - { - parse_elf_header_32_be( - elf_header32, - block->base, - block->size, - context->flags, - module_object); - } + parse_elf_header_32_be( + elf_header32, + block->base, + block->size, + context->flags, + module_object); } + } - break; + break; - case CLASS_DATA(ELF_CLASS_64,ELF_DATA_2LSB): + case CLASS_DATA(ELF_CLASS_64, ELF_DATA_2LSB): - if (block->size > sizeof(elf64_header_t)) + if (block->size > sizeof(elf64_header_t)) + { + elf_header64 = (elf64_header_t*) block_data; + + if (!(context->flags & SCAN_FLAGS_PROCESS_MEMORY) || + yr_le16toh(elf_header64->type) == ELF_ET_EXEC) { - elf_header64 = (elf64_header_t*) block_data; - - if (!(context->flags & SCAN_FLAGS_PROCESS_MEMORY) || - yr_le16toh(elf_header64->type) == ELF_ET_EXEC) - { - parse_elf_header_64_le( - elf_header64, - block->base, - block->size, - context->flags, - module_object); - } + parse_elf_header_64_le( + elf_header64, + block->base, + block->size, + context->flags, + module_object); } + } + + break; - break; + case CLASS_DATA(ELF_CLASS_64, ELF_DATA_2MSB): - case CLASS_DATA(ELF_CLASS_64,ELF_DATA_2MSB): + if (block->size > sizeof(elf64_header_t)) + { + elf_header64 = (elf64_header_t*) block_data; - if (block->size > sizeof(elf64_header_t)) + if (!(context->flags & SCAN_FLAGS_PROCESS_MEMORY) || + yr_be16toh(elf_header64->type) == ELF_ET_EXEC) { - elf_header64 = (elf64_header_t*) block_data; - - if (!(context->flags & SCAN_FLAGS_PROCESS_MEMORY) || - yr_be16toh(elf_header64->type) == ELF_ET_EXEC) - { - parse_elf_header_64_be( - elf_header64, - block->base, - block->size, - context->flags, - module_object); - } + parse_elf_header_64_be( + elf_header64, + block->base, + block->size, + context->flags, + module_object); } + } - break; + break; } } diff --git a/libyara/modules/hash/hash.c b/libyara/modules/hash/hash.c index 47704bf0e0..cc02e58f40 100644 --- a/libyara/modules/hash/hash.c +++ b/libyara/modules/hash/hash.c @@ -27,11 +27,11 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "../crypto.h" - +#include #include #include -#include + +#include "../crypto.h" #define MODULE_NAME hash @@ -45,50 +45,49 @@ typedef struct _CACHE_KEY const uint32_t crc32_tab[] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d -}; + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; static void digest_to_ascii( @@ -118,13 +117,16 @@ static char* get_from_cache( key.length = length; char* result = (char*) yr_hash_table_lookup_raw_key( - hash_table, - &key, - sizeof(key), - ns); + hash_table, &key, sizeof(key), ns); - YR_DEBUG_FPRINTF(2, stderr, "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {} = %p\n", - __FUNCTION__, offset, length, result); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {} = %p\n", + __FUNCTION__, + offset, + length, + result); return result; } @@ -149,14 +151,17 @@ static int add_to_cache( return ERROR_INSUFFICIENT_MEMORY; int result = yr_hash_table_add_raw_key( - hash_table, - &key, - sizeof(key), - ns, - (void*) copy); - - YR_DEBUG_FPRINTF(2, stderr, "+ %s(offset=%" PRIi64 " length=%" PRIi64 " digest=%s) {} = %d\n", - __FUNCTION__, offset, length, digest, result); + hash_table, &key, sizeof(key), ns, (void*) copy); + + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s(offset=%" PRIi64 " length=%" PRIi64 " digest=%s) {} = %d\n", + __FUNCTION__, + offset, + length, + digest, + result); return result; } @@ -176,8 +181,13 @@ define_function(string_md5) digest_to_ascii(digest, digest_ascii, YR_MD5_LEN); - YR_DEBUG_FPRINTF(2, stderr, "+ %s() {} = 0x%s // s->length=%u\n", - __FUNCTION__, digest_ascii, s->length); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s() {} = 0x%s // s->length=%u\n", + __FUNCTION__, + digest_ascii, + s->length); return_string(digest_ascii); } @@ -197,8 +207,13 @@ define_function(string_sha256) digest_to_ascii(digest, digest_ascii, YR_SHA256_LEN); - YR_DEBUG_FPRINTF(2, stderr, "+ %s() {} = 0x%s // s->length=%u\n", - __FUNCTION__, digest_ascii, s->length); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s() {} = 0x%s // s->length=%u\n", + __FUNCTION__, + digest_ascii, + s->length); return_string(digest_ascii); } @@ -218,8 +233,13 @@ define_function(string_sha1) digest_to_ascii(digest, digest_ascii, YR_SHA1_LEN); - YR_DEBUG_FPRINTF(2, stderr, "+ %s() {} = 0x%s // s->length=%u\n", - __FUNCTION__, digest_ascii, s->length); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s() {} = 0x%s // s->length=%u\n", + __FUNCTION__, + digest_ascii, + s->length); return_string(digest_ascii); } @@ -232,11 +252,15 @@ define_function(string_checksum32) SIZED_STRING* s = sized_string_argument(1); uint32_t checksum = 0; - for (i = 0; i < s->length; i++) - checksum += (uint8_t)(s->c_string[i]); + for (i = 0; i < s->length; i++) checksum += (uint8_t)(s->c_string[i]); - YR_DEBUG_FPRINTF(2, stderr, "+ %s() {} = 0x%x // s->length=%u\n", - __FUNCTION__, checksum, s->length); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s() {} = 0x%x // s->length=%u\n", + __FUNCTION__, + checksum, + s->length); return_integer(checksum); } @@ -256,18 +280,24 @@ define_function(data_md5) YR_MEMORY_BLOCK* block = first_memory_block(context); YR_MEMORY_BLOCK_ITERATOR* iterator = context->iterator; - int64_t arg_offset = integer_argument(1); // offset where to start - int64_t arg_length = integer_argument(2); // length of bytes we want hash on + int64_t arg_offset = integer_argument(1); // offset where to start + int64_t arg_length = integer_argument(2); // length of bytes we want hash on int64_t offset = arg_offset; int64_t length = arg_length; - YR_DEBUG_FPRINTF(2, stderr, "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {\n", - __FUNCTION__, offset, length); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {\n", + __FUNCTION__, + offset, + length); if (block == NULL) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // block == NULL\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, stderr, "} // %s() = YR_UNDEFINED // block == NULL\n", __FUNCTION__); return_string(YR_UNDEFINED); } @@ -275,16 +305,24 @@ define_function(data_md5) if (offset < 0 || length < 0 || offset < block->base) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // bad offset / length\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = YR_UNDEFINED // bad offset / length\n", + __FUNCTION__); return_string(YR_UNDEFINED); } - cached_ascii_digest = get_from_cache( - module(), "md5", arg_offset, arg_length); + cached_ascii_digest = get_from_cache(module(), "md5", arg_offset, arg_length); if (cached_ascii_digest != NULL) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = %s (cached)\n", __FUNCTION__, cached_ascii_digest); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = %s (cached)\n", + __FUNCTION__, + cached_ascii_digest); return_string(cached_ascii_digest); } @@ -292,16 +330,15 @@ define_function(data_md5) { // if desired block within current block - if (offset >= block->base && - offset < block->base + block->size) + if (offset >= block->base && offset < block->base + block->size) { const uint8_t* block_data = block->fetch_data(block); if (block_data != NULL) { - size_t data_offset = (size_t) (offset - block->base); + size_t data_offset = (size_t)(offset - block->base); size_t data_len = (size_t) yr_min( - length, (size_t) (block->size - data_offset)); + length, (size_t)(block->size - data_offset)); offset += data_len; length -= data_len; @@ -319,7 +356,11 @@ define_function(data_md5) // range contains gaps of undefined data the checksum is // undefined. - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // past_first_block\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = YR_UNDEFINED // past_first_block\n", + __FUNCTION__); return_string(YR_UNDEFINED); } @@ -329,7 +370,11 @@ define_function(data_md5) if (!past_first_block) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // !past_first_block\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = YR_UNDEFINED // !past_first_block\n", + __FUNCTION__); return_string(YR_UNDEFINED); } @@ -355,8 +400,8 @@ define_function(data_sha1) int past_first_block = false; - int64_t arg_offset = integer_argument(1); // offset where to start - int64_t arg_length = integer_argument(2); // length of bytes we want hash on + int64_t arg_offset = integer_argument(1); // offset where to start + int64_t arg_length = integer_argument(2); // length of bytes we want hash on int64_t offset = arg_offset; int64_t length = arg_length; @@ -365,12 +410,18 @@ define_function(data_sha1) YR_MEMORY_BLOCK* block = first_memory_block(context); YR_MEMORY_BLOCK_ITERATOR* iterator = context->iterator; - YR_DEBUG_FPRINTF(2, stderr, "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {\n", - __FUNCTION__, offset, length); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {\n", + __FUNCTION__, + offset, + length); if (block == NULL) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // block == NULL\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, stderr, "} // %s() = YR_UNDEFINED // block == NULL\n", __FUNCTION__); return_string(YR_UNDEFINED); } @@ -378,7 +429,11 @@ define_function(data_sha1) if (offset < 0 || length < 0 || offset < block->base) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // bad offset / length\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = YR_UNDEFINED // bad offset / length\n", + __FUNCTION__); return_string(YR_UNDEFINED); } @@ -387,23 +442,27 @@ define_function(data_sha1) if (cached_ascii_digest != NULL) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = %s (cached)\n", __FUNCTION__, cached_ascii_digest); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = %s (cached)\n", + __FUNCTION__, + cached_ascii_digest); return_string(cached_ascii_digest); } foreach_memory_block(iterator, block) { // if desired block within current block - if (offset >= block->base && - offset < block->base + block->size) + if (offset >= block->base && offset < block->base + block->size) { const uint8_t* block_data = block->fetch_data(block); if (block_data != NULL) { - size_t data_offset = (size_t) (offset - block->base); + size_t data_offset = (size_t)(offset - block->base); size_t data_len = (size_t) yr_min( - length, (size_t) block->size - data_offset); + length, (size_t) block->size - data_offset); offset += data_len; length -= data_len; @@ -421,7 +480,11 @@ define_function(data_sha1) // range contains gaps of undefined data the checksum is // undefined. - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // past_first_block\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = YR_UNDEFINED // past_first_block\n", + __FUNCTION__); return_string(YR_UNDEFINED); } @@ -431,7 +494,11 @@ define_function(data_sha1) if (!past_first_block) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // !past_first_block\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = YR_UNDEFINED // !past_first_block\n", + __FUNCTION__); return_string(YR_UNDEFINED); } @@ -457,8 +524,8 @@ define_function(data_sha256) int past_first_block = false; - int64_t arg_offset = integer_argument(1); // offset where to start - int64_t arg_length = integer_argument(2); // length of bytes we want hash on + int64_t arg_offset = integer_argument(1); // offset where to start + int64_t arg_length = integer_argument(2); // length of bytes we want hash on int64_t offset = arg_offset; int64_t length = arg_length; @@ -467,12 +534,18 @@ define_function(data_sha256) YR_MEMORY_BLOCK* block = first_memory_block(context); YR_MEMORY_BLOCK_ITERATOR* iterator = context->iterator; - YR_DEBUG_FPRINTF(2, stderr, "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {\n", - __FUNCTION__, offset, length); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {\n", + __FUNCTION__, + offset, + length); if (block == NULL) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // block == NULL\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, stderr, "} // %s() = YR_UNDEFINED // block == NULL\n", __FUNCTION__); return_string(YR_UNDEFINED); } @@ -480,7 +553,11 @@ define_function(data_sha256) if (offset < 0 || length < 0 || offset < block->base) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // bad offset / length\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = YR_UNDEFINED // bad offset / length\n", + __FUNCTION__); return_string(YR_UNDEFINED); } @@ -489,21 +566,25 @@ define_function(data_sha256) if (cached_ascii_digest != NULL) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = %s (cached)\n", __FUNCTION__, cached_ascii_digest); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = %s (cached)\n", + __FUNCTION__, + cached_ascii_digest); return_string(cached_ascii_digest); } foreach_memory_block(iterator, block) { // if desired block within current block - if (offset >= block->base && - offset < block->base + block->size) + if (offset >= block->base && offset < block->base + block->size) { const uint8_t* block_data = block->fetch_data(block); if (block_data != NULL) { - size_t data_offset = (size_t) (offset - block->base); + size_t data_offset = (size_t)(offset - block->base); size_t data_len = (size_t) yr_min(length, block->size - data_offset); offset += data_len; @@ -522,7 +603,11 @@ define_function(data_sha256) // range contains gaps of undefined data the checksum is // undefined. - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // past_first_block\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = YR_UNDEFINED // past_first_block\n", + __FUNCTION__); return_string(YR_UNDEFINED); } @@ -532,7 +617,11 @@ define_function(data_sha256) if (!past_first_block) { - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = YR_UNDEFINED // !past_first_block\n", __FUNCTION__); + YR_DEBUG_FPRINTF( + 2, + stderr, + "} // %s() = YR_UNDEFINED // !past_first_block\n", + __FUNCTION__); return_string(YR_UNDEFINED); } @@ -550,11 +639,16 @@ define_function(data_sha256) define_function(data_checksum32) { - int64_t offset = integer_argument(1); // offset where to start - int64_t length = integer_argument(2); // length of bytes we want hash on + int64_t offset = integer_argument(1); // offset where to start + int64_t length = integer_argument(2); // length of bytes we want hash on - YR_DEBUG_FPRINTF(2, stderr, "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {\n", - __FUNCTION__, offset, length); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {\n", + __FUNCTION__, + offset, + length); YR_SCAN_CONTEXT* context = scan_context(); YR_MEMORY_BLOCK* block = first_memory_block(context); @@ -571,8 +665,7 @@ define_function(data_checksum32) foreach_memory_block(iterator, block) { - if (offset >= block->base && - offset < block->base + block->size) + if (offset >= block->base && offset < block->base + block->size) { const uint8_t* block_data = block->fetch_data(block); @@ -580,7 +673,7 @@ define_function(data_checksum32) { size_t i; - size_t data_offset = (size_t) (offset - block->base); + size_t data_offset = (size_t)(offset - block->base); size_t data_len = (size_t) yr_min(length, block->size - data_offset); offset += data_len; @@ -622,10 +715,16 @@ define_function(string_crc32) uint32_t checksum = 0xFFFFFFFF; for (i = 0; i < s->length; i++) - checksum = crc32_tab[(checksum ^ (uint8_t)s->c_string[i]) & 0xFF] ^ (checksum >> 8); + checksum = crc32_tab[(checksum ^ (uint8_t) s->c_string[i]) & 0xFF] ^ + (checksum >> 8); - YR_DEBUG_FPRINTF(2, stderr, "+ %s() {} = 0x%x // s->length=%u\n", - __FUNCTION__, checksum ^ 0xFFFFFFFF, s->length); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s() {} = 0x%x // s->length=%u\n", + __FUNCTION__, + checksum ^ 0xFFFFFFFF, + s->length); return_integer(checksum ^ 0xFFFFFFFF); } @@ -633,16 +732,21 @@ define_function(string_crc32) define_function(data_crc32) { - int64_t offset = integer_argument(1); // offset where to start - int64_t length = integer_argument(2); // length of bytes we want hash on + int64_t offset = integer_argument(1); // offset where to start + int64_t length = integer_argument(2); // length of bytes we want hash on uint32_t checksum = 0xFFFFFFFF; YR_SCAN_CONTEXT* context = scan_context(); YR_MEMORY_BLOCK* block = first_memory_block(context); YR_MEMORY_BLOCK_ITERATOR* iterator = context->iterator; - YR_DEBUG_FPRINTF(2, stderr, "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {\n", - __FUNCTION__, offset, length); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s(offset=%" PRIi64 " length=%" PRIi64 ") {\n", + __FUNCTION__, + offset, + length); int past_first_block = false; @@ -654,8 +758,7 @@ define_function(data_crc32) foreach_memory_block(iterator, block) { - if (offset >= block->base && - offset < block->base + block->size) + if (offset >= block->base && offset < block->base + block->size) { const uint8_t* block_data = block->fetch_data(block); @@ -663,14 +766,16 @@ define_function(data_crc32) { size_t i; - size_t data_offset = (size_t) (offset - block->base); + size_t data_offset = (size_t)(offset - block->base); size_t data_len = (size_t) yr_min(length, block->size - data_offset); offset += data_len; length -= data_len; for (i = 0; i < data_len; i++) - checksum = crc32_tab[(checksum ^ *(block_data + data_offset + i)) & 0xFF] ^ (checksum >> 8); + checksum = + crc32_tab[(checksum ^ *(block_data + data_offset + i)) & 0xFF] ^ + (checksum >> 8); } past_first_block = true; @@ -693,13 +798,14 @@ define_function(data_crc32) if (!past_first_block) return_integer(YR_UNDEFINED); - YR_DEBUG_FPRINTF(2, stderr, "} // %s() = 0x%x\n", __FUNCTION__, checksum ^ 0xFFFFFFFF); + YR_DEBUG_FPRINTF( + 2, stderr, "} // %s() = 0x%x\n", __FUNCTION__, checksum ^ 0xFFFFFFFF); return_integer(checksum ^ 0xFFFFFFFF); } - -begin_declarations; +begin_declarations + ; declare_function("md5", "ii", "s", data_md5); declare_function("md5", "s", "s", string_md5); @@ -719,8 +825,7 @@ begin_declarations; end_declarations; -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { YR_DEBUG_FPRINTF(2, stderr, "+ %s() {}\n", __FUNCTION__); @@ -728,8 +833,7 @@ int module_initialize( } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { YR_DEBUG_FPRINTF(2, stderr, "+ %s() {}\n", __FUNCTION__); @@ -755,17 +859,14 @@ int module_load( } -int module_unload( - YR_OBJECT* module_object) +int module_unload(YR_OBJECT* module_object) { YR_DEBUG_FPRINTF(2, stderr, "+ %s() {}\n", __FUNCTION__); YR_HASH_TABLE* hash_table = (YR_HASH_TABLE*) module_object->data; if (hash_table != NULL) - yr_hash_table_destroy( - hash_table, - (YR_HASH_TABLE_FREE_VALUE_FUNC) yr_free); + yr_hash_table_destroy(hash_table, (YR_HASH_TABLE_FREE_VALUE_FUNC) yr_free); return ERROR_SUCCESS; } diff --git a/libyara/modules/macho/macho.c b/libyara/modules/macho/macho.c index d8661baaf3..ff638c9301 100644 --- a/libyara/modules/macho/macho.c +++ b/libyara/modules/macho/macho.c @@ -27,30 +27,26 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include -#include +#include #include +#include #define MODULE_NAME macho // Check for Mach-O binary magic constant. -int is_macho_file_block( - const uint32_t* magic) +int is_macho_file_block(const uint32_t* magic) { - return *magic == MH_MAGIC - || *magic == MH_CIGAM - || *magic == MH_MAGIC_64 - || *magic == MH_CIGAM_64; + return *magic == MH_MAGIC || *magic == MH_CIGAM || *magic == MH_MAGIC_64 || + *magic == MH_CIGAM_64; } // Check if file is for 32-bit architecture. -int macho_is_32( - const uint8_t* magic) +int macho_is_32(const uint8_t* magic) { // Magic must be [CE]FAEDFE or FEEDFA[CE]. return magic[0] == 0xce || magic[3] == 0xce; @@ -59,8 +55,7 @@ int macho_is_32( // Check if file is for big-endian architecture. -int macho_is_big( - const uint8_t* magic) +int macho_is_big(const uint8_t* magic) { // Magic must be [FE]EDFACE or [FE]EDFACF. return magic[0] == 0xfe; @@ -69,37 +64,29 @@ int macho_is_big( // Check for Mach-O fat binary magic constant. -int is_fat_macho_file_block( - const uint32_t* magic) +int is_fat_macho_file_block(const uint32_t* magic) { - return *magic == FAT_MAGIC - || *magic == FAT_CIGAM - || *magic == FAT_MAGIC_64 - || *magic == FAT_CIGAM_64; + return *magic == FAT_MAGIC || *magic == FAT_CIGAM || *magic == FAT_MAGIC_64 || + *magic == FAT_CIGAM_64; } // Check if file is 32-bit fat file. -int macho_fat_is_32( - const uint8_t* magic) +int macho_fat_is_32(const uint8_t* magic) { // Magic must be CAFEBA[BE]. return magic[3] == 0xbe; } -static int should_swap_bytes( - const uint32_t magic) +static int should_swap_bytes(const uint32_t magic) { - return magic == MH_CIGAM - || magic == MH_CIGAM_64 - || magic == FAT_CIGAM - || magic == FAT_CIGAM_64; + return magic == MH_CIGAM || magic == MH_CIGAM_64 || magic == FAT_CIGAM || + magic == FAT_CIGAM_64; } -static void swap_mach_header( - yr_mach_header_64_t *mh) +static void swap_mach_header(yr_mach_header_64_t* mh) { // Don't swap the magic number so we can tell if swapping is needed mh->cputype = yr_bswap32(mh->cputype); @@ -114,14 +101,14 @@ static void swap_mach_header( } -static void swap_load_command(yr_load_command_t *lc) +static void swap_load_command(yr_load_command_t* lc) { lc->cmd = yr_bswap32(lc->cmd); lc->cmdsize = yr_bswap32(lc->cmdsize); } -static void swap_segment_command(yr_segment_command_32_t *sg) +static void swap_segment_command(yr_segment_command_32_t* sg) { sg->cmd = yr_bswap32(sg->cmd); sg->cmdsize = yr_bswap32(sg->cmdsize); @@ -136,7 +123,7 @@ static void swap_segment_command(yr_segment_command_32_t *sg) } -static void swap_segment_command_64(yr_segment_command_64_t *sg) +static void swap_segment_command_64(yr_segment_command_64_t* sg) { sg->cmd = yr_bswap32(sg->cmd); sg->cmdsize = yr_bswap32(sg->cmdsize); @@ -151,7 +138,7 @@ static void swap_segment_command_64(yr_segment_command_64_t *sg) } -static void swap_section(yr_section_32_t *sec) +static void swap_section(yr_section_32_t* sec) { sec->addr = yr_bswap32(sec->addr); sec->size = yr_bswap32(sec->size); @@ -165,7 +152,7 @@ static void swap_section(yr_section_32_t *sec) } -static void swap_section_64(yr_section_64_t *sec) +static void swap_section_64(yr_section_64_t* sec) { sec->addr = yr_bswap64(sec->addr); sec->size = yr_bswap64(sec->size); @@ -190,10 +177,7 @@ static void swap_entry_point_command(yr_entry_point_command_t* ep_command) // Convert virtual address to file offset. Segments have to be already loaded. -bool macho_rva_to_offset( - uint64_t address, - uint64_t* result, - YR_OBJECT* object) +bool macho_rva_to_offset(uint64_t address, uint64_t* result, YR_OBJECT* object) { uint64_t segment_count = get_integer(object, "number_of_segments"); @@ -216,10 +200,7 @@ bool macho_rva_to_offset( // Convert file offset to virtual address. Segments have to be already loaded. -int macho_offset_to_rva( - uint64_t offset, - uint64_t* result, - YR_OBJECT* object) +int macho_offset_to_rva(uint64_t offset, uint64_t* result, YR_OBJECT* object) { uint64_t segment_count = get_integer(object, "number_of_segments"); @@ -249,71 +230,71 @@ void macho_handle_unixthread( { int should_swap = should_swap_bytes(get_integer(object, "magic")); bool is64 = false; - command = (void*)((uint8_t*)command + sizeof(yr_thread_command_t)); + command = (void*) ((uint8_t*) command + sizeof(yr_thread_command_t)); uint64_t address = 0; switch (get_integer(object, "cputype")) { - case CPU_TYPE_MC680X0: - { - yr_m68k_thread_state_t* m68k_state = (yr_m68k_thread_state_t*)command; - address = m68k_state->pc; - break; - } - case CPU_TYPE_MC88000: - { - yr_m88k_thread_state_t* m88k_state = (yr_m88k_thread_state_t*)command; - address = m88k_state->xip; - break; - } - case CPU_TYPE_SPARC: - { - yr_sparc_thread_state_t* sparc_state = (yr_sparc_thread_state_t*)command; - address = sparc_state->pc; - break; - } - case CPU_TYPE_POWERPC: - { - yr_ppc_thread_state_t* ppc_state = (yr_ppc_thread_state_t*)command; - address = ppc_state->srr0; - break; - } - case CPU_TYPE_X86: - { - yr_x86_thread_state_t* x86_state = (yr_x86_thread_state_t*)command; - address = x86_state->eip; - break; - } - case CPU_TYPE_ARM: - { - yr_arm_thread_state_t* arm_state = (yr_arm_thread_state_t*)command; - address = arm_state->pc; - break; - } - case CPU_TYPE_X86_64: - { - yr_x86_thread_state64_t* x64_state = (yr_x86_thread_state64_t*)command; - address = x64_state->rip; - is64 = true; - break; - } - case CPU_TYPE_ARM64: - { - yr_arm_thread_state64_t* arm64_state = (yr_arm_thread_state64_t*)command; - address = arm64_state->pc; - is64 = true; - break; - } - case CPU_TYPE_POWERPC64: - { - yr_ppc_thread_state64_t* ppc64_state = (yr_ppc_thread_state64_t*)command; - address = ppc64_state->srr0; - is64 = true; - break; - } + case CPU_TYPE_MC680X0: + { + yr_m68k_thread_state_t* m68k_state = (yr_m68k_thread_state_t*) command; + address = m68k_state->pc; + break; + } + case CPU_TYPE_MC88000: + { + yr_m88k_thread_state_t* m88k_state = (yr_m88k_thread_state_t*) command; + address = m88k_state->xip; + break; + } + case CPU_TYPE_SPARC: + { + yr_sparc_thread_state_t* sparc_state = (yr_sparc_thread_state_t*) command; + address = sparc_state->pc; + break; + } + case CPU_TYPE_POWERPC: + { + yr_ppc_thread_state_t* ppc_state = (yr_ppc_thread_state_t*) command; + address = ppc_state->srr0; + break; + } + case CPU_TYPE_X86: + { + yr_x86_thread_state_t* x86_state = (yr_x86_thread_state_t*) command; + address = x86_state->eip; + break; + } + case CPU_TYPE_ARM: + { + yr_arm_thread_state_t* arm_state = (yr_arm_thread_state_t*) command; + address = arm_state->pc; + break; + } + case CPU_TYPE_X86_64: + { + yr_x86_thread_state64_t* x64_state = (yr_x86_thread_state64_t*) command; + address = x64_state->rip; + is64 = true; + break; + } + case CPU_TYPE_ARM64: + { + yr_arm_thread_state64_t* arm64_state = (yr_arm_thread_state64_t*) command; + address = arm64_state->pc; + is64 = true; + break; + } + case CPU_TYPE_POWERPC64: + { + yr_ppc_thread_state64_t* ppc64_state = (yr_ppc_thread_state64_t*) command; + address = ppc64_state->srr0; + is64 = true; + break; + } - default: - return; + default: + return; } if (should_swap) @@ -372,7 +353,7 @@ void macho_handle_main( // Load segment and its sections. void macho_handle_segment( - const uint8_t *command, + const uint8_t* command, const unsigned i, YR_OBJECT* object) { @@ -383,8 +364,8 @@ void macho_handle_segment( if (should_swap) swap_segment_command(&sg); - set_sized_string(sg.segname, strnlen(sg.segname, 16), - object, "segments[%i].segname", i); + set_sized_string( + sg.segname, strnlen(sg.segname, 16), object, "segments[%i].segname", i); set_integer(sg.vmaddr, object, "segments[%i].vmaddr", i); set_integer(sg.vmsize, object, "segments[%i].vmsize", i); @@ -404,42 +385,44 @@ void macho_handle_segment( if (sg.cmdsize < parsed_size) break; - memcpy(&sec, - command + sizeof(yr_segment_command_32_t) + (j * sizeof(yr_section_32_t)), - sizeof(yr_section_32_t)); + memcpy( + &sec, + command + sizeof(yr_segment_command_32_t) + + (j * sizeof(yr_section_32_t)), + sizeof(yr_section_32_t)); if (should_swap) swap_section(&sec); set_sized_string( - sec.segname, strnlen(sec.segname, 16), object, - "segments[%i].sections[%i].segname", i, j); + sec.segname, + strnlen(sec.segname, 16), + object, + "segments[%i].sections[%i].segname", + i, + j); set_sized_string( - sec.sectname, strnlen(sec.sectname, 16), object, - "segments[%i].sections[%i].sectname", i, j); + sec.sectname, + strnlen(sec.sectname, 16), + object, + "segments[%i].sections[%i].sectname", + i, + j); - set_integer( - sec.addr, object, - "segments[%i].sections[%i].addr", i, j); + set_integer(sec.addr, object, "segments[%i].sections[%i].addr", i, j); - set_integer( - sec.size, object, "segments[%i].sections[%i].size", i, j); + set_integer(sec.size, object, "segments[%i].sections[%i].size", i, j); - set_integer( - sec.offset, object, "segments[%i].sections[%i].offset", i, j); + set_integer(sec.offset, object, "segments[%i].sections[%i].offset", i, j); - set_integer( - sec.align, object, "segments[%i].sections[%i].align", i, j); + set_integer(sec.align, object, "segments[%i].sections[%i].align", i, j); - set_integer( - sec.reloff, object, "segments[%i].sections[%i].reloff", i, j); + set_integer(sec.reloff, object, "segments[%i].sections[%i].reloff", i, j); - set_integer( - sec.nreloc, object, "segments[%i].sections[%i].nreloc", i, j); + set_integer(sec.nreloc, object, "segments[%i].sections[%i].nreloc", i, j); - set_integer( - sec.flags, object, "segments[%i].sections[%i].flags", i, j); + set_integer(sec.flags, object, "segments[%i].sections[%i].flags", i, j); set_integer( sec.reserved1, object, "segments[%i].sections[%i].reserved1", i, j); @@ -450,7 +433,7 @@ void macho_handle_segment( } void macho_handle_segment_64( - const uint8_t *command, + const uint8_t* command, const unsigned i, YR_OBJECT* object) { @@ -461,8 +444,8 @@ void macho_handle_segment_64( if (should_swap) swap_segment_command_64(&sg); - set_sized_string(sg.segname, strnlen(sg.segname, 16), - object, "segments[%i].segname", i); + set_sized_string( + sg.segname, strnlen(sg.segname, 16), object, "segments[%i].segname", i); set_integer(sg.vmaddr, object, "segments[%i].vmaddr", i); set_integer(sg.vmsize, object, "segments[%i].vmsize", i); @@ -481,41 +464,44 @@ void macho_handle_segment_64( if (sg.cmdsize < parsed_size) break; - memcpy(&sec, - command + sizeof(yr_segment_command_64_t) + (j * sizeof(yr_section_64_t)), - sizeof(yr_section_64_t)); + memcpy( + &sec, + command + sizeof(yr_segment_command_64_t) + + (j * sizeof(yr_section_64_t)), + sizeof(yr_section_64_t)); if (should_swap) swap_section_64(&sec); set_sized_string( - sec.segname, strnlen(sec.segname, 16), object, - "segments[%i].sections[%i].segname", i, j); + sec.segname, + strnlen(sec.segname, 16), + object, + "segments[%i].sections[%i].segname", + i, + j); set_sized_string( - sec.sectname, strnlen(sec.sectname, 16), object, - "segments[%i].sections[%i].sectname", i, j); + sec.sectname, + strnlen(sec.sectname, 16), + object, + "segments[%i].sections[%i].sectname", + i, + j); - set_integer( - sec.addr, object, "segments[%i].sections[%i].addr", i, j); + set_integer(sec.addr, object, "segments[%i].sections[%i].addr", i, j); - set_integer( - sec.size, object, "segments[%i].sections[%i].size", i, j); + set_integer(sec.size, object, "segments[%i].sections[%i].size", i, j); - set_integer( - sec.offset, object, "segments[%i].sections[%i].offset", i, j); + set_integer(sec.offset, object, "segments[%i].sections[%i].offset", i, j); - set_integer( - sec.align, object, "segments[%i].sections[%i].align", i, j); + set_integer(sec.align, object, "segments[%i].sections[%i].align", i, j); - set_integer( - sec.reloff, object, "segments[%i].sections[%i].reloff", i, j); + set_integer(sec.reloff, object, "segments[%i].sections[%i].reloff", i, j); - set_integer( - sec.nreloc, object, "segments[%i].sections[%i].nreloc", i, j); + set_integer(sec.nreloc, object, "segments[%i].sections[%i].nreloc", i, j); - set_integer( - sec.flags, object, "segments[%i].sections[%i].flags", i, j); + set_integer(sec.flags, object, "segments[%i].sections[%i].flags", i, j); set_integer( sec.reserved1, object, "segments[%i].sections[%i].reserved1", i, j); @@ -537,9 +523,8 @@ void macho_parse_file( YR_OBJECT* object, YR_SCAN_CONTEXT* context) { - size_t header_size = macho_is_32(data)? - sizeof(yr_mach_header_32_t): - sizeof(yr_mach_header_64_t); + size_t header_size = macho_is_32(data) ? sizeof(yr_mach_header_32_t) + : sizeof(yr_mach_header_64_t); if (size < header_size) return; @@ -572,7 +557,7 @@ void macho_parse_file( uint64_t seg_count = 0; uint64_t parsed_size = header_size; - uint8_t *command = (uint8_t*)(data + header_size); + uint8_t* command = (uint8_t*) (data + header_size); yr_load_command_t command_struct; @@ -586,18 +571,18 @@ void macho_parse_file( if (size < header_size + command_struct.cmdsize) break; - switch(command_struct.cmd) + switch (command_struct.cmd) { - case LC_SEGMENT: - { - macho_handle_segment(command, seg_count++, object); - break; - } - case LC_SEGMENT_64: - { - macho_handle_segment_64(command, seg_count++, object); - break; - } + case LC_SEGMENT: + { + macho_handle_segment(command, seg_count++, object); + break; + } + case LC_SEGMENT_64: + { + macho_handle_segment_64(command, seg_count++, object); + break; + } } command += command_struct.cmdsize; @@ -608,7 +593,7 @@ void macho_parse_file( // The second command parsing pass handles others, who use segment count. parsed_size = header_size; - command = (uint8_t*)(data + header_size); + command = (uint8_t*) (data + header_size); for (unsigned i = 0; i < header.ncmds; i++) { @@ -620,18 +605,18 @@ void macho_parse_file( if (size < header_size + command_struct.cmdsize) break; - switch(command_struct.cmd) + switch (command_struct.cmd) { - case LC_UNIXTHREAD: - { - macho_handle_unixthread(command, object, context); - break; - } - case LC_MAIN: - { - macho_handle_main(command, object, context); - break; - } + case LC_UNIXTHREAD: + { + macho_handle_unixthread(command, object, context); + break; + } + case LC_MAIN: + { + macho_handle_main(command, object, context); + break; + } } command += command_struct.cmdsize; @@ -648,10 +633,10 @@ void macho_load_fat_arch_header( uint32_t num, yr_fat_arch_64_t* arch) { - if (macho_fat_is_32(data)) { + if (macho_fat_is_32(data)) + { yr_fat_arch_32_t* arch32 = - (yr_fat_arch_32_t*)(data + sizeof(yr_fat_header_t) + - (num * sizeof(yr_fat_arch_32_t))); + (yr_fat_arch_32_t*) (data + sizeof(yr_fat_header_t) + (num * sizeof(yr_fat_arch_32_t))); arch->cputype = yr_be32toh(arch32->cputype); arch->cpusubtype = yr_be32toh(arch32->cpusubtype); arch->offset = yr_be32toh(arch32->offset); @@ -659,10 +644,10 @@ void macho_load_fat_arch_header( arch->align = yr_be32toh(arch32->align); arch->reserved = 0; } - else { + else + { yr_fat_arch_64_t* arch64 = - (yr_fat_arch_64_t*)(data + sizeof(yr_fat_header_t) + - (num * sizeof(yr_fat_arch_64_t))); + (yr_fat_arch_64_t*) (data + sizeof(yr_fat_header_t) + (num * sizeof(yr_fat_arch_64_t))); arch->cputype = yr_be32toh(arch64->cputype); arch->cpusubtype = yr_be32toh(arch64->cpusubtype); arch->offset = yr_be64toh(arch64->offset); @@ -711,22 +696,24 @@ void macho_parse_fat_file( set_integer(arch.reserved, object, "fat_arch[%i].reserved", i); if (size < arch.offset + arch.size) - continue; + continue; /* Force 'file' array entry creation. */ set_integer(YR_UNDEFINED, object, "file[%i].magic", i); /* Get specific Mach-O file data. */ - macho_parse_file(data + arch.offset, arch.size, - get_object(object, "file[%i]", i), context); + macho_parse_file( + data + arch.offset, + arch.size, + get_object(object, "file[%i]", i), + context); } } // Sets all necessary Mach-O constants and definitions. -void macho_set_definitions( - YR_OBJECT* object) +void macho_set_definitions(YR_OBJECT* object) { // Magic constants @@ -764,11 +751,11 @@ void macho_set_definitions( // CPU sub-types - set_integer(CPU_SUBTYPE_INTEL_MODEL_ALL, object, - "CPU_SUBTYPE_INTEL_MODEL_ALL"); - set_integer(CPU_SUBTYPE_386, object,"CPU_SUBTYPE_386"); - set_integer(CPU_SUBTYPE_386, object,"CPU_SUBTYPE_I386_ALL"); - set_integer(CPU_SUBTYPE_386, object,"CPU_SUBTYPE_X86_64_ALL"); + set_integer( + CPU_SUBTYPE_INTEL_MODEL_ALL, object, "CPU_SUBTYPE_INTEL_MODEL_ALL"); + set_integer(CPU_SUBTYPE_386, object, "CPU_SUBTYPE_386"); + set_integer(CPU_SUBTYPE_386, object, "CPU_SUBTYPE_I386_ALL"); + set_integer(CPU_SUBTYPE_386, object, "CPU_SUBTYPE_X86_64_ALL"); set_integer(CPU_SUBTYPE_486, object, "CPU_SUBTYPE_486"); set_integer(CPU_SUBTYPE_486SX, object, "CPU_SUBTYPE_486SX"); set_integer(CPU_SUBTYPE_586, object, "CPU_SUBTYPE_586"); @@ -777,12 +764,10 @@ void macho_set_definitions( set_integer(CPU_SUBTYPE_PENTII_M3, object, "CPU_SUBTYPE_PENTII_M3"); set_integer(CPU_SUBTYPE_PENTII_M5, object, "CPU_SUBTYPE_PENTII_M5"); set_integer(CPU_SUBTYPE_CELERON, object, "CPU_SUBTYPE_CELERON"); - set_integer(CPU_SUBTYPE_CELERON_MOBILE, object, - "CPU_SUBTYPE_CELERON_MOBILE"); + set_integer(CPU_SUBTYPE_CELERON_MOBILE, object, "CPU_SUBTYPE_CELERON_MOBILE"); set_integer(CPU_SUBTYPE_PENTIUM_3, object, "CPU_SUBTYPE_PENTIUM_3"); set_integer(CPU_SUBTYPE_PENTIUM_3_M, object, "CPU_SUBTYPE_PENTIUM_3_M"); - set_integer(CPU_SUBTYPE_PENTIUM_3_XEON, object, - "CPU_SUBTYPE_PENTIUM_3_XEON"); + set_integer(CPU_SUBTYPE_PENTIUM_3_XEON, object, "CPU_SUBTYPE_PENTIUM_3_XEON"); set_integer(CPU_SUBTYPE_PENTIUM_M, object, "CPU_SUBTYPE_PENTIUM_M"); set_integer(CPU_SUBTYPE_PENTIUM_4, object, "CPU_SUBTYPE_PENTIUM_4"); set_integer(CPU_SUBTYPE_PENTIUM_4_M, object, "CPU_SUBTYPE_PENTIUM_4_M"); @@ -850,8 +835,7 @@ void macho_set_definitions( set_integer(MH_NOFIXPREBINDING, object, "MH_NOFIXPREBINDING"); set_integer(MH_PREBINDABLE, object, "MH_PREBINDABLE"); set_integer(MH_ALLMODSBOUND, object, "MH_ALLMODSBOUND"); - set_integer(MH_SUBSECTIONS_VIA_SYMBOLS, object, - "MH_SUBSECTIONS_VIA_SYMBOLS"); + set_integer(MH_SUBSECTIONS_VIA_SYMBOLS, object, "MH_SUBSECTIONS_VIA_SYMBOLS"); set_integer(MH_CANONICAL, object, "MH_CANONICAL"); set_integer(MH_WEAK_DEFINES, object, "MH_WEAK_DEFINES"); set_integer(MH_BINDS_TO_WEAK, object, "MH_BINDS_TO_WEAK"); @@ -884,8 +868,7 @@ void macho_set_definitions( set_integer(S_CSTRING_LITERALS, object, "S_CSTRING_LITERALS"); set_integer(S_4BYTE_LITERALS, object, "S_4BYTE_LITERALS"); set_integer(S_8BYTE_LITERALS, object, "S_8BYTE_LITERALS"); - set_integer(S_NON_LAZY_SYMBOL_POINTERS, object, - "S_NON_LAZY_SYMBOL_POINTERS"); + set_integer(S_NON_LAZY_SYMBOL_POINTERS, object, "S_NON_LAZY_SYMBOL_POINTERS"); set_integer(S_LAZY_SYMBOL_POINTERS, object, "S_LAZY_SYMBOL_POINTERS"); set_integer(S_LITERAL_POINTERS, object, "S_LITERAL_POINTERS"); set_integer(S_SYMBOL_STUBS, object, "S_SYMBOL_STUBS"); @@ -896,15 +879,19 @@ void macho_set_definitions( set_integer(S_INTERPOSING, object, "S_INTERPOSING"); set_integer(S_16BYTE_LITERALS, object, "S_16BYTE_LITERALS"); set_integer(S_DTRACE_DOF, object, "S_DTRACE_DOF"); - set_integer(S_LAZY_DYLIB_SYMBOL_POINTERS, object, - "S_LAZY_DYLIB_SYMBOL_POINTERS"); + set_integer( + S_LAZY_DYLIB_SYMBOL_POINTERS, object, "S_LAZY_DYLIB_SYMBOL_POINTERS"); set_integer(S_THREAD_LOCAL_REGULAR, object, "S_THREAD_LOCAL_REGULAR"); set_integer(S_THREAD_LOCAL_ZEROFILL, object, "S_THREAD_LOCAL_ZEROFILL"); set_integer(S_THREAD_LOCAL_VARIABLES, object, "S_THREAD_LOCAL_VARIABLES"); - set_integer(S_THREAD_LOCAL_VARIABLE_POINTERS, object, - "S_THREAD_LOCAL_VARIABLE_POINTERS"); - set_integer(S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, object, - "S_THREAD_LOCAL_INIT_FUNCTION_POINTERS"); + set_integer( + S_THREAD_LOCAL_VARIABLE_POINTERS, + object, + "S_THREAD_LOCAL_VARIABLE_POINTERS"); + set_integer( + S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, + object, + "S_THREAD_LOCAL_INIT_FUNCTION_POINTERS"); // Section attributes @@ -913,8 +900,7 @@ void macho_set_definitions( set_integer(S_ATTR_STRIP_STATIC_SYMS, object, "S_ATTR_STRIP_STATIC_SYMS"); set_integer(S_ATTR_NO_DEAD_STRIP, object, "S_ATTR_NO_DEAD_STRIP"); set_integer(S_ATTR_LIVE_SUPPORT, object, "S_ATTR_LIVE_SUPPORT"); - set_integer(S_ATTR_SELF_MODIFYING_CODE, object, - "S_ATTR_SELF_MODIFYING_CODE"); + set_integer(S_ATTR_SELF_MODIFYING_CODE, object, "S_ATTR_SELF_MODIFYING_CODE"); set_integer(S_ATTR_DEBUG, object, "S_ATTR_DEBUG"); set_integer(S_ATTR_SOME_INSTRUCTIONS, object, "S_ATTR_SOME_INSTRUCTIONS"); set_integer(S_ATTR_EXT_RELOC, object, "S_ATTR_EXT_RELOC"); @@ -1023,7 +1009,8 @@ define_function(ep_for_arch_subtype) } -begin_declarations; +begin_declarations + ; // Magic constants @@ -1223,7 +1210,8 @@ begin_declarations; declare_integer("number_of_segments"); - begin_struct_array("segments"); + begin_struct_array("segments") + ; declare_string("segname"); declare_integer("vmaddr"); declare_integer("vmsize"); @@ -1233,7 +1221,8 @@ begin_declarations; declare_integer("initprot"); declare_integer("nsects"); declare_integer("flags"); - begin_struct_array("sections"); + begin_struct_array("sections") + ; declare_string("sectname"); declare_string("segname"); declare_integer("addr"); @@ -1259,7 +1248,8 @@ begin_declarations; declare_integer("fat_magic"); declare_integer("nfat_arch"); - begin_struct_array("fat_arch"); + begin_struct_array("fat_arch") + ; declare_integer("cputype"); declare_integer("cpusubtype"); declare_integer("offset"); @@ -1269,7 +1259,8 @@ begin_declarations; // Included Mach-O files (must be same as single file structure above) - begin_struct_array("file"); + begin_struct_array("file") + ; // Single file header @@ -1286,7 +1277,8 @@ begin_declarations; declare_integer("number_of_segments"); - begin_struct_array("segments"); + begin_struct_array("segments") + ; declare_string("segname"); declare_integer("vmaddr"); declare_integer("vmsize"); @@ -1296,7 +1288,8 @@ begin_declarations; declare_integer("initprot"); declare_integer("nsects"); declare_integer("flags"); - begin_struct_array("sections"); + begin_struct_array("sections") + ; declare_string("sectname"); declare_string("segname"); declare_integer("addr"); @@ -1328,14 +1321,12 @@ begin_declarations; end_declarations; -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { return ERROR_SUCCESS; } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { return ERROR_SUCCESS; } @@ -1374,8 +1365,7 @@ int module_load( return ERROR_SUCCESS; } -int module_unload( - YR_OBJECT* module_object) +int module_unload(YR_OBJECT* module_object) { return ERROR_SUCCESS; } diff --git a/libyara/modules/magic/magic.c b/libyara/modules/magic/magic.c index 5d9ba978e7..8024177e6d 100644 --- a/libyara/modules/magic/magic.c +++ b/libyara/modules/magic/magic.c @@ -33,9 +33,9 @@ The original idea and inspiration for this module comes from Armin Buescher. */ +#include #include #include -#include #define MODULE_NAME magic @@ -50,7 +50,7 @@ typedef struct const char* cached_type; const char* cached_mime_type; -} MAGIC_CACHE ; +} MAGIC_CACHE; static int get_cache(MAGIC_CACHE** cache) @@ -71,8 +71,8 @@ static int get_cache(MAGIC_CACHE** cache) if (magic_load((*cache)->magic_cookie, NULL) != 0) { - magic_close((*cache)->magic_cookie); - return ERROR_INTERNAL_FATAL_ERROR; + magic_close((*cache)->magic_cookie); + return ERROR_INTERNAL_FATAL_ERROR; } (*cache)->cached_type = NULL; @@ -108,9 +108,7 @@ define_function(magic_mime_type) magic_setflags(cache->magic_cookie, MAGIC_MIME_TYPE); cache->cached_mime_type = magic_buffer( - cache->magic_cookie, - block_data, - block->size); + cache->magic_cookie, block_data, block->size); } } @@ -144,9 +142,7 @@ define_function(magic_type) magic_setflags(cache->magic_cookie, 0); cache->cached_type = magic_buffer( - cache->magic_cookie, - block_data, - block->size); + cache->magic_cookie, block_data, block->size); } } @@ -156,7 +152,8 @@ define_function(magic_type) return_string((char*) cache->cached_type); } -begin_declarations; +begin_declarations + ; declare_function("mime_type", "", "s", magic_mime_type); declare_function("type", "", "s", magic_type); @@ -164,15 +161,13 @@ begin_declarations; end_declarations; -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { return yr_thread_storage_create(&magic_tls); } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { MAGIC_CACHE* cache = (MAGIC_CACHE*) yr_thread_storage_get_value(&magic_tls); @@ -196,8 +191,7 @@ int module_load( } -int module_unload( - YR_OBJECT* module) +int module_unload(YR_OBJECT* module) { MAGIC_CACHE* cache = (MAGIC_CACHE*) yr_thread_storage_get_value(&magic_tls); diff --git a/libyara/modules/math/math.c b/libyara/modules/math/math.c index 3037c5567f..df0f8e720f 100644 --- a/libyara/modules/math/math.c +++ b/libyara/modules/math/math.c @@ -28,10 +28,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include - -#include -#include #include +#include +#include #define MODULE_NAME math @@ -89,8 +88,8 @@ define_function(data_entropy) uint32_t* data; - int64_t offset = integer_argument(1); // offset where to start - int64_t length = integer_argument(2); // length of bytes we want entropy on + int64_t offset = integer_argument(1); // offset where to start + int64_t length = integer_argument(2); // length of bytes we want entropy on YR_SCAN_CONTEXT* context = scan_context(); YR_MEMORY_BLOCK* block = first_memory_block(context); @@ -106,12 +105,11 @@ define_function(data_entropy) foreach_memory_block(iterator, block) { - if (offset >= block->base && - offset < block->base + block->size) + if (offset >= block->base && offset < block->base + block->size) { - size_t data_offset = (size_t) (offset - block->base); + size_t data_offset = (size_t)(offset - block->base); size_t data_len = (size_t) yr_min( - length, (size_t) (block->size - data_offset)); + length, (size_t)(block->size - data_offset)); const uint8_t* block_data = block->fetch_data(block); @@ -178,8 +176,7 @@ define_function(string_deviation) size_t i; - for (i = 0; i < s->length; i++) - sum += fabs(((double) s->c_string[i]) - mean); + for (i = 0; i < s->length; i++) sum += fabs(((double) s->c_string[i]) - mean); return_float(sum / s->length); } @@ -211,12 +208,10 @@ define_function(data_deviation) foreach_memory_block(iterator, block) { - if (offset >= block->base && - offset < block->base + block->size) + if (offset >= block->base && offset < block->base + block->size) { data_offset = (size_t)(offset - block->base); - data_len = (size_t)yr_min( - length, (size_t)(block->size - data_offset)); + data_len = (size_t) yr_min(length, (size_t)(block->size - data_offset)); block_data = block->fetch_data(block); if (block_data == NULL) @@ -227,7 +222,7 @@ define_function(data_deviation) length -= data_len; for (i = 0; i < data_len; i++) - sum += fabs(((double)* (block_data + data_offset + i)) - mean); + sum += fabs(((double) *(block_data + data_offset + i)) - mean); past_first_block = true; } @@ -259,8 +254,7 @@ define_function(string_mean) SIZED_STRING* s = sized_string_argument(1); - for (i = 0; i < s->length; i++) - sum += (double) s->c_string[i]; + for (i = 0; i < s->length; i++) sum += (double) s->c_string[i]; return_float(sum / s->length); } @@ -286,12 +280,11 @@ define_function(data_mean) foreach_memory_block(iterator, block) { - if (offset >= block->base && - offset < block->base + block->size) + if (offset >= block->base && offset < block->base + block->size) { - size_t data_offset = (size_t) (offset - block->base); + size_t data_offset = (size_t)(offset - block->base); size_t data_len = (size_t) yr_min( - length, (size_t) (block->size - data_offset)); + length, (size_t)(block->size - data_offset)); const uint8_t* block_data = block->fetch_data(block); @@ -303,7 +296,7 @@ define_function(data_mean) length -= data_len; for (i = 0; i < data_len; i++) - sum += (double)* (block_data + data_offset + i); + sum += (double) *(block_data + data_offset + i); past_first_block = true; } @@ -354,12 +347,11 @@ define_function(data_serial_correlation) foreach_memory_block(iterator, block) { - if (offset >= block->base && - offset < block->base + block->size) + if (offset >= block->base && offset < block->base + block->size) { size_t data_offset = (size_t)(offset - block->base); size_t data_len = (size_t) yr_min( - length, (size_t) (block->size - data_offset)); + length, (size_t)(block->size - data_offset)); const uint8_t* block_data = block->fetch_data(block); @@ -372,7 +364,7 @@ define_function(data_serial_correlation) for (i = 0; i < data_len; i++) { - sccun = (double)* (block_data + data_offset + i); + sccun = (double) *(block_data + data_offset + i); scct1 += scclast * sccun; scct2 += sccun; scct3 += sccun * sccun; @@ -471,14 +463,13 @@ define_function(data_monte_carlo_pi) foreach_memory_block(iterator, block) { - if (offset >= block->base && - offset < block->base + block->size) + if (offset >= block->base && offset < block->base + block->size) { unsigned int monte[6]; - size_t data_offset = (size_t) (offset - block->base); + size_t data_offset = (size_t)(offset - block->base); size_t data_len = (size_t) yr_min( - length, (size_t) (block->size - data_offset)); + length, (size_t)(block->size - data_offset)); const uint8_t* block_data = block->fetch_data(block); @@ -490,7 +481,7 @@ define_function(data_monte_carlo_pi) for (i = 0; i < data_len; i++) { - monte[i % 6] = (unsigned int)* (block_data + data_offset + i); + monte[i % 6] = (unsigned int) *(block_data + data_offset + i); if (i % 6 == 5) { @@ -615,7 +606,8 @@ define_function(max) } -begin_declarations; +begin_declarations + ; declare_float("MEAN_BYTES"); declare_function("in_range", "fff", "i", in_range); @@ -635,15 +627,13 @@ begin_declarations; end_declarations; -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { return ERROR_SUCCESS; } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { return ERROR_SUCCESS; } @@ -660,8 +650,7 @@ int module_load( } -int module_unload( - YR_OBJECT* module_object) +int module_unload(YR_OBJECT* module_object) { return ERROR_SUCCESS; } diff --git a/libyara/modules/pb_tests/pb_tests.c b/libyara/modules/pb_tests/pb_tests.c index 07e50e66a3..7e1e48a5fe 100644 --- a/libyara/modules/pb_tests/pb_tests.c +++ b/libyara/modules/pb_tests/pb_tests.c @@ -2,23 +2,27 @@ /* Generated by the protoc-gen-yara. DO NOT EDIT! */ #include #include + #include "modules/pb_tests/pb_tests.pb-c.h" #define MODULE_NAME pb_tests -static void* _pb_alloc(void *allocator_data, size_t size) +static void* _pb_alloc(void* allocator_data, size_t size) { return yr_malloc(size); } -static void _pb_free(void *allocator_data, void *pointer) +static void _pb_free(void* allocator_data, void* pointer) { return yr_free(pointer); } -begin_declarations; - begin_struct("struct"); - begin_struct("enum"); +begin_declarations + ; + begin_struct("struct") + ; + begin_struct("enum") + ; declare_integer("FIRST"); declare_integer("SECOND"); end_struct("enum"); @@ -32,14 +36,17 @@ begin_declarations; declare_integer("f_bool"); declare_string("f_string"); declare_string("f_bytes"); - begin_struct_array("f_struct_array"); + begin_struct_array("f_struct_array") + ; declare_string("f_string"); declare_integer("f_enum"); - begin_struct("f_nested_struct"); + begin_struct("f_nested_struct") + ; declare_integer("f_int32"); declare_string("f_string"); end_struct("f_nested_struct"); - begin_struct_array("f_nested_struct_array"); + begin_struct_array("f_nested_struct_array") + ; declare_integer("f_int32"); declare_string("f_string"); end_struct_array("f_nested_struct_array"); @@ -48,32 +55,31 @@ begin_declarations; declare_integer_dictionary("f_map_bool"); declare_string_dictionary("f_map_string"); declare_float_dictionary("f_map_float"); - begin_struct_dictionary("f_map_struct"); + begin_struct_dictionary("f_map_struct") + ; declare_integer("f_int32"); declare_integer("f_int64"); end_struct_dictionary("f_map_struct"); declare_string("f_oneof_string"); - begin_struct("f_oneof_struct"); + begin_struct("f_oneof_struct") + ; declare_integer("f_int32"); declare_integer("f_int64"); end_struct("f_oneof_struct"); declare_string("f_yara_name"); end_declarations; -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { return ERROR_SUCCESS; } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { return ERROR_SUCCESS; } -int module_unload( - YR_OBJECT* module_object) +int module_unload(YR_OBJECT* module_object) { return ERROR_SUCCESS; } @@ -92,7 +98,8 @@ int module_load( if (module_data == NULL) return ERROR_SUCCESS; - Test__RootMessage* pb = test__root_message__unpack(&allocator, module_data_size, module_data); + Test__RootMessage* pb = test__root_message__unpack( + &allocator, module_data_size, module_data); if (pb == NULL) return ERROR_INVALID_MODULE_DATA; @@ -100,134 +107,214 @@ int module_load( set_integer(0, module_object, "struct.enum.FIRST"); set_integer(1, module_object, "struct.enum.SECOND"); - if (pb->has_f_int32) { + if (pb->has_f_int32) + { set_integer(pb->f_int32, module_object, "f_int32"); } - if (pb->has_f_int64) { + if (pb->has_f_int64) + { set_integer(pb->f_int64, module_object, "f_int64"); } - if (pb->has_f_sint32) { + if (pb->has_f_sint32) + { set_integer(pb->f_sint32, module_object, "f_sint32"); } - if (pb->has_f_sint64) { + if (pb->has_f_sint64) + { set_integer(pb->f_sint64, module_object, "f_sint64"); } - if (pb->has_f_sfixed32) { + if (pb->has_f_sfixed32) + { set_integer(pb->f_sfixed32, module_object, "f_sfixed32"); } - if (pb->has_f_sfixed64) { + if (pb->has_f_sfixed64) + { set_integer(pb->f_sfixed64, module_object, "f_sfixed64"); } - if (pb->has_f_bool) { + if (pb->has_f_bool) + { set_integer(pb->f_bool, module_object, "f_bool"); } set_string(pb->f_string, module_object, "f_string"); - set_sized_string((const char *) pb->f_bytes.data, pb->f_bytes.len, module_object, "f_bytes"); - - for (int i = 0; i < pb->n_f_struct_array; i++) { - - if (pb->f_struct_array[i] != NULL) { - set_string(pb->f_struct_array[i]->f_string, module_object, "f_struct_array[%i].f_string", i); - - if (pb->f_struct_array[i]->has_f_enum) { - set_integer(pb->f_struct_array[i]->f_enum, module_object, "f_struct_array[%i].f_enum", i); + set_sized_string( + (const char*) pb->f_bytes.data, + pb->f_bytes.len, + module_object, + "f_bytes"); + + for (int i = 0; i < pb->n_f_struct_array; i++) + { + if (pb->f_struct_array[i] != NULL) + { + set_string( + pb->f_struct_array[i]->f_string, + module_object, + "f_struct_array[%i].f_string", + i); + + if (pb->f_struct_array[i]->has_f_enum) + { + set_integer( + pb->f_struct_array[i]->f_enum, + module_object, + "f_struct_array[%i].f_enum", + i); } - if (pb->f_struct_array[i]->f_nested_struct != NULL) { - - if (pb->f_struct_array[i]->f_nested_struct->has_f_int32) { - set_integer(pb->f_struct_array[i]->f_nested_struct->f_int32, module_object, "f_struct_array[%i].f_nested_struct.f_int32", i); + if (pb->f_struct_array[i]->f_nested_struct != NULL) + { + if (pb->f_struct_array[i]->f_nested_struct->has_f_int32) + { + set_integer( + pb->f_struct_array[i]->f_nested_struct->f_int32, + module_object, + "f_struct_array[%i].f_nested_struct.f_int32", + i); } - set_string(pb->f_struct_array[i]->f_nested_struct->f_string, module_object, "f_struct_array[%i].f_nested_struct.f_string", i); + set_string( + pb->f_struct_array[i]->f_nested_struct->f_string, + module_object, + "f_struct_array[%i].f_nested_struct.f_string", + i); } - for (int j = 0; j < pb->f_struct_array[i]->n_f_nested_struct_array; j++) { - - if (pb->f_struct_array[i]->f_nested_struct_array[j] != NULL) { - - if (pb->f_struct_array[i]->f_nested_struct_array[j]->has_f_int32) { - set_integer(pb->f_struct_array[i]->f_nested_struct_array[j]->f_int32, module_object, "f_struct_array[%i].f_nested_struct_array[%i].f_int32", i, j); + for (int j = 0; j < pb->f_struct_array[i]->n_f_nested_struct_array; j++) + { + if (pb->f_struct_array[i]->f_nested_struct_array[j] != NULL) + { + if (pb->f_struct_array[i]->f_nested_struct_array[j]->has_f_int32) + { + set_integer( + pb->f_struct_array[i]->f_nested_struct_array[j]->f_int32, + module_object, + "f_struct_array[%i].f_nested_struct_array[%i].f_int32", + i, + j); } - set_string(pb->f_struct_array[i]->f_nested_struct_array[j]->f_string, module_object, "f_struct_array[%i].f_nested_struct_array[%i].f_string", i, j); + set_string( + pb->f_struct_array[i]->f_nested_struct_array[j]->f_string, + module_object, + "f_struct_array[%i].f_nested_struct_array[%i].f_string", + i, + j); } } } } - for (int i = 0; i < pb->n_f_map_int32; i++) { - - if (pb->f_map_int32[i] != NULL) { - - if (pb->f_map_int32[i]->has_value) { - set_integer(pb->f_map_int32[i]->value, module_object, "f_map_int32[%s]", pb->f_map_int32[i]->key); + for (int i = 0; i < pb->n_f_map_int32; i++) + { + if (pb->f_map_int32[i] != NULL) + { + if (pb->f_map_int32[i]->has_value) + { + set_integer( + pb->f_map_int32[i]->value, + module_object, + "f_map_int32[%s]", + pb->f_map_int32[i]->key); } } } - for (int i = 0; i < pb->n_f_map_bool; i++) { - - if (pb->f_map_bool[i] != NULL) { - - if (pb->f_map_bool[i]->has_value) { - set_integer(pb->f_map_bool[i]->value, module_object, "f_map_bool[%s]", pb->f_map_bool[i]->key); + for (int i = 0; i < pb->n_f_map_bool; i++) + { + if (pb->f_map_bool[i] != NULL) + { + if (pb->f_map_bool[i]->has_value) + { + set_integer( + pb->f_map_bool[i]->value, + module_object, + "f_map_bool[%s]", + pb->f_map_bool[i]->key); } } } - for (int i = 0; i < pb->n_f_map_string; i++) { - - if (pb->f_map_string[i] != NULL) { - set_string(pb->f_map_string[i]->value, module_object, "f_map_string[%s]", pb->f_map_string[i]->key); + for (int i = 0; i < pb->n_f_map_string; i++) + { + if (pb->f_map_string[i] != NULL) + { + set_string( + pb->f_map_string[i]->value, + module_object, + "f_map_string[%s]", + pb->f_map_string[i]->key); } } - for (int i = 0; i < pb->n_f_map_float; i++) { - - if (pb->f_map_float[i] != NULL) { - - if (pb->f_map_float[i]->has_value) { - set_float(pb->f_map_float[i]->value, module_object, "f_map_float[%s]", pb->f_map_float[i]->key); + for (int i = 0; i < pb->n_f_map_float; i++) + { + if (pb->f_map_float[i] != NULL) + { + if (pb->f_map_float[i]->has_value) + { + set_float( + pb->f_map_float[i]->value, + module_object, + "f_map_float[%s]", + pb->f_map_float[i]->key); } } } - for (int i = 0; i < pb->n_f_map_struct; i++) { - - if (pb->f_map_struct[i] != NULL) { - - if (pb->f_map_struct[i]->value != NULL) { - - if (pb->f_map_struct[i]->value->has_f_int32) { - set_integer(pb->f_map_struct[i]->value->f_int32, module_object, "f_map_struct[%s].f_int32", pb->f_map_struct[i]->key); + for (int i = 0; i < pb->n_f_map_struct; i++) + { + if (pb->f_map_struct[i] != NULL) + { + if (pb->f_map_struct[i]->value != NULL) + { + if (pb->f_map_struct[i]->value->has_f_int32) + { + set_integer( + pb->f_map_struct[i]->value->f_int32, + module_object, + "f_map_struct[%s].f_int32", + pb->f_map_struct[i]->key); } - if (pb->f_map_struct[i]->value->has_f_int64) { - set_integer(pb->f_map_struct[i]->value->f_int64, module_object, "f_map_struct[%s].f_int64", pb->f_map_struct[i]->key); + if (pb->f_map_struct[i]->value->has_f_int64) + { + set_integer( + pb->f_map_struct[i]->value->f_int64, + module_object, + "f_map_struct[%s].f_int64", + pb->f_map_struct[i]->key); } } } } - if (pb->f_oneof_case == 20) { + if (pb->f_oneof_case == 20) + { set_string(pb->f_oneof_string, module_object, "f_oneof_string"); } - if (pb->f_oneof_case == 21) { - - if (pb->f_oneof_struct != NULL) { - - if (pb->f_oneof_struct->has_f_int32) { - set_integer(pb->f_oneof_struct->f_int32, module_object, "f_oneof_struct.f_int32"); + if (pb->f_oneof_case == 21) + { + if (pb->f_oneof_struct != NULL) + { + if (pb->f_oneof_struct->has_f_int32) + { + set_integer( + pb->f_oneof_struct->f_int32, + module_object, + "f_oneof_struct.f_int32"); } - if (pb->f_oneof_struct->has_f_int64) { - set_integer(pb->f_oneof_struct->f_int64, module_object, "f_oneof_struct.f_int64"); + if (pb->f_oneof_struct->has_f_int64) + { + set_integer( + pb->f_oneof_struct->f_int64, + module_object, + "f_oneof_struct.f_int64"); } } } diff --git a/libyara/modules/pb_tests/pb_tests.pb-c.c b/libyara/modules/pb_tests/pb_tests.pb-c.c index a9c91cf1ef..4d4beeb380 100644 --- a/libyara/modules/pb_tests/pb_tests.pb-c.c +++ b/libyara/modules/pb_tests/pb_tests.pb-c.c @@ -7,910 +7,990 @@ #endif #include "modules/pb_tests/pb_tests.pb-c.h" -void test__struct__nested_struct__init - (Test__Struct__NestedStruct *message) +void test__struct__nested_struct__init(Test__Struct__NestedStruct *message) { - static const Test__Struct__NestedStruct init_value = TEST__STRUCT__NESTED_STRUCT__INIT; + static const Test__Struct__NestedStruct init_value = + TEST__STRUCT__NESTED_STRUCT__INIT; *message = init_value; } -void test__struct__init - (Test__Struct *message) +void test__struct__init(Test__Struct *message) { static const Test__Struct init_value = TEST__STRUCT__INIT; *message = init_value; } -size_t test__struct__get_packed_size - (const Test__Struct *message) +size_t test__struct__get_packed_size(const Test__Struct *message) { assert(message->base.descriptor == &test__struct__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); + return protobuf_c_message_get_packed_size( + (const ProtobufCMessage *) (message)); } -size_t test__struct__pack - (const Test__Struct *message, - uint8_t *out) +size_t test__struct__pack(const Test__Struct *message, uint8_t *out) { assert(message->base.descriptor == &test__struct__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); + return protobuf_c_message_pack((const ProtobufCMessage *) message, out); } -size_t test__struct__pack_to_buffer - (const Test__Struct *message, - ProtobufCBuffer *buffer) +size_t test__struct__pack_to_buffer( + const Test__Struct *message, + ProtobufCBuffer *buffer) { assert(message->base.descriptor == &test__struct__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); + return protobuf_c_message_pack_to_buffer( + (const ProtobufCMessage *) message, buffer); } -Test__Struct * - test__struct__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) +Test__Struct *test__struct__unpack( + ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data) { - return (Test__Struct *) - protobuf_c_message_unpack (&test__struct__descriptor, - allocator, len, data); + return (Test__Struct *) protobuf_c_message_unpack( + &test__struct__descriptor, allocator, len, data); } -void test__struct__free_unpacked - (Test__Struct *message, - ProtobufCAllocator *allocator) +void test__struct__free_unpacked( + Test__Struct *message, + ProtobufCAllocator *allocator) { - if(!message) + if (!message) return; assert(message->base.descriptor == &test__struct__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); + protobuf_c_message_free_unpacked((ProtobufCMessage *) message, allocator); } -void test__map_struct__init - (Test__MapStruct *message) +void test__map_struct__init(Test__MapStruct *message) { static const Test__MapStruct init_value = TEST__MAP_STRUCT__INIT; *message = init_value; } -size_t test__map_struct__get_packed_size - (const Test__MapStruct *message) +size_t test__map_struct__get_packed_size(const Test__MapStruct *message) { assert(message->base.descriptor == &test__map_struct__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); + return protobuf_c_message_get_packed_size( + (const ProtobufCMessage *) (message)); } -size_t test__map_struct__pack - (const Test__MapStruct *message, - uint8_t *out) +size_t test__map_struct__pack(const Test__MapStruct *message, uint8_t *out) { assert(message->base.descriptor == &test__map_struct__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); + return protobuf_c_message_pack((const ProtobufCMessage *) message, out); } -size_t test__map_struct__pack_to_buffer - (const Test__MapStruct *message, - ProtobufCBuffer *buffer) +size_t test__map_struct__pack_to_buffer( + const Test__MapStruct *message, + ProtobufCBuffer *buffer) { assert(message->base.descriptor == &test__map_struct__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); + return protobuf_c_message_pack_to_buffer( + (const ProtobufCMessage *) message, buffer); } -Test__MapStruct * - test__map_struct__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) +Test__MapStruct *test__map_struct__unpack( + ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data) { - return (Test__MapStruct *) - protobuf_c_message_unpack (&test__map_struct__descriptor, - allocator, len, data); + return (Test__MapStruct *) protobuf_c_message_unpack( + &test__map_struct__descriptor, allocator, len, data); } -void test__map_struct__free_unpacked - (Test__MapStruct *message, - ProtobufCAllocator *allocator) +void test__map_struct__free_unpacked( + Test__MapStruct *message, + ProtobufCAllocator *allocator) { - if(!message) + if (!message) return; assert(message->base.descriptor == &test__map_struct__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); + protobuf_c_message_free_unpacked((ProtobufCMessage *) message, allocator); } -void test__root_message__fmap_int32_entry__init - (Test__RootMessage__FMapInt32Entry *message) +void test__root_message__fmap_int32_entry__init( + Test__RootMessage__FMapInt32Entry *message) { - static const Test__RootMessage__FMapInt32Entry init_value = TEST__ROOT_MESSAGE__FMAP_INT32_ENTRY__INIT; + static const Test__RootMessage__FMapInt32Entry init_value = + TEST__ROOT_MESSAGE__FMAP_INT32_ENTRY__INIT; *message = init_value; } -void test__root_message__fmap_bool_entry__init - (Test__RootMessage__FMapBoolEntry *message) +void test__root_message__fmap_bool_entry__init( + Test__RootMessage__FMapBoolEntry *message) { - static const Test__RootMessage__FMapBoolEntry init_value = TEST__ROOT_MESSAGE__FMAP_BOOL_ENTRY__INIT; + static const Test__RootMessage__FMapBoolEntry init_value = + TEST__ROOT_MESSAGE__FMAP_BOOL_ENTRY__INIT; *message = init_value; } -void test__root_message__fmap_string_entry__init - (Test__RootMessage__FMapStringEntry *message) +void test__root_message__fmap_string_entry__init( + Test__RootMessage__FMapStringEntry *message) { - static const Test__RootMessage__FMapStringEntry init_value = TEST__ROOT_MESSAGE__FMAP_STRING_ENTRY__INIT; + static const Test__RootMessage__FMapStringEntry init_value = + TEST__ROOT_MESSAGE__FMAP_STRING_ENTRY__INIT; *message = init_value; } -void test__root_message__fmap_float_entry__init - (Test__RootMessage__FMapFloatEntry *message) +void test__root_message__fmap_float_entry__init( + Test__RootMessage__FMapFloatEntry *message) { - static const Test__RootMessage__FMapFloatEntry init_value = TEST__ROOT_MESSAGE__FMAP_FLOAT_ENTRY__INIT; + static const Test__RootMessage__FMapFloatEntry init_value = + TEST__ROOT_MESSAGE__FMAP_FLOAT_ENTRY__INIT; *message = init_value; } -void test__root_message__fmap_struct_entry__init - (Test__RootMessage__FMapStructEntry *message) +void test__root_message__fmap_struct_entry__init( + Test__RootMessage__FMapStructEntry *message) { - static const Test__RootMessage__FMapStructEntry init_value = TEST__ROOT_MESSAGE__FMAP_STRUCT_ENTRY__INIT; + static const Test__RootMessage__FMapStructEntry init_value = + TEST__ROOT_MESSAGE__FMAP_STRUCT_ENTRY__INIT; *message = init_value; } -void test__root_message__init - (Test__RootMessage *message) +void test__root_message__init(Test__RootMessage *message) { static const Test__RootMessage init_value = TEST__ROOT_MESSAGE__INIT; *message = init_value; } -size_t test__root_message__get_packed_size - (const Test__RootMessage *message) +size_t test__root_message__get_packed_size(const Test__RootMessage *message) { assert(message->base.descriptor == &test__root_message__descriptor); - return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); + return protobuf_c_message_get_packed_size( + (const ProtobufCMessage *) (message)); } -size_t test__root_message__pack - (const Test__RootMessage *message, - uint8_t *out) +size_t test__root_message__pack(const Test__RootMessage *message, uint8_t *out) { assert(message->base.descriptor == &test__root_message__descriptor); - return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); + return protobuf_c_message_pack((const ProtobufCMessage *) message, out); } -size_t test__root_message__pack_to_buffer - (const Test__RootMessage *message, - ProtobufCBuffer *buffer) +size_t test__root_message__pack_to_buffer( + const Test__RootMessage *message, + ProtobufCBuffer *buffer) { assert(message->base.descriptor == &test__root_message__descriptor); - return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); + return protobuf_c_message_pack_to_buffer( + (const ProtobufCMessage *) message, buffer); } -Test__RootMessage * - test__root_message__unpack - (ProtobufCAllocator *allocator, - size_t len, - const uint8_t *data) +Test__RootMessage *test__root_message__unpack( + ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data) { - return (Test__RootMessage *) - protobuf_c_message_unpack (&test__root_message__descriptor, - allocator, len, data); + return (Test__RootMessage *) protobuf_c_message_unpack( + &test__root_message__descriptor, allocator, len, data); } -void test__root_message__free_unpacked - (Test__RootMessage *message, - ProtobufCAllocator *allocator) +void test__root_message__free_unpacked( + Test__RootMessage *message, + ProtobufCAllocator *allocator) { - if(!message) + if (!message) return; assert(message->base.descriptor == &test__root_message__descriptor); - protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); + protobuf_c_message_free_unpacked((ProtobufCMessage *) message, allocator); } -static const ProtobufCFieldDescriptor test__struct__nested_struct__field_descriptors[2] = -{ - { - "f_int32", - 1, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_INT32, - offsetof(Test__Struct__NestedStruct, has_f_int32), - offsetof(Test__Struct__NestedStruct, f_int32), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_string", - 2, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(Test__Struct__NestedStruct, f_string), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, +static const ProtobufCFieldDescriptor + test__struct__nested_struct__field_descriptors[2] = { + { + "f_int32", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_INT32, + offsetof(Test__Struct__NestedStruct, has_f_int32), + offsetof(Test__Struct__NestedStruct, f_int32), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_string", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(Test__Struct__NestedStruct, f_string), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned test__struct__nested_struct__field_indices_by_name[] = { - 0, /* field[0] = f_int32 */ - 1, /* field[1] = f_string */ -}; -static const ProtobufCIntRange test__struct__nested_struct__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 2 } -}; -const ProtobufCMessageDescriptor test__struct__nested_struct__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "test.Struct.NestedStruct", - "NestedStruct", - "Test__Struct__NestedStruct", - "test", - sizeof(Test__Struct__NestedStruct), - 2, - test__struct__nested_struct__field_descriptors, - test__struct__nested_struct__field_indices_by_name, - 1, test__struct__nested_struct__number_ranges, - (ProtobufCMessageInit) test__struct__nested_struct__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCEnumValue test__struct__enum__enum_values_by_number[2] = -{ - { "FIRST", "TEST__STRUCT__ENUM__FIRST", 0 }, - { "SECOND", "TEST__STRUCT__ENUM__SECOND", 1 }, -}; -static const ProtobufCIntRange test__struct__enum__value_ranges[] = { -{0, 0},{0, 2} -}; -static const ProtobufCEnumValueIndex test__struct__enum__enum_values_by_name[2] = -{ - { "FIRST", 0 }, - { "SECOND", 1 }, -}; -const ProtobufCEnumDescriptor test__struct__enum__descriptor = -{ - PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC, - "test.Struct.Enum", - "Enum", - "Test__Struct__Enum", - "test", - 2, - test__struct__enum__enum_values_by_number, - 2, - test__struct__enum__enum_values_by_name, - 1, - test__struct__enum__value_ranges, - NULL,NULL,NULL,NULL /* reserved[1234] */ -}; -static const ProtobufCFieldDescriptor test__struct__field_descriptors[4] = -{ - { - "f_string", - 1, - PROTOBUF_C_LABEL_REQUIRED, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(Test__Struct, f_string), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_enum", + 0, /* field[0] = f_int32 */ + 1, /* field[1] = f_string */ +}; +static const ProtobufCIntRange + test__struct__nested_struct__number_ranges[1 + 1] = {{1, 0}, {0, 2}}; +const ProtobufCMessageDescriptor test__struct__nested_struct__descriptor = { + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "test.Struct.NestedStruct", + "NestedStruct", + "Test__Struct__NestedStruct", + "test", + sizeof(Test__Struct__NestedStruct), 2, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_ENUM, - offsetof(Test__Struct, has_f_enum), - offsetof(Test__Struct, f_enum), - &test__struct__enum__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_nested_struct", - 3, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_MESSAGE, - 0, /* quantifier_offset */ - offsetof(Test__Struct, f_nested_struct), - &test__struct__nested_struct__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_nested_struct_array", - 4, - PROTOBUF_C_LABEL_REPEATED, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(Test__Struct, n_f_nested_struct_array), - offsetof(Test__Struct, f_nested_struct_array), - &test__struct__nested_struct__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned test__struct__field_indices_by_name[] = { - 1, /* field[1] = f_enum */ - 2, /* field[2] = f_nested_struct */ - 3, /* field[3] = f_nested_struct_array */ - 0, /* field[0] = f_string */ -}; -static const ProtobufCIntRange test__struct__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 4 } -}; -const ProtobufCMessageDescriptor test__struct__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "test.Struct", - "Struct", - "Test__Struct", - "test", - sizeof(Test__Struct), - 4, - test__struct__field_descriptors, - test__struct__field_indices_by_name, - 1, test__struct__number_ranges, - (ProtobufCMessageInit) test__struct__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor test__map_struct__field_descriptors[2] = -{ - { - "f_int32", + test__struct__nested_struct__field_descriptors, + test__struct__nested_struct__field_indices_by_name, 1, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_INT32, - offsetof(Test__MapStruct, has_f_int32), - offsetof(Test__MapStruct, f_int32), + test__struct__nested_struct__number_ranges, + (ProtobufCMessageInit) test__struct__nested_struct__init, NULL, NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_int64", - 2, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_INT64, - offsetof(Test__MapStruct, has_f_int64), - offsetof(Test__MapStruct, f_int64), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, + NULL /* reserved[123] */ }; -static const unsigned test__map_struct__field_indices_by_name[] = { - 0, /* field[0] = f_int32 */ - 1, /* field[1] = f_int64 */ +static const ProtobufCEnumValue test__struct__enum__enum_values_by_number[2] = { + {"FIRST", "TEST__STRUCT__ENUM__FIRST", 0}, + {"SECOND", "TEST__STRUCT__ENUM__SECOND", 1}, }; -static const ProtobufCIntRange test__map_struct__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 2 } -}; -const ProtobufCMessageDescriptor test__map_struct__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "test.MapStruct", - "MapStruct", - "Test__MapStruct", - "test", - sizeof(Test__MapStruct), - 2, - test__map_struct__field_descriptors, - test__map_struct__field_indices_by_name, - 1, test__map_struct__number_ranges, - (ProtobufCMessageInit) test__map_struct__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor test__root_message__fmap_int32_entry__field_descriptors[2] = -{ - { - "key", - 1, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(Test__RootMessage__FMapInt32Entry, key), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "value", +static const ProtobufCIntRange test__struct__enum__value_ranges[] = { + {0, 0}, + {0, 2}}; +static const ProtobufCEnumValueIndex + test__struct__enum__enum_values_by_name[2] = { + {"FIRST", 0}, + {"SECOND", 1}, +}; +const ProtobufCEnumDescriptor test__struct__enum__descriptor = { + PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC, + "test.Struct.Enum", + "Enum", + "Test__Struct__Enum", + "test", 2, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_INT32, - offsetof(Test__RootMessage__FMapInt32Entry, has_value), - offsetof(Test__RootMessage__FMapInt32Entry, value), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned test__root_message__fmap_int32_entry__field_indices_by_name[] = { - 0, /* field[0] = key */ - 1, /* field[1] = value */ -}; -static const ProtobufCIntRange test__root_message__fmap_int32_entry__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 2 } -}; -const ProtobufCMessageDescriptor test__root_message__fmap_int32_entry__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "test.RootMessage.FMapInt32Entry", - "FMapInt32Entry", - "Test__RootMessage__FMapInt32Entry", - "test", - sizeof(Test__RootMessage__FMapInt32Entry), - 2, - test__root_message__fmap_int32_entry__field_descriptors, - test__root_message__fmap_int32_entry__field_indices_by_name, - 1, test__root_message__fmap_int32_entry__number_ranges, - (ProtobufCMessageInit) test__root_message__fmap_int32_entry__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor test__root_message__fmap_bool_entry__field_descriptors[2] = -{ - { - "key", - 1, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(Test__RootMessage__FMapBoolEntry, key), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "value", + test__struct__enum__enum_values_by_number, 2, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_BOOL, - offsetof(Test__RootMessage__FMapBoolEntry, has_value), - offsetof(Test__RootMessage__FMapBoolEntry, value), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned test__root_message__fmap_bool_entry__field_indices_by_name[] = { - 0, /* field[0] = key */ - 1, /* field[1] = value */ -}; -static const ProtobufCIntRange test__root_message__fmap_bool_entry__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 2 } -}; -const ProtobufCMessageDescriptor test__root_message__fmap_bool_entry__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "test.RootMessage.FMapBoolEntry", - "FMapBoolEntry", - "Test__RootMessage__FMapBoolEntry", - "test", - sizeof(Test__RootMessage__FMapBoolEntry), - 2, - test__root_message__fmap_bool_entry__field_descriptors, - test__root_message__fmap_bool_entry__field_indices_by_name, - 1, test__root_message__fmap_bool_entry__number_ranges, - (ProtobufCMessageInit) test__root_message__fmap_bool_entry__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor test__root_message__fmap_string_entry__field_descriptors[2] = -{ - { - "key", + test__struct__enum__enum_values_by_name, 1, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(Test__RootMessage__FMapStringEntry, key), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "value", - 2, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(Test__RootMessage__FMapStringEntry, value), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned test__root_message__fmap_string_entry__field_indices_by_name[] = { - 0, /* field[0] = key */ - 1, /* field[1] = value */ -}; -static const ProtobufCIntRange test__root_message__fmap_string_entry__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 2 } -}; -const ProtobufCMessageDescriptor test__root_message__fmap_string_entry__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "test.RootMessage.FMapStringEntry", - "FMapStringEntry", - "Test__RootMessage__FMapStringEntry", - "test", - sizeof(Test__RootMessage__FMapStringEntry), - 2, - test__root_message__fmap_string_entry__field_descriptors, - test__root_message__fmap_string_entry__field_indices_by_name, - 1, test__root_message__fmap_string_entry__number_ranges, - (ProtobufCMessageInit) test__root_message__fmap_string_entry__init, - NULL,NULL,NULL /* reserved[123] */ + test__struct__enum__value_ranges, + NULL, + NULL, + NULL, + NULL /* reserved[1234] */ +}; +static const ProtobufCFieldDescriptor test__struct__field_descriptors[4] = { + { + "f_string", + 1, + PROTOBUF_C_LABEL_REQUIRED, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(Test__Struct, f_string), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_enum", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_ENUM, + offsetof(Test__Struct, has_f_enum), + offsetof(Test__Struct, f_enum), + &test__struct__enum__descriptor, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_nested_struct", + 3, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_MESSAGE, + 0, /* quantifier_offset */ + offsetof(Test__Struct, f_nested_struct), + &test__struct__nested_struct__descriptor, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_nested_struct_array", + 4, + PROTOBUF_C_LABEL_REPEATED, + PROTOBUF_C_TYPE_MESSAGE, + offsetof(Test__Struct, n_f_nested_struct_array), + offsetof(Test__Struct, f_nested_struct_array), + &test__struct__nested_struct__descriptor, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, }; -static const ProtobufCFieldDescriptor test__root_message__fmap_float_entry__field_descriptors[2] = -{ - { - "key", +static const unsigned test__struct__field_indices_by_name[] = { + 1, /* field[1] = f_enum */ + 2, /* field[2] = f_nested_struct */ + 3, /* field[3] = f_nested_struct_array */ + 0, /* field[0] = f_string */ +}; +static const ProtobufCIntRange test__struct__number_ranges[1 + 1] = { + {1, 0}, + {0, 4}}; +const ProtobufCMessageDescriptor test__struct__descriptor = { + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "test.Struct", + "Struct", + "Test__Struct", + "test", + sizeof(Test__Struct), + 4, + test__struct__field_descriptors, + test__struct__field_indices_by_name, 1, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(Test__RootMessage__FMapFloatEntry, key), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "value", - 2, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_FLOAT, - offsetof(Test__RootMessage__FMapFloatEntry, has_value), - offsetof(Test__RootMessage__FMapFloatEntry, value), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned test__root_message__fmap_float_entry__field_indices_by_name[] = { - 0, /* field[0] = key */ - 1, /* field[1] = value */ -}; -static const ProtobufCIntRange test__root_message__fmap_float_entry__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 2 } + test__struct__number_ranges, + (ProtobufCMessageInit) test__struct__init, + NULL, + NULL, + NULL /* reserved[123] */ +}; +static const ProtobufCFieldDescriptor test__map_struct__field_descriptors[2] = { + { + "f_int32", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_INT32, + offsetof(Test__MapStruct, has_f_int32), + offsetof(Test__MapStruct, f_int32), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_int64", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_INT64, + offsetof(Test__MapStruct, has_f_int64), + offsetof(Test__MapStruct, f_int64), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, }; -const ProtobufCMessageDescriptor test__root_message__fmap_float_entry__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "test.RootMessage.FMapFloatEntry", - "FMapFloatEntry", - "Test__RootMessage__FMapFloatEntry", - "test", - sizeof(Test__RootMessage__FMapFloatEntry), - 2, - test__root_message__fmap_float_entry__field_descriptors, - test__root_message__fmap_float_entry__field_indices_by_name, - 1, test__root_message__fmap_float_entry__number_ranges, - (ProtobufCMessageInit) test__root_message__fmap_float_entry__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor test__root_message__fmap_struct_entry__field_descriptors[2] = -{ - { - "key", - 1, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(Test__RootMessage__FMapStructEntry, key), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "value", +static const unsigned test__map_struct__field_indices_by_name[] = { + 0, /* field[0] = f_int32 */ + 1, /* field[1] = f_int64 */ +}; +static const ProtobufCIntRange test__map_struct__number_ranges[1 + 1] = { + {1, 0}, + {0, 2}}; +const ProtobufCMessageDescriptor test__map_struct__descriptor = { + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "test.MapStruct", + "MapStruct", + "Test__MapStruct", + "test", + sizeof(Test__MapStruct), 2, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_MESSAGE, - 0, /* quantifier_offset */ - offsetof(Test__RootMessage__FMapStructEntry, value), - &test__map_struct__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned test__root_message__fmap_struct_entry__field_indices_by_name[] = { - 0, /* field[0] = key */ - 1, /* field[1] = value */ -}; -static const ProtobufCIntRange test__root_message__fmap_struct_entry__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 2 } -}; -const ProtobufCMessageDescriptor test__root_message__fmap_struct_entry__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "test.RootMessage.FMapStructEntry", - "FMapStructEntry", - "Test__RootMessage__FMapStructEntry", - "test", - sizeof(Test__RootMessage__FMapStructEntry), - 2, - test__root_message__fmap_struct_entry__field_descriptors, - test__root_message__fmap_struct_entry__field_indices_by_name, - 1, test__root_message__fmap_struct_entry__number_ranges, - (ProtobufCMessageInit) test__root_message__fmap_struct_entry__init, - NULL,NULL,NULL /* reserved[123] */ -}; -static const ProtobufCFieldDescriptor test__root_message__field_descriptors[19] = -{ - { - "f_int32", + test__map_struct__field_descriptors, + test__map_struct__field_indices_by_name, 1, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_INT32, - offsetof(Test__RootMessage, has_f_int32), - offsetof(Test__RootMessage, f_int32), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_int64", - 2, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_INT64, - offsetof(Test__RootMessage, has_f_int64), - offsetof(Test__RootMessage, f_int64), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_sint32", - 5, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_SINT32, - offsetof(Test__RootMessage, has_f_sint32), - offsetof(Test__RootMessage, f_sint32), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_sint64", - 6, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_SINT64, - offsetof(Test__RootMessage, has_f_sint64), - offsetof(Test__RootMessage, f_sint64), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_sfixed32", - 9, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_SFIXED32, - offsetof(Test__RootMessage, has_f_sfixed32), - offsetof(Test__RootMessage, f_sfixed32), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_sfixed64", - 10, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_SFIXED64, - offsetof(Test__RootMessage, has_f_sfixed64), - offsetof(Test__RootMessage, f_sfixed64), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_bool", - 11, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_BOOL, - offsetof(Test__RootMessage, has_f_bool), - offsetof(Test__RootMessage, f_bool), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_string", - 12, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(Test__RootMessage, f_string), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_bytes", - 13, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_BYTES, - offsetof(Test__RootMessage, has_f_bytes), - offsetof(Test__RootMessage, f_bytes), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_struct_array", - 14, - PROTOBUF_C_LABEL_REPEATED, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(Test__RootMessage, n_f_struct_array), - offsetof(Test__RootMessage, f_struct_array), - &test__struct__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_map_int32", - 15, - PROTOBUF_C_LABEL_REPEATED, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(Test__RootMessage, n_f_map_int32), - offsetof(Test__RootMessage, f_map_int32), - &test__root_message__fmap_int32_entry__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_map_bool", - 16, - PROTOBUF_C_LABEL_REPEATED, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(Test__RootMessage, n_f_map_bool), - offsetof(Test__RootMessage, f_map_bool), - &test__root_message__fmap_bool_entry__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_map_string", - 17, - PROTOBUF_C_LABEL_REPEATED, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(Test__RootMessage, n_f_map_string), - offsetof(Test__RootMessage, f_map_string), - &test__root_message__fmap_string_entry__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_map_float", - 18, - PROTOBUF_C_LABEL_REPEATED, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(Test__RootMessage, n_f_map_float), - offsetof(Test__RootMessage, f_map_float), - &test__root_message__fmap_float_entry__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_map_struct", + test__map_struct__number_ranges, + (ProtobufCMessageInit) test__map_struct__init, + NULL, + NULL, + NULL /* reserved[123] */ +}; +static const ProtobufCFieldDescriptor + test__root_message__fmap_int32_entry__field_descriptors[2] = { + { + "key", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(Test__RootMessage__FMapInt32Entry, key), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "value", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_INT32, + offsetof(Test__RootMessage__FMapInt32Entry, has_value), + offsetof(Test__RootMessage__FMapInt32Entry, value), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned + test__root_message__fmap_int32_entry__field_indices_by_name[] = { + 0, /* field[0] = key */ + 1, /* field[1] = value */ +}; +static const ProtobufCIntRange + test__root_message__fmap_int32_entry__number_ranges[1 + 1] = { + {1, 0}, + {0, 2}}; +const ProtobufCMessageDescriptor + test__root_message__fmap_int32_entry__descriptor = { + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "test.RootMessage.FMapInt32Entry", + "FMapInt32Entry", + "Test__RootMessage__FMapInt32Entry", + "test", + sizeof(Test__RootMessage__FMapInt32Entry), + 2, + test__root_message__fmap_int32_entry__field_descriptors, + test__root_message__fmap_int32_entry__field_indices_by_name, + 1, + test__root_message__fmap_int32_entry__number_ranges, + (ProtobufCMessageInit) test__root_message__fmap_int32_entry__init, + NULL, + NULL, + NULL /* reserved[123] */ +}; +static const ProtobufCFieldDescriptor + test__root_message__fmap_bool_entry__field_descriptors[2] = { + { + "key", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(Test__RootMessage__FMapBoolEntry, key), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "value", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_BOOL, + offsetof(Test__RootMessage__FMapBoolEntry, has_value), + offsetof(Test__RootMessage__FMapBoolEntry, value), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned + test__root_message__fmap_bool_entry__field_indices_by_name[] = { + 0, /* field[0] = key */ + 1, /* field[1] = value */ +}; +static const ProtobufCIntRange + test__root_message__fmap_bool_entry__number_ranges[1 + 1] = { + {1, 0}, + {0, 2}}; +const ProtobufCMessageDescriptor + test__root_message__fmap_bool_entry__descriptor = { + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "test.RootMessage.FMapBoolEntry", + "FMapBoolEntry", + "Test__RootMessage__FMapBoolEntry", + "test", + sizeof(Test__RootMessage__FMapBoolEntry), + 2, + test__root_message__fmap_bool_entry__field_descriptors, + test__root_message__fmap_bool_entry__field_indices_by_name, + 1, + test__root_message__fmap_bool_entry__number_ranges, + (ProtobufCMessageInit) test__root_message__fmap_bool_entry__init, + NULL, + NULL, + NULL /* reserved[123] */ +}; +static const ProtobufCFieldDescriptor + test__root_message__fmap_string_entry__field_descriptors[2] = { + { + "key", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(Test__RootMessage__FMapStringEntry, key), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "value", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(Test__RootMessage__FMapStringEntry, value), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned + test__root_message__fmap_string_entry__field_indices_by_name[] = { + 0, /* field[0] = key */ + 1, /* field[1] = value */ +}; +static const ProtobufCIntRange + test__root_message__fmap_string_entry__number_ranges[1 + 1] = { + {1, 0}, + {0, 2}}; +const ProtobufCMessageDescriptor + test__root_message__fmap_string_entry__descriptor = { + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "test.RootMessage.FMapStringEntry", + "FMapStringEntry", + "Test__RootMessage__FMapStringEntry", + "test", + sizeof(Test__RootMessage__FMapStringEntry), + 2, + test__root_message__fmap_string_entry__field_descriptors, + test__root_message__fmap_string_entry__field_indices_by_name, + 1, + test__root_message__fmap_string_entry__number_ranges, + (ProtobufCMessageInit) test__root_message__fmap_string_entry__init, + NULL, + NULL, + NULL /* reserved[123] */ +}; +static const ProtobufCFieldDescriptor + test__root_message__fmap_float_entry__field_descriptors[2] = { + { + "key", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(Test__RootMessage__FMapFloatEntry, key), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "value", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_FLOAT, + offsetof(Test__RootMessage__FMapFloatEntry, has_value), + offsetof(Test__RootMessage__FMapFloatEntry, value), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned + test__root_message__fmap_float_entry__field_indices_by_name[] = { + 0, /* field[0] = key */ + 1, /* field[1] = value */ +}; +static const ProtobufCIntRange + test__root_message__fmap_float_entry__number_ranges[1 + 1] = { + {1, 0}, + {0, 2}}; +const ProtobufCMessageDescriptor + test__root_message__fmap_float_entry__descriptor = { + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "test.RootMessage.FMapFloatEntry", + "FMapFloatEntry", + "Test__RootMessage__FMapFloatEntry", + "test", + sizeof(Test__RootMessage__FMapFloatEntry), + 2, + test__root_message__fmap_float_entry__field_descriptors, + test__root_message__fmap_float_entry__field_indices_by_name, + 1, + test__root_message__fmap_float_entry__number_ranges, + (ProtobufCMessageInit) test__root_message__fmap_float_entry__init, + NULL, + NULL, + NULL /* reserved[123] */ +}; +static const ProtobufCFieldDescriptor + test__root_message__fmap_struct_entry__field_descriptors[2] = { + { + "key", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(Test__RootMessage__FMapStructEntry, key), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "value", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_MESSAGE, + 0, /* quantifier_offset */ + offsetof(Test__RootMessage__FMapStructEntry, value), + &test__map_struct__descriptor, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned + test__root_message__fmap_struct_entry__field_indices_by_name[] = { + 0, /* field[0] = key */ + 1, /* field[1] = value */ +}; +static const ProtobufCIntRange + test__root_message__fmap_struct_entry__number_ranges[1 + 1] = { + {1, 0}, + {0, 2}}; +const ProtobufCMessageDescriptor + test__root_message__fmap_struct_entry__descriptor = { + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "test.RootMessage.FMapStructEntry", + "FMapStructEntry", + "Test__RootMessage__FMapStructEntry", + "test", + sizeof(Test__RootMessage__FMapStructEntry), + 2, + test__root_message__fmap_struct_entry__field_descriptors, + test__root_message__fmap_struct_entry__field_indices_by_name, + 1, + test__root_message__fmap_struct_entry__number_ranges, + (ProtobufCMessageInit) test__root_message__fmap_struct_entry__init, + NULL, + NULL, + NULL /* reserved[123] */ +}; +static const ProtobufCFieldDescriptor + test__root_message__field_descriptors[19] = { + { + "f_int32", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_INT32, + offsetof(Test__RootMessage, has_f_int32), + offsetof(Test__RootMessage, f_int32), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_int64", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_INT64, + offsetof(Test__RootMessage, has_f_int64), + offsetof(Test__RootMessage, f_int64), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_sint32", + 5, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_SINT32, + offsetof(Test__RootMessage, has_f_sint32), + offsetof(Test__RootMessage, f_sint32), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_sint64", + 6, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_SINT64, + offsetof(Test__RootMessage, has_f_sint64), + offsetof(Test__RootMessage, f_sint64), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_sfixed32", + 9, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_SFIXED32, + offsetof(Test__RootMessage, has_f_sfixed32), + offsetof(Test__RootMessage, f_sfixed32), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_sfixed64", + 10, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_SFIXED64, + offsetof(Test__RootMessage, has_f_sfixed64), + offsetof(Test__RootMessage, f_sfixed64), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_bool", + 11, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_BOOL, + offsetof(Test__RootMessage, has_f_bool), + offsetof(Test__RootMessage, f_bool), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_string", + 12, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(Test__RootMessage, f_string), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_bytes", + 13, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_BYTES, + offsetof(Test__RootMessage, has_f_bytes), + offsetof(Test__RootMessage, f_bytes), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_struct_array", + 14, + PROTOBUF_C_LABEL_REPEATED, + PROTOBUF_C_TYPE_MESSAGE, + offsetof(Test__RootMessage, n_f_struct_array), + offsetof(Test__RootMessage, f_struct_array), + &test__struct__descriptor, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_map_int32", + 15, + PROTOBUF_C_LABEL_REPEATED, + PROTOBUF_C_TYPE_MESSAGE, + offsetof(Test__RootMessage, n_f_map_int32), + offsetof(Test__RootMessage, f_map_int32), + &test__root_message__fmap_int32_entry__descriptor, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_map_bool", + 16, + PROTOBUF_C_LABEL_REPEATED, + PROTOBUF_C_TYPE_MESSAGE, + offsetof(Test__RootMessage, n_f_map_bool), + offsetof(Test__RootMessage, f_map_bool), + &test__root_message__fmap_bool_entry__descriptor, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_map_string", + 17, + PROTOBUF_C_LABEL_REPEATED, + PROTOBUF_C_TYPE_MESSAGE, + offsetof(Test__RootMessage, n_f_map_string), + offsetof(Test__RootMessage, f_map_string), + &test__root_message__fmap_string_entry__descriptor, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_map_float", + 18, + PROTOBUF_C_LABEL_REPEATED, + PROTOBUF_C_TYPE_MESSAGE, + offsetof(Test__RootMessage, n_f_map_float), + offsetof(Test__RootMessage, f_map_float), + &test__root_message__fmap_float_entry__descriptor, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_map_struct", + 19, + PROTOBUF_C_LABEL_REPEATED, + PROTOBUF_C_TYPE_MESSAGE, + offsetof(Test__RootMessage, n_f_map_struct), + offsetof(Test__RootMessage, f_map_struct), + &test__root_message__fmap_struct_entry__descriptor, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_oneof_string", + 20, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + offsetof(Test__RootMessage, f_oneof_case), + offsetof(Test__RootMessage, f_oneof_string), + NULL, + NULL, + 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_oneof_struct", + 21, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_MESSAGE, + offsetof(Test__RootMessage, f_oneof_case), + offsetof(Test__RootMessage, f_oneof_struct), + &test__map_struct__descriptor, + NULL, + 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_ignored", + 22, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(Test__RootMessage, f_ignored), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, + { + "f_renamed", + 23, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(Test__RootMessage, f_renamed), + NULL, + NULL, + 0, /* flags */ + 0, + NULL, + NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned test__root_message__field_indices_by_name[] = { + 6, /* field[6] = f_bool */ + 8, /* field[8] = f_bytes */ + 17, /* field[17] = f_ignored */ + 0, /* field[0] = f_int32 */ + 1, /* field[1] = f_int64 */ + 11, /* field[11] = f_map_bool */ + 13, /* field[13] = f_map_float */ + 10, /* field[10] = f_map_int32 */ + 12, /* field[12] = f_map_string */ + 14, /* field[14] = f_map_struct */ + 15, /* field[15] = f_oneof_string */ + 16, /* field[16] = f_oneof_struct */ + 18, /* field[18] = f_renamed */ + 4, /* field[4] = f_sfixed32 */ + 5, /* field[5] = f_sfixed64 */ + 2, /* field[2] = f_sint32 */ + 3, /* field[3] = f_sint64 */ + 7, /* field[7] = f_string */ + 9, /* field[9] = f_struct_array */ +}; +static const ProtobufCIntRange test__root_message__number_ranges[3 + 1] = { + {1, 0}, + {5, 2}, + {9, 4}, + {0, 19}}; +const ProtobufCMessageDescriptor test__root_message__descriptor = { + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "test.RootMessage", + "RootMessage", + "Test__RootMessage", + "test", + sizeof(Test__RootMessage), 19, - PROTOBUF_C_LABEL_REPEATED, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(Test__RootMessage, n_f_map_struct), - offsetof(Test__RootMessage, f_map_struct), - &test__root_message__fmap_struct_entry__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_oneof_string", - 20, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - offsetof(Test__RootMessage, f_oneof_case), - offsetof(Test__RootMessage, f_oneof_string), - NULL, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_oneof_struct", - 21, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_MESSAGE, - offsetof(Test__RootMessage, f_oneof_case), - offsetof(Test__RootMessage, f_oneof_struct), - &test__map_struct__descriptor, - NULL, - 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_ignored", - 22, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(Test__RootMessage, f_ignored), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "f_renamed", - 23, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(Test__RootMessage, f_renamed), + test__root_message__field_descriptors, + test__root_message__field_indices_by_name, + 3, + test__root_message__number_ranges, + (ProtobufCMessageInit) test__root_message__init, NULL, NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned test__root_message__field_indices_by_name[] = { - 6, /* field[6] = f_bool */ - 8, /* field[8] = f_bytes */ - 17, /* field[17] = f_ignored */ - 0, /* field[0] = f_int32 */ - 1, /* field[1] = f_int64 */ - 11, /* field[11] = f_map_bool */ - 13, /* field[13] = f_map_float */ - 10, /* field[10] = f_map_int32 */ - 12, /* field[12] = f_map_string */ - 14, /* field[14] = f_map_struct */ - 15, /* field[15] = f_oneof_string */ - 16, /* field[16] = f_oneof_struct */ - 18, /* field[18] = f_renamed */ - 4, /* field[4] = f_sfixed32 */ - 5, /* field[5] = f_sfixed64 */ - 2, /* field[2] = f_sint32 */ - 3, /* field[3] = f_sint64 */ - 7, /* field[7] = f_string */ - 9, /* field[9] = f_struct_array */ -}; -static const ProtobufCIntRange test__root_message__number_ranges[3 + 1] = -{ - { 1, 0 }, - { 5, 2 }, - { 9, 4 }, - { 0, 19 } -}; -const ProtobufCMessageDescriptor test__root_message__descriptor = -{ - PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "test.RootMessage", - "RootMessage", - "Test__RootMessage", - "test", - sizeof(Test__RootMessage), - 19, - test__root_message__field_descriptors, - test__root_message__field_indices_by_name, - 3, test__root_message__number_ranges, - (ProtobufCMessageInit) test__root_message__init, - NULL,NULL,NULL /* reserved[123] */ + NULL /* reserved[123] */ }; diff --git a/libyara/modules/pb_to_module.rst b/libyara/modules/pb_to_module.rst new file mode 100644 index 0000000000..5cd01187ee --- /dev/null +++ b/libyara/modules/pb_to_module.rst @@ -0,0 +1,33 @@ +Generating a module from a Protocol Buffer + + +[Protocol Buffers](https://developers.google.com/protocol-buffers) (protobufs) +are Google's language-neutral, platform-idependent mechanism for serializing +structured data. The first thing you need to do for using protobuf is defining +your data structures, for example: + +message Employee { + int32 id = 1; + string name = 2; + int32 age = 3 + string email = 4; +} + +Once you have defined your data structure, you use a protobuf compiler to +automatically generate the code that will marshal/unmarshall the data structure +into/from a bytes sequence. The protobuf compiler is able to generate code in +multiple languages, including C/C++, Python, Java and Go. + +Now imagine that you can pass the marshalled data structure to YARA, and create +rules based in that data. Like for example: + +import "vt_employee" + +rule virustotal_employee_under_25 +{ + condition: + vt_employee.age < 25 and + vt_employee.email matches /*.@virustotal\.com/ +} + +Neat, right? diff --git a/libyara/modules/pe/pe.c b/libyara/modules/pe/pe.c index 7a5e7e7907..e943c4ef89 100644 --- a/libyara/modules/pe/pe.c +++ b/libyara/modules/pe/pe.c @@ -27,16 +27,16 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include #include #include "../crypto.h" #if defined(HAVE_LIBCRYPTO) -#include #include #include #include +#include #include #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) @@ -45,20 +45,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if OPENSSL_VERSION_NUMBER < 0x10100000L #define X509_get0_notBefore X509_get_notBefore -#define X509_get0_notAfter X509_get_notAfter +#define X509_get0_notAfter X509_get_notAfter #endif #endif #include -#include -#include #include +#include +#include +#include #include #include - -#include - #define MODULE_NAME pe // http://msdn.microsoft.com/en-us/library/ms648009(v=vs.85).aspx @@ -73,53 +71,52 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define RESOURCE_TYPE_ACCELERATOR 9 #define RESOURCE_TYPE_RCDATA 10 #define RESOURCE_TYPE_MESSAGETABLE 11 -#define RESOURCE_TYPE_GROUP_CURSOR 12 // MAKEINTRESOURCE((ULONG_PTR)(RT_CURSOR) + 11) -#define RESOURCE_TYPE_GROUP_ICON 14 // MAKEINTRESOURCE((ULONG_PTR)(RT_ICON) + 11) -#define RESOURCE_TYPE_VERSION 16 -#define RESOURCE_TYPE_DLGINCLUDE 17 -#define RESOURCE_TYPE_PLUGPLAY 19 -#define RESOURCE_TYPE_VXD 20 -#define RESOURCE_TYPE_ANICURSOR 21 -#define RESOURCE_TYPE_ANIICON 22 -#define RESOURCE_TYPE_HTML 23 -#define RESOURCE_TYPE_MANIFEST 24 +#define RESOURCE_TYPE_GROUP_CURSOR \ + 12 // MAKEINTRESOURCE((ULONG_PTR)(RT_CURSOR) + 11) +#define RESOURCE_TYPE_GROUP_ICON \ + 14 // MAKEINTRESOURCE((ULONG_PTR)(RT_ICON) + 11) +#define RESOURCE_TYPE_VERSION 16 +#define RESOURCE_TYPE_DLGINCLUDE 17 +#define RESOURCE_TYPE_PLUGPLAY 19 +#define RESOURCE_TYPE_VXD 20 +#define RESOURCE_TYPE_ANICURSOR 21 +#define RESOURCE_TYPE_ANIICON 22 +#define RESOURCE_TYPE_HTML 23 +#define RESOURCE_TYPE_MANIFEST 24 -#define RESOURCE_CALLBACK_CONTINUE 0 -#define RESOURCE_CALLBACK_ABORT 1 +#define RESOURCE_CALLBACK_CONTINUE 0 +#define RESOURCE_CALLBACK_ABORT 1 -#define RESOURCE_ITERATOR_FINISHED 0 -#define RESOURCE_ITERATOR_ABORTED 1 +#define RESOURCE_ITERATOR_FINISHED 0 +#define RESOURCE_ITERATOR_ABORTED 1 -#define MAX_PE_IMPORTS 16384 -#define MAX_PE_EXPORTS 8192 -#define MAX_EXPORT_NAME_LENGTH 512 +#define MAX_PE_IMPORTS 16384 +#define MAX_PE_EXPORTS 8192 +#define MAX_EXPORT_NAME_LENGTH 512 #define IS_RESOURCE_SUBDIRECTORY(entry) \ - (yr_le32toh((entry)->OffsetToData) & 0x80000000) + (yr_le32toh((entry)->OffsetToData) & 0x80000000) -#define RESOURCE_OFFSET(entry) \ - (yr_le32toh((entry)->OffsetToData) & 0x7FFFFFFF) +#define RESOURCE_OFFSET(entry) (yr_le32toh((entry)->OffsetToData) & 0x7FFFFFFF) -typedef int (*RESOURCE_CALLBACK_FUNC) ( \ - PIMAGE_RESOURCE_DATA_ENTRY rsrc_data, \ - int rsrc_type, \ - int rsrc_id, \ - int rsrc_language, \ - const uint8_t* type_string, \ - const uint8_t* name_string, \ - const uint8_t* lang_string, \ - void* cb_data); +typedef int (*RESOURCE_CALLBACK_FUNC)( + PIMAGE_RESOURCE_DATA_ENTRY rsrc_data, + int rsrc_type, + int rsrc_id, + int rsrc_language, + const uint8_t* type_string, + const uint8_t* name_string, + const uint8_t* lang_string, + void* cb_data); -static size_t available_space( - PE* pe, - void* pointer) +static size_t available_space(PE* pe, void* pointer) { if ((uint8_t*) pointer < pe->data) return 0; @@ -131,9 +128,7 @@ static size_t available_space( } -static int wide_string_fits_in_pe( - PE* pe, - char* data) +static int wide_string_fits_in_pe(PE* pe, char* data) { size_t i = 0; size_t space_left = available_space(pe, data); @@ -153,9 +148,7 @@ static int wide_string_fits_in_pe( // Parse the rich signature. // http://www.ntcore.com/files/richsign.htm -static void pe_parse_rich_signature( - PE* pe, - uint64_t base_address) +static void pe_parse_rich_signature(PE* pe, uint64_t base_address) { PIMAGE_DOS_HEADER mz_header; PRICH_SIGNATURE rich_signature = NULL; @@ -186,8 +179,9 @@ static void pe_parse_rich_signature( // true. 582ce3eea9c97d5e89f7d83953a6d518b16770e635a19a456c0225449c6967a4 is // one sample which has a Rich header starting at offset 0x200. To properly // find the Rich header we need to start at the NT header and work backwards. - p = (DWORD*)(pe->data + nthdr_offset - 4); - while (p > (DWORD*)(pe->data + sizeof(IMAGE_DOS_HEADER))) + p = (DWORD*) (pe->data + nthdr_offset - 4); + + while (p > (DWORD*) (pe->data + sizeof(IMAGE_DOS_HEADER))) { if (yr_le32toh(*p) == RICH_RICH) { @@ -208,7 +202,7 @@ static void pe_parse_rich_signature( return; // If we have found the key we need to now find the start (DanS). - while (p > (DWORD*)(pe->data + sizeof(IMAGE_DOS_HEADER))) + while (p > (DWORD*) (pe->data + sizeof(IMAGE_DOS_HEADER))) { if (yr_le32toh((*(p) ^ key)) == RICH_DANS) { @@ -229,7 +223,8 @@ static void pe_parse_rich_signature( if (yr_le32toh(rich_signature->key1) != yr_le32toh(rich_signature->key2) || yr_le32toh(rich_signature->key2) != yr_le32toh(rich_signature->key3) || - (yr_le32toh(rich_signature->dans) ^ yr_le32toh(rich_signature->key1)) != RICH_DANS) + (yr_le32toh(rich_signature->dans) ^ yr_le32toh(rich_signature->key1)) != + RICH_DANS) { return; } @@ -245,11 +240,13 @@ static void pe_parse_rich_signature( set_integer( base_address + ((uint8_t*) rich_signature - pe->data), - pe->object, "rich_signature.offset"); + pe->object, + "rich_signature.offset"); set_integer(rich_len, pe->object, "rich_signature.length"); - set_integer(yr_le32toh(rich_signature->key1), pe->object, "rich_signature.key"); + set_integer( + yr_le32toh(rich_signature->key1), pe->object, "rich_signature.key"); clear_data = (BYTE*) yr_malloc(rich_len); @@ -281,8 +278,7 @@ static void pe_parse_rich_signature( } -static void pe_parse_debug_directory( - PE* pe) +static void pe_parse_debug_directory(PE* pe) { PIMAGE_DATA_DIRECTORY data_dir; PIMAGE_DEBUG_DIRECTORY debug_dir; @@ -292,8 +288,7 @@ static void pe_parse_debug_directory( size_t pdb_path_len; char* pdb_path = NULL; - data_dir = pe_get_directory_entry( - pe, IMAGE_DIRECTORY_ENTRY_DEBUG); + data_dir = pe_get_directory_entry(pe, IMAGE_DIRECTORY_ENTRY_DEBUG); if (data_dir == NULL) return; @@ -307,8 +302,7 @@ static void pe_parse_debug_directory( if (yr_le32toh(data_dir->VirtualAddress) == 0) return; - debug_dir_offset = pe_rva_to_offset( - pe, yr_le32toh(data_dir->VirtualAddress)); + debug_dir_offset = pe_rva_to_offset(pe, yr_le32toh(data_dir->VirtualAddress)); if (debug_dir_offset < 0) return; @@ -317,8 +311,8 @@ static void pe_parse_debug_directory( for (i = 0; i < dcount; i++) { - debug_dir = (PIMAGE_DEBUG_DIRECTORY) \ - (pe->data + debug_dir_offset + i * sizeof(IMAGE_DEBUG_DIRECTORY)); + debug_dir = (PIMAGE_DEBUG_DIRECTORY)( + pe->data + debug_dir_offset + i * sizeof(IMAGE_DEBUG_DIRECTORY)); if (!struct_fits_in_pe(pe, debug_dir, IMAGE_DEBUG_DIRECTORY)) break; @@ -335,7 +329,7 @@ static void pe_parse_debug_directory( if (pcv_hdr_offset < 0) continue; - PCV_HEADER cv_hdr = (PCV_HEADER) (pe->data + pcv_hdr_offset); + PCV_HEADER cv_hdr = (PCV_HEADER)(pe->data + pcv_hdr_offset); if (!struct_fits_in_pe(pe, cv_hdr, CV_HEADER)) continue; @@ -380,7 +374,6 @@ static const uint8_t* parse_resource_name( const uint8_t* rsrc_data, PIMAGE_RESOURCE_DIRECTORY_ENTRY entry) { - // If high bit is set it is an offset relative to rsrc_data, which contains // a resource directory string. @@ -388,8 +381,8 @@ static const uint8_t* parse_resource_name( { DWORD length; - const uint8_t* rsrc_str_ptr = rsrc_data + \ - (yr_le32toh(entry->Name) & 0x7FFFFFFF); + const uint8_t* rsrc_str_ptr = rsrc_data + + (yr_le32toh(entry->Name) & 0x7FFFFFFF); // A resource directory string is 2 bytes for the length and then a variable // length Unicode string. Make sure we have at least 2 bytes. @@ -445,7 +438,7 @@ static int _pe_iterate_resources( // by incrementing resource_dir we skip sizeof(resource_dir) bytes // and get a pointer to the end of the resource directory. - entry = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (resource_dir + 1); + entry = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(resource_dir + 1); for (i = 0; i < total_entries; i++) { @@ -455,26 +448,26 @@ static int _pe_iterate_resources( break; } - switch(rsrc_tree_level) + switch (rsrc_tree_level) { - case 0: - *type = yr_le32toh(entry->Name); - type_string = parse_resource_name(pe, rsrc_data, entry); - break; - case 1: - *id = yr_le32toh(entry->Name); - name_string = parse_resource_name(pe, rsrc_data, entry); - break; - case 2: - *language = yr_le32toh(entry->Name); - lang_string = parse_resource_name(pe, rsrc_data, entry); - break; + case 0: + *type = yr_le32toh(entry->Name); + type_string = parse_resource_name(pe, rsrc_data, entry); + break; + case 1: + *id = yr_le32toh(entry->Name); + name_string = parse_resource_name(pe, rsrc_data, entry); + break; + case 2: + *language = yr_le32toh(entry->Name); + lang_string = parse_resource_name(pe, rsrc_data, entry); + break; } if (IS_RESOURCE_SUBDIRECTORY(entry) && rsrc_tree_level < 2) { - PIMAGE_RESOURCE_DIRECTORY directory = (PIMAGE_RESOURCE_DIRECTORY) \ - (rsrc_data + RESOURCE_OFFSET(entry)); + PIMAGE_RESOURCE_DIRECTORY directory = (PIMAGE_RESOURCE_DIRECTORY)( + rsrc_data + RESOURCE_OFFSET(entry)); if (struct_fits_in_pe(pe, directory, IMAGE_RESOURCE_DIRECTORY)) { @@ -499,20 +492,20 @@ static int _pe_iterate_resources( } else { - PIMAGE_RESOURCE_DATA_ENTRY data_entry = (PIMAGE_RESOURCE_DATA_ENTRY) \ - (rsrc_data + RESOURCE_OFFSET(entry)); + PIMAGE_RESOURCE_DATA_ENTRY data_entry = (PIMAGE_RESOURCE_DATA_ENTRY)( + rsrc_data + RESOURCE_OFFSET(entry)); if (struct_fits_in_pe(pe, data_entry, IMAGE_RESOURCE_DATA_ENTRY)) { if (callback( - data_entry, - *type, - *id, - *language, - type_string, - name_string, - lang_string, - callback_data) == RESOURCE_CALLBACK_ABORT) + data_entry, + *type, + *id, + *language, + type_string, + name_string, + lang_string, + callback_data) == RESOURCE_CALLBACK_ABORT) { result = RESOURCE_ITERATOR_ABORTED; } @@ -552,7 +545,7 @@ static int pe_iterate_resources( pe, IMAGE_DIRECTORY_ENTRY_RESOURCE); if (directory == NULL) - return 0; + return 0; if (yr_le32toh(directory->VirtualAddress) != 0) { @@ -563,20 +556,24 @@ static int pe_iterate_resources( if (offset < 0) return 0; - rsrc_dir = (PIMAGE_RESOURCE_DIRECTORY) (pe->data + offset); + rsrc_dir = (PIMAGE_RESOURCE_DIRECTORY)(pe->data + offset); if (struct_fits_in_pe(pe, rsrc_dir, IMAGE_RESOURCE_DIRECTORY)) { - set_integer(yr_le32toh(rsrc_dir->TimeDateStamp), + set_integer( + yr_le32toh(rsrc_dir->TimeDateStamp), pe->object, "resource_timestamp"); - set_integer(yr_le16toh(rsrc_dir->MajorVersion), - pe->object, - "resource_version.major"); - set_integer(yr_le16toh(rsrc_dir->MinorVersion), - pe->object, - "resource_version.minor"); + set_integer( + yr_le16toh(rsrc_dir->MajorVersion), + pe->object, + "resource_version.major"); + + set_integer( + yr_le16toh(rsrc_dir->MinorVersion), + pe->object, + "resource_version.minor"); _pe_iterate_resources( pe, @@ -603,12 +600,10 @@ static int pe_iterate_resources( // Align offset to a 32-bit boundary and add it to a pointer #define ADD_OFFSET(ptr, offset) \ - (PVERSION_INFO) ((uint8_t*) (ptr) + ((offset + 3) & ~3)) + (PVERSION_INFO)((uint8_t*) (ptr) + ((offset + 3) & ~3)) -static void pe_parse_version_info( - PIMAGE_RESOURCE_DATA_ENTRY rsrc_data, - PE* pe) +static void pe_parse_version_info(PIMAGE_RESOURCE_DATA_ENTRY rsrc_data, PE* pe) { PVERSION_INFO version_info; @@ -618,7 +613,7 @@ static void pe_parse_version_info( if (version_info_offset < 0) return; - version_info = (PVERSION_INFO) (pe->data + version_info_offset); + version_info = (PVERSION_INFO)(pe->data + version_info_offset); if (!struct_fits_in_pe(pe, version_info, VERSION_INFO)) return; @@ -629,52 +624,42 @@ static void pe_parse_version_info( if (strcmp_w(version_info->Key, "VS_VERSION_INFO") != 0) return; - version_info = ADD_OFFSET( - version_info, sizeof(VERSION_INFO) + 86); + version_info = ADD_OFFSET(version_info, sizeof(VERSION_INFO) + 86); - while(fits_in_pe(pe, version_info->Key, sizeof("VarFileInfo") * 2) && - strcmp_w(version_info->Key, "VarFileInfo") == 0 && - yr_le16toh(version_info->Length) != 0) + while (fits_in_pe(pe, version_info->Key, sizeof("VarFileInfo") * 2) && + strcmp_w(version_info->Key, "VarFileInfo") == 0 && + yr_le16toh(version_info->Length) != 0) { - version_info = ADD_OFFSET( - version_info, - yr_le16toh(version_info->Length)); + version_info = ADD_OFFSET(version_info, yr_le16toh(version_info->Length)); } - while(fits_in_pe(pe, version_info->Key, sizeof("StringFileInfo") * 2) && - strcmp_w(version_info->Key, "StringFileInfo") == 0 && - yr_le16toh(version_info->Length) != 0) + while (fits_in_pe(pe, version_info->Key, sizeof("StringFileInfo") * 2) && + strcmp_w(version_info->Key, "StringFileInfo") == 0 && + yr_le16toh(version_info->Length) != 0) { PVERSION_INFO string_table = ADD_OFFSET( - version_info, - sizeof(VERSION_INFO) + 30); + version_info, sizeof(VERSION_INFO) + 30); - version_info = ADD_OFFSET( - version_info, - yr_le16toh(version_info->Length)); + version_info = ADD_OFFSET(version_info, yr_le16toh(version_info->Length)); while (struct_fits_in_pe(pe, string_table, VERSION_INFO) && wide_string_fits_in_pe(pe, string_table->Key) && - yr_le16toh(string_table->Length) != 0 && - string_table < version_info) + yr_le16toh(string_table->Length) != 0 && string_table < version_info) { PVERSION_INFO string = ADD_OFFSET( string_table, sizeof(VERSION_INFO) + 2 * (strnlen_w(string_table->Key) + 1)); - string_table = ADD_OFFSET( - string_table, - yr_le16toh(string_table->Length)); + string_table = ADD_OFFSET(string_table, yr_le16toh(string_table->Length)); while (struct_fits_in_pe(pe, string, VERSION_INFO) && wide_string_fits_in_pe(pe, string->Key) && - yr_le16toh(string->Length) != 0 && - string < string_table) + yr_le16toh(string->Length) != 0 && string < string_table) { if (yr_le16toh(string->ValueLength) > 0) { - char* string_value = (char*) ADD_OFFSET(string, - sizeof(VERSION_INFO) + 2 * (strnlen_w(string->Key) + 1)); + char* string_value = (char*) ADD_OFFSET( + string, sizeof(VERSION_INFO) + 2 * (strnlen_w(string->Key) + 1)); if (wide_string_fits_in_pe(pe, string_value)) { @@ -708,27 +693,23 @@ static int pe_collect_resources( DWORD length; set_integer( - yr_le32toh(rsrc_data->OffsetToData), - pe->object, - "resources[%i].rva", - pe->resources); + yr_le32toh(rsrc_data->OffsetToData), + pe->object, + "resources[%i].rva", + pe->resources); int64_t offset = pe_rva_to_offset(pe, yr_le32toh(rsrc_data->OffsetToData)); if (offset < 0) offset = YR_UNDEFINED; - set_integer( - offset, - pe->object, - "resources[%i].offset", - pe->resources); + set_integer(offset, pe->object, "resources[%i].offset", pe->resources); set_integer( - yr_le32toh(rsrc_data->Size), - pe->object, - "resources[%i].length", - pe->resources); + yr_le32toh(rsrc_data->Size), + pe->object, + "resources[%i].length", + pe->resources); if (type_string) { @@ -737,16 +718,15 @@ static int pe_collect_resources( type_string += 2; set_sized_string( - (char*) type_string, length, pe->object, - "resources[%i].type_string", pe->resources); + (char*) type_string, + length, + pe->object, + "resources[%i].type_string", + pe->resources); } else { - set_integer( - rsrc_type, - pe->object, - "resources[%i].type", - pe->resources); + set_integer(rsrc_type, pe->object, "resources[%i].type", pe->resources); } if (name_string) @@ -755,16 +735,15 @@ static int pe_collect_resources( length = ((DWORD) *name_string) * 2; name_string += 2; set_sized_string( - (char*) name_string, length, pe->object, - "resources[%i].name_string", pe->resources); + (char*) name_string, + length, + pe->object, + "resources[%i].name_string", + pe->resources); } else { - set_integer( - rsrc_id, - pe->object, - "resources[%i].id", - pe->resources); + set_integer(rsrc_id, pe->object, "resources[%i].id", pe->resources); } if (lang_string) @@ -773,16 +752,16 @@ static int pe_collect_resources( length = ((DWORD) *lang_string) * 2; lang_string += 2; set_sized_string( - (char*) lang_string, length, pe->object, - "resources[%i].language_string", pe->resources); + (char*) lang_string, + length, + pe->object, + "resources[%i].language_string", + pe->resources); } else { set_integer( - rsrc_language, - pe->object, - "resources[%i].language", - pe->resources); + rsrc_language, pe->object, "resources[%i].language", pe->resources); } // Resources we do extra parsing on @@ -834,12 +813,12 @@ static IMPORT_FUNCTION* pe_parse_import_descriptor( if (offset >= 0) { - PIMAGE_IMPORT_BY_NAME import = (PIMAGE_IMPORT_BY_NAME) \ - (pe->data + offset); + PIMAGE_IMPORT_BY_NAME import = (PIMAGE_IMPORT_BY_NAME)( + pe->data + offset); if (struct_fits_in_pe(pe, import, IMAGE_IMPORT_BY_NAME)) { - name = (char *) yr_strndup( + name = (char*) yr_strndup( (char*) import->Name, yr_min(available_space(pe, import->Name), 512)); } @@ -856,8 +835,8 @@ static IMPORT_FUNCTION* pe_parse_import_descriptor( if (name != NULL || has_ordinal == 1) { - IMPORT_FUNCTION* imported_func = (IMPORT_FUNCTION*) - yr_calloc(1, sizeof(IMPORT_FUNCTION)); + IMPORT_FUNCTION* imported_func = (IMPORT_FUNCTION*) yr_calloc( + 1, sizeof(IMPORT_FUNCTION)); if (imported_func == NULL) { @@ -888,7 +867,8 @@ static IMPORT_FUNCTION* pe_parse_import_descriptor( PIMAGE_THUNK_DATA32 thunks32 = (PIMAGE_THUNK_DATA32)(pe->data + offset); while (struct_fits_in_pe(pe, thunks32, IMAGE_THUNK_DATA32) && - yr_le32toh(thunks32->u1.Ordinal) != 0 && *num_function_imports < MAX_PE_IMPORTS) + yr_le32toh(thunks32->u1.Ordinal) != 0 && + *num_function_imports < MAX_PE_IMPORTS) { char* name = NULL; uint16_t ordinal = 0; @@ -901,12 +881,12 @@ static IMPORT_FUNCTION* pe_parse_import_descriptor( if (offset >= 0) { - PIMAGE_IMPORT_BY_NAME import = (PIMAGE_IMPORT_BY_NAME) \ - (pe->data + offset); + PIMAGE_IMPORT_BY_NAME import = (PIMAGE_IMPORT_BY_NAME)( + pe->data + offset); if (struct_fits_in_pe(pe, import, IMAGE_IMPORT_BY_NAME)) { - name = (char *) yr_strndup( + name = (char*) yr_strndup( (char*) import->Name, yr_min(available_space(pe, import->Name), 512)); } @@ -923,8 +903,8 @@ static IMPORT_FUNCTION* pe_parse_import_descriptor( if (name != NULL || has_ordinal == 1) { - IMPORT_FUNCTION* imported_func = (IMPORT_FUNCTION*) - yr_calloc(1, sizeof(IMPORT_FUNCTION)); + IMPORT_FUNCTION* imported_func = (IMPORT_FUNCTION*) yr_calloc( + 1, sizeof(IMPORT_FUNCTION)); if (imported_func == NULL) { @@ -955,19 +935,15 @@ static IMPORT_FUNCTION* pe_parse_import_descriptor( } -static int pe_valid_dll_name( - const char* dll_name, - size_t n) +static int pe_valid_dll_name(const char* dll_name, size_t n) { const char* c = dll_name; size_t l = 0; while (l < n && *c != '\0') { - if ((*c >= 'a' && *c <= 'z') || - (*c >= 'A' && *c <= 'Z') || - (*c >= '0' && *c <= '9') || - (*c == '_' || *c == '.' || *c == '-')) + if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || + (*c >= '0' && *c <= '9') || (*c == '_' || *c == '.' || *c == '-')) { c++; l++; @@ -988,8 +964,7 @@ static int pe_valid_dll_name( // calculation. // -static IMPORTED_DLL* pe_parse_imports( - PE* pe) +static IMPORTED_DLL* pe_parse_imports(PE* pe) { int64_t offset; int num_imports = 0; // Number of imported DLLs @@ -1004,8 +979,7 @@ static IMPORTED_DLL* pe_parse_imports( // Default to 0 imports until we know there are any set_integer(0, pe->object, "number_of_imports"); - directory = pe_get_directory_entry( - pe, IMAGE_DIRECTORY_ENTRY_IMPORT); + directory = pe_get_directory_entry(pe, IMAGE_DIRECTORY_ENTRY_IMPORT); if (directory == NULL) return NULL; @@ -1018,8 +992,7 @@ static IMPORTED_DLL* pe_parse_imports( if (offset < 0) return NULL; - imports = (PIMAGE_IMPORT_DESCRIPTOR) \ - (pe->data + offset); + imports = (PIMAGE_IMPORT_DESCRIPTOR)(pe->data + offset); while (struct_fits_in_pe(pe, imports, IMAGE_IMPORT_DESCRIPTOR) && yr_le32toh(imports->Name) != 0 && num_imports < MAX_PE_IMPORTS) @@ -1030,12 +1003,12 @@ static IMPORTED_DLL* pe_parse_imports( { IMPORTED_DLL* imported_dll; - char* dll_name = (char *) (pe->data + offset); + char* dll_name = (char*) (pe->data + offset); if (!pe_valid_dll_name(dll_name, pe->data_size - (size_t) offset)) { - imports++; - continue; + imports++; + continue; } imported_dll = (IMPORTED_DLL*) yr_calloc(1, sizeof(IMPORTED_DLL)); @@ -1047,7 +1020,8 @@ static IMPORTED_DLL* pe_parse_imports( if (functions != NULL) { - imported_dll->name = yr_strdup(dll_name);; + imported_dll->name = yr_strdup(dll_name); + ; imported_dll->functions = functions; imported_dll->next = NULL; @@ -1079,8 +1053,7 @@ static IMPORTED_DLL* pe_parse_imports( // "exports" function for comparison. // -static void pe_parse_exports( - PE* pe) +static void pe_parse_exports(PE* pe) { PIMAGE_DATA_DIRECTORY directory; PIMAGE_EXPORT_DIRECTORY exports; @@ -1108,8 +1081,7 @@ static void pe_parse_exports( // Default to 0 exports until we know there are any set_integer(0, pe->object, "number_of_exports"); - directory = pe_get_directory_entry( - pe, IMAGE_DIRECTORY_ENTRY_EXPORT); + directory = pe_get_directory_entry(pe, IMAGE_DIRECTORY_ENTRY_EXPORT); if (directory == NULL) return; @@ -1125,18 +1097,18 @@ static void pe_parse_exports( export_start = offset; export_size = yr_le32toh(directory->Size); - exports = (PIMAGE_EXPORT_DIRECTORY) (pe->data + offset); + exports = (PIMAGE_EXPORT_DIRECTORY)(pe->data + offset); if (!struct_fits_in_pe(pe, exports, IMAGE_EXPORT_DIRECTORY)) return; number_of_exports = yr_min( - yr_le32toh(exports->NumberOfFunctions), - MAX_PE_EXPORTS); + yr_le32toh(exports->NumberOfFunctions), MAX_PE_EXPORTS); ordinal_base = yr_le32toh(exports->Base); - set_integer(yr_le32toh(exports->TimeDateStamp), pe->object, "export_timestamp"); + set_integer( + yr_le32toh(exports->TimeDateStamp), pe->object, "export_timestamp"); offset = pe_rva_to_offset(pe, yr_le32toh(exports->Name)); @@ -1158,10 +1130,11 @@ static void pe_parse_exports( if (offset < 0) return; - if (yr_le32toh(exports->NumberOfNames) * sizeof(DWORD) > pe->data_size - offset) + if (yr_le32toh(exports->NumberOfNames) * sizeof(DWORD) > + pe->data_size - offset) return; - names = (DWORD*)(pe->data + offset); + names = (DWORD*) (pe->data + offset); } offset = pe_rva_to_offset(pe, yr_le32toh(exports->AddressOfNameOrdinals)); @@ -1169,7 +1142,7 @@ static void pe_parse_exports( if (offset < 0) return; - ordinals = (WORD*)(pe->data + offset); + ordinals = (WORD*) (pe->data + offset); if (available_space(pe, ordinals) < sizeof(WORD) * number_of_exports) return; @@ -1179,7 +1152,7 @@ static void pe_parse_exports( if (offset < 0) return; - function_addrs = (DWORD*)(pe->data + offset); + function_addrs = (DWORD*) (pe->data + offset); if (available_space(pe, function_addrs) < sizeof(DWORD) * number_of_exports) return; @@ -1237,7 +1210,8 @@ static void pe_parse_exports( (char*) (pe->data + offset), yr_min(name_len, MAX_EXPORT_NAME_LENGTH), pe->object, - "export_details[%i].forward_name", exp_sz); + "export_details[%i].forward_name", + exp_sz); } else { @@ -1260,7 +1234,8 @@ static void pe_parse_exports( (char*) (pe->data + offset), yr_min(name_len, MAX_EXPORT_NAME_LENGTH), pe->object, - "export_details[%i].name", exp_sz); + "export_details[%i].name", + exp_sz); } break; } @@ -1283,10 +1258,7 @@ static void pe_parse_exports( // Parse a PKCS7 blob, looking for certs and nested PKCS7 blobs. // -void _parse_pkcs7( - PE* pe, - PKCS7* pkcs7, - int* counter) +void _parse_pkcs7(PE* pe, PKCS7* pkcs7, int* counter) { int i, j; time_t date_time; @@ -1306,7 +1278,7 @@ void _parse_pkcs7( ASN1_STRING* value = NULL; X509* cert = NULL; STACK_OF(X509)* certs = NULL; - X509_ATTRIBUTE *xa = NULL; + X509_ATTRIBUTE* xa = NULL; STACK_OF(X509_ATTRIBUTE)* attrs = NULL; if (*counter >= MAX_PE_CERTS) @@ -1332,20 +1304,19 @@ void _parse_pkcs7( "signatures[%i].thumbprint", *counter); - X509_NAME_oneline( - X509_get_issuer_name(cert), buffer, sizeof(buffer)); + X509_NAME_oneline(X509_get_issuer_name(cert), buffer, sizeof(buffer)); set_string(buffer, pe->object, "signatures[%i].issuer", *counter); - X509_NAME_oneline( - X509_get_subject_name(cert), buffer, sizeof(buffer)); + X509_NAME_oneline(X509_get_subject_name(cert), buffer, sizeof(buffer)); set_string(buffer, pe->object, "signatures[%i].subject", *counter); set_integer( - X509_get_version(cert) + 1, // Versions are zero based, so add one. + X509_get_version(cert) + 1, // Versions are zero based, so add one. pe->object, - "signatures[%i].version", *counter); + "signatures[%i].version", + *counter); sig_alg = OBJ_nid2ln(X509_get_signature_nid(cert)); @@ -1386,7 +1357,7 @@ void _parse_pkcs7( if (serial_der != NULL) { unsigned char* serial_bytes; - char *serial_ascii; + char* serial_ascii; bytes = i2d_ASN1_INTEGER(serial, &serial_der); @@ -1415,18 +1386,13 @@ void _parse_pkcs7( { // Don't put the colon on the last one. if (j < bytes - 1) - snprintf( - serial_ascii + 3 * j, 4, "%02x:", serial_bytes[j]); + snprintf(serial_ascii + 3 * j, 4, "%02x:", serial_bytes[j]); else - snprintf( - serial_ascii + 3 * j, 3, "%02x", serial_bytes[j]); + snprintf(serial_ascii + 3 * j, 3, "%02x", serial_bytes[j]); } set_string( - serial_ascii, - pe->object, - "signatures[%i].serial", - *counter); + serial_ascii, pe->object, "signatures[%i].serial", *counter); yr_free(serial_ascii); } @@ -1478,8 +1444,7 @@ void _parse_pkcs7( } -static void pe_parse_certificates( - PE* pe) +static void pe_parse_certificates(PE* pe) { int counter = 0; @@ -1502,18 +1467,18 @@ static void pe_parse_certificates( if (yr_le32toh(directory->VirtualAddress) == 0 || yr_le32toh(directory->VirtualAddress) > pe->data_size || yr_le32toh(directory->Size) > pe->data_size || - yr_le32toh(directory->VirtualAddress) + yr_le32toh(directory->Size) > pe->data_size) + yr_le32toh(directory->VirtualAddress) + yr_le32toh(directory->Size) > + pe->data_size) { return; } // Store the end of directory, making comparisons easier. - eod = pe->data + \ - yr_le32toh(directory->VirtualAddress) + \ - yr_le32toh(directory->Size); + eod = pe->data + yr_le32toh(directory->VirtualAddress) + + yr_le32toh(directory->Size); - win_cert = (PWIN_CERTIFICATE) \ - (pe->data + yr_le32toh(directory->VirtualAddress)); + win_cert = (PWIN_CERTIFICATE)( + pe->data + yr_le32toh(directory->VirtualAddress)); // // Walk the directory, pulling out certificates. @@ -1551,7 +1516,7 @@ static void pe_parse_certificates( { end = (uintptr_t)((uint8_t*) win_cert) + yr_le32toh(win_cert->Length); - win_cert = (PWIN_CERTIFICATE) (end + (end % 8)); + win_cert = (PWIN_CERTIFICATE)(end + (end % 8)); continue; } @@ -1570,7 +1535,7 @@ static void pe_parse_certificates( pkcs7 = NULL; } - win_cert = (PWIN_CERTIFICATE) (end + (end % 8)); + win_cert = (PWIN_CERTIFICATE)(end + (end % 8)); } set_integer(counter, pe->object, "number_of_signatures"); @@ -1579,10 +1544,7 @@ static void pe_parse_certificates( #endif // defined(HAVE_LIBCRYPTO) -static void pe_parse_header( - PE* pe, - uint64_t base_address, - int flags) +static void pe_parse_header(PE* pe, uint64_t base_address, int flags) { PIMAGE_SECTION_HEADER section; PIMAGE_DATA_DIRECTORY data_dir; @@ -1599,171 +1561,186 @@ static void pe_parse_header( set_integer(1, pe->object, "is_pe"); set_integer( - yr_le16toh(pe->header->FileHeader.Machine), - pe->object, "machine"); + yr_le16toh(pe->header->FileHeader.Machine), pe->object, "machine"); set_integer( yr_le16toh(pe->header->FileHeader.NumberOfSections), - pe->object, "number_of_sections"); + pe->object, + "number_of_sections"); set_integer( yr_le32toh(pe->header->FileHeader.TimeDateStamp), - pe->object, "timestamp"); + pe->object, + "timestamp"); set_integer( yr_le32toh(pe->header->FileHeader.PointerToSymbolTable), - pe->object, "pointer_to_symbol_table"); + pe->object, + "pointer_to_symbol_table"); set_integer( yr_le32toh(pe->header->FileHeader.NumberOfSymbols), - pe->object, "number_of_symbols"); + pe->object, + "number_of_symbols"); set_integer( yr_le32toh(pe->header->FileHeader.SizeOfOptionalHeader), - pe->object, "size_of_optional_header"); + pe->object, + "size_of_optional_header"); set_integer( yr_le16toh(pe->header->FileHeader.Characteristics), - pe->object, "characteristics"); + pe->object, + "characteristics"); set_integer( - flags & SCAN_FLAGS_PROCESS_MEMORY ? - base_address + yr_le32toh(OptionalHeader(pe, AddressOfEntryPoint)) : - pe_rva_to_offset(pe, yr_le32toh(OptionalHeader(pe, AddressOfEntryPoint))), - pe->object, "entry_point"); + flags & SCAN_FLAGS_PROCESS_MEMORY + ? base_address + yr_le32toh(OptionalHeader(pe, AddressOfEntryPoint)) + : pe_rva_to_offset( + pe, yr_le32toh(OptionalHeader(pe, AddressOfEntryPoint))), + pe->object, + "entry_point"); set_integer( - IS_64BITS_PE(pe) ? - yr_le64toh(OptionalHeader(pe, ImageBase)) : - yr_le32toh(OptionalHeader(pe, ImageBase)), - pe->object, "image_base"); + IS_64BITS_PE(pe) ? yr_le64toh(OptionalHeader(pe, ImageBase)) + : yr_le32toh(OptionalHeader(pe, ImageBase)), + pe->object, + "image_base"); set_integer( yr_le32toh(OptionalHeader(pe, NumberOfRvaAndSizes)), - pe->object, "number_of_rva_and_sizes"); + pe->object, + "number_of_rva_and_sizes"); set_integer( - yr_le32toh(OptionalHeader(pe, Magic)), - pe->object, "opthdr_magic"); + yr_le32toh(OptionalHeader(pe, Magic)), pe->object, "opthdr_magic"); set_integer( OptionalHeader(pe, MajorLinkerVersion), - pe->object, "linker_version.major"); + pe->object, + "linker_version.major"); set_integer( OptionalHeader(pe, MinorLinkerVersion), - pe->object, "linker_version.minor"); + pe->object, + "linker_version.minor"); set_integer( - yr_le32toh(OptionalHeader(pe, SizeOfCode)), - pe->object, "size_of_code"); + yr_le32toh(OptionalHeader(pe, SizeOfCode)), pe->object, "size_of_code"); set_integer( yr_le32toh(OptionalHeader(pe, SizeOfInitializedData)), - pe->object, "size_of_initialized_data"); + pe->object, + "size_of_initialized_data"); set_integer( yr_le32toh(OptionalHeader(pe, SizeOfUninitializedData)), - pe->object, "size_of_uninitialized_data"); + pe->object, + "size_of_uninitialized_data"); set_integer( - yr_le32toh(OptionalHeader(pe, BaseOfCode)), - pe->object, "base_of_code"); + yr_le32toh(OptionalHeader(pe, BaseOfCode)), pe->object, "base_of_code"); if (!IS_64BITS_PE(pe)) { - set_integer( + set_integer( yr_le32toh(pe->header->OptionalHeader.BaseOfData), - pe->object, "base_of_data"); + pe->object, + "base_of_data"); } set_integer( yr_le32toh(OptionalHeader(pe, SectionAlignment)), - pe->object, "section_alignment"); + pe->object, + "section_alignment"); set_integer( yr_le32toh(OptionalHeader(pe, FileAlignment)), - pe->object, "file_alignment"); + pe->object, + "file_alignment"); set_integer( yr_le16toh(OptionalHeader(pe, MajorOperatingSystemVersion)), - pe->object, "os_version.major"); + pe->object, + "os_version.major"); set_integer( yr_le16toh(OptionalHeader(pe, MinorOperatingSystemVersion)), - pe->object, "os_version.minor"); + pe->object, + "os_version.minor"); set_integer( yr_le16toh(OptionalHeader(pe, MajorImageVersion)), - pe->object, "image_version.major"); + pe->object, + "image_version.major"); set_integer( yr_le16toh(OptionalHeader(pe, MinorImageVersion)), - pe->object, "image_version.minor"); + pe->object, + "image_version.minor"); set_integer( yr_le16toh(OptionalHeader(pe, MajorSubsystemVersion)), - pe->object, "subsystem_version.major"); + pe->object, + "subsystem_version.major"); set_integer( yr_le16toh(OptionalHeader(pe, MinorSubsystemVersion)), - pe->object, "subsystem_version.minor"); + pe->object, + "subsystem_version.minor"); set_integer( yr_le32toh(OptionalHeader(pe, Win32VersionValue)), - pe->object, "win32_version_value"); + pe->object, + "win32_version_value"); set_integer( - yr_le32toh(OptionalHeader(pe, SizeOfImage)), - pe->object, "size_of_image"); + yr_le32toh(OptionalHeader(pe, SizeOfImage)), pe->object, "size_of_image"); set_integer( yr_le32toh(OptionalHeader(pe, SizeOfHeaders)), - pe->object, "size_of_headers"); + pe->object, + "size_of_headers"); - set_integer( - yr_le32toh(OptionalHeader(pe, CheckSum)), - pe->object, "checksum"); + set_integer(yr_le32toh(OptionalHeader(pe, CheckSum)), pe->object, "checksum"); set_integer( - yr_le16toh(OptionalHeader(pe, Subsystem)), - pe->object, "subsystem"); + yr_le16toh(OptionalHeader(pe, Subsystem)), pe->object, "subsystem"); set_integer( OptionalHeader(pe, DllCharacteristics), - pe->object, "dll_characteristics"); + pe->object, + "dll_characteristics"); set_integer( - IS_64BITS_PE(pe) ? - yr_le64toh(OptionalHeader(pe, SizeOfStackReserve)) : - yr_le32toh(OptionalHeader(pe, SizeOfStackReserve)), - pe->object, "size_of_stack_reserve"); + IS_64BITS_PE(pe) ? yr_le64toh(OptionalHeader(pe, SizeOfStackReserve)) + : yr_le32toh(OptionalHeader(pe, SizeOfStackReserve)), + pe->object, + "size_of_stack_reserve"); set_integer( - IS_64BITS_PE(pe) ? - yr_le64toh(OptionalHeader(pe, SizeOfStackCommit)) : - yr_le32toh(OptionalHeader(pe, SizeOfStackCommit)), - pe->object, "size_of_stack_commit"); + IS_64BITS_PE(pe) ? yr_le64toh(OptionalHeader(pe, SizeOfStackCommit)) + : yr_le32toh(OptionalHeader(pe, SizeOfStackCommit)), + pe->object, + "size_of_stack_commit"); set_integer( - IS_64BITS_PE(pe) ? - yr_le64toh(OptionalHeader(pe, SizeOfHeapReserve)) : - yr_le32toh(OptionalHeader(pe, SizeOfHeapReserve)), - pe->object, "size_of_heap_reserve"); + IS_64BITS_PE(pe) ? yr_le64toh(OptionalHeader(pe, SizeOfHeapReserve)) + : yr_le32toh(OptionalHeader(pe, SizeOfHeapReserve)), + pe->object, + "size_of_heap_reserve"); set_integer( - IS_64BITS_PE(pe) ? - yr_le64toh(OptionalHeader(pe, SizeOfHeapCommit)) : - yr_le32toh(OptionalHeader(pe, SizeOfHeapCommit)), - pe->object, "size_of_heap_commit"); + IS_64BITS_PE(pe) ? yr_le64toh(OptionalHeader(pe, SizeOfHeapCommit)) + : yr_le32toh(OptionalHeader(pe, SizeOfHeapCommit)), + pe->object, + "size_of_heap_commit"); set_integer( - yr_le32toh(OptionalHeader(pe, LoaderFlags)), - pe->object, "loader_flags"); + yr_le32toh(OptionalHeader(pe, LoaderFlags)), pe->object, "loader_flags"); - data_dir = IS_64BITS_PE(pe) ? - pe->header64->OptionalHeader.DataDirectory: - pe->header->OptionalHeader.DataDirectory; + data_dir = IS_64BITS_PE(pe) ? pe->header64->OptionalHeader.DataDirectory + : pe->header->OptionalHeader.DataDirectory; ddcount = yr_le16toh(OptionalHeader(pe, NumberOfRvaAndSizes)); ddcount = yr_min(ddcount, IMAGE_NUMBEROF_DIRECTORY_ENTRIES); @@ -1774,20 +1751,19 @@ static void pe_parse_header( break; set_integer( - yr_le32toh(data_dir->VirtualAddress), - pe->object, "data_directories[%i].virtual_address", i); + yr_le32toh(data_dir->VirtualAddress), + pe->object, + "data_directories[%i].virtual_address", + i); set_integer( - yr_le32toh(data_dir->Size), - pe->object, "data_directories[%i].size", i); + yr_le32toh(data_dir->Size), pe->object, "data_directories[%i].size", i); data_dir++; } pe_iterate_resources( - pe, - (RESOURCE_CALLBACK_FUNC) pe_collect_resources, - (void*) pe); + pe, (RESOURCE_CALLBACK_FUNC) pe_collect_resources, (void*) pe); set_integer(pe->resources, pe->object, "number_of_resources"); @@ -1804,45 +1780,61 @@ static void pe_parse_header( strncpy(section_name, (char*) section->Name, IMAGE_SIZEOF_SHORT_NAME); section_name[IMAGE_SIZEOF_SHORT_NAME] = '\0'; - set_string( - section_name, - pe->object, "sections[%i].name", i); + set_string(section_name, pe->object, "sections[%i].name", i); set_integer( yr_le32toh(section->Characteristics), - pe->object, "sections[%i].characteristics", i); + pe->object, + "sections[%i].characteristics", + i); set_integer( yr_le32toh(section->SizeOfRawData), - pe->object, "sections[%i].raw_data_size", i); + pe->object, + "sections[%i].raw_data_size", + i); set_integer( yr_le32toh(section->PointerToRawData), - pe->object, "sections[%i].raw_data_offset", i); + pe->object, + "sections[%i].raw_data_offset", + i); set_integer( yr_le32toh(section->VirtualAddress), - pe->object, "sections[%i].virtual_address", i); + pe->object, + "sections[%i].virtual_address", + i); set_integer( yr_le32toh(section->Misc.VirtualSize), - pe->object, "sections[%i].virtual_size", i); + pe->object, + "sections[%i].virtual_size", + i); set_integer( yr_le32toh(section->PointerToRelocations), - pe->object, "sections[%i].pointer_to_relocations", i); + pe->object, + "sections[%i].pointer_to_relocations", + i); set_integer( yr_le32toh(section->PointerToLinenumbers), - pe->object, "sections[%i].pointer_to_line_numbers", i); + pe->object, + "sections[%i].pointer_to_line_numbers", + i); set_integer( yr_le32toh(section->NumberOfRelocations), - pe->object, "sections[%i].number_of_relocations", i); + pe->object, + "sections[%i].number_of_relocations", + i); set_integer( yr_le32toh(section->NumberOfLinenumbers), - pe->object, "sections[%i].number_of_line_numbers", i); + pe->object, + "sections[%i].number_of_line_numbers", + i); // This will catch the section with the highest raw offset to help checking // if overlay data is present. If two sections have the same raw pointer @@ -1865,7 +1857,8 @@ static void pe_parse_header( // RawData + RawOffset of the last section on the physical file last_section_end = highest_sec_siz + highest_sec_ofs; - // "overlay.offset" is set to YR_UNDEFINED for files that do not have an overlay + // "overlay.offset" is set to YR_UNDEFINED for files that do not have an + // overlay if (last_section_end && (pe->data_size > last_section_end)) set_integer(last_section_end, pe->object, "overlay.offset"); @@ -1896,7 +1889,7 @@ define_function(valid_on) not_before = get_integer(parent(), "not_before"); not_after = get_integer(parent(), "not_after"); - return_integer(timestamp >= not_before && timestamp <= not_after); + return_integer(timestamp >= not_before && timestamp <= not_after); } @@ -2164,8 +2157,7 @@ define_function(exports_index_regex) } -#if defined(HAVE_LIBCRYPTO) || \ - defined(HAVE_WINCRYPT_H) || \ +#if defined(HAVE_LIBCRYPTO) || defined(HAVE_WINCRYPT_H) || \ defined(HAVE_COMMONCRYPTO_COMMONCRYPTO_H) // @@ -2196,10 +2188,7 @@ define_function(imphash) return_string(YR_UNDEFINED); // Lookup in cache first. - digest_ascii = (char*) yr_hash_table_lookup( - pe->hash_table, - "imphash", - NULL); + digest_ascii = (char*) yr_hash_table_lookup(pe->hash_table, "imphash", NULL); if (digest_ascii != NULL) return_string(digest_ascii); @@ -2219,9 +2208,9 @@ define_function(imphash) char* ext = strstr(dll->name, "."); - if (ext && (strncasecmp(ext, ".ocx", 4) == 0 || - strncasecmp(ext, ".sys", 4) == 0 || - strncasecmp(ext, ".dll", 4) == 0)) + if (ext && + (strncasecmp(ext, ".ocx", 4) == 0 || strncasecmp(ext, ".sys", 4) == 0 || + strncasecmp(ext, ".dll", 4) == 0)) { dll_name_len = (ext - dll->name); } @@ -2232,7 +2221,7 @@ define_function(imphash) // Allocate a new string to hold the dll name. - dll_name = (char *) yr_malloc(dll_name_len + 1); + dll_name = (char*) yr_malloc(dll_name_len + 1); if (!dll_name) return ERROR_INSUFFICIENT_MEMORY; @@ -2247,14 +2236,14 @@ define_function(imphash) size_t final_name_len = dll_name_len + strlen(func->name) + 1; if (!first) - final_name_len++; // Additional byte to accommodate the extra comma + final_name_len++; // Additional byte to accommodate the extra comma final_name = (char*) yr_malloc(final_name_len + 1); if (final_name == NULL) break; - sprintf(final_name, first ? "%s.%s": ",%s.%s", dll_name, func->name); + sprintf(final_name, first ? "%s.%s" : ",%s.%s", dll_name, func->name); // Lowercase the whole thing. @@ -2374,7 +2363,7 @@ define_function(imports_ordinal) define_function(imports_regex) { YR_OBJECT* module = module(); - PE* pe = (PE*)module->data; + PE* pe = (PE*) module->data; IMPORTED_DLL* imported_dll; uint64_t imported_func_count = 0; @@ -2392,7 +2381,8 @@ define_function(imports_regex) while (imported_func != NULL) { - if (yr_re_match(scan_context(), regexp_argument(2), imported_func->name) > 0) + if (yr_re_match( + scan_context(), regexp_argument(2), imported_func->name) > 0) imported_func_count++; imported_func = imported_func->next; } @@ -2459,7 +2449,7 @@ define_function(locale) for (i = 0; i < n; i++) { uint64_t rsrc_language = get_integer( - module, "resources[%i].language", (int32_t)i); + module, "resources[%i].language", (int32_t) i); if ((rsrc_language & 0xFFFF) == locale) return_integer(1); @@ -2490,7 +2480,7 @@ define_function(language) for (i = 0; i < n; i++) { uint64_t rsrc_language = get_integer( - module, "resources[%i].language", (int32_t)i); + module, "resources[%i].language", (int32_t) i); if ((rsrc_language & 0xFF) == language) return_integer(1); @@ -2559,24 +2549,24 @@ static uint64_t _rich_version( // Check if the required fields are set if (is_undefined(module, "rich_signature.length")) - return YR_UNDEFINED; + return YR_UNDEFINED; rich_length = get_integer(module, "rich_signature.length"); rich_string = get_string(module, "rich_signature.clear_data"); // If the clear_data was not set, return YR_UNDEFINED if (rich_string == NULL) - return YR_UNDEFINED; + return YR_UNDEFINED; if (version == YR_UNDEFINED && toolid == YR_UNDEFINED) - return false; + return false; clear_rich_signature = (PRICH_SIGNATURE) rich_string->c_string; // Loop over the versions in the rich signature - rich_count = \ - (rich_length - sizeof(RICH_SIGNATURE)) / sizeof(RICH_VERSION_INFO); + rich_count = (rich_length - sizeof(RICH_SIGNATURE)) / + sizeof(RICH_VERSION_INFO); for (i = 0; i < rich_count; i++) { @@ -2598,8 +2588,7 @@ static uint64_t _rich_version( define_function(rich_version) { - return_integer( - _rich_version(module(), integer_argument(1), YR_UNDEFINED)); + return_integer(_rich_version(module(), integer_argument(1), YR_UNDEFINED)); } @@ -2612,8 +2601,7 @@ define_function(rich_version_toolid) define_function(rich_toolid) { - return_integer( - _rich_version(module(), YR_UNDEFINED, integer_argument(1))); + return_integer(_rich_version(module(), YR_UNDEFINED, integer_argument(1))); } @@ -2637,7 +2625,8 @@ define_function(calculate_checksum) return_integer(YR_UNDEFINED); csum_offset = ((uint8_t*) &(pe->header->OptionalHeader) + - offsetof(IMAGE_OPTIONAL_HEADER32, CheckSum)) - pe->data; + offsetof(IMAGE_OPTIONAL_HEADER32, CheckSum)) - + pe->data; for (i = 0; i <= pe->data_size / 4; i++) { @@ -2649,10 +2638,10 @@ define_function(calculate_checksum) if (4 * i + 4 <= pe->data_size) { - csum += ((uint64_t) pe->data[4 * i] + - ((uint64_t) pe->data[4 * i + 1] << 8) + - ((uint64_t) pe->data[4 * i + 2] << 16) + - ((uint64_t) pe->data[4 * i + 3] << 24)); + csum += + ((uint64_t) pe->data[4 * i] + ((uint64_t) pe->data[4 * i + 1] << 8) + + ((uint64_t) pe->data[4 * i + 2] << 16) + + ((uint64_t) pe->data[4 * i + 3] << 24)); } else { @@ -2691,7 +2680,8 @@ define_function(rva_to_offset) return_integer(offset); } - +// Prevent clang-format from messing up indentation +// clang-format off begin_declarations; declare_integer("MACHINE_UNKNOWN"); @@ -2980,10 +2970,10 @@ begin_declarations; declare_function("rva_to_offset", "i", "i", rva_to_offset); end_declarations; +// clang-format on -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { #if defined(HAVE_LIBCRYPTO) // Not checking return value here because if it fails we will not parse the @@ -2994,8 +2984,7 @@ int module_initialize( } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { return ERROR_SUCCESS; } @@ -3014,333 +3003,209 @@ int module_load( const uint8_t* block_data = NULL; PE* pe = NULL; - set_integer( - IMAGE_FILE_MACHINE_UNKNOWN, module_object, - "MACHINE_UNKNOWN"); - set_integer( - IMAGE_FILE_MACHINE_AM33, module_object, - "MACHINE_AM33"); - set_integer( - IMAGE_FILE_MACHINE_AMD64, module_object, - "MACHINE_AMD64"); - set_integer( - IMAGE_FILE_MACHINE_ARM, module_object, - "MACHINE_ARM"); - set_integer( - IMAGE_FILE_MACHINE_ARMNT, module_object, - "MACHINE_ARMNT"); - set_integer( - IMAGE_FILE_MACHINE_ARM64, module_object, - "MACHINE_ARM64"); - set_integer( - IMAGE_FILE_MACHINE_EBC, module_object, - "MACHINE_EBC"); - set_integer( - IMAGE_FILE_MACHINE_I386, module_object, - "MACHINE_I386"); - set_integer( - IMAGE_FILE_MACHINE_IA64, module_object, - "MACHINE_IA64"); - set_integer( - IMAGE_FILE_MACHINE_M32R, module_object, - "MACHINE_M32R"); - set_integer( - IMAGE_FILE_MACHINE_MIPS16, module_object, - "MACHINE_MIPS16"); - set_integer( - IMAGE_FILE_MACHINE_MIPSFPU, module_object, - "MACHINE_MIPSFPU"); - set_integer( - IMAGE_FILE_MACHINE_MIPSFPU16, module_object, - "MACHINE_MIPSFPU16"); - set_integer( - IMAGE_FILE_MACHINE_POWERPC, module_object, - "MACHINE_POWERPC"); - set_integer( - IMAGE_FILE_MACHINE_POWERPCFP, module_object, - "MACHINE_POWERPCFP"); - set_integer( - IMAGE_FILE_MACHINE_R4000, module_object, - "MACHINE_R4000"); - set_integer( - IMAGE_FILE_MACHINE_SH3, module_object, - "MACHINE_SH3"); - set_integer( - IMAGE_FILE_MACHINE_SH3DSP, module_object, - "MACHINE_SH3DSP"); - set_integer( - IMAGE_FILE_MACHINE_SH4, module_object, - "MACHINE_SH4"); - set_integer( - IMAGE_FILE_MACHINE_SH5, module_object, - "MACHINE_SH5"); - set_integer( - IMAGE_FILE_MACHINE_THUMB, module_object, - "MACHINE_THUMB"); - set_integer( - IMAGE_FILE_MACHINE_WCEMIPSV2, module_object, - "MACHINE_WCEMIPSV2"); - - set_integer( - IMAGE_SUBSYSTEM_UNKNOWN, module_object, - "SUBSYSTEM_UNKNOWN"); - set_integer( - IMAGE_SUBSYSTEM_NATIVE, module_object, - "SUBSYSTEM_NATIVE"); - set_integer( - IMAGE_SUBSYSTEM_WINDOWS_GUI, module_object, - "SUBSYSTEM_WINDOWS_GUI"); - set_integer( - IMAGE_SUBSYSTEM_WINDOWS_CUI, module_object, - "SUBSYSTEM_WINDOWS_CUI"); - set_integer( - IMAGE_SUBSYSTEM_OS2_CUI, module_object, - "SUBSYSTEM_OS2_CUI"); - set_integer( - IMAGE_SUBSYSTEM_POSIX_CUI, module_object, - "SUBSYSTEM_POSIX_CUI"); - set_integer( - IMAGE_SUBSYSTEM_NATIVE_WINDOWS, module_object, + set_integer(IMAGE_FILE_MACHINE_UNKNOWN, module_object, "MACHINE_UNKNOWN"); + set_integer(IMAGE_FILE_MACHINE_AM33, module_object, "MACHINE_AM33"); + set_integer(IMAGE_FILE_MACHINE_AMD64, module_object, "MACHINE_AMD64"); + set_integer(IMAGE_FILE_MACHINE_ARM, module_object, "MACHINE_ARM"); + set_integer(IMAGE_FILE_MACHINE_ARMNT, module_object, "MACHINE_ARMNT"); + set_integer(IMAGE_FILE_MACHINE_ARM64, module_object, "MACHINE_ARM64"); + set_integer(IMAGE_FILE_MACHINE_EBC, module_object, "MACHINE_EBC"); + set_integer(IMAGE_FILE_MACHINE_I386, module_object, "MACHINE_I386"); + set_integer(IMAGE_FILE_MACHINE_IA64, module_object, "MACHINE_IA64"); + set_integer(IMAGE_FILE_MACHINE_M32R, module_object, "MACHINE_M32R"); + set_integer(IMAGE_FILE_MACHINE_MIPS16, module_object, "MACHINE_MIPS16"); + set_integer(IMAGE_FILE_MACHINE_MIPSFPU, module_object, "MACHINE_MIPSFPU"); + set_integer(IMAGE_FILE_MACHINE_MIPSFPU16, module_object, "MACHINE_MIPSFPU16"); + set_integer(IMAGE_FILE_MACHINE_POWERPC, module_object, "MACHINE_POWERPC"); + set_integer(IMAGE_FILE_MACHINE_POWERPCFP, module_object, "MACHINE_POWERPCFP"); + set_integer(IMAGE_FILE_MACHINE_R4000, module_object, "MACHINE_R4000"); + set_integer(IMAGE_FILE_MACHINE_SH3, module_object, "MACHINE_SH3"); + set_integer(IMAGE_FILE_MACHINE_SH3DSP, module_object, "MACHINE_SH3DSP"); + set_integer(IMAGE_FILE_MACHINE_SH4, module_object, "MACHINE_SH4"); + set_integer(IMAGE_FILE_MACHINE_SH5, module_object, "MACHINE_SH5"); + set_integer(IMAGE_FILE_MACHINE_THUMB, module_object, "MACHINE_THUMB"); + set_integer(IMAGE_FILE_MACHINE_WCEMIPSV2, module_object, "MACHINE_WCEMIPSV2"); + + set_integer(IMAGE_SUBSYSTEM_UNKNOWN, module_object, "SUBSYSTEM_UNKNOWN"); + set_integer(IMAGE_SUBSYSTEM_NATIVE, module_object, "SUBSYSTEM_NATIVE"); + set_integer( + IMAGE_SUBSYSTEM_WINDOWS_GUI, module_object, "SUBSYSTEM_WINDOWS_GUI"); + set_integer( + IMAGE_SUBSYSTEM_WINDOWS_CUI, module_object, "SUBSYSTEM_WINDOWS_CUI"); + set_integer(IMAGE_SUBSYSTEM_OS2_CUI, module_object, "SUBSYSTEM_OS2_CUI"); + set_integer(IMAGE_SUBSYSTEM_POSIX_CUI, module_object, "SUBSYSTEM_POSIX_CUI"); + set_integer( + IMAGE_SUBSYSTEM_NATIVE_WINDOWS, + module_object, "SUBSYSTEM_NATIVE_WINDOWS"); set_integer( - IMAGE_SUBSYSTEM_WINDOWS_CE_GUI, module_object, + IMAGE_SUBSYSTEM_WINDOWS_CE_GUI, + module_object, "SUBSYSTEM_WINDOWS_CE_GUI"); set_integer( - IMAGE_SUBSYSTEM_EFI_APPLICATION, module_object, + IMAGE_SUBSYSTEM_EFI_APPLICATION, + module_object, "SUBSYSTEM_EFI_APPLICATION"); set_integer( - IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER, module_object, + IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER, + module_object, "SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER"); set_integer( - IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER, module_object, + IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER, + module_object, "SUBSYSTEM_EFI_RUNTIME_DRIVER"); + set_integer(IMAGE_SUBSYSTEM_XBOX, module_object, "SUBSYSTEM_XBOX"); set_integer( - IMAGE_SUBSYSTEM_XBOX, module_object, - "SUBSYSTEM_XBOX"); - set_integer( - IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION, module_object, + IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION, + module_object, "SUBSYSTEM_WINDOWS_BOOT_APPLICATION"); set_integer( - IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE, module_object, - "DYNAMIC_BASE"); + IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE, module_object, "DYNAMIC_BASE"); set_integer( - IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY, module_object, + IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY, + module_object, "FORCE_INTEGRITY"); + set_integer(IMAGE_DLLCHARACTERISTICS_NX_COMPAT, module_object, "NX_COMPAT"); set_integer( - IMAGE_DLLCHARACTERISTICS_NX_COMPAT, module_object, - "NX_COMPAT"); - set_integer( - IMAGE_DLLCHARACTERISTICS_NO_ISOLATION, module_object, - "NO_ISOLATION"); - set_integer( - IMAGE_DLLCHARACTERISTICS_NO_SEH, module_object, - "NO_SEH"); + IMAGE_DLLCHARACTERISTICS_NO_ISOLATION, module_object, "NO_ISOLATION"); + set_integer(IMAGE_DLLCHARACTERISTICS_NO_SEH, module_object, "NO_SEH"); + set_integer(IMAGE_DLLCHARACTERISTICS_NO_BIND, module_object, "NO_BIND"); + set_integer(IMAGE_DLLCHARACTERISTICS_WDM_DRIVER, module_object, "WDM_DRIVER"); set_integer( - IMAGE_DLLCHARACTERISTICS_NO_BIND, module_object, - "NO_BIND"); - set_integer( - IMAGE_DLLCHARACTERISTICS_WDM_DRIVER, module_object, - "WDM_DRIVER"); - set_integer( - IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE, module_object, + IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE, + module_object, "TERMINAL_SERVER_AWARE"); + set_integer(IMAGE_FILE_RELOCS_STRIPPED, module_object, "RELOCS_STRIPPED"); + set_integer(IMAGE_FILE_EXECUTABLE_IMAGE, module_object, "EXECUTABLE_IMAGE"); set_integer( - IMAGE_FILE_RELOCS_STRIPPED, module_object, - "RELOCS_STRIPPED"); - set_integer( - IMAGE_FILE_EXECUTABLE_IMAGE, module_object, - "EXECUTABLE_IMAGE"); - set_integer( - IMAGE_FILE_LINE_NUMS_STRIPPED, module_object, - "LINE_NUMS_STRIPPED"); - set_integer( - IMAGE_FILE_LOCAL_SYMS_STRIPPED, module_object, - "LOCAL_SYMS_STRIPPED"); - set_integer( - IMAGE_FILE_AGGRESIVE_WS_TRIM, module_object, - "AGGRESIVE_WS_TRIM"); - set_integer( - IMAGE_FILE_LARGE_ADDRESS_AWARE, module_object, - "LARGE_ADDRESS_AWARE"); - set_integer( - IMAGE_FILE_BYTES_REVERSED_LO, module_object, - "BYTES_REVERSED_LO"); + IMAGE_FILE_LINE_NUMS_STRIPPED, module_object, "LINE_NUMS_STRIPPED"); set_integer( - IMAGE_FILE_32BIT_MACHINE, module_object, - "MACHINE_32BIT"); + IMAGE_FILE_LOCAL_SYMS_STRIPPED, module_object, "LOCAL_SYMS_STRIPPED"); + set_integer(IMAGE_FILE_AGGRESIVE_WS_TRIM, module_object, "AGGRESIVE_WS_TRIM"); set_integer( - IMAGE_FILE_DEBUG_STRIPPED, module_object, - "DEBUG_STRIPPED"); + IMAGE_FILE_LARGE_ADDRESS_AWARE, module_object, "LARGE_ADDRESS_AWARE"); + set_integer(IMAGE_FILE_BYTES_REVERSED_LO, module_object, "BYTES_REVERSED_LO"); + set_integer(IMAGE_FILE_32BIT_MACHINE, module_object, "MACHINE_32BIT"); + set_integer(IMAGE_FILE_DEBUG_STRIPPED, module_object, "DEBUG_STRIPPED"); set_integer( - IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP, module_object, + IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP, + module_object, "REMOVABLE_RUN_FROM_SWAP"); - set_integer( - IMAGE_FILE_NET_RUN_FROM_SWAP, module_object, - "NET_RUN_FROM_SWAP"); - set_integer( - IMAGE_FILE_SYSTEM, module_object, - "SYSTEM"); - set_integer( - IMAGE_FILE_DLL, module_object, - "DLL"); - set_integer( - IMAGE_FILE_UP_SYSTEM_ONLY, module_object, - "UP_SYSTEM_ONLY"); - set_integer( - IMAGE_FILE_BYTES_REVERSED_HI, module_object, - "BYTES_REVERSED_HI"); + set_integer(IMAGE_FILE_NET_RUN_FROM_SWAP, module_object, "NET_RUN_FROM_SWAP"); + set_integer(IMAGE_FILE_SYSTEM, module_object, "SYSTEM"); + set_integer(IMAGE_FILE_DLL, module_object, "DLL"); + set_integer(IMAGE_FILE_UP_SYSTEM_ONLY, module_object, "UP_SYSTEM_ONLY"); + set_integer(IMAGE_FILE_BYTES_REVERSED_HI, module_object, "BYTES_REVERSED_HI"); set_integer( - IMAGE_DIRECTORY_ENTRY_EXPORT, module_object, + IMAGE_DIRECTORY_ENTRY_EXPORT, + module_object, "IMAGE_DIRECTORY_ENTRY_EXPORT"); set_integer( - IMAGE_DIRECTORY_ENTRY_IMPORT, module_object, + IMAGE_DIRECTORY_ENTRY_IMPORT, + module_object, "IMAGE_DIRECTORY_ENTRY_IMPORT"); set_integer( - IMAGE_DIRECTORY_ENTRY_RESOURCE, module_object, + IMAGE_DIRECTORY_ENTRY_RESOURCE, + module_object, "IMAGE_DIRECTORY_ENTRY_RESOURCE"); set_integer( - IMAGE_DIRECTORY_ENTRY_EXCEPTION, module_object, + IMAGE_DIRECTORY_ENTRY_EXCEPTION, + module_object, "IMAGE_DIRECTORY_ENTRY_EXCEPTION"); set_integer( - IMAGE_DIRECTORY_ENTRY_SECURITY, module_object, + IMAGE_DIRECTORY_ENTRY_SECURITY, + module_object, "IMAGE_DIRECTORY_ENTRY_SECURITY"); set_integer( - IMAGE_DIRECTORY_ENTRY_BASERELOC, module_object, + IMAGE_DIRECTORY_ENTRY_BASERELOC, + module_object, "IMAGE_DIRECTORY_ENTRY_BASERELOC"); set_integer( - IMAGE_DIRECTORY_ENTRY_DEBUG, module_object, + IMAGE_DIRECTORY_ENTRY_DEBUG, + module_object, "IMAGE_DIRECTORY_ENTRY_DEBUG"); set_integer( - IMAGE_DIRECTORY_ENTRY_ARCHITECTURE, module_object, + IMAGE_DIRECTORY_ENTRY_ARCHITECTURE, + module_object, "IMAGE_DIRECTORY_ENTRY_ARCHITECTURE"); set_integer( - IMAGE_DIRECTORY_ENTRY_GLOBALPTR, module_object, + IMAGE_DIRECTORY_ENTRY_GLOBALPTR, + module_object, "IMAGE_DIRECTORY_ENTRY_GLOBALPTR"); set_integer( - IMAGE_DIRECTORY_ENTRY_TLS, module_object, - "IMAGE_DIRECTORY_ENTRY_TLS"); + IMAGE_DIRECTORY_ENTRY_TLS, module_object, "IMAGE_DIRECTORY_ENTRY_TLS"); set_integer( - IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, module_object, + IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, + module_object, "IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG"); set_integer( - IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT, module_object, + IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT, + module_object, "IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT"); set_integer( - IMAGE_DIRECTORY_ENTRY_IAT, module_object, - "IMAGE_DIRECTORY_ENTRY_IAT"); + IMAGE_DIRECTORY_ENTRY_IAT, module_object, "IMAGE_DIRECTORY_ENTRY_IAT"); set_integer( - IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT, module_object, + IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT, + module_object, "IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT"); set_integer( - IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR, module_object, + IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR, + module_object, "IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR"); + set_integer(IMAGE_SCN_CNT_CODE, module_object, "SECTION_CNT_CODE"); set_integer( - IMAGE_SCN_CNT_CODE, module_object, - "SECTION_CNT_CODE"); - set_integer( - IMAGE_SCN_CNT_INITIALIZED_DATA, module_object, + IMAGE_SCN_CNT_INITIALIZED_DATA, + module_object, "SECTION_CNT_INITIALIZED_DATA"); set_integer( - IMAGE_SCN_CNT_UNINITIALIZED_DATA, module_object, + IMAGE_SCN_CNT_UNINITIALIZED_DATA, + module_object, "SECTION_CNT_UNINITIALIZED_DATA"); + set_integer(IMAGE_SCN_GPREL, module_object, "SECTION_GPREL"); + set_integer(IMAGE_SCN_MEM_16BIT, module_object, "SECTION_MEM_16BIT"); set_integer( - IMAGE_SCN_GPREL, module_object, - "SECTION_GPREL"); - set_integer( - IMAGE_SCN_MEM_16BIT, module_object, - "SECTION_MEM_16BIT"); - set_integer( - IMAGE_SCN_LNK_NRELOC_OVFL, module_object, - "SECTION_LNK_NRELOC_OVFL"); - set_integer( - IMAGE_SCN_MEM_DISCARDABLE, module_object, - "SECTION_MEM_DISCARDABLE"); - set_integer( - IMAGE_SCN_MEM_NOT_CACHED, module_object, - "SECTION_MEM_NOT_CACHED"); + IMAGE_SCN_LNK_NRELOC_OVFL, module_object, "SECTION_LNK_NRELOC_OVFL"); set_integer( - IMAGE_SCN_MEM_NOT_PAGED, module_object, - "SECTION_MEM_NOT_PAGED"); + IMAGE_SCN_MEM_DISCARDABLE, module_object, "SECTION_MEM_DISCARDABLE"); set_integer( - IMAGE_SCN_MEM_SHARED, module_object, - "SECTION_MEM_SHARED"); - set_integer( - IMAGE_SCN_MEM_EXECUTE, module_object, - "SECTION_MEM_EXECUTE"); - set_integer( - IMAGE_SCN_MEM_READ, module_object, - "SECTION_MEM_READ"); - set_integer( - IMAGE_SCN_MEM_WRITE, module_object, - "SECTION_MEM_WRITE"); + IMAGE_SCN_MEM_NOT_CACHED, module_object, "SECTION_MEM_NOT_CACHED"); + set_integer(IMAGE_SCN_MEM_NOT_PAGED, module_object, "SECTION_MEM_NOT_PAGED"); + set_integer(IMAGE_SCN_MEM_SHARED, module_object, "SECTION_MEM_SHARED"); + set_integer(IMAGE_SCN_MEM_EXECUTE, module_object, "SECTION_MEM_EXECUTE"); + set_integer(IMAGE_SCN_MEM_READ, module_object, "SECTION_MEM_READ"); + set_integer(IMAGE_SCN_MEM_WRITE, module_object, "SECTION_MEM_WRITE"); + set_integer(RESOURCE_TYPE_CURSOR, module_object, "RESOURCE_TYPE_CURSOR"); + set_integer(RESOURCE_TYPE_BITMAP, module_object, "RESOURCE_TYPE_BITMAP"); + set_integer(RESOURCE_TYPE_ICON, module_object, "RESOURCE_TYPE_ICON"); + set_integer(RESOURCE_TYPE_MENU, module_object, "RESOURCE_TYPE_MENU"); + set_integer(RESOURCE_TYPE_DIALOG, module_object, "RESOURCE_TYPE_DIALOG"); + set_integer(RESOURCE_TYPE_STRING, module_object, "RESOURCE_TYPE_STRING"); + set_integer(RESOURCE_TYPE_FONTDIR, module_object, "RESOURCE_TYPE_FONTDIR"); + set_integer(RESOURCE_TYPE_FONT, module_object, "RESOURCE_TYPE_FONT"); set_integer( - RESOURCE_TYPE_CURSOR, module_object, - "RESOURCE_TYPE_CURSOR"); - set_integer( - RESOURCE_TYPE_BITMAP, module_object, - "RESOURCE_TYPE_BITMAP"); - set_integer( - RESOURCE_TYPE_ICON, module_object, - "RESOURCE_TYPE_ICON"); - set_integer( - RESOURCE_TYPE_MENU, module_object, - "RESOURCE_TYPE_MENU"); - set_integer( - RESOURCE_TYPE_DIALOG, module_object, - "RESOURCE_TYPE_DIALOG"); - set_integer( - RESOURCE_TYPE_STRING, module_object, - "RESOURCE_TYPE_STRING"); - set_integer( - RESOURCE_TYPE_FONTDIR, module_object, - "RESOURCE_TYPE_FONTDIR"); - set_integer( - RESOURCE_TYPE_FONT, module_object, - "RESOURCE_TYPE_FONT"); + RESOURCE_TYPE_ACCELERATOR, module_object, "RESOURCE_TYPE_ACCELERATOR"); + set_integer(RESOURCE_TYPE_RCDATA, module_object, "RESOURCE_TYPE_RCDATA"); set_integer( - RESOURCE_TYPE_ACCELERATOR, module_object, - "RESOURCE_TYPE_ACCELERATOR"); + RESOURCE_TYPE_MESSAGETABLE, module_object, "RESOURCE_TYPE_MESSAGETABLE"); set_integer( - RESOURCE_TYPE_RCDATA, module_object, - "RESOURCE_TYPE_RCDATA"); + RESOURCE_TYPE_GROUP_CURSOR, module_object, "RESOURCE_TYPE_GROUP_CURSOR"); set_integer( - RESOURCE_TYPE_MESSAGETABLE, module_object, - "RESOURCE_TYPE_MESSAGETABLE"); + RESOURCE_TYPE_GROUP_ICON, module_object, "RESOURCE_TYPE_GROUP_ICON"); + set_integer(RESOURCE_TYPE_VERSION, module_object, "RESOURCE_TYPE_VERSION"); set_integer( - RESOURCE_TYPE_GROUP_CURSOR, module_object, - "RESOURCE_TYPE_GROUP_CURSOR"); + RESOURCE_TYPE_DLGINCLUDE, module_object, "RESOURCE_TYPE_DLGINCLUDE"); + set_integer(RESOURCE_TYPE_PLUGPLAY, module_object, "RESOURCE_TYPE_PLUGPLAY"); + set_integer(RESOURCE_TYPE_VXD, module_object, "RESOURCE_TYPE_VXD"); set_integer( - RESOURCE_TYPE_GROUP_ICON, module_object, - "RESOURCE_TYPE_GROUP_ICON"); - set_integer( - RESOURCE_TYPE_VERSION, module_object, - "RESOURCE_TYPE_VERSION"); - set_integer( - RESOURCE_TYPE_DLGINCLUDE, module_object, - "RESOURCE_TYPE_DLGINCLUDE"); - set_integer( - RESOURCE_TYPE_PLUGPLAY, module_object, - "RESOURCE_TYPE_PLUGPLAY"); - set_integer( - RESOURCE_TYPE_VXD, module_object, - "RESOURCE_TYPE_VXD"); - set_integer( - RESOURCE_TYPE_ANICURSOR, module_object, - "RESOURCE_TYPE_ANICURSOR"); - set_integer( - RESOURCE_TYPE_ANIICON, module_object, - "RESOURCE_TYPE_ANIICON"); - set_integer( - RESOURCE_TYPE_HTML, module_object, - "RESOURCE_TYPE_HTML"); - set_integer( - RESOURCE_TYPE_MANIFEST, module_object, - "RESOURCE_TYPE_MANIFEST"); + RESOURCE_TYPE_ANICURSOR, module_object, "RESOURCE_TYPE_ANICURSOR"); + set_integer(RESOURCE_TYPE_ANIICON, module_object, "RESOURCE_TYPE_ANIICON"); + set_integer(RESOURCE_TYPE_HTML, module_object, "RESOURCE_TYPE_HTML"); + set_integer(RESOURCE_TYPE_MANIFEST, module_object, "RESOURCE_TYPE_MANIFEST"); set_integer(0, module_object, "is_pe"); foreach_memory_block(iterator, block) @@ -3365,8 +3230,7 @@ int module_load( return ERROR_INSUFFICIENT_MEMORY; FAIL_ON_ERROR_WITH_CLEANUP( - yr_hash_table_create(17, &pe->hash_table), - yr_free(pe)); + yr_hash_table_create(17, &pe->hash_table), yr_free(pe)); pe->data = block_data; pe->data_size = block->size; @@ -3380,9 +3244,9 @@ int module_load( pe_parse_rich_signature(pe, block->base); pe_parse_debug_directory(pe); - #if defined(HAVE_LIBCRYPTO) && !defined(BORINGSSL) +#if defined(HAVE_LIBCRYPTO) && !defined(BORINGSSL) pe_parse_certificates(pe); - #endif +#endif pe->imported_dlls = pe_parse_imports(pe); pe_parse_exports(pe); @@ -3396,23 +3260,21 @@ int module_load( } -int module_unload( - YR_OBJECT* module_object) +int module_unload(YR_OBJECT* module_object) { IMPORTED_DLL* dll = NULL; IMPORTED_DLL* next_dll = NULL; IMPORT_FUNCTION* func = NULL; IMPORT_FUNCTION* next_func = NULL; - PE* pe = (PE *) module_object->data; + PE* pe = (PE*) module_object->data; if (pe == NULL) return ERROR_SUCCESS; if (pe->hash_table != NULL) yr_hash_table_destroy( - pe->hash_table, - (YR_HASH_TABLE_FREE_VALUE_FUNC) yr_free); + pe->hash_table, (YR_HASH_TABLE_FREE_VALUE_FUNC) yr_free); dll = pe->imported_dlls; diff --git a/libyara/modules/pe/pe_utils.c b/libyara/modules/pe/pe_utils.c index 5255d8c746..72695b2fe2 100644 --- a/libyara/modules/pe/pe_utils.c +++ b/libyara/modules/pe/pe_utils.c @@ -28,24 +28,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include - #include - #include -#include -#include -#include #include -#include +#include #include +#include +#include +#include #if HAVE_LIBCRYPTO #include #endif -PIMAGE_NT_HEADERS32 pe_get_header( - const uint8_t* data, - size_t data_size) +PIMAGE_NT_HEADERS32 pe_get_header(const uint8_t* data, size_t data_size) { PIMAGE_DOS_HEADER mz_header; PIMAGE_NT_HEADERS32 pe_header; @@ -63,14 +59,13 @@ PIMAGE_NT_HEADERS32 pe_get_header( if (yr_le32toh(mz_header->e_lfanew) < 0) return NULL; - headers_size = yr_le32toh(mz_header->e_lfanew) + \ - sizeof(pe_header->Signature) + \ - sizeof(IMAGE_FILE_HEADER); + headers_size = yr_le32toh(mz_header->e_lfanew) + + sizeof(pe_header->Signature) + sizeof(IMAGE_FILE_HEADER); if (data_size < headers_size) return NULL; - pe_header = (PIMAGE_NT_HEADERS32) (data + yr_le32toh(mz_header->e_lfanew)); + pe_header = (PIMAGE_NT_HEADERS32)(data + yr_le32toh(mz_header->e_lfanew)); if (yr_le32toh(pe_header->Signature) != IMAGE_NT_SIGNATURE) return NULL; @@ -98,9 +93,11 @@ PIMAGE_NT_HEADERS32 pe_get_header( yr_le16toh(pe_header->FileHeader.Machine) != IMAGE_FILE_MACHINE_M32R && yr_le16toh(pe_header->FileHeader.Machine) != IMAGE_FILE_MACHINE_MIPS16 && yr_le16toh(pe_header->FileHeader.Machine) != IMAGE_FILE_MACHINE_MIPSFPU && - yr_le16toh(pe_header->FileHeader.Machine) != IMAGE_FILE_MACHINE_MIPSFPU16 && + yr_le16toh(pe_header->FileHeader.Machine) != + IMAGE_FILE_MACHINE_MIPSFPU16 && yr_le16toh(pe_header->FileHeader.Machine) != IMAGE_FILE_MACHINE_POWERPC && - yr_le16toh(pe_header->FileHeader.Machine) != IMAGE_FILE_MACHINE_POWERPCFP && + yr_le16toh(pe_header->FileHeader.Machine) != + IMAGE_FILE_MACHINE_POWERPCFP && yr_le16toh(pe_header->FileHeader.Machine) != IMAGE_FILE_MACHINE_R4000 && yr_le16toh(pe_header->FileHeader.Machine) != IMAGE_FILE_MACHINE_SH3 && yr_le16toh(pe_header->FileHeader.Machine) != IMAGE_FILE_MACHINE_SH3DSP && @@ -116,9 +113,7 @@ PIMAGE_NT_HEADERS32 pe_get_header( } -PIMAGE_DATA_DIRECTORY pe_get_directory_entry( - PE* pe, - int entry) +PIMAGE_DATA_DIRECTORY pe_get_directory_entry(PE* pe, int entry) { PIMAGE_DATA_DIRECTORY directory_start; uint8_t* optional_header_start; @@ -152,7 +147,8 @@ PIMAGE_DATA_DIRECTORY pe_get_directory_entry( } // Make sure the entry doesn't point outside of the OptionalHeader. - if ((uint8_t*) (directory_start + entry) <= optional_header_start + optional_header_size) + if ((uint8_t*) (directory_start + entry) <= + optional_header_start + optional_header_size) { if (IS_64BITS_PE(pe)) return &pe->header64->OptionalHeader.DataDirectory[entry]; @@ -164,9 +160,7 @@ PIMAGE_DATA_DIRECTORY pe_get_directory_entry( } -int64_t pe_rva_to_offset( - PE* pe, - uint64_t rva) +int64_t pe_rva_to_offset(PE* pe, uint64_t rva) { PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION(pe->header); @@ -182,7 +176,9 @@ int64_t pe_rva_to_offset( int alignment = 0; int rest = 0; - while(i < yr_min(yr_le16toh(pe->header->FileHeader.NumberOfSections), MAX_PE_SECTIONS)) + while (i < yr_min( + yr_le16toh(pe->header->FileHeader.NumberOfSections), + MAX_PE_SECTIONS)) { if (struct_fits_in_pe(pe, section, IMAGE_SECTION_HEADER)) { @@ -205,7 +201,8 @@ int64_t pe_rva_to_offset( // If FileAlignment is >= 0x200, it is apparently ignored (see // Ero Carreras's pefile.py, PE.adjust_FileAlignment). - alignment = yr_min(yr_le32toh(OptionalHeader(pe, FileAlignment)), 0x200); + alignment = yr_min( + yr_le32toh(OptionalHeader(pe, FileAlignment)), 0x200); section_rva = yr_le32toh(section->VirtualAddress); section_offset = yr_le32toh(section->PointerToRawData); @@ -263,16 +260,14 @@ int64_t pe_rva_to_offset( #include -static bool is_leap( - unsigned int year) +static bool is_leap(unsigned int year) { year += 1900; return (year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0); } -time_t timegm( - struct tm *tm) +time_t timegm(struct tm* tm) { static const unsigned ndays[2][12] = { {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, @@ -281,11 +276,9 @@ time_t timegm( time_t res = 0; int i; - for (i = 70; i < tm->tm_year; ++i) - res += is_leap(i) ? 366 : 365; + for (i = 70; i < tm->tm_year; ++i) res += is_leap(i) ? 366 : 365; - for (i = 0; i < tm->tm_mon; ++i) - res += ndays[is_leap(tm->tm_year)][i]; + for (i = 0; i < tm->tm_mon; ++i) res += ndays[is_leap(tm->tm_year)][i]; res += tm->tm_mday - 1; res *= 24; @@ -298,16 +291,15 @@ time_t timegm( return res; } -#endif // HAVE__MKGMTIME -#endif // !HAVE_TIMEGM +#endif // HAVE__MKGMTIME +#endif // !HAVE_TIMEGM #if HAVE_LIBCRYPTO // Taken from http://stackoverflow.com/questions/10975542/asn1-time-conversion // and cleaned up. Also uses timegm(3) instead of mktime(3). -time_t ASN1_get_time_t( - const ASN1_TIME* time) +time_t ASN1_get_time_t(const ASN1_TIME* time) { struct tm t; const char* str = (const char*) time->data; @@ -333,7 +325,7 @@ time_t ASN1_get_time_t( } t.tm_mon = (str[i++] - '0') * 10; - t.tm_mon += (str[i++] - '0') - 1; // -1 since January is 0 not 1. + t.tm_mon += (str[i++] - '0') - 1; // -1 since January is 0 not 1. t.tm_mday = (str[i++] - '0') * 10; t.tm_mday += (str[i++] - '0'); t.tm_hour = (str[i++] - '0') * 10; @@ -354,9 +346,7 @@ time_t ASN1_get_time_t( // "ordN" and if that fails, return NULL. The caller is responsible for freeing // the returned string. -char *ord_lookup( - char *dll, - uint16_t ord) +char* ord_lookup(char* dll, uint16_t ord) { char name[64]; name[0] = '\0'; @@ -364,1561 +354,1563 @@ char *ord_lookup( if (strncasecmp(dll, "WS2_32.dll", 10) == 0 || strncasecmp(dll, "wsock32.dll", 11) == 0) { - switch(ord) { - case 1: - sprintf(name, "accept"); - break; - case 2: - sprintf(name, "bind"); - break; - case 3: - sprintf(name, "closesocket"); - break; - case 4: - sprintf(name, "connect"); - break; - case 5: - sprintf(name, "getpeername"); - break; - case 6: - sprintf(name, "getsockname"); - break; - case 7: - sprintf(name, "getsockopt"); - break; - case 8: - sprintf(name, "htonl"); - break; - case 9: - sprintf(name, "htons"); - break; - case 10: - sprintf(name, "ioctlsocket"); - break; - case 11: - sprintf(name, "inet_addr"); - break; - case 12: - sprintf(name, "inet_ntoa"); - break; - case 13: - sprintf(name, "listen"); - break; - case 14: - sprintf(name, "ntohl"); - break; - case 15: - sprintf(name, "ntohs"); - break; - case 16: - sprintf(name, "recv"); - break; - case 17: - sprintf(name, "recvfrom"); - break; - case 18: - sprintf(name, "select"); - break; - case 19: - sprintf(name, "send"); - break; - case 20: - sprintf(name, "sendto"); - break; - case 21: - sprintf(name, "setsockopt"); - break; - case 22: - sprintf(name, "shutdown"); - break; - case 23: - sprintf(name, "socket"); - break; - case 24: - sprintf(name, "GetAddrInfoW"); - break; - case 25: - sprintf(name, "GetNameInfoW"); - break; - case 26: - sprintf(name, "WSApSetPostRoutine"); - break; - case 27: - sprintf(name, "FreeAddrInfoW"); - break; - case 28: - sprintf(name, "WPUCompleteOverlappedRequest"); - break; - case 29: - sprintf(name, "WSAAccept"); - break; - case 30: - sprintf(name, "WSAAddressToStringA"); - break; - case 31: - sprintf(name, "WSAAddressToStringW"); - break; - case 32: - sprintf(name, "WSACloseEvent"); - break; - case 33: - sprintf(name, "WSAConnect"); - break; - case 34: - sprintf(name, "WSACreateEvent"); - break; - case 35: - sprintf(name, "WSADuplicateSocketA"); - break; - case 36: - sprintf(name, "WSADuplicateSocketW"); - break; - case 37: - sprintf(name, "WSAEnumNameSpaceProvidersA"); - break; - case 38: - sprintf(name, "WSAEnumNameSpaceProvidersW"); - break; - case 39: - sprintf(name, "WSAEnumNetworkEvents"); - break; - case 40: - sprintf(name, "WSAEnumProtocolsA"); - break; - case 41: - sprintf(name, "WSAEnumProtocolsW"); - break; - case 42: - sprintf(name, "WSAEventSelect"); - break; - case 43: - sprintf(name, "WSAGetOverlappedResult"); - break; - case 44: - sprintf(name, "WSAGetQOSByName"); - break; - case 45: - sprintf(name, "WSAGetServiceClassInfoA"); - break; - case 46: - sprintf(name, "WSAGetServiceClassInfoW"); - break; - case 47: - sprintf(name, "WSAGetServiceClassNameByClassIdA"); - break; - case 48: - sprintf(name, "WSAGetServiceClassNameByClassIdW"); - break; - case 49: - sprintf(name, "WSAHtonl"); - break; - case 50: - sprintf(name, "WSAHtons"); - break; - case 51: - sprintf(name, "gethostbyaddr"); - break; - case 52: - sprintf(name, "gethostbyname"); - break; - case 53: - sprintf(name, "getprotobyname"); - break; - case 54: - sprintf(name, "getprotobynumber"); - break; - case 55: - sprintf(name, "getservbyname"); - break; - case 56: - sprintf(name, "getservbyport"); - break; - case 57: - sprintf(name, "gethostname"); - break; - case 58: - sprintf(name, "WSAInstallServiceClassA"); - break; - case 59: - sprintf(name, "WSAInstallServiceClassW"); - break; - case 60: - sprintf(name, "WSAIoctl"); - break; - case 61: - sprintf(name, "WSAJoinLeaf"); - break; - case 62: - sprintf(name, "WSALookupServiceBeginA"); - break; - case 63: - sprintf(name, "WSALookupServiceBeginW"); - break; - case 64: - sprintf(name, "WSALookupServiceEnd"); - break; - case 65: - sprintf(name, "WSALookupServiceNextA"); - break; - case 66: - sprintf(name, "WSALookupServiceNextW"); - break; - case 67: - sprintf(name, "WSANSPIoctl"); - break; - case 68: - sprintf(name, "WSANtohl"); - break; - case 69: - sprintf(name, "WSANtohs"); - break; - case 70: - sprintf(name, "WSAProviderConfigChange"); - break; - case 71: - sprintf(name, "WSARecv"); - break; - case 72: - sprintf(name, "WSARecvDisconnect"); - break; - case 73: - sprintf(name, "WSARecvFrom"); - break; - case 74: - sprintf(name, "WSARemoveServiceClass"); - break; - case 75: - sprintf(name, "WSAResetEvent"); - break; - case 76: - sprintf(name, "WSASend"); - break; - case 77: - sprintf(name, "WSASendDisconnect"); - break; - case 78: - sprintf(name, "WSASendTo"); - break; - case 79: - sprintf(name, "WSASetEvent"); - break; - case 80: - sprintf(name, "WSASetServiceA"); - break; - case 81: - sprintf(name, "WSASetServiceW"); - break; - case 82: - sprintf(name, "WSASocketA"); - break; - case 83: - sprintf(name, "WSASocketW"); - break; - case 84: - sprintf(name, "WSAStringToAddressA"); - break; - case 85: - sprintf(name, "WSAStringToAddressW"); - break; - case 86: - sprintf(name, "WSAWaitForMultipleEvents"); - break; - case 87: - sprintf(name, "WSCDeinstallProvider"); - break; - case 88: - sprintf(name, "WSCEnableNSProvider"); - break; - case 89: - sprintf(name, "WSCEnumProtocols"); - break; - case 90: - sprintf(name, "WSCGetProviderPath"); - break; - case 91: - sprintf(name, "WSCInstallNameSpace"); - break; - case 92: - sprintf(name, "WSCInstallProvider"); - break; - case 93: - sprintf(name, "WSCUnInstallNameSpace"); - break; - case 94: - sprintf(name, "WSCUpdateProvider"); - break; - case 95: - sprintf(name, "WSCWriteNameSpaceOrder"); - break; - case 96: - sprintf(name, "WSCWriteProviderOrder"); - break; - case 97: - sprintf(name, "freeaddrinfo"); - break; - case 98: - sprintf(name, "getaddrinfo"); - break; - case 99: - sprintf(name, "getnameinfo"); - break; - case 101: - sprintf(name, "WSAAsyncSelect"); - break; - case 102: - sprintf(name, "WSAAsyncGetHostByAddr"); - break; - case 103: - sprintf(name, "WSAAsyncGetHostByName"); - break; - case 104: - sprintf(name, "WSAAsyncGetProtoByNumber"); - break; - case 105: - sprintf(name, "WSAAsyncGetProtoByName"); - break; - case 106: - sprintf(name, "WSAAsyncGetServByPort"); - break; - case 107: - sprintf(name, "WSAAsyncGetServByName"); - break; - case 108: - sprintf(name, "WSACancelAsyncRequest"); - break; - case 109: - sprintf(name, "WSASetBlockingHook"); - break; - case 110: - sprintf(name, "WSAUnhookBlockingHook"); - break; - case 111: - sprintf(name, "WSAGetLastError"); - break; - case 112: - sprintf(name, "WSASetLastError"); - break; - case 113: - sprintf(name, "WSACancelBlockingCall"); - break; - case 114: - sprintf(name, "WSAIsBlocking"); - break; - case 115: - sprintf(name, "WSAStartup"); - break; - case 116: - sprintf(name, "WSACleanup"); - break; - case 151: - sprintf(name, "__WSAFDIsSet"); - break; - case 500: - sprintf(name, "WEP"); - break; - default: - break; + switch (ord) + { + case 1: + sprintf(name, "accept"); + break; + case 2: + sprintf(name, "bind"); + break; + case 3: + sprintf(name, "closesocket"); + break; + case 4: + sprintf(name, "connect"); + break; + case 5: + sprintf(name, "getpeername"); + break; + case 6: + sprintf(name, "getsockname"); + break; + case 7: + sprintf(name, "getsockopt"); + break; + case 8: + sprintf(name, "htonl"); + break; + case 9: + sprintf(name, "htons"); + break; + case 10: + sprintf(name, "ioctlsocket"); + break; + case 11: + sprintf(name, "inet_addr"); + break; + case 12: + sprintf(name, "inet_ntoa"); + break; + case 13: + sprintf(name, "listen"); + break; + case 14: + sprintf(name, "ntohl"); + break; + case 15: + sprintf(name, "ntohs"); + break; + case 16: + sprintf(name, "recv"); + break; + case 17: + sprintf(name, "recvfrom"); + break; + case 18: + sprintf(name, "select"); + break; + case 19: + sprintf(name, "send"); + break; + case 20: + sprintf(name, "sendto"); + break; + case 21: + sprintf(name, "setsockopt"); + break; + case 22: + sprintf(name, "shutdown"); + break; + case 23: + sprintf(name, "socket"); + break; + case 24: + sprintf(name, "GetAddrInfoW"); + break; + case 25: + sprintf(name, "GetNameInfoW"); + break; + case 26: + sprintf(name, "WSApSetPostRoutine"); + break; + case 27: + sprintf(name, "FreeAddrInfoW"); + break; + case 28: + sprintf(name, "WPUCompleteOverlappedRequest"); + break; + case 29: + sprintf(name, "WSAAccept"); + break; + case 30: + sprintf(name, "WSAAddressToStringA"); + break; + case 31: + sprintf(name, "WSAAddressToStringW"); + break; + case 32: + sprintf(name, "WSACloseEvent"); + break; + case 33: + sprintf(name, "WSAConnect"); + break; + case 34: + sprintf(name, "WSACreateEvent"); + break; + case 35: + sprintf(name, "WSADuplicateSocketA"); + break; + case 36: + sprintf(name, "WSADuplicateSocketW"); + break; + case 37: + sprintf(name, "WSAEnumNameSpaceProvidersA"); + break; + case 38: + sprintf(name, "WSAEnumNameSpaceProvidersW"); + break; + case 39: + sprintf(name, "WSAEnumNetworkEvents"); + break; + case 40: + sprintf(name, "WSAEnumProtocolsA"); + break; + case 41: + sprintf(name, "WSAEnumProtocolsW"); + break; + case 42: + sprintf(name, "WSAEventSelect"); + break; + case 43: + sprintf(name, "WSAGetOverlappedResult"); + break; + case 44: + sprintf(name, "WSAGetQOSByName"); + break; + case 45: + sprintf(name, "WSAGetServiceClassInfoA"); + break; + case 46: + sprintf(name, "WSAGetServiceClassInfoW"); + break; + case 47: + sprintf(name, "WSAGetServiceClassNameByClassIdA"); + break; + case 48: + sprintf(name, "WSAGetServiceClassNameByClassIdW"); + break; + case 49: + sprintf(name, "WSAHtonl"); + break; + case 50: + sprintf(name, "WSAHtons"); + break; + case 51: + sprintf(name, "gethostbyaddr"); + break; + case 52: + sprintf(name, "gethostbyname"); + break; + case 53: + sprintf(name, "getprotobyname"); + break; + case 54: + sprintf(name, "getprotobynumber"); + break; + case 55: + sprintf(name, "getservbyname"); + break; + case 56: + sprintf(name, "getservbyport"); + break; + case 57: + sprintf(name, "gethostname"); + break; + case 58: + sprintf(name, "WSAInstallServiceClassA"); + break; + case 59: + sprintf(name, "WSAInstallServiceClassW"); + break; + case 60: + sprintf(name, "WSAIoctl"); + break; + case 61: + sprintf(name, "WSAJoinLeaf"); + break; + case 62: + sprintf(name, "WSALookupServiceBeginA"); + break; + case 63: + sprintf(name, "WSALookupServiceBeginW"); + break; + case 64: + sprintf(name, "WSALookupServiceEnd"); + break; + case 65: + sprintf(name, "WSALookupServiceNextA"); + break; + case 66: + sprintf(name, "WSALookupServiceNextW"); + break; + case 67: + sprintf(name, "WSANSPIoctl"); + break; + case 68: + sprintf(name, "WSANtohl"); + break; + case 69: + sprintf(name, "WSANtohs"); + break; + case 70: + sprintf(name, "WSAProviderConfigChange"); + break; + case 71: + sprintf(name, "WSARecv"); + break; + case 72: + sprintf(name, "WSARecvDisconnect"); + break; + case 73: + sprintf(name, "WSARecvFrom"); + break; + case 74: + sprintf(name, "WSARemoveServiceClass"); + break; + case 75: + sprintf(name, "WSAResetEvent"); + break; + case 76: + sprintf(name, "WSASend"); + break; + case 77: + sprintf(name, "WSASendDisconnect"); + break; + case 78: + sprintf(name, "WSASendTo"); + break; + case 79: + sprintf(name, "WSASetEvent"); + break; + case 80: + sprintf(name, "WSASetServiceA"); + break; + case 81: + sprintf(name, "WSASetServiceW"); + break; + case 82: + sprintf(name, "WSASocketA"); + break; + case 83: + sprintf(name, "WSASocketW"); + break; + case 84: + sprintf(name, "WSAStringToAddressA"); + break; + case 85: + sprintf(name, "WSAStringToAddressW"); + break; + case 86: + sprintf(name, "WSAWaitForMultipleEvents"); + break; + case 87: + sprintf(name, "WSCDeinstallProvider"); + break; + case 88: + sprintf(name, "WSCEnableNSProvider"); + break; + case 89: + sprintf(name, "WSCEnumProtocols"); + break; + case 90: + sprintf(name, "WSCGetProviderPath"); + break; + case 91: + sprintf(name, "WSCInstallNameSpace"); + break; + case 92: + sprintf(name, "WSCInstallProvider"); + break; + case 93: + sprintf(name, "WSCUnInstallNameSpace"); + break; + case 94: + sprintf(name, "WSCUpdateProvider"); + break; + case 95: + sprintf(name, "WSCWriteNameSpaceOrder"); + break; + case 96: + sprintf(name, "WSCWriteProviderOrder"); + break; + case 97: + sprintf(name, "freeaddrinfo"); + break; + case 98: + sprintf(name, "getaddrinfo"); + break; + case 99: + sprintf(name, "getnameinfo"); + break; + case 101: + sprintf(name, "WSAAsyncSelect"); + break; + case 102: + sprintf(name, "WSAAsyncGetHostByAddr"); + break; + case 103: + sprintf(name, "WSAAsyncGetHostByName"); + break; + case 104: + sprintf(name, "WSAAsyncGetProtoByNumber"); + break; + case 105: + sprintf(name, "WSAAsyncGetProtoByName"); + break; + case 106: + sprintf(name, "WSAAsyncGetServByPort"); + break; + case 107: + sprintf(name, "WSAAsyncGetServByName"); + break; + case 108: + sprintf(name, "WSACancelAsyncRequest"); + break; + case 109: + sprintf(name, "WSASetBlockingHook"); + break; + case 110: + sprintf(name, "WSAUnhookBlockingHook"); + break; + case 111: + sprintf(name, "WSAGetLastError"); + break; + case 112: + sprintf(name, "WSASetLastError"); + break; + case 113: + sprintf(name, "WSACancelBlockingCall"); + break; + case 114: + sprintf(name, "WSAIsBlocking"); + break; + case 115: + sprintf(name, "WSAStartup"); + break; + case 116: + sprintf(name, "WSACleanup"); + break; + case 151: + sprintf(name, "__WSAFDIsSet"); + break; + case 500: + sprintf(name, "WEP"); + break; + default: + break; } } else if (strncasecmp(dll, "oleaut32.dll", 12) == 0) { - switch (ord) { - case 2: - sprintf(name, "SysAllocString"); - break; - case 3: - sprintf(name, "SysReAllocString"); - break; - case 4: - sprintf(name, "SysAllocStringLen"); - break; - case 5: - sprintf(name, "SysReAllocStringLen"); - break; - case 6: - sprintf(name, "SysFreeString"); - break; - case 7: - sprintf(name, "SysStringLen"); - break; - case 8: - sprintf(name, "VariantInit"); - break; - case 9: - sprintf(name, "VariantClear"); - break; - case 10: - sprintf(name, "VariantCopy"); - break; - case 11: - sprintf(name, "VariantCopyInd"); - break; - case 12: - sprintf(name, "VariantChangeType"); - break; - case 13: - sprintf(name, "VariantTimeToDosDateTime"); - break; - case 14: - sprintf(name, "DosDateTimeToVariantTime"); - break; - case 15: - sprintf(name, "SafeArrayCreate"); - break; - case 16: - sprintf(name, "SafeArrayDestroy"); - break; - case 17: - sprintf(name, "SafeArrayGetDim"); - break; - case 18: - sprintf(name, "SafeArrayGetElemsize"); - break; - case 19: - sprintf(name, "SafeArrayGetUBound"); - break; - case 20: - sprintf(name, "SafeArrayGetLBound"); - break; - case 21: - sprintf(name, "SafeArrayLock"); - break; - case 22: - sprintf(name, "SafeArrayUnlock"); - break; - case 23: - sprintf(name, "SafeArrayAccessData"); - break; - case 24: - sprintf(name, "SafeArrayUnaccessData"); - break; - case 25: - sprintf(name, "SafeArrayGetElement"); - break; - case 26: - sprintf(name, "SafeArrayPutElement"); - break; - case 27: - sprintf(name, "SafeArrayCopy"); - break; - case 28: - sprintf(name, "DispGetParam"); - break; - case 29: - sprintf(name, "DispGetIDsOfNames"); - break; - case 30: - sprintf(name, "DispInvoke"); - break; - case 31: - sprintf(name, "CreateDispTypeInfo"); - break; - case 32: - sprintf(name, "CreateStdDispatch"); - break; - case 33: - sprintf(name, "RegisterActiveObject"); - break; - case 34: - sprintf(name, "RevokeActiveObject"); - break; - case 35: - sprintf(name, "GetActiveObject"); - break; - case 36: - sprintf(name, "SafeArrayAllocDescriptor"); - break; - case 37: - sprintf(name, "SafeArrayAllocData"); - break; - case 38: - sprintf(name, "SafeArrayDestroyDescriptor"); - break; - case 39: - sprintf(name, "SafeArrayDestroyData"); - break; - case 40: - sprintf(name, "SafeArrayRedim"); - break; - case 41: - sprintf(name, "SafeArrayAllocDescriptorEx"); - break; - case 42: - sprintf(name, "SafeArrayCreateEx"); - break; - case 43: - sprintf(name, "SafeArrayCreateVectorEx"); - break; - case 44: - sprintf(name, "SafeArraySetRecordInfo"); - break; - case 45: - sprintf(name, "SafeArrayGetRecordInfo"); - break; - case 46: - sprintf(name, "VarParseNumFromStr"); - break; - case 47: - sprintf(name, "VarNumFromParseNum"); - break; - case 48: - sprintf(name, "VarI2FromUI1"); - break; - case 49: - sprintf(name, "VarI2FromI4"); - break; - case 50: - sprintf(name, "VarI2FromR4"); - break; - case 51: - sprintf(name, "VarI2FromR8"); - break; - case 52: - sprintf(name, "VarI2FromCy"); - break; - case 53: - sprintf(name, "VarI2FromDate"); - break; - case 54: - sprintf(name, "VarI2FromStr"); - break; - case 55: - sprintf(name, "VarI2FromDisp"); - break; - case 56: - sprintf(name, "VarI2FromBool"); - break; - case 57: - sprintf(name, "SafeArraySetIID"); - break; - case 58: - sprintf(name, "VarI4FromUI1"); - break; - case 59: - sprintf(name, "VarI4FromI2"); - break; - case 60: - sprintf(name, "VarI4FromR4"); - break; - case 61: - sprintf(name, "VarI4FromR8"); - break; - case 62: - sprintf(name, "VarI4FromCy"); - break; - case 63: - sprintf(name, "VarI4FromDate"); - break; - case 64: - sprintf(name, "VarI4FromStr"); - break; - case 65: - sprintf(name, "VarI4FromDisp"); - break; - case 66: - sprintf(name, "VarI4FromBool"); - break; - case 67: - sprintf(name, "SafeArrayGetIID"); - break; - case 68: - sprintf(name, "VarR4FromUI1"); - break; - case 69: - sprintf(name, "VarR4FromI2"); - break; - case 70: - sprintf(name, "VarR4FromI4"); - break; - case 71: - sprintf(name, "VarR4FromR8"); - break; - case 72: - sprintf(name, "VarR4FromCy"); - break; - case 73: - sprintf(name, "VarR4FromDate"); - break; - case 74: - sprintf(name, "VarR4FromStr"); - break; - case 75: - sprintf(name, "VarR4FromDisp"); - break; - case 76: - sprintf(name, "VarR4FromBool"); - break; - case 77: - sprintf(name, "SafeArrayGetVartype"); - break; - case 78: - sprintf(name, "VarR8FromUI1"); - break; - case 79: - sprintf(name, "VarR8FromI2"); - break; - case 80: - sprintf(name, "VarR8FromI4"); - break; - case 81: - sprintf(name, "VarR8FromR4"); - break; - case 82: - sprintf(name, "VarR8FromCy"); - break; - case 83: - sprintf(name, "VarR8FromDate"); - break; - case 84: - sprintf(name, "VarR8FromStr"); - break; - case 85: - sprintf(name, "VarR8FromDisp"); - break; - case 86: - sprintf(name, "VarR8FromBool"); - break; - case 87: - sprintf(name, "VarFormat"); - break; - case 88: - sprintf(name, "VarDateFromUI1"); - break; - case 89: - sprintf(name, "VarDateFromI2"); - break; - case 90: - sprintf(name, "VarDateFromI4"); - break; - case 91: - sprintf(name, "VarDateFromR4"); - break; - case 92: - sprintf(name, "VarDateFromR8"); - break; - case 93: - sprintf(name, "VarDateFromCy"); - break; - case 94: - sprintf(name, "VarDateFromStr"); - break; - case 95: - sprintf(name, "VarDateFromDisp"); - break; - case 96: - sprintf(name, "VarDateFromBool"); - break; - case 97: - sprintf(name, "VarFormatDateTime"); - break; - case 98: - sprintf(name, "VarCyFromUI1"); - break; - case 99: - sprintf(name, "VarCyFromI2"); - break; - case 100: - sprintf(name, "VarCyFromI4"); - break; - case 101: - sprintf(name, "VarCyFromR4"); - break; - case 102: - sprintf(name, "VarCyFromR8"); - break; - case 103: - sprintf(name, "VarCyFromDate"); - break; - case 104: - sprintf(name, "VarCyFromStr"); - break; - case 105: - sprintf(name, "VarCyFromDisp"); - break; - case 106: - sprintf(name, "VarCyFromBool"); - break; - case 107: - sprintf(name, "VarFormatNumber"); - break; - case 108: - sprintf(name, "VarBstrFromUI1"); - break; - case 109: - sprintf(name, "VarBstrFromI2"); - break; - case 110: - sprintf(name, "VarBstrFromI4"); - break; - case 111: - sprintf(name, "VarBstrFromR4"); - break; - case 112: - sprintf(name, "VarBstrFromR8"); - break; - case 113: - sprintf(name, "VarBstrFromCy"); - break; - case 114: - sprintf(name, "VarBstrFromDate"); - break; - case 115: - sprintf(name, "VarBstrFromDisp"); - break; - case 116: - sprintf(name, "VarBstrFromBool"); - break; - case 117: - sprintf(name, "VarFormatPercent"); - break; - case 118: - sprintf(name, "VarBoolFromUI1"); - break; - case 119: - sprintf(name, "VarBoolFromI2"); - break; - case 120: - sprintf(name, "VarBoolFromI4"); - break; - case 121: - sprintf(name, "VarBoolFromR4"); - break; - case 122: - sprintf(name, "VarBoolFromR8"); - break; - case 123: - sprintf(name, "VarBoolFromDate"); - break; - case 124: - sprintf(name, "VarBoolFromCy"); - break; - case 125: - sprintf(name, "VarBoolFromStr"); - break; - case 126: - sprintf(name, "VarBoolFromDisp"); - break; - case 127: - sprintf(name, "VarFormatCurrency"); - break; - case 128: - sprintf(name, "VarWeekdayName"); - break; - case 129: - sprintf(name, "VarMonthName"); - break; - case 130: - sprintf(name, "VarUI1FromI2"); - break; - case 131: - sprintf(name, "VarUI1FromI4"); - break; - case 132: - sprintf(name, "VarUI1FromR4"); - break; - case 133: - sprintf(name, "VarUI1FromR8"); - break; - case 134: - sprintf(name, "VarUI1FromCy"); - break; - case 135: - sprintf(name, "VarUI1FromDate"); - break; - case 136: - sprintf(name, "VarUI1FromStr"); - break; - case 137: - sprintf(name, "VarUI1FromDisp"); - break; - case 138: - sprintf(name, "VarUI1FromBool"); - break; - case 139: - sprintf(name, "VarFormatFromTokens"); - break; - case 140: - sprintf(name, "VarTokenizeFormatString"); - break; - case 141: - sprintf(name, "VarAdd"); - break; - case 142: - sprintf(name, "VarAnd"); - break; - case 143: - sprintf(name, "VarDiv"); - break; - case 144: - sprintf(name, "DllCanUnloadNow"); - break; - case 145: - sprintf(name, "DllGetClassObject"); - break; - case 146: - sprintf(name, "DispCallFunc"); - break; - case 147: - sprintf(name, "VariantChangeTypeEx"); - break; - case 148: - sprintf(name, "SafeArrayPtrOfIndex"); - break; - case 149: - sprintf(name, "SysStringByteLen"); - break; - case 150: - sprintf(name, "SysAllocStringByteLen"); - break; - case 151: - sprintf(name, "DllRegisterServer"); - break; - case 152: - sprintf(name, "VarEqv"); - break; - case 153: - sprintf(name, "VarIdiv"); - break; - case 154: - sprintf(name, "VarImp"); - break; - case 155: - sprintf(name, "VarMod"); - break; - case 156: - sprintf(name, "VarMul"); - break; - case 157: - sprintf(name, "VarOr"); - break; - case 158: - sprintf(name, "VarPow"); - break; - case 159: - sprintf(name, "VarSub"); - break; - case 160: - sprintf(name, "CreateTypeLib"); - break; - case 161: - sprintf(name, "LoadTypeLib"); - break; - case 162: - sprintf(name, "LoadRegTypeLib"); - break; - case 163: - sprintf(name, "RegisterTypeLib"); - break; - case 164: - sprintf(name, "QueryPathOfRegTypeLib"); - break; - case 165: - sprintf(name, "LHashValOfNameSys"); - break; - case 166: - sprintf(name, "LHashValOfNameSysA"); - break; - case 167: - sprintf(name, "VarXor"); - break; - case 168: - sprintf(name, "VarAbs"); - break; - case 169: - sprintf(name, "VarFix"); - break; - case 170: - sprintf(name, "OaBuildVersion"); - break; - case 171: - sprintf(name, "ClearCustData"); - break; - case 172: - sprintf(name, "VarInt"); - break; - case 173: - sprintf(name, "VarNeg"); - break; - case 174: - sprintf(name, "VarNot"); - break; - case 175: - sprintf(name, "VarRound"); - break; - case 176: - sprintf(name, "VarCmp"); - break; - case 177: - sprintf(name, "VarDecAdd"); - break; - case 178: - sprintf(name, "VarDecDiv"); - break; - case 179: - sprintf(name, "VarDecMul"); - break; - case 180: - sprintf(name, "CreateTypeLib2"); - break; - case 181: - sprintf(name, "VarDecSub"); - break; - case 182: - sprintf(name, "VarDecAbs"); - break; - case 183: - sprintf(name, "LoadTypeLibEx"); - break; - case 184: - sprintf(name, "SystemTimeToVariantTime"); - break; - case 185: - sprintf(name, "VariantTimeToSystemTime"); - break; - case 186: - sprintf(name, "UnRegisterTypeLib"); - break; - case 187: - sprintf(name, "VarDecFix"); - break; - case 188: - sprintf(name, "VarDecInt"); - break; - case 189: - sprintf(name, "VarDecNeg"); - break; - case 190: - sprintf(name, "VarDecFromUI1"); - break; - case 191: - sprintf(name, "VarDecFromI2"); - break; - case 192: - sprintf(name, "VarDecFromI4"); - break; - case 193: - sprintf(name, "VarDecFromR4"); - break; - case 194: - sprintf(name, "VarDecFromR8"); - break; - case 195: - sprintf(name, "VarDecFromDate"); - break; - case 196: - sprintf(name, "VarDecFromCy"); - break; - case 197: - sprintf(name, "VarDecFromStr"); - break; - case 198: - sprintf(name, "VarDecFromDisp"); - break; - case 199: - sprintf(name, "VarDecFromBool"); - break; - case 200: - sprintf(name, "GetErrorInfo"); - break; - case 201: - sprintf(name, "SetErrorInfo"); - break; - case 202: - sprintf(name, "CreateErrorInfo"); - break; - case 203: - sprintf(name, "VarDecRound"); - break; - case 204: - sprintf(name, "VarDecCmp"); - break; - case 205: - sprintf(name, "VarI2FromI1"); - break; - case 206: - sprintf(name, "VarI2FromUI2"); - break; - case 207: - sprintf(name, "VarI2FromUI4"); - break; - case 208: - sprintf(name, "VarI2FromDec"); - break; - case 209: - sprintf(name, "VarI4FromI1"); - break; - case 210: - sprintf(name, "VarI4FromUI2"); - break; - case 211: - sprintf(name, "VarI4FromUI4"); - break; - case 212: - sprintf(name, "VarI4FromDec"); - break; - case 213: - sprintf(name, "VarR4FromI1"); - break; - case 214: - sprintf(name, "VarR4FromUI2"); - break; - case 215: - sprintf(name, "VarR4FromUI4"); - break; - case 216: - sprintf(name, "VarR4FromDec"); - break; - case 217: - sprintf(name, "VarR8FromI1"); - break; - case 218: - sprintf(name, "VarR8FromUI2"); - break; - case 219: - sprintf(name, "VarR8FromUI4"); - break; - case 220: - sprintf(name, "VarR8FromDec"); - break; - case 221: - sprintf(name, "VarDateFromI1"); - break; - case 222: - sprintf(name, "VarDateFromUI2"); - break; - case 223: - sprintf(name, "VarDateFromUI4"); - break; - case 224: - sprintf(name, "VarDateFromDec"); - break; - case 225: - sprintf(name, "VarCyFromI1"); - break; - case 226: - sprintf(name, "VarCyFromUI2"); - break; - case 227: - sprintf(name, "VarCyFromUI4"); - break; - case 228: - sprintf(name, "VarCyFromDec"); - break; - case 229: - sprintf(name, "VarBstrFromI1"); - break; - case 230: - sprintf(name, "VarBstrFromUI2"); - break; - case 231: - sprintf(name, "VarBstrFromUI4"); - break; - case 232: - sprintf(name, "VarBstrFromDec"); - break; - case 233: - sprintf(name, "VarBoolFromI1"); - break; - case 234: - sprintf(name, "VarBoolFromUI2"); - break; - case 235: - sprintf(name, "VarBoolFromUI4"); - break; - case 236: - sprintf(name, "VarBoolFromDec"); - break; - case 237: - sprintf(name, "VarUI1FromI1"); - break; - case 238: - sprintf(name, "VarUI1FromUI2"); - break; - case 239: - sprintf(name, "VarUI1FromUI4"); - break; - case 240: - sprintf(name, "VarUI1FromDec"); - break; - case 241: - sprintf(name, "VarDecFromI1"); - break; - case 242: - sprintf(name, "VarDecFromUI2"); - break; - case 243: - sprintf(name, "VarDecFromUI4"); - break; - case 244: - sprintf(name, "VarI1FromUI1"); - break; - case 245: - sprintf(name, "VarI1FromI2"); - break; - case 246: - sprintf(name, "VarI1FromI4"); - break; - case 247: - sprintf(name, "VarI1FromR4"); - break; - case 248: - sprintf(name, "VarI1FromR8"); - break; - case 249: - sprintf(name, "VarI1FromDate"); - break; - case 250: - sprintf(name, "VarI1FromCy"); - break; - case 251: - sprintf(name, "VarI1FromStr"); - break; - case 252: - sprintf(name, "VarI1FromDisp"); - break; - case 253: - sprintf(name, "VarI1FromBool"); - break; - case 254: - sprintf(name, "VarI1FromUI2"); - break; - case 255: - sprintf(name, "VarI1FromUI4"); - break; - case 256: - sprintf(name, "VarI1FromDec"); - break; - case 257: - sprintf(name, "VarUI2FromUI1"); - break; - case 258: - sprintf(name, "VarUI2FromI2"); - break; - case 259: - sprintf(name, "VarUI2FromI4"); - break; - case 260: - sprintf(name, "VarUI2FromR4"); - break; - case 261: - sprintf(name, "VarUI2FromR8"); - break; - case 262: - sprintf(name, "VarUI2FromDate"); - break; - case 263: - sprintf(name, "VarUI2FromCy"); - break; - case 264: - sprintf(name, "VarUI2FromStr"); - break; - case 265: - sprintf(name, "VarUI2FromDisp"); - break; - case 266: - sprintf(name, "VarUI2FromBool"); - break; - case 267: - sprintf(name, "VarUI2FromI1"); - break; - case 268: - sprintf(name, "VarUI2FromUI4"); - break; - case 269: - sprintf(name, "VarUI2FromDec"); - break; - case 270: - sprintf(name, "VarUI4FromUI1"); - break; - case 271: - sprintf(name, "VarUI4FromI2"); - break; - case 272: - sprintf(name, "VarUI4FromI4"); - break; - case 273: - sprintf(name, "VarUI4FromR4"); - break; - case 274: - sprintf(name, "VarUI4FromR8"); - break; - case 275: - sprintf(name, "VarUI4FromDate"); - break; - case 276: - sprintf(name, "VarUI4FromCy"); - break; - case 277: - sprintf(name, "VarUI4FromStr"); - break; - case 278: - sprintf(name, "VarUI4FromDisp"); - break; - case 279: - sprintf(name, "VarUI4FromBool"); - break; - case 280: - sprintf(name, "VarUI4FromI1"); - break; - case 281: - sprintf(name, "VarUI4FromUI2"); - break; - case 282: - sprintf(name, "VarUI4FromDec"); - break; - case 283: - sprintf(name, "BSTR_UserSize"); - break; - case 284: - sprintf(name, "BSTR_UserMarshal"); - break; - case 285: - sprintf(name, "BSTR_UserUnmarshal"); - break; - case 286: - sprintf(name, "BSTR_UserFree"); - break; - case 287: - sprintf(name, "VARIANT_UserSize"); - break; - case 288: - sprintf(name, "VARIANT_UserMarshal"); - break; - case 289: - sprintf(name, "VARIANT_UserUnmarshal"); - break; - case 290: - sprintf(name, "VARIANT_UserFree"); - break; - case 291: - sprintf(name, "LPSAFEARRAY_UserSize"); - break; - case 292: - sprintf(name, "LPSAFEARRAY_UserMarshal"); - break; - case 293: - sprintf(name, "LPSAFEARRAY_UserUnmarshal"); - break; - case 294: - sprintf(name, "LPSAFEARRAY_UserFree"); - break; - case 295: - sprintf(name, "LPSAFEARRAY_Size"); - break; - case 296: - sprintf(name, "LPSAFEARRAY_Marshal"); - break; - case 297: - sprintf(name, "LPSAFEARRAY_Unmarshal"); - break; - case 298: - sprintf(name, "VarDecCmpR8"); - break; - case 299: - sprintf(name, "VarCyAdd"); - break; - case 300: - sprintf(name, "DllUnregisterServer"); - break; - case 301: - sprintf(name, "OACreateTypeLib2"); - break; - case 303: - sprintf(name, "VarCyMul"); - break; - case 304: - sprintf(name, "VarCyMulI4"); - break; - case 305: - sprintf(name, "VarCySub"); - break; - case 306: - sprintf(name, "VarCyAbs"); - break; - case 307: - sprintf(name, "VarCyFix"); - break; - case 308: - sprintf(name, "VarCyInt"); - break; - case 309: - sprintf(name, "VarCyNeg"); - break; - case 310: - sprintf(name, "VarCyRound"); - break; - case 311: - sprintf(name, "VarCyCmp"); - break; - case 312: - sprintf(name, "VarCyCmpR8"); - break; - case 313: - sprintf(name, "VarBstrCat"); - break; - case 314: - sprintf(name, "VarBstrCmp"); - break; - case 315: - sprintf(name, "VarR8Pow"); - break; - case 316: - sprintf(name, "VarR4CmpR8"); - break; - case 317: - sprintf(name, "VarR8Round"); - break; - case 318: - sprintf(name, "VarCat"); - break; - case 319: - sprintf(name, "VarDateFromUdateEx"); - break; - case 322: - sprintf(name, "GetRecordInfoFromGuids"); - break; - case 323: - sprintf(name, "GetRecordInfoFromTypeInfo"); - break; - case 325: - sprintf(name, "SetVarConversionLocaleSetting"); - break; - case 326: - sprintf(name, "GetVarConversionLocaleSetting"); - break; - case 327: - sprintf(name, "SetOaNoCache"); - break; - case 329: - sprintf(name, "VarCyMulI8"); - break; - case 330: - sprintf(name, "VarDateFromUdate"); - break; - case 331: - sprintf(name, "VarUdateFromDate"); - break; - case 332: - sprintf(name, "GetAltMonthNames"); - break; - case 333: - sprintf(name, "VarI8FromUI1"); - break; - case 334: - sprintf(name, "VarI8FromI2"); - break; - case 335: - sprintf(name, "VarI8FromR4"); - break; - case 336: - sprintf(name, "VarI8FromR8"); - break; - case 337: - sprintf(name, "VarI8FromCy"); - break; - case 338: - sprintf(name, "VarI8FromDate"); - break; - case 339: - sprintf(name, "VarI8FromStr"); - break; - case 340: - sprintf(name, "VarI8FromDisp"); - break; - case 341: - sprintf(name, "VarI8FromBool"); - break; - case 342: - sprintf(name, "VarI8FromI1"); - break; - case 343: - sprintf(name, "VarI8FromUI2"); - break; - case 344: - sprintf(name, "VarI8FromUI4"); - break; - case 345: - sprintf(name, "VarI8FromDec"); - break; - case 346: - sprintf(name, "VarI2FromI8"); - break; - case 347: - sprintf(name, "VarI2FromUI8"); - break; - case 348: - sprintf(name, "VarI4FromI8"); - break; - case 349: - sprintf(name, "VarI4FromUI8"); - break; - case 360: - sprintf(name, "VarR4FromI8"); - break; - case 361: - sprintf(name, "VarR4FromUI8"); - break; - case 362: - sprintf(name, "VarR8FromI8"); - break; - case 363: - sprintf(name, "VarR8FromUI8"); - break; - case 364: - sprintf(name, "VarDateFromI8"); - break; - case 365: - sprintf(name, "VarDateFromUI8"); - break; - case 366: - sprintf(name, "VarCyFromI8"); - break; - case 367: - sprintf(name, "VarCyFromUI8"); - break; - case 368: - sprintf(name, "VarBstrFromI8"); - break; - case 369: - sprintf(name, "VarBstrFromUI8"); - break; - case 370: - sprintf(name, "VarBoolFromI8"); - break; - case 371: - sprintf(name, "VarBoolFromUI8"); - break; - case 372: - sprintf(name, "VarUI1FromI8"); - break; - case 373: - sprintf(name, "VarUI1FromUI8"); - break; - case 374: - sprintf(name, "VarDecFromI8"); - break; - case 375: - sprintf(name, "VarDecFromUI8"); - break; - case 376: - sprintf(name, "VarI1FromI8"); - break; - case 377: - sprintf(name, "VarI1FromUI8"); - break; - case 378: - sprintf(name, "VarUI2FromI8"); - break; - case 379: - sprintf(name, "VarUI2FromUI8"); - break; - case 401: - sprintf(name, "OleLoadPictureEx"); - break; - case 402: - sprintf(name, "OleLoadPictureFileEx"); - break; - case 411: - sprintf(name, "SafeArrayCreateVector"); - break; - case 412: - sprintf(name, "SafeArrayCopyData"); - break; - case 413: - sprintf(name, "VectorFromBstr"); - break; - case 414: - sprintf(name, "BstrFromVector"); - break; - case 415: - sprintf(name, "OleIconToCursor"); - break; - case 416: - sprintf(name, "OleCreatePropertyFrameIndirect"); - break; - case 417: - sprintf(name, "OleCreatePropertyFrame"); - break; - case 418: - sprintf(name, "OleLoadPicture"); - break; - case 419: - sprintf(name, "OleCreatePictureIndirect"); - break; - case 420: - sprintf(name, "OleCreateFontIndirect"); - break; - case 421: - sprintf(name, "OleTranslateColor"); - break; - case 422: - sprintf(name, "OleLoadPictureFile"); - break; - case 423: - sprintf(name, "OleSavePictureFile"); - break; - case 424: - sprintf(name, "OleLoadPicturePath"); - break; - case 425: - sprintf(name, "VarUI4FromI8"); - break; - case 426: - sprintf(name, "VarUI4FromUI8"); - break; - case 427: - sprintf(name, "VarI8FromUI8"); - break; - case 428: - sprintf(name, "VarUI8FromI8"); - break; - case 429: - sprintf(name, "VarUI8FromUI1"); - break; - case 430: - sprintf(name, "VarUI8FromI2"); - break; - case 431: - sprintf(name, "VarUI8FromR4"); - break; - case 432: - sprintf(name, "VarUI8FromR8"); - break; - case 433: - sprintf(name, "VarUI8FromCy"); - break; - case 434: - sprintf(name, "VarUI8FromDate"); - break; - case 435: - sprintf(name, "VarUI8FromStr"); - break; - case 436: - sprintf(name, "VarUI8FromDisp"); - break; - case 437: - sprintf(name, "VarUI8FromBool"); - break; - case 438: - sprintf(name, "VarUI8FromI1"); - break; - case 439: - sprintf(name, "VarUI8FromUI2"); - break; - case 440: - sprintf(name, "VarUI8FromUI4"); - break; - case 441: - sprintf(name, "VarUI8FromDec"); - break; - case 442: - sprintf(name, "RegisterTypeLibForUser"); - break; - case 443: - sprintf(name, "UnRegisterTypeLibForUser"); - break; - default: - break; + switch (ord) + { + case 2: + sprintf(name, "SysAllocString"); + break; + case 3: + sprintf(name, "SysReAllocString"); + break; + case 4: + sprintf(name, "SysAllocStringLen"); + break; + case 5: + sprintf(name, "SysReAllocStringLen"); + break; + case 6: + sprintf(name, "SysFreeString"); + break; + case 7: + sprintf(name, "SysStringLen"); + break; + case 8: + sprintf(name, "VariantInit"); + break; + case 9: + sprintf(name, "VariantClear"); + break; + case 10: + sprintf(name, "VariantCopy"); + break; + case 11: + sprintf(name, "VariantCopyInd"); + break; + case 12: + sprintf(name, "VariantChangeType"); + break; + case 13: + sprintf(name, "VariantTimeToDosDateTime"); + break; + case 14: + sprintf(name, "DosDateTimeToVariantTime"); + break; + case 15: + sprintf(name, "SafeArrayCreate"); + break; + case 16: + sprintf(name, "SafeArrayDestroy"); + break; + case 17: + sprintf(name, "SafeArrayGetDim"); + break; + case 18: + sprintf(name, "SafeArrayGetElemsize"); + break; + case 19: + sprintf(name, "SafeArrayGetUBound"); + break; + case 20: + sprintf(name, "SafeArrayGetLBound"); + break; + case 21: + sprintf(name, "SafeArrayLock"); + break; + case 22: + sprintf(name, "SafeArrayUnlock"); + break; + case 23: + sprintf(name, "SafeArrayAccessData"); + break; + case 24: + sprintf(name, "SafeArrayUnaccessData"); + break; + case 25: + sprintf(name, "SafeArrayGetElement"); + break; + case 26: + sprintf(name, "SafeArrayPutElement"); + break; + case 27: + sprintf(name, "SafeArrayCopy"); + break; + case 28: + sprintf(name, "DispGetParam"); + break; + case 29: + sprintf(name, "DispGetIDsOfNames"); + break; + case 30: + sprintf(name, "DispInvoke"); + break; + case 31: + sprintf(name, "CreateDispTypeInfo"); + break; + case 32: + sprintf(name, "CreateStdDispatch"); + break; + case 33: + sprintf(name, "RegisterActiveObject"); + break; + case 34: + sprintf(name, "RevokeActiveObject"); + break; + case 35: + sprintf(name, "GetActiveObject"); + break; + case 36: + sprintf(name, "SafeArrayAllocDescriptor"); + break; + case 37: + sprintf(name, "SafeArrayAllocData"); + break; + case 38: + sprintf(name, "SafeArrayDestroyDescriptor"); + break; + case 39: + sprintf(name, "SafeArrayDestroyData"); + break; + case 40: + sprintf(name, "SafeArrayRedim"); + break; + case 41: + sprintf(name, "SafeArrayAllocDescriptorEx"); + break; + case 42: + sprintf(name, "SafeArrayCreateEx"); + break; + case 43: + sprintf(name, "SafeArrayCreateVectorEx"); + break; + case 44: + sprintf(name, "SafeArraySetRecordInfo"); + break; + case 45: + sprintf(name, "SafeArrayGetRecordInfo"); + break; + case 46: + sprintf(name, "VarParseNumFromStr"); + break; + case 47: + sprintf(name, "VarNumFromParseNum"); + break; + case 48: + sprintf(name, "VarI2FromUI1"); + break; + case 49: + sprintf(name, "VarI2FromI4"); + break; + case 50: + sprintf(name, "VarI2FromR4"); + break; + case 51: + sprintf(name, "VarI2FromR8"); + break; + case 52: + sprintf(name, "VarI2FromCy"); + break; + case 53: + sprintf(name, "VarI2FromDate"); + break; + case 54: + sprintf(name, "VarI2FromStr"); + break; + case 55: + sprintf(name, "VarI2FromDisp"); + break; + case 56: + sprintf(name, "VarI2FromBool"); + break; + case 57: + sprintf(name, "SafeArraySetIID"); + break; + case 58: + sprintf(name, "VarI4FromUI1"); + break; + case 59: + sprintf(name, "VarI4FromI2"); + break; + case 60: + sprintf(name, "VarI4FromR4"); + break; + case 61: + sprintf(name, "VarI4FromR8"); + break; + case 62: + sprintf(name, "VarI4FromCy"); + break; + case 63: + sprintf(name, "VarI4FromDate"); + break; + case 64: + sprintf(name, "VarI4FromStr"); + break; + case 65: + sprintf(name, "VarI4FromDisp"); + break; + case 66: + sprintf(name, "VarI4FromBool"); + break; + case 67: + sprintf(name, "SafeArrayGetIID"); + break; + case 68: + sprintf(name, "VarR4FromUI1"); + break; + case 69: + sprintf(name, "VarR4FromI2"); + break; + case 70: + sprintf(name, "VarR4FromI4"); + break; + case 71: + sprintf(name, "VarR4FromR8"); + break; + case 72: + sprintf(name, "VarR4FromCy"); + break; + case 73: + sprintf(name, "VarR4FromDate"); + break; + case 74: + sprintf(name, "VarR4FromStr"); + break; + case 75: + sprintf(name, "VarR4FromDisp"); + break; + case 76: + sprintf(name, "VarR4FromBool"); + break; + case 77: + sprintf(name, "SafeArrayGetVartype"); + break; + case 78: + sprintf(name, "VarR8FromUI1"); + break; + case 79: + sprintf(name, "VarR8FromI2"); + break; + case 80: + sprintf(name, "VarR8FromI4"); + break; + case 81: + sprintf(name, "VarR8FromR4"); + break; + case 82: + sprintf(name, "VarR8FromCy"); + break; + case 83: + sprintf(name, "VarR8FromDate"); + break; + case 84: + sprintf(name, "VarR8FromStr"); + break; + case 85: + sprintf(name, "VarR8FromDisp"); + break; + case 86: + sprintf(name, "VarR8FromBool"); + break; + case 87: + sprintf(name, "VarFormat"); + break; + case 88: + sprintf(name, "VarDateFromUI1"); + break; + case 89: + sprintf(name, "VarDateFromI2"); + break; + case 90: + sprintf(name, "VarDateFromI4"); + break; + case 91: + sprintf(name, "VarDateFromR4"); + break; + case 92: + sprintf(name, "VarDateFromR8"); + break; + case 93: + sprintf(name, "VarDateFromCy"); + break; + case 94: + sprintf(name, "VarDateFromStr"); + break; + case 95: + sprintf(name, "VarDateFromDisp"); + break; + case 96: + sprintf(name, "VarDateFromBool"); + break; + case 97: + sprintf(name, "VarFormatDateTime"); + break; + case 98: + sprintf(name, "VarCyFromUI1"); + break; + case 99: + sprintf(name, "VarCyFromI2"); + break; + case 100: + sprintf(name, "VarCyFromI4"); + break; + case 101: + sprintf(name, "VarCyFromR4"); + break; + case 102: + sprintf(name, "VarCyFromR8"); + break; + case 103: + sprintf(name, "VarCyFromDate"); + break; + case 104: + sprintf(name, "VarCyFromStr"); + break; + case 105: + sprintf(name, "VarCyFromDisp"); + break; + case 106: + sprintf(name, "VarCyFromBool"); + break; + case 107: + sprintf(name, "VarFormatNumber"); + break; + case 108: + sprintf(name, "VarBstrFromUI1"); + break; + case 109: + sprintf(name, "VarBstrFromI2"); + break; + case 110: + sprintf(name, "VarBstrFromI4"); + break; + case 111: + sprintf(name, "VarBstrFromR4"); + break; + case 112: + sprintf(name, "VarBstrFromR8"); + break; + case 113: + sprintf(name, "VarBstrFromCy"); + break; + case 114: + sprintf(name, "VarBstrFromDate"); + break; + case 115: + sprintf(name, "VarBstrFromDisp"); + break; + case 116: + sprintf(name, "VarBstrFromBool"); + break; + case 117: + sprintf(name, "VarFormatPercent"); + break; + case 118: + sprintf(name, "VarBoolFromUI1"); + break; + case 119: + sprintf(name, "VarBoolFromI2"); + break; + case 120: + sprintf(name, "VarBoolFromI4"); + break; + case 121: + sprintf(name, "VarBoolFromR4"); + break; + case 122: + sprintf(name, "VarBoolFromR8"); + break; + case 123: + sprintf(name, "VarBoolFromDate"); + break; + case 124: + sprintf(name, "VarBoolFromCy"); + break; + case 125: + sprintf(name, "VarBoolFromStr"); + break; + case 126: + sprintf(name, "VarBoolFromDisp"); + break; + case 127: + sprintf(name, "VarFormatCurrency"); + break; + case 128: + sprintf(name, "VarWeekdayName"); + break; + case 129: + sprintf(name, "VarMonthName"); + break; + case 130: + sprintf(name, "VarUI1FromI2"); + break; + case 131: + sprintf(name, "VarUI1FromI4"); + break; + case 132: + sprintf(name, "VarUI1FromR4"); + break; + case 133: + sprintf(name, "VarUI1FromR8"); + break; + case 134: + sprintf(name, "VarUI1FromCy"); + break; + case 135: + sprintf(name, "VarUI1FromDate"); + break; + case 136: + sprintf(name, "VarUI1FromStr"); + break; + case 137: + sprintf(name, "VarUI1FromDisp"); + break; + case 138: + sprintf(name, "VarUI1FromBool"); + break; + case 139: + sprintf(name, "VarFormatFromTokens"); + break; + case 140: + sprintf(name, "VarTokenizeFormatString"); + break; + case 141: + sprintf(name, "VarAdd"); + break; + case 142: + sprintf(name, "VarAnd"); + break; + case 143: + sprintf(name, "VarDiv"); + break; + case 144: + sprintf(name, "DllCanUnloadNow"); + break; + case 145: + sprintf(name, "DllGetClassObject"); + break; + case 146: + sprintf(name, "DispCallFunc"); + break; + case 147: + sprintf(name, "VariantChangeTypeEx"); + break; + case 148: + sprintf(name, "SafeArrayPtrOfIndex"); + break; + case 149: + sprintf(name, "SysStringByteLen"); + break; + case 150: + sprintf(name, "SysAllocStringByteLen"); + break; + case 151: + sprintf(name, "DllRegisterServer"); + break; + case 152: + sprintf(name, "VarEqv"); + break; + case 153: + sprintf(name, "VarIdiv"); + break; + case 154: + sprintf(name, "VarImp"); + break; + case 155: + sprintf(name, "VarMod"); + break; + case 156: + sprintf(name, "VarMul"); + break; + case 157: + sprintf(name, "VarOr"); + break; + case 158: + sprintf(name, "VarPow"); + break; + case 159: + sprintf(name, "VarSub"); + break; + case 160: + sprintf(name, "CreateTypeLib"); + break; + case 161: + sprintf(name, "LoadTypeLib"); + break; + case 162: + sprintf(name, "LoadRegTypeLib"); + break; + case 163: + sprintf(name, "RegisterTypeLib"); + break; + case 164: + sprintf(name, "QueryPathOfRegTypeLib"); + break; + case 165: + sprintf(name, "LHashValOfNameSys"); + break; + case 166: + sprintf(name, "LHashValOfNameSysA"); + break; + case 167: + sprintf(name, "VarXor"); + break; + case 168: + sprintf(name, "VarAbs"); + break; + case 169: + sprintf(name, "VarFix"); + break; + case 170: + sprintf(name, "OaBuildVersion"); + break; + case 171: + sprintf(name, "ClearCustData"); + break; + case 172: + sprintf(name, "VarInt"); + break; + case 173: + sprintf(name, "VarNeg"); + break; + case 174: + sprintf(name, "VarNot"); + break; + case 175: + sprintf(name, "VarRound"); + break; + case 176: + sprintf(name, "VarCmp"); + break; + case 177: + sprintf(name, "VarDecAdd"); + break; + case 178: + sprintf(name, "VarDecDiv"); + break; + case 179: + sprintf(name, "VarDecMul"); + break; + case 180: + sprintf(name, "CreateTypeLib2"); + break; + case 181: + sprintf(name, "VarDecSub"); + break; + case 182: + sprintf(name, "VarDecAbs"); + break; + case 183: + sprintf(name, "LoadTypeLibEx"); + break; + case 184: + sprintf(name, "SystemTimeToVariantTime"); + break; + case 185: + sprintf(name, "VariantTimeToSystemTime"); + break; + case 186: + sprintf(name, "UnRegisterTypeLib"); + break; + case 187: + sprintf(name, "VarDecFix"); + break; + case 188: + sprintf(name, "VarDecInt"); + break; + case 189: + sprintf(name, "VarDecNeg"); + break; + case 190: + sprintf(name, "VarDecFromUI1"); + break; + case 191: + sprintf(name, "VarDecFromI2"); + break; + case 192: + sprintf(name, "VarDecFromI4"); + break; + case 193: + sprintf(name, "VarDecFromR4"); + break; + case 194: + sprintf(name, "VarDecFromR8"); + break; + case 195: + sprintf(name, "VarDecFromDate"); + break; + case 196: + sprintf(name, "VarDecFromCy"); + break; + case 197: + sprintf(name, "VarDecFromStr"); + break; + case 198: + sprintf(name, "VarDecFromDisp"); + break; + case 199: + sprintf(name, "VarDecFromBool"); + break; + case 200: + sprintf(name, "GetErrorInfo"); + break; + case 201: + sprintf(name, "SetErrorInfo"); + break; + case 202: + sprintf(name, "CreateErrorInfo"); + break; + case 203: + sprintf(name, "VarDecRound"); + break; + case 204: + sprintf(name, "VarDecCmp"); + break; + case 205: + sprintf(name, "VarI2FromI1"); + break; + case 206: + sprintf(name, "VarI2FromUI2"); + break; + case 207: + sprintf(name, "VarI2FromUI4"); + break; + case 208: + sprintf(name, "VarI2FromDec"); + break; + case 209: + sprintf(name, "VarI4FromI1"); + break; + case 210: + sprintf(name, "VarI4FromUI2"); + break; + case 211: + sprintf(name, "VarI4FromUI4"); + break; + case 212: + sprintf(name, "VarI4FromDec"); + break; + case 213: + sprintf(name, "VarR4FromI1"); + break; + case 214: + sprintf(name, "VarR4FromUI2"); + break; + case 215: + sprintf(name, "VarR4FromUI4"); + break; + case 216: + sprintf(name, "VarR4FromDec"); + break; + case 217: + sprintf(name, "VarR8FromI1"); + break; + case 218: + sprintf(name, "VarR8FromUI2"); + break; + case 219: + sprintf(name, "VarR8FromUI4"); + break; + case 220: + sprintf(name, "VarR8FromDec"); + break; + case 221: + sprintf(name, "VarDateFromI1"); + break; + case 222: + sprintf(name, "VarDateFromUI2"); + break; + case 223: + sprintf(name, "VarDateFromUI4"); + break; + case 224: + sprintf(name, "VarDateFromDec"); + break; + case 225: + sprintf(name, "VarCyFromI1"); + break; + case 226: + sprintf(name, "VarCyFromUI2"); + break; + case 227: + sprintf(name, "VarCyFromUI4"); + break; + case 228: + sprintf(name, "VarCyFromDec"); + break; + case 229: + sprintf(name, "VarBstrFromI1"); + break; + case 230: + sprintf(name, "VarBstrFromUI2"); + break; + case 231: + sprintf(name, "VarBstrFromUI4"); + break; + case 232: + sprintf(name, "VarBstrFromDec"); + break; + case 233: + sprintf(name, "VarBoolFromI1"); + break; + case 234: + sprintf(name, "VarBoolFromUI2"); + break; + case 235: + sprintf(name, "VarBoolFromUI4"); + break; + case 236: + sprintf(name, "VarBoolFromDec"); + break; + case 237: + sprintf(name, "VarUI1FromI1"); + break; + case 238: + sprintf(name, "VarUI1FromUI2"); + break; + case 239: + sprintf(name, "VarUI1FromUI4"); + break; + case 240: + sprintf(name, "VarUI1FromDec"); + break; + case 241: + sprintf(name, "VarDecFromI1"); + break; + case 242: + sprintf(name, "VarDecFromUI2"); + break; + case 243: + sprintf(name, "VarDecFromUI4"); + break; + case 244: + sprintf(name, "VarI1FromUI1"); + break; + case 245: + sprintf(name, "VarI1FromI2"); + break; + case 246: + sprintf(name, "VarI1FromI4"); + break; + case 247: + sprintf(name, "VarI1FromR4"); + break; + case 248: + sprintf(name, "VarI1FromR8"); + break; + case 249: + sprintf(name, "VarI1FromDate"); + break; + case 250: + sprintf(name, "VarI1FromCy"); + break; + case 251: + sprintf(name, "VarI1FromStr"); + break; + case 252: + sprintf(name, "VarI1FromDisp"); + break; + case 253: + sprintf(name, "VarI1FromBool"); + break; + case 254: + sprintf(name, "VarI1FromUI2"); + break; + case 255: + sprintf(name, "VarI1FromUI4"); + break; + case 256: + sprintf(name, "VarI1FromDec"); + break; + case 257: + sprintf(name, "VarUI2FromUI1"); + break; + case 258: + sprintf(name, "VarUI2FromI2"); + break; + case 259: + sprintf(name, "VarUI2FromI4"); + break; + case 260: + sprintf(name, "VarUI2FromR4"); + break; + case 261: + sprintf(name, "VarUI2FromR8"); + break; + case 262: + sprintf(name, "VarUI2FromDate"); + break; + case 263: + sprintf(name, "VarUI2FromCy"); + break; + case 264: + sprintf(name, "VarUI2FromStr"); + break; + case 265: + sprintf(name, "VarUI2FromDisp"); + break; + case 266: + sprintf(name, "VarUI2FromBool"); + break; + case 267: + sprintf(name, "VarUI2FromI1"); + break; + case 268: + sprintf(name, "VarUI2FromUI4"); + break; + case 269: + sprintf(name, "VarUI2FromDec"); + break; + case 270: + sprintf(name, "VarUI4FromUI1"); + break; + case 271: + sprintf(name, "VarUI4FromI2"); + break; + case 272: + sprintf(name, "VarUI4FromI4"); + break; + case 273: + sprintf(name, "VarUI4FromR4"); + break; + case 274: + sprintf(name, "VarUI4FromR8"); + break; + case 275: + sprintf(name, "VarUI4FromDate"); + break; + case 276: + sprintf(name, "VarUI4FromCy"); + break; + case 277: + sprintf(name, "VarUI4FromStr"); + break; + case 278: + sprintf(name, "VarUI4FromDisp"); + break; + case 279: + sprintf(name, "VarUI4FromBool"); + break; + case 280: + sprintf(name, "VarUI4FromI1"); + break; + case 281: + sprintf(name, "VarUI4FromUI2"); + break; + case 282: + sprintf(name, "VarUI4FromDec"); + break; + case 283: + sprintf(name, "BSTR_UserSize"); + break; + case 284: + sprintf(name, "BSTR_UserMarshal"); + break; + case 285: + sprintf(name, "BSTR_UserUnmarshal"); + break; + case 286: + sprintf(name, "BSTR_UserFree"); + break; + case 287: + sprintf(name, "VARIANT_UserSize"); + break; + case 288: + sprintf(name, "VARIANT_UserMarshal"); + break; + case 289: + sprintf(name, "VARIANT_UserUnmarshal"); + break; + case 290: + sprintf(name, "VARIANT_UserFree"); + break; + case 291: + sprintf(name, "LPSAFEARRAY_UserSize"); + break; + case 292: + sprintf(name, "LPSAFEARRAY_UserMarshal"); + break; + case 293: + sprintf(name, "LPSAFEARRAY_UserUnmarshal"); + break; + case 294: + sprintf(name, "LPSAFEARRAY_UserFree"); + break; + case 295: + sprintf(name, "LPSAFEARRAY_Size"); + break; + case 296: + sprintf(name, "LPSAFEARRAY_Marshal"); + break; + case 297: + sprintf(name, "LPSAFEARRAY_Unmarshal"); + break; + case 298: + sprintf(name, "VarDecCmpR8"); + break; + case 299: + sprintf(name, "VarCyAdd"); + break; + case 300: + sprintf(name, "DllUnregisterServer"); + break; + case 301: + sprintf(name, "OACreateTypeLib2"); + break; + case 303: + sprintf(name, "VarCyMul"); + break; + case 304: + sprintf(name, "VarCyMulI4"); + break; + case 305: + sprintf(name, "VarCySub"); + break; + case 306: + sprintf(name, "VarCyAbs"); + break; + case 307: + sprintf(name, "VarCyFix"); + break; + case 308: + sprintf(name, "VarCyInt"); + break; + case 309: + sprintf(name, "VarCyNeg"); + break; + case 310: + sprintf(name, "VarCyRound"); + break; + case 311: + sprintf(name, "VarCyCmp"); + break; + case 312: + sprintf(name, "VarCyCmpR8"); + break; + case 313: + sprintf(name, "VarBstrCat"); + break; + case 314: + sprintf(name, "VarBstrCmp"); + break; + case 315: + sprintf(name, "VarR8Pow"); + break; + case 316: + sprintf(name, "VarR4CmpR8"); + break; + case 317: + sprintf(name, "VarR8Round"); + break; + case 318: + sprintf(name, "VarCat"); + break; + case 319: + sprintf(name, "VarDateFromUdateEx"); + break; + case 322: + sprintf(name, "GetRecordInfoFromGuids"); + break; + case 323: + sprintf(name, "GetRecordInfoFromTypeInfo"); + break; + case 325: + sprintf(name, "SetVarConversionLocaleSetting"); + break; + case 326: + sprintf(name, "GetVarConversionLocaleSetting"); + break; + case 327: + sprintf(name, "SetOaNoCache"); + break; + case 329: + sprintf(name, "VarCyMulI8"); + break; + case 330: + sprintf(name, "VarDateFromUdate"); + break; + case 331: + sprintf(name, "VarUdateFromDate"); + break; + case 332: + sprintf(name, "GetAltMonthNames"); + break; + case 333: + sprintf(name, "VarI8FromUI1"); + break; + case 334: + sprintf(name, "VarI8FromI2"); + break; + case 335: + sprintf(name, "VarI8FromR4"); + break; + case 336: + sprintf(name, "VarI8FromR8"); + break; + case 337: + sprintf(name, "VarI8FromCy"); + break; + case 338: + sprintf(name, "VarI8FromDate"); + break; + case 339: + sprintf(name, "VarI8FromStr"); + break; + case 340: + sprintf(name, "VarI8FromDisp"); + break; + case 341: + sprintf(name, "VarI8FromBool"); + break; + case 342: + sprintf(name, "VarI8FromI1"); + break; + case 343: + sprintf(name, "VarI8FromUI2"); + break; + case 344: + sprintf(name, "VarI8FromUI4"); + break; + case 345: + sprintf(name, "VarI8FromDec"); + break; + case 346: + sprintf(name, "VarI2FromI8"); + break; + case 347: + sprintf(name, "VarI2FromUI8"); + break; + case 348: + sprintf(name, "VarI4FromI8"); + break; + case 349: + sprintf(name, "VarI4FromUI8"); + break; + case 360: + sprintf(name, "VarR4FromI8"); + break; + case 361: + sprintf(name, "VarR4FromUI8"); + break; + case 362: + sprintf(name, "VarR8FromI8"); + break; + case 363: + sprintf(name, "VarR8FromUI8"); + break; + case 364: + sprintf(name, "VarDateFromI8"); + break; + case 365: + sprintf(name, "VarDateFromUI8"); + break; + case 366: + sprintf(name, "VarCyFromI8"); + break; + case 367: + sprintf(name, "VarCyFromUI8"); + break; + case 368: + sprintf(name, "VarBstrFromI8"); + break; + case 369: + sprintf(name, "VarBstrFromUI8"); + break; + case 370: + sprintf(name, "VarBoolFromI8"); + break; + case 371: + sprintf(name, "VarBoolFromUI8"); + break; + case 372: + sprintf(name, "VarUI1FromI8"); + break; + case 373: + sprintf(name, "VarUI1FromUI8"); + break; + case 374: + sprintf(name, "VarDecFromI8"); + break; + case 375: + sprintf(name, "VarDecFromUI8"); + break; + case 376: + sprintf(name, "VarI1FromI8"); + break; + case 377: + sprintf(name, "VarI1FromUI8"); + break; + case 378: + sprintf(name, "VarUI2FromI8"); + break; + case 379: + sprintf(name, "VarUI2FromUI8"); + break; + case 401: + sprintf(name, "OleLoadPictureEx"); + break; + case 402: + sprintf(name, "OleLoadPictureFileEx"); + break; + case 411: + sprintf(name, "SafeArrayCreateVector"); + break; + case 412: + sprintf(name, "SafeArrayCopyData"); + break; + case 413: + sprintf(name, "VectorFromBstr"); + break; + case 414: + sprintf(name, "BstrFromVector"); + break; + case 415: + sprintf(name, "OleIconToCursor"); + break; + case 416: + sprintf(name, "OleCreatePropertyFrameIndirect"); + break; + case 417: + sprintf(name, "OleCreatePropertyFrame"); + break; + case 418: + sprintf(name, "OleLoadPicture"); + break; + case 419: + sprintf(name, "OleCreatePictureIndirect"); + break; + case 420: + sprintf(name, "OleCreateFontIndirect"); + break; + case 421: + sprintf(name, "OleTranslateColor"); + break; + case 422: + sprintf(name, "OleLoadPictureFile"); + break; + case 423: + sprintf(name, "OleSavePictureFile"); + break; + case 424: + sprintf(name, "OleLoadPicturePath"); + break; + case 425: + sprintf(name, "VarUI4FromI8"); + break; + case 426: + sprintf(name, "VarUI4FromUI8"); + break; + case 427: + sprintf(name, "VarI8FromUI8"); + break; + case 428: + sprintf(name, "VarUI8FromI8"); + break; + case 429: + sprintf(name, "VarUI8FromUI1"); + break; + case 430: + sprintf(name, "VarUI8FromI2"); + break; + case 431: + sprintf(name, "VarUI8FromR4"); + break; + case 432: + sprintf(name, "VarUI8FromR8"); + break; + case 433: + sprintf(name, "VarUI8FromCy"); + break; + case 434: + sprintf(name, "VarUI8FromDate"); + break; + case 435: + sprintf(name, "VarUI8FromStr"); + break; + case 436: + sprintf(name, "VarUI8FromDisp"); + break; + case 437: + sprintf(name, "VarUI8FromBool"); + break; + case 438: + sprintf(name, "VarUI8FromI1"); + break; + case 439: + sprintf(name, "VarUI8FromUI2"); + break; + case 440: + sprintf(name, "VarUI8FromUI4"); + break; + case 441: + sprintf(name, "VarUI8FromDec"); + break; + case 442: + sprintf(name, "RegisterTypeLibForUser"); + break; + case 443: + sprintf(name, "UnRegisterTypeLibForUser"); + break; + default: + break; } } diff --git a/libyara/modules/tests/tests.c b/libyara/modules/tests/tests.c index 70c816dee2..71a94ce397 100644 --- a/libyara/modules/tests/tests.c +++ b/libyara/modules/tests/tests.c @@ -85,10 +85,7 @@ define_function(empty) define_function(match) { return_integer( - yr_re_match( - scan_context(), - regexp_argument(1), - string_argument(2))); + yr_re_match(scan_context(), regexp_argument(1), string_argument(2))); } @@ -98,50 +95,56 @@ define_function(foobar) switch (arg) { - case 1: - return_string("foo"); - break; - case 2: - return_string("bar"); - break; + case 1: + return_string("foo"); + break; + case 2: + return_string("bar"); + break; } return_string("oops") } -begin_declarations; +begin_declarations + ; - begin_struct("constants"); + begin_struct("constants") + ; declare_integer("one"); declare_integer("two"); declare_string("foo"); declare_string("empty"); end_struct("constants"); - begin_struct("undefined"); + begin_struct("undefined") + ; declare_integer("i"); declare_float("f"); end_struct("undefined"); declare_string("module_data") - declare_integer_array("integer_array"); + declare_integer_array("integer_array"); declare_string_array("string_array"); declare_integer_dictionary("integer_dict"); declare_string_dictionary("string_dict"); - begin_struct_array("struct_array"); + begin_struct_array("struct_array") + ; declare_integer("i"); declare_string("s"); end_struct_array("struct_array"); - begin_struct_dictionary("struct_dict"); + begin_struct_dictionary("struct_dict") + ; declare_integer("i"); declare_string("s"); end_struct_dictionary("struct_dict"); - begin_struct_dictionary("empty_struct_dict"); + begin_struct_dictionary("empty_struct_dict") + ; declare_integer("unused"); end_struct_dictionary("empty_struct_dict"); @@ -157,15 +160,13 @@ begin_declarations; end_declarations; -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { return ERROR_SUCCESS; } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { return ERROR_SUCCESS; } @@ -200,7 +201,8 @@ int module_load( set_string("foo", module_object, "struct_dict[%s].s", "foo"); set_integer(1, module_object, "struct_dict[%s].i", "foo"); - if (module_data_size > 0 && module_data != NULL) { + if (module_data_size > 0 && module_data != NULL) + { set_sized_string( (const char*) module_data, module_data_size, @@ -212,8 +214,7 @@ int module_load( } -int module_unload( - YR_OBJECT* module_object) +int module_unload(YR_OBJECT* module_object) { // Fail if module_unload is called twice with the same module_object if (module_object->data == (void*) 0xFABADA) diff --git a/libyara/modules/time/time.c b/libyara/modules/time/time.c index 94180abec7..751461755e 100644 --- a/libyara/modules/time/time.c +++ b/libyara/modules/time/time.c @@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include - #include #define MODULE_NAME time @@ -43,22 +42,21 @@ define_function(now) } -begin_declarations; +begin_declarations + ; declare_function("now", "", "i", now); end_declarations; -int module_initialize( - YR_MODULE* module) +int module_initialize(YR_MODULE* module) { return ERROR_SUCCESS; } -int module_finalize( - YR_MODULE* module) +int module_finalize(YR_MODULE* module) { return ERROR_SUCCESS; } @@ -74,8 +72,7 @@ int module_load( } -int module_unload( - YR_OBJECT* module_object) +int module_unload(YR_OBJECT* module_object) { return ERROR_SUCCESS; } diff --git a/libyara/notebook.c b/libyara/notebook.c index f12324835d..abd9a2608f 100644 --- a/libyara/notebook.c +++ b/libyara/notebook.c @@ -30,7 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include - #include #include #include @@ -72,12 +71,9 @@ struct YR_NOTEBOOK_PAGE }; - // Creates a new notebook. The notebook initially has a single page of the // specified size, but more pages are created if needed. -int yr_notebook_create( - size_t page_size, - YR_NOTEBOOK** pool) +int yr_notebook_create(size_t page_size, YR_NOTEBOOK** pool) { YR_NOTEBOOK* new_notebook = yr_malloc(sizeof(YR_NOTEBOOK)); @@ -104,8 +100,7 @@ int yr_notebook_create( // Destroys a notebook and frees all the notebook's pages. -int yr_notebook_destroy( - YR_NOTEBOOK* pool) +int yr_notebook_destroy(YR_NOTEBOOK* pool) { YR_NOTEBOOK_PAGE* page = pool->page_list_head; @@ -122,9 +117,7 @@ int yr_notebook_destroy( } -void* yr_notebook_alloc( - YR_NOTEBOOK* notebook, - size_t size) +void* yr_notebook_alloc(YR_NOTEBOOK* notebook, size_t size) { // The requested memory size can't be larger than a notebook's page. assert(size <= notebook->page_size); @@ -144,10 +137,10 @@ void* yr_notebook_alloc( notebook->page_list_head = new_page; } - void *ptr = notebook->page_list_head->data + notebook->page_list_head->used; + void* ptr = notebook->page_list_head->data + notebook->page_list_head->used; - // In ARM make sure the alignment of the returned buffer is 4 bytes. - #if defined(__arm__) +// In ARM make sure the alignment of the returned buffer is 4 bytes. +#if defined(__arm__) uintptr_t misalignment = (uintptr_t) ptr & 3; if (misalignment) @@ -155,7 +148,7 @@ void* yr_notebook_alloc( size += 4 - misalignment; ptr += 4 - misalignment; } - #endif +#endif notebook->page_list_head->used += size; diff --git a/libyara/object.c b/libyara/object.c index 94910e2acd..6e17a1ba9b 100644 --- a/libyara/object.c +++ b/libyara/object.c @@ -30,17 +30,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include #include #include -#include - +#include +#include #include #include -#include #include -#include #include @@ -58,29 +57,29 @@ int yr_object_create( switch (type) { - case OBJECT_TYPE_STRUCTURE: - object_size = sizeof(YR_OBJECT_STRUCTURE); - break; - case OBJECT_TYPE_ARRAY: - object_size = sizeof(YR_OBJECT_ARRAY); - break; - case OBJECT_TYPE_DICTIONARY: - object_size = sizeof(YR_OBJECT_DICTIONARY); - break; - case OBJECT_TYPE_INTEGER: - object_size = sizeof(YR_OBJECT); - break; - case OBJECT_TYPE_FLOAT: - object_size = sizeof(YR_OBJECT); - break; - case OBJECT_TYPE_STRING: - object_size = sizeof(YR_OBJECT); - break; - case OBJECT_TYPE_FUNCTION: - object_size = sizeof(YR_OBJECT_FUNCTION); - break; - default: - assert(false); + case OBJECT_TYPE_STRUCTURE: + object_size = sizeof(YR_OBJECT_STRUCTURE); + break; + case OBJECT_TYPE_ARRAY: + object_size = sizeof(YR_OBJECT_ARRAY); + break; + case OBJECT_TYPE_DICTIONARY: + object_size = sizeof(YR_OBJECT_DICTIONARY); + break; + case OBJECT_TYPE_INTEGER: + object_size = sizeof(YR_OBJECT); + break; + case OBJECT_TYPE_FLOAT: + object_size = sizeof(YR_OBJECT); + break; + case OBJECT_TYPE_STRING: + object_size = sizeof(YR_OBJECT); + break; + case OBJECT_TYPE_FUNCTION: + object_size = sizeof(YR_OBJECT_FUNCTION); + break; + default: + assert(false); } obj = (YR_OBJECT*) yr_malloc(object_size); @@ -93,36 +92,36 @@ int yr_object_create( obj->parent = parent; obj->data = NULL; - switch(type) + switch (type) { - case OBJECT_TYPE_INTEGER: - obj->value.i = YR_UNDEFINED; - break; - case OBJECT_TYPE_FLOAT: - obj->value.d = NAN; - break; - case OBJECT_TYPE_STRING: - obj->value.ss = NULL; - break; - case OBJECT_TYPE_STRUCTURE: - object_as_structure(obj)->members = NULL; - break; - case OBJECT_TYPE_ARRAY: - object_as_array(obj)->items = NULL; - object_as_array(obj)->prototype_item = NULL; - break; - case OBJECT_TYPE_DICTIONARY: - object_as_dictionary(obj)->items = NULL; - object_as_dictionary(obj)->prototype_item = NULL; - break; - case OBJECT_TYPE_FUNCTION: - object_as_function(obj)->return_obj = NULL; - for (i = 0; i < YR_MAX_OVERLOADED_FUNCTIONS; i++) - { - object_as_function(obj)->prototypes[i].arguments_fmt = NULL; - object_as_function(obj)->prototypes[i].code = NULL; - } - break; + case OBJECT_TYPE_INTEGER: + obj->value.i = YR_UNDEFINED; + break; + case OBJECT_TYPE_FLOAT: + obj->value.d = NAN; + break; + case OBJECT_TYPE_STRING: + obj->value.ss = NULL; + break; + case OBJECT_TYPE_STRUCTURE: + object_as_structure(obj)->members = NULL; + break; + case OBJECT_TYPE_ARRAY: + object_as_array(obj)->items = NULL; + object_as_array(obj)->prototype_item = NULL; + break; + case OBJECT_TYPE_DICTIONARY: + object_as_dictionary(obj)->items = NULL; + object_as_dictionary(obj)->prototype_item = NULL; + break; + case OBJECT_TYPE_FUNCTION: + object_as_function(obj)->return_obj = NULL; + for (i = 0; i < YR_MAX_OVERLOADED_FUNCTIONS; i++) + { + object_as_function(obj)->prototypes[i].arguments_fmt = NULL; + object_as_function(obj)->prototypes[i].code = NULL; + } + break; } if (obj->identifier == NULL) @@ -133,36 +132,35 @@ int yr_object_create( if (parent != NULL) { - assert(parent->type == OBJECT_TYPE_STRUCTURE || - parent->type == OBJECT_TYPE_ARRAY || - parent->type == OBJECT_TYPE_DICTIONARY || - parent->type == OBJECT_TYPE_FUNCTION); + assert( + parent->type == OBJECT_TYPE_STRUCTURE || + parent->type == OBJECT_TYPE_ARRAY || + parent->type == OBJECT_TYPE_DICTIONARY || + parent->type == OBJECT_TYPE_FUNCTION); // Objects with a parent take the canary from it. obj->canary = parent->canary; - switch(parent->type) + switch (parent->type) { - case OBJECT_TYPE_STRUCTURE: - FAIL_ON_ERROR_WITH_CLEANUP( - yr_object_structure_set_member(parent, obj), - { - yr_free((void*) obj->identifier); - yr_free(obj); - }); - break; + case OBJECT_TYPE_STRUCTURE: + FAIL_ON_ERROR_WITH_CLEANUP(yr_object_structure_set_member(parent, obj), { + yr_free((void*) obj->identifier); + yr_free(obj); + }); + break; - case OBJECT_TYPE_ARRAY: - object_as_array(parent)->prototype_item = obj; - break; + case OBJECT_TYPE_ARRAY: + object_as_array(parent)->prototype_item = obj; + break; - case OBJECT_TYPE_DICTIONARY: - object_as_dictionary(parent)->prototype_item = obj; - break; + case OBJECT_TYPE_DICTIONARY: + object_as_dictionary(parent)->prototype_item = obj; + break; - case OBJECT_TYPE_FUNCTION: - object_as_function(parent)->return_obj = obj; - break; + case OBJECT_TYPE_FUNCTION: + object_as_function(parent)->return_obj = obj; + break; } } @@ -173,9 +171,7 @@ int yr_object_create( } -void yr_object_set_canary( - YR_OBJECT* object, - int canary) +void yr_object_set_canary(YR_OBJECT* object, int canary) { object->canary = canary; } @@ -201,17 +197,17 @@ int yr_object_function_create( switch (*return_fmt) { - case 'i': - return_type = OBJECT_TYPE_INTEGER; - break; - case 's': - return_type = OBJECT_TYPE_STRING; - break; - case 'f': - return_type = OBJECT_TYPE_FLOAT; - break; - default: - return ERROR_INVALID_FORMAT; + case 'i': + return_type = OBJECT_TYPE_INTEGER; + break; + case 's': + return_type = OBJECT_TYPE_STRING; + break; + case 'f': + return_type = OBJECT_TYPE_FLOAT; + break; + default: + return ERROR_INVALID_FORMAT; } // Try to find if the structure already has a function @@ -222,21 +218,13 @@ int yr_object_function_create( if (f != NULL && return_type != f->return_obj->type) return ERROR_WRONG_RETURN_TYPE; - if (f == NULL) // Function doesn't exist yet + if (f == NULL) // Function doesn't exist yet { FAIL_ON_ERROR( - yr_object_create( - OBJECT_TYPE_FUNCTION, - identifier, - parent, - &o)); + yr_object_create(OBJECT_TYPE_FUNCTION, identifier, parent, &o)); FAIL_ON_ERROR_WITH_CLEANUP( - yr_object_create( - return_type, - "result", - o, - &return_obj), + yr_object_create(return_type, "result", o, &return_obj), yr_object_destroy(o)); f = object_as_function(o); @@ -268,50 +256,46 @@ int yr_object_from_external_variable( int result; uint8_t obj_type = 0; - switch(external->type) + switch (external->type) { + case EXTERNAL_VARIABLE_TYPE_INTEGER: + case EXTERNAL_VARIABLE_TYPE_BOOLEAN: + obj_type = OBJECT_TYPE_INTEGER; + break; + + case EXTERNAL_VARIABLE_TYPE_FLOAT: + obj_type = OBJECT_TYPE_FLOAT; + break; + + case EXTERNAL_VARIABLE_TYPE_STRING: + case EXTERNAL_VARIABLE_TYPE_MALLOC_STRING: + obj_type = OBJECT_TYPE_STRING; + break; + + default: + assert(false); + } + + result = yr_object_create(obj_type, external->identifier, NULL, &obj); + + if (result == ERROR_SUCCESS) + { + switch (external->type) + { case EXTERNAL_VARIABLE_TYPE_INTEGER: case EXTERNAL_VARIABLE_TYPE_BOOLEAN: - obj_type = OBJECT_TYPE_INTEGER; + result = yr_object_set_integer(external->value.i, obj, NULL); break; case EXTERNAL_VARIABLE_TYPE_FLOAT: - obj_type = OBJECT_TYPE_FLOAT; + result = yr_object_set_float(external->value.f, obj, NULL); break; case EXTERNAL_VARIABLE_TYPE_STRING: case EXTERNAL_VARIABLE_TYPE_MALLOC_STRING: - obj_type = OBJECT_TYPE_STRING; + result = yr_object_set_string( + external->value.s, strlen(external->value.s), obj, NULL); break; - - default: - assert(false); - } - - result = yr_object_create( - obj_type, - external->identifier, - NULL, - &obj); - - if (result == ERROR_SUCCESS) - { - switch(external->type) - { - case EXTERNAL_VARIABLE_TYPE_INTEGER: - case EXTERNAL_VARIABLE_TYPE_BOOLEAN: - result = yr_object_set_integer(external->value.i, obj, NULL); - break; - - case EXTERNAL_VARIABLE_TYPE_FLOAT: - result = yr_object_set_float(external->value.f, obj, NULL); - break; - - case EXTERNAL_VARIABLE_TYPE_STRING: - case EXTERNAL_VARIABLE_TYPE_MALLOC_STRING: - result = yr_object_set_string( - external->value.s, strlen(external->value.s), obj, NULL); - break; } if (result == ERROR_SUCCESS) @@ -328,8 +312,7 @@ int yr_object_from_external_variable( } -void yr_object_destroy( - YR_OBJECT* object) +void yr_object_destroy(YR_OBJECT* object) { YR_STRUCTURE_MEMBER* member; YR_STRUCTURE_MEMBER* next_member; @@ -341,65 +324,65 @@ void yr_object_destroy( if (object == NULL) return; - switch(object->type) + switch (object->type) { - case OBJECT_TYPE_STRUCTURE: - member = object_as_structure(object)->members; + case OBJECT_TYPE_STRUCTURE: + member = object_as_structure(object)->members; - while (member != NULL) - { - next_member = member->next; - yr_object_destroy(member->object); - yr_free(member); - member = next_member; - } - break; + while (member != NULL) + { + next_member = member->next; + yr_object_destroy(member->object); + yr_free(member); + member = next_member; + } + break; - case OBJECT_TYPE_STRING: - if (object->value.ss != NULL) - yr_free(object->value.ss); - break; + case OBJECT_TYPE_STRING: + if (object->value.ss != NULL) + yr_free(object->value.ss); + break; - case OBJECT_TYPE_ARRAY: - if (object_as_array(object)->prototype_item != NULL) - yr_object_destroy(object_as_array(object)->prototype_item); + case OBJECT_TYPE_ARRAY: + if (object_as_array(object)->prototype_item != NULL) + yr_object_destroy(object_as_array(object)->prototype_item); - array_items = object_as_array(object)->items; + array_items = object_as_array(object)->items; - if (array_items != NULL) - { - for (i = 0; i < array_items->length; i++) - if (array_items->objects[i] != NULL) - yr_object_destroy(array_items->objects[i]); - } + if (array_items != NULL) + { + for (i = 0; i < array_items->length; i++) + if (array_items->objects[i] != NULL) + yr_object_destroy(array_items->objects[i]); + } - yr_free(array_items); - break; + yr_free(array_items); + break; - case OBJECT_TYPE_DICTIONARY: - if (object_as_dictionary(object)->prototype_item != NULL) - yr_object_destroy(object_as_dictionary(object)->prototype_item); + case OBJECT_TYPE_DICTIONARY: + if (object_as_dictionary(object)->prototype_item != NULL) + yr_object_destroy(object_as_dictionary(object)->prototype_item); - dict_items = object_as_dictionary(object)->items; + dict_items = object_as_dictionary(object)->items; - if (dict_items != NULL) + if (dict_items != NULL) + { + for (i = 0; i < dict_items->used; i++) { - for (i = 0; i < dict_items->used; i++) - { - if (dict_items->objects[i].key != NULL) - yr_free(dict_items->objects[i].key); + if (dict_items->objects[i].key != NULL) + yr_free(dict_items->objects[i].key); - if (dict_items->objects[i].obj != NULL) - yr_object_destroy(dict_items->objects[i].obj); - } + if (dict_items->objects[i].obj != NULL) + yr_object_destroy(dict_items->objects[i].obj); } + } - yr_free(dict_items); - break; + yr_free(dict_items); + break; - case OBJECT_TYPE_FUNCTION: - yr_object_destroy(object_as_function(object)->return_obj); - break; + case OBJECT_TYPE_FUNCTION: + yr_object_destroy(object_as_function(object)->return_obj); + break; } yr_free((void*) object->identifier); @@ -407,9 +390,7 @@ void yr_object_destroy( } -YR_OBJECT* yr_object_lookup_field( - YR_OBJECT* object, - const char* field_name) +YR_OBJECT* yr_object_lookup_field(YR_OBJECT* object, const char* field_name) { YR_STRUCTURE_MEMBER* member; @@ -473,17 +454,17 @@ static YR_OBJECT* _yr_object_lookup( { p++; - switch(*p++) + switch (*p++) { - case 'i': - index = va_arg(args, int); - break; - case 's': - key = va_arg(args, const char*); - break; - - default: - return NULL; + case 'i': + index = va_arg(args, int); + break; + case 's': + key = va_arg(args, const char*); + break; + + default: + return NULL; } } else if (*p >= '0' && *p <= '9') @@ -493,13 +474,12 @@ static YR_OBJECT* _yr_object_lookup( else if (*p == '"') { i = 0; - p++; // skip the opening quotation mark + p++; // skip the opening quotation mark - while (*p != '"' && *p != '\0' && i < sizeof(str) - 1) - str[i++] = *p++; + while (*p != '"' && *p != '\0' && i < sizeof(str) - 1) str[i++] = *p++; str[i] = '\0'; - p++; // skip the closing quotation mark + p++; // skip the closing quotation mark key = str; } else @@ -511,17 +491,17 @@ static YR_OBJECT* _yr_object_lookup( p++; assert(*p == '.' || *p == '\0'); - switch(obj->type) + switch (obj->type) { - case OBJECT_TYPE_ARRAY: - assert(index != -1); - obj = yr_object_array_get_item(obj, flags, index); - break; + case OBJECT_TYPE_ARRAY: + assert(index != -1); + obj = yr_object_array_get_item(obj, flags, index); + break; - case OBJECT_TYPE_DICTIONARY: - assert(key != NULL); - obj = yr_object_dict_get_item(obj, flags, key); - break; + case OBJECT_TYPE_DICTIONARY: + assert(key != NULL); + obj = yr_object_dict_get_item(obj, flags, key); + break; } } @@ -551,13 +531,10 @@ YR_OBJECT* yr_object_lookup( va_end(args); return result; - } -int yr_object_copy( - YR_OBJECT* object, - YR_OBJECT** object_copy) +int yr_object_copy(YR_OBJECT* object, YR_OBJECT** object_copy) { YR_OBJECT* copy; YR_OBJECT* o; @@ -568,92 +545,87 @@ int yr_object_copy( *object_copy = NULL; - FAIL_ON_ERROR(yr_object_create( - object->type, - object->identifier, - NULL, - ©)); + FAIL_ON_ERROR( + yr_object_create(object->type, object->identifier, NULL, ©)); copy->canary = object->canary; - switch(object->type) + switch (object->type) { - case OBJECT_TYPE_INTEGER: - copy->value.i = object->value.i; - break; + case OBJECT_TYPE_INTEGER: + copy->value.i = object->value.i; + break; - case OBJECT_TYPE_FLOAT: - copy->value.d = object->value.d; - break; + case OBJECT_TYPE_FLOAT: + copy->value.d = object->value.d; + break; - case OBJECT_TYPE_STRING: + case OBJECT_TYPE_STRING: - if (object->value.ss != NULL) - copy->value.ss = ss_dup(object->value.ss); - else - copy->value.ss = NULL; + if (object->value.ss != NULL) + copy->value.ss = ss_dup(object->value.ss); + else + copy->value.ss = NULL; - break; + break; - case OBJECT_TYPE_FUNCTION: + case OBJECT_TYPE_FUNCTION: - FAIL_ON_ERROR_WITH_CLEANUP( - yr_object_copy( - object_as_function(object)->return_obj, - &object_as_function(copy)->return_obj), - // cleanup - yr_object_destroy(copy)); + FAIL_ON_ERROR_WITH_CLEANUP( + yr_object_copy( + object_as_function(object)->return_obj, + &object_as_function(copy)->return_obj), + // cleanup + yr_object_destroy(copy)); - for (i = 0; i < YR_MAX_OVERLOADED_FUNCTIONS; i++) - object_as_function(copy)->prototypes[i] = \ - object_as_function(object)->prototypes[i]; + for (i = 0; i < YR_MAX_OVERLOADED_FUNCTIONS; i++) + object_as_function(copy)->prototypes[i] = + object_as_function(object)->prototypes[i]; - break; + break; - case OBJECT_TYPE_STRUCTURE: + case OBJECT_TYPE_STRUCTURE: - structure_member = object_as_structure(object)->members; + structure_member = object_as_structure(object)->members; - while (structure_member != NULL) - { - FAIL_ON_ERROR_WITH_CLEANUP( - yr_object_copy(structure_member->object, &o), - yr_object_destroy(copy)); + while (structure_member != NULL) + { + FAIL_ON_ERROR_WITH_CLEANUP( + yr_object_copy(structure_member->object, &o), + yr_object_destroy(copy)); - FAIL_ON_ERROR_WITH_CLEANUP( - yr_object_structure_set_member(copy, o), - // cleanup - yr_free(o); - yr_object_destroy(copy)); + FAIL_ON_ERROR_WITH_CLEANUP(yr_object_structure_set_member(copy, o), + // cleanup + yr_free(o); + yr_object_destroy(copy)); - structure_member = structure_member->next; - } + structure_member = structure_member->next; + } - break; + break; - case OBJECT_TYPE_ARRAY: + case OBJECT_TYPE_ARRAY: - FAIL_ON_ERROR_WITH_CLEANUP( - yr_object_copy(object_as_array(object)->prototype_item, &o), - yr_object_destroy(copy)); - - object_as_array(copy)->prototype_item = o; + FAIL_ON_ERROR_WITH_CLEANUP( + yr_object_copy(object_as_array(object)->prototype_item, &o), + yr_object_destroy(copy)); - break; + object_as_array(copy)->prototype_item = o; - case OBJECT_TYPE_DICTIONARY: + break; - FAIL_ON_ERROR_WITH_CLEANUP( - yr_object_copy(object_as_dictionary(object)->prototype_item, &o), - yr_object_destroy(copy)); + case OBJECT_TYPE_DICTIONARY: - object_as_dictionary(copy)->prototype_item = o; + FAIL_ON_ERROR_WITH_CLEANUP( + yr_object_copy(object_as_dictionary(object)->prototype_item, &o), + yr_object_destroy(copy)); - break; + object_as_dictionary(copy)->prototype_item = o; - default: - assert(false); + break; + default: + assert(false); } *object_copy = copy; @@ -662,9 +634,7 @@ int yr_object_copy( } -int yr_object_structure_set_member( - YR_OBJECT* object, - YR_OBJECT* member) +int yr_object_structure_set_member(YR_OBJECT* object, YR_OBJECT* member) { YR_STRUCTURE_MEMBER* sm; @@ -672,7 +642,7 @@ int yr_object_structure_set_member( // Check if the object already have a member with the same identifier - if (yr_object_lookup_field(object, member->identifier) != NULL) + if (yr_object_lookup_field(object, member->identifier) != NULL) return ERROR_DUPLICATED_STRUCTURE_MEMBER; sm = (YR_STRUCTURE_MEMBER*) yr_malloc(sizeof(YR_STRUCTURE_MEMBER)); @@ -690,8 +660,7 @@ int yr_object_structure_set_member( } -int yr_object_array_length( - YR_OBJECT* object) +int yr_object_array_length(YR_OBJECT* object) { YR_OBJECT_ARRAY* array; @@ -705,10 +674,7 @@ int yr_object_array_length( } -YR_OBJECT* yr_object_array_get_item( - YR_OBJECT* object, - int flags, - int index) +YR_OBJECT* yr_object_array_get_item(YR_OBJECT* object, int flags, int index) { YR_OBJECT* result = NULL; YR_OBJECT_ARRAY* array; @@ -735,10 +701,7 @@ YR_OBJECT* yr_object_array_get_item( } -int yr_object_array_set_item( - YR_OBJECT* object, - YR_OBJECT* item, - int index) +int yr_object_array_set_item(YR_OBJECT* object, YR_OBJECT* item, int index) { YR_OBJECT_ARRAY* array; @@ -754,8 +717,7 @@ int yr_object_array_set_item( { capacity = 64; - while (capacity <= index) - capacity *= 2; + while (capacity <= index) capacity *= 2; array->items = (YR_ARRAY_ITEMS*) yr_malloc( sizeof(YR_ARRAY_ITEMS) + capacity * sizeof(YR_OBJECT*)); @@ -772,12 +734,10 @@ int yr_object_array_set_item( { capacity = array->items->capacity * 2; - while (capacity <= index) - capacity *= 2; + while (capacity <= index) capacity *= 2; array->items = (YR_ARRAY_ITEMS*) yr_realloc( - array->items, - sizeof(YR_ARRAY_ITEMS) + capacity * sizeof(YR_OBJECT*)); + array->items, sizeof(YR_ARRAY_ITEMS) + capacity * sizeof(YR_OBJECT*)); if (array->items == NULL) return ERROR_INSUFFICIENT_MEMORY; @@ -833,10 +793,7 @@ YR_OBJECT* yr_object_dict_get_item( } -int yr_object_dict_set_item( - YR_OBJECT* object, - YR_OBJECT* item, - const char* key) +int yr_object_dict_set_item(YR_OBJECT* object, YR_OBJECT* item, const char* key) { YR_OBJECT_DICTIONARY* dict; @@ -893,10 +850,7 @@ int yr_object_dict_set_item( } -bool yr_object_has_undefined_value( - YR_OBJECT* object, - const char* field, - ...) +bool yr_object_has_undefined_value(YR_OBJECT* object, const char* field, ...) { YR_OBJECT* field_obj; @@ -913,24 +867,21 @@ bool yr_object_has_undefined_value( if (field_obj == NULL) return true; - switch(field_obj->type) + switch (field_obj->type) { - case OBJECT_TYPE_FLOAT: - return isnan(field_obj->value.d); - case OBJECT_TYPE_STRING: - return field_obj->value.ss == NULL; - case OBJECT_TYPE_INTEGER: - return field_obj->value.i == YR_UNDEFINED; + case OBJECT_TYPE_FLOAT: + return isnan(field_obj->value.d); + case OBJECT_TYPE_STRING: + return field_obj->value.ss == NULL; + case OBJECT_TYPE_INTEGER: + return field_obj->value.i == YR_UNDEFINED; } return false; } -int64_t yr_object_get_integer( - YR_OBJECT* object, - const char* field, - ...) +int64_t yr_object_get_integer(YR_OBJECT* object, const char* field, ...) { YR_OBJECT* integer_obj; @@ -947,17 +898,16 @@ int64_t yr_object_get_integer( if (integer_obj == NULL) return YR_UNDEFINED; - assertf(integer_obj->type == OBJECT_TYPE_INTEGER, - "type of \"%s\" is not integer\n", field); + assertf( + integer_obj->type == OBJECT_TYPE_INTEGER, + "type of \"%s\" is not integer\n", + field); return integer_obj->value.i; } -double yr_object_get_float( - YR_OBJECT* object, - const char* field, - ...) +double yr_object_get_float(YR_OBJECT* object, const char* field, ...) { YR_OBJECT* double_obj; @@ -974,17 +924,16 @@ double yr_object_get_float( if (double_obj == NULL) return NAN; - assertf(double_obj->type == OBJECT_TYPE_FLOAT, - "type of \"%s\" is not double\n", field); + assertf( + double_obj->type == OBJECT_TYPE_FLOAT, + "type of \"%s\" is not double\n", + field); return double_obj->value.d; } -SIZED_STRING* yr_object_get_string( - YR_OBJECT* object, - const char* field, - ...) +SIZED_STRING* yr_object_get_string(YR_OBJECT* object, const char* field, ...) { YR_OBJECT* string_obj; @@ -1001,8 +950,10 @@ SIZED_STRING* yr_object_get_string( if (string_obj == NULL) return NULL; - assertf(string_obj->type == OBJECT_TYPE_STRING, - "type of \"%s\" is not string\n", field); + assertf( + string_obj->type == OBJECT_TYPE_STRING, + "type of \"%s\" is not string\n", + field); return string_obj->value.ss; } @@ -1042,11 +993,7 @@ int yr_object_set_integer( } -int yr_object_set_float( - double value, - YR_OBJECT* object, - const char* field, - ...) +int yr_object_set_float(double value, YR_OBJECT* object, const char* field, ...) { YR_OBJECT* double_obj; @@ -1131,13 +1078,11 @@ int yr_object_set_string( } -YR_OBJECT* yr_object_get_root( - YR_OBJECT* object) +YR_OBJECT* yr_object_get_root(YR_OBJECT* object) { YR_OBJECT* o = object; - while (o->parent != NULL) - o = o->parent; + while (o->parent != NULL) o = o->parent; return o; } @@ -1161,97 +1106,94 @@ YR_API void yr_object_print_data( if (print_identifier && object->type != OBJECT_TYPE_FUNCTION) printf("%s%s", indent_spaces, object->identifier); - switch(object->type) + switch (object->type) { - case OBJECT_TYPE_FLOAT: - if (object->value.i != YR_UNDEFINED) - printf(" = %f", object->value.d); - else - printf(" = YR_UNDEFINED"); - - break; - - case OBJECT_TYPE_INTEGER: + case OBJECT_TYPE_FLOAT: + if (object->value.i != YR_UNDEFINED) + printf(" = %f", object->value.d); + else + printf(" = YR_UNDEFINED"); - if (object->value.i != YR_UNDEFINED) - printf(" = %" PRId64, object->value.i); - else - printf(" = YR_UNDEFINED"); + break; - break; + case OBJECT_TYPE_INTEGER: - case OBJECT_TYPE_STRING: + if (object->value.i != YR_UNDEFINED) + printf(" = %" PRId64, object->value.i); + else + printf(" = YR_UNDEFINED"); - if (object->value.ss != NULL) - { - size_t l; - printf(" = \""); + break; - for (l = 0; l < object->value.ss->length; l++) - { - char c = object->value.ss->c_string[l]; + case OBJECT_TYPE_STRING: - if (isprint((unsigned char) c)) - printf("%c", c); - else - printf("\\x%02x", (unsigned char) c); - } + if (object->value.ss != NULL) + { + size_t l; + printf(" = \""); - printf("\""); - } - else + for (l = 0; l < object->value.ss->length; l++) { - printf(" = YR_UNDEFINED"); + char c = object->value.ss->c_string[l]; + + if (isprint((unsigned char) c)) + printf("%c", c); + else + printf("\\x%02x", (unsigned char) c); } - break; + printf("\""); + } + else + { + printf(" = YR_UNDEFINED"); + } - case OBJECT_TYPE_STRUCTURE: + break; + + case OBJECT_TYPE_STRUCTURE: - member = object_as_structure(object)->members; + member = object_as_structure(object)->members; - while (member != NULL) + while (member != NULL) + { + if (member->object->type != OBJECT_TYPE_FUNCTION) { - if (member->object->type != OBJECT_TYPE_FUNCTION) - { - printf("\n"); - yr_object_print_data(member->object, indent + 1, 1); - } - member = member->next; + printf("\n"); + yr_object_print_data(member->object, indent + 1, 1); } + member = member->next; + } - break; + break; - case OBJECT_TYPE_ARRAY: - for (i = 0; i < yr_object_array_length(object); i++) - { - YR_OBJECT* o = yr_object_array_get_item(object, 0, i); + case OBJECT_TYPE_ARRAY: + for (i = 0; i < yr_object_array_length(object); i++) + { + YR_OBJECT* o = yr_object_array_get_item(object, 0, i); - if (o != NULL) - { - printf("\n%s\t[%d]", indent_spaces, i); - yr_object_print_data(o, indent + 1, 0); - } + if (o != NULL) + { + printf("\n%s\t[%d]", indent_spaces, i); + yr_object_print_data(o, indent + 1, 0); } - break; + } + break; - case OBJECT_TYPE_DICTIONARY: + case OBJECT_TYPE_DICTIONARY: - dict_items = object_as_dictionary(object)->items; + dict_items = object_as_dictionary(object)->items; - if (dict_items != NULL) + if (dict_items != NULL) + { + for (i = 0; i < dict_items->used; i++) { - for (i = 0; i < dict_items->used; i++) - { - printf( - "\n%s\t%s", - indent_spaces, - dict_items->objects[i].key->c_string); + printf("\n%s\t%s", indent_spaces, dict_items->objects[i].key->c_string); - yr_object_print_data(dict_items->objects[i].obj, indent + 1, 0); - } + yr_object_print_data(dict_items->objects[i].obj, indent + 1, 0); } + } - break; + break; } } diff --git a/libyara/parser.c b/libyara/parser.c index 2dd437acee..8b81108c13 100644 --- a/libyara/parser.c +++ b/libyara/parser.c @@ -27,28 +27,26 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include -#include - #include #include #include -#include #include #include +#include +#include +#include #include +#include +#include #include #include -#include -#include -#include -#include -#define todigit(x) ((x) >='A'&& (x) <='F')? \ - ((uint8_t) (x - 'A' + 10)) : \ - ((uint8_t) (x - '0')) +#define todigit(x) \ + ((x) >= 'A' && (x) <= 'F') ? ((uint8_t)(x - 'A' + 10)) : ((uint8_t)(x - '0')) int yr_parser_emit( @@ -174,10 +172,7 @@ int yr_parser_emit_with_arg_reloc( if (result == ERROR_SUCCESS) result = yr_arena_make_ptr_relocatable( - yyget_extra(yyscanner)->arena, - YR_CODE_SECTION, - ref.offset, - EOL); + yyget_extra(yyscanner)->arena, YR_CODE_SECTION, ref.offset, EOL); if (argument_ref != NULL) *argument_ref = ref; @@ -212,8 +207,7 @@ int yr_parser_emit_pushes_for_strings( string_identifier = string->identifier; target_identifier = identifier; - while (*target_identifier != '\0' && - *string_identifier != '\0' && + while (*target_identifier != '\0' && *string_identifier != '\0' && *target_identifier == *string_identifier) { target_identifier++; @@ -221,14 +215,9 @@ int yr_parser_emit_pushes_for_strings( } if ((*target_identifier == '\0' && *string_identifier == '\0') || - *target_identifier == '*') + *target_identifier == '*') { - yr_parser_emit_with_arg_reloc( - yyscanner, - OP_PUSH, - string, - NULL, - NULL); + yr_parser_emit_with_arg_reloc(yyscanner, OP_PUSH, string, NULL, NULL); string->flags |= STRING_FLAGS_REFERENCED; string->flags &= ~STRING_FLAGS_FIXED_OFFSET; @@ -239,19 +228,17 @@ int yr_parser_emit_pushes_for_strings( if (matching == 0) { - yr_compiler_set_error_extra_info(compiler, identifier) - return ERROR_UNDEFINED_STRING; + yr_compiler_set_error_extra_info( + compiler, identifier) return ERROR_UNDEFINED_STRING; } return ERROR_SUCCESS; } -int yr_parser_emit_push_const( - yyscan_t yyscanner, - uint64_t argument) +int yr_parser_emit_push_const(yyscan_t yyscanner, uint64_t argument) { - uint64_t u = (uint64_t)argument; + uint64_t u = (uint64_t) argument; uint8_t buf[9]; int bufsz = 1; if (u == YR_UNDEFINED) @@ -262,31 +249,28 @@ int yr_parser_emit_push_const( { buf[0] = OP_PUSH_8; bufsz += sizeof(uint8_t); - buf[1] = (uint8_t)argument; + buf[1] = (uint8_t) argument; } else if (u <= 0xffff) { buf[0] = OP_PUSH_16; bufsz += sizeof(uint16_t); - *((uint16_t*)(buf+1)) = (uint16_t)argument; + *((uint16_t*) (buf + 1)) = (uint16_t) argument; } else if (u <= 0xffffffff) { buf[0] = OP_PUSH_32; bufsz += sizeof(uint32_t); - *((uint32_t*)(buf+1)) = (uint32_t)argument; + *((uint32_t*) (buf + 1)) = (uint32_t) argument; } - else { + else + { buf[0] = OP_PUSH; bufsz += sizeof(uint64_t); - *((uint64_t*)(buf+1)) = (uint64_t)argument; + *((uint64_t*) (buf + 1)) = (uint64_t) argument; } return yr_arena_write_data( - yyget_extra(yyscanner)->arena, - YR_CODE_SECTION, - buf, - bufsz, - NULL); + yyget_extra(yyscanner)->arena, YR_CODE_SECTION, buf, bufsz, NULL); } @@ -308,7 +292,7 @@ int yr_parser_check_types( yr_compiler_set_error_extra_info(compiler, function->identifier) - return ERROR_WRONG_ARGUMENTS; + return ERROR_WRONG_ARGUMENTS; } @@ -338,7 +322,7 @@ int yr_parser_lookup_string( yr_compiler_set_error_extra_info(compiler, identifier) - *string = NULL; + * string = NULL; return ERROR_UNDEFINED_STRING; } @@ -376,14 +360,14 @@ int yr_parser_lookup_loop_variable( for (j = 0; j < compiler->loop[i].vars_count; j++) { - if (compiler->loop[i].vars[j].identifier.ptr != NULL && - strcmp(identifier, compiler->loop[i].vars[j].identifier.ptr) == 0) - { - if (expr != NULL) - *expr = compiler->loop[i].vars[j]; + if (compiler->loop[i].vars[j].identifier.ptr != NULL && + strcmp(identifier, compiler->loop[i].vars[j].identifier.ptr) == 0) + { + if (expr != NULL) + *expr = compiler->loop[i].vars[j]; - return var_offset + j; - } + return var_offset + j; + } } var_offset += compiler->loop[i].vars_count; @@ -426,11 +410,9 @@ static int _yr_parser_write_string( YR_ARENA_REF ref; - FAIL_ON_ERROR(_yr_compiler_store_string( - compiler, identifier, &ref)); + FAIL_ON_ERROR(_yr_compiler_store_string(compiler, identifier, &ref)); - string->identifier = (const char*) yr_arena_ref_to_ptr( - compiler->arena, &ref); + string->identifier = (const char*) yr_arena_ref_to_ptr(compiler->arena, &ref); if (modifier.flags & STRING_FLAGS_HEXADECIMAL || modifier.flags & STRING_FLAGS_REGEXP || @@ -472,7 +454,7 @@ static int _yr_parser_write_string( result = _yr_compiler_store_data( compiler, literal_string->c_string, - literal_string->length + 1, // +1 to include terminating NULL + literal_string->length + 1, // +1 to include terminating NULL &ref); string->length = (uint32_t) literal_string->length; @@ -492,13 +474,11 @@ static int _yr_parser_write_string( else { // Emit forwards code - result = yr_re_ast_emit_code( - re_ast, compiler->arena, false); + result = yr_re_ast_emit_code(re_ast, compiler->arena, false); // Emit backwards code if (result == ERROR_SUCCESS) - result = yr_re_ast_emit_code( - re_ast, compiler->arena, true); + result = yr_re_ast_emit_code(re_ast, compiler->arena, true); if (result == ERROR_SUCCESS) result = yr_atoms_extract_from_re( @@ -581,24 +561,20 @@ int yr_parser_reduce_string_declaration( // Determine if a string with the same identifier was already defined // by searching for the identifier in strings_table. uint32_t string_idx = yr_hash_table_lookup_uint32( - compiler->strings_table, - identifier, - NULL); + compiler->strings_table, identifier, NULL); // The string was already defined, return an error. if (string_idx != UINT32_MAX) { result = ERROR_DUPLICATED_STRING_IDENTIFIER; - yr_compiler_set_error_extra_info(compiler, identifier) - goto _exit; + yr_compiler_set_error_extra_info(compiler, identifier) goto _exit; } // Empty strings are not allowed if (str->length == 0) { result = ERROR_EMPTY_STRING; - yr_compiler_set_error_extra_info(compiler, identifier) - goto _exit; + yr_compiler_set_error_extra_info(compiler, identifier) goto _exit; } // If string identifier is $ this is an anonymous string, if not add the @@ -633,9 +609,8 @@ int yr_parser_reduce_string_declaration( if (modifier.flags & STRING_FLAGS_XOR && modifier.flags & STRING_FLAGS_NO_CASE) { - result = ERROR_INVALID_MODIFIER; - yr_compiler_set_error_extra_info(compiler, "xor nocase") - goto _exit; + result = ERROR_INVALID_MODIFIER; + yr_compiler_set_error_extra_info(compiler, "xor nocase") goto _exit; } // base64 and nocase together is not implemented. @@ -643,13 +618,11 @@ int yr_parser_reduce_string_declaration( (modifier.flags & STRING_FLAGS_BASE64 || modifier.flags & STRING_FLAGS_BASE64_WIDE)) { - result = ERROR_INVALID_MODIFIER; - yr_compiler_set_error_extra_info( - compiler, - modifier.flags & STRING_FLAGS_BASE64 ? - "base64 nocase" : - "base64wide nocase") - goto _exit; + result = ERROR_INVALID_MODIFIER; + yr_compiler_set_error_extra_info( + compiler, + modifier.flags & STRING_FLAGS_BASE64 ? "base64 nocase" + : "base64wide nocase") goto _exit; } // base64 and fullword together is not implemented. @@ -657,13 +630,12 @@ int yr_parser_reduce_string_declaration( (modifier.flags & STRING_FLAGS_BASE64 || modifier.flags & STRING_FLAGS_BASE64_WIDE)) { - result = ERROR_INVALID_MODIFIER; - yr_compiler_set_error_extra_info( - compiler, - modifier.flags & STRING_FLAGS_BASE64 ? - "base64 fullword" : - "base64wide fullword") - goto _exit; + result = ERROR_INVALID_MODIFIER; + yr_compiler_set_error_extra_info( + compiler, + modifier.flags & STRING_FLAGS_BASE64 + ? "base64 fullword" + : "base64wide fullword") goto _exit; } // base64 and xor together is not implemented. @@ -671,13 +643,11 @@ int yr_parser_reduce_string_declaration( (modifier.flags & STRING_FLAGS_BASE64 || modifier.flags & STRING_FLAGS_BASE64_WIDE)) { - result = ERROR_INVALID_MODIFIER; - yr_compiler_set_error_extra_info( - compiler, - modifier.flags & STRING_FLAGS_BASE64 ? - "base64 xor" : - "base64wide xor") - goto _exit; + result = ERROR_INVALID_MODIFIER; + yr_compiler_set_error_extra_info( + compiler, + modifier.flags & STRING_FLAGS_BASE64 ? "base64 xor" + : "base64wide xor") goto _exit; } if (!(modifier.flags & STRING_FLAGS_WIDE) && @@ -721,15 +691,14 @@ int yr_parser_reduce_string_declaration( message, sizeof(message), "invalid %s \"%s\": %s", - (modifier.flags & STRING_FLAGS_HEXADECIMAL) ? - "hex string" : "regular expression", + (modifier.flags & STRING_FLAGS_HEXADECIMAL) ? "hex string" + : "regular expression", identifier, re_error.message); - yr_compiler_set_error_extra_info( - compiler, message) + yr_compiler_set_error_extra_info(compiler, message) - goto _exit; + goto _exit; } if (re_ast->flags & RE_FLAGS_FAST_REGEXP) @@ -749,28 +718,27 @@ int yr_parser_reduce_string_declaration( { result = ERROR_INVALID_REGULAR_EXPRESSION; - yr_compiler_set_error_extra_info(compiler, + yr_compiler_set_error_extra_info( + compiler, "greedy and ungreedy quantifiers can't be mixed in a regular " "expression") - goto _exit; + goto _exit; } if (yr_re_ast_contains_dot_star(re_ast)) { yywarning( yyscanner, - "%s contains .* or .+, consider using .{,N} or .{1,N} with a reasonable value for N", + "%s contains .* or .+, consider using .{,N} or .{1,N} with a " + "reasonable value for N", identifier); } if (compiler->re_ast_callback != NULL) { compiler->re_ast_callback( - current_rule, - identifier, - re_ast, - compiler->re_ast_clbk_user_data); + current_rule, identifier, re_ast, compiler->re_ast_clbk_user_data); } *string_ref = YR_ARENA_NULL_REF; @@ -889,7 +857,7 @@ int yr_parser_reduce_rule_declaration_phase_1( const char* identifier, YR_ARENA_REF* rule_ref) { - YR_FIXUP *fixup; + YR_FIXUP* fixup; YR_COMPILER* compiler = yyget_extra(yyscanner); YR_NAMESPACE* ns = (YR_NAMESPACE*) yr_arena_get_ptr( @@ -898,19 +866,14 @@ int yr_parser_reduce_rule_declaration_phase_1( compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE)); if (yr_hash_table_lookup_uint32( - compiler->rules_table, - identifier, - ns->name) != UINT32_MAX || - yr_hash_table_lookup( - compiler->objects_table, - identifier, - NULL) != NULL) + compiler->rules_table, identifier, ns->name) != UINT32_MAX || + yr_hash_table_lookup(compiler->objects_table, identifier, NULL) != NULL) { // A rule or variable with the same identifier already exists, return the // appropriate error. - yr_compiler_set_error_extra_info(compiler, identifier) - return ERROR_DUPLICATED_IDENTIFIER; + yr_compiler_set_error_extra_info( + compiler, identifier) return ERROR_DUPLICATED_IDENTIFIER; } FAIL_ON_ERROR(yr_arena_allocate_struct( @@ -929,10 +892,7 @@ int yr_parser_reduce_rule_declaration_phase_1( YR_ARENA_REF ref; - FAIL_ON_ERROR(_yr_compiler_store_string( - compiler, - identifier, - &ref)); + FAIL_ON_ERROR(_yr_compiler_store_string(compiler, identifier, &ref)); rule->identifier = (const char*) yr_arena_ref_to_ptr(compiler->arena, &ref); rule->flags = flags; @@ -953,11 +913,7 @@ int yr_parser_reduce_rule_declaration_phase_1( // its final value. FAIL_ON_ERROR(yr_parser_emit_with_arg_int32( - yyscanner, - OP_INIT_RULE, - 0, - NULL, - &jmp_offset_ref)); + yyscanner, OP_INIT_RULE, 0, NULL, &jmp_offset_ref)); FAIL_ON_ERROR(yr_arena_write_data( compiler->arena, @@ -980,10 +936,7 @@ int yr_parser_reduce_rule_declaration_phase_1( yr_hash_table_clean(compiler->strings_table, NULL); FAIL_ON_ERROR(yr_hash_table_add_uint32( - compiler->rules_table, - identifier, - ns->name, - compiler->current_rule_idx)); + compiler->rules_table, identifier, ns->name, compiler->current_rule_idx)); return ERROR_SUCCESS; } @@ -995,13 +948,12 @@ int yr_parser_reduce_rule_declaration_phase_2( uint32_t max_strings_per_rule; uint32_t strings_in_rule = 0; - YR_FIXUP *fixup; + YR_FIXUP* fixup; YR_STRING* string; YR_COMPILER* compiler = yyget_extra(yyscanner); yr_get_configuration( - YR_CONFIG_MAX_STRINGS_PER_RULE, - (void*) &max_strings_per_rule); + YR_CONFIG_MAX_STRINGS_PER_RULE, (void*) &max_strings_per_rule); YR_RULE* rule = (YR_RULE*) yr_arena_ref_to_ptr(compiler->arena, rule_ref); @@ -1021,37 +973,32 @@ int yr_parser_reduce_rule_declaration_phase_2( // chained_to == NULL) must be referenced. All other fragments // are never marked as referenced. - if (!STRING_IS_REFERENCED(string) && - string->chained_to == NULL) + if (!STRING_IS_REFERENCED(string) && string->chained_to == NULL) { - yr_compiler_set_error_extra_info(compiler, string->identifier) - return ERROR_UNREFERENCED_STRING; + yr_compiler_set_error_extra_info( + compiler, string->identifier) return ERROR_UNREFERENCED_STRING; } strings_in_rule++; if (strings_in_rule > max_strings_per_rule) { - yr_compiler_set_error_extra_info(compiler, rule->identifier) - return ERROR_TOO_MANY_STRINGS; + yr_compiler_set_error_extra_info( + compiler, rule->identifier) return ERROR_TOO_MANY_STRINGS; } } FAIL_ON_ERROR(yr_parser_emit_with_arg( - yyscanner, - OP_MATCH_RULE, - compiler->current_rule_idx, - NULL, - NULL)); + yyscanner, OP_MATCH_RULE, compiler->current_rule_idx, NULL, NULL)); fixup = compiler->fixup_stack_head; int32_t* jmp_offset_addr = (int32_t*) yr_arena_ref_to_ptr( compiler->arena, &fixup->ref); - int32_t jmp_offset = \ - yr_arena_get_current_offset(compiler->arena, YR_CODE_SECTION) - - fixup->ref.offset + 1; + int32_t jmp_offset = yr_arena_get_current_offset( + compiler->arena, YR_CODE_SECTION) - + fixup->ref.offset + 1; *jmp_offset_addr = jmp_offset; @@ -1076,16 +1023,12 @@ int yr_parser_reduce_string_identifier( YR_STRING* string; YR_COMPILER* compiler = yyget_extra(yyscanner); - if (strcmp(identifier, "$") == 0) // is an anonymous string ? + if (strcmp(identifier, "$") == 0) // is an anonymous string ? { - if (compiler->loop_for_of_var_index >= 0) // inside a loop ? + if (compiler->loop_for_of_var_index >= 0) // inside a loop ? { yr_parser_emit_with_arg( - yyscanner, - OP_PUSH_M, - compiler->loop_for_of_var_index, - NULL, - NULL); + yyscanner, OP_PUSH_M, compiler->loop_for_of_var_index, NULL, NULL); yr_parser_emit(yyscanner, instruction, NULL); @@ -1123,15 +1066,10 @@ int yr_parser_reduce_string_identifier( } else { - FAIL_ON_ERROR(yr_parser_lookup_string( - yyscanner, identifier, &string)); + FAIL_ON_ERROR(yr_parser_lookup_string(yyscanner, identifier, &string)); - FAIL_ON_ERROR(yr_parser_emit_with_arg_reloc( - yyscanner, - OP_PUSH, - string, - NULL, - NULL)); + FAIL_ON_ERROR( + yr_parser_emit_with_arg_reloc(yyscanner, OP_PUSH, string, NULL, NULL)); if (instruction != OP_FOUND) string->flags &= ~STRING_FLAGS_SINGLE_MATCH; @@ -1192,19 +1130,13 @@ int yr_parser_reduce_meta_declaration( meta->type = type; meta->integer = integer; - FAIL_ON_ERROR(_yr_compiler_store_string( - compiler, - identifier, - &ref)); + FAIL_ON_ERROR(_yr_compiler_store_string(compiler, identifier, &ref)); meta->identifier = (const char*) yr_arena_ref_to_ptr(compiler->arena, &ref); if (string != NULL) { - FAIL_ON_ERROR(_yr_compiler_store_string( - compiler, - string, - &ref)); + FAIL_ON_ERROR(_yr_compiler_store_string(compiler, string, &ref)); meta->string = (const char*) yr_arena_ref_to_ptr(compiler->arena, &ref); } @@ -1219,8 +1151,7 @@ int yr_parser_reduce_meta_declaration( } -static int _yr_parser_valid_module_name( - SIZED_STRING* module_name) +static int _yr_parser_valid_module_name(SIZED_STRING* module_name) { if (module_name->length == 0) return false; @@ -1232,9 +1163,7 @@ static int _yr_parser_valid_module_name( } -int yr_parser_reduce_import( - yyscan_t yyscanner, - SIZED_STRING* module_name) +int yr_parser_reduce_import(yyscan_t yyscanner, SIZED_STRING* module_name) { int result; @@ -1244,8 +1173,8 @@ int yr_parser_reduce_import( if (!_yr_parser_valid_module_name(module_name)) { - yr_compiler_set_error_extra_info(compiler, module_name->c_string) - return ERROR_INVALID_MODULE_NAME; + yr_compiler_set_error_extra_info( + compiler, module_name->c_string) return ERROR_INVALID_MODULE_NAME; } YR_NAMESPACE* ns = (YR_NAMESPACE*) yr_arena_get_ptr( @@ -1254,9 +1183,7 @@ int yr_parser_reduce_import( compiler->current_namespace_idx * sizeof(struct YR_NAMESPACE)); module_structure = (YR_OBJECT*) yr_hash_table_lookup( - compiler->objects_table, - module_name->c_string, - ns->name); + compiler->objects_table, module_name->c_string, ns->name); // if module already imported, do nothing @@ -1264,10 +1191,7 @@ int yr_parser_reduce_import( return ERROR_SUCCESS; FAIL_ON_ERROR(yr_object_create( - OBJECT_TYPE_STRUCTURE, - module_name->c_string, - NULL, - &module_structure)); + OBJECT_TYPE_STRUCTURE, module_name->c_string, NULL, &module_structure)); FAIL_ON_ERROR(yr_hash_table_add( compiler->objects_table, @@ -1275,20 +1199,15 @@ int yr_parser_reduce_import( ns->name, module_structure)); - result = yr_modules_do_declarations( - module_name->c_string, - module_structure); + result = yr_modules_do_declarations(module_name->c_string, module_structure); if (result == ERROR_UNKNOWN_MODULE) yr_compiler_set_error_extra_info(compiler, module_name->c_string) - if (result != ERROR_SUCCESS) - return result; + if (result != ERROR_SUCCESS) return result; - FAIL_ON_ERROR(_yr_compiler_store_string( - compiler, - module_name->c_string, - &ref)); + FAIL_ON_ERROR( + _yr_compiler_store_string(compiler, module_name->c_string, &ref)); FAIL_ON_ERROR(yr_parser_emit_with_arg_reloc( yyscanner, @@ -1301,25 +1220,23 @@ int yr_parser_reduce_import( } -static int _yr_parser_operator_to_opcode( - const char* op, - int expression_type) +static int _yr_parser_operator_to_opcode(const char* op, int expression_type) { int opcode = 0; - switch(expression_type) + switch (expression_type) { - case EXPRESSION_TYPE_INTEGER: - opcode = OP_INT_BEGIN; - break; - case EXPRESSION_TYPE_FLOAT: - opcode = OP_DBL_BEGIN; - break; - case EXPRESSION_TYPE_STRING: - opcode = OP_STR_BEGIN; - break; - default: - assert(false); + case EXPRESSION_TYPE_INTEGER: + opcode = OP_INT_BEGIN; + break; + case EXPRESSION_TYPE_FLOAT: + opcode = OP_DBL_BEGIN; + break; + case EXPRESSION_TYPE_STRING: + opcode = OP_STR_BEGIN; + break; + default: + assert(false); } if (op[0] == '<') @@ -1406,35 +1323,31 @@ int yr_parser_reduce_operation( } FAIL_ON_ERROR(yr_parser_emit( - yyscanner, - _yr_parser_operator_to_opcode(op, expression_type), - NULL)); + yyscanner, _yr_parser_operator_to_opcode(op, expression_type), NULL)); } - else if (left_operand.type == EXPRESSION_TYPE_STRING && - right_operand.type == EXPRESSION_TYPE_STRING) + else if ( + left_operand.type == EXPRESSION_TYPE_STRING && + right_operand.type == EXPRESSION_TYPE_STRING) { int opcode = _yr_parser_operator_to_opcode(op, EXPRESSION_TYPE_STRING); if (opcode != OP_ERROR) { - FAIL_ON_ERROR(yr_parser_emit( - yyscanner, - opcode, - NULL)); + FAIL_ON_ERROR(yr_parser_emit(yyscanner, opcode, NULL)); } else { yr_compiler_set_error_extra_info_fmt( compiler, "strings don't support \"%s\" operation", op) - return ERROR_WRONG_TYPE; + return ERROR_WRONG_TYPE; } } else { yr_compiler_set_error_extra_info(compiler, "type mismatch") - return ERROR_WRONG_TYPE; + return ERROR_WRONG_TYPE; } return ERROR_SUCCESS; diff --git a/libyara/proc.c b/libyara/proc.c index c636f5f618..142624cd64 100644 --- a/libyara/proc.c +++ b/libyara/proc.c @@ -28,21 +28,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include -#include #include +#include +#include int _yr_process_attach(int, YR_PROC_ITERATOR_CTX*); int _yr_process_detach(YR_PROC_ITERATOR_CTX*); -YR_API int yr_process_open_iterator( - int pid, - YR_MEMORY_BLOCK_ITERATOR* iterator) +YR_API int yr_process_open_iterator(int pid, YR_MEMORY_BLOCK_ITERATOR* iterator) { YR_DEBUG_FPRINTF(2, stderr, "+ %s(pid=%d) {}\n", __FUNCTION__, pid); - YR_PROC_ITERATOR_CTX* context = (YR_PROC_ITERATOR_CTX*) \ - yr_malloc(sizeof(YR_PROC_ITERATOR_CTX)); + YR_PROC_ITERATOR_CTX* context = (YR_PROC_ITERATOR_CTX*) yr_malloc( + sizeof(YR_PROC_ITERATOR_CTX)); if (context == NULL) return ERROR_INSUFFICIENT_MEMORY; @@ -60,15 +58,13 @@ YR_API int yr_process_open_iterator( context->proc_info = NULL; FAIL_ON_ERROR_WITH_CLEANUP( - _yr_process_attach(pid, context), - yr_free(context)); + _yr_process_attach(pid, context), yr_free(context)); return ERROR_SUCCESS; } -YR_API int yr_process_close_iterator( - YR_MEMORY_BLOCK_ITERATOR* iterator) +YR_API int yr_process_close_iterator(YR_MEMORY_BLOCK_ITERATOR* iterator) { YR_DEBUG_FPRINTF(2, stderr, "+ %s() {}\n", __FUNCTION__); diff --git a/libyara/proc/freebsd.c b/libyara/proc/freebsd.c index 35fb880014..6f77bb53ec 100644 --- a/libyara/proc/freebsd.c +++ b/libyara/proc/freebsd.c @@ -29,30 +29,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(USE_FREEBSD_PROC) -#include -#include - +#include #include -#include -#include #include +#include #include -#include - +#include #include -#include #include +#include -typedef struct _YR_PROC_INFO { - int pid; +typedef struct _YR_PROC_INFO +{ + int pid; struct ptrace_vm_entry vm_entry; } YR_PROC_INFO; -int _yr_process_attach( - int pid, - YR_PROC_ITERATOR_CTX* context) +int _yr_process_attach(int pid, YR_PROC_ITERATOR_CTX* context) { int status; @@ -85,8 +80,7 @@ int _yr_process_attach( } -int _yr_process_detach( - YR_PROC_ITERATOR_CTX* context) +int _yr_process_detach(YR_PROC_ITERATOR_CTX* context) { YR_PROC_INFO* proc_info = (YR_PROC_INFO*) context->proc_info; @@ -97,8 +91,7 @@ int _yr_process_detach( } -YR_API const uint8_t* yr_process_fetch_memory_block_data( - YR_MEMORY_BLOCK* block) +YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block) { YR_PROC_ITERATOR_CTX* context = (YR_PROC_ITERATOR_CTX*) block->context; YR_PROC_INFO* proc_info = (YR_PROC_INFO*) context->proc_info; @@ -123,11 +116,11 @@ YR_API const uint8_t* yr_process_fetch_memory_block_data( } io_desc.piod_op = PIOD_READ_D; - io_desc.piod_offs = (void*)block->base; - io_desc.piod_addr = (void*)context->buffer; + io_desc.piod_offs = (void*) block->base; + io_desc.piod_addr = (void*) context->buffer; io_desc.piod_len = block->size; - if (ptrace(PT_IO, proc_info->pid, (char*)&io_desc, 0) == -1) + if (ptrace(PT_IO, proc_info->pid, (char*) &io_desc, 0) == -1) { return NULL; } @@ -147,13 +140,15 @@ YR_API YR_MEMORY_BLOCK* yr_process_get_next_memory_block( proc_info->vm_entry.pve_path = buf; proc_info->vm_entry.pve_pathlen = sizeof(buf); - if (ptrace(PT_VM_ENTRY, proc_info->pid, (char*)(&proc_info->vm_entry), 0) == -1) { + if (ptrace(PT_VM_ENTRY, proc_info->pid, (char*) (&proc_info->vm_entry), 0) == + -1) + { return NULL; } context->current_block.base = proc_info->vm_entry.pve_start; - context->current_block.size = - proc_info->vm_entry.pve_end - proc_info->vm_entry.pve_start + 1; + context->current_block.size = proc_info->vm_entry.pve_end - + proc_info->vm_entry.pve_start + 1; return &context->current_block; } diff --git a/libyara/proc/linux.c b/libyara/proc/linux.c index 0dc91294bd..dd4e3b07a2 100644 --- a/libyara/proc/linux.c +++ b/libyara/proc/linux.c @@ -29,29 +29,27 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(USE_LINUX_PROC) +#include #include #include -#include #include #include -#include - +#include #include -#include -#include #include +#include +#include -typedef struct _YR_PROC_INFO { - int pid; - int mem_fd; - FILE* maps; +typedef struct _YR_PROC_INFO +{ + int pid; + int mem_fd; + FILE* maps; } YR_PROC_INFO; -int _yr_process_attach( - int pid, - YR_PROC_ITERATOR_CTX* context) +int _yr_process_attach(int pid, YR_PROC_ITERATOR_CTX* context) { char buffer[256]; @@ -92,8 +90,7 @@ int _yr_process_attach( } -int _yr_process_detach( - YR_PROC_ITERATOR_CTX* context) +int _yr_process_detach(YR_PROC_ITERATOR_CTX* context) { YR_PROC_INFO* proc_info = (YR_PROC_INFO*) context->proc_info; @@ -104,8 +101,7 @@ int _yr_process_detach( } -YR_API const uint8_t* yr_process_fetch_memory_block_data( - YR_MEMORY_BLOCK* block) +YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block) { const uint8_t* result = NULL; @@ -126,21 +122,22 @@ YR_API const uint8_t* yr_process_fetch_memory_block_data( else { context->buffer_size = 0; - goto _exit; // return NULL; + goto _exit; // return NULL; } } - if (pread(proc_info->mem_fd, - (void *) context->buffer, - block->size, - block->base) == -1) + if (pread( + proc_info->mem_fd, + (void*) context->buffer, + block->size, + block->base) == -1) { - goto _exit; // return NULL; + goto _exit; // return NULL; } result = context->buffer; - _exit:; +_exit:; YR_DEBUG_FPRINTF(2, stderr, "+ %s() {} = %p\n", __FUNCTION__, result); @@ -159,14 +156,18 @@ YR_API YR_MEMORY_BLOCK* yr_process_get_next_memory_block( if (fgets(buffer, sizeof(buffer), proc_info->maps) != NULL) { - sscanf(buffer, "%"SCNx64"-%"SCNx64, &begin, &end); + sscanf(buffer, "%" SCNx64 "-%" SCNx64, &begin, &end); context->current_block.base = begin; context->current_block.size = end - begin; - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s() {} // .base=0x%" PRIx64 " .size=%lu\n", - __FUNCTION__, context->current_block.base, context->current_block.size); + __FUNCTION__, + context->current_block.base, + context->current_block.size); return &context->current_block; } diff --git a/libyara/proc/mach.c b/libyara/proc/mach.c index 8ab6c527eb..dd2ff9d396 100644 --- a/libyara/proc/mach.c +++ b/libyara/proc/mach.c @@ -33,20 +33,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include - +#include #include #include -#include -typedef struct _YR_PROC_INFO { - task_t task; +typedef struct _YR_PROC_INFO +{ + task_t task; } YR_PROC_INFO; -int _yr_process_attach( - int pid, - YR_PROC_ITERATOR_CTX* context) +int _yr_process_attach(int pid, YR_PROC_ITERATOR_CTX* context) { YR_PROC_INFO* proc_info = (YR_PROC_INFO*) yr_malloc(sizeof(YR_PROC_INFO)); @@ -67,8 +65,7 @@ int _yr_process_attach( } -int _yr_process_detach( - YR_PROC_ITERATOR_CTX* context) +int _yr_process_detach(YR_PROC_ITERATOR_CTX* context) { YR_PROC_INFO* proc_info = context->proc_info; @@ -79,8 +76,7 @@ int _yr_process_detach( } -YR_API const uint8_t* yr_process_fetch_memory_block_data( - YR_MEMORY_BLOCK* block) +YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block) { YR_PROC_ITERATOR_CTX* context = (YR_PROC_ITERATOR_CTX*) block->context; YR_PROC_INFO* proc_info = context->proc_info; @@ -105,11 +101,11 @@ YR_API const uint8_t* yr_process_fetch_memory_block_data( } if (vm_read_overwrite( - proc_info->task, - (vm_address_t) block->base, - block->size, - (vm_address_t) context->buffer, - &size) != KERN_SUCCESS) + proc_info->task, + (vm_address_t) block->base, + block->size, + (vm_address_t) context->buffer, + &size) != KERN_SUCCESS) { return NULL; } @@ -129,8 +125,10 @@ YR_API YR_MEMORY_BLOCK* yr_process_get_next_memory_block( mach_port_t object; vm_region_basic_info_data_64_t info; vm_size_t size = 0; - vm_address_t address = (vm_address_t) \ - context->current_block.base + context->current_block.size; + + vm_address_t address = (vm_address_t) context->current_block.base + + context->current_block.size; + do { info_count = VM_REGION_BASIC_INFO_COUNT_64; diff --git a/libyara/proc/none.c b/libyara/proc/none.c index 8b37431841..1051139746 100644 --- a/libyara/proc/none.c +++ b/libyara/proc/none.c @@ -32,21 +32,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -int _yr_process_attach( - int pid, - YR_PROC_ITERATOR_CTX* context) +int _yr_process_attach(int pid, YR_PROC_ITERATOR_CTX* context) { return ERROR_COULD_NOT_ATTACH_TO_PROCESS; } -int _yr_process_detach( - YR_PROC_ITERATOR_CTX* context) +int _yr_process_detach(YR_PROC_ITERATOR_CTX* context) { return ERROR_INVALID_ARGUMENT; } -YR_API const uint8_t* yr_process_fetch_memory_block_data( - YR_MEMORY_BLOCK* block) +YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block) { return NULL; } diff --git a/libyara/proc/openbsd.c b/libyara/proc/openbsd.c index 5c7d51bbb7..d31c2826fd 100644 --- a/libyara/proc/openbsd.c +++ b/libyara/proc/openbsd.c @@ -29,32 +29,30 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(USE_OPENBSD_PROC) -#include +#include #include #include +#include #include -#include - #include -#include #include +#include -typedef struct _YR_PROC_INFO { - int pid; - uint64_t old_end; +typedef struct _YR_PROC_INFO +{ + int pid; + uint64_t old_end; struct kinfo_vmentry vm_entry; } YR_PROC_INFO; -int _yr_process_attach( - int pid, - YR_PROC_ITERATOR_CTX* context) +int _yr_process_attach(int pid, YR_PROC_ITERATOR_CTX* context) { int status; size_t len = sizeof(struct kinfo_vmentry); - int mib[] = { CTL_KERN, KERN_PROC_VMMAP, pid }; + int mib[] = {CTL_KERN, KERN_PROC_VMMAP, pid}; YR_PROC_INFO* proc_info = (YR_PROC_INFO*) yr_malloc(sizeof(YR_PROC_INFO)); if (proc_info == NULL) @@ -91,8 +89,7 @@ int _yr_process_attach( } -int _yr_process_detach( - YR_PROC_ITERATOR_CTX* context) +int _yr_process_detach(YR_PROC_ITERATOR_CTX* context) { YR_PROC_INFO* proc_info = (YR_PROC_INFO*) context->proc_info; @@ -102,8 +99,7 @@ int _yr_process_detach( } -YR_API const uint8_t* yr_process_fetch_memory_block_data( - YR_MEMORY_BLOCK* block) +YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block) { YR_PROC_ITERATOR_CTX* context = (YR_PROC_ITERATOR_CTX*) block->context; YR_PROC_INFO* proc_info = (YR_PROC_INFO*) context->proc_info; @@ -129,11 +125,11 @@ YR_API const uint8_t* yr_process_fetch_memory_block_data( } io_desc.piod_op = PIOD_READ_D; - io_desc.piod_offs = (void*)block->base; - io_desc.piod_addr = (void*)context->buffer; + io_desc.piod_offs = (void*) block->base; + io_desc.piod_addr = (void*) context->buffer; io_desc.piod_len = block->size; - if (ptrace(PT_IO, proc_info->pid, (char*)&io_desc, 0) == -1) + if (ptrace(PT_IO, proc_info->pid, (char*) &io_desc, 0) == -1) return NULL; return context->buffer; @@ -146,7 +142,7 @@ YR_API YR_MEMORY_BLOCK* yr_process_get_next_memory_block( YR_PROC_ITERATOR_CTX* context = (YR_PROC_ITERATOR_CTX*) iterator->context; YR_PROC_INFO* proc_info = (YR_PROC_INFO*) context->proc_info; - int mib[] = { CTL_KERN, KERN_PROC_VMMAP, proc_info->pid }; + int mib[] = {CTL_KERN, KERN_PROC_VMMAP, proc_info->pid}; size_t len = sizeof(struct kinfo_vmentry); if (sysctl(mib, 3, &proc_info->vm_entry, &len, NULL, 0) < 0) @@ -158,8 +154,8 @@ YR_API YR_MEMORY_BLOCK* yr_process_get_next_memory_block( proc_info->old_end = proc_info->vm_entry.kve_end; context->current_block.base = proc_info->vm_entry.kve_start; - context->current_block.size = - proc_info->vm_entry.kve_end - proc_info->vm_entry.kve_start; + context->current_block.size = proc_info->vm_entry.kve_end - + proc_info->vm_entry.kve_start; proc_info->vm_entry.kve_start = proc_info->vm_entry.kve_start + 1; diff --git a/libyara/proc/windows.c b/libyara/proc/windows.c index c39521daf0..8873653fff 100644 --- a/libyara/proc/windows.c +++ b/libyara/proc/windows.c @@ -30,20 +30,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(USE_WINDOWS_PROC) #include - -#include #include +#include #include -typedef struct _YR_PROC_INFO { - HANDLE hProcess; - SYSTEM_INFO si; +typedef struct _YR_PROC_INFO +{ + HANDLE hProcess; + SYSTEM_INFO si; } YR_PROC_INFO; -int _yr_process_attach( - int pid, - YR_PROC_ITERATOR_CTX* context) +int _yr_process_attach(int pid, YR_PROC_ITERATOR_CTX* context) { TOKEN_PRIVILEGES tokenPriv; LUID luidDebug; @@ -62,21 +60,14 @@ int _yr_process_attach( tokenPriv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges( - hToken, - FALSE, - &tokenPriv, - sizeof(tokenPriv), - NULL, - NULL); + hToken, FALSE, &tokenPriv, sizeof(tokenPriv), NULL, NULL); } if (hToken != NULL) CloseHandle(hToken); proc_info->hProcess = OpenProcess( - PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, - FALSE, - pid); + PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, pid); if (proc_info->hProcess == NULL) { @@ -92,18 +83,16 @@ int _yr_process_attach( } -int _yr_process_detach( - YR_PROC_ITERATOR_CTX* context) +int _yr_process_detach(YR_PROC_ITERATOR_CTX* context) { - YR_PROC_INFO* proc_info = (YR_PROC_INFO*)context->proc_info; + YR_PROC_INFO* proc_info = (YR_PROC_INFO*) context->proc_info; CloseHandle(proc_info->hProcess); return ERROR_SUCCESS; } -YR_API const uint8_t* yr_process_fetch_memory_block_data( - YR_MEMORY_BLOCK* block) +YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block) { SIZE_T read; @@ -129,14 +118,14 @@ YR_API const uint8_t* yr_process_fetch_memory_block_data( } if (ReadProcessMemory( - proc_info->hProcess, - (LPCVOID) block->base, - (LPVOID) context->buffer, - (SIZE_T) block->size, - &read) == FALSE) - { - return NULL; - } + proc_info->hProcess, + (LPCVOID) block->base, + (LPVOID) context->buffer, + (SIZE_T) block->size, + &read) == FALSE) + { + return NULL; + } return context->buffer; } @@ -149,8 +138,8 @@ YR_API YR_MEMORY_BLOCK* yr_process_get_next_memory_block( YR_PROC_INFO* proc_info = (YR_PROC_INFO*) context->proc_info; MEMORY_BASIC_INFORMATION mbi; - PVOID address = (PVOID) (context->current_block.base + \ - context->current_block.size); + PVOID address = (PVOID)( + context->current_block.base + context->current_block.size); while (address < proc_info->si.lpMaximumApplicationAddress && VirtualQueryEx(proc_info->hProcess, address, &mbi, sizeof(mbi)) != 0) @@ -182,8 +171,8 @@ YR_API YR_MEMORY_BLOCK* yr_process_get_first_memory_block( YR_PROC_INFO* proc_info = (YR_PROC_INFO*) context->proc_info; context->current_block.size = 0; - context->current_block.base = \ - (size_t) proc_info->si.lpMinimumApplicationAddress; + context->current_block.base = (size_t) + proc_info->si.lpMinimumApplicationAddress; return yr_process_get_next_memory_block(iterator); } diff --git a/libyara/re.c b/libyara/re.c index 3048efa474..51547600da 100644 --- a/libyara/re.c +++ b/libyara/re.c @@ -40,25 +40,24 @@ order to avoid confusion with operating system threads. #include #include - #include -#include +#include #include -#include +#include +#include #include #include -#include -#include #include -#include +#include +#include -#define EMIT_BACKWARDS 0x01 -#define EMIT_DONT_SET_FORWARDS_CODE 0x02 -#define EMIT_DONT_SET_BACKWARDS_CODE 0x04 +#define EMIT_BACKWARDS 0x01 +#define EMIT_DONT_SET_FORWARDS_CODE 0x02 +#define EMIT_DONT_SET_BACKWARDS_CODE 0x04 #ifndef INT16_MAX -#define INT16_MAX (32767) +#define INT16_MAX (32767) #endif @@ -67,31 +66,30 @@ typedef uint8_t RE_SPLIT_ID_TYPE; typedef struct _RE_REPEAT_ARGS { - uint16_t min; - uint16_t max; - int32_t offset; + uint16_t min; + uint16_t max; + int32_t offset; } RE_REPEAT_ARGS; typedef struct _RE_REPEAT_ANY_ARGS { - uint16_t min; - uint16_t max; + uint16_t min; + uint16_t max; } RE_REPEAT_ANY_ARGS; typedef struct _RE_EMIT_CONTEXT { - YR_ARENA* arena; - RE_SPLIT_ID_TYPE next_split_id; + YR_ARENA* arena; + RE_SPLIT_ID_TYPE next_split_id; } RE_EMIT_CONTEXT; -#define CHAR_IN_CLASS(cls, chr) \ - ((cls)[(chr) / 8] & 1 << ((chr) % 8)) +#define CHAR_IN_CLASS(cls, chr) ((cls)[(chr) / 8] & 1 << ((chr) % 8)) static bool _yr_re_is_char_in_class( @@ -111,9 +109,7 @@ static bool _yr_re_is_char_in_class( } -static bool _yr_re_is_word_char( - const uint8_t* input, - uint8_t character_size) +static bool _yr_re_is_word_char(const uint8_t* input, uint8_t character_size) { int result = ((isalnum(*input) || (*input) == '_')); @@ -124,8 +120,7 @@ static bool _yr_re_is_word_char( } -RE_NODE* yr_re_node_create( - int type) +RE_NODE* yr_re_node_create(int type) { RE_NODE* result = (RE_NODE*) yr_malloc(sizeof(RE_NODE)); @@ -145,8 +140,7 @@ RE_NODE* yr_re_node_create( } -void yr_re_node_destroy( - RE_NODE* node) +void yr_re_node_destroy(RE_NODE* node) { RE_NODE* child = node->children_head; RE_NODE* next_child; @@ -170,9 +164,7 @@ void yr_re_node_destroy( // // Appends a node to the end of the children list. // -void yr_re_node_append_child( - RE_NODE* node, - RE_NODE* child) +void yr_re_node_append_child(RE_NODE* node, RE_NODE* child) { if (node->children_head == NULL) node->children_head = child; @@ -190,9 +182,7 @@ void yr_re_node_append_child( // // Appends a node to the beginning of the children list. // -void yr_re_node_prepend_child( - RE_NODE* node, - RE_NODE* child) +void yr_re_node_prepend_child(RE_NODE* node, RE_NODE* child) { child->next_sibling = node->children_head; @@ -206,8 +196,7 @@ void yr_re_node_prepend_child( } -int yr_re_ast_create( - RE_AST** re_ast) +int yr_re_ast_create(RE_AST** re_ast) { *re_ast = (RE_AST*) yr_malloc(sizeof(RE_AST)); @@ -221,8 +210,7 @@ int yr_re_ast_create( } -void yr_re_ast_destroy( - RE_AST* re_ast) +void yr_re_ast_destroy(RE_AST* re_ast) { if (re_ast->root_node != NULL) yr_re_node_destroy(re_ast->root_node); @@ -238,10 +226,7 @@ void yr_re_ast_destroy( // yr_re_ast_emit_code is required to get the code. // -int yr_re_parse( - const char* re_string, - RE_AST** re_ast, - RE_ERROR* error) +int yr_re_parse(const char* re_string, RE_AST** re_ast, RE_ERROR* error) { return yr_parse_re_string(re_string, re_ast, error); } @@ -254,10 +239,7 @@ int yr_re_parse( // yr_re_ast_emit_code is required to get the code. // -int yr_re_parse_hex( - const char* hex_string, - RE_AST** re_ast, - RE_ERROR* error) +int yr_re_parse_hex(const char* hex_string, RE_AST** re_ast, RE_ERROR* error) { return yr_parse_hex_string(hex_string, re_ast, error); } @@ -285,17 +267,11 @@ int yr_re_compile( _re.flags = flags; FAIL_ON_ERROR_WITH_CLEANUP( - yr_arena_write_data( - arena, - YR_RE_CODE_SECTION, - &_re, - sizeof(_re), - ref), + yr_arena_write_data(arena, YR_RE_CODE_SECTION, &_re, sizeof(_re), ref), yr_re_ast_destroy(re_ast)); FAIL_ON_ERROR_WITH_CLEANUP( - yr_re_ast_emit_code(re_ast, arena, false), - yr_re_ast_destroy(re_ast)); + yr_re_ast_emit_code(re_ast, arena, false), yr_re_ast_destroy(re_ast)); yr_re_ast_destroy(re_ast); @@ -317,10 +293,7 @@ int yr_re_compile( // See return codes for yr_re_exec -int yr_re_match( - YR_SCAN_CONTEXT* context, - RE* re, - const char* target) +int yr_re_match(YR_SCAN_CONTEXT* context, RE* re, const char* target) { int result; @@ -350,8 +323,7 @@ int yr_re_match( // calling yr_free. // -SIZED_STRING* yr_re_ast_extract_literal( - RE_AST* re_ast) +SIZED_STRING* yr_re_ast_extract_literal(RE_AST* re_ast) { SIZED_STRING* string; RE_NODE* child; @@ -409,8 +381,7 @@ SIZED_STRING* yr_re_ast_extract_literal( } -int _yr_re_node_contains_dot_star( - RE_NODE* re_node) +int _yr_re_node_contains_dot_star(RE_NODE* re_node) { RE_NODE* child; @@ -435,8 +406,7 @@ int _yr_re_node_contains_dot_star( } -int yr_re_ast_contains_dot_star( - RE_AST* re_ast) +int yr_re_ast_contains_dot_star(RE_AST* re_ast) { return _yr_re_node_contains_dot_star(re_ast->root_node); } @@ -525,10 +495,8 @@ int yr_re_ast_split_at_chaining_point( while (child != NULL) { - if (!child->greedy && - child->type == RE_NODE_RANGE_ANY && - child->prev_sibling != NULL && - child->next_sibling != NULL && + if (!child->greedy && child->type == RE_NODE_RANGE_ANY && + child->prev_sibling != NULL && child->next_sibling != NULL && (child->start > YR_STRING_CHAINING_THRESHOLD || child->end > YR_STRING_CHAINING_THRESHOLD)) { @@ -750,7 +718,7 @@ int _yr_emit_split( #define current_re_code_offset() \ - yr_arena_get_current_offset(emit_context->arena, YR_RE_CODE_SECTION) + yr_arena_get_current_offset(emit_context->arena, YR_RE_CODE_SECTION) static int _yr_re_emit( RE_EMIT_CONTEXT* emit_context, @@ -785,7 +753,7 @@ static int _yr_re_emit( YR_ARENA_REF jmp_offset_ref; YR_ARENA_REF repeat_start_args_ref; - switch(re_node->type) + switch (re_node->type) { case RE_NODE_LITERAL: FAIL_ON_ERROR(_yr_emit_inst_arg_uint8( @@ -806,73 +774,52 @@ static int _yr_re_emit( break; case RE_NODE_WORD_CHAR: - FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_WORD_CHAR, - &instruction_ref)); + FAIL_ON_ERROR( + _yr_emit_inst(emit_context, RE_OPCODE_WORD_CHAR, &instruction_ref)); break; case RE_NODE_NON_WORD_CHAR: - FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_NON_WORD_CHAR, - &instruction_ref)); + FAIL_ON_ERROR( + _yr_emit_inst(emit_context, RE_OPCODE_NON_WORD_CHAR, &instruction_ref)); break; case RE_NODE_WORD_BOUNDARY: - FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_WORD_BOUNDARY, - &instruction_ref)); + FAIL_ON_ERROR( + _yr_emit_inst(emit_context, RE_OPCODE_WORD_BOUNDARY, &instruction_ref)); break; case RE_NODE_NON_WORD_BOUNDARY: FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_NON_WORD_BOUNDARY, - &instruction_ref)); + emit_context, RE_OPCODE_NON_WORD_BOUNDARY, &instruction_ref)); break; case RE_NODE_SPACE: - FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_SPACE, - &instruction_ref)); + FAIL_ON_ERROR( + _yr_emit_inst(emit_context, RE_OPCODE_SPACE, &instruction_ref)); break; case RE_NODE_NON_SPACE: - FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_NON_SPACE, - &instruction_ref)); + FAIL_ON_ERROR( + _yr_emit_inst(emit_context, RE_OPCODE_NON_SPACE, &instruction_ref)); break; case RE_NODE_DIGIT: - FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_DIGIT, - &instruction_ref)); + FAIL_ON_ERROR( + _yr_emit_inst(emit_context, RE_OPCODE_DIGIT, &instruction_ref)); break; case RE_NODE_NON_DIGIT: - FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_NON_DIGIT, - &instruction_ref)); + FAIL_ON_ERROR( + _yr_emit_inst(emit_context, RE_OPCODE_NON_DIGIT, &instruction_ref)); break; case RE_NODE_ANY: - FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_ANY, - &instruction_ref)); + FAIL_ON_ERROR(_yr_emit_inst(emit_context, RE_OPCODE_ANY, &instruction_ref)); break; case RE_NODE_CLASS: - FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_CLASS, - &instruction_ref)); + FAIL_ON_ERROR( + _yr_emit_inst(emit_context, RE_OPCODE_CLASS, &instruction_ref)); FAIL_ON_ERROR(yr_arena_write_data( emit_context->arena, @@ -884,24 +831,19 @@ static int _yr_re_emit( case RE_NODE_ANCHOR_START: FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_MATCH_AT_START, - &instruction_ref)); + emit_context, RE_OPCODE_MATCH_AT_START, &instruction_ref)); break; case RE_NODE_ANCHOR_END: - FAIL_ON_ERROR(_yr_emit_inst( - emit_context, - RE_OPCODE_MATCH_AT_END, - &instruction_ref)); + FAIL_ON_ERROR( + _yr_emit_inst(emit_context, RE_OPCODE_MATCH_AT_END, &instruction_ref)); break; case RE_NODE_CONCAT: FAIL_ON_ERROR(_yr_re_emit( emit_context, - (flags & EMIT_BACKWARDS)? - re_node->children_tail: - re_node->children_head, + (flags & EMIT_BACKWARDS) ? re_node->children_tail + : re_node->children_head, flags, &instruction_ref)); @@ -912,15 +854,10 @@ static int _yr_re_emit( while (child != NULL) { - FAIL_ON_ERROR(_yr_re_emit( - emit_context, - child, - flags, - NULL)); + FAIL_ON_ERROR(_yr_re_emit(emit_context, child, flags, NULL)); - child = (flags & EMIT_BACKWARDS) ? - child->prev_sibling: - child->next_sibling; + child = (flags & EMIT_BACKWARDS) ? child->prev_sibling + : child->next_sibling; } break; @@ -932,10 +869,7 @@ static int _yr_re_emit( // L2: // FAIL_ON_ERROR(_yr_re_emit( - emit_context, - re_node->children_head, - flags, - &instruction_ref)); + emit_context, re_node->children_head, flags, &instruction_ref)); jmp_offset = instruction_ref.offset - current_re_code_offset(); @@ -965,11 +899,8 @@ static int _yr_re_emit( &instruction_ref, &split_offset_ref)); - FAIL_ON_ERROR(_yr_re_emit( - emit_context, - re_node->children_head, - flags, - NULL)); + FAIL_ON_ERROR( + _yr_re_emit(emit_context, re_node->children_head, flags, NULL)); jmp_offset = instruction_ref.offset - current_re_code_offset(); @@ -979,11 +910,7 @@ static int _yr_re_emit( // Emit jump with offset set to 0. FAIL_ON_ERROR(_yr_emit_inst_arg_int16( - emit_context, - RE_OPCODE_JUMP, - (int16_t) jmp_offset, - NULL, - NULL)); + emit_context, RE_OPCODE_JUMP, (int16_t) jmp_offset, NULL, NULL)); jmp_offset = current_re_code_offset() - instruction_ref.offset; @@ -1017,11 +944,8 @@ static int _yr_re_emit( &instruction_ref, &split_offset_ref)); - FAIL_ON_ERROR(_yr_re_emit( - emit_context, - re_node->children_head, - flags, - NULL)); + FAIL_ON_ERROR( + _yr_re_emit(emit_context, re_node->children_head, flags, NULL)); // Emit jump with offset set to 0. @@ -1039,15 +963,12 @@ static int _yr_re_emit( // Update split offset. split_offset_addr = (int16_t*) yr_arena_ref_to_ptr( - emit_context->arena, &split_offset_ref); + emit_context->arena, &split_offset_ref); *split_offset_addr = (int16_t) jmp_offset; - FAIL_ON_ERROR(_yr_re_emit( - emit_context, - re_node->children_tail, - flags, - NULL)); + FAIL_ON_ERROR( + _yr_re_emit(emit_context, re_node->children_tail, flags, NULL)); jmp_offset = current_re_code_offset() - jmp_instruction_ref.offset; @@ -1056,7 +977,7 @@ static int _yr_re_emit( // Update offset for jmp instruction. jmp_offset_addr = (int16_t*) yr_arena_ref_to_ptr( - emit_context->arena, &jmp_offset_ref); + emit_context->arena, &jmp_offset_ref); *jmp_offset_addr = (int16_t) jmp_offset; break; @@ -1067,9 +988,8 @@ static int _yr_re_emit( FAIL_ON_ERROR(_yr_emit_inst_arg_struct( emit_context, - re_node->greedy ? - RE_OPCODE_REPEAT_ANY_GREEDY : - RE_OPCODE_REPEAT_ANY_UNGREEDY, + re_node->greedy ? RE_OPCODE_REPEAT_ANY_GREEDY + : RE_OPCODE_REPEAT_ANY_UNGREEDY, &repeat_any_args, sizeof(repeat_any_args), &instruction_ref, @@ -1134,10 +1054,7 @@ static int _yr_re_emit( if (emit_prolog) { FAIL_ON_ERROR(_yr_re_emit( - emit_context, - re_node->children_head, - flags, - &instruction_ref)); + emit_context, re_node->children_head, flags, &instruction_ref)); } if (emit_repeat) @@ -1167,9 +1084,8 @@ static int _yr_re_emit( FAIL_ON_ERROR(_yr_emit_inst_arg_struct( emit_context, - re_node->greedy ? - RE_OPCODE_REPEAT_START_GREEDY : - RE_OPCODE_REPEAT_START_UNGREEDY, + re_node->greedy ? RE_OPCODE_REPEAT_START_GREEDY + : RE_OPCODE_REPEAT_START_UNGREEDY, &repeat_args, sizeof(repeat_args), emit_prolog ? NULL : &instruction_ref, @@ -1192,9 +1108,8 @@ static int _yr_re_emit( FAIL_ON_ERROR(_yr_emit_inst_arg_struct( emit_context, - re_node->greedy ? - RE_OPCODE_REPEAT_END_GREEDY : - RE_OPCODE_REPEAT_END_UNGREEDY, + re_node->greedy ? RE_OPCODE_REPEAT_END_GREEDY + : RE_OPCODE_REPEAT_END_UNGREEDY, &repeat_args, sizeof(repeat_args), NULL, @@ -1217,9 +1132,7 @@ static int _yr_re_emit( FAIL_ON_ERROR(_yr_emit_split( emit_context, - re_node->greedy ? - RE_OPCODE_SPLIT_A : - RE_OPCODE_SPLIT_B, + re_node->greedy ? RE_OPCODE_SPLIT_A : RE_OPCODE_SPLIT_B, 0, NULL, &split_offset_ref)); @@ -1244,7 +1157,7 @@ static int _yr_re_emit( split_offset_addr = (int16_t*) yr_arena_ref_to_ptr( emit_context->arena, &split_offset_ref); - *split_offset_addr = (int16_t) (bookmark_2 - bookmark_1); + *split_offset_addr = (int16_t)(bookmark_2 - bookmark_1); } break; @@ -1274,10 +1187,7 @@ static int _yr_re_emit( } -int yr_re_ast_emit_code( - RE_AST* re_ast, - YR_ARENA* arena, - int backwards_code) +int yr_re_ast_emit_code(RE_AST* re_ast, YR_ARENA* arena, int backwards_code) { RE_EMIT_CONTEXT emit_context; @@ -1291,18 +1201,13 @@ int yr_re_ast_emit_code( backwards_code ? EMIT_BACKWARDS : 0, NULL)); - FAIL_ON_ERROR(_yr_emit_inst( - &emit_context, - RE_OPCODE_MATCH, - NULL)); + FAIL_ON_ERROR(_yr_emit_inst(&emit_context, RE_OPCODE_MATCH, NULL)); return ERROR_SUCCESS; } -static int _yr_re_fiber_create( - RE_FIBER_POOL* fiber_pool, - RE_FIBER** new_fiber) +static int _yr_re_fiber_create(RE_FIBER_POOL* fiber_pool, RE_FIBER** new_fiber) { RE_FIBER* fiber; @@ -1345,9 +1250,7 @@ static int _yr_re_fiber_create( // Appends 'fiber' to 'fiber_list' // -static void _yr_re_fiber_append( - RE_FIBER_LIST* fiber_list, - RE_FIBER* fiber) +static void _yr_re_fiber_append(RE_FIBER_LIST* fiber_list, RE_FIBER* fiber) { assert(fiber->prev == NULL); assert(fiber->next == NULL); @@ -1391,8 +1294,7 @@ static int _yr_re_fiber_exists( while (fiber != last_fiber->next) { - if (fiber->ip == target_fiber->ip && - fiber->sp == target_fiber->sp && + if (fiber->ip == target_fiber->ip && fiber->sp == target_fiber->sp && fiber->rc == target_fiber->rc) { equal_stacks = true; @@ -1444,8 +1346,7 @@ static int _yr_re_fiber_split( (*new_fiber)->ip = fiber->ip; (*new_fiber)->rc = fiber->rc; - for (i = 0; i <= fiber->sp; i++) - (*new_fiber)->stack[i] = fiber->stack[i]; + for (i = 0; i <= fiber->sp; i++) (*new_fiber)->stack[i] = fiber->stack[i]; (*new_fiber)->next = fiber->next; (*new_fiber)->prev = fiber; @@ -1512,9 +1413,9 @@ static RE_FIBER* _yr_re_fiber_kill( // static void _yr_re_fiber_kill_tail( - RE_FIBER_LIST* fiber_list, - RE_FIBER_POOL* fiber_pool, - RE_FIBER* fiber) + RE_FIBER_LIST* fiber_list, + RE_FIBER_POOL* fiber_pool, + RE_FIBER* fiber) { RE_FIBER* prev_fiber = fiber->prev; @@ -1595,177 +1496,175 @@ static int _yr_re_fiber_sync( switch (opcode) { - case RE_OPCODE_SPLIT_A: - case RE_OPCODE_SPLIT_B: + case RE_OPCODE_SPLIT_A: + case RE_OPCODE_SPLIT_B: - split_id = *(RE_SPLIT_ID_TYPE*)(fiber->ip + 1); - split_already_executed = false; + split_id = *(RE_SPLIT_ID_TYPE*) (fiber->ip + 1); + split_already_executed = false; - for (splits_executed_idx = 0; - splits_executed_idx < splits_executed_count; - splits_executed_idx++) + for (splits_executed_idx = 0; splits_executed_idx < splits_executed_count; + splits_executed_idx++) + { + if (split_id == splits_executed[splits_executed_idx]) { - if (split_id == splits_executed[splits_executed_idx]) - { - split_already_executed = true; - break; - } + split_already_executed = true; + break; } + } - if (split_already_executed) - { - fiber = _yr_re_fiber_kill(fiber_list, fiber_pool, fiber); - } - else - { - branch_a = fiber; + if (split_already_executed) + { + fiber = _yr_re_fiber_kill(fiber_list, fiber_pool, fiber); + } + else + { + branch_a = fiber; - FAIL_ON_ERROR(_yr_re_fiber_split( - fiber_list, fiber_pool, branch_a, &branch_b)); + FAIL_ON_ERROR( + _yr_re_fiber_split(fiber_list, fiber_pool, branch_a, &branch_b)); - // With RE_OPCODE_SPLIT_A the current fiber continues at the next - // instruction in the stream (branch A), while the newly created - // fiber starts at the address indicated by the instruction (branch B) - // RE_OPCODE_SPLIT_B has the opposite behavior. + // With RE_OPCODE_SPLIT_A the current fiber continues at the next + // instruction in the stream (branch A), while the newly created + // fiber starts at the address indicated by the instruction (branch B) + // RE_OPCODE_SPLIT_B has the opposite behavior. - if (opcode == RE_OPCODE_SPLIT_B) - yr_swap(branch_a, branch_b, RE_FIBER*); + if (opcode == RE_OPCODE_SPLIT_B) + yr_swap(branch_a, branch_b, RE_FIBER*); - // Branch A continues at the next instruction + // Branch A continues at the next instruction - branch_a->ip += (sizeof(RE_SPLIT_ID_TYPE) + 3); + branch_a->ip += (sizeof(RE_SPLIT_ID_TYPE) + 3); - // Branch B adds the offset encoded in the opcode to its instruction - // pointer. + // Branch B adds the offset encoded in the opcode to its instruction + // pointer. - branch_b->ip += *(int16_t*)( + branch_b->ip += *(int16_t*)( branch_b->ip + 1 // opcode size + sizeof(RE_SPLIT_ID_TYPE)); - splits_executed[splits_executed_count] = split_id; - splits_executed_count++; - } + splits_executed[splits_executed_count] = split_id; + splits_executed_count++; + } - break; + break; - case RE_OPCODE_REPEAT_START_GREEDY: - case RE_OPCODE_REPEAT_START_UNGREEDY: + case RE_OPCODE_REPEAT_START_GREEDY: + case RE_OPCODE_REPEAT_START_UNGREEDY: - repeat_args = (RE_REPEAT_ARGS*)(fiber->ip + 1); - assert(repeat_args->max > 0); - branch_a = fiber; + repeat_args = (RE_REPEAT_ARGS*) (fiber->ip + 1); + assert(repeat_args->max > 0); + branch_a = fiber; - if (repeat_args->min == 0) - { - FAIL_ON_ERROR(_yr_re_fiber_split( - fiber_list, fiber_pool, branch_a, &branch_b)); + if (repeat_args->min == 0) + { + FAIL_ON_ERROR( + _yr_re_fiber_split(fiber_list, fiber_pool, branch_a, &branch_b)); - if (opcode == RE_OPCODE_REPEAT_START_UNGREEDY) - yr_swap(branch_a, branch_b, RE_FIBER*); + if (opcode == RE_OPCODE_REPEAT_START_UNGREEDY) + yr_swap(branch_a, branch_b, RE_FIBER*); - branch_b->ip += repeat_args->offset; - } + branch_b->ip += repeat_args->offset; + } - branch_a->stack[++branch_a->sp] = 0; - branch_a->ip += (1 + sizeof(RE_REPEAT_ARGS)); - break; + branch_a->stack[++branch_a->sp] = 0; + branch_a->ip += (1 + sizeof(RE_REPEAT_ARGS)); + break; - case RE_OPCODE_REPEAT_END_GREEDY: - case RE_OPCODE_REPEAT_END_UNGREEDY: + case RE_OPCODE_REPEAT_END_GREEDY: + case RE_OPCODE_REPEAT_END_UNGREEDY: - repeat_args = (RE_REPEAT_ARGS*)(fiber->ip + 1); - fiber->stack[fiber->sp]++; + repeat_args = (RE_REPEAT_ARGS*) (fiber->ip + 1); + fiber->stack[fiber->sp]++; - if (fiber->stack[fiber->sp] < repeat_args->min) - { - fiber->ip += repeat_args->offset; - break; - } + if (fiber->stack[fiber->sp] < repeat_args->min) + { + fiber->ip += repeat_args->offset; + break; + } - branch_a = fiber; + branch_a = fiber; - if (fiber->stack[fiber->sp] < repeat_args->max) - { - FAIL_ON_ERROR(_yr_re_fiber_split( - fiber_list, fiber_pool, branch_a, &branch_b)); + if (fiber->stack[fiber->sp] < repeat_args->max) + { + FAIL_ON_ERROR( + _yr_re_fiber_split(fiber_list, fiber_pool, branch_a, &branch_b)); - if (opcode == RE_OPCODE_REPEAT_END_GREEDY) - yr_swap(branch_a, branch_b, RE_FIBER*); + if (opcode == RE_OPCODE_REPEAT_END_GREEDY) + yr_swap(branch_a, branch_b, RE_FIBER*); - branch_b->ip += repeat_args->offset; - } + branch_b->ip += repeat_args->offset; + } - branch_a->sp--; - branch_a->ip += (1 + sizeof(RE_REPEAT_ARGS)); - break; + branch_a->sp--; + branch_a->ip += (1 + sizeof(RE_REPEAT_ARGS)); + break; - case RE_OPCODE_REPEAT_ANY_GREEDY: - case RE_OPCODE_REPEAT_ANY_UNGREEDY: + case RE_OPCODE_REPEAT_ANY_GREEDY: + case RE_OPCODE_REPEAT_ANY_UNGREEDY: - repeat_any_args = (RE_REPEAT_ANY_ARGS*)(fiber->ip + 1); + repeat_any_args = (RE_REPEAT_ANY_ARGS*) (fiber->ip + 1); - // If repetition counter (rc) is -1 it means that we are reaching this - // instruction from the previous one in the instructions stream. In - // this case let's initialize the counter to 0 and start looping. + // If repetition counter (rc) is -1 it means that we are reaching this + // instruction from the previous one in the instructions stream. In + // this case let's initialize the counter to 0 and start looping. - if (fiber->rc == -1) - fiber->rc = 0; + if (fiber->rc == -1) + fiber->rc = 0; - if (fiber->rc < repeat_any_args->min) - { - // Increase repetition counter and continue with next fiber. The - // instruction pointer for this fiber is not incremented yet, this - // fiber spins in this same instruction until reaching the minimum - // number of repetitions. + if (fiber->rc < repeat_any_args->min) + { + // Increase repetition counter and continue with next fiber. The + // instruction pointer for this fiber is not incremented yet, this + // fiber spins in this same instruction until reaching the minimum + // number of repetitions. - fiber->rc++; - fiber = fiber->next; - } - else if (fiber->rc < repeat_any_args->max) - { - // Once the minimum number of repetitions are matched one fiber - // remains spinning in this instruction until reaching the maximum - // number of repetitions while new fibers are created. New fibers - // start executing at the next instruction. + fiber->rc++; + fiber = fiber->next; + } + else if (fiber->rc < repeat_any_args->max) + { + // Once the minimum number of repetitions are matched one fiber + // remains spinning in this instruction until reaching the maximum + // number of repetitions while new fibers are created. New fibers + // start executing at the next instruction. - next = fiber->next; - branch_a = fiber; + next = fiber->next; + branch_a = fiber; - FAIL_ON_ERROR(_yr_re_fiber_split( - fiber_list, fiber_pool, branch_a, &branch_b)); + FAIL_ON_ERROR( + _yr_re_fiber_split(fiber_list, fiber_pool, branch_a, &branch_b)); - if (opcode == RE_OPCODE_REPEAT_ANY_UNGREEDY) - yr_swap(branch_a, branch_b, RE_FIBER*); + if (opcode == RE_OPCODE_REPEAT_ANY_UNGREEDY) + yr_swap(branch_a, branch_b, RE_FIBER*); - branch_a->rc++; - branch_b->ip += (1 + sizeof(RE_REPEAT_ANY_ARGS)); - branch_b->rc = -1; + branch_a->rc++; + branch_b->ip += (1 + sizeof(RE_REPEAT_ANY_ARGS)); + branch_b->rc = -1; - FAIL_ON_ERROR(_yr_re_fiber_sync( - fiber_list, fiber_pool, branch_b)); + FAIL_ON_ERROR(_yr_re_fiber_sync(fiber_list, fiber_pool, branch_b)); - fiber = next; - } - else - { - // When the maximum number of repetitions is reached the fiber keeps - // executing at the next instruction. The repetition counter is set - // to -1 indicating that we are not spinning in a repeat instruction - // anymore. + fiber = next; + } + else + { + // When the maximum number of repetitions is reached the fiber keeps + // executing at the next instruction. The repetition counter is set + // to -1 indicating that we are not spinning in a repeat instruction + // anymore. - fiber->ip += (1 + sizeof(RE_REPEAT_ANY_ARGS)); - fiber->rc = -1; - } + fiber->ip += (1 + sizeof(RE_REPEAT_ANY_ARGS)); + fiber->rc = -1; + } - break; + break; - case RE_OPCODE_JUMP: - fiber->ip += *(int16_t*)(fiber->ip + 1); - break; + case RE_OPCODE_JUMP: + fiber->ip += *(int16_t*) (fiber->ip + 1); + break; - default: - fiber = fiber->next; + default: + fiber = fiber->next; } } @@ -1842,19 +1741,20 @@ int yr_re_exec( int kill; int action; - #define ACTION_NONE 0 - #define ACTION_CONTINUE 1 - #define ACTION_KILL 2 - #define ACTION_KILL_TAIL 3 - - #define prolog { \ - if ((bytes_matched >= max_bytes_matched) || \ - (character_size == 2 && *(input + 1) != 0)) \ - { \ - action = ACTION_KILL; \ - break; \ - } \ - } +#define ACTION_NONE 0 +#define ACTION_CONTINUE 1 +#define ACTION_KILL 2 +#define ACTION_KILL_TAIL 3 + +#define prolog \ + { \ + if ((bytes_matched >= max_bytes_matched) || \ + (character_size == 2 && *(input + 1) != 0)) \ + { \ + action = ACTION_KILL; \ + break; \ + } \ + } if (matches != NULL) *matches = -1; @@ -1918,225 +1818,221 @@ int yr_re_exec( switch (*ip) { - case RE_OPCODE_ANY: - prolog; - match = (flags & RE_FLAGS_DOT_ALL) || (*input != 0x0A); - action = match ? ACTION_NONE : ACTION_KILL; - fiber->ip += 1; - break; + case RE_OPCODE_ANY: + prolog; + match = (flags & RE_FLAGS_DOT_ALL) || (*input != 0x0A); + action = match ? ACTION_NONE : ACTION_KILL; + fiber->ip += 1; + break; - case RE_OPCODE_REPEAT_ANY_GREEDY: - case RE_OPCODE_REPEAT_ANY_UNGREEDY: - prolog; - match = (flags & RE_FLAGS_DOT_ALL) || (*input != 0x0A); - action = match ? ACTION_NONE : ACTION_KILL; + case RE_OPCODE_REPEAT_ANY_GREEDY: + case RE_OPCODE_REPEAT_ANY_UNGREEDY: + prolog; + match = (flags & RE_FLAGS_DOT_ALL) || (*input != 0x0A); + action = match ? ACTION_NONE : ACTION_KILL; - // The instruction pointer is not incremented here. The current fiber - // spins in this instruction until reaching the required number of - // repetitions. The code controlling the number of repetitions is in - // _yr_re_fiber_sync. + // The instruction pointer is not incremented here. The current fiber + // spins in this instruction until reaching the required number of + // repetitions. The code controlling the number of repetitions is in + // _yr_re_fiber_sync. - break; + break; - case RE_OPCODE_LITERAL: - prolog; - if (flags & RE_FLAGS_NO_CASE) - match = yr_lowercase[*input] == yr_lowercase[*(ip + 1)]; - else - match = (*input == *(ip + 1)); - action = match ? ACTION_NONE : ACTION_KILL; - fiber->ip += 2; - break; + case RE_OPCODE_LITERAL: + prolog; + if (flags & RE_FLAGS_NO_CASE) + match = yr_lowercase[*input] == yr_lowercase[*(ip + 1)]; + else + match = (*input == *(ip + 1)); + action = match ? ACTION_NONE : ACTION_KILL; + fiber->ip += 2; + break; - case RE_OPCODE_MASKED_LITERAL: - prolog; - value = *(int16_t*)(ip + 1) & 0xFF; - mask = *(int16_t*)(ip + 1) >> 8; + case RE_OPCODE_MASKED_LITERAL: + prolog; + value = *(int16_t*) (ip + 1) & 0xFF; + mask = *(int16_t*) (ip + 1) >> 8; - // We don't need to take into account the case-insensitive - // case because this opcode is only used with hex strings, - // which can't be case-insensitive. + // We don't need to take into account the case-insensitive + // case because this opcode is only used with hex strings, + // which can't be case-insensitive. - match = ((*input & mask) == value); - action = match ? ACTION_NONE : ACTION_KILL; - fiber->ip += 3; - break; + match = ((*input & mask) == value); + action = match ? ACTION_NONE : ACTION_KILL; + fiber->ip += 3; + break; - case RE_OPCODE_CLASS: - prolog; - match = _yr_re_is_char_in_class( - (RE_CLASS*) (ip + 1), *input, flags & RE_FLAGS_NO_CASE); - action = match ? ACTION_NONE : ACTION_KILL; - fiber->ip += (sizeof(RE_CLASS) + 1); - break; + case RE_OPCODE_CLASS: + prolog; + match = _yr_re_is_char_in_class( + (RE_CLASS*) (ip + 1), *input, flags & RE_FLAGS_NO_CASE); + action = match ? ACTION_NONE : ACTION_KILL; + fiber->ip += (sizeof(RE_CLASS) + 1); + break; - case RE_OPCODE_WORD_CHAR: - prolog; - match = _yr_re_is_word_char(input, character_size); - action = match ? ACTION_NONE : ACTION_KILL; - fiber->ip += 1; - break; + case RE_OPCODE_WORD_CHAR: + prolog; + match = _yr_re_is_word_char(input, character_size); + action = match ? ACTION_NONE : ACTION_KILL; + fiber->ip += 1; + break; - case RE_OPCODE_NON_WORD_CHAR: - prolog; - match = !_yr_re_is_word_char(input, character_size); - action = match ? ACTION_NONE : ACTION_KILL; - fiber->ip += 1; - break; + case RE_OPCODE_NON_WORD_CHAR: + prolog; + match = !_yr_re_is_word_char(input, character_size); + action = match ? ACTION_NONE : ACTION_KILL; + fiber->ip += 1; + break; - case RE_OPCODE_SPACE: - case RE_OPCODE_NON_SPACE: + case RE_OPCODE_SPACE: + case RE_OPCODE_NON_SPACE: - prolog; + prolog; - switch (*input) - { - case ' ': - case '\t': - case '\r': - case '\n': - case '\v': - case '\f': - match = true; - break; - default: - match = false; - } + switch (*input) + { + case ' ': + case '\t': + case '\r': + case '\n': + case '\v': + case '\f': + match = true; + break; + default: + match = false; + } - if (*ip == RE_OPCODE_NON_SPACE) - match = !match; + if (*ip == RE_OPCODE_NON_SPACE) + match = !match; - action = match ? ACTION_NONE : ACTION_KILL; - fiber->ip += 1; - break; + action = match ? ACTION_NONE : ACTION_KILL; + fiber->ip += 1; + break; - case RE_OPCODE_DIGIT: - prolog; - match = isdigit(*input); - action = match ? ACTION_NONE : ACTION_KILL; - fiber->ip += 1; - break; + case RE_OPCODE_DIGIT: + prolog; + match = isdigit(*input); + action = match ? ACTION_NONE : ACTION_KILL; + fiber->ip += 1; + break; - case RE_OPCODE_NON_DIGIT: - prolog; - match = !isdigit(*input); - action = match ? ACTION_NONE : ACTION_KILL; - fiber->ip += 1; - break; + case RE_OPCODE_NON_DIGIT: + prolog; + match = !isdigit(*input); + action = match ? ACTION_NONE : ACTION_KILL; + fiber->ip += 1; + break; - case RE_OPCODE_WORD_BOUNDARY: - case RE_OPCODE_NON_WORD_BOUNDARY: + case RE_OPCODE_WORD_BOUNDARY: + case RE_OPCODE_NON_WORD_BOUNDARY: - if (bytes_matched == 0 && input_backwards_size < character_size) - { - match = true; - } - else if (bytes_matched >= max_bytes_matched) - { - match = true; - } - else - { - assert(input < input_data + input_forwards_size); - assert(input >= input_data - input_backwards_size); + if (bytes_matched == 0 && input_backwards_size < character_size) + { + match = true; + } + else if (bytes_matched >= max_bytes_matched) + { + match = true; + } + else + { + assert(input < input_data + input_forwards_size); + assert(input >= input_data - input_backwards_size); - assert(input - input_incr < input_data + input_forwards_size); - assert(input - input_incr >= input_data - input_backwards_size); + assert(input - input_incr < input_data + input_forwards_size); + assert(input - input_incr >= input_data - input_backwards_size); - match = _yr_re_is_word_char(input, character_size) != \ - _yr_re_is_word_char(input - input_incr, character_size); - } + match = _yr_re_is_word_char(input, character_size) != + _yr_re_is_word_char(input - input_incr, character_size); + } - if (*ip == RE_OPCODE_NON_WORD_BOUNDARY) - match = !match; + if (*ip == RE_OPCODE_NON_WORD_BOUNDARY) + match = !match; - action = match ? ACTION_CONTINUE : ACTION_KILL; - fiber->ip += 1; - break; + action = match ? ACTION_CONTINUE : ACTION_KILL; + fiber->ip += 1; + break; - case RE_OPCODE_MATCH_AT_START: - if (flags & RE_FLAGS_BACKWARDS) - kill = input_backwards_size > (size_t) bytes_matched; - else - kill = input_backwards_size > 0 || (bytes_matched != 0); - action = kill ? ACTION_KILL : ACTION_CONTINUE; - fiber->ip += 1; - break; + case RE_OPCODE_MATCH_AT_START: + if (flags & RE_FLAGS_BACKWARDS) + kill = input_backwards_size > (size_t) bytes_matched; + else + kill = input_backwards_size > 0 || (bytes_matched != 0); + action = kill ? ACTION_KILL : ACTION_CONTINUE; + fiber->ip += 1; + break; - case RE_OPCODE_MATCH_AT_END: - kill = flags & RE_FLAGS_BACKWARDS || - input_forwards_size > (size_t) bytes_matched; - action = kill ? ACTION_KILL : ACTION_CONTINUE; - fiber->ip += 1; - break; + case RE_OPCODE_MATCH_AT_END: + kill = flags & RE_FLAGS_BACKWARDS || + input_forwards_size > (size_t) bytes_matched; + action = kill ? ACTION_KILL : ACTION_CONTINUE; + fiber->ip += 1; + break; - case RE_OPCODE_MATCH: + case RE_OPCODE_MATCH: - if (matches != NULL) - *matches = bytes_matched; + if (matches != NULL) + *matches = bytes_matched; - if (flags & RE_FLAGS_EXHAUSTIVE) + if (flags & RE_FLAGS_EXHAUSTIVE) + { + if (callback != NULL) { - if (callback != NULL) + if (flags & RE_FLAGS_BACKWARDS) { - if (flags & RE_FLAGS_BACKWARDS) - { - FAIL_ON_ERROR_WITH_CLEANUP( - callback( - input + character_size, - bytes_matched, - flags, - callback_args), - _yr_re_fiber_kill_all(&fibers, &context->re_fiber_pool)); - } - else - { - FAIL_ON_ERROR_WITH_CLEANUP( - callback( - input_data, - bytes_matched, - flags, - callback_args), - _yr_re_fiber_kill_all(&fibers, &context->re_fiber_pool)); - } + FAIL_ON_ERROR_WITH_CLEANUP( + callback( + input + character_size, + bytes_matched, + flags, + callback_args), + _yr_re_fiber_kill_all(&fibers, &context->re_fiber_pool)); + } + else + { + FAIL_ON_ERROR_WITH_CLEANUP( + callback(input_data, bytes_matched, flags, callback_args), + _yr_re_fiber_kill_all(&fibers, &context->re_fiber_pool)); } - - action = ACTION_KILL; - } - else - { - action = ACTION_KILL_TAIL; } - break; + action = ACTION_KILL; + } + else + { + action = ACTION_KILL_TAIL; + } - default: - assert(false); + break; + + default: + assert(false); } switch (action) { - case ACTION_KILL: - fiber = _yr_re_fiber_kill(&fibers, &context->re_fiber_pool, fiber); - break; + case ACTION_KILL: + fiber = _yr_re_fiber_kill(&fibers, &context->re_fiber_pool, fiber); + break; - case ACTION_KILL_TAIL: - _yr_re_fiber_kill_tail(&fibers, &context->re_fiber_pool, fiber); - fiber = NULL; - break; + case ACTION_KILL_TAIL: + _yr_re_fiber_kill_tail(&fibers, &context->re_fiber_pool, fiber); + fiber = NULL; + break; - case ACTION_CONTINUE: - FAIL_ON_ERROR_WITH_CLEANUP( - _yr_re_fiber_sync(&fibers, &context->re_fiber_pool, fiber), - _yr_re_fiber_kill_all(&fibers, &context->re_fiber_pool)); - break; + case ACTION_CONTINUE: + FAIL_ON_ERROR_WITH_CLEANUP( + _yr_re_fiber_sync(&fibers, &context->re_fiber_pool, fiber), + _yr_re_fiber_kill_all(&fibers, &context->re_fiber_pool)); + break; - default: - next_fiber = fiber->next; - FAIL_ON_ERROR_WITH_CLEANUP( - _yr_re_fiber_sync(&fibers, &context->re_fiber_pool, fiber), - _yr_re_fiber_kill_all(&fibers, &context->re_fiber_pool)); - fiber = next_fiber; + default: + next_fiber = fiber->next; + FAIL_ON_ERROR_WITH_CLEANUP( + _yr_re_fiber_sync(&fibers, &context->re_fiber_pool, fiber), + _yr_re_fiber_kill_all(&fibers, &context->re_fiber_pool)); + fiber = next_fiber; } } @@ -2207,9 +2103,8 @@ int yr_re_fast_exec( size_t bytes_matched; size_t max_bytes_matched; - max_bytes_matched = flags & RE_FLAGS_BACKWARDS ? - input_backwards_size : - input_forwards_size; + max_bytes_matched = flags & RE_FLAGS_BACKWARDS ? input_backwards_size + : input_forwards_size; input_incr = flags & RE_FLAGS_BACKWARDS ? -1 : 1; @@ -2236,10 +2131,10 @@ int yr_re_fast_exec( if (flags & RE_FLAGS_EXHAUSTIVE) { FAIL_ON_ERROR(callback( - flags & RE_FLAGS_BACKWARDS ? input + 1 : input_data, - bytes_matched, - flags, - callback_args)); + flags & RE_FLAGS_BACKWARDS ? input + 1 : input_data, + bytes_matched, + flags, + callback_args)); break; } @@ -2257,82 +2152,82 @@ int yr_re_fast_exec( switch (*ip) { - case RE_OPCODE_LITERAL: + case RE_OPCODE_LITERAL: - if (*input == *(ip + 1)) - { - bytes_matched++; - input += input_incr; - ip += 2; - } - else - { - stop = true; - } + if (*input == *(ip + 1)) + { + bytes_matched++; + input += input_incr; + ip += 2; + } + else + { + stop = true; + } - break; + break; - case RE_OPCODE_MASKED_LITERAL: + case RE_OPCODE_MASKED_LITERAL: - value = *(int16_t*)(ip + 1) & 0xFF; - mask = *(int16_t*)(ip + 1) >> 8; + value = *(int16_t*) (ip + 1) & 0xFF; + mask = *(int16_t*) (ip + 1) >> 8; - if ((*input & mask) == value) - { - bytes_matched++; - input += input_incr; - ip += 3; - } - else - { - stop = true; - } + if ((*input & mask) == value) + { + bytes_matched++; + input += input_incr; + ip += 3; + } + else + { + stop = true; + } - break; + break; - case RE_OPCODE_ANY: + case RE_OPCODE_ANY: - bytes_matched++; - input += input_incr; - ip += 1; + bytes_matched++; + input += input_incr; + ip += 1; - break; + break; - case RE_OPCODE_REPEAT_ANY_UNGREEDY: + case RE_OPCODE_REPEAT_ANY_UNGREEDY: - repeat_any_args = (RE_REPEAT_ANY_ARGS*)(ip + 1); - next_opcode = ip + 1 + sizeof(RE_REPEAT_ANY_ARGS); + repeat_any_args = (RE_REPEAT_ANY_ARGS*) (ip + 1); + next_opcode = ip + 1 + sizeof(RE_REPEAT_ANY_ARGS); - for (i = repeat_any_args->min + 1; i <= repeat_any_args->max; i++) - { - if (bytes_matched + i >= max_bytes_matched) - break; + for (i = repeat_any_args->min + 1; i <= repeat_any_args->max; i++) + { + if (bytes_matched + i >= max_bytes_matched) + break; - next_input = input + i * input_incr; + next_input = input + i * input_incr; - if ( *(next_opcode) != RE_OPCODE_LITERAL || - (*(next_opcode) == RE_OPCODE_LITERAL && - *(next_opcode + 1) == *next_input)) - { - if (sp >= YR_MAX_FAST_RE_STACK) - return ERROR_TOO_MANY_RE_FIBERS; + if (*(next_opcode) != RE_OPCODE_LITERAL || + (*(next_opcode) == RE_OPCODE_LITERAL && + *(next_opcode + 1) == *next_input)) + { + if (sp >= YR_MAX_FAST_RE_STACK) + return ERROR_TOO_MANY_RE_FIBERS; - code_stack[sp] = next_opcode; - input_stack[sp] = next_input; - matches_stack[sp] = bytes_matched + i; - sp++; - } + code_stack[sp] = next_opcode; + input_stack[sp] = next_input; + matches_stack[sp] = bytes_matched + i; + sp++; } + } - input += input_incr * repeat_any_args->min; - bytes_matched += repeat_any_args->min; - bytes_matched = yr_min(bytes_matched, max_bytes_matched); - ip = next_opcode; + input += input_incr * repeat_any_args->min; + bytes_matched += repeat_any_args->min; + bytes_matched = yr_min(bytes_matched, max_bytes_matched); + ip = next_opcode; - break; + break; - default: - assert(false); + default: + assert(false); } } } @@ -2344,9 +2239,7 @@ int yr_re_fast_exec( } -static void _yr_re_print_node( - RE_NODE* re_node, - uint32_t indent) +static void _yr_re_print_node(RE_NODE* re_node, uint32_t indent) { RE_NODE* child; int i; @@ -2363,7 +2256,7 @@ static void _yr_re_print_node( _yr_re_print_node(re_node->children_head, indent + 4); printf(","); _yr_re_print_node(re_node->children_tail, indent + 4); - printf("\n%*s%s", indent, " " , ")"); + printf("\n%*s%s", indent, " ", ")"); break; case RE_NODE_CONCAT: @@ -2446,8 +2339,7 @@ static void _yr_re_print_node( } } -void yr_re_print( - RE_AST* re_ast) +void yr_re_print(RE_AST* re_ast) { _yr_re_print_node(re_ast->root_node, 0); } diff --git a/libyara/re_grammar.c b/libyara/re_grammar.c index f0218a427d..1947ffb388 100644 --- a/libyara/re_grammar.c +++ b/libyara/re_grammar.c @@ -60,73 +60,73 @@ /* Substitute the variable and function names. */ -#define yyparse re_yyparse -#define yylex re_yylex -#define yyerror re_yyerror -#define yydebug re_yydebug -#define yynerrs re_yynerrs +#define yyparse re_yyparse +#define yylex re_yylex +#define yyerror re_yyerror +#define yydebug re_yydebug +#define yynerrs re_yynerrs /* Copy the first part of user declarations. */ #line 30 "re_grammar.y" /* yacc.c:339 */ -#include -#include #include +#include #include #include #include #include +#include #define YYERROR_VERBOSE #define YYMALLOC yr_malloc -#define YYFREE yr_free +#define YYFREE yr_free #define mark_as_not_fast_regexp() \ - ((RE_AST*) yyget_extra(yyscanner))->flags &= ~RE_FLAGS_FAST_REGEXP + ((RE_AST *) yyget_extra(yyscanner))->flags &= ~RE_FLAGS_FAST_REGEXP -#define fail_if(x, error) \ - if (x) \ - { \ - lex_env->last_error = error; \ - YYABORT; \ - } \ +#define fail_if(x, error) \ + if (x) \ + { \ + lex_env->last_error = error; \ + YYABORT; \ + } #define destroy_node_if(x, node) \ - if (x) \ - { \ - yr_re_node_destroy(node); \ - } \ + if (x) \ + { \ + yr_re_node_destroy(node); \ + } #line 106 "re_grammar.c" /* yacc.c:339 */ -# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# endif +#ifndef YY_NULLPTR +#if defined __cplusplus && 201103L <= __cplusplus +#define YY_NULLPTR nullptr +#else +#define YY_NULLPTR 0 +#endif +#endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 +#undef YYERROR_VERBOSE +#define YYERROR_VERBOSE 1 #else -# define YYERROR_VERBOSE 0 +#define YYERROR_VERBOSE 0 #endif /* In a future release of Bison, this section will be replaced by #include "y.tab.h". */ #ifndef YY_RE_YY_RE_GRAMMAR_H_INCLUDED -# define YY_RE_YY_RE_GRAMMAR_H_INCLUDED +#define YY_RE_YY_RE_GRAMMAR_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG -# define YYDEBUG 0 +#define YYDEBUG 0 #endif #if YYDEBUG extern int re_yydebug; @@ -134,39 +134,39 @@ extern int re_yydebug; /* Token type. */ #ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - _CHAR_ = 258, - _ANY_ = 259, - _RANGE_ = 260, - _CLASS_ = 261, - _WORD_CHAR_ = 262, - _NON_WORD_CHAR_ = 263, - _SPACE_ = 264, - _NON_SPACE_ = 265, - _DIGIT_ = 266, - _NON_DIGIT_ = 267, - _WORD_BOUNDARY_ = 268, - _NON_WORD_BOUNDARY_ = 269 - }; +#define YYTOKENTYPE +enum yytokentype +{ + _CHAR_ = 258, + _ANY_ = 259, + _RANGE_ = 260, + _CLASS_ = 261, + _WORD_CHAR_ = 262, + _NON_WORD_CHAR_ = 263, + _SPACE_ = 264, + _NON_SPACE_ = 265, + _DIGIT_ = 266, + _NON_DIGIT_ = 267, + _WORD_BOUNDARY_ = 268, + _NON_WORD_BOUNDARY_ = 269 +}; #endif /* Tokens. */ -#define _CHAR_ 258 -#define _ANY_ 259 -#define _RANGE_ 260 -#define _CLASS_ 261 -#define _WORD_CHAR_ 262 -#define _NON_WORD_CHAR_ 263 -#define _SPACE_ 264 -#define _NON_SPACE_ 265 -#define _DIGIT_ 266 -#define _NON_DIGIT_ 267 -#define _WORD_BOUNDARY_ 268 +#define _CHAR_ 258 +#define _ANY_ 259 +#define _RANGE_ 260 +#define _CLASS_ 261 +#define _WORD_CHAR_ 262 +#define _NON_WORD_CHAR_ 263 +#define _SPACE_ 264 +#define _NON_SPACE_ 265 +#define _DIGIT_ 266 +#define _NON_DIGIT_ 267 +#define _WORD_BOUNDARY_ 268 #define _NON_WORD_BOUNDARY_ 269 /* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED union YYSTYPE { @@ -174,20 +174,19 @@ union YYSTYPE int integer; uint32_t range; - RE_NODE* re_node; - RE_CLASS* re_class; + RE_NODE *re_node; + RE_CLASS *re_class; #line 181 "re_grammar.c" /* yacc.c:355 */ }; typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 +#define YYSTYPE_IS_TRIVIAL 1 +#define YYSTYPE_IS_DECLARED 1 #endif - -int re_yyparse (void *yyscanner, RE_LEX_ENVIRONMENT *lex_env); +int re_yyparse(void *yyscanner, RE_LEX_ENVIRONMENT *lex_env); #endif /* !YY_RE_YY_RE_GRAMMAR_H_INCLUDED */ @@ -196,7 +195,7 @@ int re_yyparse (void *yyscanner, RE_LEX_ENVIRONMENT *lex_env); #line 197 "re_grammar.c" /* yacc.c:358 */ #ifdef short -# undef short +#undef short #endif #ifdef YYTYPE_UINT8 @@ -224,157 +223,163 @@ typedef short int yytype_int16; #endif #ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif ! defined YYSIZE_T -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned int -# endif +#ifdef __SIZE_TYPE__ +#define YYSIZE_T __SIZE_TYPE__ +#elif defined size_t +#define YYSIZE_T size_t +#elif !defined YYSIZE_T +#include /* INFRINGES ON USER NAME SPACE */ +#define YYSIZE_T size_t +#else +#define YYSIZE_T unsigned int +#endif #endif #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) -# endif -# endif -# ifndef YY_ -# define YY_(Msgid) Msgid -# endif +#if defined YYENABLE_NLS && YYENABLE_NLS +#if ENABLE_NLS +#include /* INFRINGES ON USER NAME SPACE */ +#define YY_(Msgid) dgettext("bison-runtime", Msgid) +#endif +#endif +#ifndef YY_ +#define YY_(Msgid) Msgid +#endif #endif #ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif +#if ( \ + defined __GNUC__ && \ + (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) || \ + defined __SUNPRO_C && 0x5110 <= __SUNPRO_C +#define YY_ATTRIBUTE(Spec) __attribute__(Spec) +#else +#define YY_ATTRIBUTE(Spec) /* empty */ +#endif #endif #ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#define YY_ATTRIBUTE_PURE YY_ATTRIBUTE((__pure__)) #endif #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +#define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE((__unused__)) #endif -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) -# endif +#if !defined _Noreturn && \ + (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) +#if defined _MSC_VER && 1200 <= _MSC_VER +#define _Noreturn __declspec(noreturn) +#else +#define _Noreturn YY_ATTRIBUTE((__noreturn__)) +#endif #endif /* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +#if !defined lint || defined __GNUC__ +#define YYUSE(E) ((void) (E)) #else -# define YYUSE(E) /* empty */ +#define YYUSE(E) /* empty */ #endif #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") +#define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +#define YY_IGNORE_MAYBE_UNINITIALIZED_END _Pragma("GCC diagnostic pop") #else -# define YY_INITIAL_VALUE(Value) Value +#define YY_INITIAL_VALUE(Value) Value #endif #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +#define YY_IGNORE_MAYBE_UNINITIALIZED_END #endif #ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif -#if ! defined yyoverflow || YYERROR_VERBOSE +#if !defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ -# ifdef YYSTACK_USE_ALLOCA -# if YYSTACK_USE_ALLOCA -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# elif defined __BUILTIN_VA_ARG_INCR -# include /* INFRINGES ON USER NAME SPACE */ -# elif defined _AIX -# define YYSTACK_ALLOC __alloca -# elif defined _MSC_VER -# include /* INFRINGES ON USER NAME SPACE */ -# define alloca _alloca -# else -# define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS -# include /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's 'empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# ifndef YYSTACK_ALLOC_MAXIMUM - /* The OS might guarantee only one guard page at the bottom of the stack, - and a page size can be as small as 4096 bytes. So we cannot safely - invoke alloca (N) if N exceeds 4096. Use a slightly smaller number - to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ -# endif -# else -# define YYSTACK_ALLOC YYMALLOC -# define YYSTACK_FREE YYFREE -# ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM -# endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) -# include /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# ifndef YYMALLOC -# define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS -void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# ifndef YYFREE -# define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS -void free (void *); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# endif +#ifdef YYSTACK_USE_ALLOCA +#if YYSTACK_USE_ALLOCA +#ifdef __GNUC__ +#define YYSTACK_ALLOC __builtin_alloca +#elif defined __BUILTIN_VA_ARG_INCR +#include /* INFRINGES ON USER NAME SPACE */ +#elif defined _AIX +#define YYSTACK_ALLOC __alloca +#elif defined _MSC_VER +#include /* INFRINGES ON USER NAME SPACE */ +#define alloca _alloca +#else +#define YYSTACK_ALLOC alloca +#if !defined _ALLOCA_H && !defined EXIT_SUCCESS +#include /* INFRINGES ON USER NAME SPACE */ +/* Use EXIT_SUCCESS as a witness for stdlib.h. */ +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#endif +#endif +#endif +#endif + +#ifdef YYSTACK_ALLOC +/* Pacify GCC's 'empty if-body' warning. */ +#define YYSTACK_FREE(Ptr) \ + do \ + { /* empty */ \ + ; \ + } while (0) +#ifndef YYSTACK_ALLOC_MAXIMUM +/* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +#define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +#endif +#else +#define YYSTACK_ALLOC YYMALLOC +#define YYSTACK_FREE YYFREE +#ifndef YYSTACK_ALLOC_MAXIMUM +#define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +#endif +#if ( \ + defined __cplusplus && !defined EXIT_SUCCESS && \ + !((defined YYMALLOC || defined malloc) && \ + (defined YYFREE || defined free))) +#include /* INFRINGES ON USER NAME SPACE */ +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#endif +#ifndef YYMALLOC +#define YYMALLOC malloc +#if !defined malloc && !defined EXIT_SUCCESS +void *malloc(YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +#endif +#endif +#ifndef YYFREE +#define YYFREE free +#if !defined free && !defined EXIT_SUCCESS +void free(void *); /* INFRINGES ON USER NAME SPACE */ +#endif +#endif +#endif #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ -#if (! defined yyoverflow \ - && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) +#if ( \ + !defined yyoverflow && \ + (!defined __cplusplus || \ + (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc @@ -384,322 +389,289 @@ union yyalloc }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +#define YYSTACK_GAP_MAXIMUM (sizeof(union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) +#define YYSTACK_BYTES(N) \ + ((N) * (sizeof(yytype_int16) + sizeof(YYSTYPE)) + YYSTACK_GAP_MAXIMUM) -# define YYCOPY_NEEDED 1 +#define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (0) +#define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY(&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof(*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof(*yyptr); \ + } while (0) #endif #if defined YYCOPY_NEEDED && YYCOPY_NEEDED /* Copy COUNT objects from SRC to DST. The source and destination do not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) -# else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ - while (0) -# endif -# endif +#ifndef YYCOPY +#if defined __GNUC__ && 1 < __GNUC__ +#define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy(Dst, Src, (Count) * sizeof(*(Src))) +#else +#define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) (Dst)[yyi] = (Src)[yyi]; \ + } while (0) +#endif +#endif #endif /* !YYCOPY_NEEDED */ /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 22 +#define YYFINAL 22 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 45 +#define YYLAST 45 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 24 +#define YYNTOKENS 24 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 6 +#define YYNNTS 6 /* YYNRULES -- Number of rules. */ -#define YYNRULES 31 +#define YYNRULES 31 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 35 +#define YYNSTATES 35 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned by yylex, with out-of-bounds checking. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 269 +#define YYUNDEFTOK 2 +#define YYMAXUTOK 269 -#define YYTRANSLATE(YYX) \ +#define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex, without out-of-bounds checking. */ -static const yytype_uint8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 20, 2, 2, 2, - 21, 22, 16, 18, 2, 2, 23, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 17, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 19, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 15, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 -}; +static const yytype_uint8 yytranslate[] = { + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 20, 2, 2, 2, 21, 22, + 16, 18, 2, 2, 23, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 17, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 19, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 15, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; #if YYDEBUG - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = -{ - 0, 104, 104, 109, 113, 117, 131, 155, 164, 172, - 188, 206, 222, 239, 262, 286, 309, 333, 337, 343, - 349, 355, 364, 368, 377, 386, 392, 398, 404, 410, - 416, 422 -}; +/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = {0, 104, 104, 109, 113, 117, 131, 155, + 164, 172, 188, 206, 222, 239, 262, 286, + 309, 333, 337, 343, 349, 355, 364, 368, + 377, 386, 392, 398, 404, 410, 416, 422}; #endif #if YYDEBUG || YYERROR_VERBOSE || 0 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "$end", "error", "$undefined", "_CHAR_", "_ANY_", "_RANGE_", "_CLASS_", - "_WORD_CHAR_", "_NON_WORD_CHAR_", "_SPACE_", "_NON_SPACE_", "_DIGIT_", - "_NON_DIGIT_", "_WORD_BOUNDARY_", "_NON_WORD_BOUNDARY_", "'|'", "'*'", - "'?'", "'+'", "'^'", "'$'", "'('", "')'", "'.'", "$accept", "re", - "alternative", "concatenation", "repeat", "single", YY_NULLPTR -}; +static const char *const yytname[] = { + "$end", + "error", + "$undefined", + "_CHAR_", + "_ANY_", + "_RANGE_", + "_CLASS_", + "_WORD_CHAR_", + "_NON_WORD_CHAR_", + "_SPACE_", + "_NON_SPACE_", + "_DIGIT_", + "_NON_DIGIT_", + "_WORD_BOUNDARY_", + "_NON_WORD_BOUNDARY_", + "'|'", + "'*'", + "'?'", + "'+'", + "'^'", + "'$'", + "'('", + "')'", + "'.'", + "$accept", + "re", + "alternative", + "concatenation", + "repeat", + "single", + YY_NULLPTR}; #endif -# ifdef YYPRINT +#ifdef YYPRINT /* YYTOKNUM[NUM] -- (External) token number corresponding to the (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 124, 42, 63, 43, 94, - 36, 40, 41, 46 -}; -# endif +static const yytype_uint16 yytoknum[] = {0, 256, 257, 258, 259, 260, 261, 262, + 263, 264, 265, 266, 267, 268, 269, 124, + 42, 63, 43, 94, 36, 40, 41, 46}; +#endif #define YYPACT_NINF -12 -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-12))) +#define yypact_value_is_default(Yystate) (!!((Yystate) == (-12))) #define YYTABLE_NINF -1 -#define yytable_value_is_error(Yytable_value) \ - 0 - - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -static const yytype_int8 yypact[] = -{ - -1, -12, -12, -12, -12, -12, -12, -12, -12, -12, - -12, -12, -12, -12, 18, -12, 1, -11, 18, -12, - -2, 21, -12, 18, -12, 0, 16, 17, 23, -12, - 18, -12, -12, -12, -12 -}; - - /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 0, 3, 24, 31, 25, 26, 27, 28, 29, 30, - 18, 19, 20, 21, 0, 23, 0, 2, 4, 7, - 17, 0, 1, 6, 8, 15, 9, 13, 11, 22, - 5, 16, 10, 14, 12 -}; - - /* YYPGOTO[NTERM-NUM]. */ -static const yytype_int8 yypgoto[] = -{ - -12, -12, 28, 22, 5, -12 -}; - - /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int8 yydefgoto[] = -{ - -1, 16, 17, 18, 19, 20 -}; - - /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_uint8 yytable[] = -{ - 1, 22, 2, 25, 23, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 26, 27, 28, 31, 12, 13, - 14, 2, 15, 24, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 32, 33, 24, 23, 12, 13, 14, - 34, 15, 21, 29, 0, 30 -}; - -static const yytype_int8 yycheck[] = -{ - 1, 0, 3, 5, 15, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 16, 17, 18, 17, 19, 20, - 21, 3, 23, 18, 6, 7, 8, 9, 10, 11, - 12, 13, 14, 17, 17, 30, 15, 19, 20, 21, - 17, 23, 14, 22, -1, 23 -}; - - /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = -{ - 0, 1, 3, 6, 7, 8, 9, 10, 11, 12, - 13, 14, 19, 20, 21, 23, 25, 26, 27, 28, - 29, 26, 0, 15, 28, 5, 16, 17, 18, 22, - 27, 17, 17, 17, 17 -}; - - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 24, 25, 25, 26, 26, 26, 27, 27, 28, - 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, - 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, - 29, 29 -}; - - /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 1, 1, 1, 3, 2, 1, 2, 2, - 3, 2, 3, 2, 3, 2, 3, 1, 1, 1, - 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, - 1, 1 -}; - - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab - - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (yyscanner, lex_env, YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (0) +#define yytable_value_is_error(Yytable_value) 0 + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int8 yypact[] = { + -1, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, + -12, -12, 18, -12, 1, -11, 18, -12, -2, 21, -12, 18, + -12, 0, 16, 17, 23, -12, 18, -12, -12, -12, -12}; + +/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = { + 0, 3, 24, 31, 25, 26, 27, 28, 29, 30, 18, 19, 20, 21, 0, 23, 0, 2, + 4, 7, 17, 0, 1, 6, 8, 15, 9, 13, 11, 22, 5, 16, 10, 14, 12}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int8 yypgoto[] = {-12, -12, 28, 22, 5, -12}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = {-1, 16, 17, 18, 19, 20}; + +/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_uint8 yytable[] = { + 1, 22, 2, 25, 23, 3, 4, 5, 6, 7, 8, 9, 10, 11, 26, 27, + 28, 31, 12, 13, 14, 2, 15, 24, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 32, 33, 24, 23, 12, 13, 14, 34, 15, 21, 29, 0, 30}; + +static const yytype_int8 yycheck[] = { + 1, 0, 3, 5, 15, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, + 18, 17, 19, 20, 21, 3, 23, 18, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 17, 17, 30, 15, 19, 20, 21, 17, 23, 14, 22, -1, 23}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = { + 0, 1, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 19, 20, 21, 23, 25, 26, + 27, 28, 29, 26, 0, 15, 28, 5, 16, 17, 18, 22, 27, 17, 17, 17, 17}; + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = {0, 24, 25, 25, 26, 26, 26, 27, 27, 28, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29}; + +/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = {0, 2, 1, 1, 1, 3, 2, 1, 2, 2, 3, + 2, 3, 2, 3, 2, 3, 1, 1, 1, 1, 1, + 3, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK(yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror(yyscanner, lex_env, YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) /* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - +#define YYTERROR 1 +#define YYERRCODE 256 /* Enable debugging if requested. */ #if YYDEBUG -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif +#ifndef YYFPRINTF +#include /* INFRINGES ON USER NAME SPACE */ +#define YYFPRINTF fprintf +#endif -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) +#define YYDPRINTF(Args) \ + do \ + { \ + if (yydebug) \ + YYFPRINTF Args; \ + } while (0) /* This macro is provided for backward compatibility. */ #ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#define YY_LOCATION_PRINT(File, Loc) ((void) 0) #endif -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value, yyscanner, lex_env); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) +#define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ + do \ + { \ + if (yydebug) \ + { \ + YYFPRINTF(stderr, "%s ", Title); \ + yy_symbol_print(stderr, Type, Value, yyscanner, lex_env); \ + YYFPRINTF(stderr, "\n"); \ + } \ + } while (0) /*----------------------------------------. | Print this symbol's value on YYOUTPUT. | `----------------------------------------*/ -static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *yyscanner, RE_LEX_ENVIRONMENT *lex_env) +static void yy_symbol_value_print( + FILE *yyoutput, + int yytype, + YYSTYPE const *const yyvaluep, + void *yyscanner, + RE_LEX_ENVIRONMENT *lex_env) { FILE *yyo = yyoutput; - YYUSE (yyo); - YYUSE (yyscanner); - YYUSE (lex_env); + YYUSE(yyo); + YYUSE(yyscanner); + YYUSE(lex_env); if (!yyvaluep) return; -# ifdef YYPRINT +#ifdef YYPRINT if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - YYUSE (yytype); + YYPRINT(yyoutput, yytoknum[yytype], *yyvaluep); +#endif + YYUSE(yytype); } @@ -707,14 +679,21 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue | Print this symbol on YYOUTPUT. | `--------------------------------*/ -static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *yyscanner, RE_LEX_ENVIRONMENT *lex_env) +static void yy_symbol_print( + FILE *yyoutput, + int yytype, + YYSTYPE const *const yyvaluep, + void *yyscanner, + RE_LEX_ENVIRONMENT *lex_env) { - YYFPRINTF (yyoutput, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); - - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yyscanner, lex_env); - YYFPRINTF (yyoutput, ")"); + YYFPRINTF( + yyoutput, + "%s %s (", + yytype < YYNTOKENS ? "token" : "nterm", + yytname[yytype]); + + yy_symbol_value_print(yyoutput, yytype, yyvaluep, yyscanner, lex_env); + YYFPRINTF(yyoutput, ")"); } /*------------------------------------------------------------------. @@ -722,69 +701,76 @@ yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, voi | TOP (included). | `------------------------------------------------------------------*/ -static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +static void yy_stack_print(yytype_int16 *yybottom, yytype_int16 *yytop) { - YYFPRINTF (stderr, "Stack now"); + YYFPRINTF(stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) - { - int yybot = *yybottom; - YYFPRINTF (stderr, " %d", yybot); - } - YYFPRINTF (stderr, "\n"); + { + int yybot = *yybottom; + YYFPRINTF(stderr, " %d", yybot); + } + YYFPRINTF(stderr, "\n"); } -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (0) +#define YY_STACK_PRINT(Bottom, Top) \ + do \ + { \ + if (yydebug) \ + yy_stack_print((Bottom), (Top)); \ + } while (0) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, void *yyscanner, RE_LEX_ENVIRONMENT *lex_env) +static void yy_reduce_print( + yytype_int16 *yyssp, + YYSTYPE *yyvsp, + int yyrule, + void *yyscanner, + RE_LEX_ENVIRONMENT *lex_env) { unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); + YYFPRINTF( + stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) - { - YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &(yyvsp[(yyi + 1) - (yynrhs)]) - , yyscanner, lex_env); - YYFPRINTF (stderr, "\n"); - } + { + YYFPRINTF(stderr, " $%d = ", yyi + 1); + yy_symbol_print( + stderr, + yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)]), + yyscanner, + lex_env); + YYFPRINTF(stderr, "\n"); + } } -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, Rule, yyscanner, lex_env); \ -} while (0) +#define YY_REDUCE_PRINT(Rule) \ + do \ + { \ + if (yydebug) \ + yy_reduce_print(yyssp, yyvsp, Rule, yyscanner, lex_env); \ + } while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) +#define YYDPRINTF(Args) +#define YY_SYMBOL_PRINT(Title, Type, Value, Location) +#define YY_STACK_PRINT(Bottom, Top) +#define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH -# define YYINITDEPTH 200 +#define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only @@ -795,49 +781,45 @@ int yydebug; evaluated with infinite-precision integer arithmetic. */ #ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 +#define YYMAXDEPTH 10000 #endif #if YYERROR_VERBOSE -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else +#ifndef yystrlen +#if defined __GLIBC__ && defined _STRING_H +#define yystrlen strlen +#else /* Return the length of YYSTR. */ -static YYSIZE_T -yystrlen (const char *yystr) +static YYSIZE_T yystrlen(const char *yystr) { YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; + for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; } -# endif -# endif +#endif +#endif -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else +#ifndef yystpcpy +#if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +#define yystpcpy stpcpy +#else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ -static char * -yystpcpy (char *yydest, const char *yysrc) +static char *yystpcpy(char *yydest, const char *yysrc) { char *yyd = yydest; const char *yys = yysrc; - while ((*yyd++ = *yys++) != '\0') - continue; + while ((*yyd++ = *yys++) != '\0') continue; return yyd - 1; } -# endif -# endif +#endif +#endif -# ifndef yytnamerr +#ifndef yytnamerr /* Copy to YYRES the contents of YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is that double-quoting is unnecessary unless the string @@ -845,45 +827,43 @@ yystpcpy (char *yydest, const char *yysrc) backslash-backslash). YYSTR is taken from yytname. If YYRES is null, do not copy; instead, return the length of what the result would have been. */ -static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) +static YYSIZE_T yytnamerr(char *yyres, const char *yystr) { if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; + for (;;) switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes:; + } - if (! yyres) - return yystrlen (yystr); + if (!yyres) + return yystrlen(yystr); - return yystpcpy (yyres, yystr) - yyres; + return yystpcpy(yyres, yystr) - yyres; } -# endif +#endif /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message about the unexpected token YYTOKEN for the state stack whose top is @@ -893,13 +873,18 @@ yytnamerr (char *yyres, const char *yystr) not large enough to hold the message. In that case, also set *YYMSG_ALLOC to the required number of bytes. Return 2 if the required number of bytes is too large to store. */ -static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) +static int yysyntax_error( + YYSIZE_T *yymsg_alloc, + char **yymsg, + yytype_int16 *yyssp, + int yytoken) { - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + YYSIZE_T yysize0 = yytnamerr(YY_NULLPTR, yytname[yytoken]); YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + enum + { + YYERROR_VERBOSE_ARGS_MAXIMUM = 5 + }; /* Internationalized format string. */ const char *yyformat = YY_NULLPTR; /* Arguments of yyformat. */ @@ -932,73 +917,72 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, accepted due to an error action in a later state. */ if (yytoken != YYEMPTY) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default(yyn)) { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR && + !yytable_value_is_error(yytable[yyx + yyn])) { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = yysize + yytnamerr(YY_NULLPTR, yytname[yyx]); + if (!(yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } } } + } switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - default: /* Avoid compiler warnings. */ - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: /* Avoid compiler warnings. */ + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_( + 5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + YYSIZE_T yysize1 = yysize + yystrlen(yyformat); + if (!(yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) return 2; yysize = yysize1; } if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } + { + *yymsg_alloc = 2 * yysize; + if (!(yysize <= *yymsg_alloc && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } /* Avoid sprintf, as that infringes on the user's name space. Don't have undefined behavior even if the translation @@ -1008,15 +992,15 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, int yyi = 0; while ((*yyp = *yyformat) != '\0') if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } + { + yyp += yytnamerr(yyp, yyarg[yyi++]); + yyformat += 2; + } else - { - yyp++; - yyformat++; - } + { + yyp++; + yyformat++; + } } return 0; } @@ -1026,101 +1010,117 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, | Release the memory associated to this symbol. | `-----------------------------------------------*/ -static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, void *yyscanner, RE_LEX_ENVIRONMENT *lex_env) +static void yydestruct( + const char *yymsg, + int yytype, + YYSTYPE *yyvaluep, + void *yyscanner, + RE_LEX_ENVIRONMENT *lex_env) { - YYUSE (yyvaluep); - YYUSE (yyscanner); - YYUSE (lex_env); + YYUSE(yyvaluep); + YYUSE(yyscanner); + YYUSE(lex_env); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT(yymsg, yytype, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN switch (yytype) - { - case 6: /* _CLASS_ */ + { + case 6: /* _CLASS_ */ #line 96 "re_grammar.y" /* yacc.c:1258 */ - { yr_free(((*yyvaluep).re_class)); ((*yyvaluep).re_class) = NULL; } + { + yr_free(((*yyvaluep).re_class)); + ((*yyvaluep).re_class) = NULL; + } #line 1046 "re_grammar.c" /* yacc.c:1258 */ - break; + break; - case 26: /* alternative */ + case 26: /* alternative */ #line 97 "re_grammar.y" /* yacc.c:1258 */ - { yr_re_node_destroy(((*yyvaluep).re_node)); ((*yyvaluep).re_node) = NULL; } + { + yr_re_node_destroy(((*yyvaluep).re_node)); + ((*yyvaluep).re_node) = NULL; + } #line 1052 "re_grammar.c" /* yacc.c:1258 */ - break; + break; - case 27: /* concatenation */ + case 27: /* concatenation */ #line 98 "re_grammar.y" /* yacc.c:1258 */ - { yr_re_node_destroy(((*yyvaluep).re_node)); ((*yyvaluep).re_node) = NULL; } + { + yr_re_node_destroy(((*yyvaluep).re_node)); + ((*yyvaluep).re_node) = NULL; + } #line 1058 "re_grammar.c" /* yacc.c:1258 */ - break; + break; - case 28: /* repeat */ + case 28: /* repeat */ #line 99 "re_grammar.y" /* yacc.c:1258 */ - { yr_re_node_destroy(((*yyvaluep).re_node)); ((*yyvaluep).re_node) = NULL; } + { + yr_re_node_destroy(((*yyvaluep).re_node)); + ((*yyvaluep).re_node) = NULL; + } #line 1064 "re_grammar.c" /* yacc.c:1258 */ - break; + break; - case 29: /* single */ + case 29: /* single */ #line 100 "re_grammar.y" /* yacc.c:1258 */ - { yr_re_node_destroy(((*yyvaluep).re_node)); ((*yyvaluep).re_node) = NULL; } + { + yr_re_node_destroy(((*yyvaluep).re_node)); + ((*yyvaluep).re_node) = NULL; + } #line 1070 "re_grammar.c" /* yacc.c:1258 */ - break; + break; - default: - break; - } + default: + break; + } YY_IGNORE_MAYBE_UNINITIALIZED_END } - - /*----------. | yyparse. | `----------*/ -int -yyparse (void *yyscanner, RE_LEX_ENVIRONMENT *lex_env) +int yyparse(void *yyscanner, RE_LEX_ENVIRONMENT *lex_env) { -/* The lookahead symbol. */ -int yychar; + /* The lookahead symbol. */ + int yychar; -/* The semantic value of the lookahead symbol. */ -/* Default value used for initialization, for pacifying older GCCs - or non-GCC compilers. */ -YY_INITIAL_VALUE (static YYSTYPE yyval_default;) -YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); + /* The semantic value of the lookahead symbol. */ + /* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ + YY_INITIAL_VALUE(static YYSTYPE yyval_default;) + YYSTYPE yylval YY_INITIAL_VALUE(= yyval_default); - /* Number of syntax errors so far. */ - int yynerrs; + /* Number of syntax errors so far. */ + int yynerrs; - int yystate; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. + /* The stacks and their tools: + 'yyss': related to states. + 'yyvs': related to semantic values. - Refer to the stacks through separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; - YYSIZE_T yystacksize; + YYSIZE_T yystacksize; int yyn; int yyresult; @@ -1137,7 +1137,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ @@ -1147,7 +1147,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yyvsp = yyvs = yyvsa; yystacksize = YYINITDEPTH; - YYDPRINTF ((stderr, "Starting parse\n")); + YYDPRINTF((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; @@ -1155,79 +1155,84 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; -/*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | -`------------------------------------------------------------*/ - yynewstate: + /*------------------------------------------------------------. + | yynewstate -- Push a new state, which is found in yystate. | + `------------------------------------------------------------*/ +yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; - yysetstate: +yysetstate: *yyssp = yystate; if (yyss + yystacksize - 1 <= yyssp) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; - } + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow( + YY_("memory exhausted"), + &yyss1, + yysize * sizeof(*yyssp), + &yyvs1, + yysize * sizeof(*yyvsp), + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } #else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE +#ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +#else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; -# else - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; - { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC( + YYSTACK_BYTES(yystacksize)); + if (!yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE(yyss_alloc, yyss); + YYSTACK_RELOCATE(yyvs_alloc, yyvs); +#undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE(yyss1); + } +#endif #endif /* no yyoverflow */ - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); + YYDPRINTF( + (stderr, + "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YYDPRINTF((stderr, "Entering state %d\n", yystate)); if (yystate == YYFINAL) YYACCEPT; @@ -1244,28 +1249,28 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) + if (yypact_value_is_default(yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (&yylval, yyscanner, lex_env); - } + { + YYDPRINTF((stderr, "Reading a token: ")); + yychar = yylex(&yylval, yyscanner, lex_env); + } if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } + { + yychar = yytoken = YYEOF; + YYDPRINTF((stderr, "Now at end of input.\n")); + } else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } + { + yytoken = YYTRANSLATE(yychar); + YY_SYMBOL_PRINT("Next token is", yytoken, &yylval, &yylloc); + } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ @@ -1274,12 +1279,12 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) - { - if (yytable_value_is_error (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } + { + if (yytable_value_is_error(yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } /* Count tokens shifted since error; after three, turn off error status. */ @@ -1287,7 +1292,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yyerrstatus--; /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + YY_SYMBOL_PRINT("Shifting", yytoken, &yylval, &yylloc); /* Discard the shifted token. */ yychar = YYEMPTY; @@ -1325,445 +1330,450 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; + yyval = yyvsp[1 - yylen]; - YY_REDUCE_PRINT (yyn); + YY_REDUCE_PRINT(yyn); switch (yyn) - { - case 2: + { + case 2: #line 105 "re_grammar.y" /* yacc.c:1663 */ - { - RE_AST* re_ast = yyget_extra(yyscanner); - re_ast->root_node = (yyvsp[0].re_node); - } + { + RE_AST *re_ast = yyget_extra(yyscanner); + re_ast->root_node = (yyvsp[0].re_node); + } #line 1341 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 4: #line 114 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = (yyvsp[0].re_node); - } + { + (yyval.re_node) = (yyvsp[0].re_node); + } #line 1349 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 5: #line 118 "re_grammar.y" /* yacc.c:1663 */ - { - mark_as_not_fast_regexp(); + { + mark_as_not_fast_regexp(); - (yyval.re_node) = yr_re_node_create(RE_NODE_ALT); + (yyval.re_node) = yr_re_node_create(RE_NODE_ALT); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[0].re_node)); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[0].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); - yr_re_node_append_child((yyval.re_node), (yyvsp[0].re_node)); - } + yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); + yr_re_node_append_child((yyval.re_node), (yyvsp[0].re_node)); + } #line 1367 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 6: #line 132 "re_grammar.y" /* yacc.c:1663 */ - { - RE_NODE* node; + { + RE_NODE *node; - mark_as_not_fast_regexp(); + mark_as_not_fast_regexp(); - node = yr_re_node_create(RE_NODE_EMPTY); + node = yr_re_node_create(RE_NODE_EMPTY); - destroy_node_if(node == NULL, (yyvsp[-1].re_node)); - fail_if(node == NULL, ERROR_INSUFFICIENT_MEMORY); + destroy_node_if(node == NULL, (yyvsp[-1].re_node)); + fail_if(node == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node) = yr_re_node_create(RE_NODE_ALT); + (yyval.re_node) = yr_re_node_create(RE_NODE_ALT); - destroy_node_if((yyval.re_node) == NULL, node); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); + destroy_node_if((yyval.re_node) == NULL, node); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); - yr_re_node_append_child((yyval.re_node), node); - } + yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); + yr_re_node_append_child((yyval.re_node), node); + } #line 1392 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 7: #line 156 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_CONCAT); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_CONCAT); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[0].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[0].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[0].re_node)); - } + yr_re_node_append_child((yyval.re_node), (yyvsp[0].re_node)); + } #line 1405 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 8: #line 165 "re_grammar.y" /* yacc.c:1663 */ - { - yr_re_node_append_child((yyvsp[-1].re_node), (yyvsp[0].re_node)); - (yyval.re_node) = (yyvsp[-1].re_node); - } + { + yr_re_node_append_child((yyvsp[-1].re_node), (yyvsp[0].re_node)); + (yyval.re_node) = (yyvsp[-1].re_node); + } #line 1414 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 9: #line 173 "re_grammar.y" /* yacc.c:1663 */ - { - RE_AST* re_ast; + { + RE_AST *re_ast; - mark_as_not_fast_regexp(); + mark_as_not_fast_regexp(); - re_ast = yyget_extra(yyscanner); - re_ast->flags |= RE_FLAGS_GREEDY; + re_ast = yyget_extra(yyscanner); + re_ast->flags |= RE_FLAGS_GREEDY; - (yyval.re_node) = yr_re_node_create(RE_NODE_STAR); + (yyval.re_node) = yr_re_node_create(RE_NODE_STAR); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); - } + yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); + } #line 1434 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 10: #line 189 "re_grammar.y" /* yacc.c:1663 */ - { - RE_AST* re_ast; + { + RE_AST *re_ast; - mark_as_not_fast_regexp(); + mark_as_not_fast_regexp(); - re_ast = yyget_extra(yyscanner); - re_ast->flags |= RE_FLAGS_UNGREEDY; + re_ast = yyget_extra(yyscanner); + re_ast->flags |= RE_FLAGS_UNGREEDY; - (yyval.re_node) = yr_re_node_create(RE_NODE_STAR); + (yyval.re_node) = yr_re_node_create(RE_NODE_STAR); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); + yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); - (yyval.re_node)->greedy = false; - } + (yyval.re_node)->greedy = false; + } #line 1456 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 11: #line 207 "re_grammar.y" /* yacc.c:1663 */ - { - RE_AST* re_ast; + { + RE_AST *re_ast; - mark_as_not_fast_regexp(); + mark_as_not_fast_regexp(); - re_ast = yyget_extra(yyscanner); - re_ast->flags |= RE_FLAGS_GREEDY; + re_ast = yyget_extra(yyscanner); + re_ast->flags |= RE_FLAGS_GREEDY; - (yyval.re_node) = yr_re_node_create(RE_NODE_PLUS); + (yyval.re_node) = yr_re_node_create(RE_NODE_PLUS); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); - } + yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); + } #line 1476 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 12: #line 223 "re_grammar.y" /* yacc.c:1663 */ - { - RE_AST* re_ast; + { + RE_AST *re_ast; - mark_as_not_fast_regexp(); + mark_as_not_fast_regexp(); - re_ast = yyget_extra(yyscanner); - re_ast->flags |= RE_FLAGS_UNGREEDY; + re_ast = yyget_extra(yyscanner); + re_ast->flags |= RE_FLAGS_UNGREEDY; - (yyval.re_node) = yr_re_node_create(RE_NODE_PLUS); + (yyval.re_node) = yr_re_node_create(RE_NODE_PLUS); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); - (yyval.re_node)->greedy = false; - } + yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); + (yyval.re_node)->greedy = false; + } #line 1497 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 13: #line 240 "re_grammar.y" /* yacc.c:1663 */ - { - RE_AST* re_ast = yyget_extra(yyscanner); - re_ast->flags |= RE_FLAGS_GREEDY; + { + RE_AST *re_ast = yyget_extra(yyscanner); + re_ast->flags |= RE_FLAGS_GREEDY; - if ((yyvsp[-1].re_node)->type == RE_NODE_ANY) - { - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); - destroy_node_if(true, (yyvsp[-1].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } - else - { - mark_as_not_fast_regexp(); - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); - } + if ((yyvsp[-1].re_node)->type == RE_NODE_ANY) + { + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); + destroy_node_if(true, (yyvsp[-1].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } + else + { + mark_as_not_fast_regexp(); + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); + } - (yyval.re_node)->start = 0; - (yyval.re_node)->end = 1; - } + (yyval.re_node)->start = 0; + (yyval.re_node)->end = 1; + } #line 1524 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 14: #line 263 "re_grammar.y" /* yacc.c:1663 */ - { - RE_AST* re_ast = yyget_extra(yyscanner); - re_ast->flags |= RE_FLAGS_UNGREEDY; + { + RE_AST *re_ast = yyget_extra(yyscanner); + re_ast->flags |= RE_FLAGS_UNGREEDY; - if ((yyvsp[-2].re_node)->type == RE_NODE_ANY) - { - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); - destroy_node_if(true, (yyvsp[-2].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } - else - { - mark_as_not_fast_regexp(); - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); - } + if ((yyvsp[-2].re_node)->type == RE_NODE_ANY) + { + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); + destroy_node_if(true, (yyvsp[-2].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } + else + { + mark_as_not_fast_regexp(); + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); + } - (yyval.re_node)->start = 0; - (yyval.re_node)->end = 1; - (yyval.re_node)->greedy = false; - } + (yyval.re_node)->start = 0; + (yyval.re_node)->end = 1; + (yyval.re_node)->greedy = false; + } #line 1552 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 15: #line 287 "re_grammar.y" /* yacc.c:1663 */ - { - RE_AST* re_ast = yyget_extra(yyscanner); - re_ast->flags |= RE_FLAGS_GREEDY; + { + RE_AST *re_ast = yyget_extra(yyscanner); + re_ast->flags |= RE_FLAGS_GREEDY; - if ((yyvsp[-1].re_node)->type == RE_NODE_ANY) - { - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); - destroy_node_if(true, (yyvsp[-1].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } - else - { - mark_as_not_fast_regexp(); - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); - } + if ((yyvsp[-1].re_node)->type == RE_NODE_ANY) + { + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); + destroy_node_if(true, (yyvsp[-1].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } + else + { + mark_as_not_fast_regexp(); + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-1].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + yr_re_node_append_child((yyval.re_node), (yyvsp[-1].re_node)); + } - (yyval.re_node)->start = (yyvsp[0].range) & 0xFFFF;; - (yyval.re_node)->end = (yyvsp[0].range) >> 16;; - } + (yyval.re_node)->start = (yyvsp[0].range) & 0xFFFF; + ; + (yyval.re_node)->end = (yyvsp[0].range) >> 16; + ; + } #line 1579 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 16: #line 310 "re_grammar.y" /* yacc.c:1663 */ - { - RE_AST* re_ast = yyget_extra(yyscanner); - re_ast->flags |= RE_FLAGS_UNGREEDY; + { + RE_AST *re_ast = yyget_extra(yyscanner); + re_ast->flags |= RE_FLAGS_UNGREEDY; - if ((yyvsp[-2].re_node)->type == RE_NODE_ANY) - { - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); - destroy_node_if(true, (yyvsp[-2].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } - else - { - mark_as_not_fast_regexp(); - (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE); - destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); - } + if ((yyvsp[-2].re_node)->type == RE_NODE_ANY) + { + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE_ANY); + destroy_node_if(true, (yyvsp[-2].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } + else + { + mark_as_not_fast_regexp(); + (yyval.re_node) = yr_re_node_create(RE_NODE_RANGE); + destroy_node_if((yyval.re_node) == NULL, (yyvsp[-2].re_node)); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + yr_re_node_append_child((yyval.re_node), (yyvsp[-2].re_node)); + } - (yyval.re_node)->start = (yyvsp[-1].range) & 0xFFFF;; - (yyval.re_node)->end = (yyvsp[-1].range) >> 16;; - (yyval.re_node)->greedy = false; - } + (yyval.re_node)->start = (yyvsp[-1].range) & 0xFFFF; + ; + (yyval.re_node)->end = (yyvsp[-1].range) >> 16; + ; + (yyval.re_node)->greedy = false; + } #line 1607 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 17: #line 334 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = (yyvsp[0].re_node); - } + { + (yyval.re_node) = (yyvsp[0].re_node); + } #line 1615 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 18: #line 338 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_WORD_BOUNDARY); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_WORD_BOUNDARY); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } #line 1625 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 19: #line 344 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_NON_WORD_BOUNDARY); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_NON_WORD_BOUNDARY); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } #line 1635 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 20: #line 350 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_ANCHOR_START); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_ANCHOR_START); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } #line 1645 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 21: #line 356 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_ANCHOR_END); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_ANCHOR_END); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } #line 1655 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 22: #line 365 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = (yyvsp[-1].re_node); - } + { + (yyval.re_node) = (yyvsp[-1].re_node); + } #line 1663 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 23: #line 369 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_ANY); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_ANY); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node)->value = 0x00; - (yyval.re_node)->mask = 0x00; - } + (yyval.re_node)->value = 0x00; + (yyval.re_node)->mask = 0x00; + } #line 1676 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 24: #line 378 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_LITERAL); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_LITERAL); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node)->value = (yyvsp[0].integer); - (yyval.re_node)->mask = 0xFF; - } + (yyval.re_node)->value = (yyvsp[0].integer); + (yyval.re_node)->mask = 0xFF; + } #line 1689 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 25: #line 387 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_WORD_CHAR); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_WORD_CHAR); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } #line 1699 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 26: #line 393 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_NON_WORD_CHAR); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_NON_WORD_CHAR); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } #line 1709 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 27: #line 399 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_SPACE); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_SPACE); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } #line 1719 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 28: #line 405 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_NON_SPACE); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_NON_SPACE); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } #line 1729 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 29: #line 411 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_DIGIT); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_DIGIT); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } #line 1739 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 30: #line 417 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_NON_DIGIT); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_NON_DIGIT); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - } + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + } #line 1749 "re_grammar.c" /* yacc.c:1663 */ - break; + break; case 31: #line 423 "re_grammar.y" /* yacc.c:1663 */ - { - (yyval.re_node) = yr_re_node_create(RE_NODE_CLASS); + { + (yyval.re_node) = yr_re_node_create(RE_NODE_CLASS); - fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); + fail_if((yyval.re_node) == NULL, ERROR_INSUFFICIENT_MEMORY); - (yyval.re_node)->re_class = (yyvsp[0].re_class); - } + (yyval.re_node)->re_class = (yyvsp[0].re_class); + } #line 1761 "re_grammar.c" /* yacc.c:1663 */ - break; + break; #line 1765 "re_grammar.c" /* yacc.c:1663 */ - default: break; - } + default: + break; + } /* User semantic actions sometimes alter yychar, and that requires that yytoken be updated with the new translation. We take the approach of translating immediately before every use of yytoken. @@ -1775,11 +1785,11 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT("-> $$ =", yyr1[yyn], &yyval, &yyloc); - YYPOPSTACK (yylen); + YYPOPSTACK(yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT(yyss, yyssp); *++yyvsp = yyval; @@ -1804,68 +1814,65 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE(yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) - { - ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (yyscanner, lex_env, YY_("syntax error")); + { + ++yynerrs; +#if !YYERROR_VERBOSE + yyerror(yyscanner, lex_env, YY_("syntax error")); #else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) +#define YYSYNTAX_ERROR yysyntax_error(&yymsg_alloc, &yymsg, yyssp, yytoken) + { + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) + if (yymsg != yymsgbuf) + YYSTACK_FREE(yymsg); + yymsg = (char *) YYSTACK_ALLOC(yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (yyscanner, lex_env, yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; + } } -# undef YYSYNTAX_ERROR -#endif + yyerror(yyscanner, lex_env, yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } - +#undef YYSYNTAX_ERROR +#endif + } if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ - if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } - else - { - yydestruct ("Error: discarding", - yytoken, &yylval, yyscanner, lex_env); - yychar = YYEMPTY; - } + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct("Error: discarding", yytoken, &yylval, yyscanner, lex_env); + yychar = YYEMPTY; } + } /* Else will try to reuse lookahead token after shifting the error token. */ @@ -1881,13 +1888,13 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); YYERROR and the label yyerrorlab therefore never appears in user code. */ if (/*CONSTCOND*/ 0) - goto yyerrorlab; + goto yyerrorlab; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ - YYPOPSTACK (yylen); + YYPOPSTACK(yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT(yyss, yyssp); yystate = *yyssp; goto yyerrlab1; @@ -1896,33 +1903,32 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ + yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default(yyn)) { - yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; - yydestruct ("Error: popping", - yystos[yystate], yyvsp, yyscanner, lex_env); - YYPOPSTACK (1); - yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); - } + yydestruct("Error: popping", yystos[yystate], yyvsp, yyscanner, lex_env); + YYPOPSTACK(1); + yystate = *yyssp; + YY_STACK_PRINT(yyss, yyssp); + } YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; @@ -1930,7 +1936,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -1955,39 +1961,37 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (yyscanner, lex_env, YY_("memory exhausted")); + yyerror(yyscanner, lex_env, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: if (yychar != YYEMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, yyscanner, lex_env); - } + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE(yychar); + yydestruct( + "Cleanup: discarding lookahead", yytoken, &yylval, yyscanner, lex_env); + } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); + YYPOPSTACK(yylen); + YY_STACK_PRINT(yyss, yyssp); while (yyssp != yyss) - { - yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yyscanner, lex_env); - YYPOPSTACK (1); - } + { + yydestruct("Cleanup: popping", yystos[*yyssp], yyvsp, yyscanner, lex_env); + YYPOPSTACK(1); + } #ifndef yyoverflow if (yyss != yyssa) - YYSTACK_FREE (yyss); + YYSTACK_FREE(yyss); #endif #if YYERROR_VERBOSE if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); + YYSTACK_FREE(yymsg); #endif return yyresult; } #line 431 "re_grammar.y" /* yacc.c:1907 */ - diff --git a/libyara/re_grammar.h b/libyara/re_grammar.h index 6d70622d35..2d4b8eadbf 100644 --- a/libyara/re_grammar.h +++ b/libyara/re_grammar.h @@ -31,10 +31,10 @@ version 2.2 of Bison. */ #ifndef YY_RE_YY_RE_GRAMMAR_H_INCLUDED -# define YY_RE_YY_RE_GRAMMAR_H_INCLUDED +#define YY_RE_YY_RE_GRAMMAR_H_INCLUDED /* Debug traces. */ #ifndef YYDEBUG -# define YYDEBUG 0 +#define YYDEBUG 0 #endif #if YYDEBUG extern int re_yydebug; @@ -42,39 +42,39 @@ extern int re_yydebug; /* Token type. */ #ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - _CHAR_ = 258, - _ANY_ = 259, - _RANGE_ = 260, - _CLASS_ = 261, - _WORD_CHAR_ = 262, - _NON_WORD_CHAR_ = 263, - _SPACE_ = 264, - _NON_SPACE_ = 265, - _DIGIT_ = 266, - _NON_DIGIT_ = 267, - _WORD_BOUNDARY_ = 268, - _NON_WORD_BOUNDARY_ = 269 - }; +#define YYTOKENTYPE +enum yytokentype +{ + _CHAR_ = 258, + _ANY_ = 259, + _RANGE_ = 260, + _CLASS_ = 261, + _WORD_CHAR_ = 262, + _NON_WORD_CHAR_ = 263, + _SPACE_ = 264, + _NON_SPACE_ = 265, + _DIGIT_ = 266, + _NON_DIGIT_ = 267, + _WORD_BOUNDARY_ = 268, + _NON_WORD_BOUNDARY_ = 269 +}; #endif /* Tokens. */ -#define _CHAR_ 258 -#define _ANY_ 259 -#define _RANGE_ 260 -#define _CLASS_ 261 -#define _WORD_CHAR_ 262 -#define _NON_WORD_CHAR_ 263 -#define _SPACE_ 264 -#define _NON_SPACE_ 265 -#define _DIGIT_ 266 -#define _NON_DIGIT_ 267 -#define _WORD_BOUNDARY_ 268 +#define _CHAR_ 258 +#define _ANY_ 259 +#define _RANGE_ 260 +#define _CLASS_ 261 +#define _WORD_CHAR_ 262 +#define _NON_WORD_CHAR_ 263 +#define _SPACE_ 264 +#define _NON_SPACE_ 265 +#define _DIGIT_ 266 +#define _NON_DIGIT_ 267 +#define _WORD_BOUNDARY_ 268 #define _NON_WORD_BOUNDARY_ 269 /* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED union YYSTYPE { @@ -89,12 +89,11 @@ union YYSTYPE }; typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 +#define YYSTYPE_IS_TRIVIAL 1 +#define YYSTYPE_IS_DECLARED 1 #endif - -int re_yyparse (void *yyscanner, RE_LEX_ENVIRONMENT *lex_env); +int re_yyparse(void* yyscanner, RE_LEX_ENVIRONMENT* lex_env); #endif /* !YY_RE_YY_RE_GRAMMAR_H_INCLUDED */ diff --git a/libyara/re_lexer.c b/libyara/re_lexer.c index 5df2f9395d..097a6a358d 100644 --- a/libyara/re_lexer.c +++ b/libyara/re_lexer.c @@ -2,13 +2,13 @@ #line 4 "re_lexer.c" -#define YY_INT_ALIGNED short int +#define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ #define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 #define YY_FLEX_SUBMINOR_VERSION 4 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA @@ -239,10 +239,10 @@ /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ -#include -#include #include +#include #include +#include /* end standard C headers. */ @@ -253,10 +253,10 @@ /* C99 systems have . Non-C99 systems may or may not. */ -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. + * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 @@ -273,41 +273,41 @@ typedef uint32_t flex_uint32_t; typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; +typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; /* Limits of integral types. */ #ifndef INT8_MIN -#define INT8_MIN (-128) +#define INT8_MIN (-128) #endif #ifndef INT16_MIN -#define INT16_MIN (-32767-1) +#define INT16_MIN (-32767 - 1) #endif #ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) +#define INT32_MIN (-2147483647 - 1) #endif #ifndef INT8_MAX -#define INT8_MAX (127) +#define INT8_MAX (127) #endif #ifndef INT16_MAX -#define INT16_MAX (32767) +#define INT16_MAX (32767) #endif #ifndef INT32_MAX -#define INT32_MAX (2147483647) +#define INT32_MAX (2147483647) #endif #ifndef UINT8_MAX -#define UINT8_MAX (255U) +#define UINT8_MAX (255U) #endif #ifndef UINT16_MAX -#define UINT16_MAX (65535U) +#define UINT16_MAX (65535U) #endif #ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) +#define UINT32_MAX (4294967295U) #endif #ifndef SIZE_MAX -#define SIZE_MAX (~(size_t)0) +#define SIZE_MAX (~(size_t) 0) #endif #endif /* ! C99 */ @@ -331,23 +331,23 @@ typedef unsigned int flex_uint32_t; /* Promotes a possibly negative, possibly signed char to an * integer in range [0..255] for use as an array index. */ -#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) +#define YY_SC_TO_UI(c) ((YY_CHAR)(c)) /* An opaque pointer. */ #ifndef YY_TYPEDEF_YY_SCANNER_T #define YY_TYPEDEF_YY_SCANNER_T -typedef void* yyscan_t; +typedef void *yyscan_t; #endif /* For convenience, these vars (plus the bison vars far below) are macros in the reentrant scanner. */ -#define yyin yyg->yyin_r -#define yyout yyg->yyout_r -#define yyextra yyg->yyextra_r -#define yyleng yyg->yyleng_r -#define yytext yyg->yytext_r -#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) -#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) #define yy_flex_debug yyg->yy_flex_debug_r /* Enter a start condition. This macro really ought to take a parameter, @@ -360,11 +360,11 @@ typedef void* yyscan_t; * compatibility. */ #define YY_START ((yyg->yy_start - 1) / 2) -#define YYSTATE YY_START +#define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin , yyscanner ) +#define YY_NEW_FILE yyrestart(yyin, yyscanner) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ @@ -380,9 +380,10 @@ typedef void* yyscan_t; #endif /* __ia64__ */ #endif -/* The state buf must be large enough to hold one state per character in the main buffer. +/* The state buf must be large enough to hold one state per character in the + * main buffer. */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE @@ -395,109 +396,109 @@ typedef size_t yy_size_t; #endif #define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires - * access to the local variable yy_act. Since yyless() is a macro, it would break - * existing scanners that call yyless() from OUTSIDE yylex. - * One obvious solution it to make yy_act a global. I tried that, and saw - * a 5% performance hit in a non-yylineno scanner, because yy_act is - * normally declared as a register variable-- so it is not worth it. - */ - #define YY_LESS_LINENO(n) \ - do { \ - int yyl;\ - for ( yyl = n; yyl < yyleng; ++yyl )\ - if ( yytext[yyl] == '\n' )\ - --yylineno;\ - }while(0) - #define YY_LINENO_REWIND_TO(dst) \ - do {\ - const char *p;\ - for ( p = yy_cp-1; p >= (dst); --p)\ - if ( *p == '\n' )\ - --yylineno;\ - }while(0) - +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* Note: We specifically omit the test for yy_rule_can_match_eol because it + * requires access to the local variable yy_act. Since yyless() is a macro, it + * would break existing scanners that call yyless() from OUTSIDE yylex. One + * obvious solution it to make yy_act a global. I tried that, and saw a 5% + * performance hit in a non-yylineno scanner, because yy_act is normally + * declared as a register variable-- so it is not worth it. + */ +#define YY_LESS_LINENO(n) \ + do \ + { \ + int yyl; \ + for (yyl = n; yyl < yyleng; ++yyl) \ + if (yytext[yyl] == '\n') \ + --yylineno; \ + } while (0) +#define YY_LINENO_REWIND_TO(dst) \ + do \ + { \ + const char *p; \ + for (p = yy_cp - 1; p >= (dst); --p) \ + if (*p == '\n') \ + --yylineno; \ + } while (0) + /* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = yyg->yy_hold_char; \ - YY_RESTORE_YY_MORE_OFFSET \ - yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) -#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg); \ + *yy_cp = yyg->yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } while (0) +#define unput(c) yyunput(c, yyg->yytext_ptr, yyscanner) #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 +{ + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ #define YY_BUFFER_EOF_PENDING 2 - - }; +}; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ /* We provide macros for accessing buffer states in case in the @@ -506,59 +507,60 @@ struct yy_buffer_state * * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ - ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ - : NULL) +#define YY_CURRENT_BUFFER \ + (yyg->yy_buffer_stack ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ #define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] -void yyrestart ( FILE *input_file , yyscan_t yyscanner ); -void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner ); -void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); -void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); -void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -void yypop_buffer_state ( yyscan_t yyscanner ); +void yyrestart(FILE *input_file, yyscan_t yyscanner); +void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner); +YY_BUFFER_STATE yy_create_buffer(FILE *file, int size, yyscan_t yyscanner); +void yy_delete_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner); +void yy_flush_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner); +void yypush_buffer_state(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner); +void yypop_buffer_state(yyscan_t yyscanner); -static void yyensure_buffer_stack ( yyscan_t yyscanner ); -static void yy_load_buffer_state ( yyscan_t yyscanner ); -static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner ); -#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , yyscanner) +static void yyensure_buffer_stack(yyscan_t yyscanner); +static void yy_load_buffer_state(yyscan_t yyscanner); +static void yy_init_buffer(YY_BUFFER_STATE b, FILE *file, yyscan_t yyscanner); +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER, yyscanner) -YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner ); -YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_buffer(char *base, yy_size_t size, yyscan_t yyscanner); +YY_BUFFER_STATE yy_scan_string(const char *yy_str, yyscan_t yyscanner); +YY_BUFFER_STATE yy_scan_bytes(const char *bytes, int len, yyscan_t yyscanner); -void *yyalloc ( yy_size_t , yyscan_t yyscanner ); -void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner ); -void yyfree ( void * , yyscan_t yyscanner ); +void *yyalloc(yy_size_t, yyscan_t yyscanner); +void *yyrealloc(void *, yy_size_t, yyscan_t yyscanner); +void yyfree(void *, yyscan_t yyscanner); #define yy_new_buffer yy_create_buffer -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } +#define yy_set_interactive(is_interactive) \ + { \ + if (!YY_CURRENT_BUFFER) \ + { \ + yyensure_buffer_stack(yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer( \ + yyin, YY_BUF_SIZE, yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } +#define yy_set_bol(at_bol) \ + { \ + if (!YY_CURRENT_BUFFER) \ + { \ + yyensure_buffer_stack(yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer( \ + yyin, YY_BUF_SIZE, yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) /* Begin user sect3 */ -#define re_yywrap(yyscanner) (/*CONSTCOND*/1) +#define re_yywrap(yyscanner) (/*CONSTCOND*/ 1) #define YY_SKIP_YYWRAP typedef flex_uint8_t YY_CHAR; @@ -566,140 +568,97 @@ typedef int yy_state_type; #define yytext_ptr yytext_r -static yy_state_type yy_get_previous_state ( yyscan_t yyscanner ); -static yy_state_type yy_try_NUL_trans ( yy_state_type current_state , yyscan_t yyscanner); -static int yy_get_next_buffer ( yyscan_t yyscanner ); -static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner ); +static yy_state_type yy_get_previous_state(yyscan_t yyscanner); +static yy_state_type yy_try_NUL_trans( + yy_state_type current_state, + yyscan_t yyscanner); +static int yy_get_next_buffer(yyscan_t yyscanner); +static void yynoreturn yy_fatal_error(const char *msg, yyscan_t yyscanner); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ -#define YY_DO_BEFORE_ACTION \ - yyg->yytext_ptr = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ - yyg->yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - yyg->yy_c_buf_p = yy_cp; -#define YY_NUM_RULES 29 +#define YY_DO_BEFORE_ACTION \ + yyg->yytext_ptr = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + yyg->yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yyg->yy_c_buf_p = yy_cp; +#define YY_NUM_RULES 29 #define YY_END_OF_BUFFER 30 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static const flex_int16_t yy_accept[45] = - { 0, - 0, 0, 0, 0, 30, 7, 7, 28, 6, 17, - 7, 27, 29, 26, 18, 5, 3, 16, 15, 13, - 11, 9, 14, 12, 10, 8, 0, 0, 0, 0, - 25, 23, 21, 24, 22, 20, 0, 4, 0, 1, - 2, 19, 0, 0 - } ; - -static const YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 3, 1, 1, 1, 3, - 3, 3, 3, 4, 5, 3, 1, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 1, 1, 1, - 1, 1, 3, 1, 7, 8, 7, 9, 7, 7, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 10, 1, 1, 1, 11, 1, 1, 1, - 12, 13, 14, 15, 1, 1, 7, 16, 7, 17, - - 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 18, 1, 1, 1, 19, 20, - 1, 1, 21, 3, 22, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static const YY_CHAR yy_meta[23] = - { 0, - 1, 2, 1, 1, 3, 4, 4, 4, 4, 1, - 1, 1, 1, 5, 1, 4, 4, 1, 1, 1, - 1, 1 - } ; - -static const flex_int16_t yy_base[51] = - { 0, - 0, 20, 3, 5, 50, 89, 89, 89, 10, 36, - 0, 44, 43, 47, 38, 89, 26, 33, 89, 89, - 89, 89, 89, 89, 89, 89, 4, 5, 0, 33, - 32, 31, 29, 26, 24, 23, 15, 89, 8, 89, - 89, 89, 0, 89, 67, 72, 77, 82, 84, 4 - } ; - -static const flex_int16_t yy_def[51] = - { 0, - 45, 45, 46, 46, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 47, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 48, 44, - 44, 44, 44, 44, 44, 44, 49, 44, 44, 44, - 44, 44, 50, 0, 44, 44, 44, 44, 44, 44 - } ; - -static const flex_int16_t yy_nxt[112] = - { 0, - 44, 7, 8, 27, 13, 28, 13, 30, 27, 39, - 28, 9, 10, 39, 8, 14, 15, 14, 15, 29, - 11, 7, 8, 16, 17, 40, 41, 29, 29, 40, - 29, 9, 10, 29, 8, 29, 29, 29, 18, 38, - 11, 18, 29, 19, 20, 21, 22, 29, 29, 44, - 44, 23, 24, 25, 26, 31, 32, 33, 44, 44, - 44, 44, 44, 34, 35, 36, 37, 6, 6, 6, - 6, 6, 12, 12, 12, 12, 12, 30, 44, 30, - 30, 30, 42, 42, 42, 42, 43, 43, 5, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44 - } ; - -static const flex_int16_t yy_chk[112] = - { 0, - 0, 1, 1, 11, 3, 11, 4, 50, 28, 27, - 28, 1, 1, 39, 1, 3, 3, 4, 4, 37, - 1, 2, 2, 9, 9, 27, 28, 36, 35, 39, - 34, 2, 2, 33, 2, 32, 31, 30, 18, 17, - 2, 10, 15, 10, 10, 10, 10, 13, 12, 5, - 0, 10, 10, 10, 10, 14, 14, 14, 0, 0, - 0, 0, 0, 14, 14, 14, 14, 45, 45, 45, - 45, 45, 46, 46, 46, 46, 46, 47, 0, 47, - 47, 47, 48, 48, 48, 48, 49, 49, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44 - } ; +{ + flex_int32_t yy_verify; + flex_int32_t yy_nxt; +}; +static const flex_int16_t yy_accept[45] = { + 0, 0, 0, 0, 0, 30, 7, 7, 28, 6, 17, 7, 27, 29, 26, + 18, 5, 3, 16, 15, 13, 11, 9, 14, 12, 10, 8, 0, 0, 0, + 0, 25, 23, 21, 24, 22, 20, 0, 4, 0, 1, 2, 19, 0, 0}; + +static const YY_CHAR yy_ec[256] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 3, 3, + 3, 3, 4, 5, 3, 1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 1, 1, 1, 1, 1, + 3, 1, 7, 8, 7, 9, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, + 1, 1, 1, 11, 1, 1, 1, 12, 13, 14, 15, 1, 1, 7, 16, 7, 17, + + 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 18, 1, 1, 1, 19, 20, 1, + 1, 21, 3, 22, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + +static const YY_CHAR yy_meta[23] = {0, 1, 2, 1, 1, 3, 4, 4, 4, 4, 1, 1, + 1, 1, 5, 1, 4, 4, 1, 1, 1, 1, 1}; + +static const flex_int16_t yy_base[51] = { + 0, 0, 20, 3, 5, 50, 89, 89, 89, 10, 36, 0, 44, 43, 47, 38, 89, + 26, 33, 89, 89, 89, 89, 89, 89, 89, 89, 4, 5, 0, 33, 32, 31, 29, + 26, 24, 23, 15, 89, 8, 89, 89, 89, 0, 89, 67, 72, 77, 82, 84, 4}; + +static const flex_int16_t yy_def[51] = { + 0, 45, 45, 46, 46, 44, 44, 44, 44, 44, 44, 44, 44, 44, 47, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 48, 44, 44, 44, 44, + 44, 44, 44, 49, 44, 44, 44, 44, 44, 50, 0, 44, 44, 44, 44, 44, 44}; + +static const flex_int16_t yy_nxt[112] = { + 0, 44, 7, 8, 27, 13, 28, 13, 30, 27, 39, 28, 9, 10, 39, 8, 14, + 15, 14, 15, 29, 11, 7, 8, 16, 17, 40, 41, 29, 29, 40, 29, 9, 10, + 29, 8, 29, 29, 29, 18, 38, 11, 18, 29, 19, 20, 21, 22, 29, 29, 44, + 44, 23, 24, 25, 26, 31, 32, 33, 44, 44, 44, 44, 44, 34, 35, 36, 37, + 6, 6, 6, 6, 6, 12, 12, 12, 12, 12, 30, 44, 30, 30, 30, 42, 42, + 42, 42, 43, 43, 5, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44}; + +static const flex_int16_t yy_chk[112] = { + 0, 0, 1, 1, 11, 3, 11, 4, 50, 28, 27, 28, 1, 1, 39, 1, 3, + 3, 4, 4, 37, 1, 2, 2, 9, 9, 27, 28, 36, 35, 39, 34, 2, 2, + 33, 2, 32, 31, 30, 18, 17, 2, 10, 15, 10, 10, 10, 10, 13, 12, 5, + 0, 10, 10, 10, 10, 14, 14, 14, 0, 0, 0, 0, 0, 14, 14, 14, 14, + 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 47, 0, 47, 47, 47, 48, 48, + 48, 48, 49, 49, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44}; /* Table of booleans, true if rule could match eol. */ -static const flex_int32_t yy_rule_can_match_eol[30] = - { 0, -0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; +static const flex_int32_t yy_rule_can_match_eol[30] = { + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET #line 1 "re_lexer.l" @@ -749,16 +708,15 @@ with noyywrap then we can remove this pragma. #include #include - -#include -#include #include +#include #include #include #include #include -#include #include +#include +#include #ifdef _WIN32 @@ -767,36 +725,30 @@ with noyywrap then we can remove this pragma. // Bitmap with 1 bit for each of the 256 characters in the ASCII table. The bit // is set to 1 if the corresponding character is alphanumeric or 0 if otherwise. -static uint8_t word_chars[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, - 0xFE, 0xFF, 0xFF, 0x87, 0xFE, 0xFF, 0xFF, 0x07, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static uint8_t word_chars[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, + 0xFE, 0xFF, 0xFF, 0x87, 0xFE, 0xFF, 0xFF, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Bitmap with 1 bit for each of the 256 characters in the ASCII table. The bit // is set to 1 if the corresponding character is considered a space. Space // characters include horizontal and vertical tabs, carriage return, new line // and form feed (\t, \v, \r, \n, \f). -static uint8_t space_chars[] = { - 0x00, 0x3E, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static uint8_t space_chars[] = {0x00, 0x3E, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -int escaped_char_value( - char* text, - uint8_t* value); +int escaped_char_value(char *text, uint8_t *value); -int read_escaped_char( - yyscan_t yyscanner, - uint8_t* escaped_char); +int read_escaped_char(yyscan_t yyscanner, uint8_t *escaped_char); #line 795 "re_lexer.c" #define YY_NO_UNISTD_H 1 #line 798 "re_lexer.c" -#define INITIAL 0 +#define INITIAL 0 #define char_class 1 #ifndef YY_NO_UNISTD_H @@ -813,86 +765,86 @@ int read_escaped_char( /* Holds the entire state of the reentrant scanner. */ struct yyguts_t - { +{ + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; - /* User-defined. Not touched by flex. */ - YY_EXTRA_TYPE yyextra_r; + /* The rest are the same as the globals declared in the non-reentrant scanner. + */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE *yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + int yy_n_chars; + int yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char *yy_last_accepting_cpos; - /* The rest are the same as the globals declared in the non-reentrant scanner. */ - FILE *yyin_r, *yyout_r; - size_t yy_buffer_stack_top; /**< index of top of stack. */ - size_t yy_buffer_stack_max; /**< capacity of stack. */ - YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ - char yy_hold_char; - int yy_n_chars; - int yyleng_r; - char *yy_c_buf_p; - int yy_init; - int yy_start; - int yy_did_buffer_switch_on_eof; - int yy_start_stack_ptr; - int yy_start_stack_depth; - int *yy_start_stack; - yy_state_type yy_last_accepting_state; - char* yy_last_accepting_cpos; + int yylineno_r; + int yy_flex_debug_r; - int yylineno_r; - int yy_flex_debug_r; + char *yytext_r; + int yy_more_flag; + int yy_more_len; - char *yytext_r; - int yy_more_flag; - int yy_more_len; + YYSTYPE *yylval_r; - YYSTYPE * yylval_r; +}; /* end struct yyguts_t */ - }; /* end struct yyguts_t */ +static int yy_init_globals(yyscan_t yyscanner); -static int yy_init_globals ( yyscan_t yyscanner ); +/* This must go here because YYSTYPE and YYLTYPE are included + * from bison output in section 1.*/ +#define yylval yyg->yylval_r - /* This must go here because YYSTYPE and YYLTYPE are included - * from bison output in section 1.*/ - # define yylval yyg->yylval_r - -int yylex_init (yyscan_t* scanner); +int yylex_init(yyscan_t *scanner); -int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner); +int yylex_init_extra(YY_EXTRA_TYPE user_defined, yyscan_t *scanner); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int yylex_destroy ( yyscan_t yyscanner ); +int yylex_destroy(yyscan_t yyscanner); -int yyget_debug ( yyscan_t yyscanner ); +int yyget_debug(yyscan_t yyscanner); -void yyset_debug ( int debug_flag , yyscan_t yyscanner ); +void yyset_debug(int debug_flag, yyscan_t yyscanner); -YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner ); +YY_EXTRA_TYPE yyget_extra(yyscan_t yyscanner); -void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); +void yyset_extra(YY_EXTRA_TYPE user_defined, yyscan_t yyscanner); -FILE *yyget_in ( yyscan_t yyscanner ); +FILE *yyget_in(yyscan_t yyscanner); -void yyset_in ( FILE * _in_str , yyscan_t yyscanner ); +void yyset_in(FILE *_in_str, yyscan_t yyscanner); -FILE *yyget_out ( yyscan_t yyscanner ); +FILE *yyget_out(yyscan_t yyscanner); -void yyset_out ( FILE * _out_str , yyscan_t yyscanner ); +void yyset_out(FILE *_out_str, yyscan_t yyscanner); - int yyget_leng ( yyscan_t yyscanner ); +int yyget_leng(yyscan_t yyscanner); -char *yyget_text ( yyscan_t yyscanner ); +char *yyget_text(yyscan_t yyscanner); -int yyget_lineno ( yyscan_t yyscanner ); +int yyget_lineno(yyscan_t yyscanner); -void yyset_lineno ( int _line_number , yyscan_t yyscanner ); +void yyset_lineno(int _line_number, yyscan_t yyscanner); -int yyget_column ( yyscan_t yyscanner ); +int yyget_column(yyscan_t yyscanner); -void yyset_column ( int _column_no , yyscan_t yyscanner ); +void yyset_column(int _column_no, yyscan_t yyscanner); -YYSTYPE * yyget_lval ( yyscan_t yyscanner ); +YYSTYPE *yyget_lval(yyscan_t yyscanner); -void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner ); +void yyset_lval(YYSTYPE *yylval_param, yyscan_t yyscanner); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -900,29 +852,29 @@ void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap ( yyscan_t yyscanner ); +extern "C" int yywrap(yyscan_t yyscanner); #else -extern int yywrap ( yyscan_t yyscanner ); +extern int yywrap(yyscan_t yyscanner); #endif #endif #ifndef YY_NO_UNPUT - + #endif #ifndef yytext_ptr -static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner); +static void yy_flex_strncpy(char *, const char *, int, yyscan_t yyscanner); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen ( const char * , yyscan_t yyscanner); +static int yy_flex_strlen(const char *, yyscan_t yyscanner); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput ( yyscan_t yyscanner ); +static int yyinput(yyscan_t yyscanner); #else -static int input ( yyscan_t yyscanner ); +static int input(yyscan_t yyscanner); #endif #endif @@ -942,42 +894,48 @@ static int input ( yyscan_t yyscanner ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) +#define ECHO \ + do \ + { \ + if (fwrite(yytext, (size_t) yyleng, 1, yyout)) \ + { \ + } \ + } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, * is returned in "result". */ #ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - int n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ +#define YY_INPUT(buf, result, max_size) \ + if (YY_CURRENT_BUFFER_LVALUE->yy_is_interactive) \ + { \ + int c = '*'; \ + int n; \ + for (n = 0; n < max_size && (c = getc(yyin)) != EOF && c != '\n'; ++n) \ + buf[n] = (char) c; \ + if (c == '\n') \ + buf[n++] = (char) c; \ + if (c == EOF && ferror(yyin)) \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + result = n; \ + } \ + else \ + { \ + errno = 0; \ + while ((result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && \ + ferror(yyin)) \ + { \ + if (errno != EINTR) \ + { \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + break; \ + } \ + errno = 0; \ + clearerr(yyin); \ + } \ + } + #endif @@ -996,7 +954,7 @@ static int input ( yyscan_t yyscanner ); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) +#define YY_FATAL_ERROR(msg) yy_fatal_error(msg, yyscanner) #endif /* end tables serialization structures and prototypes */ @@ -1007,11 +965,9 @@ static int input ( yyscan_t yyscanner ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int yylex \ - (YYSTYPE * yylval_param , yyscan_t yyscanner); +extern int yylex(YYSTYPE *yylval_param, yyscan_t yyscanner); -#define YY_DECL int yylex \ - (YYSTYPE * yylval_param , yyscan_t yyscanner) +#define YY_DECL int yylex(YYSTYPE *yylval_param, yyscan_t yyscanner) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -1023,860 +979,842 @@ extern int yylex \ /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; +#define YY_BREAK /*LINTED*/ break; #endif -#define YY_RULE_SETUP \ - YY_USER_ACTION +#define YY_RULE_SETUP YY_USER_ACTION /** The main scanner function which does all the work. */ YY_DECL { - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - yylval = yylval_param; + yylval = yylval_param; - if ( !yyg->yy_init ) - { - yyg->yy_init = 1; + if (!yyg->yy_init) + { + yyg->yy_init = 1; #ifdef YY_USER_INIT - YY_USER_INIT; + YY_USER_INIT; #endif - if ( ! yyg->yy_start ) - yyg->yy_start = 1; /* first start state */ + if (!yyg->yy_start) + yyg->yy_start = 1; /* first start state */ - if ( ! yyin ) - yyin = stdin; + if (!yyin) + yyin = stdin; - if ( ! yyout ) - yyout = stdout; + if (!yyout) + yyout = stdout; - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); - } + if (!YY_CURRENT_BUFFER) + { + yyensure_buffer_stack(yyscanner); + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE, yyscanner); + } - yy_load_buffer_state( yyscanner ); - } + yy_load_buffer_state(yyscanner); + } - { + { #line 111 "re_lexer.l" #line 1074 "re_lexer.c" - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = yyg->yy_c_buf_p; - - /* Support of yytext. */ - *yy_cp = yyg->yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = yyg->yy_start; -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 45 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - ++yy_cp; - } - while ( yy_current_state != 44 ); - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - - YY_DO_BEFORE_ACTION; - - if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) - { - int yyl; - for ( yyl = 0; yyl < yyleng; ++yyl ) - if ( yytext[yyl] == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; - } - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = yyg->yy_hold_char; - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - goto yy_find_action; - -case 1: -YY_RULE_SETUP + while (/*CONSTCOND*/ 1) /* loops until end-of-file is reached */ + { + yy_cp = yyg->yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yyg->yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yyg->yy_start; + yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if (yy_accept[yy_current_state]) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) + { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 45) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } while (yy_current_state != 44); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + + yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + + if (yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act]) + { + int yyl; + for (yyl = 0; yyl < yyleng; ++yyl) + if (yytext[yyl] == '\n') + + do + { + yylineno++; + yycolumn = 0; + } while (0); + } + + do_action: /* This label is used only to access EOF actions. */ + + switch (yy_act) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yyg->yy_hold_char; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + goto yy_find_action; + + case 1: + YY_RULE_SETUP #line 113 "re_lexer.l" -{ - - // Examples: {3,8} {0,5} {,5} {7,} - - int hi_bound; - int lo_bound = atoi(yytext + 1); - - char* comma = strchr(yytext, ','); - - if (comma - yytext == strlen(yytext) - 2) - // if comma is followed by the closing curly bracket - // (example: {2,}) set high bound value to maximum. - hi_bound = INT16_MAX; - else - hi_bound = atoi(comma + 1); - - if (hi_bound > INT16_MAX) - { - yyerror(yyscanner, lex_env, "repeat interval too large"); - yyterminate(); - } - - if (hi_bound < lo_bound || hi_bound < 0 || lo_bound < 0) - { - yyerror(yyscanner, lex_env, "bad repeat interval"); - yyterminate(); - } - - if (hi_bound == 0 && lo_bound == 0) - { - yyerror(yyscanner, lex_env, "bad repeat interval"); - yyterminate(); - } - - yylval->range = (hi_bound << 16) | lo_bound; - - return _RANGE_; -} - YY_BREAK -case 2: -YY_RULE_SETUP + { + // Examples: {3,8} {0,5} {,5} {7,} + + int hi_bound; + int lo_bound = atoi(yytext + 1); + + char *comma = strchr(yytext, ','); + + if (comma - yytext == strlen(yytext) - 2) + // if comma is followed by the closing curly bracket + // (example: {2,}) set high bound value to maximum. + hi_bound = INT16_MAX; + else + hi_bound = atoi(comma + 1); + + if (hi_bound > INT16_MAX) + { + yyerror(yyscanner, lex_env, "repeat interval too large"); + yyterminate(); + } + + if (hi_bound < lo_bound || hi_bound < 0 || lo_bound < 0) + { + yyerror(yyscanner, lex_env, "bad repeat interval"); + yyterminate(); + } + + if (hi_bound == 0 && lo_bound == 0) + { + yyerror(yyscanner, lex_env, "bad repeat interval"); + yyterminate(); + } + + yylval->range = (hi_bound << 16) | lo_bound; + + return _RANGE_; + } + YY_BREAK + case 2: + YY_RULE_SETUP #line 153 "re_lexer.l" -{ - - // Example: {10} + { + // Example: {10} - int value = atoi(yytext + 1); + int value = atoi(yytext + 1); - // atoi can return a negative value if the input string represents a number - // too large to fit in an integer. + // atoi can return a negative value if the input string represents a + // number too large to fit in an integer. - if (value > INT16_MAX || value < 0) - { - yyerror(yyscanner, lex_env, "repeat interval too large"); - yyterminate(); - } + if (value > INT16_MAX || value < 0) + { + yyerror(yyscanner, lex_env, "repeat interval too large"); + yyterminate(); + } - if (value == 0) - { - yyerror(yyscanner, lex_env, "bad repeat interval"); - yyterminate(); - } + if (value == 0) + { + yyerror(yyscanner, lex_env, "bad repeat interval"); + yyterminate(); + } - yylval->range = (value << 16) | value; + yylval->range = (value << 16) | value; - return _RANGE_; -} - YY_BREAK -case 3: -YY_RULE_SETUP + return _RANGE_; + } + YY_BREAK + case 3: + YY_RULE_SETUP #line 180 "re_lexer.l" -{ - - // Start of a negated character class. Example: [^abcd] - - BEGIN(char_class); - memset(LEX_ENV->re_class.bitmap, 0, 32); - LEX_ENV->re_class.negated = true; -} - YY_BREAK -case 4: -YY_RULE_SETUP + { + // Start of a negated character class. Example: [^abcd] + + BEGIN(char_class); + memset(LEX_ENV->re_class.bitmap, 0, 32); + LEX_ENV->re_class.negated = true; + } + YY_BREAK + case 4: + YY_RULE_SETUP #line 189 "re_lexer.l" -{ - - // Start of character negated class containing a ]. - // Example: [^]abc] this must be interpreted as a class - // not matching ], a, b, nor c - - BEGIN(char_class); - memset(LEX_ENV->re_class.bitmap, 0, 32); - LEX_ENV->re_class.negated = true; - LEX_ENV->re_class.bitmap[']' / 8] |= 1 << ']' % 8; -} - YY_BREAK -case 5: -YY_RULE_SETUP + { + // Start of character negated class containing a ]. + // Example: [^]abc] this must be interpreted as a class + // not matching ], a, b, nor c + + BEGIN(char_class); + memset(LEX_ENV->re_class.bitmap, 0, 32); + LEX_ENV->re_class.negated = true; + LEX_ENV->re_class.bitmap[']' / 8] |= 1 << ']' % 8; + } + YY_BREAK + case 5: + YY_RULE_SETUP #line 202 "re_lexer.l" -{ - - // Start of character class containing a ]. - // Example: []abc] this must be interpreted as a class - // matching ], a, b, or c. - - BEGIN(char_class); - memset(LEX_ENV->re_class.bitmap, 0, 32); - LEX_ENV->re_class.negated = false; - LEX_ENV->re_class.bitmap[']' / 8] |= 1 << ']' % 8; -} - YY_BREAK -case 6: -YY_RULE_SETUP + { + // Start of character class containing a ]. + // Example: []abc] this must be interpreted as a class + // matching ], a, b, or c. + + BEGIN(char_class); + memset(LEX_ENV->re_class.bitmap, 0, 32); + LEX_ENV->re_class.negated = false; + LEX_ENV->re_class.bitmap[']' / 8] |= 1 << ']' % 8; + } + YY_BREAK + case 6: + YY_RULE_SETUP #line 215 "re_lexer.l" -{ - - // Start of character class. Example: [abcd] - - BEGIN(char_class); - memset(LEX_ENV->re_class.bitmap, 0, 32); - LEX_ENV->re_class.negated = false; -} - YY_BREAK -case 7: -/* rule 7 can match eol */ -YY_RULE_SETUP + { + // Start of character class. Example: [abcd] + + BEGIN(char_class); + memset(LEX_ENV->re_class.bitmap, 0, 32); + LEX_ENV->re_class.negated = false; + } + YY_BREAK + case 7: + /* rule 7 can match eol */ + YY_RULE_SETUP #line 225 "re_lexer.l" -{ - - // Any non-special character is passed as a CHAR token to the scanner. - - yylval->integer = yytext[0]; - return _CHAR_; -} - YY_BREAK -case 8: -YY_RULE_SETUP + { + // Any non-special character is passed as a CHAR token to the scanner. + + yylval->integer = yytext[0]; + return _CHAR_; + } + YY_BREAK + case 8: + YY_RULE_SETUP #line 234 "re_lexer.l" -{ - return _WORD_CHAR_; -} - YY_BREAK -case 9: -YY_RULE_SETUP + { + return _WORD_CHAR_; + } + YY_BREAK + case 9: + YY_RULE_SETUP #line 239 "re_lexer.l" -{ - return _NON_WORD_CHAR_; -} - YY_BREAK -case 10: -YY_RULE_SETUP + { + return _NON_WORD_CHAR_; + } + YY_BREAK + case 10: + YY_RULE_SETUP #line 244 "re_lexer.l" -{ - return _SPACE_; -} - YY_BREAK -case 11: -YY_RULE_SETUP + { + return _SPACE_; + } + YY_BREAK + case 11: + YY_RULE_SETUP #line 249 "re_lexer.l" -{ - return _NON_SPACE_; -} - YY_BREAK -case 12: -YY_RULE_SETUP + { + return _NON_SPACE_; + } + YY_BREAK + case 12: + YY_RULE_SETUP #line 254 "re_lexer.l" -{ - return _DIGIT_; -} - YY_BREAK -case 13: -YY_RULE_SETUP + { + return _DIGIT_; + } + YY_BREAK + case 13: + YY_RULE_SETUP #line 259 "re_lexer.l" -{ - return _NON_DIGIT_; -} - YY_BREAK -case 14: -YY_RULE_SETUP + { + return _NON_DIGIT_; + } + YY_BREAK + case 14: + YY_RULE_SETUP #line 264 "re_lexer.l" -{ - return _WORD_BOUNDARY_; -} - YY_BREAK -case 15: -YY_RULE_SETUP + { + return _WORD_BOUNDARY_; + } + YY_BREAK + case 15: + YY_RULE_SETUP #line 268 "re_lexer.l" -{ - return _NON_WORD_BOUNDARY_; -} - YY_BREAK -case 16: -YY_RULE_SETUP + { + return _NON_WORD_BOUNDARY_; + } + YY_BREAK + case 16: + YY_RULE_SETUP #line 273 "re_lexer.l" -{ - - yyerror(yyscanner, lex_env, "backreferences are not allowed"); - yyterminate(); -} - YY_BREAK -case 17: -YY_RULE_SETUP + { + yyerror(yyscanner, lex_env, "backreferences are not allowed"); + yyterminate(); + } + YY_BREAK + case 17: + YY_RULE_SETUP #line 280 "re_lexer.l" -{ - - uint8_t c; - - if (read_escaped_char(yyscanner, &c)) - { - yylval->integer = c; - return _CHAR_; - } - else - { - yyerror(yyscanner, lex_env, "illegal escape sequence"); - yyterminate(); - } -} - YY_BREAK -case 18: -YY_RULE_SETUP + { + uint8_t c; + + if (read_escaped_char(yyscanner, &c)) + { + yylval->integer = c; + return _CHAR_; + } + else + { + yyerror(yyscanner, lex_env, "illegal escape sequence"); + yyterminate(); + } + } + YY_BREAK + case 18: + YY_RULE_SETUP #line 297 "re_lexer.l" -{ - - // End of character class. - yylval->re_class = (RE_CLASS*) yr_malloc(sizeof(RE_CLASS)); - memcpy(yylval->re_class->bitmap, LEX_ENV->re_class.bitmap, 32); + { + // End of character class. + yylval->re_class = (RE_CLASS *) yr_malloc(sizeof(RE_CLASS)); + memcpy(yylval->re_class->bitmap, LEX_ENV->re_class.bitmap, 32); + + yylval->re_class->negated = LEX_ENV->re_class.negated; + + BEGIN(INITIAL); + return _CLASS_; + } + YY_BREAK + case 19: + /* rule 19 can match eol */ + YY_RULE_SETUP +#line 311 "re_lexer.l" + { + // A range inside a character class. + // [abc0-9] + // ^- matching here + + uint16_t c; + uint8_t start = yytext[0]; + uint8_t end = yytext[2]; + + if (start == '\\') + { + if (!escaped_char_value(yytext, &start)) + { + yyerror(yyscanner, lex_env, "illegal escape sequence"); + yyterminate(); + } + + if (yytext[1] == 'x') + end = yytext[5]; + else + end = yytext[3]; + } + + if (end == '\\') + { + if (!read_escaped_char(yyscanner, &end)) + { + yyerror(yyscanner, lex_env, "illegal escape sequence"); + yyterminate(); + } + } + + if (end < start) + { + yyerror(yyscanner, lex_env, "bad character range"); + yyterminate(); + } + + for (c = start; c <= end; c++) + { + LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8; + } + } + YY_BREAK + case 20: + YY_RULE_SETUP +#line 357 "re_lexer.l" + { + int i; + + for (i = 0; i < 32; i++) LEX_ENV->re_class.bitmap[i] |= word_chars[i]; + } + YY_BREAK + case 21: + YY_RULE_SETUP +#line 366 "re_lexer.l" + { + int i; + + for (i = 0; i < 32; i++) + LEX_ENV->re_class.bitmap[i] |= ~word_chars[i]; + } + YY_BREAK + case 22: + YY_RULE_SETUP +#line 375 "re_lexer.l" + { + int i; + + for (i = 0; i < 32; i++) + LEX_ENV->re_class.bitmap[i] |= space_chars[i]; + } + YY_BREAK + case 23: + YY_RULE_SETUP +#line 384 "re_lexer.l" + { + int i; + + for (i = 0; i < 32; i++) + LEX_ENV->re_class.bitmap[i] |= ~space_chars[i]; + } + YY_BREAK + case 24: + YY_RULE_SETUP +#line 393 "re_lexer.l" + { + char c; + + for (c = '0'; c <= '9'; c++) + LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8; + } + YY_BREAK + case 25: + YY_RULE_SETUP +#line 402 "re_lexer.l" + { + int i; + + for (i = 0; i < 32; i++) + { + // digits 0-7 are in the sixth byte of the vector, let that byte + // alone + if (i == 6) + continue; + + // digits 8 and 9 are the lowest two bits in the seventh byte of the + // vector, let those bits alone. + if (i == 7) + LEX_ENV->re_class.bitmap[i] |= 0xFC; + else + LEX_ENV->re_class.bitmap[i] = 0xFF; + } + } + YY_BREAK + case 26: + YY_RULE_SETUP +#line 422 "re_lexer.l" + { + uint8_t c; + + if (read_escaped_char(yyscanner, &c)) + { + LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8; + } + else + { + yyerror(yyscanner, lex_env, "illegal escape sequence"); + yyterminate(); + } + } + YY_BREAK + case 27: + YY_RULE_SETUP +#line 438 "re_lexer.l" + { + if (yytext[0] >= 32 && yytext[0] < 127) + { + // A character class (i.e: [0-9a-f]) is represented by a 256-bits + // vector, here we set to 1 the vector's bit corresponding to the + // input character. + + LEX_ENV->re_class.bitmap[yytext[0] / 8] |= 1 << yytext[0] % 8; + } + else + { + yyerror(yyscanner, lex_env, "non-ascii character"); + yyterminate(); + } + } + YY_BREAK + case YY_STATE_EOF(char_class): +#line 455 "re_lexer.l" + { + // End of regexp reached while scanning a character class. + + yyerror( + yyscanner, lex_env, "missing terminating ] for character class"); + yyterminate(); + } + YY_BREAK + case 28: + YY_RULE_SETUP +#line 464 "re_lexer.l" + { + if (yytext[0] >= 32 && yytext[0] < 127) + { + return yytext[0]; + } + else + { + yyerror(yyscanner, lex_env, "non-ascii character"); + yyterminate(); + } + } + YY_BREAK + case YY_STATE_EOF(INITIAL): +#line 478 "re_lexer.l" + { + yyterminate(); + } + YY_BREAK + case 29: + YY_RULE_SETUP +#line 483 "re_lexer.l" + ECHO; + YY_BREAK +#line 1576 "re_lexer.c" - yylval->re_class->negated = LEX_ENV->re_class.negated; + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yyg->yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if (yyg->yy_c_buf_p <= + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(yyscanner); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans(yy_current_state, yyscanner); + + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + + if (yy_next_state) + { + /* Consume the NUL. */ + yy_cp = ++yyg->yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + goto yy_find_action; + } + } + + else + switch (yy_get_next_buffer(yyscanner)) + { + case EOB_ACT_END_OF_FILE: + { + yyg->yy_did_buffer_switch_on_eof = 0; + + if (yywrap(yyscanner)) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if (!yyg->yy_did_buffer_switch_on_eof) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(yyscanner); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; + + yy_current_state = yy_get_previous_state(yyscanner); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR("fatal flex scanner internal error--no action found"); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of yylex */ - BEGIN(INITIAL); - return _CLASS_; -} - YY_BREAK -case 19: -/* rule 19 can match eol */ -YY_RULE_SETUP -#line 311 "re_lexer.l" +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = yyg->yytext_ptr; + int number_to_move, i; + int ret_val; - // A range inside a character class. - // [abc0-9] - // ^- matching here - - uint16_t c; - uint8_t start = yytext[0]; - uint8_t end = yytext[2]; + if (yyg->yy_c_buf_p > + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1]) + YY_FATAL_ERROR("fatal flex scanner internal error--end of buffer missed"); - if (start == '\\') - { - if (!escaped_char_value(yytext, &start)) + if (YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0) + { /* Don't try to fill the buffer, so this is an EOF. */ + if (yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1) { - yyerror(yyscanner, lex_env, "illegal escape sequence"); - yyterminate(); + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; } - if (yytext[1] == 'x') - end = yytext[5]; else - end = yytext[3]; - } - - if (end == '\\') - { - if (!read_escaped_char(yyscanner, &end)) { - yyerror(yyscanner, lex_env, "illegal escape sequence"); - yyterminate(); + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; } } - if (end < start) - { - yyerror(yyscanner, lex_env, "bad character range"); - yyterminate(); - } + /* Try to read more data. */ - for (c = start; c <= end; c++) - { - LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8; - } -} - YY_BREAK -case 20: -YY_RULE_SETUP -#line 357 "re_lexer.l" -{ + /* First move last chars to start of buffer. */ + number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1); - int i; + for (i = 0; i < number_to_move; ++i) *(dest++) = *(source++); - for (i = 0; i < 32; i++) - LEX_ENV->re_class.bitmap[i] |= word_chars[i]; -} - YY_BREAK -case 21: -YY_RULE_SETUP -#line 366 "re_lexer.l" -{ + if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; - int i; + else + { + int num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - + 1; - for (i = 0; i < 32; i++) - LEX_ENV->re_class.bitmap[i] |= ~word_chars[i]; -} - YY_BREAK -case 22: -YY_RULE_SETUP -#line 375 "re_lexer.l" -{ + while (num_to_read <= 0) + { /* Not enough room in the buffer - grow it. */ - int i; + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - for (i = 0; i < 32; i++) - LEX_ENV->re_class.bitmap[i] |= space_chars[i]; -} - YY_BREAK -case 23: -YY_RULE_SETUP -#line 384 "re_lexer.l" -{ + int yy_c_buf_p_offset = (int) (yyg->yy_c_buf_p - b->yy_ch_buf); - int i; + if (b->yy_is_our_buffer) + { + int new_size = b->yy_buf_size * 2; - for (i = 0; i < 32; i++) - LEX_ENV->re_class.bitmap[i] |= ~space_chars[i]; -} - YY_BREAK -case 24: -YY_RULE_SETUP -#line 393 "re_lexer.l" -{ + if (new_size <= 0) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; - char c; + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc( + (void *) b->yy_ch_buf, + (yy_size_t)(b->yy_buf_size + 2), + yyscanner); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; - for (c = '0'; c <= '9'; c++) - LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8; -} - YY_BREAK -case 25: -YY_RULE_SETUP -#line 402 "re_lexer.l" -{ + if (!b->yy_ch_buf) + YY_FATAL_ERROR("fatal error - scanner input buffer overflow"); - int i; + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - for (i = 0; i < 32; i++) - { - // digits 0-7 are in the sixth byte of the vector, let that byte alone - if (i == 6) - continue; - - // digits 8 and 9 are the lowest two bits in the seventh byte of the - // vector, let those bits alone. - if (i == 7) - LEX_ENV->re_class.bitmap[i] |= 0xFC; - else - LEX_ENV->re_class.bitmap[i] = 0xFF; - } -} - YY_BREAK -case 26: -YY_RULE_SETUP -#line 422 "re_lexer.l" -{ + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + } - uint8_t c; + if (num_to_read > YY_READ_BUF_SIZE) + num_to_read = YY_READ_BUF_SIZE; - if (read_escaped_char(yyscanner, &c)) - { - LEX_ENV->re_class.bitmap[c / 8] |= 1 << c % 8; - } - else - { - yyerror(yyscanner, lex_env, "illegal escape sequence"); - yyterminate(); + /* Read in more data. */ + YY_INPUT( + (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + yyg->yy_n_chars, + num_to_read); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } -} - YY_BREAK -case 27: -YY_RULE_SETUP -#line 438 "re_lexer.l" -{ - if (yytext[0] >= 32 && yytext[0] < 127) + if (yyg->yy_n_chars == 0) { - // A character class (i.e: [0-9a-f]) is represented by a 256-bits vector, - // here we set to 1 the vector's bit corresponding to the input character. + if (number_to_move == YY_MORE_ADJ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin, yyscanner); + } - LEX_ENV->re_class.bitmap[yytext[0] / 8] |= 1 << yytext[0] % 8; - } - else - { - yyerror(yyscanner, lex_env, "non-ascii character"); - yyterminate(); + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING; + } } -} - YY_BREAK -case YY_STATE_EOF(char_class): -#line 455 "re_lexer.l" -{ - - // End of regexp reached while scanning a character class. - - yyerror(yyscanner, lex_env, "missing terminating ] for character class"); - yyterminate(); -} - YY_BREAK -case 28: -YY_RULE_SETUP -#line 464 "re_lexer.l" -{ - if (yytext[0] >= 32 && yytext[0] < 127) - { - return yytext[0]; - } else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yyg->yy_n_chars + number_to_move) > + YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - yyerror(yyscanner, lex_env, "non-ascii character"); - yyterminate(); + /* Extend the array by 50%, plus the number we really need. */ + int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, + (yy_size_t) new_size, + yyscanner); + if (!YY_CURRENT_BUFFER_LVALUE->yy_ch_buf) + YY_FATAL_ERROR("out of dynamic memory in yy_get_next_buffer()"); + /* "- 2" to take care of EOB's */ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); } -} - YY_BREAK -case YY_STATE_EOF(INITIAL): -#line 478 "re_lexer.l" -{ - yyterminate(); -} - YY_BREAK -case 29: -YY_RULE_SETUP -#line 483 "re_lexer.l" -ECHO; - YY_BREAK -#line 1576 "re_lexer.c" + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = + YY_END_OF_BUFFER_CHAR; - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yyg->yy_hold_char; - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yyg->yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_END_OF_FILE: - { - yyg->yy_did_buffer_switch_on_eof = 0; - - if ( yywrap( yyscanner ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = - yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - yyg->yy_c_buf_p = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = yyg->yytext_ptr; - int number_to_move, i; - int ret_val; - - if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1); - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; - - else - { - int num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) (yyg->yy_c_buf_p - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc( (void *) b->yy_ch_buf, - (yy_size_t) (b->yy_buf_size + 2) , yyscanner ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = NULL; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - if ( yyg->yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin , yyscanner); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( - (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - /* "- 2" to take care of EOB's */ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); - } - - yyg->yy_n_chars += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; + return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ - static yy_state_type yy_get_previous_state (yyscan_t yyscanner) +static yy_state_type yy_get_previous_state(yyscan_t yyscanner) { - yy_state_type yy_current_state; - char *yy_cp; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - yy_current_state = yyg->yy_start; - - for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 45 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - } - - return yy_current_state; + yy_state_type yy_current_state; + char *yy_cp; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + yy_current_state = yyg->yy_start; + + for (yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if (yy_accept[yy_current_state]) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) + { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 45) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return yy_current_state; } /* yy_try_NUL_trans - try to make a transition on the NUL character @@ -1884,29 +1822,32 @@ static int yy_get_next_buffer (yyscan_t yyscanner) * synopsis * next_state = yy_try_NUL_trans( current_state ); */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) +static yy_state_type yy_try_NUL_trans( + yy_state_type yy_current_state, + yyscan_t yyscanner) { - int yy_is_jam; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ - char *yy_cp = yyg->yy_c_buf_p; - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 45 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 44); - - (void)yyg; - return yy_is_jam ? 0 : yy_current_state; + int yy_is_jam; + struct yyguts_t *yyg = (struct yyguts_t *) + yyscanner; /* This var may be unused depending upon options. */ + char *yy_cp = yyg->yy_c_buf_p; + + YY_CHAR yy_c = 1; + if (yy_accept[yy_current_state]) + { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) + { + yy_current_state = (int) yy_def[yy_current_state]; + if (yy_current_state >= 45) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 44); + + (void) yyg; + return yy_is_jam ? 0 : yy_current_state; } #ifndef YY_NO_UNPUT @@ -1915,255 +1856,258 @@ static int yy_get_next_buffer (yyscan_t yyscanner) #ifndef YY_NO_INPUT #ifdef __cplusplus - static int yyinput (yyscan_t yyscanner) +static int yyinput(yyscan_t yyscanner) #else - static int input (yyscan_t yyscanner) +static int input(yyscan_t yyscanner) #endif { - int c; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - *yyg->yy_c_buf_p = yyg->yy_hold_char; - - if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - /* This was really a NUL. */ - *yyg->yy_c_buf_p = '\0'; - - else - { /* need more input */ - int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr); - ++yyg->yy_c_buf_p; - - switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart( yyin , yyscanner); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( yyscanner ) ) - return 0; - - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; + int c; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + *yyg->yy_c_buf_p = yyg->yy_hold_char; + + if (*yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if (yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]) + /* This was really a NUL. */ + *yyg->yy_c_buf_p = '\0'; + + else + { /* need more input */ + int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr); + ++yyg->yy_c_buf_p; + + switch (yy_get_next_buffer(yyscanner)) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin, yyscanner); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if (yywrap(yyscanner)) + return 0; + + if (!yyg->yy_did_buffer_switch_on_eof) + YY_NEW_FILE; #ifdef __cplusplus - return yyinput(yyscanner); + return yyinput(yyscanner); #else - return input(yyscanner); + return input(yyscanner); #endif - } + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; + break; + } + } + } - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = yyg->yytext_ptr + offset; - break; - } - } - } + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; - c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ - *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ - yyg->yy_hold_char = *++yyg->yy_c_buf_p; + if (c == '\n') - if ( c == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; + do + { + yylineno++; + yycolumn = 0; + } while (0); - return c; + return c; } -#endif /* ifndef YY_NO_INPUT */ +#endif /* ifndef YY_NO_INPUT */ /** Immediately switch to a different input stream. * @param input_file A readable stream. * @param yyscanner The scanner object. * @note This function does not reset the start condition to @c INITIAL . */ - void yyrestart (FILE * input_file , yyscan_t yyscanner) +void yyrestart(FILE *input_file, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); - } + if (!YY_CURRENT_BUFFER) + { + yyensure_buffer_stack(yyscanner); + YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE, yyscanner); + } - yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner); - yy_load_buffer_state( yyscanner ); + yy_init_buffer(YY_CURRENT_BUFFER, input_file, yyscanner); + yy_load_buffer_state(yyscanner); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. * @param yyscanner The scanner object. */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (yyscanner); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( yyscanner ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - yyg->yy_did_buffer_switch_on_eof = 1; + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack(yyscanner); + if (YY_CURRENT_BUFFER == new_buffer) + return; + + if (YY_CURRENT_BUFFER) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state(yyscanner); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yyg->yy_did_buffer_switch_on_eof = 1; } -static void yy_load_buffer_state (yyscan_t yyscanner) +static void yy_load_buffer_state(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - yyg->yy_hold_char = *yyg->yy_c_buf_p; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + yyg->yy_hold_char = *yyg->yy_c_buf_p; } /** Allocate and initialize an input buffer state. * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * @param size The character buffer size in bytes. When in doubt, use @c + * YY_BUF_SIZE. * @param yyscanner The scanner object. * @return the allocated buffer state. */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner) +YY_BUFFER_STATE yy_create_buffer(FILE *file, int size, yyscan_t yyscanner) { - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + YY_BUFFER_STATE b; - b->yy_buf_size = size; + b = (YY_BUFFER_STATE) yyalloc(sizeof(struct yy_buffer_state), yyscanner); + if (!b) + YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + b->yy_buf_size = size; - b->yy_is_our_buffer = 1; + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc((yy_size_t)(b->yy_buf_size + 2), yyscanner); + if (!b->yy_ch_buf) + YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); - yy_init_buffer( b, file , yyscanner); + b->yy_is_our_buffer = 1; - return b; + yy_init_buffer(b, file, yyscanner); + + return b; } /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() * @param yyscanner The scanner object. */ - void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +void yy_delete_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - if ( ! b ) - return; + if (!b) + return; - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + if (b == YY_CURRENT_BUFFER) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - if ( b->yy_is_our_buffer ) - yyfree( (void *) b->yy_ch_buf , yyscanner ); + if (b->yy_is_our_buffer) + yyfree((void *) b->yy_ch_buf, yyscanner); - yyfree( (void *) b , yyscanner ); + yyfree((void *) b, yyscanner); } /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) +static void yy_init_buffer(YY_BUFFER_STATE b, FILE *file, yyscan_t yyscanner) { - int oerrno = errno; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + int oerrno = errno; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - yy_flush_buffer( b , yyscanner); + yy_flush_buffer(b, yyscanner); - b->yy_input_file = file; - b->yy_fill_buffer = 1; + b->yy_input_file = file; + b->yy_fill_buffer = 1; - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER) + { + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } - b->yy_is_interactive = 0; - - errno = oerrno; + b->yy_is_interactive = 0; + + errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. * @param yyscanner The scanner object. */ - void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) +void yy_flush_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if ( ! b ) - return; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + if (!b) + return; - b->yy_n_chars = 0; + b->yy_n_chars = 0; - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - b->yy_buf_pos = &b->yy_ch_buf[0]; + b->yy_buf_pos = &b->yy_ch_buf[0]; - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( yyscanner ); + if (b == YY_CURRENT_BUFFER) + yy_load_buffer_state(yyscanner); } /** Pushes the new state onto the stack. The new state becomes @@ -2172,134 +2116,140 @@ static void yy_load_buffer_state (yyscan_t yyscanner) * @param new_buffer The new state. * @param yyscanner The scanner object. */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) +void yypush_buffer_state(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(yyscanner); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - yyg->yy_buffer_stack_top++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(yyscanner); + + /* This block is copied from yy_switch_to_buffer. */ + if (YY_CURRENT_BUFFER) + { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + yyg->yy_buffer_stack_top++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state(yyscanner); + yyg->yy_did_buffer_switch_on_eof = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. * @param yyscanner The scanner object. */ -void yypop_buffer_state (yyscan_t yyscanner) +void yypop_buffer_state(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER , yyscanner); - YY_CURRENT_BUFFER_LVALUE = NULL; - if (yyg->yy_buffer_stack_top > 0) - --yyg->yy_buffer_stack_top; - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; - } + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER, yyscanner); + YY_CURRENT_BUFFER_LVALUE = NULL; + if (yyg->yy_buffer_stack_top > 0) + --yyg->yy_buffer_stack_top; + + if (YY_CURRENT_BUFFER) + { + yy_load_buffer_state(yyscanner); + yyg->yy_did_buffer_switch_on_eof = 1; + } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ -static void yyensure_buffer_stack (yyscan_t yyscanner) +static void yyensure_buffer_stack(yyscan_t yyscanner) { - yy_size_t num_to_alloc; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_size_t num_to_alloc; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - if (!yyg->yy_buffer_stack) { + if (!yyg->yy_buffer_stack) + { + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + yyg->yy_buffer_stack = (struct yy_buffer_state **) yyalloc( + num_to_alloc * sizeof(struct yy_buffer_state *), yyscanner); + if (!yyg->yy_buffer_stack) + YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()"); + + memset( + yyg->yy_buffer_stack, + 0, + num_to_alloc * sizeof(struct yy_buffer_state *)); + + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; + return; + } - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - yyg->yy_buffer_stack_max = num_to_alloc; - yyg->yy_buffer_stack_top = 0; - return; - } - - if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = yyg->yy_buffer_stack_max + grow_size; - yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc - (yyg->yy_buffer_stack, - num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); - yyg->yy_buffer_stack_max = num_to_alloc; - } + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1) + { + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state **) yyrealloc( + yyg->yy_buffer_stack, + num_to_alloc * sizeof(struct yy_buffer_state *), + yyscanner); + if (!yyg->yy_buffer_stack) + YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()"); + + /* zero only the new slots.*/ + memset( + yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, + 0, + grow_size * sizeof(struct yy_buffer_state *)); + yyg->yy_buffer_stack_max = num_to_alloc; + } } -/** Setup the input buffer state to scan directly from a user-specified character buffer. +/** Setup the input buffer state to scan directly from a user-specified + * character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) +YY_BUFFER_STATE yy_scan_buffer(char *base, yy_size_t size, yyscan_t yyscanner) { - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return NULL; - - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = NULL; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer( b , yyscanner ); - - return b; + YY_BUFFER_STATE b; + + if (size < 2 || base[size - 2] != YY_END_OF_BUFFER_CHAR || + base[size - 1] != YY_END_OF_BUFFER_CHAR) + /* They forgot to leave room for the EOB's. */ + return NULL; + + b = (YY_BUFFER_STATE) yyalloc(sizeof(struct yy_buffer_state), yyscanner); + if (!b) + YY_FATAL_ERROR("out of dynamic memory in yy_scan_buffer()"); + + b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = NULL; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer(b, yyscanner); + + return b; } /** Setup the input buffer state to scan a string. The next call to yylex() will @@ -2310,190 +2260,190 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscann * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ -YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner) +YY_BUFFER_STATE yy_scan_string(const char *yystr, yyscan_t yyscanner) { - - return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner); + return yy_scan_bytes(yystr, (int) strlen(yystr), yyscanner); } -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. +/** Setup the input buffer state to scan the given bytes. The next call to + * yylex() will scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = (yy_size_t) (_yybytes_len + 2); - buf = (char *) yyalloc( n , yyscanner ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer( buf, n , yyscanner); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; +YY_BUFFER_STATE yy_scan_bytes( + const char *yybytes, + int _yybytes_len, + yyscan_t yyscanner) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = (yy_size_t)(_yybytes_len + 2); + buf = (char *) yyalloc(n, yyscanner); + if (!buf) + YY_FATAL_ERROR("out of dynamic memory in yy_scan_bytes()"); + + for (i = 0; i < _yybytes_len; ++i) buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len + 1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer(buf, n, yyscanner); + if (!b) + YY_FATAL_ERROR("bad buffer in yy_scan_bytes()"); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; } #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif -static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner) +static void yynoreturn yy_fatal_error(const char *msg, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + fprintf(stderr, "%s\n", msg); + exit(YY_EXIT_FAILURE); } /* Redefine yyless() so it works in section 3 code. */ #undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = yyg->yy_hold_char; \ - yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ - yyg->yy_hold_char = *yyg->yy_c_buf_p; \ - *yyg->yy_c_buf_p = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg); \ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ + yyleng = yyless_macro_arg; \ + } while (0) /* Accessor methods (get/set functions) to struct members. */ /** Get the user-defined data for this scanner. * @param yyscanner The scanner object. */ -YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner) +YY_EXTRA_TYPE yyget_extra(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyextra; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyextra; } /** Get the current line number. * @param yyscanner The scanner object. */ -int yyget_lineno (yyscan_t yyscanner) +int yyget_lineno(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - if (! YY_CURRENT_BUFFER) - return 0; - - return yylineno; + if (!YY_CURRENT_BUFFER) + return 0; + + return yylineno; } /** Get the current column number. * @param yyscanner The scanner object. */ -int yyget_column (yyscan_t yyscanner) +int yyget_column(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + if (!YY_CURRENT_BUFFER) + return 0; - if (! YY_CURRENT_BUFFER) - return 0; - - return yycolumn; + return yycolumn; } /** Get the input stream. * @param yyscanner The scanner object. */ -FILE *yyget_in (yyscan_t yyscanner) +FILE *yyget_in(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyin; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyin; } /** Get the output stream. * @param yyscanner The scanner object. */ -FILE *yyget_out (yyscan_t yyscanner) +FILE *yyget_out(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyout; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyout; } /** Get the length of the current token. * @param yyscanner The scanner object. */ -int yyget_leng (yyscan_t yyscanner) +int yyget_leng(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyleng; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yyleng; } /** Get the current token. * @param yyscanner The scanner object. */ -char *yyget_text (yyscan_t yyscanner) +char *yyget_text(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yytext; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yytext; } /** Set the user-defined data. This data is never touched by the scanner. * @param user_defined The data to be associated with this scanner. * @param yyscanner The scanner object. */ -void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) +void yyset_extra(YY_EXTRA_TYPE user_defined, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyextra = user_defined ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyextra = user_defined; } /** Set the current line number. * @param _line_number line number * @param yyscanner The scanner object. */ -void yyset_lineno (int _line_number , yyscan_t yyscanner) +void yyset_lineno(int _line_number, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; - /* lineno is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "yyset_lineno called with no buffer" ); - - yylineno = _line_number; + /* lineno is only valid if an input buffer exists. */ + if (!YY_CURRENT_BUFFER) + YY_FATAL_ERROR("yyset_lineno called with no buffer"); + + yylineno = _line_number; } /** Set the current column. * @param _column_no column number * @param yyscanner The scanner object. */ -void yyset_column (int _column_no , yyscan_t yyscanner) +void yyset_column(int _column_no, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + /* column is only valid if an input buffer exists. */ + if (!YY_CURRENT_BUFFER) + YY_FATAL_ERROR("yyset_column called with no buffer"); - /* column is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "yyset_column called with no buffer" ); - - yycolumn = _column_no; + yycolumn = _column_no; } /** Set the input stream. This does not discard the current @@ -2502,68 +2452,72 @@ void yyset_column (int _column_no , yyscan_t yyscanner) * @param yyscanner The scanner object. * @see yy_switch_to_buffer */ -void yyset_in (FILE * _in_str , yyscan_t yyscanner) +void yyset_in(FILE *_in_str, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyin = _in_str ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyin = _in_str; } -void yyset_out (FILE * _out_str , yyscan_t yyscanner) +void yyset_out(FILE *_out_str, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyout = _out_str ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yyout = _out_str; } -int yyget_debug (yyscan_t yyscanner) +int yyget_debug(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yy_flex_debug; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yy_flex_debug; } -void yyset_debug (int _bdebug , yyscan_t yyscanner) +void yyset_debug(int _bdebug, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yy_flex_debug = _bdebug ; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yy_flex_debug = _bdebug; } /* Accessor methods for yylval and yylloc */ -YYSTYPE * yyget_lval (yyscan_t yyscanner) +YYSTYPE *yyget_lval(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yylval; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + return yylval; } -void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) +void yyset_lval(YYSTYPE *yylval_param, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yylval = yylval_param; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + yylval = yylval_param; } /* User-visible API */ /* yylex_init is special because it creates the scanner itself, so it is - * the ONLY reentrant function that doesn't take the scanner as the last argument. - * That's why we explicitly handle the declaration, instead of using our macros. + * the ONLY reentrant function that doesn't take the scanner as the last + * argument. That's why we explicitly handle the declaration, instead of using + * our macros. */ -int yylex_init(yyscan_t* ptr_yy_globals) +int yylex_init(yyscan_t *ptr_yy_globals) { - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } + if (ptr_yy_globals == NULL) + { + errno = EINVAL; + return 1; + } - *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL ); + *ptr_yy_globals = (yyscan_t) yyalloc(sizeof(struct yyguts_t), NULL); - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } + if (*ptr_yy_globals == NULL) + { + errno = ENOMEM; + return 1; + } - /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for + * releases. */ + memset(*ptr_yy_globals, 0x00, sizeof(struct yyguts_t)); - return yy_init_globals ( *ptr_yy_globals ); + return yy_init_globals(*ptr_yy_globals); } /* yylex_init_extra has the same functionality as yylex_init, but follows the @@ -2573,94 +2527,97 @@ int yylex_init(yyscan_t* ptr_yy_globals) * The user defined value in the first argument will be available to yyalloc in * the yyextra field. */ -int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals ) +int yylex_init_extra(YY_EXTRA_TYPE yy_user_defined, yyscan_t *ptr_yy_globals) { - struct yyguts_t dummy_yyguts; + struct yyguts_t dummy_yyguts; - yyset_extra (yy_user_defined, &dummy_yyguts); + yyset_extra(yy_user_defined, &dummy_yyguts); - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } + if (ptr_yy_globals == NULL) + { + errno = EINVAL; + return 1; + } - *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + *ptr_yy_globals = (yyscan_t) yyalloc(sizeof(struct yyguts_t), &dummy_yyguts); - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } + if (*ptr_yy_globals == NULL) + { + errno = ENOMEM; + return 1; + } - /* By setting to 0xAA, we expose bugs in - yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals, 0x00, sizeof(struct yyguts_t)); - yyset_extra (yy_user_defined, *ptr_yy_globals); + yyset_extra(yy_user_defined, *ptr_yy_globals); - return yy_init_globals ( *ptr_yy_globals ); + return yy_init_globals(*ptr_yy_globals); } -static int yy_init_globals (yyscan_t yyscanner) +static int yy_init_globals(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ - yyg->yy_buffer_stack = NULL; - yyg->yy_buffer_stack_top = 0; - yyg->yy_buffer_stack_max = 0; - yyg->yy_c_buf_p = NULL; - yyg->yy_init = 0; - yyg->yy_start = 0; + yyg->yy_buffer_stack = NULL; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = NULL; + yyg->yy_init = 0; + yyg->yy_start = 0; - yyg->yy_start_stack_ptr = 0; - yyg->yy_start_stack_depth = 0; - yyg->yy_start_stack = NULL; + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; /* Defined in main.c */ #ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; + yyin = stdin; + yyout = stdout; #else - yyin = NULL; - yyout = NULL; + yyin = NULL; + yyout = NULL; #endif - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; } /* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (yyscan_t yyscanner) +int yylex_destroy(yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(yyscanner); - } - - /* Destroy the stack itself. */ - yyfree(yyg->yy_buffer_stack , yyscanner); - yyg->yy_buffer_stack = NULL; - - /* Destroy the start condition stack. */ - yyfree( yyg->yy_start_stack , yyscanner ); - yyg->yy_start_stack = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( yyscanner); - - /* Destroy the main struct (reentrant only). */ - yyfree ( yyscanner , yyscanner ); - yyscanner = NULL; - return 0; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + + /* Pop the buffer stack, destroying each element. */ + while (YY_CURRENT_BUFFER) + { + yy_delete_buffer(YY_CURRENT_BUFFER, yyscanner); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(yyscanner); + } + + /* Destroy the stack itself. */ + yyfree(yyg->yy_buffer_stack, yyscanner); + yyg->yy_buffer_stack = NULL; + + /* Destroy the start condition stack. */ + yyfree(yyg->yy_start_stack, yyscanner); + yyg->yy_start_stack = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next + * time yylex() is called, initialization will occur. */ + yy_init_globals(yyscanner); + + /* Destroy the main struct (reentrant only). */ + yyfree(yyscanner, yyscanner); + yyscanner = NULL; + return 0; } /* @@ -2668,55 +2625,54 @@ int yylex_destroy (yyscan_t yyscanner) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner) +static void yy_flex_strncpy(char *s1, const char *s2, int n, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; + int i; + for (i = 0; i < n; ++i) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (const char * s , yyscan_t yyscanner) +static int yy_flex_strlen(const char *s, yyscan_t yyscanner) { - int n; - for ( n = 0; s[n]; ++n ) - ; + int n; + for (n = 0; s[n]; ++n) + ; - return n; + return n; } #endif -void *yyalloc (yy_size_t size , yyscan_t yyscanner) +void *yyalloc(yy_size_t size, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - return malloc(size); + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + return malloc(size); } -void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner) +void *yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return realloc(ptr, size); + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return realloc(ptr, size); } -void yyfree (void * ptr , yyscan_t yyscanner) +void yyfree(void *ptr, yyscan_t yyscanner) { - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ + struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; + (void) yyg; + free((char *) ptr); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" @@ -2724,16 +2680,14 @@ void yyfree (void * ptr , yyscan_t yyscanner) #line 483 "re_lexer.l" -int escaped_char_value( - char* text, - uint8_t* value) +int escaped_char_value(char *text, uint8_t *value) { unsigned int hex_value; char hex[3]; assert(text[0] == '\\'); - switch(text[1]) + switch (text[1]) { case 'x': if (!isxdigit(text[2]) || !isxdigit(text[3])) @@ -2780,9 +2734,7 @@ int escaped_char_value( #endif -int read_escaped_char( - yyscan_t yyscanner, - uint8_t* escaped_char) +int read_escaped_char(yyscan_t yyscanner, uint8_t *escaped_char) { char text[4] = {0, 0, 0, 0}; @@ -2815,11 +2767,9 @@ int read_escaped_char( // happens we are deep inside the parsing logic generated by flex/bison and // the only way to exit gracefully from there is using setjmp/longjmp. // -void yyfatal( - yyscan_t yyscanner, - const char *error_message) +void yyfatal(yyscan_t yyscanner, const char *error_message) { - jmp_buf* recovery_trampoline = (jmp_buf*) yr_thread_storage_get_value( + jmp_buf *recovery_trampoline = (jmp_buf *) yr_thread_storage_get_value( &yr_yyfatal_trampoline_tls); longjmp(*recovery_trampoline, 1); @@ -2828,7 +2778,7 @@ void yyfatal( void yyerror( yyscan_t yyscanner, - RE_LEX_ENVIRONMENT* lex_env, + RE_LEX_ENVIRONMENT *lex_env, const char *error_message) { // if lex_env->last_error was set to some error code before @@ -2848,10 +2798,7 @@ void yyerror( } -int yr_parse_re_string( - const char* re_string, - RE_AST** re_ast, - RE_ERROR* error) +int yr_parse_re_string(const char *re_string, RE_AST **re_ast, RE_ERROR *error) { yyscan_t yyscanner; jmp_buf recovery_trampoline; @@ -2860,9 +2807,7 @@ int yr_parse_re_string( lex_env.last_error = ERROR_SUCCESS; lex_env.last_error_message[0] = '\0'; - yr_thread_storage_set_value( - &yr_yyfatal_trampoline_tls, - &recovery_trampoline); + yr_thread_storage_set_value(&yr_yyfatal_trampoline_tls, &recovery_trampoline); // setjmp returns a non-zero value only when we are returning to this // point via a call to longjmp to the recovery trampoline. @@ -2882,14 +2827,10 @@ int yr_parse_re_string( yr_re_ast_destroy(*re_ast); *re_ast = NULL; - strlcpy( - error->message, - lex_env.last_error_message, - sizeof(error->message)); + strlcpy(error->message, lex_env.last_error_message, sizeof(error->message)); return lex_env.last_error; } return ERROR_SUCCESS; } - diff --git a/libyara/rules.c b/libyara/rules.c index e9ab95c74a..78a1aedcf8 100644 --- a/libyara/rules.c +++ b/libyara/rules.c @@ -28,19 +28,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include #include - +#include +#include #include #include +#include #include #include #include -#include -#include #include #include -#include +#include YR_API int yr_rules_define_integer_variable( @@ -209,9 +208,14 @@ YR_API int yr_rules_scan_mem( void* user_data, int timeout) { - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s(buffer=%p buffer_size=%zu timeout=%d) {}\n", - __FUNCTION__, buffer, buffer_size, timeout); + __FUNCTION__, + buffer, + buffer_size, + timeout); YR_SCANNER* scanner; int result; @@ -245,13 +249,7 @@ YR_API int yr_rules_scan_file( if (result == ERROR_SUCCESS) { result = yr_rules_scan_mem( - rules, - mfile.data, - mfile.size, - flags, - callback, - user_data, - timeout); + rules, mfile.data, mfile.size, flags, callback, user_data, timeout); yr_filemap_unmap(&mfile); } @@ -275,13 +273,7 @@ YR_API int yr_rules_scan_fd( if (result == ERROR_SUCCESS) { result = yr_rules_scan_mem( - rules, - mfile.data, - mfile.size, - flags, - callback, - user_data, - timeout); + rules, mfile.data, mfile.size, flags, callback, user_data, timeout); yr_filemap_unmap_fd(&mfile); } @@ -298,14 +290,12 @@ YR_API int yr_rules_scan_proc( void* user_data, int timeout) { - YR_DEBUG_FPRINTF(2, stderr, - "+ %s(pid=%d timeout=%d) {}\n", __FUNCTION__, pid, timeout); + YR_DEBUG_FPRINTF( + 2, stderr, "+ %s(pid=%d timeout=%d) {}\n", __FUNCTION__, pid, timeout); YR_MEMORY_BLOCK_ITERATOR iterator; - int result = yr_process_open_iterator( - pid, - &iterator); + int result = yr_process_open_iterator(pid, &iterator); if (result == ERROR_SUCCESS) { @@ -324,9 +314,7 @@ YR_API int yr_rules_scan_proc( } -int yr_rules_from_arena( - YR_ARENA* arena, - YR_RULES** rules) +int yr_rules_from_arena(YR_ARENA* arena, YR_RULES** rules) { YR_RULES* new_rules = (YR_RULES*) yr_malloc(sizeof(YR_RULES)); @@ -346,11 +334,9 @@ int yr_rules_from_arena( new_rules->num_strings = summary->num_strings; new_rules->num_namespaces = summary->num_namespaces; - new_rules->rules_list_head = yr_arena_get_ptr( - arena, YR_RULES_TABLE, 0); + new_rules->rules_list_head = yr_arena_get_ptr(arena, YR_RULES_TABLE, 0); - new_rules->strings_list_head = yr_arena_get_ptr( - arena, YR_STRINGS_TABLE, 0); + new_rules->strings_list_head = yr_arena_get_ptr(arena, YR_STRINGS_TABLE, 0); new_rules->externals_list_head = yr_arena_get_ptr( arena, YR_EXTERNAL_VARIABLES_TABLE, 0); @@ -364,8 +350,7 @@ int yr_rules_from_arena( new_rules->ac_match_pool = yr_arena_get_ptr( arena, YR_AC_STATE_MATCHES_POOL, 0); - new_rules->code_start = yr_arena_get_ptr( - arena, YR_CODE_SECTION, 0); + new_rules->code_start = yr_arena_get_ptr(arena, YR_CODE_SECTION, 0); *rules = new_rules; @@ -373,10 +358,7 @@ int yr_rules_from_arena( } - -YR_API int yr_rules_load_stream( - YR_STREAM* stream, - YR_RULES** rules) +YR_API int yr_rules_load_stream(YR_STREAM* stream, YR_RULES** rules) { YR_ARENA* arena; @@ -395,9 +377,7 @@ YR_API int yr_rules_load_stream( } -YR_API int yr_rules_load( - const char* filename, - YR_RULES** rules) +YR_API int yr_rules_load(const char* filename, YR_RULES** rules) { int result; @@ -417,17 +397,13 @@ YR_API int yr_rules_load( } -YR_API int yr_rules_save_stream( - YR_RULES* rules, - YR_STREAM* stream) +YR_API int yr_rules_save_stream(YR_RULES* rules, YR_STREAM* stream) { return yr_arena_save_stream(rules->arena, stream); } -YR_API int yr_rules_save( - YR_RULES* rules, - const char* filename) +YR_API int yr_rules_save(YR_RULES* rules, const char* filename) { int result; @@ -447,21 +423,18 @@ YR_API int yr_rules_save( } -static int _uint32_cmp ( - const void * a, - const void * b) +static int _uint32_cmp(const void* a, const void* b) { - return (*(uint32_t*) a - *(uint32_t*) b); + return (*(uint32_t*) a - *(uint32_t*) b); } -YR_API int yr_rules_get_stats( - YR_RULES* rules, - YR_RULES_STATS *stats) +YR_API int yr_rules_get_stats(YR_RULES* rules, YR_RULES_STATS* stats) { memset(stats, 0, sizeof(YR_RULES_STATS)); stats->ac_tables_size = yr_arena_get_current_offset( - rules->arena, YR_AC_TRANSITION_TABLE) / sizeof(YR_AC_TRANSITION); + rules->arena, YR_AC_TRANSITION_TABLE) / + sizeof(YR_AC_TRANSITION); uint32_t* match_list_lengths = (uint32_t*) yr_malloc( sizeof(uint32_t) * stats->ac_tables_size); @@ -481,7 +454,7 @@ YR_API int yr_rules_get_stats( if (rules->ac_match_table[i] != 0) { - YR_AC_MATCH *m = &rules->ac_match_pool[rules->ac_match_table[i]-1]; + YR_AC_MATCH* m = &rules->ac_match_pool[rules->ac_match_table[i] - 1]; while (m != NULL) { @@ -515,14 +488,14 @@ YR_API int yr_rules_get_stats( for (int i = 0; i < 100; i++) { if (i < c) - stats->top_ac_match_list_lengths[i] = match_list_lengths[c-i-1]; + stats->top_ac_match_list_lengths[i] = match_list_lengths[c - i - 1]; else stats->top_ac_match_list_lengths[i] = 0; } stats->ac_average_match_list_length = match_list_length_sum / c; stats->ac_match_list_length_pctls[0] = match_list_lengths[0]; - stats->ac_match_list_length_pctls[100] = match_list_lengths[c-1]; + stats->ac_match_list_length_pctls[100] = match_list_lengths[c - 1]; for (int i = 1; i < 100; i++) stats->ac_match_list_length_pctls[i] = match_list_lengths[(c * i) / 100]; @@ -533,8 +506,7 @@ YR_API int yr_rules_get_stats( } -YR_API int yr_rules_destroy( - YR_RULES* rules) +YR_API int yr_rules_destroy(YR_RULES* rules) { YR_EXTERNAL_VARIABLE* external = rules->externals_list_head; @@ -552,8 +524,7 @@ YR_API int yr_rules_destroy( return ERROR_SUCCESS; } -YR_API void yr_rule_disable( - YR_RULE* rule) +YR_API void yr_rule_disable(YR_RULE* rule) { YR_STRING* string; @@ -566,8 +537,7 @@ YR_API void yr_rule_disable( } -YR_API void yr_rule_enable( - YR_RULE* rule) +YR_API void yr_rule_enable(YR_RULE* rule) { YR_STRING* string; diff --git a/libyara/scan.c b/libyara/scan.c index 04ff589430..023c223853 100644 --- a/libyara/scan.c +++ b/libyara/scan.c @@ -28,20 +28,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include #include #include - +#include +#include #include +#include #include -#include #include -#include -#include -#include #include #include - +#include +#include typedef struct _CALLBACK_ARGS @@ -80,16 +78,20 @@ static int _yr_scan_xor_compare( // every *s2 as we compare. k = *s1 ^ *s2; - while (i < string_length && *s1++ == ((*s2++) ^ k)) - i++; + while (i < string_length && *s1++ == ((*s2++) ^ k)) i++; result = (int) ((i == string_length) ? i : 0); - _exit:; +_exit:; - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s(data_size=%zu string_length=%zu) {} = %d\n", - __FUNCTION__, data_size, string_length, result); + __FUNCTION__, + data_size, + string_length, + result); return result; } @@ -116,7 +118,7 @@ static int _yr_scan_xor_wcompare( while (i < string_length && *s1 == ((*s2) ^ k) && ((*(s1 + 1)) ^ k) == 0x00) { - s1+=2; + s1 += 2; s2++; i++; } @@ -139,8 +141,7 @@ static int _yr_scan_compare( if (data_size < string_length) return 0; - while (i < string_length && *s1++ == *s2++) - i++; + while (i < string_length && *s1++ == *s2++) i++; return (int) ((i == string_length) ? i : 0); } @@ -160,8 +161,7 @@ static int _yr_scan_icompare( if (data_size < string_length) return 0; - while (i < string_length && yr_lowercase[*s1++] == yr_lowercase[*s2++]) - i++; + while (i < string_length && yr_lowercase[*s1++] == yr_lowercase[*s2++]) i++; return (int) ((i == string_length) ? i : 0); } @@ -184,18 +184,23 @@ static int _yr_scan_wcompare( while (i < string_length && *s1 == *s2 && *(s1 + 1) == 0x00) { - s1+=2; + s1 += 2; s2++; i++; } result = (int) ((i == string_length) ? i * 2 : 0); - _exit:; +_exit:; - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s(data_size=%zu string_length=%zu) {} = %d\n", - __FUNCTION__, data_size, string_length, result); + __FUNCTION__, + data_size, + string_length, + result); return result; } @@ -216,22 +221,26 @@ static int _yr_scan_wicompare( if (data_size < string_length * 2) goto _exit; - while (i < string_length && - yr_lowercase[*s1] == yr_lowercase[*s2] && + while (i < string_length && yr_lowercase[*s1] == yr_lowercase[*s2] && *(s1 + 1) == 0x00) { - s1+=2; + s1 += 2; s2++; i++; } result = (int) ((i == string_length) ? i * 2 : 0); - _exit:; +_exit:; - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s(data_size=%zu string_length=%zu) {} = %d\n", - __FUNCTION__, data_size, string_length, result); + __FUNCTION__, + data_size, + string_length, + result); return result; } @@ -278,9 +287,9 @@ static int _yr_scan_add_match_to_list( { int result = ERROR_SUCCESS; - #if YR_DEBUG_VERBOSITY > 0 +#if YR_DEBUG_VERBOSITY > 0 int32_t count_orig = matches_list->count; - #endif +#endif YR_MATCH* insertion_point = matches_list->tail; @@ -292,7 +301,8 @@ static int _yr_scan_add_match_to_list( while (insertion_point != NULL) { - if ((match->base + match->offset) == (insertion_point->base + insertion_point->offset)) + if ((match->base + match->offset) == + (insertion_point->base + insertion_point->offset)) { if (replace_if_exists) { @@ -301,10 +311,11 @@ static int _yr_scan_add_match_to_list( insertion_point->data = match->data; } - goto _exit; // return ERROR_SUCCESS + goto _exit; // return ERROR_SUCCESS } - if ((match->base + match->offset) > (insertion_point->base + insertion_point->offset)) + if ((match->base + match->offset) > + (insertion_point->base + insertion_point->offset)) break; insertion_point = insertion_point->prev; @@ -330,12 +341,13 @@ static int _yr_scan_add_match_to_list( else matches_list->tail = match; - _exit:; +_exit:; - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s(replace_if_exists=%d) {} = %d //" - " match->base=0x%" PRIx64 - " match->offset=%" PRIi64 + " match->base=0x%" PRIx64 " match->offset=%" PRIi64 " matches_list->count=%u += %u\n", __FUNCTION__, replace_if_exists, @@ -393,9 +405,11 @@ static int _yr_scan_verify_chained_string_match( uint64_t match_offset, int32_t match_length) { - YR_DEBUG_FPRINTF(2, stderr, - "+ %s (match_data=%p match_base=%" PRIx64 - " match_offset=0x%" PRIx64 " match_length=%'d) {} \n", + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s (match_data=%p match_base=%" PRIx64 " match_offset=0x%" PRIx64 + " match_length=%'d) {} \n", __FUNCTION__, match_data, match_base, @@ -462,8 +476,9 @@ static int _yr_scan_verify_chained_string_match( match, &context->unconfirmed_matches[matching_string->chained_to->idx]); } - else if (ending_offset + matching_string->chain_gap_max >= match_offset && - ending_offset + matching_string->chain_gap_min <= match_offset) + else if ( + ending_offset + matching_string->chain_gap_max >= match_offset && + ending_offset + matching_string->chain_gap_min <= match_offset) { // If the distance between the end of the unconfirmed match and the // start of the current match is within the range specified in the @@ -480,9 +495,8 @@ static int _yr_scan_verify_chained_string_match( { uint32_t max_match_data; - FAIL_ON_ERROR(yr_get_configuration( - YR_CONFIG_MAX_MATCH_DATA, - &max_match_data)) + FAIL_ON_ERROR( + yr_get_configuration(YR_CONFIG_MAX_MATCH_DATA, &max_match_data)) if (STRING_IS_CHAIN_TAIL(matching_string)) { @@ -495,7 +509,8 @@ static int _yr_scan_verify_chained_string_match( // is a recursive operation that will update the chain_length field for // every unconfirmed match in all the strings in the chain up to the head // of the chain. - match = context->unconfirmed_matches[matching_string->chained_to->idx].head; + match = + context->unconfirmed_matches[matching_string->chained_to->idx].head; while (match != NULL) { @@ -514,7 +529,7 @@ static int _yr_scan_verify_chained_string_match( full_chain_length = 0; string = matching_string; - while(string->chained_to != NULL) + while (string->chained_to != NULL) { full_chain_length++; string = string->chained_to; @@ -534,11 +549,10 @@ static int _yr_scan_verify_chained_string_match( if (match->chain_length == full_chain_length) { _yr_scan_remove_match_from_list( - match, - &context->unconfirmed_matches[string->idx]); + match, &context->unconfirmed_matches[string->idx]); - match->match_length = (int32_t) \ - (match_offset - match->offset + match_length); + match->match_length = (int32_t)( + match_offset - match->offset + match_length); match->data_length = yr_min(match->match_length, max_match_data); @@ -554,17 +568,16 @@ static int _yr_scan_verify_chained_string_match( match->data_length); FAIL_ON_ERROR(_yr_scan_add_match_to_list( - match, - &context->matches[string->idx], - false)); + match, &context->matches[string->idx], false)); } match = next_match; } } - else // It's a part of a chain, but not the tail. + else // It's a part of a chain, but not the tail. { - new_match = yr_notebook_alloc(context->matches_notebook, sizeof(YR_MATCH)); + new_match = yr_notebook_alloc( + context->matches_notebook, sizeof(YR_MATCH)); if (new_match == NULL) return ERROR_INSUFFICIENT_MEMORY; @@ -589,10 +602,7 @@ static int _yr_scan_verify_chained_string_match( if (new_match->data == NULL) return ERROR_INSUFFICIENT_MEMORY; - memcpy( - (void*) new_match->data, - match_data, - new_match->data_length); + memcpy((void*) new_match->data, match_data, new_match->data_length); } else { @@ -628,11 +638,12 @@ static int _yr_scan_match_callback( size_t match_offset = match_data - callback_args->data; - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s(match_data=%p match_length=%d) { //" " match_offset=%ld args->data=%p args->string.length=%u" - " args->data_base=0x%" PRIx64 - " args->data_size=%zu" + " args->data_base=0x%" PRIx64 " args->data_size=%zu" " args->forward_matches=%'u\n", __FUNCTION__, match_data, @@ -654,26 +665,24 @@ static int _yr_scan_match_callback( { if (flags & RE_FLAGS_WIDE) { - if (match_offset >= 2 && - *(match_data - 1) == 0 && + if (match_offset >= 2 && *(match_data - 1) == 0 && isalnum(*(match_data - 2))) - goto _exit; // return ERROR_SUCCESS; + goto _exit; // return ERROR_SUCCESS; if (match_offset + match_length + 1 < callback_args->data_size && *(match_data + match_length + 1) == 0 && isalnum(*(match_data + match_length))) - goto _exit; // return ERROR_SUCCESS; + goto _exit; // return ERROR_SUCCESS; } else { - if (match_offset >= 1 && - isalnum(*(match_data - 1))) - goto _exit; // return ERROR_SUCCESS; + if (match_offset >= 1 && isalnum(*(match_data - 1))) + goto _exit; // return ERROR_SUCCESS; if (match_offset + match_length < callback_args->data_size && isalnum(*(match_data + match_length))) - goto _exit; // return ERROR_SUCCESS; + goto _exit; // return ERROR_SUCCESS; } } @@ -691,9 +700,8 @@ static int _yr_scan_match_callback( { uint32_t max_match_data; - FAIL_ON_ERROR(yr_get_configuration( - YR_CONFIG_MAX_MATCH_DATA, - &max_match_data)); + FAIL_ON_ERROR( + yr_get_configuration(YR_CONFIG_MAX_MATCH_DATA, &max_match_data)); new_match = yr_notebook_alloc( callback_args->context->matches_notebook, sizeof(YR_MATCH)); @@ -717,10 +725,7 @@ static int _yr_scan_match_callback( goto _exit; } - memcpy( - (void*) new_match->data, - match_data, - new_match->data_length); + memcpy((void*) new_match->data, match_data, new_match->data_length); } else { @@ -743,7 +748,7 @@ static int _yr_scan_match_callback( } } - _exit:; +_exit:; YR_DEBUG_FPRINTF(2, stderr, "} // %s() {} = %d\n", __FUNCTION__, result); @@ -771,9 +776,15 @@ static int _yr_scan_verify_re_match( uint64_t data_base, size_t offset) { - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s(data=%p data_size=%zu data_base=0x%" PRIx64 " offset=%zu) {}\n", - __FUNCTION__, data, data_size, data_base, offset); + __FUNCTION__, + data, + data_size, + data_base, + offset); CALLBACK_ARGS callback_args; RE_EXEC_FUNC exec; @@ -796,8 +807,7 @@ static int _yr_scan_verify_re_match( else exec = yr_re_exec; - if (STRING_IS_ASCII(ac_match->string) || - STRING_IS_BASE64(ac_match->string) || + if (STRING_IS_ASCII(ac_match->string) || STRING_IS_BASE64(ac_match->string) || STRING_IS_BASE64_WIDE(ac_match->string)) { FAIL_ON_ERROR(exec( @@ -812,10 +822,9 @@ static int _yr_scan_verify_re_match( &forward_matches)); } - if ((forward_matches == -1) && - (STRING_IS_WIDE(ac_match->string) && - !(STRING_IS_BASE64(ac_match->string) || - STRING_IS_BASE64_WIDE(ac_match->string)))) + if ((forward_matches == -1) && (STRING_IS_WIDE(ac_match->string) && + !(STRING_IS_BASE64(ac_match->string) || + STRING_IS_BASE64_WIDE(ac_match->string)))) { flags |= RE_FLAGS_WIDE; FAIL_ON_ERROR(exec( @@ -859,8 +868,8 @@ static int _yr_scan_verify_re_match( } else { - FAIL_ON_ERROR(_yr_scan_match_callback( - data + offset, 0, flags, &callback_args)); + FAIL_ON_ERROR( + _yr_scan_match_callback(data + offset, 0, flags, &callback_args)); } return ERROR_SUCCESS; @@ -874,9 +883,15 @@ static int _yr_scan_verify_literal_match( uint64_t data_base, size_t offset) { - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s(data=%p data_size=%zu data_base=0x%" PRIx64 " offset=%zu) {}\n", - __FUNCTION__, data, data_size, data_base, offset); + __FUNCTION__, + data, + data_size, + data_base, + offset); int flags = 0; int forward_matches = 0; @@ -893,19 +908,13 @@ static int _yr_scan_verify_literal_match( if (STRING_IS_ASCII(string)) { forward_matches = _yr_scan_icompare( - data + offset, - data_size - offset, - string->string, - string->length); + data + offset, data_size - offset, string->string, string->length); } if (STRING_IS_WIDE(string) && forward_matches == 0) { forward_matches = _yr_scan_wicompare( - data + offset, - data_size - offset, - string->string, - string->length); + data + offset, data_size - offset, string->string, string->length); } } else @@ -913,19 +922,13 @@ static int _yr_scan_verify_literal_match( if (STRING_IS_ASCII(string)) { forward_matches = _yr_scan_compare( - data + offset, - data_size - offset, - string->string, - string->length); + data + offset, data_size - offset, string->string, string->length); } if (STRING_IS_WIDE(string) && forward_matches == 0) { forward_matches = _yr_scan_wcompare( - data + offset, - data_size - offset, - string->string, - string->length); + data + offset, data_size - offset, string->string, string->length); } if (STRING_IS_XOR(string) && forward_matches == 0) @@ -933,22 +936,15 @@ static int _yr_scan_verify_literal_match( if (STRING_IS_WIDE(string)) { forward_matches = _yr_scan_xor_wcompare( - data + offset, - data_size - offset, - string->string, - string->length); + data + offset, data_size - offset, string->string, string->length); } if (forward_matches == 0) { forward_matches = _yr_scan_xor_compare( - data + offset, - data_size - offset, - string->string, - string->length); + data + offset, data_size - offset, string->string, string->length); } } - } if (forward_matches == 0) @@ -968,8 +964,8 @@ static int _yr_scan_verify_literal_match( callback_args.forward_matches = forward_matches; callback_args.full_word = STRING_IS_FULL_WORD(string); - FAIL_ON_ERROR(_yr_scan_match_callback( - data + offset, 0, flags, &callback_args)); + FAIL_ON_ERROR( + _yr_scan_match_callback(data + offset, 0, flags, &callback_args)); return ERROR_SUCCESS; } @@ -983,9 +979,15 @@ int yr_scan_verify_match( uint64_t data_base, size_t offset) { - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s(data=%p data_size=%zu data_base=0x%" PRIx64 " offset=%zu) {}\n", - __FUNCTION__, data, data_size, data_base, offset); + __FUNCTION__, + data, + data_size, + data_base, + offset); YR_STRING* string = ac_match->string; @@ -997,8 +999,7 @@ int yr_scan_verify_match( if (STRING_IS_DISABLED(string)) return ERROR_SUCCESS; - if (context->flags & SCAN_FLAGS_FAST_MODE && - STRING_IS_SINGLE_MATCH(string) && + if (context->flags & SCAN_FLAGS_FAST_MODE && STRING_IS_SINGLE_MATCH(string) && context->matches[string->idx].head != NULL) return ERROR_SUCCESS; @@ -1006,14 +1007,15 @@ int yr_scan_verify_match( string->fixed_offset != data_base + offset) return ERROR_SUCCESS; - #ifdef YR_PROFILING_ENABLED +#ifdef YR_PROFILING_ENABLED uint64_t start_time; - bool sample = context->profiling_info[string->rule_idx].atom_matches - % YR_MATCH_VERIFICATION_PROFILING_RATE == 0; + bool sample = context->profiling_info[string->rule_idx].atom_matches % + YR_MATCH_VERIFICATION_PROFILING_RATE == + 0; if (sample) start_time = yr_stopwatch_elapsed_ns(&context->stopwatch); - #endif +#endif if (STRING_IS_LITERAL(string)) { @@ -1026,15 +1028,15 @@ int yr_scan_verify_match( context, ac_match, data, data_size, data_base, offset); } - #ifdef YR_PROFILING_ENABLED +#ifdef YR_PROFILING_ENABLED if (sample) { uint64_t finish_time = yr_stopwatch_elapsed_ns(&context->stopwatch); - context->profiling_info[string->rule_idx].match_time += ( - finish_time - start_time); + context->profiling_info[string->rule_idx].match_time += + (finish_time - start_time); } context->profiling_info[string->rule_idx].atom_matches++; - #endif +#endif if (result != ERROR_SUCCESS) context->last_error_string = string; diff --git a/libyara/scanner.c b/libyara/scanner.c index 3e1b2fe734..8b206b8006 100644 --- a/libyara/scanner.c +++ b/libyara/scanner.c @@ -28,17 +28,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include - #include #include #include #include +#include #include #include #include #include #include -#include #include "exception.h" @@ -48,9 +47,14 @@ static int _yr_scanner_scan_mem_block( const uint8_t* block_data, YR_MEMORY_BLOCK* block) { - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s(block_data=%p block->base=0x%" PRIx64 " block->size=%zu) {}\n", - __FUNCTION__, block_data, block->base, block->size); + __FUNCTION__, + block_data, + block->base, + block->size); YR_RULES* rules = scanner->rules; YR_AC_TRANSITION* transition_table = rules->ac_transition_table; @@ -71,13 +75,20 @@ static int _yr_scanner_scan_mem_block( return ERROR_SCAN_TIMEOUT; } - #if 2 == YR_DEBUG_VERBOSITY +#if 2 == YR_DEBUG_VERBOSITY if (0 != state) - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "- match_table[state=%u]=%'u i=%'ld " "block_data=%p block->base=0x%" PRIx64 " // %s() {}\n", - state, match_table[state], i, block_data, block->base, __FUNCTION__); - #endif + state, + match_table[state], + i, + block_data, + block->base, + __FUNCTION__); +#endif if (match_table[state] != 0) { @@ -150,30 +161,28 @@ static int _yr_scanner_scan_mem_block( } -static void _yr_scanner_clean_matches( - YR_SCANNER* scanner) +static void _yr_scanner_clean_matches(YR_SCANNER* scanner) { memset( - scanner->rule_matches_flags, 0, + scanner->rule_matches_flags, + 0, sizeof(YR_BITMASK) * YR_BITMASK_SIZE(scanner->rules->num_rules)); memset( - scanner->ns_unsatisfied_flags, 0, + scanner->ns_unsatisfied_flags, + 0, sizeof(YR_BITMASK) * YR_BITMASK_SIZE(scanner->rules->num_namespaces)); - memset( - scanner->matches, 0, - sizeof(YR_MATCHES) * scanner->rules->num_strings); + memset(scanner->matches, 0, sizeof(YR_MATCHES) * scanner->rules->num_strings); memset( - scanner->unconfirmed_matches, 0, + scanner->unconfirmed_matches, + 0, sizeof(YR_MATCHES) * scanner->rules->num_strings); } -YR_API int yr_scanner_create( - YR_RULES* rules, - YR_SCANNER** scanner) +YR_API int yr_scanner_create(YR_RULES* rules, YR_SCANNER** scanner) { YR_DEBUG_FPRINTF(2, stderr, "+ %s() {} \n", __FUNCTION__); @@ -195,9 +204,8 @@ YR_API int yr_scanner_create( new_scanner->canary = rand(); // By default report both matching and non-matching rules. - new_scanner->flags = \ - SCAN_FLAGS_REPORT_RULES_MATCHING | - SCAN_FLAGS_REPORT_RULES_NOT_MATCHING; + new_scanner->flags = SCAN_FLAGS_REPORT_RULES_MATCHING | + SCAN_FLAGS_REPORT_RULES_NOT_MATCHING; new_scanner->rule_matches_flags = (YR_BITMASK*) yr_calloc( sizeof(YR_BITMASK), YR_BITMASK_SIZE(rules->num_rules)); @@ -211,17 +219,18 @@ YR_API int yr_scanner_create( new_scanner->unconfirmed_matches = (YR_MATCHES*) yr_calloc( rules->num_strings, sizeof(YR_MATCHES)); - #ifdef YR_PROFILING_ENABLED - new_scanner->profiling_info = yr_calloc(rules->num_rules, sizeof(YR_PROFILING_INFO)); +#ifdef YR_PROFILING_ENABLED + new_scanner->profiling_info = yr_calloc( + rules->num_rules, sizeof(YR_PROFILING_INFO)); if (new_scanner->profiling_info == NULL) { yr_scanner_destroy(new_scanner); return ERROR_INSUFFICIENT_MEMORY; } - #else +#else new_scanner->profiling_info = NULL; - #endif +#endif external = rules->externals_list_head; @@ -234,15 +243,14 @@ YR_API int yr_scanner_create( // cleanup yr_scanner_destroy(new_scanner)); - FAIL_ON_ERROR_WITH_CLEANUP( - yr_hash_table_add( - new_scanner->objects_table, - external->identifier, - NULL, - (void*) object), - // cleanup - yr_object_destroy(object); - yr_scanner_destroy(new_scanner)); + FAIL_ON_ERROR_WITH_CLEANUP(yr_hash_table_add( + new_scanner->objects_table, + external->identifier, + NULL, + (void*) object), + // cleanup + yr_object_destroy(object); + yr_scanner_destroy(new_scanner)); yr_object_set_canary(object, new_scanner->canary); external++; @@ -254,8 +262,7 @@ YR_API int yr_scanner_create( } -YR_API void yr_scanner_destroy( - YR_SCANNER* scanner) +YR_API void yr_scanner_destroy(YR_SCANNER* scanner) { YR_DEBUG_FPRINTF(2, stderr, "+ %s() {} \n", __FUNCTION__); @@ -278,9 +285,9 @@ YR_API void yr_scanner_destroy( (YR_HASH_TABLE_FREE_VALUE_FUNC) yr_object_destroy); } - #ifdef YR_PROFILING_ENABLED +#ifdef YR_PROFILING_ENABLED yr_free(scanner->profiling_info); - #endif +#endif yr_free(scanner->rule_matches_flags); yr_free(scanner->ns_unsatisfied_flags); @@ -300,17 +307,13 @@ YR_API void yr_scanner_set_callback( } -YR_API void yr_scanner_set_timeout( - YR_SCANNER* scanner, - int timeout) +YR_API void yr_scanner_set_timeout(YR_SCANNER* scanner, int timeout) { // Convert timeout from seconds to nanoseconds. scanner->timeout = timeout * 1000000000ULL; } -YR_API void yr_scanner_set_flags( - YR_SCANNER* scanner, - int flags) +YR_API void yr_scanner_set_flags(YR_SCANNER* scanner, int flags) { // For backward compatibility, if neither SCAN_FLAGS_REPORT_RULES_MATCHING // nor SCAN_FLAGS_REPORT_RULES_NOT_MATCHING are specified, both are assumed. @@ -332,9 +335,7 @@ YR_API int yr_scanner_define_integer_variable( int64_t value) { YR_OBJECT* obj = (YR_OBJECT*) yr_hash_table_lookup( - scanner->objects_table, - identifier, - NULL); + scanner->objects_table, identifier, NULL); if (obj == NULL) return ERROR_INVALID_ARGUMENT; @@ -361,9 +362,7 @@ YR_API int yr_scanner_define_float_variable( double value) { YR_OBJECT* obj = (YR_OBJECT*) yr_hash_table_lookup( - scanner->objects_table, - identifier, - NULL); + scanner->objects_table, identifier, NULL); if (obj == NULL) return ERROR_INVALID_ARGUMENT; @@ -381,9 +380,7 @@ YR_API int yr_scanner_define_string_variable( const char* value) { YR_OBJECT* obj = (YR_OBJECT*) yr_hash_table_lookup( - scanner->objects_table, - identifier, - NULL); + scanner->objects_table, identifier, NULL); if (obj == NULL) return ERROR_INVALID_ARGUMENT; @@ -412,9 +409,7 @@ YR_API int yr_scanner_scan_mem_blocks( if (scanner->callback == NULL) return ERROR_CALLBACK_REQUIRED; - FAIL_ON_ERROR(yr_get_configuration( - YR_CONFIG_MAX_MATCH_DATA, - &max_match_data)) + FAIL_ON_ERROR(yr_get_configuration(YR_CONFIG_MAX_MATCH_DATA, &max_match_data)) scanner->iterator = iterator; rules = scanner->rules; @@ -428,8 +423,7 @@ YR_API int yr_scanner_scan_mem_blocks( // data (the "data" field in YR_MATCH points to the snippet corresponding to // the match). Each notebook's page can store up to 1024 matches. result = yr_notebook_create( - 1024 * (sizeof(YR_MATCH) + max_match_data), - &scanner->matches_notebook); + 1024 * (sizeof(YR_MATCH) + max_match_data), &scanner->matches_notebook); if (result != ERROR_SUCCESS) goto _exit; @@ -450,30 +444,22 @@ YR_API int yr_scanner_scan_mem_blocks( if (scanner->entry_point == YR_UNDEFINED) { YR_TRYCATCH( - !(scanner->flags & SCAN_FLAGS_NO_TRYCATCH), - { - if (scanner->flags & SCAN_FLAGS_PROCESS_MEMORY) - scanner->entry_point = yr_get_entry_point_address( - data, - block->size, - block->base); - else - scanner->entry_point = yr_get_entry_point_offset( - data, - block->size); - },{}); + !(scanner->flags & SCAN_FLAGS_NO_TRYCATCH), + { + if (scanner->flags & SCAN_FLAGS_PROCESS_MEMORY) + scanner->entry_point = yr_get_entry_point_address( + data, block->size, block->base); + else + scanner->entry_point = yr_get_entry_point_offset( + data, block->size); + }, + {}); } YR_TRYCATCH( - !(scanner->flags & SCAN_FLAGS_NO_TRYCATCH), - { - result = _yr_scanner_scan_mem_block( - scanner, - data, - block); - },{ - result = ERROR_COULD_NOT_MAP_FILE; - }); + !(scanner->flags & SCAN_FLAGS_NO_TRYCATCH), + { result = _yr_scanner_scan_mem_block(scanner, data, block); }, + { result = ERROR_COULD_NOT_MAP_FILE; }); if (result != ERROR_SUCCESS) goto _exit; @@ -482,19 +468,14 @@ YR_API int yr_scanner_scan_mem_blocks( } YR_TRYCATCH( - !(scanner->flags & SCAN_FLAGS_NO_TRYCATCH), - { - result = yr_execute_code(scanner); - },{ - result = ERROR_COULD_NOT_MAP_FILE; - }); + !(scanner->flags & SCAN_FLAGS_NO_TRYCATCH), + { result = yr_execute_code(scanner); }, + { result = ERROR_COULD_NOT_MAP_FILE; }); if (result != ERROR_SUCCESS) goto _exit; - for (i = 0, rule = rules->rules_list_head; - !RULE_IS_NULL(rule); - i++, rule++) + for (i = 0, rule = rules->rules_list_head; !RULE_IS_NULL(rule); i++, rule++) { int message = 0; @@ -514,22 +495,19 @@ YR_API int yr_scanner_scan_mem_blocks( { switch (scanner->callback(scanner, message, rule, scanner->user_data)) { - case CALLBACK_ABORT: - result = ERROR_SUCCESS; - goto _exit; + case CALLBACK_ABORT: + result = ERROR_SUCCESS; + goto _exit; - case CALLBACK_ERROR: - result = ERROR_CALLBACK_ERROR; - goto _exit; + case CALLBACK_ERROR: + result = ERROR_CALLBACK_ERROR; + goto _exit; } } } scanner->callback( - scanner, - CALLBACK_MSG_SCAN_FINISHED, - NULL, - scanner->user_data); + scanner, CALLBACK_MSG_SCAN_FINISHED, NULL, scanner->user_data); _exit: @@ -545,22 +523,19 @@ YR_API int yr_scanner_scan_mem_blocks( } -static YR_MEMORY_BLOCK* _yr_get_first_block( - YR_MEMORY_BLOCK_ITERATOR* iterator) +static YR_MEMORY_BLOCK* _yr_get_first_block(YR_MEMORY_BLOCK_ITERATOR* iterator) { return (YR_MEMORY_BLOCK*) iterator->context; } -static YR_MEMORY_BLOCK* _yr_get_next_block( - YR_MEMORY_BLOCK_ITERATOR* iterator) +static YR_MEMORY_BLOCK* _yr_get_next_block(YR_MEMORY_BLOCK_ITERATOR* iterator) { return NULL; } -static const uint8_t* _yr_fetch_block_data( - YR_MEMORY_BLOCK* block) +static const uint8_t* _yr_fetch_block_data(YR_MEMORY_BLOCK* block) { return (const uint8_t*) block->context; } @@ -571,9 +546,13 @@ static int __yr_scanner_scan_mem( const uint8_t* buffer, size_t buffer_size) { - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s(buffer=%p buffer_size=%zu)\n", - __FUNCTION__, buffer, buffer_size); + __FUNCTION__, + buffer, + buffer_size); YR_MEMORY_BLOCK block; YR_MEMORY_BLOCK_ITERATOR iterator; @@ -594,7 +573,8 @@ static int __yr_scanner_scan_mem( // -// Tests may override this default with their own iterator, e.g. for testing multiple blocks. +// Tests may override this default with their own iterator, e.g. for testing +// multiple blocks. // YR_API int (*_yr_scanner_scan_mem)( YR_SCANNER* scanner, @@ -607,13 +587,11 @@ YR_API int yr_scanner_scan_mem( const uint8_t* buffer, size_t buffer_size) { - return _yr_scanner_scan_mem(scanner, buffer, buffer_size); + return _yr_scanner_scan_mem(scanner, buffer, buffer_size); } -YR_API int yr_scanner_scan_file( - YR_SCANNER* scanner, - const char* filename) +YR_API int yr_scanner_scan_file(YR_SCANNER* scanner, const char* filename) { YR_MAPPED_FILE mfile; @@ -629,9 +607,7 @@ YR_API int yr_scanner_scan_file( } -YR_API int yr_scanner_scan_fd( - YR_SCANNER* scanner, - YR_FILE_DESCRIPTOR fd) +YR_API int yr_scanner_scan_fd(YR_SCANNER* scanner, YR_FILE_DESCRIPTOR fd) { YR_MAPPED_FILE mfile; @@ -647,9 +623,7 @@ YR_API int yr_scanner_scan_fd( } -YR_API int yr_scanner_scan_proc( - YR_SCANNER* scanner, - int pid) +YR_API int yr_scanner_scan_proc(YR_SCANNER* scanner, int pid) { YR_MEMORY_BLOCK_ITERATOR iterator; @@ -668,15 +642,13 @@ YR_API int yr_scanner_scan_proc( } -YR_API YR_STRING* yr_scanner_last_error_string( - YR_SCANNER* scanner) +YR_API YR_STRING* yr_scanner_last_error_string(YR_SCANNER* scanner) { return scanner->last_error_string; } -YR_API YR_RULE* yr_scanner_last_error_rule( - YR_SCANNER* scanner) +YR_API YR_RULE* yr_scanner_last_error_rule(YR_SCANNER* scanner) { if (scanner->last_error_string == NULL) return NULL; @@ -721,22 +693,21 @@ YR_API YR_RULE_PROFILING_INFO* yr_scanner_get_profiling_info( for (uint32_t i = 0; i < scanner->rules->num_rules; i++) { profiling_info[i].rule = &scanner->rules->rules_list_head[i]; - #ifdef YR_PROFILING_ENABLED - profiling_info[i].cost = \ - scanner->profiling_info[i].exec_time + - (scanner->profiling_info[i].atom_matches * - scanner->profiling_info[i].match_time) / - YR_MATCH_VERIFICATION_PROFILING_RATE; - #else +#ifdef YR_PROFILING_ENABLED + profiling_info[i].cost = scanner->profiling_info[i].exec_time + + (scanner->profiling_info[i].atom_matches * + scanner->profiling_info[i].match_time) / + YR_MATCH_VERIFICATION_PROFILING_RATE; +#else memset(&profiling_info[i], 0, sizeof(YR_RULE_PROFILING_INFO)); - #endif +#endif } qsort( profiling_info, scanner->rules->num_rules, sizeof(YR_RULE_PROFILING_INFO), - (int (*)(const void *, const void *)) sort_by_cost_desc); + (int (*)(const void*, const void*)) sort_by_cost_desc); profiling_info[scanner->rules->num_rules].rule = NULL; profiling_info[scanner->rules->num_rules].cost = 0; @@ -745,18 +716,17 @@ YR_API YR_RULE_PROFILING_INFO* yr_scanner_get_profiling_info( } -YR_API void yr_scanner_reset_profiling_info( - YR_SCANNER* scanner) +YR_API void yr_scanner_reset_profiling_info(YR_SCANNER* scanner) { - #ifdef YR_PROFILING_ENABLED +#ifdef YR_PROFILING_ENABLED memset( - scanner->profiling_info, 0, - scanner->rules->num_rules * sizeof(YR_PROFILING_INFO)); - #endif + scanner->profiling_info, + 0, + scanner->rules->num_rules * sizeof(YR_PROFILING_INFO)); +#endif } -YR_API int yr_scanner_print_profiling_info( - YR_SCANNER* scanner) +YR_API int yr_scanner_print_profiling_info(YR_SCANNER* scanner) { printf("\n===== PROFILING INFORMATION =====\n\n"); diff --git a/libyara/sizedstr.c b/libyara/sizedstr.c index dd10a43311..2cafc73562 100644 --- a/libyara/sizedstr.c +++ b/libyara/sizedstr.c @@ -40,15 +40,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // -1 if s1 < s2 // 1 if s1 > s2 // -int ss_compare( - SIZED_STRING* s1, - SIZED_STRING* s2) +int ss_compare(SIZED_STRING* s1, SIZED_STRING* s2) { size_t i = 0; - while (s1->length > i && - s2->length > i && - s1->c_string[i] == s2->c_string[i]) + while (s1->length > i && s2->length > i && s1->c_string[i] == s2->c_string[i]) { i++; } @@ -68,16 +64,13 @@ int ss_compare( // // ss_icompare is the case-insensitive version of ss_compare. // -int ss_icompare( - SIZED_STRING* s1, - SIZED_STRING* s2) +int ss_icompare(SIZED_STRING* s1, SIZED_STRING* s2) { size_t i = 0; - while (s1->length > i && - s2->length > i && + while (s1->length > i && s2->length > i && yr_lowercase[(uint8_t) s1->c_string[i]] == - yr_lowercase[(uint8_t) s2->c_string[i]]) + yr_lowercase[(uint8_t) s2->c_string[i]]) { i++; } @@ -98,21 +91,16 @@ int ss_icompare( // // ss_contains returns true if the sized string s1 contains s2. // -bool ss_contains( - SIZED_STRING* s1, - SIZED_STRING* s2) +bool ss_contains(SIZED_STRING* s1, SIZED_STRING* s2) { - return memmem(s1->c_string, s1->length, - s2->c_string, s2->length) != NULL; + return memmem(s1->c_string, s1->length, s2->c_string, s2->length) != NULL; } // // ss_icontains is the case-insensitive version of ss_contains. // -bool ss_icontains( - SIZED_STRING* s1, - SIZED_STRING* s2) +bool ss_icontains(SIZED_STRING* s1, SIZED_STRING* s2) { if (s1->length < s2->length) return false; @@ -137,9 +125,7 @@ bool ss_icontains( // // ss_startswith returns true if the sized string s1 starts with s2. // -bool ss_startswith( - SIZED_STRING* s1, - SIZED_STRING* s2) +bool ss_startswith(SIZED_STRING* s1, SIZED_STRING* s2) { if (s1->length < s2->length) return false; @@ -157,9 +143,7 @@ bool ss_startswith( // // ss_istartswith is the case-insensitive version of ss_startswith // -bool ss_istartswith( - SIZED_STRING* s1, - SIZED_STRING* s2) +bool ss_istartswith(SIZED_STRING* s1, SIZED_STRING* s2) { if (s1->length < s2->length) return false; @@ -178,9 +162,7 @@ bool ss_istartswith( // // ss_endswith returns true if the sized string s1 ends with s2. // -bool ss_endswith( - SIZED_STRING* s1, - SIZED_STRING* s2) +bool ss_endswith(SIZED_STRING* s1, SIZED_STRING* s2) { if (s1->length < s2->length) return false; @@ -195,9 +177,7 @@ bool ss_endswith( } -bool ss_iendswith( - SIZED_STRING* s1, - SIZED_STRING* s2) +bool ss_iendswith(SIZED_STRING* s1, SIZED_STRING* s2) { if (s1->length < s2->length) return false; @@ -213,9 +193,7 @@ bool ss_iendswith( } - -SIZED_STRING* ss_dup( - SIZED_STRING* s) +SIZED_STRING* ss_dup(SIZED_STRING* s) { SIZED_STRING* result = (SIZED_STRING*) yr_malloc( sizeof(SIZED_STRING) + s->length); @@ -232,8 +210,7 @@ SIZED_STRING* ss_dup( } -SIZED_STRING* ss_new( - const char* s) +SIZED_STRING* ss_new(const char* s) { SIZED_STRING* result; @@ -258,8 +235,7 @@ SIZED_STRING* ss_new( // the returned string. // -SIZED_STRING* ss_convert_to_wide( - SIZED_STRING* s) +SIZED_STRING* ss_convert_to_wide(SIZED_STRING* s) { SIZED_STRING* wide = (SIZED_STRING*) yr_malloc( sizeof(SIZED_STRING) + s->length * 2); diff --git a/libyara/stack.c b/libyara/stack.c index 6dcf44d095..6ee326afa0 100644 --- a/libyara/stack.c +++ b/libyara/stack.c @@ -28,10 +28,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include -#include #include -#include +#include // @@ -43,10 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // more objects are pushed. // -int yr_stack_create( - int initial_capacity, - int item_size, - YR_STACK** stack) +int yr_stack_create(int initial_capacity, int item_size, YR_STACK** stack) { *stack = (YR_STACK*) yr_malloc(sizeof(YR_STACK)); @@ -75,8 +72,7 @@ int yr_stack_create( // Destroys a stack and deallocates all its resources. // -void yr_stack_destroy( - YR_STACK* stack) +void yr_stack_destroy(YR_STACK* stack) { yr_free(stack->items); yr_free(stack); @@ -91,9 +87,7 @@ void yr_stack_destroy( // ERROR_INSUFFICIENT_MEMORY. // -int yr_stack_push( - YR_STACK* stack, - void* item) +int yr_stack_push(YR_STACK* stack, void* item) { if (stack->top == stack->capacity) { @@ -127,9 +121,7 @@ int yr_stack_push( // was already empty. // -int yr_stack_pop( - YR_STACK* stack, - void* item) +int yr_stack_pop(YR_STACK* stack, void* item) { if (stack->top == 0) // Return 0 if stack is empty. return 0; diff --git a/libyara/stopwatch.c b/libyara/stopwatch.c index 2f6fbed585..95e8b94879 100644 --- a/libyara/stopwatch.c +++ b/libyara/stopwatch.c @@ -31,37 +31,34 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(_WIN32) -void yr_stopwatch_start( - YR_STOPWATCH* sw) +void yr_stopwatch_start(YR_STOPWATCH* sw) { QueryPerformanceFrequency(&sw->frequency); QueryPerformanceCounter(&sw->start); } -uint64_t yr_stopwatch_elapsed_ns( - YR_STOPWATCH* sw) +uint64_t yr_stopwatch_elapsed_ns(YR_STOPWATCH* sw) { LARGE_INTEGER li; QueryPerformanceCounter(&li); - return (li.QuadPart - sw->start.QuadPart) * 1000000000ULL / sw->frequency.QuadPart; + return (li.QuadPart - sw->start.QuadPart) * 1000000000ULL / + sw->frequency.QuadPart; } #elif defined(__APPLE__) && defined(__MACH__) -void yr_stopwatch_start( - YR_STOPWATCH* sw) +void yr_stopwatch_start(YR_STOPWATCH* sw) { mach_timebase_info(&sw->timebase); sw->start = mach_absolute_time(); } -uint64_t yr_stopwatch_elapsed_ns( - YR_STOPWATCH* sw) +uint64_t yr_stopwatch_elapsed_ns(YR_STOPWATCH* sw) { uint64_t now = mach_absolute_time(); return ((now - sw->start) * sw->timebase.numer) / sw->timebase.denom; @@ -70,26 +67,26 @@ uint64_t yr_stopwatch_elapsed_ns( #elif defined(HAVE_CLOCK_GETTIME) -#define timespecsub(tsp, usp, vsp) \ -do { \ - (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ - (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ - if ((vsp)->tv_nsec < 0) { \ - (vsp)->tv_sec--; \ - (vsp)->tv_nsec += 1000000000L; \ - } \ -} while (0) +#define timespecsub(tsp, usp, vsp) \ + do \ + { \ + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ + if ((vsp)->tv_nsec < 0) \ + { \ + (vsp)->tv_sec--; \ + (vsp)->tv_nsec += 1000000000L; \ + } \ + } while (0) -void yr_stopwatch_start( - YR_STOPWATCH* stopwatch) +void yr_stopwatch_start(YR_STOPWATCH* stopwatch) { clock_gettime(CLOCK_MONOTONIC, &stopwatch->ts_start); } -uint64_t yr_stopwatch_elapsed_ns( - YR_STOPWATCH* stopwatch) +uint64_t yr_stopwatch_elapsed_ns(YR_STOPWATCH* stopwatch) { struct timespec ts_stop; struct timespec ts_elapsed; @@ -104,26 +101,26 @@ uint64_t yr_stopwatch_elapsed_ns( #include -#define timevalsub(tvp, uvp, vvp) \ -do { \ - (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ - if ((vvp)->tv_usec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_usec += 1000000L; \ - } \ -} while (0) +#define timevalsub(tvp, uvp, vvp) \ + do \ + { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) \ + { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000L; \ + } \ + } while (0) -void yr_stopwatch_start( - YR_STOPWATCH* stopwatch) +void yr_stopwatch_start(YR_STOPWATCH* stopwatch) { gettimeofday(&stopwatch->tv_start, NULL); } -uint64_t yr_stopwatch_elapsed_ns( - YR_STOPWATCH* stopwatch) +uint64_t yr_stopwatch_elapsed_ns(YR_STOPWATCH* stopwatch) { struct timeval tv_stop; struct timeval tv_elapsed; diff --git a/libyara/stream.c b/libyara/stream.c index 63fce5ecbd..2b8883a3fc 100644 --- a/libyara/stream.c +++ b/libyara/stream.c @@ -31,11 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -size_t yr_stream_read( - void* ptr, - size_t size, - size_t count, - YR_STREAM* stream) +size_t yr_stream_read(void* ptr, size_t size, size_t count, YR_STREAM* stream) { if (stream->read == NULL) return 0; diff --git a/libyara/strutils.c b/libyara/strutils.c index 934ae86904..3b086c549f 100644 --- a/libyara/strutils.c +++ b/libyara/strutils.c @@ -29,11 +29,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include - #include -uint64_t xtoi( - const char* hexstr) +uint64_t xtoi(const char* hexstr) { size_t i; size_t l = strlen(hexstr); @@ -44,36 +42,36 @@ uint64_t xtoi( { switch (hexstr[i]) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - r |= ((uint64_t)(hexstr[i] - '0')) << ((l - i - 1) * 4); - break; - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - r |= ((uint64_t)(hexstr[i] - 'a' + 10)) << ((l - i - 1) * 4); - break; - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - r |= ((uint64_t)(hexstr[i] - 'A' + 10)) << ((l - i - 1) * 4); - break; - default: - i = l; // force loop exit + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + r |= ((uint64_t)(hexstr[i] - '0')) << ((l - i - 1) * 4); + break; + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + r |= ((uint64_t)(hexstr[i] - 'a' + 10)) << ((l - i - 1) * 4); + break; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + r |= ((uint64_t)(hexstr[i] - 'A' + 10)) << ((l - i - 1) * 4); + break; + default: + i = l; // force loop exit } } @@ -89,10 +87,7 @@ the following implementations were taken from OpenBSD. #if !HAVE_STRLCPY && !defined(strlcpy) -size_t strlcpy( - char* dst, - const char* src, - size_t size) +size_t strlcpy(char* dst, const char* src, size_t size) { register char* d = dst; register const char* s = src; @@ -115,9 +110,10 @@ size_t strlcpy( if (n == 0) { if (size != 0) - *d = '\0'; // NULL-terminate dst + *d = '\0'; // NULL-terminate dst - while (*s++); + while (*s++) + ; } return (s - src - 1); // count does not include NULL @@ -128,10 +124,7 @@ size_t strlcpy( #if !HAVE_STRLCAT && !defined(strlcat) -size_t strlcat( - char* dst, - const char* src, - size_t size) +size_t strlcat(char* dst, const char* src, size_t size) { register char* d = dst; register const char* s = src; @@ -146,7 +139,7 @@ size_t strlcat( n = size - dlen; if (n == 0) - return(dlen + strlen(s)); + return (dlen + strlen(s)); while (*s != '\0') { @@ -166,8 +159,7 @@ size_t strlcat( #endif -int strnlen_w( - const char* w_str) +int strnlen_w(const char* w_str) { int len = 0; @@ -181,9 +173,7 @@ int strnlen_w( } -int strcmp_w( - const char* w_str, - const char* str) +int strcmp_w(const char* w_str, const char* str) { while (*str != 0 && w_str[0] == *str && w_str[1] == 0) { @@ -200,10 +190,7 @@ int strcmp_w( } -size_t strlcpy_w( - char* dst, - const char* w_src, - size_t n) +size_t strlcpy_w(char* dst, const char* w_src, size_t n) { register char* d = dst; register const char* s = w_src; @@ -226,17 +213,17 @@ size_t strlcpy_w( #if !HAVE_MEMMEM && !defined(memmem) void* memmem( - const void *haystack, + const void* haystack, size_t haystack_size, - const void *needle, + const void* needle, size_t needle_size) { - char *sp = (char *) haystack; - char *pp = (char *) needle; - char *eos; + char* sp = (char*) haystack; + char* pp = (char*) needle; + char* eos; - if (haystack == NULL || haystack_size == 0 || - needle == NULL || needle_size == 0) + if (haystack == NULL || haystack_size == 0 || needle == NULL || + needle_size == 0) return NULL; eos = sp + haystack_size - needle_size; diff --git a/libyara/threading.c b/libyara/threading.c index 1fa00989af..b6bcbef4b6 100644 --- a/libyara/threading.c +++ b/libyara/threading.c @@ -38,8 +38,7 @@ YR_THREAD_ID yr_current_thread_id(void) } -int yr_mutex_create( - YR_MUTEX* mutex) +int yr_mutex_create(YR_MUTEX* mutex) { *mutex = CreateMutex(NULL, FALSE, NULL); @@ -50,8 +49,7 @@ int yr_mutex_create( } -int yr_mutex_destroy( - YR_MUTEX* mutex) +int yr_mutex_destroy(YR_MUTEX* mutex) { if (CloseHandle(*mutex) == FALSE) return ERROR_INTERNAL_FATAL_ERROR; @@ -60,8 +58,7 @@ int yr_mutex_destroy( } -int yr_mutex_lock( - YR_MUTEX* mutex) +int yr_mutex_lock(YR_MUTEX* mutex) { if (WaitForSingleObject(*mutex, INFINITE) == WAIT_FAILED) return ERROR_INTERNAL_FATAL_ERROR; @@ -70,8 +67,7 @@ int yr_mutex_lock( } -int yr_mutex_unlock( - YR_MUTEX* mutex) +int yr_mutex_unlock(YR_MUTEX* mutex) { if (ReleaseMutex(*mutex) == FALSE) return ERROR_INTERNAL_FATAL_ERROR; @@ -80,8 +76,7 @@ int yr_mutex_unlock( } -int yr_thread_storage_create( - YR_THREAD_STORAGE_KEY* storage) +int yr_thread_storage_create(YR_THREAD_STORAGE_KEY* storage) { *storage = TlsAlloc(); @@ -92,8 +87,7 @@ int yr_thread_storage_create( } -int yr_thread_storage_destroy( - YR_THREAD_STORAGE_KEY* storage) +int yr_thread_storage_destroy(YR_THREAD_STORAGE_KEY* storage) { if (TlsFree(*storage) == FALSE) return ERROR_INTERNAL_FATAL_ERROR; @@ -102,9 +96,7 @@ int yr_thread_storage_destroy( } -int yr_thread_storage_set_value( - YR_THREAD_STORAGE_KEY* storage, - void* value) +int yr_thread_storage_set_value(YR_THREAD_STORAGE_KEY* storage, void* value) { if (TlsSetValue(*storage, value) == FALSE) return ERROR_INTERNAL_FATAL_ERROR; @@ -113,8 +105,7 @@ int yr_thread_storage_set_value( } -void* yr_thread_storage_get_value( - YR_THREAD_STORAGE_KEY* storage) +void* yr_thread_storage_get_value(YR_THREAD_STORAGE_KEY* storage) { return TlsGetValue(*storage); } @@ -129,8 +120,7 @@ YR_THREAD_ID yr_current_thread_id(void) } -int yr_mutex_create( - YR_MUTEX* mutex) +int yr_mutex_create(YR_MUTEX* mutex) { if (pthread_mutex_init(mutex, NULL) != 0) return ERROR_INTERNAL_FATAL_ERROR; @@ -139,8 +129,7 @@ int yr_mutex_create( } -int yr_mutex_destroy( - YR_MUTEX* mutex) +int yr_mutex_destroy(YR_MUTEX* mutex) { if (pthread_mutex_destroy(mutex) != 0) return ERROR_INTERNAL_FATAL_ERROR; @@ -149,8 +138,7 @@ int yr_mutex_destroy( } -int yr_mutex_lock( - YR_MUTEX* mutex) +int yr_mutex_lock(YR_MUTEX* mutex) { if (pthread_mutex_lock(mutex) != 0) return ERROR_INTERNAL_FATAL_ERROR; @@ -159,8 +147,7 @@ int yr_mutex_lock( } -int yr_mutex_unlock( - YR_MUTEX* mutex) +int yr_mutex_unlock(YR_MUTEX* mutex) { if (pthread_mutex_unlock(mutex) != 0) return ERROR_INTERNAL_FATAL_ERROR; @@ -169,8 +156,7 @@ int yr_mutex_unlock( } -int yr_thread_storage_create( - YR_THREAD_STORAGE_KEY* storage) +int yr_thread_storage_create(YR_THREAD_STORAGE_KEY* storage) { if (pthread_key_create(storage, NULL) != 0) return ERROR_INTERNAL_FATAL_ERROR; @@ -179,8 +165,7 @@ int yr_thread_storage_create( } -int yr_thread_storage_destroy( - YR_THREAD_STORAGE_KEY* storage) +int yr_thread_storage_destroy(YR_THREAD_STORAGE_KEY* storage) { if (pthread_key_delete(*storage) != 0) return ERROR_INTERNAL_FATAL_ERROR; @@ -189,9 +174,7 @@ int yr_thread_storage_destroy( } -int yr_thread_storage_set_value( - YR_THREAD_STORAGE_KEY* storage, - void* value) +int yr_thread_storage_set_value(YR_THREAD_STORAGE_KEY* storage, void* value) { if (pthread_setspecific(*storage, value) != 0) return ERROR_INTERNAL_FATAL_ERROR; @@ -200,8 +183,7 @@ int yr_thread_storage_set_value( } -void* yr_thread_storage_get_value( - YR_THREAD_STORAGE_KEY* storage) +void* yr_thread_storage_get_value(YR_THREAD_STORAGE_KEY* storage) { return pthread_getspecific(*storage); } diff --git a/sandbox/collect_matches.cc b/sandbox/collect_matches.cc index dc00e52153..322c55a36a 100644 --- a/sandbox/collect_matches.cc +++ b/sandbox/collect_matches.cc @@ -32,11 +32,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "libyara/include/yara.h" #include "sandbox/yara_matches.pb.h" -namespace yara { - -int CollectMatches(YR_SCAN_CONTEXT*, int message, void* message_data, - void* user_data) { - if (message != CALLBACK_MSG_RULE_MATCHING) { +namespace yara +{ +int CollectMatches( + YR_SCAN_CONTEXT*, + int message, + void* message_data, + void* user_data) +{ + if (message != CALLBACK_MSG_RULE_MATCHING) + { return ERROR_SUCCESS; // There are no matching rules, simply return } @@ -44,21 +49,27 @@ int CollectMatches(YR_SCAN_CONTEXT*, int message, void* message_data, YR_META* rule_meta = rule->metas; auto* match = reinterpret_cast(user_data)->add_match(); - if (rule->ns != nullptr && rule->ns->name != nullptr) { + + if (rule->ns != nullptr && rule->ns->name != nullptr) + { match->mutable_id()->set_rule_namespace(rule->ns->name); } + match->mutable_id()->set_rule_name(rule->identifier); - yr_rule_metas_foreach(rule, rule_meta) { + + yr_rule_metas_foreach(rule, rule_meta) + { auto* meta = match->add_meta(); meta->set_identifier(rule_meta->identifier); - switch (rule_meta->type) { - case META_TYPE_BOOLEAN: - case META_TYPE_INTEGER: - meta->set_int_value(rule_meta->integer); - break; - case META_TYPE_STRING: - meta->set_bytes_value(rule_meta->string); - break; + switch (rule_meta->type) + { + case META_TYPE_BOOLEAN: + case META_TYPE_INTEGER: + meta->set_int_value(rule_meta->integer); + break; + case META_TYPE_STRING: + meta->set_bytes_value(rule_meta->string); + break; } ++rule_meta; } diff --git a/sandbox/sandboxed_yara.cc b/sandbox/sandboxed_yara.cc index 1d8368cff4..17c73dd30f 100644 --- a/sandbox/sandboxed_yara.cc +++ b/sandbox/sandboxed_yara.cc @@ -54,15 +54,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ABSL_FLAG(std::string, identifier, "", "print only rules with this name"); ABSL_FLAG(int, timeout, 5, "abort scanning after the given number of seconds"); -namespace yara { -namespace { - -::sapi::StatusOr ReadFileToString(absl::string_view filename) { +namespace yara +{ +namespace +{ +::sapi::StatusOr ReadFileToString(absl::string_view filename) +{ std::ifstream input(std::string(filename), std::ios::in | std::ios::binary); std::ostringstream output; output << input.rdbuf(); - if (!input) { - return absl::UnknownError(absl::StrCat("Cannot read file '", filename, "'")); + if (!input) + { + return absl::UnknownError( + absl::StrCat("Cannot read file '", filename, "'")); } return output.str(); } @@ -71,8 +75,10 @@ ::sapi::StatusOr ReadFileToString(absl::string_view filename) { // Implements a subset of the YARA command line scanner, but runs the actual // scan inside of a sandbox. -absl::Status YaraMain(const std::vector& args) { - if (args.size() < 3) { +absl::Status YaraMain(const std::vector& args) +{ + if (args.size() < 3) + { return absl::InvalidArgumentError("Missing operand. Try '--help'."); } @@ -80,7 +86,9 @@ absl::Status YaraMain(const std::vector& args) { // files. std::string scan_filename = args.back(); std::string all_rules; - for (size_t i = 1; i != args.size() - 1; ++i) { + + for (size_t i = 1; i != args.size() - 1; ++i) + { SAPI_ASSIGN_OR_RETURN(std::string rules, ReadFileToString(args[i])); absl::StrAppend(&all_rules, rules, "\n"); } @@ -91,23 +99,30 @@ absl::Status YaraMain(const std::vector& args) { YaraTransaction::Options() .set_scan_timeout(absl::Seconds(absl::GetFlag(FLAGS_timeout))) .set_num_workers(1))); - SAPI_ASSIGN_OR_RETURN(int num_rules ABSL_ATTRIBUTE_UNUSED, - transaction->LoadRules(all_rules)); + SAPI_ASSIGN_OR_RETURN( + int num_rules ABSL_ATTRIBUTE_UNUSED, transaction->LoadRules(all_rules)); - struct FDCloser { + struct FDCloser + { ~FDCloser() { close(fd); } int fd; } fd_closer{open(scan_filename.c_str(), O_RDONLY)}; - if (fd_closer.fd == -1) { + + if (fd_closer.fd == -1) + { return absl::UnknownError(absl::StrCat( "Cannot open file '", scan_filename, "': ", strerror(errno))); } SAPI_ASSIGN_OR_RETURN(YaraMatches matches, transaction->ScanFd(fd_closer.fd)); - for (const auto& match : matches.match()) { + + for (const auto& match : matches.match()) + { const std::string& rule_name = match.id().rule_name(); + if (absl::GetFlag(FLAGS_identifier).empty() || - (absl::GetFlag(FLAGS_identifier) == rule_name)) { + (absl::GetFlag(FLAGS_identifier) == rule_name)) + { absl::PrintF("%s %s\n", rule_name, scan_filename); } } @@ -117,22 +132,30 @@ absl::Status YaraMain(const std::vector& args) { } // namespace yara -int main(int argc, char* argv[]) { +int main(int argc, char* argv[]) +{ absl::string_view argv0 = argv[0]; { auto last_slash_pos = argv0.find_last_of("/\\"); - if (last_slash_pos != absl::string_view::npos) { + if (last_slash_pos != absl::string_view::npos) + { argv0 = argv0.substr(last_slash_pos + 1); } } - absl::SetProgramUsageMessage( - absl::StrCat("YARA, the pattern matching swiss army knife.\n", - "Usage: ", argv0, " [OPTION] RULES_FILE... FILE")); + + absl::SetProgramUsageMessage(absl::StrCat( + "YARA, the pattern matching swiss army knife.\n", + "Usage: ", + argv0, + " [OPTION] RULES_FILE... FILE")); absl::Status status = ::yara::YaraMain(absl::ParseCommandLine(argc, argv)); - if (!status.ok()) { + + if (!status.ok()) + { absl::FPrintF(stderr, "ERROR: %s\n", status.message()); return EXIT_FAILURE; } + return EXIT_SUCCESS; } diff --git a/sandbox/yara_entry_points.cc b/sandbox/yara_entry_points.cc index 8e3a147b4a..b2ded63efa 100644 --- a/sandbox/yara_entry_points.cc +++ b/sandbox/yara_entry_points.cc @@ -47,10 +47,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "sandbox/collect_matches.h" #include "sandbox/yara_matches.pb.h" -namespace yara { -namespace { - -struct ScanTask { +namespace yara +{ +namespace +{ +struct ScanTask +{ // Key into the g_results map, used by YaraGetScanResult() uint64_t result_id; @@ -64,7 +66,8 @@ struct ScanTask { absl::Duration timeout; }; -struct ScanResult { +struct ScanResult +{ int code; YaraMatches matches; }; @@ -104,8 +107,10 @@ static auto* g_results GUARDED_BY(g_results_mutex) = ABSL_CONST_INIT static absl::Mutex g_rules_mutex(absl::kConstInit); static YR_RULES* g_rules GUARDED_BY(g_rules_mutex) = nullptr; -void ScanWorker() { - while (true) { +void ScanWorker() +{ + while (true) + { // Wait for and retrieve a new ScanTask from the queue. g_queue_mutex.LockWhen(absl::Condition( +[](std::queue* queue) { return !queue->empty(); }, g_queue)); @@ -117,9 +122,11 @@ void ScanWorker() { { absl::ReaderMutexLock lock(&g_rules_mutex); result.code = yr_rules_scan_fd( - g_rules, task.data_fd, + g_rules, + task.data_fd, // Disable SIGSEGV handler, allowing YARA to crash/coredump. - SCAN_FLAGS_NO_TRYCATCH, CollectMatches, + SCAN_FLAGS_NO_TRYCATCH, + CollectMatches, /*user_data=*/reinterpret_cast(&result.matches), absl::ToInt64Seconds(task.timeout)); } @@ -132,9 +139,10 @@ void ScanWorker() { // writing 8 bytes, as long as the event_fd stays open in this function, // hence the CHECK. uint64_t unblock_value = 1; - ABSL_RAW_CHECK(write(task.event_fd, &unblock_value, - sizeof(unblock_value)) == sizeof(unblock_value), - strerror(errno)); + ABSL_RAW_CHECK( + write(task.event_fd, &unblock_value, sizeof(unblock_value)) == + sizeof(unblock_value), + strerror(errno)); close(task.event_fd); close(task.data_fd); @@ -143,13 +151,17 @@ void ScanWorker() { } // namespace -extern "C" void YaraInitWorkers(int num_workers) { - const int num_threads = - std::min(static_cast(std::min(num_workers, YR_MAX_THREADS)), - std::thread::hardware_concurrency()); +extern "C" void YaraInitWorkers(int num_workers) +{ + const int num_threads = std::min( + static_cast(std::min(num_workers, YR_MAX_THREADS)), + std::thread::hardware_concurrency()); + static auto* workers = new std::vector(); workers->reserve(num_threads); - for (int i = 0; i < num_threads; ++i) { + + for (int i = 0; i < num_threads; ++i) + { workers->emplace_back(ScanWorker); } } @@ -157,21 +169,27 @@ extern "C" void YaraInitWorkers(int num_workers) { // Initializes the global YARA rules set from a string. Returns the number of // rules loaded. Extended error information can be found in status if it is not // nullptr. -extern "C" int YaraLoadRules(const char* rule_string, YaraStatus* error_status) { +extern "C" int YaraLoadRules(const char* rule_string, YaraStatus* error_status) +{ _YR_COMPILER* compiler; int error = yr_compiler_create(&compiler); - if (error != ERROR_SUCCESS) { - if (error_status) { + + if (error != ERROR_SUCCESS) + { + if (error_status) + { error_status->set_code(error); } return 0; } + std::unique_ptr<_YR_COMPILER, void (*)(_YR_COMPILER*)> compiler_cleanup( compiler, yr_compiler_destroy); - if (yr_compiler_add_string(compiler, rule_string, /*namespace_=*/nullptr) != - 0) { - if (error_status) { + if (yr_compiler_add_string(compiler, rule_string, nullptr) != 0) + { + if (error_status) + { error_status->set_code(compiler->last_error); char message[512] = {'\0'}; @@ -183,8 +201,11 @@ extern "C" int YaraLoadRules(const char* rule_string, YaraStatus* error_status) YR_RULES* rules = nullptr; error = yr_compiler_get_rules(compiler, &rules); - if (error != ERROR_SUCCESS) { - if (error_status) { + + if (error != ERROR_SUCCESS) + { + if (error_status) + { error_status->set_code(error); } return 0; @@ -195,9 +216,12 @@ extern "C" int YaraLoadRules(const char* rule_string, YaraStatus* error_status) yr_rules_foreach(rules, rule) { ++num_rules; } absl::MutexLock lock(&g_rules_mutex); - if (g_rules) { + + if (g_rules) + { yr_rules_destroy(g_rules); } + g_rules = rules; return num_rules; @@ -206,24 +230,28 @@ extern "C" int YaraLoadRules(const char* rule_string, YaraStatus* error_status) // Schedules a new asynchronous YARA scan task on the data in the specified file // descriptor. Notifies host code via writing to the event_fd file descriptor. // Returns a unique identifier that can be used to retrieve the results. -extern "C" uint64_t YaraAsyncScanFd(int data_fd, int event_fd, - int timeout_secs) { +extern "C" uint64_t YaraAsyncScanFd(int data_fd, int event_fd, int timeout_secs) +{ absl::MutexLock queue_lock(&g_queue_mutex); ++g_result_id; g_queue->push({g_result_id, data_fd, event_fd, absl::Seconds(timeout_secs)}); return g_result_id; } -extern "C" int YaraGetScanResult(uint64_t result_id, YaraMatches* matches) { +extern "C" int YaraGetScanResult(uint64_t result_id, YaraMatches* matches) +{ absl::MutexLock lock(&g_results_mutex); auto result = g_results->find(result_id); - if (result == g_results->end()) { + + if (result == g_results->end()) + { return -1; } int code = result->second.code; *matches = std::move(result->second.matches); g_results->erase(result); + return code; } diff --git a/sandbox/yara_transaction.cc b/sandbox/yara_transaction.cc index 23f97714f7..072e8a8aef 100644 --- a/sandbox/yara_transaction.cc +++ b/sandbox/yara_transaction.cc @@ -37,14 +37,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "libyara/include/yara/error.h" #include "sandboxed_api/util/status_macros.h" -namespace yara { - +namespace yara +{ absl::Mutex YaraTransaction::mutex_(absl::kConstInit); ::sapi::StatusOr> YaraTransaction::Create( - Options options) { - auto transaction = - absl::WrapUnique(new YaraTransaction(options.scan_timeout)); + Options options) +{ + auto transaction = absl::WrapUnique( + new YaraTransaction(options.scan_timeout)); // "Run" the transaction in order to initialize the underlying sandbox. SAPI_RETURN_IF_ERROR(transaction->Run()); @@ -55,20 +56,23 @@ ::sapi::StatusOr> YaraTransaction::Create( return transaction; } -::sapi::StatusOr YaraTransaction::LoadRules( - const std::string& rule_string) { +::sapi::StatusOr YaraTransaction::LoadRules(const std::string& rule_string) +{ absl::MutexLock lock(&mutex_); sandbox::YaraApi api(sandbox()); ::sapi::v::ConstCStr rule_string_sapi(rule_string.c_str()); YaraStatus error_status; ::sapi::v::Proto error_status_sapi(error_status); - SAPI_ASSIGN_OR_RETURN(int num_rules, - api.YaraLoadRules(rule_string_sapi.PtrBefore(), - error_status_sapi.PtrBoth())); - if (num_rules <= 0) { + SAPI_ASSIGN_OR_RETURN( + int num_rules, + api.YaraLoadRules( + rule_string_sapi.PtrBefore(), error_status_sapi.PtrBoth())); + if (num_rules <= 0) + { auto error_status_copy = error_status_sapi.GetProtoCopy(); - if (!error_status_copy) { + if (!error_status_copy) + { return absl::UnknownError("Deserialization of response failed"); } return absl::InvalidArgumentError(error_status_copy->message()); @@ -76,13 +80,16 @@ ::sapi::StatusOr YaraTransaction::LoadRules( return num_rules; } -::sapi::StatusOr YaraTransaction::ScanFd(int fd) { +::sapi::StatusOr YaraTransaction::ScanFd(int fd) +{ int local_event_fd = eventfd(0 /* initval */, 0 /* flags */); - if (local_event_fd == -1) { + if (local_event_fd == -1) + { return absl::InternalError( absl::StrCat("eventfd() error: ", strerror(errno))); } - struct FDCloser { + struct FDCloser + { ~FDCloser() { close(event_fd); } int event_fd; } event_fd_closer = {local_event_fd}; @@ -106,8 +113,10 @@ ::sapi::StatusOr YaraTransaction::ScanFd(int fd) { SAPI_ASSIGN_OR_RETURN( result_id, - api.YaraAsyncScanFd(data_fd.GetRemoteFd(), event_fd.GetRemoteFd(), - absl::ToInt64Seconds(scan_timeout_))); + api.YaraAsyncScanFd( + data_fd.GetRemoteFd(), + event_fd.GetRemoteFd(), + absl::ToInt64Seconds(scan_timeout_))); } pollfd poll_events{local_event_fd, POLLIN}; @@ -115,20 +124,23 @@ ::sapi::StatusOr YaraTransaction::ScanFd(int fd) { // TEMP_FAILURE_RETRY is a GNU extension that retries if the call returns // EINTR. - poll_result = TEMP_FAILURE_RETRY( - poll(&poll_events, 1 /* nfds */, - // Add extra time to allow code inside the sandbox to time out first. - absl::ToInt64Milliseconds(scan_timeout_ + absl::Seconds(10)))); - if (poll_result == 0) { + poll_result = TEMP_FAILURE_RETRY(poll( + &poll_events, + 1 /* nfds */, + // Add extra time to allow code inside the sandbox to time out first. + absl::ToInt64Milliseconds(scan_timeout_ + absl::Seconds(10)))); + if (poll_result == 0) + { return absl::DeadlineExceededError("Scan timeout during poll()"); } - if (poll_result == -1) { - return absl::InternalError( - absl::StrCat("poll() error: ", strerror(errno))); + if (poll_result == -1) + { + return absl::InternalError(absl::StrCat("poll() error: ", strerror(errno))); } if (poll_events.revents & POLLHUP || poll_events.revents & POLLERR || - poll_events.revents & POLLNVAL) { + poll_events.revents & POLLNVAL) + { return absl::InternalError( absl::StrCat("poll() error, revents: ", poll_events.revents)); } @@ -139,18 +151,21 @@ ::sapi::StatusOr YaraTransaction::ScanFd(int fd) { SAPI_ASSIGN_OR_RETURN( int scan_result, api.YaraGetScanResult(result_id, matches_sapi.PtrBoth())); - switch (scan_result) { - case ERROR_SUCCESS: - case ERROR_TOO_MANY_MATCHES: { - auto matches_copy = matches_sapi.GetProtoCopy(); - if (!matches_copy) { - return absl::UnknownError("Deserialization of response failed"); - } - return *matches_copy; + switch (scan_result) + { + case ERROR_SUCCESS: + case ERROR_TOO_MANY_MATCHES: + { + auto matches_copy = matches_sapi.GetProtoCopy(); + if (!matches_copy) + { + return absl::UnknownError("Deserialization of response failed"); } + return *matches_copy; + } - case ERROR_SCAN_TIMEOUT: - return absl::DeadlineExceededError("Scan timeout"); + case ERROR_SCAN_TIMEOUT: + return absl::DeadlineExceededError("Scan timeout"); } return absl::InternalError(absl::StrCat("Error during scan: ", scan_result)); } diff --git a/sandbox/yara_transaction_test.cc b/sandbox/yara_transaction_test.cc index 9029f3d37d..0a5aad2c88 100644 --- a/sandbox/yara_transaction_test.cc +++ b/sandbox/yara_transaction_test.cc @@ -48,30 +48,36 @@ using ::sapi::IsOk; using ::testing::Eq; using ::testing::StrEq; -namespace yara { -namespace { - +namespace yara +{ +namespace +{ // Wraps an in-memory file descriptor created by memfd_create(). -class MemoryFD { +class MemoryFD +{ public: - static ::sapi::StatusOr CreateWithContent( - absl::string_view content) { + static ::sapi::StatusOr CreateWithContent(absl::string_view content) + { MemoryFD mem_fd; // Avoid dependency on UAPI headers constexpr uintptr_t MFD_CLOEXEC = 0x0001U; constexpr const char* kName = "memfd"; - mem_fd.fd_ = syscall(__NR_memfd_create, reinterpret_cast(kName), - MFD_CLOEXEC); - if (mem_fd.fd_ == -1) { + mem_fd.fd_ = syscall( + __NR_memfd_create, reinterpret_cast(kName), MFD_CLOEXEC); + if (mem_fd.fd_ == -1) + { return absl::UnknownError(absl::StrCat("memfd(): ", strerror(errno))); } - if (ftruncate(mem_fd.fd_, content.size()) == -1) { + if (ftruncate(mem_fd.fd_, content.size()) == -1) + { return absl::UnknownError(absl::StrCat("ftruncate(): ", strerror(errno))); } - while (!content.empty()) { - ssize_t written = - TEMP_FAILURE_RETRY(write(mem_fd.fd_, content.data(), content.size())); - if (written <= 0) { + while (!content.empty()) + { + ssize_t written = TEMP_FAILURE_RETRY( + write(mem_fd.fd_, content.data(), content.size())); + if (written <= 0) + { return absl::UnknownError(absl::StrCat("write(): ", strerror(errno))); } content.remove_prefix(written); @@ -81,14 +87,17 @@ class MemoryFD { MemoryFD(MemoryFD&& other) { *this = std::move(other); } - MemoryFD& operator=(MemoryFD&& other) { + MemoryFD& operator=(MemoryFD&& other) + { fd_ = other.fd_; other.fd_ = 0; return *this; } - ~MemoryFD() { - if (fd_ > 0) { + ~MemoryFD() + { + if (fd_ > 0) + { close(fd_); }; } @@ -100,9 +109,11 @@ class MemoryFD { int fd_; }; -class TransactionTest : public ::testing::Test { +class TransactionTest : public ::testing::Test +{ protected: - void SetUp() override { + void SetUp() override + { SAPI_ASSERT_OK_AND_ASSIGN( transaction_, YaraTransaction::Create(YaraTransaction::Options{} @@ -110,18 +121,21 @@ class TransactionTest : public ::testing::Test { .set_num_workers(16))); } - ::sapi::StatusOr ScanString(absl::string_view content) { - SAPI_ASSIGN_OR_RETURN(MemoryFD mem_fd, - MemoryFD::CreateWithContent(content)); + ::sapi::StatusOr ScanString(absl::string_view content) + { + SAPI_ASSIGN_OR_RETURN( + MemoryFD mem_fd, MemoryFD::CreateWithContent(content)); return transaction_->ScanFd(mem_fd.fd()); } std::unique_ptr transaction_; }; -TEST_F(TransactionTest, BasicFunctionality) { - ASSERT_THAT(transaction_ - ->LoadRules(R"( +TEST_F(TransactionTest, BasicFunctionality) +{ + ASSERT_THAT( + transaction_ + ->LoadRules(R"( rule Number { strings: $ = "123" condition: all of them @@ -135,8 +149,8 @@ TEST_F(TransactionTest, BasicFunctionality) { condition: all of them })") - .ValueOrDie(), - Eq(3)); + .ValueOrDie(), + Eq(3)); SAPI_ASSERT_OK_AND_ASSIGN(YaraMatches matches, ScanString("qwerty 123")); @@ -149,22 +163,25 @@ TEST_F(TransactionTest, BasicFunctionality) { EXPECT_THAT(matches.match(1).id().rule_name(), StrEq("Keyboard")); } -TEST_F(TransactionTest, ConcurrentScanStressTest) { - ASSERT_THAT(transaction_ - ->LoadRules(R"( +TEST_F(TransactionTest, ConcurrentScanStressTest) +{ + ASSERT_THAT( + transaction_ + ->LoadRules(R"( rule Simple { strings: $ = "A" condition: all of them })") - .ValueOrDie(), - Eq(1)); + .ValueOrDie(), + Eq(1)); // Large number of threads during testing to increase likelihood of exposing // race conditions in threading code. constexpr int kThreads = 64; std::vector bundle; - for (int i = 0; i < kThreads; ++i) { + for (int i = 0; i < kThreads; ++i) + { bundle.emplace_back([this, i]() { std::string buf((i + 1) * 102400, 'B'); buf.append("A"); // Force the match to be at the very end @@ -173,7 +190,8 @@ TEST_F(TransactionTest, ConcurrentScanStressTest) { EXPECT_THAT(matches.match(0).id().rule_name(), StrEq("Simple")); }); } - for (auto& thread : bundle) { + for (auto& thread : bundle) + { thread.join(); } } diff --git a/tests/oss-fuzz/dex_fuzzer.cc b/tests/oss-fuzz/dex_fuzzer.cc index dec5cd219c..b9b4180679 100644 --- a/tests/oss-fuzz/dex_fuzzer.cc +++ b/tests/oss-fuzz/dex_fuzzer.cc @@ -1,6 +1,5 @@ -#include #include - +#include #include @@ -26,25 +25,23 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) } -int callback(YR_SCAN_CONTEXT* context, int message, void* message_data, void* user_data) +int callback( + YR_SCAN_CONTEXT* context, + int message, + void* message_data, + void* user_data) { return CALLBACK_CONTINUE; } -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (rules == NULL) return 0; yr_rules_scan_mem( - rules, - data, - size, - SCAN_FLAGS_NO_TRYCATCH, - callback, - NULL, - 0); + rules, data, size, SCAN_FLAGS_NO_TRYCATCH, callback, NULL, 0); return 0; } diff --git a/tests/oss-fuzz/dotnet_fuzzer.cc b/tests/oss-fuzz/dotnet_fuzzer.cc index 0f6e749a5a..090fe4988b 100644 --- a/tests/oss-fuzz/dotnet_fuzzer.cc +++ b/tests/oss-fuzz/dotnet_fuzzer.cc @@ -27,17 +27,15 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include - +#include #include -const char* RULES = \ - "import \"dotnet\"" - "rule test {" - " condition:" - " dotnet.module_name == \"foo.exe\"" - "}"; +const char* RULES = "import \"dotnet\"" + "rule test {" + " condition:" + " dotnet.module_name == \"foo.exe\"" + "}"; YR_RULES* rules = NULL; @@ -60,25 +58,23 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) } -int callback(YR_SCAN_CONTEXT* context, int message, void* message_data, void* user_data) +int callback( + YR_SCAN_CONTEXT* context, + int message, + void* message_data, + void* user_data) { return CALLBACK_CONTINUE; } -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (rules == NULL) return 0; yr_rules_scan_mem( - rules, - data, - size, - SCAN_FLAGS_NO_TRYCATCH, - callback, - NULL, - 0); + rules, data, size, SCAN_FLAGS_NO_TRYCATCH, callback, NULL, 0); return 0; } diff --git a/tests/oss-fuzz/elf_fuzzer.cc b/tests/oss-fuzz/elf_fuzzer.cc index 41dfddfc18..052d5fabb3 100644 --- a/tests/oss-fuzz/elf_fuzzer.cc +++ b/tests/oss-fuzz/elf_fuzzer.cc @@ -27,9 +27,8 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include - +#include #include @@ -55,25 +54,23 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) } -int callback(YR_SCAN_CONTEXT* context, int message, void* message_data, void* user_data) +int callback( + YR_SCAN_CONTEXT* context, + int message, + void* message_data, + void* user_data) { return CALLBACK_CONTINUE; } -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (rules == NULL) return 0; yr_rules_scan_mem( - rules, - data, - size, - SCAN_FLAGS_NO_TRYCATCH, - callback, - NULL, - 0); + rules, data, size, SCAN_FLAGS_NO_TRYCATCH, callback, NULL, 0); return 0; } \ No newline at end of file diff --git a/tests/oss-fuzz/macho_fuzzer.cc b/tests/oss-fuzz/macho_fuzzer.cc index 7101dc166d..a1307232e0 100644 --- a/tests/oss-fuzz/macho_fuzzer.cc +++ b/tests/oss-fuzz/macho_fuzzer.cc @@ -27,17 +27,15 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include - +#include #include -const char* RULES = \ - "import \"macho\"" - "rule test {" - " condition:" - " macho.segments[1].sections[0].segname == \"__TEXT\"" - "}"; +const char* RULES = "import \"macho\"" + "rule test {" + " condition:" + " macho.segments[1].sections[0].segname == \"__TEXT\"" + "}"; YR_RULES* rules = NULL; @@ -60,25 +58,23 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) } -int callback(YR_SCAN_CONTEXT* context, int message, void* message_data, void* user_data) +int callback( + YR_SCAN_CONTEXT* context, + int message, + void* message_data, + void* user_data) { return CALLBACK_CONTINUE; } -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (rules == NULL) return 0; yr_rules_scan_mem( - rules, - data, - size, - SCAN_FLAGS_NO_TRYCATCH, - callback, - NULL, - 0); + rules, data, size, SCAN_FLAGS_NO_TRYCATCH, callback, NULL, 0); return 0; } diff --git a/tests/oss-fuzz/pe_fuzzer.cc b/tests/oss-fuzz/pe_fuzzer.cc index 5e65b45e0f..15782f4af1 100644 --- a/tests/oss-fuzz/pe_fuzzer.cc +++ b/tests/oss-fuzz/pe_fuzzer.cc @@ -27,17 +27,16 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include - +#include #include -const char* RULES = \ - "import \"pe\"" - "rule test {" - " condition:" - " pe.rva_to_offset(pe.sections[0].virtual_address) == pe.sections[0].raw_data_offset" - "}"; +const char* RULES = "import \"pe\"" + "rule test {" + " condition:" + " pe.rva_to_offset(pe.sections[0].virtual_address) == " + "pe.sections[0].raw_data_offset" + "}"; YR_RULES* rules = NULL; @@ -60,25 +59,23 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) } -int callback(YR_SCAN_CONTEXT* context, int message, void* message_data, void* user_data) +int callback( + YR_SCAN_CONTEXT* context, + int message, + void* message_data, + void* user_data) { return CALLBACK_CONTINUE; } -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (rules == NULL) return 0; yr_rules_scan_mem( - rules, - data, - size, - SCAN_FLAGS_NO_TRYCATCH, - callback, - NULL, - 0); + rules, data, size, SCAN_FLAGS_NO_TRYCATCH, callback, NULL, 0); return 0; } \ No newline at end of file diff --git a/tests/oss-fuzz/rules_fuzzer.cc b/tests/oss-fuzz/rules_fuzzer.cc index 31613bd48a..4c2e9e7129 100644 --- a/tests/oss-fuzz/rules_fuzzer.cc +++ b/tests/oss-fuzz/rules_fuzzer.cc @@ -27,21 +27,20 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include #include - #include extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { - yr_initialize(); + yr_initialize(); return 0; } -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { YR_RULES* rules; YR_COMPILER* compiler; @@ -51,7 +50,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) if (!buffer) return 0; - strncpy(buffer, (const char *) data, size); + strncpy(buffer, (const char*) data, size); buffer[size] = 0; if (yr_compiler_create(&compiler) != ERROR_SUCCESS) diff --git a/tests/test-alignment.c b/tests/test-alignment.c index 43e8490782..a473ab060e 100644 --- a/tests/test-alignment.c +++ b/tests/test-alignment.c @@ -27,46 +27,47 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include #undef NDEBUG #include int err = 0; -#define CHECK_SIZE(expr,size) \ +#define CHECK_SIZE(expr, size) \ + do \ + { \ + printf("sizeof(" #expr ") = %zd ...", sizeof(expr)); \ + if (sizeof(expr) == size) \ + { \ + puts("ok"); \ + } \ + else \ + { \ + printf("expected %d\n", size); \ + err = 1; \ + } \ + } while (0); + +#define CHECK_OFFSET(expr, offset, subexpr) \ do \ { \ - printf("sizeof("#expr") = %zd ...", sizeof(expr)); \ - if (sizeof(expr) == size) \ + printf( \ + "offsetof(" #expr ", " #subexpr ") = %zd ...", \ + offsetof(expr, subexpr)); \ + if (offsetof(expr, subexpr) == offset) \ { \ puts("ok"); \ } \ else \ { \ - printf("expected %d\n", size); \ + printf("expected %d\n", offset); \ err = 1; \ } \ - } while (0); - -#define CHECK_OFFSET(expr,offset,subexpr) \ - do \ - { \ - printf("offsetof("#expr", "#subexpr") = %zd ...", \ - offsetof(expr, subexpr)); \ - if (offsetof(expr, subexpr) == offset) \ - { \ - puts("ok"); \ - } \ - else \ - { \ - printf("expected %d\n", offset); \ - err = 1; \ - } \ } while (0) -int main (int argc, char **argv) +int main(int argc, char **argv) { CHECK_SIZE(YR_NAMESPACE, 16); CHECK_OFFSET(YR_NAMESPACE, 0, name); @@ -75,9 +76,9 @@ int main (int argc, char **argv) CHECK_SIZE(YR_META, 32); CHECK_OFFSET(YR_META, 0, identifier); CHECK_OFFSET(YR_META, 8, string); - CHECK_OFFSET(YR_META, 16, integer); - CHECK_OFFSET(YR_META, 24, type); - CHECK_OFFSET(YR_META, 28, flags); + CHECK_OFFSET(YR_META, 16, integer); + CHECK_OFFSET(YR_META, 24, type); + CHECK_OFFSET(YR_META, 28, flags); CHECK_SIZE(YR_STRING, 56); CHECK_OFFSET(YR_STRING, 0, flags); @@ -92,21 +93,21 @@ int main (int argc, char **argv) CHECK_OFFSET(YR_STRING, 48, identifier); CHECK_SIZE(YR_RULE, 48); - CHECK_OFFSET(YR_RULE, 8, identifier); + CHECK_OFFSET(YR_RULE, 8, identifier); CHECK_OFFSET(YR_RULE, 16, tags); CHECK_OFFSET(YR_RULE, 24, metas); CHECK_OFFSET(YR_RULE, 32, strings); CHECK_OFFSET(YR_RULE, 40, ns); CHECK_SIZE(YR_SUMMARY, 12); - CHECK_OFFSET(YR_SUMMARY, 0, num_rules); - CHECK_OFFSET(YR_SUMMARY, 4, num_strings); - CHECK_OFFSET(YR_SUMMARY, 8, num_namespaces); + CHECK_OFFSET(YR_SUMMARY, 0, num_rules); + CHECK_OFFSET(YR_SUMMARY, 4, num_strings); + CHECK_OFFSET(YR_SUMMARY, 8, num_namespaces); CHECK_SIZE(YR_EXTERNAL_VARIABLE, 24); - CHECK_OFFSET(YR_EXTERNAL_VARIABLE, 8, value.i); - CHECK_OFFSET(YR_EXTERNAL_VARIABLE, 8, value.f); - CHECK_OFFSET(YR_EXTERNAL_VARIABLE, 8, value.s); + CHECK_OFFSET(YR_EXTERNAL_VARIABLE, 8, value.i); + CHECK_OFFSET(YR_EXTERNAL_VARIABLE, 8, value.f); + CHECK_OFFSET(YR_EXTERNAL_VARIABLE, 8, value.s); CHECK_OFFSET(YR_EXTERNAL_VARIABLE, 16, identifier); CHECK_SIZE(YR_AC_MATCH, 40); diff --git a/tests/test-api.c b/tests/test-api.c index de8393e0d2..ad14de586a 100644 --- a/tests/test-api.c +++ b/tests/test-api.c @@ -1,6 +1,7 @@ -#include #include #include +#include + #include "util.h" #if defined(_WIN32) || defined(__CYGWIN__) @@ -41,8 +42,7 @@ void test_disabled_rules() yr_rule_disable(rule); } - yr_rules_scan_mem( - rules, (uint8_t *) buf, strlen(buf), 0, count, &counters, 0); + yr_rules_scan_mem(rules, (uint8_t*) buf, strlen(buf), 0, count, &counters, 0); yr_rules_destroy(rules); @@ -58,15 +58,15 @@ void test_disabled_rules() const char* _include_callback( - const char* include_name, - const char* calling_rule_filename, - const char* calling_rule_namespace, - void* user_data) + const char* include_name, + const char* calling_rule_filename, + const char* calling_rule_namespace, + void* user_data) { -if (strcmp(include_name, "ok") == 0) - return "rule test {condition: true}"; -else - return NULL; + if (strcmp(include_name, "ok") == 0) + return "rule test {condition: true}"; + else + return NULL; } @@ -109,7 +109,8 @@ void test_file_descriptor() YR_RULES* rules = NULL; #if defined(_WIN32) || defined(__CYGWIN__) - HANDLE fd = CreateFile("tests/data/baz.yar", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); + HANDLE fd = CreateFile( + "tests/data/baz.yar", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (fd == INVALID_HANDLE_VALUE) { fputs("CreateFile failed", stderr); @@ -169,12 +170,10 @@ void test_max_string_per_rules() yr_initialize(); yr_get_configuration( - YR_CONFIG_MAX_STRINGS_PER_RULE, - (void*) &old_max_strings_per_rule); + YR_CONFIG_MAX_STRINGS_PER_RULE, (void*) &old_max_strings_per_rule); yr_set_configuration( - YR_CONFIG_MAX_STRINGS_PER_RULE, - (void*) &new_max_strings_per_rule); + YR_CONFIG_MAX_STRINGS_PER_RULE, (void*) &new_max_strings_per_rule); assert_error( "rule test { \ @@ -188,8 +187,7 @@ void test_max_string_per_rules() new_max_strings_per_rule = 2; yr_set_configuration( - YR_CONFIG_MAX_STRINGS_PER_RULE, - (void*) &new_max_strings_per_rule); + YR_CONFIG_MAX_STRINGS_PER_RULE, (void*) &new_max_strings_per_rule); assert_error( "rule test { \ @@ -201,8 +199,7 @@ void test_max_string_per_rules() ERROR_SUCCESS); yr_set_configuration( - YR_CONFIG_MAX_STRINGS_PER_RULE, - (void*) &old_max_strings_per_rule); + YR_CONFIG_MAX_STRINGS_PER_RULE, (void*) &old_max_strings_per_rule); yr_finalize(); } @@ -245,13 +242,9 @@ void test_max_match_data() yr_initialize(); - yr_get_configuration( - YR_CONFIG_MAX_MATCH_DATA, - (void*) &old_max_match_data); + yr_get_configuration(YR_CONFIG_MAX_MATCH_DATA, (void*) &old_max_match_data); - yr_set_configuration( - YR_CONFIG_MAX_MATCH_DATA, - (void*) &new_max_match_data); + yr_set_configuration(YR_CONFIG_MAX_MATCH_DATA, (void*) &new_max_match_data); if (compile_rule(rules_str, &rules) != ERROR_SUCCESS) { @@ -261,7 +254,7 @@ void test_max_match_data() int err = yr_rules_scan_mem( rules, - (const uint8_t *) "foobar", + (const uint8_t*) "foobar", 6, 0, test_max_match_data_callback, @@ -333,14 +326,7 @@ void test_save_load_rules() exit(EXIT_FAILURE); } - int err = yr_rules_scan_mem( - rules, - (uint8_t *) "", - 0, - 0, - count, - &counters, - 0); + int err = yr_rules_scan_mem(rules, (uint8_t*) "", 0, 0, count, &counters, 0); if (err != ERROR_SUCCESS) { @@ -398,8 +384,8 @@ void test_scanner() yr_compiler_define_string_variable(compiler, "str_var", ""); - if (yr_compiler_define_string_variable( - compiler, "str_var", "") != ERROR_DUPLICATED_EXTERNAL_VARIABLE) + if (yr_compiler_define_string_variable(compiler, "str_var", "") != + ERROR_DUPLICATED_EXTERNAL_VARIABLE) { yr_compiler_destroy(compiler); perror("expecting ERROR_DUPLICATED_EXTERNAL_VARIABLE"); @@ -424,7 +410,7 @@ void test_scanner() yr_compiler_destroy(compiler); // Create an scanner - if (yr_scanner_create(rules, &scanner1)!= ERROR_SUCCESS) + if (yr_scanner_create(rules, &scanner1) != ERROR_SUCCESS) { yr_rules_destroy(rules); perror("yr_scanner_create"); @@ -432,7 +418,7 @@ void test_scanner() } // Create another scanner - if (yr_scanner_create(rules, &scanner2)!= ERROR_SUCCESS) + if (yr_scanner_create(rules, &scanner2) != ERROR_SUCCESS) { yr_scanner_destroy(scanner1); yr_rules_destroy(rules); @@ -442,15 +428,17 @@ void test_scanner() // Let's check the yr_scanner_scan_mem returns the appropriate error when // called without specifying a callback. - result = yr_scanner_scan_mem(scanner1, (uint8_t *) buf, strlen(buf)); + result = yr_scanner_scan_mem(scanner1, (uint8_t*) buf, strlen(buf)); if (result != ERROR_CALLBACK_REQUIRED) { yr_scanner_destroy(scanner1); yr_scanner_destroy(scanner2); yr_rules_destroy(rules); - printf("expecting ERROR_CALLBACK_REQUIRED (%d), got: %d\n", - ERROR_CALLBACK_REQUIRED, result); + printf( + "expecting ERROR_CALLBACK_REQUIRED (%d), got: %d\n", + ERROR_CALLBACK_REQUIRED, + result); exit(EXIT_FAILURE); } @@ -471,20 +459,18 @@ void test_scanner() yr_scanner_define_boolean_variable(scanner2, "bool_var", 0); yr_scanner_define_string_variable(scanner2, "str_var", "bar"); - result = yr_scanner_scan_mem(scanner1, (uint8_t *) buf, strlen(buf)); + result = yr_scanner_scan_mem(scanner1, (uint8_t*) buf, strlen(buf)); if (result != ERROR_SUCCESS) { yr_scanner_destroy(scanner1); yr_scanner_destroy(scanner2); yr_rules_destroy(rules); - printf("expecting ERROR_SUCCESS (%d), got: %d\n", - ERROR_SUCCESS, result); + printf("expecting ERROR_SUCCESS (%d), got: %d\n", ERROR_SUCCESS, result); exit(EXIT_FAILURE); } - if (counters.rules_matching != 2 || - counters.rules_not_matching != 1) + if (counters.rules_matching != 2 || counters.rules_not_matching != 1) { yr_scanner_destroy(scanner1); yr_scanner_destroy(scanner2); @@ -497,10 +483,9 @@ void test_scanner() yr_scanner_set_flags(scanner1, SCAN_FLAGS_REPORT_RULES_MATCHING); yr_scanner_set_callback(scanner1, count, &counters); - yr_scanner_scan_mem(scanner1, (uint8_t *) buf, strlen(buf)); + yr_scanner_scan_mem(scanner1, (uint8_t*) buf, strlen(buf)); - if (counters.rules_matching != 2 || - counters.rules_not_matching != 0) + if (counters.rules_matching != 2 || counters.rules_not_matching != 0) { yr_scanner_destroy(scanner1); yr_scanner_destroy(scanner2); @@ -513,10 +498,9 @@ void test_scanner() yr_scanner_set_flags(scanner2, SCAN_FLAGS_REPORT_RULES_NOT_MATCHING); yr_scanner_set_callback(scanner2, count, &counters); - yr_scanner_scan_mem(scanner2, (uint8_t *) buf, strlen(buf)); + yr_scanner_scan_mem(scanner2, (uint8_t*) buf, strlen(buf)); - if (counters.rules_not_matching != 2 || - counters.rules_matching != 0) + if (counters.rules_not_matching != 2 || counters.rules_matching != 0) { yr_scanner_destroy(scanner1); yr_scanner_destroy(scanner2); @@ -567,7 +551,7 @@ void test_issue_834() yr_compiler_destroy(compiler); - if (yr_scanner_create(rules, &scanner)!= ERROR_SUCCESS) + if (yr_scanner_create(rules, &scanner) != ERROR_SUCCESS) { yr_rules_destroy(rules); perror("yr_scanner_create"); @@ -577,8 +561,8 @@ void test_issue_834() yr_scanner_set_callback(scanner, do_nothing, NULL); // Call yr_scanner_scan_mem twice. - yr_scanner_scan_mem(scanner, (uint8_t *) buf, strlen(buf)); - yr_scanner_scan_mem(scanner, (uint8_t *) buf, strlen(buf)); + yr_scanner_scan_mem(scanner, (uint8_t*) buf, strlen(buf)); + yr_scanner_scan_mem(scanner, (uint8_t*) buf, strlen(buf)); yr_scanner_destroy(scanner); yr_rules_destroy(rules); @@ -618,10 +602,7 @@ void test_ast_callback() int ok = 0; - yr_compiler_set_re_ast_callback( - compiler, - ast_callback, - &ok); + yr_compiler_set_re_ast_callback(compiler, ast_callback, &ok); // Compile a rule that use the variables in the condition. if (yr_compiler_add_string(compiler, rules_str, NULL) != 0) @@ -642,9 +623,7 @@ void test_ast_callback() } -void stats_for_rules( - const char* rules_str, - YR_RULES_STATS* stats) +void stats_for_rules(const char* rules_str, YR_RULES_STATS* stats) { YR_COMPILER* compiler = NULL; YR_RULES* rules = NULL; @@ -683,7 +662,8 @@ void test_rules_stats() { YR_RULES_STATS stats; - stats_for_rules("\ + stats_for_rules( + "\ rule test { \ strings: $ = /.*/ \ condition: all of them }", @@ -693,7 +673,8 @@ void test_rules_stats() assert_true_expr(stats.num_strings == 1); assert_true_expr(stats.ac_root_match_list_length == 1); - stats_for_rules("\ + stats_for_rules( + "\ rule test { \ strings: $ = \"abc\" \ condition: all of them }", @@ -707,7 +688,8 @@ void test_rules_stats() assert_true_expr(stats.ac_match_list_length_pctls[1] == 1); assert_true_expr(stats.ac_match_list_length_pctls[100] == 1); - stats_for_rules("\ + stats_for_rules( + "\ rule test { \ strings: \ $ = \"00000\" \ @@ -727,7 +709,8 @@ void test_rules_stats() assert_true_expr(stats.ac_match_list_length_pctls[1] == 3); assert_true_expr(stats.ac_match_list_length_pctls[100] == 3); - stats_for_rules("\ + stats_for_rules( + "\ rule test { \ strings: \ $ = \"00000\" \ @@ -749,13 +732,14 @@ void test_rules_stats() assert_true_expr(stats.ac_match_list_length_pctls[1] == 1); assert_true_expr(stats.ac_match_list_length_pctls[100] == 3); - stats_for_rules("\ + stats_for_rules( + "\ rule test { \ condition: true }", &stats); assert_true_expr(stats.num_rules == 1); - assert_true_expr(stats.num_strings== 0); + assert_true_expr(stats.num_strings == 0); assert_true_expr(stats.ac_matches == 0); assert_true_expr(stats.ac_root_match_list_length == 0); } @@ -788,8 +772,10 @@ void test_issue_920() if (compiler->last_error != ERROR_DUPLICATED_IDENTIFIER) { yr_compiler_destroy(compiler); - printf("expecting ERROR_CALLBACK_REQUIRED (%d), got: %d\n", - ERROR_DUPLICATED_IDENTIFIER, compiler->last_error); + printf( + "expecting ERROR_CALLBACK_REQUIRED (%d), got: %d\n", + ERROR_DUPLICATED_IDENTIFIER, + compiler->last_error); exit(EXIT_FAILURE); } diff --git a/tests/test-arena.c b/tests/test-arena.c index 2853ef27c3..0630eac150 100644 --- a/tests/test-arena.c +++ b/tests/test-arena.c @@ -27,9 +27,10 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include -#include + #include "util.h" static void basic_tests() @@ -53,14 +54,16 @@ static void basic_tests() // Write 16 bytes, "123456789ABCDEF" + null terminator. This forces a // reallocation. assert_true_expr( - yr_arena_write_string(arena, 0, "123456789ABCDEF", &ref) == ERROR_SUCCESS); + yr_arena_write_string(arena, 0, "123456789ABCDEF", &ref) == + ERROR_SUCCESS); // Offset should be 5 as this was written after the first 5-bytes write. assert_true_expr(ref.offset == 5); // Write 4 bytes, "bar" + null terminator. assert_true_expr( - yr_arena_write_string(arena, 0, "123456789ABCDEF", &ref) == ERROR_SUCCESS); + yr_arena_write_string(arena, 0, "123456789ABCDEF", &ref) == + ERROR_SUCCESS); // Offset should be 21. assert_true_expr(ref.offset == 21); @@ -72,7 +75,8 @@ static void basic_tests() typedef struct TEST_STRUCT TEST_STRUCT; -struct TEST_STRUCT { +struct TEST_STRUCT +{ DECLARE_REFERENCE(char*, str1); DECLARE_REFERENCE(char*, str2); }; @@ -112,21 +116,23 @@ static void advanced_tests() yr_arena_write_string(arena, 1, "foo", &ref); // Get the string's address and store it in the struct's "str" field. - s->str1 = (char *) yr_arena_ref_to_ptr(arena, &ref); + s->str1 = (char*) yr_arena_ref_to_ptr(arena, &ref); // Write another string in buffer 1. yr_arena_write_string(arena, 1, "bar", &ref); // Get the string's address and store it in the struct's "str" field. - s->str2 = (char *) yr_arena_ref_to_ptr(arena, &ref); + s->str2 = (char*) yr_arena_ref_to_ptr(arena, &ref); // The arena should have two reloc entries for the "str1" and "str2" fields. assert_true_expr(arena->reloc_list_head != NULL); assert_true_expr(arena->reloc_list_tail != NULL); assert_true_expr(arena->reloc_list_head->buffer_id == 0); assert_true_expr(arena->reloc_list_tail->buffer_id == 0); - assert_true_expr(arena->reloc_list_head->offset == offsetof(TEST_STRUCT, str1)); - assert_true_expr(arena->reloc_list_tail->offset == offsetof(TEST_STRUCT, str2)); + assert_true_expr( + arena->reloc_list_head->offset == offsetof(TEST_STRUCT, str1)); + assert_true_expr( + arena->reloc_list_tail->offset == offsetof(TEST_STRUCT, str2)); // Write another string in buffer 1 that causes a buffer reallocation. yr_arena_write_string(arena, 1, "aaaaaaaaaaa", NULL); diff --git a/tests/test-atoms.c b/tests/test-atoms.c index 37f91b66a7..cde318dfc9 100644 --- a/tests/test-atoms.c +++ b/tests/test-atoms.c @@ -28,28 +28,29 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include + #include "util.h" void test_table_quality() { YR_ATOM_QUALITY_TABLE_ENTRY l1[] = { - {{0x00, 0x00, 0x00, 0x00}, 1}, - {{0x00, 0x00, 0x00, 0x01}, 2}, - {{0x00, 0x00, 0x00, 0x02}, 3}, + {{0x00, 0x00, 0x00, 0x00}, 1}, + {{0x00, 0x00, 0x00, 0x01}, 2}, + {{0x00, 0x00, 0x00, 0x02}, 3}, }; YR_ATOM_QUALITY_TABLE_ENTRY l2[] = { - {{0x00, 0x00, 0x00, 0x00}, 1}, - {{0x00, 0x00, 0x00, 0x01}, 2}, - {{0x00, 0x00, 0x00, 0x02}, 3}, - {{0x00, 0x00, 0x00, 0x03}, 4}, + {{0x00, 0x00, 0x00, 0x00}, 1}, + {{0x00, 0x00, 0x00, 0x01}, 2}, + {{0x00, 0x00, 0x00, 0x02}, 3}, + {{0x00, 0x00, 0x00, 0x03}, 4}, }; YR_ATOM a0 = { - .length = 4, - .bytes = {0x00, 0x00, 0x00, 0x00}, - .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; + .length = 4, + .bytes = {0x00, 0x00, 0x00, 0x00}, + .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; YR_ATOM a1 = {4, {0x00, 0x00, 0x00, 0x01}, {0xFF, 0xFF, 0xFF, 0xFF}}; YR_ATOM a2 = {4, {0x00, 0x00, 0x00, 0x02}, {0xFF, 0xFF, 0xFF, 0xFF}}; @@ -83,69 +84,54 @@ void test_heuristic_quality() YR_ATOMS_CONFIG c; YR_ATOM a00000000 = { - .length = 4, - .bytes = {0x00, 0x00, 0x00, 0x00}, - .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; + .length = 4, + .bytes = {0x00, 0x00, 0x00, 0x00}, + .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; YR_ATOM a00000001 = { - .length = 4, - .bytes = {0x00, 0x00, 0x00, 0x01}, - .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; + .length = 4, + .bytes = {0x00, 0x00, 0x00, 0x01}, + .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; YR_ATOM a00000102 = { - .length = 4, - .bytes = {0x00, 0x00, 0x01, 0x02}, - .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; + .length = 4, + .bytes = {0x00, 0x00, 0x01, 0x02}, + .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; YR_ATOM a00010203 = { - .length = 4, - .bytes = {0x00, 0x01, 0x02, 0x03}, - .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; + .length = 4, + .bytes = {0x00, 0x01, 0x02, 0x03}, + .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; YR_ATOM a01020304 = { - .length = 4, - .bytes = {0x01, 0x02, 0x03, 0x04}, - .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; + .length = 4, + .bytes = {0x01, 0x02, 0x03, 0x04}, + .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; - YR_ATOM a01 = { - .length = 1, - .bytes = {0x01}, - .mask = {0xFF}}; + YR_ATOM a01 = {.length = 1, .bytes = {0x01}, .mask = {0xFF}}; - YR_ATOM a0001 = { - .length = 2, - .bytes = {0x00, 0x01}, - .mask = {0xFF, 0xFF}}; + YR_ATOM a0001 = {.length = 2, .bytes = {0x00, 0x01}, .mask = {0xFF, 0xFF}}; YR_ATOM a000001 = { - .length = 3, - .bytes = {0x00, 0x00, 0x01}, - .mask = {0xFF, 0xFF, 0xFF}}; + .length = 3, .bytes = {0x00, 0x00, 0x01}, .mask = {0xFF, 0xFF, 0xFF}}; YR_ATOM a000102 = { - .length = 3, - .bytes = {0x00, 0x01, 0x02}, - .mask = {0xFF, 0xFF, 0xFF}}; + .length = 3, .bytes = {0x00, 0x01, 0x02}, .mask = {0xFF, 0xFF, 0xFF}}; YR_ATOM a010203 = { - .length = 3, - .bytes = {0x01, 0x02, 0x03}, - .mask = {0xFF, 0xFF, 0xFF}}; + .length = 3, .bytes = {0x01, 0x02, 0x03}, .mask = {0xFF, 0xFF, 0xFF}}; - YR_ATOM a0102 = { - .length = 2, - .bytes = {0x01, 0x02}, - .mask = {0xFF, 0xFF}}; + YR_ATOM a0102 = {.length = 2, .bytes = {0x01, 0x02}, .mask = {0xFF, 0xFF}}; YR_ATOM a01020000 = { - .length = 4, - .bytes = {0x01, 0x02, 0x00, 0x00}, - .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; + .length = 4, + .bytes = {0x01, 0x02, 0x00, 0x00}, + .mask = {0xFF, 0xFF, 0xFF, 0xFF}}; YR_ATOM a0102XX04 = { - .length = 4, - .bytes = {0x01, 0x02, 0x03, 0x04}, - .mask = {0xFF, 0xFF, 0x00, 0xFF}}; + .length = 4, + .bytes = {0x01, 0x02, 0x03, 0x04}, + .mask = {0xFF, 0xFF, 0x00, 0xFF}}; c.get_atom_quality = yr_atoms_heuristic_quality; @@ -154,322 +140,192 @@ void test_heuristic_quality() int q00000102 = yr_atoms_heuristic_quality(&c, &a00000102); int q00010203 = yr_atoms_heuristic_quality(&c, &a00010203); int q01020304 = yr_atoms_heuristic_quality(&c, &a01020304); - int q010203 = yr_atoms_heuristic_quality(&c, &a010203); - int q0102 = yr_atoms_heuristic_quality(&c, &a0102); - int q01 = yr_atoms_heuristic_quality(&c, &a01); - int q0001 = yr_atoms_heuristic_quality(&c, &a0001); - int q000001 = yr_atoms_heuristic_quality(&c, &a000001); - int q000102 = yr_atoms_heuristic_quality(&c, &a000102); + int q010203 = yr_atoms_heuristic_quality(&c, &a010203); + int q0102 = yr_atoms_heuristic_quality(&c, &a0102); + int q01 = yr_atoms_heuristic_quality(&c, &a01); + int q0001 = yr_atoms_heuristic_quality(&c, &a0001); + int q000001 = yr_atoms_heuristic_quality(&c, &a000001); + int q000102 = yr_atoms_heuristic_quality(&c, &a000102); int q01020000 = yr_atoms_heuristic_quality(&c, &a01020000); int q0102XX04 = yr_atoms_heuristic_quality(&c, &a0102XX04); a010203.mask[1] = 0x00; - int q01XX03 = yr_atoms_heuristic_quality(&c, &a010203); + int q01XX03 = yr_atoms_heuristic_quality(&c, &a010203); a010203.mask[1] = 0x0F; - int q01X203 = yr_atoms_heuristic_quality(&c, &a010203); + int q01X203 = yr_atoms_heuristic_quality(&c, &a010203); a010203.mask[1] = 0x0F; - int q010X03 = yr_atoms_heuristic_quality(&c, &a010203); + int q010X03 = yr_atoms_heuristic_quality(&c, &a010203); a010203.mask[2] = 0x0F; - int q010X0X = yr_atoms_heuristic_quality(&c, &a010203); + int q010X0X = yr_atoms_heuristic_quality(&c, &a010203); assert_true_expr(q00000001 > q00000000); assert_true_expr(q00000001 > q000001); - assert_true_expr(q000001 > q0001); + assert_true_expr(q000001 > q0001); assert_true_expr(q00000102 > q00000001); assert_true_expr(q00010203 > q00000102); assert_true_expr(q01020304 > q00010203); - assert_true_expr(q000102 > q000001); + assert_true_expr(q000102 > q000001); assert_true_expr(q00010203 > q010203); - assert_true_expr(q010203 > q0102); - assert_true_expr(q010203 > q00000000); - assert_true_expr(q0102 > q01); - assert_true_expr(q01X203 > q0102); - assert_true_expr(q01X203 > q0001); - assert_true_expr(q01X203 < q010203); - assert_true_expr(q01X203 == q010X03); - assert_true_expr(q01XX03 <= q0102); - assert_true_expr(q01XX03 < q010X03); - assert_true_expr(q01XX03 < q010203); - assert_true_expr(q010X0X > q01); - assert_true_expr(q010X0X < q010203); + assert_true_expr(q010203 > q0102); + assert_true_expr(q010203 > q00000000); + assert_true_expr(q0102 > q01); + assert_true_expr(q01X203 > q0102); + assert_true_expr(q01X203 > q0001); + assert_true_expr(q01X203 < q010203); + assert_true_expr(q01X203 == q010X03); + assert_true_expr(q01XX03 <= q0102); + assert_true_expr(q01XX03 < q010X03); + assert_true_expr(q01XX03 < q010203); + assert_true_expr(q010X0X > q01); + assert_true_expr(q010X0X < q010203); assert_true_expr(q01020000 > q0102XX04); assert_true_expr(q01020304 == YR_MAX_ATOM_QUALITY); } - void test_atom_choose() { - struct atom atoms_61_XX_63_64[] = { - {4, {0x61, 0x00, 0x63, 0x64}}, - {4, {0x61, 0x01, 0x63, 0x64}}, - {4, {0x61, 0x02, 0x63, 0x64}}, - {4, {0x61, 0x03, 0x63, 0x64}}, - {4, {0x61, 0x04, 0x63, 0x64}}, - {4, {0x61, 0x05, 0x63, 0x64}}, - {4, {0x61, 0x06, 0x63, 0x64}}, - {4, {0x61, 0x07, 0x63, 0x64}}, - {4, {0x61, 0x08, 0x63, 0x64}}, - {4, {0x61, 0x09, 0x63, 0x64}}, - {4, {0x61, 0x0A, 0x63, 0x64}}, - {4, {0x61, 0x0B, 0x63, 0x64}}, - {4, {0x61, 0x0C, 0x63, 0x64}}, - {4, {0x61, 0x0D, 0x63, 0x64}}, - {4, {0x61, 0x0E, 0x63, 0x64}}, - {4, {0x61, 0x0F, 0x63, 0x64}}, - {4, {0x61, 0x10, 0x63, 0x64}}, - {4, {0x61, 0x11, 0x63, 0x64}}, - {4, {0x61, 0x12, 0x63, 0x64}}, - {4, {0x61, 0x13, 0x63, 0x64}}, - {4, {0x61, 0x14, 0x63, 0x64}}, - {4, {0x61, 0x15, 0x63, 0x64}}, - {4, {0x61, 0x16, 0x63, 0x64}}, - {4, {0x61, 0x17, 0x63, 0x64}}, - {4, {0x61, 0x18, 0x63, 0x64}}, - {4, {0x61, 0x19, 0x63, 0x64}}, - {4, {0x61, 0x1A, 0x63, 0x64}}, - {4, {0x61, 0x1B, 0x63, 0x64}}, - {4, {0x61, 0x1C, 0x63, 0x64}}, - {4, {0x61, 0x1D, 0x63, 0x64}}, - {4, {0x61, 0x1E, 0x63, 0x64}}, - {4, {0x61, 0x1F, 0x63, 0x64}}, - {4, {0x61, 0x20, 0x63, 0x64}}, - {4, {0x61, 0x21, 0x63, 0x64}}, - {4, {0x61, 0x22, 0x63, 0x64}}, - {4, {0x61, 0x23, 0x63, 0x64}}, - {4, {0x61, 0x24, 0x63, 0x64}}, - {4, {0x61, 0x25, 0x63, 0x64}}, - {4, {0x61, 0x26, 0x63, 0x64}}, - {4, {0x61, 0x27, 0x63, 0x64}}, - {4, {0x61, 0x28, 0x63, 0x64}}, - {4, {0x61, 0x29, 0x63, 0x64}}, - {4, {0x61, 0x2A, 0x63, 0x64}}, - {4, {0x61, 0x2B, 0x63, 0x64}}, - {4, {0x61, 0x2C, 0x63, 0x64}}, - {4, {0x61, 0x2D, 0x63, 0x64}}, - {4, {0x61, 0x2E, 0x63, 0x64}}, - {4, {0x61, 0x2F, 0x63, 0x64}}, - {4, {0x61, 0x30, 0x63, 0x64}}, - {4, {0x61, 0x31, 0x63, 0x64}}, - {4, {0x61, 0x32, 0x63, 0x64}}, - {4, {0x61, 0x33, 0x63, 0x64}}, - {4, {0x61, 0x34, 0x63, 0x64}}, - {4, {0x61, 0x35, 0x63, 0x64}}, - {4, {0x61, 0x36, 0x63, 0x64}}, - {4, {0x61, 0x37, 0x63, 0x64}}, - {4, {0x61, 0x38, 0x63, 0x64}}, - {4, {0x61, 0x39, 0x63, 0x64}}, - {4, {0x61, 0x3A, 0x63, 0x64}}, - {4, {0x61, 0x3B, 0x63, 0x64}}, - {4, {0x61, 0x3C, 0x63, 0x64}}, - {4, {0x61, 0x3D, 0x63, 0x64}}, - {4, {0x61, 0x3E, 0x63, 0x64}}, - {4, {0x61, 0x3F, 0x63, 0x64}}, - {4, {0x61, 0x40, 0x63, 0x64}}, - {4, {0x61, 0x41, 0x63, 0x64}}, - {4, {0x61, 0x42, 0x63, 0x64}}, - {4, {0x61, 0x43, 0x63, 0x64}}, - {4, {0x61, 0x44, 0x63, 0x64}}, - {4, {0x61, 0x45, 0x63, 0x64}}, - {4, {0x61, 0x46, 0x63, 0x64}}, - {4, {0x61, 0x47, 0x63, 0x64}}, - {4, {0x61, 0x48, 0x63, 0x64}}, - {4, {0x61, 0x49, 0x63, 0x64}}, - {4, {0x61, 0x4A, 0x63, 0x64}}, - {4, {0x61, 0x4B, 0x63, 0x64}}, - {4, {0x61, 0x4C, 0x63, 0x64}}, - {4, {0x61, 0x4D, 0x63, 0x64}}, - {4, {0x61, 0x4E, 0x63, 0x64}}, - {4, {0x61, 0x4F, 0x63, 0x64}}, - {4, {0x61, 0x50, 0x63, 0x64}}, - {4, {0x61, 0x51, 0x63, 0x64}}, - {4, {0x61, 0x52, 0x63, 0x64}}, - {4, {0x61, 0x53, 0x63, 0x64}}, - {4, {0x61, 0x54, 0x63, 0x64}}, - {4, {0x61, 0x55, 0x63, 0x64}}, - {4, {0x61, 0x56, 0x63, 0x64}}, - {4, {0x61, 0x57, 0x63, 0x64}}, - {4, {0x61, 0x58, 0x63, 0x64}}, - {4, {0x61, 0x59, 0x63, 0x64}}, - {4, {0x61, 0x5A, 0x63, 0x64}}, - {4, {0x61, 0x5B, 0x63, 0x64}}, - {4, {0x61, 0x5C, 0x63, 0x64}}, - {4, {0x61, 0x5D, 0x63, 0x64}}, - {4, {0x61, 0x5E, 0x63, 0x64}}, - {4, {0x61, 0x5F, 0x63, 0x64}}, - {4, {0x61, 0x60, 0x63, 0x64}}, - {4, {0x61, 0x61, 0x63, 0x64}}, - {4, {0x61, 0x62, 0x63, 0x64}}, - {4, {0x61, 0x63, 0x63, 0x64}}, - {4, {0x61, 0x64, 0x63, 0x64}}, - {4, {0x61, 0x65, 0x63, 0x64}}, - {4, {0x61, 0x66, 0x63, 0x64}}, - {4, {0x61, 0x67, 0x63, 0x64}}, - {4, {0x61, 0x68, 0x63, 0x64}}, - {4, {0x61, 0x69, 0x63, 0x64}}, - {4, {0x61, 0x6A, 0x63, 0x64}}, - {4, {0x61, 0x6B, 0x63, 0x64}}, - {4, {0x61, 0x6C, 0x63, 0x64}}, - {4, {0x61, 0x6D, 0x63, 0x64}}, - {4, {0x61, 0x6E, 0x63, 0x64}}, - {4, {0x61, 0x6F, 0x63, 0x64}}, - {4, {0x61, 0x70, 0x63, 0x64}}, - {4, {0x61, 0x71, 0x63, 0x64}}, - {4, {0x61, 0x72, 0x63, 0x64}}, - {4, {0x61, 0x73, 0x63, 0x64}}, - {4, {0x61, 0x74, 0x63, 0x64}}, - {4, {0x61, 0x75, 0x63, 0x64}}, - {4, {0x61, 0x76, 0x63, 0x64}}, - {4, {0x61, 0x77, 0x63, 0x64}}, - {4, {0x61, 0x78, 0x63, 0x64}}, - {4, {0x61, 0x79, 0x63, 0x64}}, - {4, {0x61, 0x7A, 0x63, 0x64}}, - {4, {0x61, 0x7B, 0x63, 0x64}}, - {4, {0x61, 0x7C, 0x63, 0x64}}, - {4, {0x61, 0x7D, 0x63, 0x64}}, - {4, {0x61, 0x7E, 0x63, 0x64}}, - {4, {0x61, 0x7F, 0x63, 0x64}}, - {4, {0x61, 0x80, 0x63, 0x64}}, - {4, {0x61, 0x81, 0x63, 0x64}}, - {4, {0x61, 0x82, 0x63, 0x64}}, - {4, {0x61, 0x83, 0x63, 0x64}}, - {4, {0x61, 0x84, 0x63, 0x64}}, - {4, {0x61, 0x85, 0x63, 0x64}}, - {4, {0x61, 0x86, 0x63, 0x64}}, - {4, {0x61, 0x87, 0x63, 0x64}}, - {4, {0x61, 0x88, 0x63, 0x64}}, - {4, {0x61, 0x89, 0x63, 0x64}}, - {4, {0x61, 0x8A, 0x63, 0x64}}, - {4, {0x61, 0x8B, 0x63, 0x64}}, - {4, {0x61, 0x8C, 0x63, 0x64}}, - {4, {0x61, 0x8D, 0x63, 0x64}}, - {4, {0x61, 0x8E, 0x63, 0x64}}, - {4, {0x61, 0x8F, 0x63, 0x64}}, - {4, {0x61, 0x90, 0x63, 0x64}}, - {4, {0x61, 0x91, 0x63, 0x64}}, - {4, {0x61, 0x92, 0x63, 0x64}}, - {4, {0x61, 0x93, 0x63, 0x64}}, - {4, {0x61, 0x94, 0x63, 0x64}}, - {4, {0x61, 0x95, 0x63, 0x64}}, - {4, {0x61, 0x96, 0x63, 0x64}}, - {4, {0x61, 0x97, 0x63, 0x64}}, - {4, {0x61, 0x98, 0x63, 0x64}}, - {4, {0x61, 0x99, 0x63, 0x64}}, - {4, {0x61, 0x9A, 0x63, 0x64}}, - {4, {0x61, 0x9B, 0x63, 0x64}}, - {4, {0x61, 0x9C, 0x63, 0x64}}, - {4, {0x61, 0x9D, 0x63, 0x64}}, - {4, {0x61, 0x9E, 0x63, 0x64}}, - {4, {0x61, 0x9F, 0x63, 0x64}}, - {4, {0x61, 0xA0, 0x63, 0x64}}, - {4, {0x61, 0xA1, 0x63, 0x64}}, - {4, {0x61, 0xA2, 0x63, 0x64}}, - {4, {0x61, 0xA3, 0x63, 0x64}}, - {4, {0x61, 0xA4, 0x63, 0x64}}, - {4, {0x61, 0xA5, 0x63, 0x64}}, - {4, {0x61, 0xA6, 0x63, 0x64}}, - {4, {0x61, 0xA7, 0x63, 0x64}}, - {4, {0x61, 0xA8, 0x63, 0x64}}, - {4, {0x61, 0xA9, 0x63, 0x64}}, - {4, {0x61, 0xAA, 0x63, 0x64}}, - {4, {0x61, 0xAB, 0x63, 0x64}}, - {4, {0x61, 0xAC, 0x63, 0x64}}, - {4, {0x61, 0xAD, 0x63, 0x64}}, - {4, {0x61, 0xAE, 0x63, 0x64}}, - {4, {0x61, 0xAF, 0x63, 0x64}}, - {4, {0x61, 0xB0, 0x63, 0x64}}, - {4, {0x61, 0xB1, 0x63, 0x64}}, - {4, {0x61, 0xB2, 0x63, 0x64}}, - {4, {0x61, 0xB3, 0x63, 0x64}}, - {4, {0x61, 0xB4, 0x63, 0x64}}, - {4, {0x61, 0xB5, 0x63, 0x64}}, - {4, {0x61, 0xB6, 0x63, 0x64}}, - {4, {0x61, 0xB7, 0x63, 0x64}}, - {4, {0x61, 0xB8, 0x63, 0x64}}, - {4, {0x61, 0xB9, 0x63, 0x64}}, - {4, {0x61, 0xBA, 0x63, 0x64}}, - {4, {0x61, 0xBB, 0x63, 0x64}}, - {4, {0x61, 0xBC, 0x63, 0x64}}, - {4, {0x61, 0xBD, 0x63, 0x64}}, - {4, {0x61, 0xBE, 0x63, 0x64}}, - {4, {0x61, 0xBF, 0x63, 0x64}}, - {4, {0x61, 0xC0, 0x63, 0x64}}, - {4, {0x61, 0xC1, 0x63, 0x64}}, - {4, {0x61, 0xC2, 0x63, 0x64}}, - {4, {0x61, 0xC3, 0x63, 0x64}}, - {4, {0x61, 0xC4, 0x63, 0x64}}, - {4, {0x61, 0xC5, 0x63, 0x64}}, - {4, {0x61, 0xC6, 0x63, 0x64}}, - {4, {0x61, 0xC7, 0x63, 0x64}}, - {4, {0x61, 0xC8, 0x63, 0x64}}, - {4, {0x61, 0xC9, 0x63, 0x64}}, - {4, {0x61, 0xCA, 0x63, 0x64}}, - {4, {0x61, 0xCB, 0x63, 0x64}}, - {4, {0x61, 0xCC, 0x63, 0x64}}, - {4, {0x61, 0xCD, 0x63, 0x64}}, - {4, {0x61, 0xCE, 0x63, 0x64}}, - {4, {0x61, 0xCF, 0x63, 0x64}}, - {4, {0x61, 0xD0, 0x63, 0x64}}, - {4, {0x61, 0xD1, 0x63, 0x64}}, - {4, {0x61, 0xD2, 0x63, 0x64}}, - {4, {0x61, 0xD3, 0x63, 0x64}}, - {4, {0x61, 0xD4, 0x63, 0x64}}, - {4, {0x61, 0xD5, 0x63, 0x64}}, - {4, {0x61, 0xD6, 0x63, 0x64}}, - {4, {0x61, 0xD7, 0x63, 0x64}}, - {4, {0x61, 0xD8, 0x63, 0x64}}, - {4, {0x61, 0xD9, 0x63, 0x64}}, - {4, {0x61, 0xDA, 0x63, 0x64}}, - {4, {0x61, 0xDB, 0x63, 0x64}}, - {4, {0x61, 0xDC, 0x63, 0x64}}, - {4, {0x61, 0xDD, 0x63, 0x64}}, - {4, {0x61, 0xDE, 0x63, 0x64}}, - {4, {0x61, 0xDF, 0x63, 0x64}}, - {4, {0x61, 0xE0, 0x63, 0x64}}, - {4, {0x61, 0xE1, 0x63, 0x64}}, - {4, {0x61, 0xE2, 0x63, 0x64}}, - {4, {0x61, 0xE3, 0x63, 0x64}}, - {4, {0x61, 0xE4, 0x63, 0x64}}, - {4, {0x61, 0xE5, 0x63, 0x64}}, - {4, {0x61, 0xE6, 0x63, 0x64}}, - {4, {0x61, 0xE7, 0x63, 0x64}}, - {4, {0x61, 0xE8, 0x63, 0x64}}, - {4, {0x61, 0xE9, 0x63, 0x64}}, - {4, {0x61, 0xEA, 0x63, 0x64}}, - {4, {0x61, 0xEB, 0x63, 0x64}}, - {4, {0x61, 0xEC, 0x63, 0x64}}, - {4, {0x61, 0xED, 0x63, 0x64}}, - {4, {0x61, 0xEE, 0x63, 0x64}}, - {4, {0x61, 0xEF, 0x63, 0x64}}, - {4, {0x61, 0xF0, 0x63, 0x64}}, - {4, {0x61, 0xF1, 0x63, 0x64}}, - {4, {0x61, 0xF2, 0x63, 0x64}}, - {4, {0x61, 0xF3, 0x63, 0x64}}, - {4, {0x61, 0xF4, 0x63, 0x64}}, - {4, {0x61, 0xF5, 0x63, 0x64}}, - {4, {0x61, 0xF6, 0x63, 0x64}}, - {4, {0x61, 0xF7, 0x63, 0x64}}, - {4, {0x61, 0xF8, 0x63, 0x64}}, - {4, {0x61, 0xF9, 0x63, 0x64}}, - {4, {0x61, 0xFA, 0x63, 0x64}}, - {4, {0x61, 0xFB, 0x63, 0x64}}, - {4, {0x61, 0xFC, 0x63, 0x64}}, - {4, {0x61, 0xFD, 0x63, 0x64}}, - {4, {0x61, 0xFE, 0x63, 0x64}}, - {4, {0x61, 0xFF, 0x63, 0x64}}, - }; - - struct atom atoms_61_62_0X_64[] = { + {4, {0x61, 0x00, 0x63, 0x64}}, {4, {0x61, 0x01, 0x63, 0x64}}, + {4, {0x61, 0x02, 0x63, 0x64}}, {4, {0x61, 0x03, 0x63, 0x64}}, + {4, {0x61, 0x04, 0x63, 0x64}}, {4, {0x61, 0x05, 0x63, 0x64}}, + {4, {0x61, 0x06, 0x63, 0x64}}, {4, {0x61, 0x07, 0x63, 0x64}}, + {4, {0x61, 0x08, 0x63, 0x64}}, {4, {0x61, 0x09, 0x63, 0x64}}, + {4, {0x61, 0x0A, 0x63, 0x64}}, {4, {0x61, 0x0B, 0x63, 0x64}}, + {4, {0x61, 0x0C, 0x63, 0x64}}, {4, {0x61, 0x0D, 0x63, 0x64}}, + {4, {0x61, 0x0E, 0x63, 0x64}}, {4, {0x61, 0x0F, 0x63, 0x64}}, + {4, {0x61, 0x10, 0x63, 0x64}}, {4, {0x61, 0x11, 0x63, 0x64}}, + {4, {0x61, 0x12, 0x63, 0x64}}, {4, {0x61, 0x13, 0x63, 0x64}}, + {4, {0x61, 0x14, 0x63, 0x64}}, {4, {0x61, 0x15, 0x63, 0x64}}, + {4, {0x61, 0x16, 0x63, 0x64}}, {4, {0x61, 0x17, 0x63, 0x64}}, + {4, {0x61, 0x18, 0x63, 0x64}}, {4, {0x61, 0x19, 0x63, 0x64}}, + {4, {0x61, 0x1A, 0x63, 0x64}}, {4, {0x61, 0x1B, 0x63, 0x64}}, + {4, {0x61, 0x1C, 0x63, 0x64}}, {4, {0x61, 0x1D, 0x63, 0x64}}, + {4, {0x61, 0x1E, 0x63, 0x64}}, {4, {0x61, 0x1F, 0x63, 0x64}}, + {4, {0x61, 0x20, 0x63, 0x64}}, {4, {0x61, 0x21, 0x63, 0x64}}, + {4, {0x61, 0x22, 0x63, 0x64}}, {4, {0x61, 0x23, 0x63, 0x64}}, + {4, {0x61, 0x24, 0x63, 0x64}}, {4, {0x61, 0x25, 0x63, 0x64}}, + {4, {0x61, 0x26, 0x63, 0x64}}, {4, {0x61, 0x27, 0x63, 0x64}}, + {4, {0x61, 0x28, 0x63, 0x64}}, {4, {0x61, 0x29, 0x63, 0x64}}, + {4, {0x61, 0x2A, 0x63, 0x64}}, {4, {0x61, 0x2B, 0x63, 0x64}}, + {4, {0x61, 0x2C, 0x63, 0x64}}, {4, {0x61, 0x2D, 0x63, 0x64}}, + {4, {0x61, 0x2E, 0x63, 0x64}}, {4, {0x61, 0x2F, 0x63, 0x64}}, + {4, {0x61, 0x30, 0x63, 0x64}}, {4, {0x61, 0x31, 0x63, 0x64}}, + {4, {0x61, 0x32, 0x63, 0x64}}, {4, {0x61, 0x33, 0x63, 0x64}}, + {4, {0x61, 0x34, 0x63, 0x64}}, {4, {0x61, 0x35, 0x63, 0x64}}, + {4, {0x61, 0x36, 0x63, 0x64}}, {4, {0x61, 0x37, 0x63, 0x64}}, + {4, {0x61, 0x38, 0x63, 0x64}}, {4, {0x61, 0x39, 0x63, 0x64}}, + {4, {0x61, 0x3A, 0x63, 0x64}}, {4, {0x61, 0x3B, 0x63, 0x64}}, + {4, {0x61, 0x3C, 0x63, 0x64}}, {4, {0x61, 0x3D, 0x63, 0x64}}, + {4, {0x61, 0x3E, 0x63, 0x64}}, {4, {0x61, 0x3F, 0x63, 0x64}}, + {4, {0x61, 0x40, 0x63, 0x64}}, {4, {0x61, 0x41, 0x63, 0x64}}, + {4, {0x61, 0x42, 0x63, 0x64}}, {4, {0x61, 0x43, 0x63, 0x64}}, + {4, {0x61, 0x44, 0x63, 0x64}}, {4, {0x61, 0x45, 0x63, 0x64}}, + {4, {0x61, 0x46, 0x63, 0x64}}, {4, {0x61, 0x47, 0x63, 0x64}}, + {4, {0x61, 0x48, 0x63, 0x64}}, {4, {0x61, 0x49, 0x63, 0x64}}, + {4, {0x61, 0x4A, 0x63, 0x64}}, {4, {0x61, 0x4B, 0x63, 0x64}}, + {4, {0x61, 0x4C, 0x63, 0x64}}, {4, {0x61, 0x4D, 0x63, 0x64}}, + {4, {0x61, 0x4E, 0x63, 0x64}}, {4, {0x61, 0x4F, 0x63, 0x64}}, + {4, {0x61, 0x50, 0x63, 0x64}}, {4, {0x61, 0x51, 0x63, 0x64}}, + {4, {0x61, 0x52, 0x63, 0x64}}, {4, {0x61, 0x53, 0x63, 0x64}}, + {4, {0x61, 0x54, 0x63, 0x64}}, {4, {0x61, 0x55, 0x63, 0x64}}, + {4, {0x61, 0x56, 0x63, 0x64}}, {4, {0x61, 0x57, 0x63, 0x64}}, + {4, {0x61, 0x58, 0x63, 0x64}}, {4, {0x61, 0x59, 0x63, 0x64}}, + {4, {0x61, 0x5A, 0x63, 0x64}}, {4, {0x61, 0x5B, 0x63, 0x64}}, + {4, {0x61, 0x5C, 0x63, 0x64}}, {4, {0x61, 0x5D, 0x63, 0x64}}, + {4, {0x61, 0x5E, 0x63, 0x64}}, {4, {0x61, 0x5F, 0x63, 0x64}}, + {4, {0x61, 0x60, 0x63, 0x64}}, {4, {0x61, 0x61, 0x63, 0x64}}, + {4, {0x61, 0x62, 0x63, 0x64}}, {4, {0x61, 0x63, 0x63, 0x64}}, + {4, {0x61, 0x64, 0x63, 0x64}}, {4, {0x61, 0x65, 0x63, 0x64}}, + {4, {0x61, 0x66, 0x63, 0x64}}, {4, {0x61, 0x67, 0x63, 0x64}}, + {4, {0x61, 0x68, 0x63, 0x64}}, {4, {0x61, 0x69, 0x63, 0x64}}, + {4, {0x61, 0x6A, 0x63, 0x64}}, {4, {0x61, 0x6B, 0x63, 0x64}}, + {4, {0x61, 0x6C, 0x63, 0x64}}, {4, {0x61, 0x6D, 0x63, 0x64}}, + {4, {0x61, 0x6E, 0x63, 0x64}}, {4, {0x61, 0x6F, 0x63, 0x64}}, + {4, {0x61, 0x70, 0x63, 0x64}}, {4, {0x61, 0x71, 0x63, 0x64}}, + {4, {0x61, 0x72, 0x63, 0x64}}, {4, {0x61, 0x73, 0x63, 0x64}}, + {4, {0x61, 0x74, 0x63, 0x64}}, {4, {0x61, 0x75, 0x63, 0x64}}, + {4, {0x61, 0x76, 0x63, 0x64}}, {4, {0x61, 0x77, 0x63, 0x64}}, + {4, {0x61, 0x78, 0x63, 0x64}}, {4, {0x61, 0x79, 0x63, 0x64}}, + {4, {0x61, 0x7A, 0x63, 0x64}}, {4, {0x61, 0x7B, 0x63, 0x64}}, + {4, {0x61, 0x7C, 0x63, 0x64}}, {4, {0x61, 0x7D, 0x63, 0x64}}, + {4, {0x61, 0x7E, 0x63, 0x64}}, {4, {0x61, 0x7F, 0x63, 0x64}}, + {4, {0x61, 0x80, 0x63, 0x64}}, {4, {0x61, 0x81, 0x63, 0x64}}, + {4, {0x61, 0x82, 0x63, 0x64}}, {4, {0x61, 0x83, 0x63, 0x64}}, + {4, {0x61, 0x84, 0x63, 0x64}}, {4, {0x61, 0x85, 0x63, 0x64}}, + {4, {0x61, 0x86, 0x63, 0x64}}, {4, {0x61, 0x87, 0x63, 0x64}}, + {4, {0x61, 0x88, 0x63, 0x64}}, {4, {0x61, 0x89, 0x63, 0x64}}, + {4, {0x61, 0x8A, 0x63, 0x64}}, {4, {0x61, 0x8B, 0x63, 0x64}}, + {4, {0x61, 0x8C, 0x63, 0x64}}, {4, {0x61, 0x8D, 0x63, 0x64}}, + {4, {0x61, 0x8E, 0x63, 0x64}}, {4, {0x61, 0x8F, 0x63, 0x64}}, + {4, {0x61, 0x90, 0x63, 0x64}}, {4, {0x61, 0x91, 0x63, 0x64}}, + {4, {0x61, 0x92, 0x63, 0x64}}, {4, {0x61, 0x93, 0x63, 0x64}}, + {4, {0x61, 0x94, 0x63, 0x64}}, {4, {0x61, 0x95, 0x63, 0x64}}, + {4, {0x61, 0x96, 0x63, 0x64}}, {4, {0x61, 0x97, 0x63, 0x64}}, + {4, {0x61, 0x98, 0x63, 0x64}}, {4, {0x61, 0x99, 0x63, 0x64}}, + {4, {0x61, 0x9A, 0x63, 0x64}}, {4, {0x61, 0x9B, 0x63, 0x64}}, + {4, {0x61, 0x9C, 0x63, 0x64}}, {4, {0x61, 0x9D, 0x63, 0x64}}, + {4, {0x61, 0x9E, 0x63, 0x64}}, {4, {0x61, 0x9F, 0x63, 0x64}}, + {4, {0x61, 0xA0, 0x63, 0x64}}, {4, {0x61, 0xA1, 0x63, 0x64}}, + {4, {0x61, 0xA2, 0x63, 0x64}}, {4, {0x61, 0xA3, 0x63, 0x64}}, + {4, {0x61, 0xA4, 0x63, 0x64}}, {4, {0x61, 0xA5, 0x63, 0x64}}, + {4, {0x61, 0xA6, 0x63, 0x64}}, {4, {0x61, 0xA7, 0x63, 0x64}}, + {4, {0x61, 0xA8, 0x63, 0x64}}, {4, {0x61, 0xA9, 0x63, 0x64}}, + {4, {0x61, 0xAA, 0x63, 0x64}}, {4, {0x61, 0xAB, 0x63, 0x64}}, + {4, {0x61, 0xAC, 0x63, 0x64}}, {4, {0x61, 0xAD, 0x63, 0x64}}, + {4, {0x61, 0xAE, 0x63, 0x64}}, {4, {0x61, 0xAF, 0x63, 0x64}}, + {4, {0x61, 0xB0, 0x63, 0x64}}, {4, {0x61, 0xB1, 0x63, 0x64}}, + {4, {0x61, 0xB2, 0x63, 0x64}}, {4, {0x61, 0xB3, 0x63, 0x64}}, + {4, {0x61, 0xB4, 0x63, 0x64}}, {4, {0x61, 0xB5, 0x63, 0x64}}, + {4, {0x61, 0xB6, 0x63, 0x64}}, {4, {0x61, 0xB7, 0x63, 0x64}}, + {4, {0x61, 0xB8, 0x63, 0x64}}, {4, {0x61, 0xB9, 0x63, 0x64}}, + {4, {0x61, 0xBA, 0x63, 0x64}}, {4, {0x61, 0xBB, 0x63, 0x64}}, + {4, {0x61, 0xBC, 0x63, 0x64}}, {4, {0x61, 0xBD, 0x63, 0x64}}, + {4, {0x61, 0xBE, 0x63, 0x64}}, {4, {0x61, 0xBF, 0x63, 0x64}}, + {4, {0x61, 0xC0, 0x63, 0x64}}, {4, {0x61, 0xC1, 0x63, 0x64}}, + {4, {0x61, 0xC2, 0x63, 0x64}}, {4, {0x61, 0xC3, 0x63, 0x64}}, + {4, {0x61, 0xC4, 0x63, 0x64}}, {4, {0x61, 0xC5, 0x63, 0x64}}, + {4, {0x61, 0xC6, 0x63, 0x64}}, {4, {0x61, 0xC7, 0x63, 0x64}}, + {4, {0x61, 0xC8, 0x63, 0x64}}, {4, {0x61, 0xC9, 0x63, 0x64}}, + {4, {0x61, 0xCA, 0x63, 0x64}}, {4, {0x61, 0xCB, 0x63, 0x64}}, + {4, {0x61, 0xCC, 0x63, 0x64}}, {4, {0x61, 0xCD, 0x63, 0x64}}, + {4, {0x61, 0xCE, 0x63, 0x64}}, {4, {0x61, 0xCF, 0x63, 0x64}}, + {4, {0x61, 0xD0, 0x63, 0x64}}, {4, {0x61, 0xD1, 0x63, 0x64}}, + {4, {0x61, 0xD2, 0x63, 0x64}}, {4, {0x61, 0xD3, 0x63, 0x64}}, + {4, {0x61, 0xD4, 0x63, 0x64}}, {4, {0x61, 0xD5, 0x63, 0x64}}, + {4, {0x61, 0xD6, 0x63, 0x64}}, {4, {0x61, 0xD7, 0x63, 0x64}}, + {4, {0x61, 0xD8, 0x63, 0x64}}, {4, {0x61, 0xD9, 0x63, 0x64}}, + {4, {0x61, 0xDA, 0x63, 0x64}}, {4, {0x61, 0xDB, 0x63, 0x64}}, + {4, {0x61, 0xDC, 0x63, 0x64}}, {4, {0x61, 0xDD, 0x63, 0x64}}, + {4, {0x61, 0xDE, 0x63, 0x64}}, {4, {0x61, 0xDF, 0x63, 0x64}}, + {4, {0x61, 0xE0, 0x63, 0x64}}, {4, {0x61, 0xE1, 0x63, 0x64}}, + {4, {0x61, 0xE2, 0x63, 0x64}}, {4, {0x61, 0xE3, 0x63, 0x64}}, + {4, {0x61, 0xE4, 0x63, 0x64}}, {4, {0x61, 0xE5, 0x63, 0x64}}, + {4, {0x61, 0xE6, 0x63, 0x64}}, {4, {0x61, 0xE7, 0x63, 0x64}}, + {4, {0x61, 0xE8, 0x63, 0x64}}, {4, {0x61, 0xE9, 0x63, 0x64}}, + {4, {0x61, 0xEA, 0x63, 0x64}}, {4, {0x61, 0xEB, 0x63, 0x64}}, + {4, {0x61, 0xEC, 0x63, 0x64}}, {4, {0x61, 0xED, 0x63, 0x64}}, + {4, {0x61, 0xEE, 0x63, 0x64}}, {4, {0x61, 0xEF, 0x63, 0x64}}, + {4, {0x61, 0xF0, 0x63, 0x64}}, {4, {0x61, 0xF1, 0x63, 0x64}}, + {4, {0x61, 0xF2, 0x63, 0x64}}, {4, {0x61, 0xF3, 0x63, 0x64}}, + {4, {0x61, 0xF4, 0x63, 0x64}}, {4, {0x61, 0xF5, 0x63, 0x64}}, + {4, {0x61, 0xF6, 0x63, 0x64}}, {4, {0x61, 0xF7, 0x63, 0x64}}, + {4, {0x61, 0xF8, 0x63, 0x64}}, {4, {0x61, 0xF9, 0x63, 0x64}}, + {4, {0x61, 0xFA, 0x63, 0x64}}, {4, {0x61, 0xFB, 0x63, 0x64}}, + {4, {0x61, 0xFC, 0x63, 0x64}}, {4, {0x61, 0xFD, 0x63, 0x64}}, + {4, {0x61, 0xFE, 0x63, 0x64}}, {4, {0x61, 0xFF, 0x63, 0x64}}, + }; + + struct atom atoms_61_62_0X_64[] = { {4, {0x61, 0x62, 0x00, 0x64}}, {4, {0x61, 0x62, 0x01, 0x64}}, {4, {0x61, 0x62, 0x02, 0x64}}, @@ -486,9 +342,9 @@ void test_atom_choose() {4, {0x61, 0x62, 0x0D, 0x64}}, {4, {0x61, 0x62, 0x0E, 0x64}}, {4, {0x61, 0x62, 0x0F, 0x64}}, - }; + }; - struct atom atoms_61_6X_63[] = { + struct atom atoms_61_6X_63[] = { {3, {0x61, 0x60, 0x63}}, {3, {0x61, 0x61, 0x63}}, {3, {0x61, 0x62, 0x63}}, @@ -505,74 +361,116 @@ void test_atom_choose() {3, {0x61, 0x6D, 0x63}}, {3, {0x61, 0x6E, 0x63}}, {3, {0x61, 0x6F, 0x63}}, - }; - - assert_re_atoms("abcd", 1, (struct atom[]) { - {4, {0x61, 0x62, 0x63, 0x64}}, - }); - - assert_re_atoms("abcd1234", 1, (struct atom[]) { - {4, {0x31, 0x32, 0x33, 0x34}}, - }); - - assert_re_atoms("a..d", 1, (struct atom[]) { - {1, {0x61}}, - }); - - assert_re_atoms("a..de", 1, (struct atom[]) { - {2, {0x64, 0x65}}, - }); - - assert_re_atoms("abcd.efgh", 1, (struct atom[]) { - {4, {0x61, 0x62, 0x63, 0x64}}, - }); - - assert_re_atoms("(abcd|efgh)", 2, (struct atom[]) { - {4, {0x65, 0x66, 0x67, 0x68}}, - {4, {0x61, 0x62, 0x63, 0x64}}, - }); - - assert_re_atoms("(abcd|efgh|ij)", 3, (struct atom[]) { - {2, {0x69, 0x6A}}, - {4, {0x65, 0x66, 0x67, 0x68}}, - {4, {0x61, 0x62, 0x63, 0x64}}, - }); - - assert_re_atoms("a.cd", 256, atoms_61_XX_63_64); - - assert_hex_atoms("{61 62 63 64}", 1, (struct atom[]) { - {4, {0x61, 0x62, 0x63, 0x64}}, - }); - - assert_hex_atoms("{61 62 63 64 [1-5] 65 66 67 68}", 1, (struct atom[]) { - {4, {0x61, 0x62, 0x63, 0x64}}, - }); - - assert_hex_atoms("{61 62 63 [1-5] 65 66 67 68}", 1, (struct atom[]) { - {4, {0x65, 0x66, 0x67, 0x68}}, - }); - - assert_hex_atoms("{61 62 63 [1-5] 65 66 }", 1, (struct atom[]) { - {3, {0x61, 0x62, 0x63}}, - }); - - assert_hex_atoms("{61 6? 63 [1-5] 65 66 }", 16, atoms_61_6X_63); - - assert_hex_atoms("{(61 62 63 | 65 66 67 68)}", 2, (struct atom[]) { - {4, {0x65, 0x66, 0x67, 0x68}}, - {3, {0x61, 0x62, 0x63}}, - }); - - assert_hex_atoms("{61 62 0? 64}", 16, atoms_61_62_0X_64); - - assert_hex_atoms("{11 ?? 11 ?? 22 33 44 55 66 }", 1, (struct atom[]) { - {4, {0x22, 0x33, 0x44, 0x55}}, - }); + }; - // Test case for issue #1025 - assert_hex_atoms("{?? 11 22 33 ?? 55 66 }", 1, (struct atom[]) { - {3, {0x11, 0x22, 0x33}}, - }); + assert_re_atoms( + "abcd", + 1, + (struct atom[]){ + {4, {0x61, 0x62, 0x63, 0x64}}, + }); + + assert_re_atoms( + "abcd1234", + 1, + (struct atom[]){ + {4, {0x31, 0x32, 0x33, 0x34}}, + }); + + assert_re_atoms( + "a..d", + 1, + (struct atom[]){ + {1, {0x61}}, + }); + + assert_re_atoms( + "a..de", + 1, + (struct atom[]){ + {2, {0x64, 0x65}}, + }); + + assert_re_atoms( + "abcd.efgh", + 1, + (struct atom[]){ + {4, {0x61, 0x62, 0x63, 0x64}}, + }); + + assert_re_atoms( + "(abcd|efgh)", + 2, + (struct atom[]){ + {4, {0x65, 0x66, 0x67, 0x68}}, + {4, {0x61, 0x62, 0x63, 0x64}}, + }); + + assert_re_atoms( + "(abcd|efgh|ij)", + 3, + (struct atom[]){ + {2, {0x69, 0x6A}}, + {4, {0x65, 0x66, 0x67, 0x68}}, + {4, {0x61, 0x62, 0x63, 0x64}}, + }); + + assert_re_atoms("a.cd", 256, atoms_61_XX_63_64); + + assert_hex_atoms( + "{61 62 63 64}", + 1, + (struct atom[]){ + {4, {0x61, 0x62, 0x63, 0x64}}, + }); + + assert_hex_atoms( + "{61 62 63 64 [1-5] 65 66 67 68}", + 1, + (struct atom[]){ + {4, {0x61, 0x62, 0x63, 0x64}}, + }); + + assert_hex_atoms( + "{61 62 63 [1-5] 65 66 67 68}", + 1, + (struct atom[]){ + {4, {0x65, 0x66, 0x67, 0x68}}, + }); + + assert_hex_atoms( + "{61 62 63 [1-5] 65 66 }", + 1, + (struct atom[]){ + {3, {0x61, 0x62, 0x63}}, + }); + + assert_hex_atoms("{61 6? 63 [1-5] 65 66 }", 16, atoms_61_6X_63); + + assert_hex_atoms( + "{(61 62 63 | 65 66 67 68)}", + 2, + (struct atom[]){ + {4, {0x65, 0x66, 0x67, 0x68}}, + {3, {0x61, 0x62, 0x63}}, + }); + + assert_hex_atoms("{61 62 0? 64}", 16, atoms_61_62_0X_64); + + assert_hex_atoms( + "{11 ?? 11 ?? 22 33 44 55 66 }", + 1, + (struct atom[]){ + {4, {0x22, 0x33, 0x44, 0x55}}, + }); + + // Test case for issue #1025 + assert_hex_atoms( + "{?? 11 22 33 ?? 55 66 }", + 1, + (struct atom[]){ + {3, {0x11, 0x22, 0x33}}, + }); } diff --git a/tests/test-bitmask.c b/tests/test-bitmask.c index f721369aa9..d4e324a093 100644 --- a/tests/test-bitmask.c +++ b/tests/test-bitmask.c @@ -28,8 +28,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include + #include "util.h" #define BITMAP_SIZE 512 @@ -65,12 +66,12 @@ void test_set_clear() if (yr_bitmask_is_set(bitmask, 0)) exit(EXIT_FAILURE); - yr_bitmask_set(bitmask, BITMAP_SIZE-1); + yr_bitmask_set(bitmask, BITMAP_SIZE - 1); if (yr_bitmask_is_not_set(bitmask, BITMAP_SIZE - 1)) exit(EXIT_FAILURE); - yr_bitmask_clear(bitmask, BITMAP_SIZE-1); + yr_bitmask_clear(bitmask, BITMAP_SIZE - 1); if (yr_bitmask_is_set(bitmask, BITMAP_SIZE - 1)) exit(EXIT_FAILURE); diff --git a/tests/test-dex.c b/tests/test-dex.c index 9b51e302ff..64296d879e 100644 --- a/tests/test-dex.c +++ b/tests/test-dex.c @@ -1,6 +1,7 @@ #include -#include "util.h" + #include "blob.h" +#include "util.h" int main(int argc, char** argv) { diff --git a/tests/test-dotnet.c b/tests/test-dotnet.c index dbb3421486..ad1351d00d 100644 --- a/tests/test-dotnet.c +++ b/tests/test-dotnet.c @@ -1,7 +1,8 @@ -#include #include #include #include +#include + #include "util.h" int main(int argc, char** argv) @@ -16,7 +17,8 @@ int main(int argc, char** argv) condition: \ dotnet.assembly.name == \"hpjsoaputility.Sv.resources\" \ }", - "tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); + "tests/data/" + "0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); assert_true_rule_file( "import \"dotnet\" \ @@ -27,7 +29,8 @@ int main(int argc, char** argv) dotnet.resources[0].length == 180 and \ dotnet.resources[0].name == \"hpjsoaputility.XmlStreamSoapExtension.pt.resources\" \ }", - "tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); + "tests/data/" + "0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); assert_true_rule_file( "import \"dotnet\" \ @@ -36,7 +39,8 @@ int main(int argc, char** argv) dotnet.number_of_guids == 1 and \ dotnet.guids[0] == \"3764d539-e21a-4366-bc7c-b56fa67efbb0\" \ }", - "tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); + "tests/data/" + "0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); assert_true_rule_file( "import \"dotnet\" \ @@ -49,7 +53,8 @@ int main(int argc, char** argv) dotnet.streams[3].name == \"#GUID\" and \ dotnet.streams[4].name == \"#Blob\" \ }", - "tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); + "tests/data/" + "0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); assert_true_rule_file( "import \"dotnet\" \ @@ -58,7 +63,8 @@ int main(int argc, char** argv) dotnet.module_name == \"hpjsoaputility.Sv.resources.dll\" and \ dotnet.version == \"v2.0.50727\" \ }", - "tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); + "tests/data/" + "0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); assert_true_rule_file( "import \"dotnet\" \ @@ -68,7 +74,8 @@ int main(int argc, char** argv) dotnet.guids[0] == \"cb9aa69f-4951-49d2-98a1-18984dcfdb91\" and \ dotnet.guids[1] == \"00000000-0000-0000-0000-000000000000\" \ }", - "tests/data/33fc70f99be6d2833ae48852d611c8048d0c053ed0b2c626db4dbe902832a08b"); + "tests/data/" + "33fc70f99be6d2833ae48852d611c8048d0c053ed0b2c626db4dbe902832a08b"); assert_true_rule_file( "import \"dotnet\" \ @@ -76,7 +83,8 @@ int main(int argc, char** argv) condition: \ dotnet.user_strings[0] == \"F\\x00r\\x00e\\x00e\\x00D\\x00i\\x00s\\x00c\\x00B\\x00u\\x00r\\x00n\\x00e\\x00r\\x00.\\x00S\\x00t\\x00r\\x00i\\x00n\\x00g\\x00R\\x00e\\x00s\\x00o\\x00u\\x00r\\x00c\\x00e\\x00s\\x00\" \ }", - "tests/data/33fc70f99be6d2833ae48852d611c8048d0c053ed0b2c626db4dbe902832a08b"); + "tests/data/" + "33fc70f99be6d2833ae48852d611c8048d0c053ed0b2c626db4dbe902832a08b"); yr_finalize(); return 0; } diff --git a/tests/test-elf.c b/tests/test-elf.c index df010bccb3..1001c7a24e 100644 --- a/tests/test-elf.c +++ b/tests/test-elf.c @@ -1,34 +1,34 @@ #include -#include "util.h" + #include "blob.h" +#include "util.h" int main(int argc, char** argv) { yr_initialize(); assert_true_rule_blob( - "import \"elf\" rule test { condition: elf.type }", - ELF32_FILE); + "import \"elf\" rule test { condition: elf.type }", ELF32_FILE); assert_true_rule_blob( - "import \"elf\" rule test { condition: elf.type }", - ELF64_FILE); + "import \"elf\" rule test { condition: elf.type }", ELF64_FILE); assert_true_rule_blob( "import \"elf\" rule test { condition: elf.machine == elf.EM_386 }", ELF32_FILE) - assert_true_rule_blob( - "import \"elf\" rule test { condition: elf.machine == elf.EM_X86_64 }", - ELF64_FILE) + assert_true_rule_blob( + "import \"elf\" rule test { condition: elf.machine == elf.EM_X86_64 " + "}", + ELF64_FILE) - assert_true_rule_blob( - "import \"elf\" \ + assert_true_rule_blob( + "import \"elf\" \ rule test { \ strings: $a = { b8 01 00 00 00 bb 2a } \ condition: $a at elf.entry_point \ }", - ELF32_FILE); + ELF32_FILE); assert_true_rule_blob( "import \"elf\" \ @@ -197,7 +197,7 @@ int main(int argc, char** argv) elf.symtab[i].value == 0x400400 and \ elf.symtab[i].name == \"main\") \ }", - ELF_x64_FILE); + ELF_x64_FILE); assert_true_rule_blob( "import \"elf\" \ @@ -218,7 +218,7 @@ int main(int argc, char** argv) elf.dynamic[13].type == elf.DT_PLTGOT and \ elf.dynamic[13].val == 0x601000 \ }", - ELF_x64_FILE); + ELF_x64_FILE); assert_true_rule_blob( "import \"elf\" \ diff --git a/tests/test-exception.c b/tests/test-exception.c index edf9662864..c3c4d7743f 100644 --- a/tests/test-exception.c +++ b/tests/test-exception.c @@ -27,20 +27,20 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include -#include #include #include -#include - +#include #include + #include "util.h" #define COUNT 128 char wbuf[1024]; -extern char **environ; +extern char** environ; int fd; uint8_t* mapped_region; @@ -87,24 +87,24 @@ void setup_rules() yr_initialize(); compile_rule( - "rule test { strings: $a = \"aaaa\" condition: all of them }", - &rules_a); + "rule test { strings: $a = \"aaaa\" condition: all of them }", &rules_a); compile_rule( "rule test { strings: $a = { 00 00 00 00 } condition: all of them }", &rules_0); } -void* crasher_func (void* x) +void* crasher_func(void* x) { sleep(1); - int *i = 0; + int* i = 0; puts("crashing process..."); *i = 0; return NULL; } -/* Set up a thread that will cause a null pointer dereference after one second */ +/* Set up a thread that will cause a null pointer dereference after one second + */ void setup_crasher() { pthread_t t; @@ -129,7 +129,8 @@ int delay_callback( return CALLBACK_CONTINUE; } -/* Scan a partially backed memory map, raising an exceptions, usually SIGBUS or SIGSEGV. */ +/* Scan a partially backed memory map, raising an exceptions, usually SIGBUS or + * SIGSEGV. */ int test_crash(int handle_exceptions) { setup_mmap(); @@ -187,7 +188,8 @@ int test_crash_other_thread() This tests that SIGUSR1 is not delivered when setting up SIGBUS signal handling -- or during SIGBUS signal handling */ -int test_blocked_signal() { +int test_blocked_signal() +{ setup_mmap(); setup_rules(); @@ -217,12 +219,12 @@ int test_blocked_signal() { return 0; } -int reexec(char *program) +int reexec(char* program) { - char *argv[] = { program, NULL }; + char* argv[] = {program, NULL}; int status; int pid = fork(); - switch(pid) + switch (pid) { case 0: return execve(program, argv, environ); @@ -233,9 +235,9 @@ int reexec(char *program) return status; } -int main(int argc, char **argv) +int main(int argc, char** argv) { - char *op = getenv("TEST_OP"); + char* op = getenv("TEST_OP"); if (op == NULL) { int status; diff --git a/tests/test-macho.c b/tests/test-macho.c index a1de596861..2cefeafc20 100644 --- a/tests/test-macho.c +++ b/tests/test-macho.c @@ -1,8 +1,9 @@ -#include #include #include -#include "util.h" +#include + #include "blob.h" +#include "util.h" int main(int argc, char** argv) { @@ -12,78 +13,109 @@ int main(int argc, char** argv) // Tests for executable files - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.cputype == macho.CPU_TYPE_X86 }", MACHO_X86_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.filetype == macho.MH_EXECUTE }", MACHO_X86_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.flags & macho.MH_PIE }", MACHO_X86_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.cputype == macho.CPU_TYPE_X86 }", + MACHO_X86_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.filetype == macho.MH_EXECUTE }", + MACHO_X86_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.flags & macho.MH_PIE }", + MACHO_X86_FILE); // Segments - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.number_of_segments == 4 }", MACHO_X86_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.number_of_segments == 4 }", + MACHO_X86_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.segments[0].segname == \"__PAGEZERO\" and \ macho.segments[1].segname == \"__TEXT\" and \ macho.segments[2].segname == \"__DATA\" and \ - macho.segments[3].segname == \"__LINKEDIT\" }", MACHO_X86_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ + macho.segments[3].segname == \"__LINKEDIT\" }", + MACHO_X86_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.segments[0].vmaddr == 0 and \ macho.segments[0].vmsize == 0x1000 and \ macho.segments[2].nsects == 2 and \ - macho.segments[3].fsize == 0x118 }", MACHO_X86_FILE); - assert_true_rule_file("import \"macho\" rule test { condition: \ - macho.number_of_segments == 1 }", "tests/data/tiny-macho"); + macho.segments[3].fsize == 0x118 }", + MACHO_X86_FILE); + assert_true_rule_file( + "import \"macho\" rule test { condition: \ + macho.number_of_segments == 1 }", + "tests/data/tiny-macho"); // Sections - assert_true_rule_blob("import \"macho\" rule test { condition: \ + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.segments[1].sections[0].addr == 0x1e90 and \ macho.segments[1].sections[0].size == 0xa6 and \ - macho.segments[1].sections[0].offset == 0x0e90 }", MACHO_X86_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ + macho.segments[1].sections[0].offset == 0x0e90 }", + MACHO_X86_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.segments[1].sections[0].sectname == \"__text\" and \ - macho.segments[1].sections[0].segname == \"__TEXT\" }", MACHO_X86_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ + macho.segments[1].sections[0].segname == \"__TEXT\" }", + MACHO_X86_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.segments[1].sections[1].sectname == \"__symbol_stub\" and \ macho.segments[1].sections[2].sectname == \"__stub_helper\" and \ macho.segments[1].sections[3].sectname == \"__cstring\" and \ macho.segments[1].sections[4].sectname == \"__unwind_info\" and \ macho.segments[2].sections[0].sectname == \"__nl_symbol_ptr\" and \ macho.segments[2].sections[1].sectname == \"__la_symbol_ptr\" }", - MACHO_X86_FILE); + MACHO_X86_FILE); // Entry point (LC_MAIN) - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.entry_point == 0xe90 }", MACHO_X86_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.entry_point == 0xe90 }", + MACHO_X86_FILE); // Tests for object files - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.cputype == macho.CPU_TYPE_X86 }", MACHO_X86_OBJECT_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.filetype == macho.MH_OBJECT }", MACHO_X86_OBJECT_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.cputype == macho.CPU_TYPE_X86 }", + MACHO_X86_OBJECT_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.filetype == macho.MH_OBJECT }", + MACHO_X86_OBJECT_FILE); // Segments and sections - assert_true_rule_blob("import \"macho\" rule test { condition: \ + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.number_of_segments == 1 and macho.segments[0].segname == \"\" and \ macho.segments[0].sections[0].sectname == \"__text\" and \ macho.segments[0].sections[0].segname == \"__TEXT\" }", - MACHO_X86_OBJECT_FILE); + MACHO_X86_OBJECT_FILE); // Tests for big-endian byte order - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.cputype == macho.CPU_TYPE_POWERPC }", MACHO_PPC_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.filetype == macho.MH_EXECUTE }", MACHO_PPC_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.cputype == macho.CPU_TYPE_POWERPC }", + MACHO_PPC_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.filetype == macho.MH_EXECUTE }", + MACHO_PPC_FILE); // Segments - assert_true_rule_blob("import \"macho\" rule test { condition: \ + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.number_of_segments == 4 and \ macho.segments[0].segname == \"__PAGEZERO\" and \ macho.segments[2].segname == \"__DATA\" and \ @@ -91,107 +123,140 @@ int main(int argc, char** argv) macho.segments[0].vmaddr == 0 and \ macho.segments[0].vmsize == 0x1000 and \ macho.segments[3].fileoff == 65536 and \ - macho.segments[3].fsize == 46032 }", MACHO_PPC_FILE); + macho.segments[3].fsize == 46032 }", + MACHO_PPC_FILE); // Entry point (LC_UNIXTHREAD) - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.entry_point == 0xeb8 }", MACHO_PPC_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.entry_point == 0xeb8 }", + MACHO_PPC_FILE); // Tests for 64-bit and shared library files - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.cputype == macho.CPU_TYPE_X86_64 }", MACHO_X86_64_DYLIB_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.filetype == macho.MH_DYLIB }", MACHO_X86_64_DYLIB_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.cputype == macho.CPU_TYPE_X86_64 }", + MACHO_X86_64_DYLIB_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.filetype == macho.MH_DYLIB }", + MACHO_X86_64_DYLIB_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.flags & macho.MH_DYLDLINK and \ macho.flags & macho.MH_NOUNDEFS and \ macho.flags & macho.MH_NO_REEXPORTED_DYLIBS and \ - macho.flags & macho.MH_TWOLEVEL }", MACHO_X86_64_DYLIB_FILE); + macho.flags & macho.MH_TWOLEVEL }", + MACHO_X86_64_DYLIB_FILE); // Segments and sections - assert_true_rule_blob("import \"macho\" rule test { condition: \ - macho.number_of_segments == 2 }", MACHO_X86_64_DYLIB_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ + macho.number_of_segments == 2 }", + MACHO_X86_64_DYLIB_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.segments[0].segname == \"__TEXT\" and \ - macho.segments[1].segname == \"__LINKEDIT\" }", MACHO_X86_64_DYLIB_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ + macho.segments[1].segname == \"__LINKEDIT\" }", + MACHO_X86_64_DYLIB_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.segments[1].vmaddr == 0x0000000000001000 and \ macho.segments[1].vmsize == 0x0000000000001000 and \ macho.segments[1].nsects == 0 and \ - macho.segments[1].fsize == 128 }", MACHO_X86_64_DYLIB_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ + macho.segments[1].fsize == 128 }", + MACHO_X86_64_DYLIB_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.segments[0].sections[0].sectname == \"__text\" and \ macho.segments[0].sections[0].segname == \"__TEXT\" }", - MACHO_X86_64_DYLIB_FILE); - assert_true_rule_blob("import \"macho\" rule test { condition: \ + MACHO_X86_64_DYLIB_FILE); + assert_true_rule_blob( + "import \"macho\" rule test { condition: \ macho.segments[0].sections[1].addr == 0x0000000000000f98 and \ macho.segments[0].sections[1].size == 0x0000000000000048 and \ - macho.segments[0].sections[1].offset == 3992 }", MACHO_X86_64_DYLIB_FILE); + macho.segments[0].sections[1].offset == 3992 }", + MACHO_X86_64_DYLIB_FILE); // Mach-O Universal Binaries tests - assert_true_rule_file("import \"macho\" rule test { condition: \ + assert_true_rule_file( + "import \"macho\" rule test { condition: \ macho.fat_magic == macho.FAT_MAGIC and macho.nfat_arch == 2 }", - "tests/data/tiny-universal"); - assert_true_rule_file("import \"macho\" rule test { condition: \ + "tests/data/tiny-universal"); + assert_true_rule_file( + "import \"macho\" rule test { condition: \ macho.fat_arch[0].cputype == macho.CPU_TYPE_I386 and \ macho.fat_arch[0].cpusubtype == macho.CPU_SUBTYPE_I386_ALL and \ macho.fat_arch[0].offset == 4096 and \ macho.fat_arch[1].cputype == macho.CPU_TYPE_X86_64 and \ macho.fat_arch[1].cpusubtype == macho.CPU_SUBTYPE_X86_64_ALL | \ macho.CPU_SUBTYPE_LIB64 and macho.fat_arch[1].align == 12 }", - "tests/data/tiny-universal"); - assert_true_rule_file("import \"macho\" rule test { condition: \ + "tests/data/tiny-universal"); + assert_true_rule_file( + "import \"macho\" rule test { condition: \ macho.file[0].cputype == macho.fat_arch[0].cputype and \ macho.file[1].cputype == macho.fat_arch[1].cputype }", - "tests/data/tiny-universal"); + "tests/data/tiny-universal"); // Entry points for files (LC_MAIN) - assert_true_rule_file("import \"macho\" rule test { \ + assert_true_rule_file( + "import \"macho\" rule test { \ strings: $1 = { 55 89 e5 56 83 ec 34 } \ condition: $1 at macho.file[0].entry_point + macho.fat_arch[0].offset }", - "tests/data/tiny-universal"); + "tests/data/tiny-universal"); - assert_true_rule_file("import \"macho\" rule test { \ + assert_true_rule_file( + "import \"macho\" rule test { \ strings: $1 = { 55 48 89 e5 48 83 ec 20 } \ condition: $1 at macho.file[1].entry_point + macho.fat_arch[1].offset }", - "tests/data/tiny-universal"); + "tests/data/tiny-universal"); // Helper functions - assert_true_rule_file("import \"macho\" rule test { condition: \ + assert_true_rule_file( + "import \"macho\" rule test { condition: \ macho.file[macho.file_index_for_arch(macho.CPU_TYPE_I386)].entry_point == \ - macho.file[0].entry_point }", "tests/data/tiny-universal"); - assert_true_rule_file("import \"macho\" rule test { condition: \ + macho.file[0].entry_point }", + "tests/data/tiny-universal"); + assert_true_rule_file( + "import \"macho\" rule test { condition: \ macho.file[macho.file_index_for_arch(macho.CPU_TYPE_X86_64)].entry_point == \ - macho.file[1].entry_point }", "tests/data/tiny-universal"); + macho.file[1].entry_point }", + "tests/data/tiny-universal"); - assert_true_rule_file("import \"macho\" rule test { condition: \ + assert_true_rule_file( + "import \"macho\" rule test { condition: \ macho.file[macho.file_index_for_arch(macho.CPU_TYPE_I386, \ macho.CPU_SUBTYPE_I386_ALL)].entry_point == \ - macho.file[0].entry_point }", "tests/data/tiny-universal"); - assert_true_rule_file("import \"macho\" rule test { condition: \ + macho.file[0].entry_point }", + "tests/data/tiny-universal"); + assert_true_rule_file( + "import \"macho\" rule test { condition: \ macho.file[macho.file_index_for_arch(macho.CPU_TYPE_X86_64, \ macho.CPU_SUBTYPE_X86_64_ALL | \ macho.CPU_SUBTYPE_LIB64)].entry_point == \ - macho.file[1].entry_point }", "tests/data/tiny-universal"); + macho.file[1].entry_point }", + "tests/data/tiny-universal"); // Entry point for specific architecture - assert_true_rule_file("import \"macho\" rule test { \ + assert_true_rule_file( + "import \"macho\" rule test { \ strings: $1 = { 55 89 e5 56 83 ec 34 } \ condition: $1 at macho.entry_point_for_arch(macho.CPU_TYPE_I386, \ macho.CPU_SUBTYPE_I386_ALL) }", - "tests/data/tiny-universal"); + "tests/data/tiny-universal"); - assert_true_rule_file("import \"macho\" rule test { \ + assert_true_rule_file( + "import \"macho\" rule test { \ strings: $1 = { 55 48 89 e5 48 83 ec 20 } \ condition: $1 at macho.entry_point_for_arch(macho.CPU_TYPE_X86_64) }", - "tests/data/tiny-universal"); + "tests/data/tiny-universal"); yr_finalize(); return 0; diff --git a/tests/test-math.c b/tests/test-math.c index e2e497b5e4..0b334f1f2c 100644 --- a/tests/test-math.c +++ b/tests/test-math.c @@ -1,5 +1,6 @@ -#include #include +#include + #include "util.h" int main(int argc, char** argv) diff --git a/tests/test-pb.c b/tests/test-pb.c index 631cd53aae..f0b910600f 100644 --- a/tests/test-pb.c +++ b/tests/test-pb.c @@ -28,6 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include + #include "util.h" diff --git a/tests/test-pe.c b/tests/test-pe.c index 3a57188063..4d1b37f7a3 100644 --- a/tests/test-pe.c +++ b/tests/test-pe.c @@ -1,7 +1,8 @@ -#include #include #include #include +#include + #include "util.h" int main(int argc, char** argv) @@ -113,9 +114,8 @@ int main(int argc, char** argv) }", "tests/data/tiny"); - #if defined(HAVE_LIBCRYPTO) || \ - defined(HAVE_WINCRYPT_H) || \ - defined(HAVE_COMMONCRYPTO_COMMONCRYPTO_H) +#if defined(HAVE_LIBCRYPTO) || defined(HAVE_WINCRYPT_H) || \ + defined(HAVE_COMMONCRYPTO_COMMONCRYPTO_H) assert_true_rule_file( "import \"pe\" \ @@ -125,9 +125,9 @@ int main(int argc, char** argv) }", "tests/data/tiny"); - #endif +#endif - #if defined(HAVE_LIBCRYPTO) +#if defined(HAVE_LIBCRYPTO) assert_true_rule_file( "import \"pe\" \ @@ -137,9 +137,10 @@ int main(int argc, char** argv) pe.signatures[0].thumbprint == \"c1bf1b8f751bf97626ed77f755f0a393106f2454\" and \ pe.signatures[0].subject == \"/C=US/ST=California/L=Menlo Park/O=Quicken, Inc./OU=Operations/CN=Quicken, Inc.\" \ }", - "tests/data/079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885"); + "tests/data/" + "079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885"); - #endif +#endif assert_true_rule_file( "import \"pe\" \ @@ -203,7 +204,8 @@ int main(int argc, char** argv) condition: \ pe.pdb_path == \"D:\\\\workspace\\\\2018_R9_RelBld\\\\target\\\\checkout\\\\custprof\\\\Release\\\\custprof.pdb\" \ }", - "tests/data/079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885"); + "tests/data/" + "079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885"); assert_false_rule_file( "import \"pe\" \ @@ -214,12 +216,10 @@ int main(int argc, char** argv) "tests/data/tiny-idata-51ff"); /* - * mtxex.dll is 23e72ce7e9cdbc80c0095484ebeb02f56b21e48fd67044e69e7a2ae76db631e5, - * which was taken from a Windows 10 install. The details of which are: - * export_timestamp = 1827812126 - * dll_name = "mtxex.dll" - * number_of_exports = 4 - * export_details + * mtxex.dll is + * 23e72ce7e9cdbc80c0095484ebeb02f56b21e48fd67044e69e7a2ae76db631e5, which was + * taken from a Windows 10 install. The details of which are: export_timestamp + * = 1827812126 dll_name = "mtxex.dll" number_of_exports = 4 export_details * [0] * offset = 1072 * name = "DllGetClassObject" @@ -299,7 +299,8 @@ int main(int argc, char** argv) condition: \ pe.export_details[0].name == \"CP_PutItem\" \ }", - "tests/data/079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885.upx"); + "tests/data/" + "079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885.upx"); assert_true_rule_file( @@ -311,10 +312,12 @@ int main(int argc, char** argv) pe.rich_signature.version(30319) and \ pe.rich_signature.version(40219, 170) == 11 \ }", - "tests/data/079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885"); + "tests/data/" + "079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885"); // This is the first 840 bytes (just enough to make sure the rich header is - // parsed) of 3593d3d08761d8ddc269dde945c0cb07e5cef5dd46ad9eefc22d17901f542093. + // parsed) of + // 3593d3d08761d8ddc269dde945c0cb07e5cef5dd46ad9eefc22d17901f542093. assert_true_rule_file( "import \"pe\" \ rule test { \ diff --git a/tests/test-re-split.c b/tests/test-re-split.c index b1374f0c7b..881ddfdc62 100644 --- a/tests/test-re-split.c +++ b/tests/test-re-split.c @@ -27,8 +27,9 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include + #include "util.h" @@ -45,12 +46,12 @@ int main(int argc, char** argv) yr_initialize(); yr_re_parse_hex( "{ 01 02 03 04 [0-300] 05 06 07 08 [1-400] 09 0A 0B 0C }", - &re_ast, &re_error); + &re_ast, + &re_error); assert(re_ast != NULL); - yr_re_ast_split_at_chaining_point( - re_ast, &re_ast_remain, &min_gap, &max_gap); + yr_re_ast_split_at_chaining_point(re_ast, &re_ast_remain, &min_gap, &max_gap); assert(re_ast != NULL); assert(re_ast_remain != NULL); @@ -60,8 +61,7 @@ int main(int argc, char** argv) yr_re_ast_destroy(re_ast); re_ast = re_ast_remain; - yr_re_ast_split_at_chaining_point( - re_ast, &re_ast_remain, &min_gap, &max_gap); + yr_re_ast_split_at_chaining_point(re_ast, &re_ast_remain, &min_gap, &max_gap); assert(re_ast != NULL); assert(re_ast_remain != NULL); @@ -71,8 +71,7 @@ int main(int argc, char** argv) yr_re_ast_destroy(re_ast); re_ast = re_ast_remain; - yr_re_ast_split_at_chaining_point( - re_ast, &re_ast_remain, &min_gap, &max_gap); + yr_re_ast_split_at_chaining_point(re_ast, &re_ast_remain, &min_gap, &max_gap); assert(re_ast != NULL); assert(re_ast_remain == NULL); diff --git a/tests/test-rules.c b/tests/test-rules.c index 6f6b738e2b..6d0ff72789 100644 --- a/tests/test-rules.c +++ b/tests/test-rules.c @@ -27,15 +27,14 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include #include #include -#include #include -#include -#include - #include #include + #include "blob.h" #include "util.h" @@ -44,26 +43,19 @@ static void test_boolean_operators() { YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); - assert_true_rule( - "rule test { condition: true }", NULL); + assert_true_rule("rule test { condition: true }", NULL); - assert_true_rule( - "rule test { condition: true or false }", NULL); + assert_true_rule("rule test { condition: true or false }", NULL); - assert_true_rule( - "rule test { condition: true and true }", NULL); + assert_true_rule("rule test { condition: true and true }", NULL); - assert_true_rule( - "rule test { condition: 0x1 and 0x2}", NULL); + assert_true_rule("rule test { condition: 0x1 and 0x2}", NULL); - assert_false_rule( - "rule test { condition: false }", NULL); + assert_false_rule("rule test { condition: false }", NULL); - assert_false_rule( - "rule test { condition: true and false }", NULL); + assert_false_rule("rule test { condition: true and false }", NULL); - assert_false_rule( - "rule test { condition: false or false }", NULL); + assert_false_rule("rule test { condition: false or false }", NULL); } @@ -71,108 +63,73 @@ static void test_comparison_operators() { YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); - assert_true_rule( - "rule test { condition: 2 > 1 }", NULL); - - assert_true_rule( - "rule test { condition: 1 < 2 }", NULL); + assert_true_rule("rule test { condition: 2 > 1 }", NULL); - assert_true_rule( - "rule test { condition: 2 >= 1 }", NULL); + assert_true_rule("rule test { condition: 1 < 2 }", NULL); - assert_true_rule( - "rule test { condition: 1 <= 1 }", NULL); + assert_true_rule("rule test { condition: 2 >= 1 }", NULL); - assert_true_rule( - "rule test { condition: 1 == 1 }", NULL); + assert_true_rule("rule test { condition: 1 <= 1 }", NULL); - assert_true_rule( - "rule test { condition: 1.5 == 1.5}", NULL); + assert_true_rule("rule test { condition: 1 == 1 }", NULL); - assert_true_rule( - "rule test { condition: 1.0 == 1}", NULL); + assert_true_rule("rule test { condition: 1.5 == 1.5}", NULL); - assert_true_rule( - "rule test { condition: 1.5 >= 1.0}", NULL); + assert_true_rule("rule test { condition: 1.0 == 1}", NULL); - assert_true_rule( - "rule test { condition: 1.0 != 1.000000000000001 }", NULL); + assert_true_rule("rule test { condition: 1.5 >= 1.0}", NULL); - assert_true_rule( - "rule test { condition: 1.0 < 1.000000000000001 }", NULL); + assert_true_rule("rule test { condition: 1.0 != 1.000000000000001 }", NULL); - assert_false_rule( - "rule test { condition: 1.0 >= 1.000000000000001 }", NULL); + assert_true_rule("rule test { condition: 1.0 < 1.000000000000001 }", NULL); - assert_true_rule( - "rule test { condition: 1.000000000000001 > 1 }", NULL); + assert_false_rule("rule test { condition: 1.0 >= 1.000000000000001 }", NULL); - assert_false_rule( - "rule test { condition: 1.000000000000001 <= 1 }", NULL); + assert_true_rule("rule test { condition: 1.000000000000001 > 1 }", NULL); - assert_true_rule( - "rule test { condition: 1.0 == 1.0000000000000001 }", NULL); + assert_false_rule("rule test { condition: 1.000000000000001 <= 1 }", NULL); - assert_true_rule( - "rule test { condition: 1.0 >= 1.0000000000000001 }", NULL); + assert_true_rule("rule test { condition: 1.0 == 1.0000000000000001 }", NULL); - assert_true_rule( - "rule test { condition: 1.5 >= 1}", NULL); + assert_true_rule("rule test { condition: 1.0 >= 1.0000000000000001 }", NULL); - assert_true_rule( - "rule test { condition: 1.0 >= 1}", NULL); + assert_true_rule("rule test { condition: 1.5 >= 1}", NULL); - assert_true_rule( - "rule test { condition: 0.5 < 1}", NULL); + assert_true_rule("rule test { condition: 1.0 >= 1}", NULL); - assert_true_rule( - "rule test { condition: 0.5 <= 1}", NULL); + assert_true_rule("rule test { condition: 0.5 < 1}", NULL); - assert_true_rule( - "rule test { condition: 1.0 <= 1}", NULL); + assert_true_rule("rule test { condition: 0.5 <= 1}", NULL); - assert_true_rule( - "rule test { condition: \"abc\" == \"abc\"}", NULL); + assert_true_rule("rule test { condition: 1.0 <= 1}", NULL); - assert_true_rule( - "rule test { condition: \"abc\" <= \"abc\"}", NULL); + assert_true_rule("rule test { condition: \"abc\" == \"abc\"}", NULL); - assert_true_rule( - "rule test { condition: \"abc\" >= \"abc\"}", NULL); + assert_true_rule("rule test { condition: \"abc\" <= \"abc\"}", NULL); - assert_true_rule( - "rule test { condition: \"ab\" < \"abc\"}", NULL); + assert_true_rule("rule test { condition: \"abc\" >= \"abc\"}", NULL); - assert_true_rule( - "rule test { condition: \"abc\" > \"ab\"}", NULL); + assert_true_rule("rule test { condition: \"ab\" < \"abc\"}", NULL); - assert_true_rule( - "rule test { condition: \"abc\" < \"abd\"}", NULL); + assert_true_rule("rule test { condition: \"abc\" > \"ab\"}", NULL); - assert_true_rule( - "rule test { condition: \"abd\" > \"abc\"}", NULL); + assert_true_rule("rule test { condition: \"abc\" < \"abd\"}", NULL); - assert_false_rule( - "rule test { condition: 1 != 1}", NULL); + assert_true_rule("rule test { condition: \"abd\" > \"abc\"}", NULL); - assert_false_rule( - "rule test { condition: 1 != 1.0}", NULL); + assert_false_rule("rule test { condition: 1 != 1}", NULL); - assert_false_rule( - "rule test { condition: 2 > 3}", NULL); + assert_false_rule("rule test { condition: 1 != 1.0}", NULL); - assert_false_rule( - "rule test { condition: 2.1 < 2}", NULL); + assert_false_rule("rule test { condition: 2 > 3}", NULL); - assert_false_rule( - "rule test { condition: \"abc\" != \"abc\"}", NULL); + assert_false_rule("rule test { condition: 2.1 < 2}", NULL); - assert_false_rule( - "rule test { condition: \"abc\" > \"abc\"}", NULL); + assert_false_rule("rule test { condition: \"abc\" != \"abc\"}", NULL); - assert_false_rule( - "rule test { condition: \"abc\" < \"abc\"}", NULL); + assert_false_rule("rule test { condition: \"abc\" > \"abc\"}", NULL); + assert_false_rule("rule test { condition: \"abc\" < \"abc\"}", NULL); } static void test_arithmetic_operators() @@ -182,125 +139,105 @@ static void test_arithmetic_operators() assert_true_rule( "rule test { condition: (1 + 1) * 2 == (9 - 1) \\ 2 }", NULL); - assert_true_rule( - "rule test { condition: 5 % 2 == 1 }", NULL); + assert_true_rule("rule test { condition: 5 % 2 == 1 }", NULL); - assert_true_rule( - "rule test { condition: 1.5 + 1.5 == 3}", NULL); + assert_true_rule("rule test { condition: 1.5 + 1.5 == 3}", NULL); - assert_true_rule( - "rule test { condition: 3 \\ 2 == 1}", NULL); + assert_true_rule("rule test { condition: 3 \\ 2 == 1}", NULL); - assert_true_rule( - "rule test { condition: 3.0 \\ 2 == 1.5}", NULL); + assert_true_rule("rule test { condition: 3.0 \\ 2 == 1.5}", NULL); - assert_true_rule( - "rule test { condition: 1 + -1 == 0}", NULL); + assert_true_rule("rule test { condition: 1 + -1 == 0}", NULL); - assert_true_rule( - "rule test { condition: -1 + -1 == -2}", NULL); + assert_true_rule("rule test { condition: -1 + -1 == -2}", NULL); - assert_true_rule( - "rule test { condition: 4 --2 * 2 == 8}", NULL); + assert_true_rule("rule test { condition: 4 --2 * 2 == 8}", NULL); - assert_true_rule( - "rule test { condition: -1.0 * 1 == -1.0}", NULL); + assert_true_rule("rule test { condition: -1.0 * 1 == -1.0}", NULL); - assert_true_rule( - "rule test { condition: 1-1 == 0}", NULL); + assert_true_rule("rule test { condition: 1-1 == 0}", NULL); - assert_true_rule( - "rule test { condition: -2.0-3.0 == -5}", NULL); + assert_true_rule("rule test { condition: -2.0-3.0 == -5}", NULL); - assert_true_rule( - "rule test { condition: --1 == 1}", NULL); + assert_true_rule("rule test { condition: --1 == 1}", NULL); - assert_true_rule( - "rule test { condition: 1--1 == 2}", NULL); + assert_true_rule("rule test { condition: 1--1 == 2}", NULL); - assert_true_rule( - "rule test { condition: 2 * -2 == -4}", NULL); + assert_true_rule("rule test { condition: 2 * -2 == -4}", NULL); - assert_true_rule( - "rule test { condition: -4 * 2 == -8}", NULL); + assert_true_rule("rule test { condition: -4 * 2 == -8}", NULL); - assert_true_rule( - "rule test { condition: -4 * -4 == 16}", NULL); + assert_true_rule("rule test { condition: -4 * -4 == 16}", NULL); - assert_true_rule( - "rule test { condition: -0x01 == -1}", NULL); + assert_true_rule("rule test { condition: -0x01 == -1}", NULL); - assert_true_rule( - "rule test { condition: 0o10 == 8 }", NULL); + assert_true_rule("rule test { condition: 0o10 == 8 }", NULL); - assert_true_rule( - "rule test { condition: 0o100 == 64 }", NULL); + assert_true_rule("rule test { condition: 0o100 == 64 }", NULL); - assert_true_rule( - "rule test { condition: 0o755 == 493 }", NULL); + assert_true_rule("rule test { condition: 0o755 == 493 }", NULL); // TODO: This should return ERROR_INTEGER_OVERFLOW, but right now it returns - // ERROR_SYNTAX_ERROR because after the lexer aborts with ERROR_INTEGER_OVERFLOW - // the parser finds an unexpected end fails with error: unexpected $end. + // ERROR_SYNTAX_ERROR because after the lexer aborts with + // ERROR_INTEGER_OVERFLOW the parser finds an unexpected end fails with error: + // unexpected $end. assert_error( - "rule test { condition: 9223372036854775808 > 0 }", - ERROR_SYNTAX_ERROR); + "rule test { condition: 9223372036854775808 > 0 }", ERROR_SYNTAX_ERROR); assert_error( - "rule test { condition: 9007199254740992KB > 0 }", - ERROR_SYNTAX_ERROR); + "rule test { condition: 9007199254740992KB > 0 }", ERROR_SYNTAX_ERROR); assert_error( // integer too long "rule test { condition: 8796093022208MB > 0 }", ERROR_SYNTAX_ERROR); assert_error( // integer too long - "rule test { condition: 0x8000000000000000 > 0 }", - ERROR_SYNTAX_ERROR); + "rule test { condition: 0x8000000000000000 > 0 }", + ERROR_SYNTAX_ERROR); assert_error( // integer too long - "rule test { condition: 0o1000000000000000000000 > 0 }", - ERROR_SYNTAX_ERROR); + "rule test { condition: 0o1000000000000000000000 > 0 }", + ERROR_SYNTAX_ERROR); assert_error( - "rule test { condition: 0x7FFFFFFFFFFFFFFF + 1 > 0 }", - ERROR_INTEGER_OVERFLOW); + "rule test { condition: 0x7FFFFFFFFFFFFFFF + 1 > 0 }", + ERROR_INTEGER_OVERFLOW); assert_error( - "rule test { condition: 9223372036854775807 + 1 > 0 }", - ERROR_INTEGER_OVERFLOW); + "rule test { condition: 9223372036854775807 + 1 > 0 }", + ERROR_INTEGER_OVERFLOW); assert_error( - "rule test { condition: -9223372036854775807 - 2 > 0 }", - ERROR_INTEGER_OVERFLOW); + "rule test { condition: -9223372036854775807 - 2 > 0 }", + ERROR_INTEGER_OVERFLOW); assert_error( - "rule test { condition: -2 + -9223372036854775807 > 0 }", - ERROR_INTEGER_OVERFLOW); + "rule test { condition: -2 + -9223372036854775807 > 0 }", + ERROR_INTEGER_OVERFLOW); assert_error( - "rule test { condition: 1 - -9223372036854775807 > 0 }", - ERROR_INTEGER_OVERFLOW); + "rule test { condition: 1 - -9223372036854775807 > 0 }", + ERROR_INTEGER_OVERFLOW); assert_error( - "rule test { condition: 0x4000000000000000 * 2 }", - ERROR_INTEGER_OVERFLOW); + "rule test { condition: 0x4000000000000000 * 2 }", + ERROR_INTEGER_OVERFLOW); assert_error( - "rule test { condition: 4611686018427387904 * 2 }", - ERROR_INTEGER_OVERFLOW); + "rule test { condition: 4611686018427387904 * 2 }", + ERROR_INTEGER_OVERFLOW); assert_error( - "rule test { condition: 4611686018427387904 * -2 }", - ERROR_INTEGER_OVERFLOW); + "rule test { condition: 4611686018427387904 * -2 }", + ERROR_INTEGER_OVERFLOW); assert_error( - "rule test { condition: -4611686018427387904 * 2 }", - ERROR_INTEGER_OVERFLOW); + "rule test { condition: -4611686018427387904 * 2 }", + ERROR_INTEGER_OVERFLOW); assert_error( - "rule test { condition: -4611686018427387904 * -2 }", - ERROR_INTEGER_OVERFLOW); + "rule test { condition: -4611686018427387904 * -2 }", + ERROR_INTEGER_OVERFLOW); } @@ -308,54 +245,32 @@ static void test_bitwise_operators() { YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); - assert_true_rule( - "rule test { condition: 0x55 | 0xAA == 0xFF }", - NULL); + assert_true_rule("rule test { condition: 0x55 | 0xAA == 0xFF }", NULL); assert_true_rule( "rule test { condition: ~0xAA ^ 0x5A & 0xFF == (~0xAA) ^ (0x5A & 0xFF) }", NULL); - assert_true_rule( - "rule test { condition: ~0x55 & 0xFF == 0xAA }", - NULL); + assert_true_rule("rule test { condition: ~0x55 & 0xFF == 0xAA }", NULL); - assert_true_rule( - "rule test { condition: 8 >> 2 == 2 }", - NULL); - - assert_true_rule( - "rule test { condition: 1 << 3 == 8 }", - NULL); + assert_true_rule("rule test { condition: 8 >> 2 == 2 }", NULL); - assert_true_rule( - "rule test { condition: 1 << 64 == 0 }", - NULL); + assert_true_rule("rule test { condition: 1 << 3 == 8 }", NULL); - assert_true_rule( - "rule test { condition: 1 >> 64 == 0 }", - NULL); + assert_true_rule("rule test { condition: 1 << 64 == 0 }", NULL); - assert_error( - "rule test { condition: 1 << -1 == 0 }", - ERROR_INVALID_OPERAND); + assert_true_rule("rule test { condition: 1 >> 64 == 0 }", NULL); - assert_error( - "rule test { condition: 1 >> -1 == 0 }", - ERROR_INVALID_OPERAND); + assert_error("rule test { condition: 1 << -1 == 0 }", ERROR_INVALID_OPERAND); - assert_true_rule( - "rule test { condition: 1 | 3 ^ 3 == 1 | (3 ^ 3) }", - NULL); + assert_error("rule test { condition: 1 >> -1 == 0 }", ERROR_INVALID_OPERAND); - assert_false_rule( - "rule test { condition: ~0xAA ^ 0x5A & 0xFF == 0x0F }", - NULL); + assert_true_rule("rule test { condition: 1 | 3 ^ 3 == 1 | (3 ^ 3) }", NULL); assert_false_rule( - "rule test { condition: 1 | 3 ^ 3 == (1 | 3) ^ 3}", - NULL); + "rule test { condition: ~0xAA ^ 0x5A & 0xFF == 0x0F }", NULL); + assert_false_rule("rule test { condition: 1 | 3 ^ 3 == (1 | 3) ^ 3}", NULL); } @@ -364,84 +279,63 @@ static void test_string_operators() YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); assert_true_rule( - "rule test { condition: \"foobarbaz\" contains \"bar\" }", - NULL); + "rule test { condition: \"foobarbaz\" contains \"bar\" }", NULL); assert_true_rule( - "rule test { condition: \"foobarbaz\" contains \"foo\" }", - NULL); + "rule test { condition: \"foobarbaz\" contains \"foo\" }", NULL); assert_true_rule( - "rule test { condition: \"foobarbaz\" contains \"baz\" }", - NULL); + "rule test { condition: \"foobarbaz\" contains \"baz\" }", NULL); assert_true_rule( - "rule test { condition: \"foobarbaz\" icontains \"BAR\" }", - NULL); + "rule test { condition: \"foobarbaz\" icontains \"BAR\" }", NULL); assert_true_rule( - "rule test { condition: \"foobarbaz\" icontains \"BaR\" }", - NULL); + "rule test { condition: \"foobarbaz\" icontains \"BaR\" }", NULL); assert_true_rule( - "rule test { condition: \"FooBarBaz\" icontains \"bar\" }", - NULL); + "rule test { condition: \"FooBarBaz\" icontains \"bar\" }", NULL); assert_true_rule( - "rule test { condition: \"FooBarBaz\" icontains \"baz\" }", - NULL); + "rule test { condition: \"FooBarBaz\" icontains \"baz\" }", NULL); assert_true_rule( - "rule test { condition: \"FooBarBaz\" icontains \"FOO\" }", - NULL); + "rule test { condition: \"FooBarBaz\" icontains \"FOO\" }", NULL); assert_true_rule( - "rule test { condition: \"foobarbaz\" contains \"foo\" }", - NULL); + "rule test { condition: \"foobarbaz\" contains \"foo\" }", NULL); assert_true_rule( - "rule test { condition: \"foobarbaz\" contains \"baz\" }", - NULL); + "rule test { condition: \"foobarbaz\" contains \"baz\" }", NULL); assert_false_rule( - "rule test { condition: \"foobarbaz\" contains \"baq\" }", - NULL); + "rule test { condition: \"foobarbaz\" contains \"baq\" }", NULL); - assert_false_rule( - "rule test { condition: \"foo\" contains \"foob\" }", - NULL); + assert_false_rule("rule test { condition: \"foo\" contains \"foob\" }", NULL); assert_true_rule( - "rule test { condition: \"foobarbaz\" startswith \"foo\" }", - NULL); + "rule test { condition: \"foobarbaz\" startswith \"foo\" }", NULL); assert_true_rule( - "rule test { condition: \"foobarbaz\" istartswith \"Foo\" }", - NULL); + "rule test { condition: \"foobarbaz\" istartswith \"Foo\" }", NULL); assert_true_rule( - "rule test { condition: \"FooBarBaz\" istartswith \"fOO\" }", - NULL); + "rule test { condition: \"FooBarBaz\" istartswith \"fOO\" }", NULL); assert_false_rule( - "rule test { condition: \"foobarbaz\" startswith \"fob\" }", - NULL); + "rule test { condition: \"foobarbaz\" startswith \"fob\" }", NULL); assert_true_rule( - "rule test { condition: \"foobarbaz\" endswith \"baz\" }", - NULL); + "rule test { condition: \"foobarbaz\" endswith \"baz\" }", NULL); assert_true_rule( - "rule test { condition: \"foobarbaz\" iendswith \"baZ\" }", - NULL); + "rule test { condition: \"foobarbaz\" iendswith \"baZ\" }", NULL); assert_true_rule( - "rule test { condition: \"foobarbaz\" iendswith \"BaZ\" }", - NULL); + "rule test { condition: \"foobarbaz\" iendswith \"BaZ\" }", NULL); assert_false_rule( - "rule test { condition: \"foobarbaz\" endswith \"ba\" }", - NULL); + "rule test { condition: \"foobarbaz\" endswith \"ba\" }", NULL); } @@ -474,9 +368,7 @@ static void test_syntax() ERROR_SYNTAX_ERROR); // Test case for issue #1295 - assert_error( - "rule test rule test", - ERROR_DUPLICATED_IDENTIFIER); + assert_error("rule test rule test", ERROR_DUPLICATED_IDENTIFIER); } @@ -490,12 +382,19 @@ static void test_anonymous_strings() } -#define TEXT_0063_BYTES "[ 123456789 123456789 123456789 123456789 123456789 123456789 ]" -#define TEXT_0256_BYTES_001 "001" TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES "\n" -#define TEXT_0256_BYTES_002 "002" TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES "\n" -#define TEXT_0256_BYTES_003 "003" TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES "\n" -#define TEXT_0256_BYTES_004 "004" TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES "\n" -#define TEXT_1024_BYTES TEXT_0256_BYTES_001 TEXT_0256_BYTES_002 TEXT_0256_BYTES_003 TEXT_0256_BYTES_004 +#define TEXT_0063_BYTES \ + "[ 123456789 123456789 123456789 123456789 123456789 123456789 ]" +#define TEXT_0256_BYTES_001 \ + "001" TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES "\n" +#define TEXT_0256_BYTES_002 \ + "002" TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES "\n" +#define TEXT_0256_BYTES_003 \ + "003" TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES "\n" +#define TEXT_0256_BYTES_004 \ + "004" TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES TEXT_0063_BYTES "\n" +#define TEXT_1024_BYTES \ + TEXT_0256_BYTES_001 TEXT_0256_BYTES_002 TEXT_0256_BYTES_003 \ + TEXT_0256_BYTES_004 static void test_strings() @@ -505,97 +404,72 @@ static void test_strings() char* str = TEXT_1024_BYTES "---- abc ---- xyz"; uint8_t blob[] = TEXT_1024_BYTES "---- a\0b\0c\0 -\0-\0-\0-\0x\0y\0z\0"; - assert_true_rule( - "rule test { strings: $a = \"a\" condition: $a }", - str); + assert_true_rule("rule test { strings: $a = \"a\" condition: $a }", str); - assert_true_rule( - "rule test { strings: $a = \"ab\" condition: $a }", - str); + assert_true_rule("rule test { strings: $a = \"ab\" condition: $a }", str); - assert_true_rule( - "rule test { strings: $a = \"abc\" condition: $a }", - str); + assert_true_rule("rule test { strings: $a = \"abc\" condition: $a }", str); - assert_true_rule( - "rule test { strings: $a = \"xyz\" condition: $a }", - str); + assert_true_rule("rule test { strings: $a = \"xyz\" condition: $a }", str); assert_true_rule( - "rule test { strings: $a = \"abc\" nocase fullword condition: $a }", - str); + "rule test { strings: $a = \"abc\" nocase fullword condition: $a }", str); assert_true_rule( - "rule test { strings: $a = \"aBc\" nocase condition: $a }", - str); + "rule test { strings: $a = \"aBc\" nocase condition: $a }", str); assert_true_rule( - "rule test { strings: $a = \"abc\" fullword condition: $a }", - str); + "rule test { strings: $a = \"abc\" fullword condition: $a }", str); assert_false_rule( - "rule test { strings: $a = \"a\" fullword condition: $a }", - str); + "rule test { strings: $a = \"a\" fullword condition: $a }", str); assert_false_rule( - "rule test { strings: $a = \"ab\" fullword condition: $a }", - str); + "rule test { strings: $a = \"ab\" fullword condition: $a }", str); assert_false_rule( - "rule test { strings: $a = \"abc\" wide fullword condition: $a }", - str); + "rule test { strings: $a = \"abc\" wide fullword condition: $a }", str); assert_true_rule_blob( - "rule test { strings: $a = \"a\" wide condition: $a }", - blob); + "rule test { strings: $a = \"a\" wide condition: $a }", blob); assert_true_rule_blob( - "rule test { strings: $a = \"a\" wide ascii condition: $a }", - blob); + "rule test { strings: $a = \"a\" wide ascii condition: $a }", blob); assert_true_rule_blob( - "rule test { strings: $a = \"ab\" wide condition: $a }", - blob); + "rule test { strings: $a = \"ab\" wide condition: $a }", blob); assert_true_rule_blob( - "rule test { strings: $a = \"ab\" wide ascii condition: $a }", - blob); + "rule test { strings: $a = \"ab\" wide ascii condition: $a }", blob); assert_true_rule_blob( - "rule test { strings: $a = \"abc\" wide condition: $a }", - blob); + "rule test { strings: $a = \"abc\" wide condition: $a }", blob); assert_true_rule_blob( "rule test { strings: $a = \"abc\" wide nocase fullword condition: $a }", blob); assert_true_rule_blob( - "rule test { strings: $a = \"aBc\" wide nocase condition: $a }", - blob); + "rule test { strings: $a = \"aBc\" wide nocase condition: $a }", blob); assert_true_rule_blob( "rule test { strings: $a = \"aBc\" wide ascii nocase condition: $a }", blob); assert_true_rule_blob( - "rule test { strings: $a = \"---xyz\" wide nocase condition: $a }", - blob); + "rule test { strings: $a = \"---xyz\" wide nocase condition: $a }", blob); assert_true_rule( - "rule test { strings: $a = \"abc\" fullword condition: $a }", - "abc"); + "rule test { strings: $a = \"abc\" fullword condition: $a }", "abc"); assert_false_rule( - "rule test { strings: $a = \"abc\" fullword condition: $a }", - "xabcx"); + "rule test { strings: $a = \"abc\" fullword condition: $a }", "xabcx"); assert_false_rule( - "rule test { strings: $a = \"abc\" fullword condition: $a }", - "xabc"); + "rule test { strings: $a = \"abc\" fullword condition: $a }", "xabc"); assert_false_rule( - "rule test { strings: $a = \"abc\" fullword condition: $a }", - "abcx"); + "rule test { strings: $a = \"abc\" fullword condition: $a }", "abcx"); assert_false_rule_blob( "rule test { strings: $a = \"abc\" wide condition: $a }", @@ -645,146 +519,163 @@ static void test_strings() $c = \"ef\"\n\ condition:\n\ all of them\n\ - }", "abcdef"); + }", + "abcdef"); // xor by itself will match the plaintext version of the string too. assert_true_rule_file( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" xor\n\ condition:\n\ #a == 256\n\ - }", "tests/data/xor.out"); + }", + "tests/data/xor.out"); // Make sure the combination of xor and ascii behaves the same as just xor. assert_true_rule_file( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" xor ascii\n\ condition:\n\ #a == 256\n\ - }", "tests/data/xor.out"); + }", + "tests/data/xor.out"); assert_true_rule_file( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" xor(1-0x10)\n\ condition:\n\ #a == 16\n\ - }", "tests/data/xor.out"); + }", + "tests/data/xor.out"); // We should have no matches here because we are not generating the ascii // string, just the wide one, and the test data contains no wide strings. assert_true_rule_file( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" xor wide\n\ condition:\n\ #a == 0\n\ - }", "tests/data/xor.out"); + }", + "tests/data/xor.out"); // xor by itself is equivalent to xor(0-255). assert_true_rule_file( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" xor wide\n\ condition:\n\ #a == 256\n\ - }", "tests/data/xorwide.out"); + }", + "tests/data/xorwide.out"); // This DOES NOT look for the plaintext wide version by itself. assert_true_rule_file( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" xor(1-16) wide\n\ condition:\n\ #a == 16\n\ - }", "tests/data/xorwide.out"); + }", + "tests/data/xorwide.out"); // Check the location of the match to make sure we match on the correct one. assert_true_rule_file( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" xor(1) wide\n\ condition:\n\ #a == 1 and @a == 0x2f\n\ - }", "tests/data/xorwide.out"); + }", + "tests/data/xorwide.out"); assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" xor(300)\n\ condition:\n\ $a\n\ - }", ERROR_INVALID_MODIFIER); + }", + ERROR_INVALID_MODIFIER); assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" xor(200-10)\n\ condition:\n\ $a\n\ - }", ERROR_INVALID_MODIFIER); + }", + ERROR_INVALID_MODIFIER); assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = {00 11 22 33} xor\n\ condition:\n\ $a\n\ - }", ERROR_SYNTAX_ERROR); + }", + ERROR_SYNTAX_ERROR); assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = /foo(bar|baz)/ xor\n\ condition:\n\ $a\n\ - }", ERROR_SYNTAX_ERROR); + }", + ERROR_SYNTAX_ERROR); assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"ab\" xor xor\n\ condition:\n\ $a\n\ - }", ERROR_DUPLICATED_MODIFIER); + }", + ERROR_DUPLICATED_MODIFIER); // We should have no matches here because we are not generating the wide // string, just the ascii one, and the test data contains no ascii strings. assert_true_rule_file( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" xor ascii\n\ condition:\n\ #a == 0\n\ - }", "tests/data/xorwide.out"); + }", + "tests/data/xorwide.out"); // This should match 512 times because we are looking for the wide and ascii // versions in plaintext and doing xor(0-255) (implicitly) assert_true_rule_file( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" xor wide ascii\n\ condition:\n\ #a == 512\n\ - }", "tests/data/xorwideandascii.out"); + }", + "tests/data/xorwideandascii.out"); assert_true_rule_file( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"This program cannot\" wide ascii\n\ condition:\n\ #a == 2\n\ - }", "tests/data/xorwideandascii.out"); + }", + "tests/data/xorwideandascii.out"); assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"ab\" xor nocase\n\ condition:\n\ true\n\ - }", ERROR_INVALID_MODIFIER); + }", + ERROR_INVALID_MODIFIER); assert_true_rule( "rule test { \ @@ -814,53 +705,59 @@ static void test_strings() "AXS1111ERS2222"); assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"ab\" base64 nocase\n\ condition:\n\ true\n\ - }", ERROR_INVALID_MODIFIER); + }", + ERROR_INVALID_MODIFIER); assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"ab\" base64 xor\n\ condition:\n\ true\n\ - }", ERROR_INVALID_MODIFIER); + }", + ERROR_INVALID_MODIFIER); assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"ab\" base64 fullword\n\ condition:\n\ true\n\ - }", ERROR_INVALID_MODIFIER); + }", + ERROR_INVALID_MODIFIER); assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"ab\" base64(\"AXS\")\n\ condition:\n\ true\n\ - }", ERROR_INVALID_MODIFIER); + }", + ERROR_INVALID_MODIFIER); assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"ab\" base64wide(\"ERS\")\n\ condition:\n\ true\n\ - }", ERROR_INVALID_MODIFIER); + }", + ERROR_INVALID_MODIFIER); // Specifying different alphabets is an error. assert_error( - "rule test {\n\ + "rule test {\n\ strings:\n\ $a = \"ab\" base64 base64wide(\"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ,.\")\n\ condition:\n\ true\n\ - }", ERROR_INVALID_MODIFIER); + }", + ERROR_INVALID_MODIFIER); // Be specific about the offsets in these tests to make sure we are matching // the correct strings. Also be specific about the length because we want to @@ -884,7 +781,8 @@ static void test_strings() !a[5] == 25 and\n\ @a[6] == 0x109 and\n\ !a[6] == 25\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // This is identical to "base64" alone, but test it to make sure we don't // accidentally include the plaintext in the base64 search. @@ -906,7 +804,8 @@ static void test_strings() !a[5] == 25 and\n\ @a[6] == 0x109 and\n\ !a[6] == 25\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // Make sure the wide modifier is applied BEFORE the base64 and we do NOT // include the wide plaintext string. @@ -928,7 +827,8 @@ static void test_strings() !a[5] == 50 and\n\ @a[6] == 0x311 and\n\ !a[6] == 50\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // Make sure that both wide and ascii are base64 encoded. We can skip the // verbose length and offset checks, since the previous tests cover that. @@ -938,7 +838,8 @@ static void test_strings() $a = \"This program cannot\" base64 wide ascii\n\ condition:\n\ #a == 12\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // Make sure that the two strings are generated when one ascii byte is // base64 encoded. When stripped, third base64 encoded is null. @@ -952,7 +853,8 @@ static void test_strings() @a[59] == 0x6b9 and\n\ @b[15] == 0x6f7 and\n\ @b[16] == 0x711\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // In the future, assert false if character classes are generated instead // of stripping the leading and trailing characters @@ -964,7 +866,8 @@ static void test_strings() #a == 2 and\n\ @a[1] == 0xa2 and\n\ @a[2] == 0xbd\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // This checks for the ascii string in base64 form then widened. assert_true_rule_file( @@ -979,7 +882,8 @@ static void test_strings() !a[2] == 48 and\n\ @a[3] == 0x3f1 and\n\ !a[3] == 50\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // Logically identical to the test above but include it to make sure we don't // accidentally include the plaintext in the future. @@ -995,7 +899,8 @@ static void test_strings() !a[2] == 48 and\n\ @a[3] == 0x3f1 and\n\ !a[3] == 50\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // Make sure the wide string is base64wide encoded. assert_true_rule_file( @@ -1010,7 +915,8 @@ static void test_strings() !a[2] == 100 and\n\ @a[3] == 0x530 and\n\ !a[3] == 100\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // Make sure both ascii and wide strings are base64wide encoded properly. assert_true_rule_file( @@ -1031,7 +937,8 @@ static void test_strings() !a[5] == 100 and\n\ @a[6] == 0x530 and\n\ !a[6] == 100\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // Make sure base64 and base64wide together work. assert_true_rule_file( @@ -1058,7 +965,8 @@ static void test_strings() !a[8] == 48 and\n\ @a[9] == 0x3f1 and\n\ !a[9] == 50\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // Identical to the test above but useful to make sure we don't accidentally // include the ascii plaintext in the future. @@ -1068,7 +976,8 @@ static void test_strings() $a = \"This program cannot\" base64 base64wide ascii\n\ condition:\n\ #a == 9\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); // Making sure we don't accidentally include the wide plaintext in the future. assert_true_rule_file( @@ -1077,7 +986,8 @@ static void test_strings() $a = \"This program cannot\" base64 base64wide wide\n\ condition:\n\ #a == 9\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); assert_true_rule_file( "rule test {\n\ @@ -1091,7 +1001,8 @@ static void test_strings() !a[2] == 24 and\n\ @a[3] == 0x656 and\n\ !a[3] == 25\n\ - }", "tests/data/base64"); + }", + "tests/data/base64"); } @@ -1107,7 +1018,9 @@ static void test_wildcard_strings() condition:\n\ for all of ($*) : ($)\n\ }", - "---- abc ---- A\x00""B\x00""C\x00 ---- xyz"); + "---- abc ---- A\x00" + "B\x00" + "C\x00 ---- xyz"); } @@ -1127,7 +1040,7 @@ static void test_hex_strings() condition: $a }", PE32_FILE); - assert_true_rule_blob(\ + assert_true_rule_blob( "rule test { \ strings: $a = { 6? 01 00 00 60 0? } \ @@ -1347,8 +1260,7 @@ static void test_count() YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); assert_true_rule( - "rule test { strings: $a = \"ssi\" condition: #a == 2 }", - "mississippi"); + "rule test { strings: $a = \"ssi\" condition: #a == 2 }", "mississippi"); assert_true_rule( "rule test { strings: $a = \"ssi\" private condition: #a == 2 }", @@ -1409,8 +1321,7 @@ static void test_offset() YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); assert_true_rule( - "rule test { strings: $a = \"ssi\" condition: @a == 2 }", - "mississippi"); + "rule test { strings: $a = \"ssi\" condition: @a == 2 }", "mississippi"); assert_true_rule( "rule test { strings: $a = \"ssi\" private condition: @a == 2 }", @@ -1443,8 +1354,7 @@ static void test_length() "mississippi"); assert_true_rule( - "rule test { strings: $a = /m.*ssi/ condition: !a == 8 }", - "mississippi"); + "rule test { strings: $a = /m.*ssi/ condition: !a == 8 }", "mississippi"); assert_true_rule( "rule test { strings: $a = /m.*ssi/ condition: !a[1] == 8 }", @@ -1471,7 +1381,8 @@ static void test_length() "mississippi"); assert_true_rule( - "rule test { strings: $a = { 6D 69 73 73 [-] 70 69 } condition: !a == 11}", + "rule test { strings: $a = { 6D 69 73 73 [-] 70 69 } condition: !a == " + "11}", "mississippi"); } @@ -1509,7 +1420,7 @@ static void test_of() condition: \ for any of ($*) : ( for any i in (1..#): (uint8(@[i] - 1) == 0x00) )\ }", - "abc\000def\000ghi"); + "abc\000def\000ghi"); assert_false_rule( "rule test { \ @@ -1522,13 +1433,9 @@ static void test_of() }", "mississippi"); - assert_error( - "rule test { condition: all of ($a*) }", - ERROR_UNDEFINED_STRING); + assert_error("rule test { condition: all of ($a*) }", ERROR_UNDEFINED_STRING); - assert_error( - "rule test { condition: all of them }", - ERROR_UNDEFINED_STRING); + assert_error("rule test { condition: all of them }", ERROR_UNDEFINED_STRING); } @@ -1660,7 +1567,7 @@ void test_for() true \ ) \ }", - NULL); + NULL); assert_false_rule( "import \"tests\" \ @@ -1670,7 +1577,7 @@ void test_for() true \ ) \ }", - NULL); + NULL); assert_false_rule( @@ -1681,7 +1588,7 @@ void test_for() true \ ) \ }", - NULL); + NULL); assert_false_rule( "import \"tests\" \ @@ -1691,7 +1598,7 @@ void test_for() false \ ) \ }", - NULL); + NULL); // Test case for issue #1180. assert_true_rule( @@ -1700,7 +1607,7 @@ void test_for() condition: \ not tests.string_array[4] contains \"foo\" \ }", - NULL); + NULL); // Test case for issue #1180. assert_true_rule( @@ -1709,7 +1616,7 @@ void test_for() condition: \ not tests.string_dict[\"undefined\"] matches /foo/ \ }", - NULL); + NULL); assert_false_rule( "import \"tests\" \ @@ -1717,7 +1624,7 @@ void test_for() condition: \ not tests.undefined.i \ }", - NULL); + NULL); assert_true_rule( "import \"tests\" \ @@ -1840,20 +1747,17 @@ void test_re() "mississippi\tmississippi.mississippi\nmississippi"); assert_false_rule( - "rule test { strings: $a = /^ssi/ condition: $a }", - "mississippi"); + "rule test { strings: $a = /^ssi/ condition: $a }", "mississippi"); assert_false_rule( - "rule test { strings: $a = /ssi$/ condition: $a }", - "mississippi"); + "rule test { strings: $a = /ssi$/ condition: $a }", "mississippi"); assert_false_rule( "rule test { strings: $a = /ssissi/ fullword condition: $a }", "mississippi"); assert_false_rule( - "rule test { strings: $a = /^[isp]+/ condition: $a }", - "mississippi"); + "rule test { strings: $a = /^[isp]+/ condition: $a }", "mississippi"); assert_true_rule_blob( "rule test { strings: $a = /a.{1,2}b/ wide condition: !a == 6 }", @@ -1864,16 +1768,13 @@ void test_re() "a\0x\0x\0b\0"); assert_true_rule_blob( - "rule test { strings: $a = /\\babc/ wide condition: $a }", - "a\0b\0c\0"); + "rule test { strings: $a = /\\babc/ wide condition: $a }", "a\0b\0c\0"); assert_true_rule_blob( - "rule test { strings: $a = /\\babc/ wide condition: $a }", - "\0a\0b\0c\0"); + "rule test { strings: $a = /\\babc/ wide condition: $a }", "\0a\0b\0c\0"); assert_true_rule_blob( - "rule test { strings: $a = /\\babc/ wide condition: $a }", - "\ta\0b\0c\0"); + "rule test { strings: $a = /\\babc/ wide condition: $a }", "\ta\0b\0c\0"); assert_false_rule_blob( "rule test { strings: $a = /\\babc/ wide condition: $a }", @@ -1884,16 +1785,13 @@ void test_re() "x\ta\0b\0c\0"); assert_true_rule_blob( - "rule test { strings: $a = /abc\\b/ wide condition: $a }", - "a\0b\0c\0"); + "rule test { strings: $a = /abc\\b/ wide condition: $a }", "a\0b\0c\0"); assert_true_rule_blob( - "rule test { strings: $a = /abc\\b/ wide condition: $a }", - "a\0b\0c\0\0"); + "rule test { strings: $a = /abc\\b/ wide condition: $a }", "a\0b\0c\0\0"); assert_true_rule_blob( - "rule test { strings: $a = /abc\\b/ wide condition: $a }", - "a\0b\0c\0\t"); + "rule test { strings: $a = /abc\\b/ wide condition: $a }", "a\0b\0c\0\t"); assert_false_rule_blob( "rule test { strings: $a = /abc\\b/ wide condition: $a }", @@ -1904,8 +1802,7 @@ void test_re() "a\0b\0c\0b\t"); assert_false_rule_blob( - "rule test { strings: $a = /\\b/ wide condition: $a }", - "abc"); + "rule test { strings: $a = /\\b/ wide condition: $a }", "abc"); assert_regexp_syntax_error(")"); assert_true_regexp("abc", "abc", "abc"); @@ -2008,7 +1905,8 @@ void test_re() assert_true_regexp("(a{2,3}b){2,3}", "aabaaabaab", "aabaaabaab"); assert_true_regexp("(a{2,3}?b){2,3}?", "aabaaabaab", "aabaaab"); assert_false_regexp("(a{4,5}b){4,5}", "aaaabaaaabaaaaab"); - assert_true_regexp("(a{4,5}b){4,5}", "aaaabaaaabaaaaabaaaaab", "aaaabaaaabaaaaabaaaaab"); + assert_true_regexp( + "(a{4,5}b){4,5}", "aaaabaaaabaaaaabaaaaab", "aaaabaaaabaaaaabaaaaab"); assert_true_regexp(".(abc){0,1}", "xabcabcabcabc", "xabc"); assert_true_regexp(".(abc){0,2}", "xabcabcabcabc", "xabcabc"); assert_true_regexp("x{1,2}abcd", "xxxxabcd", "xxabcd"); @@ -2140,7 +2038,7 @@ void test_re() assert_false_regexp("abc^", "abc"); assert_false_regexp("ab^c", "abc"); assert_false_regexp("a^bcdef", "abcdef") - assert_true_regexp("abc$", "aabc", "abc"); + assert_true_regexp("abc$", "aabc", "abc"); assert_false_regexp("$abc", "abc"); assert_true_regexp("(a|a$)bcd", "abcd", "abcd"); assert_false_regexp("(a$|a$)bcd", "abcd"); @@ -2168,27 +2066,33 @@ void test_re() assert_true_regexp("(a|\\b)[a]{1,}", "aaaa", "aaaa"); // Test cases for issue #1018 - assert_true_regexp("(ba{4}){4,10}", "baaaabaaaabaaaabaaaabaaaa", "baaaabaaaabaaaabaaaabaaaa"); - assert_true_regexp("(ba{2}a{2}){5,10}", "baaaabaaaabaaaabaaaabaaaa", "baaaabaaaabaaaabaaaabaaaa"); - assert_true_regexp("(ba{3}){4,10}", "baaabaaabaaabaaabaaa", "baaabaaabaaabaaabaaa"); - assert_true_regexp("(ba{4}){5,10}", "baaaabaaaabaaaabaaaabaaaa", "baaaabaaaabaaaabaaaabaaaa"); + assert_true_regexp( + "(ba{4}){4,10}", + "baaaabaaaabaaaabaaaabaaaa", + "baaaabaaaabaaaabaaaabaaaa"); + assert_true_regexp( + "(ba{2}a{2}){5,10}", + "baaaabaaaabaaaabaaaabaaaa", + "baaaabaaaabaaaabaaaabaaaa"); + assert_true_regexp( + "(ba{3}){4,10}", "baaabaaabaaabaaabaaa", "baaabaaabaaabaaabaaa"); + assert_true_regexp( + "(ba{4}){5,10}", + "baaaabaaaabaaaabaaaabaaaa", + "baaaabaaaabaaaabaaaabaaaa"); assert_false_regexp("(ba{4}){4,10}", "baaaabaaaabaaaa"); // Test for integer overflow in repeat interval assert_regexp_syntax_error("a{2977952116}"); assert_error( - "rule test { strings: $a = /a\\/ condition: $a }", - ERROR_SYNTAX_ERROR); + "rule test { strings: $a = /a\\/ condition: $a }", ERROR_SYNTAX_ERROR); assert_error( - "rule test { strings: $a = /[a\\/ condition: $a }", - ERROR_SYNTAX_ERROR); + "rule test { strings: $a = /[a\\/ condition: $a }", ERROR_SYNTAX_ERROR); // Test case for issue #996 - assert_error( - "rule test {strings:$=/.{,}? /", - ERROR_SYNTAX_ERROR); + assert_error("rule test {strings:$=/.{,}? /", ERROR_SYNTAX_ERROR); assert_true_rule_blob( "rule test { \ @@ -2203,46 +2107,38 @@ void test_re() PE32_FILE); assert_false_rule( - "rule test { strings: $a = /abc[^d]/ nocase condition: $a }", - "abcd"); + "rule test { strings: $a = /abc[^d]/ nocase condition: $a }", "abcd"); assert_false_rule( - "rule test { strings: $a = /abc[^d]/ condition: $a }", - "abcd"); + "rule test { strings: $a = /abc[^d]/ condition: $a }", "abcd"); assert_false_rule( - "rule test { strings: $a = /abc[^D]/ nocase condition: $a }", - "abcd"); + "rule test { strings: $a = /abc[^D]/ nocase condition: $a }", "abcd"); assert_true_rule( - "rule test { strings: $a = /abc[^D]/ condition: $a }", - "abcd"); + "rule test { strings: $a = /abc[^D]/ condition: $a }", "abcd"); assert_true_rule( - "rule test { strings: $a = /abc[^f]/ nocase condition: $a }", - "abcd"); + "rule test { strings: $a = /abc[^f]/ nocase condition: $a }", "abcd"); assert_true_rule( - "rule test { strings: $a = /abc[^f]/ condition: $a }", - "abcd"); + "rule test { strings: $a = /abc[^f]/ condition: $a }", "abcd"); assert_true_rule( - "rule test { strings: $a = /abc[^F]/ nocase condition: $a }", - "abcd"); + "rule test { strings: $a = /abc[^F]/ nocase condition: $a }", "abcd"); assert_true_rule( - "rule test { strings: $a = /abc[^F]/ condition: $a }", - "abcd"); + "rule test { strings: $a = /abc[^F]/ condition: $a }", "abcd"); // Test case for issue #1006 assert_false_rule_blob( - "rule test { strings: $a = \" cmd.exe \" nocase wide condition: $a }", - ISSUE_1006); + "rule test { strings: $a = \" cmd.exe \" nocase wide condition: $a }", + ISSUE_1006); // Test case for issue #1117 assert_true_rule_blob( - "rule test { strings: $a =/abc([^\"\\\\])*\"/ nocase condition: $a }", - "abc\xE0\x22"); + "rule test { strings: $a =/abc([^\"\\\\])*\"/ nocase condition: $a }", + "abc\xE0\x22"); } @@ -2268,9 +2164,7 @@ static void test_entrypoint() condition: $a at entrypoint }", ELF64_FILE); - assert_false_rule( - "rule test { condition: entrypoint >= 0 }", - NULL); + assert_false_rule("rule test { condition: entrypoint >= 0 }", NULL); } @@ -2286,9 +2180,7 @@ static void test_filesize() "rule test { condition: filesize == %zd }", sizeof(PE32_FILE)); - assert_true_rule_blob( - rule, - PE32_FILE); + assert_true_rule_blob(rule, PE32_FILE); } @@ -2352,41 +2244,27 @@ static void test_matches_operator() { YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); - assert_true_rule( - "rule test { condition: \"foo\" matches /foo/ }", - NULL); + assert_true_rule("rule test { condition: \"foo\" matches /foo/ }", NULL); - assert_false_rule( - "rule test { condition: \"foo\" matches /bar/ }", - NULL); + assert_false_rule("rule test { condition: \"foo\" matches /bar/ }", NULL); - assert_true_rule( - "rule test { condition: \"FoO\" matches /fOo/i }", - NULL); + assert_true_rule("rule test { condition: \"FoO\" matches /fOo/i }", NULL); - assert_true_rule( - "rule test { condition: \"xxFoOxx\" matches /fOo/i }", - NULL); + assert_true_rule("rule test { condition: \"xxFoOxx\" matches /fOo/i }", NULL); assert_false_rule( - "rule test { condition: \"xxFoOxx\" matches /^fOo/i }", - NULL); + "rule test { condition: \"xxFoOxx\" matches /^fOo/i }", NULL); assert_false_rule( - "rule test { condition: \"xxFoOxx\" matches /fOo$/i }", - NULL); + "rule test { condition: \"xxFoOxx\" matches /fOo$/i }", NULL); - assert_true_rule( - "rule test { condition: \"foo\" matches /^foo$/i }", - NULL); + assert_true_rule("rule test { condition: \"foo\" matches /^foo$/i }", NULL); assert_true_rule( - "rule test { condition: \"foo\\nbar\" matches /foo.*bar/s }", - NULL); + "rule test { condition: \"foo\\nbar\" matches /foo.*bar/s }", NULL); assert_false_rule( - "rule test { condition: \"foo\\nbar\" matches /foo.*bar/ }", - NULL); + "rule test { condition: \"foo\\nbar\" matches /foo.*bar/ }", NULL); } @@ -2603,13 +2481,9 @@ static void test_modules() }", NULL); - assert_error( - "import \"\\x00\"", - ERROR_INVALID_MODULE_NAME); + assert_error("import \"\\x00\"", ERROR_INVALID_MODULE_NAME); - assert_error( - "import \"\"", - ERROR_INVALID_MODULE_NAME); + assert_error("import \"\"", ERROR_INVALID_MODULE_NAME); } @@ -2617,10 +2491,10 @@ static void test_time_module() { YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); - assert_true_rule( - "import \"time\" \ + assert_true_rule( + "import \"time\" \ rule test { condition: time.now() > 0 }", - NULL); + NULL); } @@ -2629,7 +2503,8 @@ static void test_hash_module() { YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); - uint8_t blob[] = {0x61, 0x62, 0x63, 0x64, 0x65}; // abcde without trailing zero + uint8_t blob[] = { + 0x61, 0x62, 0x63, 0x64, 0x65}; // abcde without trailing zero assert_true_rule_blob( "import \"hash\" \ @@ -2735,28 +2610,22 @@ void test_integer_functions() YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); assert_true_rule( - "rule test { condition: uint8(0) == 0xAA}", - "\xaa\xbb\xcc\xdd"); + "rule test { condition: uint8(0) == 0xAA}", "\xaa\xbb\xcc\xdd"); assert_true_rule( - "rule test { condition: uint16(0) == 0xBBAA}", - "\xaa\xbb\xcc\xdd"); + "rule test { condition: uint16(0) == 0xBBAA}", "\xaa\xbb\xcc\xdd"); assert_true_rule( - "rule test { condition: uint32(0) == 0xDDCCBBAA}", - "\xaa\xbb\xcc\xdd"); + "rule test { condition: uint32(0) == 0xDDCCBBAA}", "\xaa\xbb\xcc\xdd"); assert_true_rule( - "rule test { condition: uint8be(0) == 0xAA}", - "\xaa\xbb\xcc\xdd"); + "rule test { condition: uint8be(0) == 0xAA}", "\xaa\xbb\xcc\xdd"); assert_true_rule( - "rule test { condition: uint16be(0) == 0xAABB}", - "\xaa\xbb\xcc\xdd"); + "rule test { condition: uint16be(0) == 0xAABB}", "\xaa\xbb\xcc\xdd"); assert_true_rule( - "rule test { condition: uint32be(0) == 0xAABBCCDD}", - "\xaa\xbb\xcc\xdd"); + "rule test { condition: uint32be(0) == 0xAABBCCDD}", "\xaa\xbb\xcc\xdd"); } @@ -2765,12 +2634,10 @@ void test_include_files() YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); assert_true_rule( - "include \"tests/data/baz.yar\" rule t { condition: baz }", - NULL); + "include \"tests/data/baz.yar\" rule t { condition: baz }", NULL); assert_true_rule( - "include \"tests/data/foo.yar\" rule t { condition: foo }", - NULL); + "include \"tests/data/foo.yar\" rule t { condition: foo }", NULL); } @@ -2778,13 +2645,9 @@ void test_tags() { YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); - assert_true_rule( - "rule test : tag1 { condition: true}", - NULL); + assert_true_rule("rule test : tag1 { condition: true}", NULL); - assert_true_rule( - "rule test : tag1 tag2 { condition: true}", - NULL); + assert_true_rule("rule test : tag1 tag2 { condition: true}", NULL); assert_error( "rule test : tag1 tag1 { condition: true}", @@ -2809,7 +2672,12 @@ void test_process_scan() if (pid == 0) { // The string should appear somewhere in the shell's process space. - if (execl("/bin/sh", "/bin/sh", "-c", "VAR='Hello, world!'; sleep 5; true", NULL) == -1) + if (execl( + "/bin/sh", + "/bin/sh", + "-c", + "VAR='Hello, world!'; sleep 5; true", + NULL) == -1) exit(1); } assert(pid > 0); @@ -2817,7 +2685,8 @@ void test_process_scan() // Give child process time to initialize. sleep(1); - status = compile_rule("\ + status = compile_rule( + "\ rule should_match {\ strings:\ $a = { 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21 }\ @@ -2828,7 +2697,7 @@ void test_process_scan() condition: \ filesize < 100000000 \ }", - &rules); + &rules); if (status != ERROR_SUCCESS) { @@ -2848,22 +2717,26 @@ void test_process_scan() } if (status != SIGALRM) { - fprintf(stderr, "Scanned process exited with unexpected status %d\n", status); + fprintf( + stderr, "Scanned process exited with unexpected status %d\n", status); exit(EXIT_FAILURE); } - switch (rc1) { + switch (rc1) + { case ERROR_SUCCESS: if (counters.rules_matching != 1) { - fprintf(stderr, + fprintf( + stderr, "Expecting one rule matching in test_process_scan, found %d\n", counters.rules_matching); exit(EXIT_FAILURE); } if (counters.rules_not_matching != 1) { - fprintf(stderr, + fprintf( + stderr, "Expecting one rule not matching in test_process_scan, found %d\n", counters.rules_not_matching); exit(EXIT_FAILURE); @@ -2883,142 +2756,127 @@ void test_performance_warnings() { YR_DEBUG_FPRINTF(1, stderr, "+ %s() {}\n", __FUNCTION__); - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 01 } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 01 ?? } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 01 ?? ?? } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 01 ?? ?? 02 } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 01 ?? ?2 03 } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 01 ?? 02 1? } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 1? 2? 3? } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 1? 2? 3? 04 } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 1? ?? 03 } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 00 01 } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 01 00 } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 00 00 } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning("rule test { \ strings: $a = { 00 00 00 } \ condition: $a }") - assert_no_warnings( - "rule test { \ + assert_no_warnings( + "rule test { \ strings: $a = { 00 00 01 } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning( + "rule test { \ strings: $a = { 00 00 00 00 } \ condition: $a }") - assert_no_warnings( - "rule test { \ + assert_no_warnings( + "rule test { \ strings: $a = { 00 00 00 01 } \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning( + "rule test { \ strings: $a = { FF FF FF FF } \ condition: $a }") - assert_no_warnings( - "rule test { \ + assert_no_warnings( + "rule test { \ strings: $a = { 00 00 01 02 } \ condition: $a }") - assert_no_warnings( - "rule test { \ + assert_no_warnings( + "rule test { \ strings: $a = { 00 01 02 03 } \ condition: $a }") - assert_no_warnings( - "rule test { \ + assert_no_warnings( + "rule test { \ strings: $a = { 01 02 03 04 } \ condition: $a }") - assert_no_warnings( - "rule test { \ + assert_no_warnings( + "rule test { \ strings: $a = { 01 02 03 } \ condition: $a }") - assert_no_warnings( - "rule test { \ + assert_no_warnings( + "rule test { \ strings: $a = { 20 01 02 } \ condition: $a }") - assert_no_warnings( - "rule test { \ + assert_no_warnings( + "rule test { \ strings: $a = { 01 02 } \ condition: $a }") - assert_no_warnings( - "rule test { \ + assert_no_warnings( + "rule test { \ strings: $a = \"foo\" wide \ condition: $a }") - assert_no_warnings( - "rule test { \ + assert_no_warnings( + "rule test { \ strings: $a = \"MZ\" \ condition: $a }") - assert_warning( - "rule test { \ + assert_warning( + "rule test { \ strings: $a = \" \" xor(0x20) \ condition: $a }") - // This will eventually xor with 0x41 and should cause a warning. - assert_warning( - "rule test { \ + // This will eventually xor with 0x41 and should cause a warning. + assert_warning("rule test { \ strings: $a = \"AAAAAAAAAAAAAAAAAAAA\" xor \ condition: $a }") - } @@ -3028,9 +2886,11 @@ int main(int argc, char** argv) yr_initialize(); - #if YR_DEBUG_VERBOSITY > 0 - yr_debug_verbosity = getenv("YR_DEBUG_VERBOSITY") ? atoi(getenv("YR_DEBUG_VERBOSITY")) : 0; - #endif +#if YR_DEBUG_VERBOSITY > 0 + yr_debug_verbosity = getenv("YR_DEBUG_VERBOSITY") + ? atoi(getenv("YR_DEBUG_VERBOSITY")) + : 0; +#endif assert_true_expr(strlen(TEXT_1024_BYTES) == 1024); @@ -3038,26 +2898,37 @@ int main(int argc, char** argv) uint64_t last_yr_test_count_get_block; - for (int i = 1; i <= 2; i ++) + for (int i = 1; i <= 2; i++) { if (2 == i) { - // "Actually, a single block will contain the whole file's content in most cases, but you - // can't rely on that while writing your code. For very big files YARA could eventually split - // the file into two or more blocks, and your module should be prepared to handle that." [1] - // [1] https://yara.readthedocs.io/en/stable/writingmodules.html#accessing-the-scanned-data - yr_test_mem_block_size = getenv("YR_TEST_MEM_BLOCK_SIZE") ? - atoi(getenv("YR_TEST_MEM_BLOCK_SIZE")) : 1024; - yr_test_mem_block_size_overlap = getenv("YR_TEST_MEM_BLOCK_SIZE_OVERLAP") ? - atoi(getenv("YR_TEST_MEM_BLOCK_SIZE_OVERLAP")) : 256; + // "Actually, a single block will contain the whole file's content in most + // cases, but you + // can't rely on that while writing your code. For very big files YARA + // could eventually split the file into two or more blocks, and your + // module should be prepared to handle that." [1] + // [1] + // https://yara.readthedocs.io/en/stable/writingmodules.html#accessing-the-scanned-data + yr_test_mem_block_size = getenv("YR_TEST_MEM_BLOCK_SIZE") + ? atoi(getenv("YR_TEST_MEM_BLOCK_SIZE")) + : 1024; + yr_test_mem_block_size_overlap = + getenv("YR_TEST_MEM_BLOCK_SIZE_OVERLAP") + ? atoi(getenv("YR_TEST_MEM_BLOCK_SIZE_OVERLAP")) + : 256; assert(yr_test_mem_block_size_overlap <= yr_test_mem_block_size); } - YR_DEBUG_FPRINTF(1, stderr, "- // run all rule tests: pass %d: " + YR_DEBUG_FPRINTF( + 1, + stderr, + "- // run all rule tests: pass %d: " "split data into blocks of max %" PRId64 " bytes " "(0 means single / unlimited block size; default) " "with %" PRId64 " bytes overlapping the previous block\n", - i, yr_test_mem_block_size, yr_test_mem_block_size_overlap); + i, + yr_test_mem_block_size, + yr_test_mem_block_size_overlap); yr_test_count_get_block = 0; @@ -3096,18 +2967,21 @@ int main(int argc, char** argv) test_global_rules(); test_tags(); - #if !defined(USE_WINDOWS_PROC) && !defined(USE_NO_PROC) +#if !defined(USE_WINDOWS_PROC) && !defined(USE_NO_PROC) test_process_scan(); - #endif +#endif - #if defined(HASH_MODULE) +#if defined(HASH_MODULE) test_hash_module(); - #endif +#endif test_time_module(); test_performance_warnings(); - YR_DEBUG_FPRINTF(1, stderr, "- // yr_test_count_get_block=%" PRId64 + YR_DEBUG_FPRINTF( + 1, + stderr, + "- // yr_test_count_get_block=%" PRId64 " is the number of times the above tests got a first or next block\n", yr_test_count_get_block); diff --git a/tests/test-stack.c b/tests/test-stack.c index 1b3b7492a6..eb3aa55579 100644 --- a/tests/test-stack.c +++ b/tests/test-stack.c @@ -28,8 +28,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include + #include "util.h" @@ -40,7 +41,7 @@ int main(int argc, char** argv) int item; yr_initialize(); - yr_stack_create(1, sizeof(item), &stack); + yr_stack_create(1, sizeof(item), &stack); item = 1; diff --git a/tests/test-version.c b/tests/test-version.c index be5e9887d1..3feaad350c 100644 --- a/tests/test-version.c +++ b/tests/test-version.c @@ -27,10 +27,10 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include -int main (int argc, char **argv) +int main(int argc, char **argv) { // make sure that versions defined in configure.ac and in // libyara/include/yara/libyara.h are in sync. diff --git a/tests/util.c b/tests/util.c index d4de05dc49..012dc8cfd7 100644 --- a/tests/util.c +++ b/tests/util.c @@ -27,17 +27,16 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include +#include "util.h" -#include -#include #include - +#include +#include +#include +#include #include -#include #include -#include "util.h" +#include // // Global variables used in test cases. @@ -57,7 +56,7 @@ uint64_t yr_test_count_get_block = 0; static YR_MEMORY_BLOCK* _yr_test_single_block_get_first_block( YR_MEMORY_BLOCK_ITERATOR* iterator) { - yr_test_count_get_block ++; + yr_test_count_get_block++; return (YR_MEMORY_BLOCK*) iterator->context; } @@ -65,7 +64,7 @@ static YR_MEMORY_BLOCK* _yr_test_single_block_get_first_block( static YR_MEMORY_BLOCK* _yr_test_single_block_get_next_block( YR_MEMORY_BLOCK_ITERATOR* iterator) { - yr_test_count_get_block ++; + yr_test_count_get_block++; return NULL; } @@ -85,45 +84,53 @@ static YR_MEMORY_BLOCK* _yr_test_multi_block_get_next_block( YR_MEMORY_BLOCK* result; uint64_t overlap; - yr_test_count_get_block ++; + yr_test_count_get_block++; - if (0 == context->current_block.size) { + if (0 == context->current_block.size) + { overlap = 0; - context->current_block.size = - (context->buffer_size < yr_test_mem_block_size) ? - context->buffer_size : - yr_test_mem_block_size; + context->current_block.size = (context->buffer_size < + yr_test_mem_block_size) + ? context->buffer_size + : yr_test_mem_block_size; result = &context->current_block; } - else { + else + { overlap = yr_test_mem_block_size_overlap; - context->current_block.base += - (0 == context->current_block.base) ? - 0 : - overlap; - context->current_block.base += - (context->current_block.base < context->buffer_size) ? - yr_test_mem_block_size : - 0; - result = (context->current_block.base < context->buffer_size) ? - &context->current_block : NULL; + context->current_block.base += (0 == context->current_block.base) ? 0 + : overlap; + context->current_block.base += (context->current_block.base < + context->buffer_size) + ? yr_test_mem_block_size + : 0; + result = (context->current_block.base < context->buffer_size) + ? &context->current_block + : NULL; context->current_block.size = - ((context->buffer_size - context->current_block.base) < yr_test_mem_block_size) ? - context->buffer_size - context->current_block.base + overlap : - yr_test_mem_block_size + overlap; + ((context->buffer_size - context->current_block.base) < + yr_test_mem_block_size) + ? context->buffer_size - context->current_block.base + overlap + : yr_test_mem_block_size + overlap; context->current_block.base -= overlap; } - YR_DEBUG_FPRINTF(2, stderr, "+ %s() {} = %p // " - ".base=(0x%" PRIx64" or %" PRId64 ") of " - "(0x%lx or %'lu) .size=%'lu, both including %" PRId64 " block overlap%s\n", - __FUNCTION__, result, + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s() {} = %p // " + ".base=(0x%" PRIx64 " or %" PRId64 ") of " + "(0x%lx or %'lu) .size=%'lu, both including %" PRId64 + " block overlap%s\n", + __FUNCTION__, + result, context->current_block.base, context->current_block.base, context->buffer_size, context->buffer_size, context->current_block.size, - overlap, overlap ? "" : " (note: 1st block overlap always 0)"); + overlap, + overlap ? "" : " (note: 1st block overlap always 0)"); return result; } @@ -132,11 +139,13 @@ static YR_MEMORY_BLOCK* _yr_test_multi_block_get_next_block( static YR_MEMORY_BLOCK* _yr_test_multi_block_get_first_block( YR_MEMORY_BLOCK_ITERATOR* iterator) { - YR_DEBUG_FPRINTF(2, stderr, + YR_DEBUG_FPRINTF( + 2, + stderr, "+ %s() {} // wrapping _yr_test_multi_block_get_next_block()\n", __FUNCTION__); - yr_test_count_get_block ++; + yr_test_count_get_block++; YR_PROC_ITERATOR_CTX* context = (YR_PROC_ITERATOR_CTX*) iterator->context; context->current_block.base = 0; @@ -150,19 +159,22 @@ static const uint8_t* _yr_test_multi_block_fetch_block_data( { YR_PROC_ITERATOR_CTX* context = (YR_PROC_ITERATOR_CTX*) block->context; - #if YR_DEBUG_VERBOSITY > 0 - uint64_t overlap = context->current_block.base > 0 ? - yr_test_mem_block_size_overlap : 0; - #endif - YR_DEBUG_FPRINTF(2, stderr, - "+ %s() {} = %p = %p + 0x%" PRIx64 - " base including %" PRId64 +#if YR_DEBUG_VERBOSITY > 0 + uint64_t overlap = context->current_block.base > 0 + ? yr_test_mem_block_size_overlap + : 0; +#endif + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s() {} = %p = %p + 0x%" PRIx64 " base including %" PRId64 " overlap%s\n", __FUNCTION__, context->buffer + context->current_block.base - overlap, context->buffer, context->current_block.base, - overlap, overlap ? "" : " (note: 1st block overlap always 0)"); + overlap, + overlap ? "" : " (note: 1st block overlap always 0)"); return context->buffer + context->current_block.base; } @@ -181,13 +193,15 @@ YR_API int _yr_test_single_or_multi_block_scan_mem( if (yr_test_mem_block_size) { - YR_DEBUG_FPRINTF(2, stderr, - "+ %s(buffer=%p buffer_size=%zu) {}" - " // yr_test_mem_block_size=%" PRId64 "\n", - __FUNCTION__, - buffer, - buffer_size, - yr_test_mem_block_size); + YR_DEBUG_FPRINTF( + 2, + stderr, + "+ %s(buffer=%p buffer_size=%zu) {}" + " // yr_test_mem_block_size=%" PRId64 "\n", + __FUNCTION__, + buffer, + buffer_size, + yr_test_mem_block_size); context.buffer = buffer; context.buffer_size = buffer_size; @@ -218,7 +232,7 @@ YR_API int _yr_test_single_or_multi_block_scan_mem( void chdir_if_env_top_srcdir(void) { - char *top_srcdir = getenv("TOP_SRCDIR"); + char* top_srcdir = getenv("TOP_SRCDIR"); if (top_srcdir) { int result = chdir(top_srcdir); @@ -239,13 +253,12 @@ int count( { switch (message) { - case CALLBACK_MSG_RULE_MATCHING: - (*(struct COUNTERS*) user_data).rules_matching++; - break; - - case CALLBACK_MSG_RULE_NOT_MATCHING: - (*(struct COUNTERS*) user_data).rules_not_matching++; + case CALLBACK_MSG_RULE_MATCHING: + (*(struct COUNTERS*) user_data).rules_matching++; + break; + case CALLBACK_MSG_RULE_NOT_MATCHING: + (*(struct COUNTERS*) user_data).rules_not_matching++; } return CALLBACK_CONTINUE; } @@ -298,9 +311,7 @@ static void _compiler_callback( } -int compile_rule( - char* string, - YR_RULES** rules) +int compile_rule(char* string, YR_RULES** rules) { YR_COMPILER* compiler = NULL; int result = ERROR_SUCCESS; @@ -332,7 +343,8 @@ int compile_rule( typedef struct SCAN_CALLBACK_CTX SCAN_CALLBACK_CTX; -struct SCAN_CALLBACK_CTX { +struct SCAN_CALLBACK_CTX +{ int matches; void* module_data; size_t module_data_size; @@ -344,7 +356,7 @@ static int _scan_callback( void* message_data, void* user_data) { - SCAN_CALLBACK_CTX* ctx = (SCAN_CALLBACK_CTX*) user_data; + SCAN_CALLBACK_CTX* ctx = (SCAN_CALLBACK_CTX*) user_data; YR_MODULE_IMPORT* mi; switch (message) @@ -380,14 +392,15 @@ int matches_blob( if (compile_rule(rule, &rules) != ERROR_SUCCESS) { - fprintf(stderr, "failed to compile rule << %s >>: %s\n", rule, compile_error); + fprintf( + stderr, "failed to compile rule << %s >>: %s\n", rule, compile_error); exit(EXIT_FAILURE); } SCAN_CALLBACK_CTX ctx = { - .matches = 0, - .module_data = module_data, - .module_data_size = module_data_size, + .matches = 0, + .module_data = module_data, + .module_data_size = module_data_size, }; int scan_result = yr_rules_scan_mem( @@ -405,9 +418,7 @@ int matches_blob( } -int matches_string( - char* rule, - char* string) +int matches_string(char* rule, char* string) { size_t len = 0; @@ -445,7 +456,8 @@ static int capture_matches( yr_string_matches_foreach(context, string, match) { if (strlen(f->expected) == match->data_length && - strncmp(f->expected, (char*)(match->data), match->data_length) == 0) + strncmp(f->expected, (char*) (match->data), match->data_length) == + 0) { f->found++; } @@ -457,16 +469,14 @@ static int capture_matches( } -int capture_string( - char* rule, - char* string, - char* expected_string) +int capture_string(char* rule, char* string, char* expected_string) { YR_RULES* rules; if (compile_rule(rule, &rules) != ERROR_SUCCESS) { - fprintf(stderr, "failed to compile rule << %s >>: %s\n", rule, compile_error); + fprintf( + stderr, "failed to compile rule << %s >>: %s\n", rule, compile_error); exit(EXIT_FAILURE); } @@ -475,8 +485,14 @@ int capture_string( f.found = 0; f.expected = expected_string; - if (yr_rules_scan_mem(rules, (uint8_t*)string, strlen(string), 0, - capture_matches, &f, 0) != ERROR_SUCCESS) + if (yr_rules_scan_mem( + rules, + (uint8_t*) string, + strlen(string), + 0, + capture_matches, + &f, + 0) != ERROR_SUCCESS) { fprintf(stderr, "yr_rules_scan_mem: error\n"); exit(EXIT_FAILURE); @@ -488,9 +504,7 @@ int capture_string( } -int read_file( - char* filename, - char** buf) +int read_file(char* filename, char** buf) { int fd; @@ -521,10 +535,7 @@ int read_file( } -int _assert_atoms( - RE_AST* re_ast, - int expected_atom_count, - atom* expected_atoms) +int _assert_atoms(RE_AST* re_ast, int expected_atom_count, atom* expected_atoms) { YR_ATOMS_CONFIG c; YR_ATOM_LIST_ITEM* atoms; @@ -552,7 +563,7 @@ int _assert_atoms( } if (atom->atom.length != expected_atoms->length || - memcmp(atom->atom.bytes, expected_atoms->data, atom->atom.length) != 0) + memcmp(atom->atom.bytes, expected_atoms->data, atom->atom.length) != 0) { exit_code = EXIT_FAILURE; break; @@ -575,10 +586,7 @@ int _assert_atoms( } -void assert_re_atoms( - char* re, - int expected_atom_count, - atom* expected_atoms) +void assert_re_atoms(char* re, int expected_atom_count, atom* expected_atoms) { RE_AST* re_ast; RE_ERROR re_error; @@ -596,10 +604,7 @@ void assert_re_atoms( } -void assert_hex_atoms( - char* hex, - int expected_atom_count, - atom* expected_atoms) +void assert_hex_atoms(char* hex, int expected_atom_count, atom* expected_atoms) { RE_AST* re_ast; RE_ERROR re_error;