Blame SOURCES/0008-add-HIVEX_OPEN_UNSAFE-flag.patch

c1e277
From 691f5532ab4138093cdd8c661aba7519b0b1e2ad Mon Sep 17 00:00:00 2001
c1e277
From: Dawid Zamirski <dzamirski@datto.com>
c1e277
Date: Thu, 16 Feb 2017 18:17:22 -0500
c1e277
Subject: [PATCH 08/12] add HIVEX_OPEN_UNSAFE flag.
c1e277
c1e277
This flag will be used to control behavior of libhivex API functions so
c1e277
that they tolerate corruption in hives by either using heuristic
c1e277
recovery from unexpected situations or simply ignore bad registry
c1e277
keys/values whenever possible.
c1e277
c1e277
(cherry picked from commit 507f9328c67c701c32894249437551395bd8072c)
c1e277
---
c1e277
 generator/generator.ml | 8 ++++++++
c1e277
 lib/handle.c           | 1 +
c1e277
 lib/hivex-internal.h   | 1 +
c1e277
 3 files changed, 10 insertions(+)
c1e277
c1e277
diff --git a/generator/generator.ml b/generator/generator.ml
c1e277
index 64c7681..249a317 100755
c1e277
--- a/generator/generator.ml
c1e277
+++ b/generator/generator.ml
c1e277
@@ -113,6 +113,7 @@ let open_flags = [
c1e277
   1, "VERBOSE", "Verbose messages";
c1e277
   2, "DEBUG", "Debug messages";
c1e277
   4, "WRITE", "Enable writes to the hive";
c1e277
+  8, "UNSAFE", "Enable heuristics to allow read/write of corrupted hives";
c1e277
 ]
c1e277
 
c1e277
 (* The API calls. *)
c1e277
@@ -145,6 +146,13 @@ Open the hive for writing.  If omitted, the hive is read-only.
c1e277
 
c1e277
 See L<hivex(3)/WRITING TO HIVE FILES>.
c1e277
 
c1e277
+=item HIVEX_OPEN_UNSAFE
c1e277
+
c1e277
+Open the hive in unsafe mode that enables heuristics to handle corrupted hives.
c1e277
+
c1e277
+This may allow to read or write registry keys/values that appear intact in an
c1e277
+otherwise corrupted hive. Use at your own risk.
c1e277
+
c1e277
 =back";
c1e277
 
c1e277
   "close", (RErrDispose, [AHive]),
c1e277
diff --git a/lib/handle.c b/lib/handle.c
c1e277
index 3a8f09b..dff2780 100644
c1e277
--- a/lib/handle.c
c1e277
+++ b/lib/handle.c
c1e277
@@ -83,6 +83,7 @@ hivex_open (const char *filename, int flags)
c1e277
   DEBUG (2, "created handle %p", h);
c1e277
 
c1e277
   h->writable = !!(flags & HIVEX_OPEN_WRITE);
c1e277
+  h->unsafe = !!(flags & HIVEX_OPEN_UNSAFE);
c1e277
   h->filename = strdup (filename);
c1e277
   if (h->filename == NULL)
c1e277
     goto error;
c1e277
diff --git a/lib/hivex-internal.h b/lib/hivex-internal.h
c1e277
index bfd24c8..bbca215 100644
c1e277
--- a/lib/hivex-internal.h
c1e277
+++ b/lib/hivex-internal.h
c1e277
@@ -30,6 +30,7 @@ struct hive_h {
c1e277
   size_t size;
c1e277
   int msglvl;                   /* 1 = verbose, 2 or 3 = debug */
c1e277
   int writable;
c1e277
+  int unsafe;
c1e277
 
c1e277
   /* Registry file, memory mapped if read-only, or malloc'd if writing. */
c1e277
   union {
c1e277
-- 
c1e277
1.8.3.1
c1e277