Blame SOURCES/0011-hivexsh-add-u-flag-for-HIVEX_OPEN_UNSAFE.patch

c1e277
From d4f5c255832391ba6132959d1ded57ce9286e7d6 Mon Sep 17 00:00:00 2001
c1e277
From: Dawid Zamirski <dzamirski@datto.com>
c1e277
Date: Thu, 16 Feb 2017 18:17:25 -0500
c1e277
Subject: [PATCH 11/12] hivexsh: add -u flag for HIVEX_OPEN_UNSAFE.
c1e277
c1e277
and pass it to hivex_open. Additionally make hivex_value_value failures
c1e277
non-critical in this mode when iterating through node children/values.
c1e277
c1e277
(cherry picked from commit 62c53cda651f34f18a2b55e91012c0448acb70f1)
c1e277
---
c1e277
 sh/hivexsh.c | 26 ++++++++++++++++++++------
c1e277
 1 file changed, 20 insertions(+), 6 deletions(-)
c1e277
c1e277
diff --git a/sh/hivexsh.c b/sh/hivexsh.c
c1e277
index f578ccc..39ab9d0 100644
c1e277
--- a/sh/hivexsh.c
c1e277
+++ b/sh/hivexsh.c
c1e277
@@ -67,6 +67,7 @@
c1e277
 
c1e277
 static int quit = 0;
c1e277
 static int is_tty;
c1e277
+static int unsafe = 0;
c1e277
 static hive_h *h = NULL;
c1e277
 static char *prompt_string = NULL; /* Normal prompt string. */
c1e277
 static char *loaded = NULL;     /* Basename of loaded file, if any. */
c1e277
@@ -97,7 +98,7 @@ static int cmd_setval (char *args);
c1e277
 static void
c1e277
 usage (void)
c1e277
 {
c1e277
-  fprintf (stderr, "hivexsh [-dfw] [hivefile]\n");
c1e277
+  fprintf (stderr, "hivexsh [-dfwu] [hivefile]\n");
c1e277
   exit (EXIT_FAILURE);
c1e277
 }
c1e277
 
c1e277
@@ -115,7 +116,7 @@ main (int argc, char *argv[])
c1e277
 
c1e277
   set_prompt_string ();
c1e277
 
c1e277
-  while ((c = getopt (argc, argv, "df:w")) != EOF) {
c1e277
+  while ((c = getopt (argc, argv, "df:wu")) != EOF) {
c1e277
     switch (c) {
c1e277
     case 'd':
c1e277
       open_flags |= HIVEX_OPEN_DEBUG;
c1e277
@@ -126,6 +127,10 @@ main (int argc, char *argv[])
c1e277
     case 'w':
c1e277
       open_flags |= HIVEX_OPEN_WRITE;
c1e277
       break;
c1e277
+    case 'u':
c1e277
+      open_flags |= HIVEX_OPEN_UNSAFE;
c1e277
+      unsafe = 1;
c1e277
+      break;
c1e277
     default:
c1e277
       usage ();
c1e277
     }
c1e277
@@ -771,6 +776,7 @@ cmd_lsval (char *key)
c1e277
 
c1e277
       hive_type t;
c1e277
       size_t len;
c1e277
+
c1e277
       if (hivex_value_type (h, values[i], &t, &len) == -1)
c1e277
         goto error;
c1e277
 
c1e277
@@ -779,8 +785,12 @@ cmd_lsval (char *key)
c1e277
       case hive_t_expand_string:
c1e277
       case hive_t_link: {
c1e277
         char *str = hivex_value_string (h, values[i]);
c1e277
-        if (!str)
c1e277
-          goto error;
c1e277
+        if (!str) {
c1e277
+          if (unsafe)
c1e277
+            continue;
c1e277
+          else
c1e277
+            goto error;
c1e277
+        }
c1e277
 
c1e277
         if (t != hive_t_string)
c1e277
           printf ("str(%d):", t);
c1e277
@@ -813,8 +823,12 @@ cmd_lsval (char *key)
c1e277
       default: {
c1e277
         unsigned char *data =
c1e277
           (unsigned char *) hivex_value_value (h, values[i], &t, &len;;
c1e277
-        if (!data)
c1e277
-          goto error;
c1e277
+        if (!data) {
c1e277
+          if (unsafe)
c1e277
+            continue;
c1e277
+          else
c1e277
+            goto error;
c1e277
+        }
c1e277
 
c1e277
         printf ("hex(%d):", t);
c1e277
         size_t j;
c1e277
-- 
c1e277
1.8.3.1
c1e277