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