[Forensics-changes] [yara] 44/407: Implement yr_rules_foreach and use it where appropriate
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:28:07 UTC 2017
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag v3.3.0
in repository yara.
commit 55ee00dc63ff14f615f87ce9f318b55f34ce2463
Author: Victor Manuel Alvarez <vmalvarez at virustotal.com>
Date: Thu Sep 18 20:33:43 2014 +0200
Implement yr_rules_foreach and use it where appropriate
---
libyara/include/yara/rules.h | 4 ++++
libyara/rules.c | 32 ++++++--------------------------
yara-python/yara-python.c | 10 ++--------
3 files changed, 12 insertions(+), 34 deletions(-)
diff --git a/libyara/include/yara/rules.h b/libyara/include/yara/rules.h
index 9114827..43cf163 100644
--- a/libyara/include/yara/rules.h
+++ b/libyara/include/yara/rules.h
@@ -49,6 +49,10 @@ limitations under the License.
for (match = STRING_MATCHES(string).head; match != NULL; match = match->next)
+#define yr_rules_foreach(rules, rule) \
+ for (rule = rules->rules_list_head; !RULE_IS_NULL(rule); rule++)
+
+
int yr_rules_scan_mem(
YR_RULES* rules,
diff --git a/libyara/rules.c b/libyara/rules.c
index 9d77a60..bea56cb 100644
--- a/libyara/rules.c
+++ b/libyara/rules.c
@@ -151,15 +151,12 @@ void _yr_rules_clean_matches(
int tidx = yr_get_tidx();
- rule = rules->rules_list_head;
-
- while (!RULE_IS_NULL(rule))
+ yr_rules_foreach(rules, rule)
{
rule->t_flags[tidx] &= ~RULE_TFLAGS_MATCH;
rule->ns->t_flags[tidx] &= ~NAMESPACE_TFLAGS_UNSATISFIED_GLOBAL;
- string = rule->strings;
- while (!STRING_IS_NULL(string))
+ yr_rule_strings_foreach(rule, string)
{
string->matches[tidx].count = 0;
string->matches[tidx].head = NULL;
@@ -167,10 +164,7 @@ void _yr_rules_clean_matches(
string->unconfirmed_matches[tidx].count = 0;
string->unconfirmed_matches[tidx].head = NULL;
string->unconfirmed_matches[tidx].tail = NULL;
- string++;
}
-
- rule++;
}
}
@@ -186,17 +180,13 @@ void yr_rules_print_profiling_info(
printf("===== PROFILING INFORMATION =====\n");
- rule = rules->rules_list_head;
-
- while (!RULE_IS_NULL(rule))
+ yr_rules_foreach(rules, rule)
{
clock_ticks = rule->clock_ticks;
- string = rule->strings;
- while (!STRING_IS_NULL(string))
+ yr_rule_strings_foreach(rule, string)
{
clock_ticks += string->clock_ticks;
- string++;
}
printf(
@@ -204,8 +194,6 @@ void yr_rules_print_profiling_info(
rule->ns->name,
rule->identifier,
clock_ticks);
-
- rule++;
}
printf("================================\n");
@@ -419,21 +407,15 @@ int yr_rules_scan_mem_blocks(
if (result != ERROR_SUCCESS)
goto _exit;
- rule = rules->rules_list_head;
-
- while (!RULE_IS_NULL(rule))
+ yr_rules_foreach(rules, rule)
{
if (RULE_IS_GLOBAL(rule) && !(rule->t_flags[tidx] & RULE_TFLAGS_MATCH))
{
rule->ns->t_flags[tidx] |= NAMESPACE_TFLAGS_UNSATISFIED_GLOBAL;
}
-
- rule++;
}
- rule = rules->rules_list_head;
-
- while (!RULE_IS_NULL(rule))
+ yr_rules_foreach(rules, rule)
{
if (rule->t_flags[tidx] & RULE_TFLAGS_MATCH &&
!(rule->ns->t_flags[tidx] & NAMESPACE_TFLAGS_UNSATISFIED_GLOBAL))
@@ -458,8 +440,6 @@ int yr_rules_scan_mem_blocks(
goto _exit;
}
}
-
- rule++;
}
callback(CALLBACK_MSG_SCAN_FINISHED, NULL, user_data);
diff --git a/yara-python/yara-python.c b/yara-python/yara-python.c
index 87a64f0..e62cfc0 100644
--- a/yara-python/yara-python.c
+++ b/yara-python/yara-python.c
@@ -1162,17 +1162,13 @@ static PyObject * Rules_profiling_info(
result = PyDict_New();
- rule = rules->rules_list_head;
-
- while (!RULE_IS_NULL(rule))
+ yr_rules_foreach(rules, rule)
{
clock_ticks = rule->clock_ticks;
- string = rule->strings;
- while (!STRING_IS_NULL(string))
+ yr_rule_strings_foreach(rule, string)
{
clock_ticks += string->clock_ticks;
- string++;
}
snprintf(key, sizeof(key), "%s:%s", rule->ns->name, rule->identifier);
@@ -1180,8 +1176,6 @@ static PyObject * Rules_profiling_info(
object = PyLong_FromLongLong(clock_ticks);
PyDict_SetItemString(result, key, object);
Py_DECREF(object);
-
- rule++;
}
return result;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/forensics/yara.git
More information about the forensics-changes
mailing list