[Forensics-changes] [yara] 02/02: filemap: yr_filemap_map_file (unix)
Hilko Bengen
bengen at moszumanska.debian.org
Wed Apr 8 22:52:29 UTC 2015
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch master
in repository yara.
commit b8484dbc591342d93b84d2fea512fc8c34a7eef3
Author: Hilko Bengen <bengen at debian.org>
Date: Sun Mar 15 19:01:38 2015 +0100
filemap: yr_filemap_map_file (unix)
---
libyara/filemap.c | 46 ++++++++++++++++++++++++++++------------------
1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/libyara/filemap.c b/libyara/filemap.c
index 2f73b57..2db7d34 100755
--- a/libyara/filemap.c
+++ b/libyara/filemap.c
@@ -84,7 +84,7 @@ YR_API int yr_filemap_map_file(
size_t size,
YR_MAPPED_FILE* pmapped_file)
{
- pmapped_file->file = INVALID_HANDLE_VALUE;
+ pmapped_file->file = file;
pmapped_file->mapping = NULL;
pmapped_file->data = NULL;
pmapped_file->size = 0;
@@ -187,40 +187,32 @@ YR_API int yr_filemap_map_ex(
#else // POSIX
-YR_API int yr_filemap_map_ex(
- const char* file_path,
+YR_API int yr_filemap_map_file(
+ FILEHANDLE file,
off_t offset,
size_t size,
YR_MAPPED_FILE* pmapped_file)
{
- struct stat fstat;
-
+ struct stat st;
+ pmapped_file->data = file;
pmapped_file->data = NULL;
pmapped_file->size = 0;
pmapped_file->file = -1;
- if (file_path == NULL)
- return ERROR_INVALID_ARGUMENT;
-
// Ensure that offset is aligned to 1MB
if (offset >> 20 << 20 != offset)
return ERROR_INVALID_ARGUMENT;
- if (stat(file_path, &fstat) != 0 || S_ISDIR(fstat.st_mode))
- return ERROR_COULD_NOT_OPEN_FILE;
+ if (fstat(file, &st) != 0 || S_ISDIR(st.st_mode))
+ return ERROR_COULD_NOT_OPEN_FILE;
- if (offset > fstat.st_size)
+ if (offset > st.st_size)
return ERROR_COULD_NOT_MAP_FILE;
if (size == 0)
- size = fstat.st_size - offset;
+ size = st.st_size - offset;
- pmapped_file->file = open(file_path, O_RDONLY);
-
- if (pmapped_file->file == -1)
- return ERROR_COULD_NOT_OPEN_FILE;
-
- pmapped_file->size = min(size, fstat.st_size - offset);
+ pmapped_file->size = min(size, st.st_size - offset);
if (pmapped_file->size != 0)
{
@@ -251,6 +243,24 @@ YR_API int yr_filemap_map_ex(
return ERROR_SUCCESS;
}
+YR_API int yr_filemap_map_ex(
+ const char* file_path,
+ off_t offset,
+ size_t size,
+ YR_MAPPED_FILE* pmapped_file)
+{
+ if (file_path == NULL)
+ return ERROR_INVALID_ARGUMENT;
+
+ FILEHANDLE file = open(file_path, O_RDONLY);
+
+ if (file == -1)
+ return ERROR_COULD_NOT_OPEN_FILE;
+
+ return yr_filemap_map_file(file, offset, size, pmapped_file);
+}
+
+
#endif
--
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