[Forensics-changes] [yara] 80/135: Add declare_ prefix declaration macros to avoid collision with type "string" in C++

Hilko Bengen bengen at moszumanska.debian.org
Sat Jul 1 10:27:34 UTC 2017


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag v3.1.0
in repository yara.

commit 70852a89f03a882f54198cc43bbd9aad74ac0a57
Author: Victor M. Alvarez <plusvic at gmail.com>
Date:   Thu Aug 7 13:03:38 2014 +0200

    Add declare_ prefix declaration macros to avoid collision with type "string" in C++
---
 docs/writingmodules.rst        |  59 +++++++++++------------
 libyara/include/yara/modules.h |  10 ++--
 libyara/modules/cuckoo.c       |  14 +++---
 libyara/modules/demo.c         |   2 +-
 libyara/modules/pe.c           | 105 ++++++++++++++++++++---------------------
 libyara/modules/tests.c        |  16 +++----
 6 files changed, 103 insertions(+), 103 deletions(-)

diff --git a/docs/writingmodules.rst b/docs/writingmodules.rst
index 4583956..9e6b315 100644
--- a/docs/writingmodules.rst
+++ b/docs/writingmodules.rst
@@ -38,7 +38,7 @@ as our starting point. The file looks like this:
 
     begin_declarations;
 
-      string("greeting");
+      declare_string("greeting");
 
     end_declarations;
 
@@ -84,7 +84,7 @@ Then follows the declaration section:
 
     begin_declarations;
 
-      string("greeting");
+      declare_string("greeting");
 
     end_declarations;
 
@@ -226,14 +226,14 @@ a declaration section like this::
 Basic types
 -----------
 
-Within the declaration section you can use ``string(<variable name>)`` and
-``integer(<variable name>)`` to declare string or integer variables
+Within the declaration section you can use ``declare_string(<variable name>)``
+and ``declare_integer(<variable name>)`` to declare string or integer variables
 respectively. For example::
 
     begin_declarations;
 
-        integer("foo");
-        string("bar");
+        declare_integer("foo");
+        declare_string("bar");
 
     end_declarations;
 
@@ -254,16 +254,16 @@ Your declarations can be organized in a more structured way::
 
     begin_declarations;
 
-        integer("foo");
-        string("bar");
+        declare_integer("foo");
+        declare_string("bar");
 
         begin_struct("some_structure");
 
-            integer("foo");
+            declare_integer("foo");
 
             begin_struct("nested_structure");
 
-                integer("bar");
+                declare_integer("bar");
 
             end_struct("nested_structure");
 
@@ -271,9 +271,9 @@ Your declarations can be organized in a more structured way::
 
         begin_struct("another_structure");
 
-            integer("foo");
-            string("bar");
-            string("baz")
+            declare_integer("foo");
+            declare_string("bar");
+            declare_string("baz")
 
         end_struct("another_structure");
 
@@ -302,13 +302,13 @@ declare arrays of them::
 
     begin_declarations;
 
-        integer_array("foo");
-        string_array("bar");
+        declare_integer_array("foo");
+        declare_string_array("bar");
 
         begin_struct_array("struct_array");
 
-            integer("baz");
-            string("qux");
+            declare_integer("baz");
+            declare_string("qux");
 
         end_struct_array("struct_array");
 
@@ -336,7 +336,7 @@ One of the more powerful features of YARA modules is the possibility of
 declaring functions that can be later invoked from your rules. Functions
 must appear in the declaration section in this way::
 
-    function(<function name>, <argument types>, <return tuype>, <C function>);
+    declare_function(<function name>, <argument types>, <return tuype>, <C function>);
 
 *<function name>* is the name that will be used in your YARA rules to invoke
 the function.
@@ -372,7 +372,7 @@ Here you have a full example:
 
     begin_declarations;
 
-        function("sum", "ii", "i", sum);
+        declare_function("sum", "ii", "i", sum);
 
     end_declarations;
 
@@ -416,11 +416,11 @@ structure. If you have the following declarations in a module named *mymodule*::
 
     begin_declarations;
 
-        integer("foo");
+        declare_integer("foo");
 
         begin_struct("bar");
 
-            string("baz");
+            declare_string("baz");
 
         end_struct("bar");
 
@@ -567,11 +567,11 @@ descendant of ``object``. For example, consider the following declarations::
 
         begin_struct("foo");
 
-            string("bar");
+            declare_string("bar");
 
             begin_struct("baz");
 
-                integer("qux");
+                declare_integer("qux");
 
             end_struct("baz");
 
@@ -609,12 +609,12 @@ you have the following declarations::
 
     begin_declarations;
 
-        integer_array("foo");
+        declare_integer_array("foo");
 
         begin_struct_array("bar")
 
-            string("baz");
-            integer_array("qux");
+            declare_string("baz");
+            declare_integer_array("qux");
 
         end_struct_array("bar");
 
@@ -809,11 +809,11 @@ contained. For example, consider the following code snipet:
 
     begin_declarations;
 
-        function("f1", "i", "i", f1);
+        declare_function("f1", "i", "i", f1);
 
         begin_struct("foo");
 
