[Forensics-changes] [yara] 29/192: Make yr_lex_parse_rules_fd compatible with Win32 (#520)
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:31:43 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 8ed04926e1badaffc05d15cbcaa87a8c64b9387a
Author: Hilko Bengen <hillu at users.noreply.github.com>
Date: Tue Sep 20 18:02:27 2016 +0200
Make yr_lex_parse_rules_fd compatible with Win32 (#520)
Close: #519
---
libyara/lexer.l | 14 ++++++++++++--
tests/test-rules.c | 20 +++++++++++++++++++-
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/libyara/lexer.l b/libyara/lexer.l
index 0a031b3..fca2ed7 100644
--- a/libyara/lexer.l
+++ b/libyara/lexer.l
@@ -49,7 +49,12 @@ with noyywrap then we can remove this pragma.
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+#include <fileapi.h>
+#else
#include <unistd.h>
+#endif
#include <yara/integers.h>
#include <yara/lexer.h>
@@ -831,12 +836,16 @@ int yr_lex_parse_rules_fd(
#endif
char buf[1024];
- int len;
yyset_extra(compiler, yyscanner);
while (1)
{
- len = read(rules_fd, buf, sizeof(buf));
+#if defined(_WIN32) || defined(__CYGWIN__)
+ DWORD len;
+ if (!ReadFile(rules_fd, buf, sizeof(buf), &len, NULL))
+ break;
+#else
+ int len = read(rules_fd, buf, sizeof(buf));
if (len < 0)
{
if (errno == EINTR)
@@ -844,6 +853,7 @@ int yr_lex_parse_rules_fd(
else
break;
}
+#endif
if (len == 0)
break;
yy_scan_bytes(buf, len, yyscanner);
diff --git a/tests/test-rules.c b/tests/test-rules.c
index a26c544..a3f7795 100644
--- a/tests/test-rules.c
+++ b/tests/test-rules.c
@@ -31,7 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "blob.h"
#include "util.h"
+#if defined(_WIN32) || defined(__CYGWIN__)
+#include <fileapi.h>
+#else
#include <unistd.h>
+#endif
#include <fcntl.h>
static void test_boolean_operators()
@@ -1327,11 +1331,21 @@ void test_file_descriptor()
YR_COMPILER* compiler = NULL;
YR_RULES* rules = NULL;
+#if defined(_WIN32) || defined(__CYGWIN__)
+ HANDLE fd = CreateFile("tests/data/true.yar", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
+ if (fd == INVALID_HANDLE_VALUE)
+ {
+ fputs("CreateFile failed", stderr);
+ exit(1);
+ }
+#else
int fd = open("tests/data/true.yar", O_RDONLY);
- if (fd < 0) {
+ if (fd < 0)
+ {
perror("open");
exit(EXIT_FAILURE);
}
+#endif
if (yr_compiler_create(&compiler) != ERROR_SUCCESS)
{
perror("yr_compiler_create");
@@ -1343,7 +1357,11 @@ void test_file_descriptor()
exit(EXIT_FAILURE);
}
+#if defined(_WIN32) || defined(__CYGWIN__)
+ CloseHandle(fd);
+#else
close(fd);
+#endif
if (yr_compiler_get_rules(compiler, &rules) != ERROR_SUCCESS) {
perror("yr_compiler_add_fd");
--
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