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