-            function("f2", "i", "i", f2);
+            declare_function("f2", "i", "i", f2);
 
         end_struct("foo");
 
@@ -822,7 +822,8 @@ contained. For example, consider the following code snipet:
 In ``f1`` the ``module`` variable points to the top-level ``YR_OBJECT`` as well
 as the ``parent`` variable, because the parent for ``f1`` is the module itself.
 In ``f2`` however the ``parent`` variable points to the ``YR_OBJECT``
-corresponding to the ``foo`` structure while ``module`` points to the top-level ``YR_OBJECT`` as before.
+corresponding to the ``foo`` structure while ``module`` points to the top-level
+``YR_OBJECT`` as before.
 
 Scan context
 ------------
diff --git a/libyara/include/yara/modules.h b/libyara/include/yara/modules.h
index 92ed41b..882485f 100644
--- a/libyara/include/yara/modules.h
+++ b/libyara/include/yara/modules.h
@@ -96,7 +96,7 @@ limitations under the License.
 #define end_struct_array(name) end_struct(name)
 
 
-#define integer(name) { \
+#define declare_integer(name) { \
     FAIL_ON_ERROR(yr_object_create( \
         OBJECT_TYPE_INTEGER, \
         name, \
@@ -105,7 +105,7 @@ limitations under the License.
   }
 
 
-#define integer_array(name) { \
+#define declare_integer_array(name) { \
     YR_OBJECT* array; \
     FAIL_ON_ERROR(yr_object_create( \
         OBJECT_TYPE_ARRAY, \
@@ -120,7 +120,7 @@ limitations under the License.
   }
 
 
-#define string(name) { \
+#define declare_string(name) { \
     FAIL_ON_ERROR(yr_object_create( \
         OBJECT_TYPE_STRING, \
         name, \
@@ -129,7 +129,7 @@ limitations under the License.
   }
 
 
-#define string_array(name) { \
+#define declare_string_array(name) { \
     YR_OBJECT* array; \
     FAIL_ON_ERROR(yr_object_create( \
         OBJECT_TYPE_ARRAY, \
@@ -144,7 +144,7 @@ limitations under the License.
   }
 
 
-#define function(name, args_fmt, ret_fmt, func) { \
+#define declare_function(name, args_fmt, ret_fmt, func) { \
     YR_OBJECT* function; \
     FAIL_ON_ERROR(yr_object_function_create( \
         name, \
diff --git a/libyara/modules/cuckoo.c b/libyara/modules/cuckoo.c
index 5b2e198..cc92ae8 100644
--- a/libyara/modules/cuckoo.c
+++ b/libyara/modules/cuckoo.c
@@ -193,22 +193,22 @@ define_function(sync_mutex)
 begin_declarations;
 
   begin_struct("network");
-    function("dns_lookup", "s", "i", network_dns_lookup);
-    function("http_get", "r", "i", network_http_get);
-    function("http_post", "r", "i", network_http_post);
-    function("http_request", "r", "i", network_http_request);
+    declare_function("dns_lookup", "s", "i", network_dns_lookup);
+    declare_function("http_get", "r", "i", network_http_get);
+    declare_function("http_post", "r", "i", network_http_post);
+    declare_function("http_request", "r", "i", network_http_request);
   end_struct("network");
 
   begin_struct("registry");
-    function("key_access", "r", "i", registry_key_access);
+    declare_function("key_access", "r", "i", registry_key_access);
   end_struct("registry");
 
   begin_struct("filesystem");
-    function("file_access", "r", "i", filesystem_file_access);
+    declare_function("file_access", "r", "i", filesystem_file_access);
   end_struct("filesystem");
 
   begin_struct("sync");
-    function("mutex", "r", "i", sync_mutex);
+    declare_function("mutex", "r", "i", sync_mutex);
   end_struct("sync");
 
 end_declarations;
diff --git a/libyara/modules/demo.c b/libyara/modules/demo.c
index bb82056..b908ab2 100644
--- a/libyara/modules/demo.c
+++ b/libyara/modules/demo.c
@@ -20,7 +20,7 @@ limitations under the License.
 
 begin_declarations;
 
-  string("greeting");
+  declare_string("greeting");
 
 end_declarations;
 
diff --git a/libyara/modules/pe.c b/libyara/modules/pe.c
index bc27e9e..e5e70cb 100644
--- a/libyara/modules/pe.c
+++ b/libyara/modules/pe.c
@@ -474,76 +474,75 @@ define_function(imports)
 
 begin_declarations;
 
-  integer("MACHINE_I386");
-  integer("MACHINE_AMD64");
-
-  integer("SUBSYSTEM_UNKNOWN");
-  integer("SUBSYSTEM_NATIVE");
-  integer("SUBSYSTEM_WINDOWS_GUI");
-  integer("SUBSYSTEM_WINDOWS_CUI");
-  integer("SUBSYSTEM_OS2_CUI");
-  integer("SUBSYSTEM_POSIX_CUI");
-  integer("SUBSYSTEM_NATIVE_WINDOWS");
-
-  integer("RELOCS_STRIPPED");
-  integer("EXECUTABLE_IMAGE");
-  integer("LINE_NUMS_STRIPPED");
-  integer("LOCAL_SYMS_STRIPPED");
-  integer("AGGRESIVE_WS_TRIM");
-  integer("LARGE_ADDRESS_AWARE");
-  integer("BYTES_REVERSED_LO");
-  integer("32BIT_MACHINE");
-  integer("DEBUG_STRIPPED");
-  integer("REMOVABLE_RUN_FROM_SWAP");
-  integer("NET_RUN_FROM_SWAP");
-  integer("SYSTEM");
-  integer("DLL");
-  integer("UP_SYSTEM_ONLY");
-  integer("BYTES_REVERSED_HI");
-
-  integer("machine");
-  integer("number_of_sections");
-  integer("timestamp");
-  integer("characteristics");
-
-  integer("entry_point");
-  integer("image_base");
+  declare_integer("MACHINE_I386");
+  declare_integer("MACHINE_AMD64");
+
+  declare_integer("SUBSYSTEM_UNKNOWN");
+  declare_integer("SUBSYSTEM_NATIVE");
+  declare_integer("SUBSYSTEM_WINDOWS_GUI");
+  declare_integer("SUBSYSTEM_WINDOWS_CUI");
+  declare_integer("SUBSYSTEM_OS2_CUI");
+  declare_integer("SUBSYSTEM_POSIX_CUI");
+  declare_integer("SUBSYSTEM_NATIVE_WINDOWS");
+
+  declare_integer("RELOCS_STRIPPED");
+  declare_integer("EXECUTABLE_IMAGE");
+  declare_integer("LINE_NUMS_STRIPPED");
+  declare_integer("LOCAL_SYMS_STRIPPED");
+  declare_integer("AGGRESIVE_WS_TRIM");
+  declare_integer("LARGE_ADDRESS_AWARE");
+  declare_integer("BYTES_REVERSED_LO");
+  declare_integer("32BIT_MACHINE");
+  declare_integer("DEBUG_STRIPPED");
+  declare_integer("REMOVABLE_RUN_FROM_SWAP");
+  declare_integer("NET_RUN_FROM_SWAP");
+  declare_integer("SYSTEM");
+  declare_integer("DLL");
+  declare_integer("UP_SYSTEM_ONLY");
+  declare_integer("BYTES_REVERSED_HI");
+
+  declare_integer("machine");
+  declare_integer("number_of_sections");
+  declare_integer("timestamp");
+  declare_integer("characteristics");
+
+  declare_integer("entry_point");
+  declare_integer("image_base");
 
   begin_struct("linker_version");
-    integer("major");
-    integer("minor");
+    declare_integer("major");
+    declare_integer("minor");
   end_struct("linker_version");
 
   begin_struct("os_version");
-    integer("major");
-    integer("minor");
+    declare_integer("major");
+    declare_integer("minor");
   end_struct("os_version");
 
   begin_struct("image_version");
-    integer("major");
-    integer("minor");
+    declare_integer("major");
+    declare_integer("minor");
   end_struct("image_version");
 
   begin_struct("subsystem_version");
-    integer("major");
-    integer("minor");
+    declare_integer("major");
+    declare_integer("minor");
   end_struct("subsystem_version");
 
-  integer("subsystem");
+  declare_integer("subsystem");
 
   begin_struct_array("sections");
-    string("name");
-    integer("characteristics");
-    integer("virtual_address");
-    integer("virtual_size");
-    integer("raw_data_offset");
-    integer("raw_data_size");
+    declare_string("name");
+    declare_integer("characteristics");
+    declare_integer("virtual_address");
+    declare_integer("virtual_size");
+    declare_integer("raw_data_offset");
+    declare_integer("raw_data_size");
   end_struct_array("sections");
 
-  function("section_index", "s", "i", section_index);
-  function("exports", "s", "i", exports);
-  function("imports", "ss", "i", imports);
-
+  declare_function("section_index", "s", "i", section_index);
+  declare_function("exports", "s", "i", exports);
+  declare_function("imports", "ss", "i", imports);
 
 end_declarations;
 
diff --git a/libyara/modules/tests.c b/libyara/modules/tests.c
index 1192237..b32049b 100644
--- a/libyara/modules/tests.c
+++ b/libyara/modules/tests.c
@@ -33,20 +33,20 @@ define_function(sum)
 begin_declarations;
 
   begin_struct("constants");
-    integer("one");
-    integer("two");
-    string("foo");
+    declare_integer("one");
+    declare_integer("two");
+    declare_string("foo");
   end_struct("constants");
 
-  integer_array("integer_array");
-  string_array("string_array");
+  declare_integer_array("integer_array");
+  declare_string_array("string_array");
 
   begin_struct_array("struct_array");
-    integer("i");
-    string("s");
+    declare_integer("i");
+    declare_string("s");
   end_struct_array("struct_array");
 
-  function("sum", "ii", "i", sum);
+  declare_function("sum", "ii", "i", sum);
 
 end_declarations;
 

-- 
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