[Forensics-changes] [yara] 53/192: Move yr_*toh() macros to their own header file (#542)
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:31:45 UTC 2017
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag v3.6.0
in repository yara.
commit d3b77eb1e9ee4731ea11c39fceb262cf4f2b006f
Author: Hilko Bengen <hillu at users.noreply.github.com>
Date: Mon Oct 24 11:14:44 2016 +0200
Move yr_*toh() macros to their own header file (#542)
See #541
---
libyara/exec.c | 1 +
libyara/exefiles.c | 1 +
libyara/include/yara/{utils.h => endian.h} | 80 ++----------------------------
libyara/include/yara/pe.h | 2 +-
libyara/include/yara/utils.h | 30 -----------
libyara/modules/elf.c | 1 +
libyara/modules/pe.c | 1 +
libyara/modules/pe_utils.c | 1 +
8 files changed, 9 insertions(+), 108 deletions(-)
diff --git a/libyara/exec.c b/libyara/exec.c
index 3facabd..1a347c0 100644
--- a/libyara/exec.c
+++ b/libyara/exec.c
@@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <time.h>
#include <math.h>
+#include <yara/endian.h>
#include <yara/exec.h>
#include <yara/limits.h>
#include <yara/error.h>
diff --git a/libyara/exefiles.c b/libyara/exefiles.c
index 599e397..05d1de7 100644
--- a/libyara/exefiles.c
+++ b/libyara/exefiles.c
@@ -29,6 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <limits.h>
+#include <yara/endian.h>
#include <yara/pe.h>
#include <yara/elf.h>
#include <yara/exec.h>
diff --git a/libyara/include/yara/utils.h b/libyara/include/yara/endian.h
similarity index 54%
copy from libyara/include/yara/utils.h
copy to libyara/include/yara/endian.h
index cdf5ae4..06d8c14 100644
--- a/libyara/include/yara/utils.h
+++ b/libyara/include/yara/endian.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2014. The YARA Authors. All Rights Reserved.
+Copyright (c) 2016. The YARA Authors. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
@@ -27,49 +27,10 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
-#ifndef YR_UTILS_H
-#define YR_UTILS_H
+#ifndef YR_ENDIAN_H
+#define YR_ENDIAN_H
#include <config.h>
-#include <limits.h>
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-#ifdef __cplusplus
-#define EXTERNC extern "C"
-#else
-#define EXTERNC
-#endif
-
-#if defined(__GNUC__)
-#define YR_API EXTERNC __attribute__((visibility("default")))
-#elif defined(_MSC_VER)
-#define YR_API EXTERNC __declspec(dllexport)
-#else
-#define YR_API EXTERNC
-#endif
-
-#if defined(__GNUC__)
-#define YR_ALIGN(n) __attribute__((aligned(n)))
-#elif defined(_MSC_VER)
-#define YR_ALIGN(n) __declspec(align(n))
-#else
-#define YR_ALIGN(n)
-#endif
-
-#define yr_min(x, y) ((x < y) ? (x) : (y))
-#define yr_max(x, y) ((x > y) ? (x) : (y))
#if defined(__GNUC__)
#define yr_bswap16(x) __builtin_bswap16(x)
@@ -99,39 +60,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define yr_be64toh(x) yr_bswap64(x)
#endif
-
-#ifdef NDEBUG
-
-#define assertf(expr, msg, ...) ((void)0)
-
-#else
-
-#include <stdlib.h>
-
-#define assertf(expr, msg, ...) \
- if(!(expr)) { \
- fprintf(stderr, "%s:%d: " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
- abort(); \
- }
-
-#endif
-
-// Set, unset, and test bits in an array of unsigned characters by integer
-// index. The underlying array must be of type char or unsigned char to
-// 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))))
-
-#define YR_BITARRAY_UNSET(uchar_array_base, bitnum) \
- (((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_NCHARS(bitnum) \
- (((bitnum)+(CHAR_BIT-1))/CHAR_BIT)
-
#endif
diff --git a/libyara/include/yara/pe.h b/libyara/include/yara/pe.h
index 0291cb0..c189146 100644
--- a/libyara/include/yara/pe.h
+++ b/libyara/include/yara/pe.h
@@ -30,8 +30,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef YR_PE_H
#define YR_PE_H
+#include <yara/endian.h>
#include <yara/types.h>
-#include <yara/utils.h>
#pragma pack(push, 1)
diff --git a/libyara/include/yara/utils.h b/libyara/include/yara/utils.h
index cdf5ae4..f9aca5f 100644
--- a/libyara/include/yara/utils.h
+++ b/libyara/include/yara/utils.h
@@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef YR_UTILS_H
#define YR_UTILS_H
-#include <config.h>
#include <limits.h>
#ifndef TRUE
@@ -71,35 +70,6 @@ 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))
-#if defined(__GNUC__)
-#define yr_bswap16(x) __builtin_bswap16(x)
-#define yr_bswap32(x) __builtin_bswap32(x)
-#define yr_bswap64(x) __builtin_bswap64(x)
-#elif defined(_MSC_VER)
-#define yr_bswap16(x) _byteswap_ushort(x)
-#define yr_bswap32(x) _byteswap_ulong(x)
-#define yr_bswap64(x) _byteswap_uint64(x)
-#else
-#error Unknown compiler: Add yr_bswap* definitions
-#endif
-
-#if defined(WORDS_BIGENDIAN)
-#define yr_le16toh(x) yr_bswap16(x)
-#define yr_le32toh(x) yr_bswap32(x)
-#define yr_le64toh(x) yr_bswap64(x)
-#define yr_be16toh(x) (x)
-#define yr_be32toh(x) (x)
-#define yr_be64toh(x) (x)
-#else
-#define yr_le16toh(x) (x)
-#define yr_le32toh(x) (x)
-#define yr_le64toh(x) (x)
-#define yr_be16toh(x) yr_bswap16(x)
-#define yr_be32toh(x) yr_bswap32(x)
-#define yr_be64toh(x) yr_bswap64(x)
-#endif
-
-
#ifdef NDEBUG
#define assertf(expr, msg, ...) ((void)0)
diff --git a/libyara/modules/elf.c b/libyara/modules/elf.c
index 08c3ce4..e934084 100644
--- a/libyara/modules/elf.c
+++ b/libyara/modules/elf.c
@@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <limits.h>
#include <yara/elf.h>
+#include <yara/endian.h>
#include <yara/modules.h>
#include <yara/mem.h>
diff --git a/libyara/modules/pe.c b/libyara/modules/pe.c
index e8d4e13..a2cc6bd 100644
--- a/libyara/modules/pe.c
+++ b/libyara/modules/pe.c
@@ -47,6 +47,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif
#endif
+#include <yara/endian.h>
#include <yara/pe.h>
#include <yara/modules.h>
#include <yara/mem.h>
diff --git a/libyara/modules/pe_utils.c b/libyara/modules/pe_utils.c
index 9b80286..dddbba3 100644
--- a/libyara/modules/pe_utils.c
+++ b/libyara/modules/pe_utils.c
@@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h>
+#include <yara/endian.h>
#include <yara/utils.h>
#include <yara/strutils.h>
#include <yara/mem.h>
--
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