Index: trunk/src/common.c
===================================================================
--- trunk/src/common.c	(revision 171)
+++ trunk/src/common.c	(revision 172)
@@ -310,2 +310,29 @@
   return NULL;
 }
+
+
+static char* get_quoted_keyname(const REGFI_NK_REC* nk)
+{
+  char* ret_val;
+
+  if(nk->keyname == NULL)
+    ret_val = quote_buffer(nk->keyname_raw, nk->name_length, key_special_chars);
+  else
+    ret_val = quote_string(nk->keyname, key_special_chars);
+
+  return ret_val;
+}
+
+
+static char* get_quoted_valuename(const REGFI_VK_REC* vk)
+{
+  char* ret_val;
+
+  if(vk->valuename == NULL)
+    ret_val = quote_buffer(vk->valuename_raw, vk->name_length, 
+			   key_special_chars);
+  else
+    ret_val = quote_string(vk->valuename, key_special_chars);
+
+  return ret_val;
+}
Index: trunk/src/reglookup-recover.c
===================================================================
--- trunk/src/reglookup-recover.c	(revision 171)
+++ trunk/src/reglookup-recover.c	(revision 172)
@@ -79,5 +79,8 @@
   strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s);
 
-  quoted_name = quote_string(nk->keyname, key_special_chars);
+  /* XXX: Add command line option to choose output encoding */
+  regfi_interpret_keyname(f, nk, REGFI_ENCODING_ASCII, true);
+
+  quoted_name = get_quoted_keyname(nk);
   if (quoted_name == NULL)
   {
@@ -104,5 +107,5 @@
 
 
-void printValue(REGFI_FILE* f, const REGFI_VK_REC* vk, const char* prefix)
+void printValue(REGFI_FILE* f, REGFI_VK_REC* vk, const char* prefix)
 {
   char* quoted_value = NULL;
@@ -112,5 +115,8 @@
   const char* str_type = NULL;
 
-  quoted_name = quote_string(vk->valuename, key_special_chars);
+  /* XXX: Add command line option to choose output encoding */
+  regfi_interpret_valuename(f, vk, REGFI_ENCODING_ASCII, true);
+  
+  quoted_name = get_quoted_valuename(vk);
   if (quoted_name == NULL)
   { /* Value names are NULL when we're looking at the "(default)" value.
@@ -120,9 +126,9 @@
      * this value.
      */
-    quoted_name = malloc(1*sizeof(char));
+    quoted_name = strdup("");
     if(quoted_name == NULL)
       bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
-    quoted_name[0] = '\0';
-  }
+  }
+
   /* XXX: Add command line option to choose output encoding */
   if(vk->data != NULL 
@@ -278,7 +284,11 @@
 	path_element = talloc(path_stack, REGFI_BUFFER);
 	if(path_element != NULL)
-	  path_element->buf = (uint8_t*)quote_string(cur_ancestor->keyname, 
-						   key_special_chars);
+	{
+	  /* XXX: Add command line option to choose output encoding */
+	  regfi_interpret_keyname(f, cur_ancestor, REGFI_ENCODING_ASCII, true);
 	  
+	  path_element->buf = (uint8_t*)get_quoted_keyname(cur_ancestor);
+	}
+ 
 	if(path_element == NULL || path_element->buf == NULL 
 	   || !void_stack_push(path_stack, path_element))
@@ -929,5 +939,8 @@
     if(tmp_key->num_values > 0 && tmp_key->values != NULL)
     {
-      tmp_name = quote_string(tmp_key->keyname, key_special_chars);
+      /* XXX: Add command line option to choose output encoding */
+      regfi_interpret_keyname(f, tmp_key, REGFI_ENCODING_ASCII, true);
+
+      tmp_name = get_quoted_keyname(tmp_key);
       tmp_path = (char*)malloc(strlen(parent_paths[i])+strlen(tmp_name)+2);
       if(tmp_path == NULL)
Index: trunk/src/reglookup.c
===================================================================
--- trunk/src/reglookup.c	(revision 171)
+++ trunk/src/reglookup.c	(revision 172)
@@ -63,9 +63,5 @@
   struct tm* tmp_time_s = NULL;
 
-  if(vk->valuename == NULL)
-    quoted_name = quote_buffer(vk->valuename_raw, vk->name_length, 
-			       key_special_chars);
-  else
-    quoted_name = quote_string(vk->valuename, key_special_chars);
+  quoted_name = get_quoted_valuename(vk);
   if (quoted_name == NULL)
   { /* Value names are NULL when we're looking at the "(default)" value.
@@ -248,9 +244,5 @@
       tmp_key = cur->nk;
 
-    if(tmp_key->keyname == NULL)
-      name = quote_buffer(i->cur_key->keyname_raw, i->cur_key->name_length,
-			  key_special_chars);
-    else
-      name = quote_string(tmp_key->keyname, key_special_chars);
+    name = get_quoted_keyname(tmp_key);
 
     buf[buf_len-buf_left-1] = '/';
