diff --git a/.gitignore b/.gitignore
index 40a4780..7babb51 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,6 +67,7 @@ ocaml/t/hivex_010_open
 ocaml/t/hivex_020_root
 ocaml/t/hivex_100_errors
 ocaml/t/hivex_110_gc_handle
+ocaml/t/hivex_120_fold_rlenvalue
 ocaml/t/hivex_200_write
 ocaml/t/hivex_300_fold
 perl/blib
diff --git a/generator/generator.ml b/generator/generator.ml
index def516f..817fd8e 100755
--- a/generator/generator.ml
+++ b/generator/generator.ml
@@ -51,6 +51,7 @@ and ret =
   | RNodeList                           (* Returns hive_node_h* or NULL. *)
   | RValue                              (* Returns hive_value_h or 0. *)
   | RValueList                          (* Returns hive_value_h* or NULL. *)
+  | RLenValue                           (* Returns offset and length of value. *)
   | RString                             (* Returns char* or NULL. *)
   | RStringList                         (* Returns char** or NULL. *)
   | RLenType                            (* See hivex_value_type. *)
@@ -272,6 +273,17 @@ Return the length of the node data structure.";
     "\
 Return the length of the value data structure.";
 
+  "value_data_cell_offset", (RLenValue, [AHive; AValue "val"]),
+    "return the offset and length of a value data cell",
+    "\
+Return the offset and length of the value's data cell, not value cell.
+E.g. if the value were \"foobar\" then the length would be 6, and the
+offset would be to a value data cell, which is the data prefixed with
+4 bytes describing the size.  If the length is not greater than 4,
+then 0 is returned, as the data are inline in the value.
+
+Returns 0 and sets errno on error.";
+
   "value_value", (RLenTypeVal, [AHive; AValue "val"]),
     "return data length, data type and data of a value",
     "\
@@ -888,6 +900,7 @@ and generate_c_prototype ?(extern = false) name style =
    | RValueList -> pr "hive_value_h *"
    | RString -> pr "char *"
    | RStringList -> pr "char **"
+   | RLenValue -> pr "hive_value_h "
    | RLenType -> pr "int "
    | RLenTypeVal -> pr "char *"
    | RInt32 -> pr "int32_t "
@@ -909,6 +922,7 @@ and generate_c_prototype ?(extern = false) name style =
   ) (snd style);
   (match fst style with
    | RLenType | RLenTypeVal -> pr ", hive_type *t, size_t *len"
+   | RLenValue -> pr ", size_t *len"
    | _ -> ()
   );
   pr ");\n"
@@ -1111,6 +1125,10 @@ On error this returns NULL and sets errno.\n\n"
            pr "\
 Returns 0 on success.
 On error this returns -1 and sets errno.\n\n"
+       | RLenValue ->
+           pr "\
+Returns a value handle.
+On error this returns 0 and sets errno.\n\n"
        | RLenTypeVal ->
            pr "\
 The value is returned as an array of bytes (of length C<len>).
@@ -1622,6 +1640,7 @@ and generate_ocaml_prototype ?(is_external = false) name style =
    | RString -> pr "string"
    | RStringList -> pr "string array"
    | RLenType -> pr "hive_type * int"
+   | RLenValue -> pr "value"
    | RLenTypeVal -> pr "hive_type * string"
    | RInt32 -> pr "int32"
    | RInt64 -> pr "int64"
@@ -1685,6 +1704,7 @@ static hive_type HiveType_val (value);
 static value Val_hive_type (hive_type);
 static value copy_int_array (size_t *);
 static value copy_type_len (size_t, hive_type);
+static value copy_value_len (hive_value_h, size_t);
 static value copy_type_value (const char *, size_t, hive_type);
 static void raise_error (const char *) Noreturn;
 static void raise_closed (const char *) Noreturn;
@@ -1707,6 +1727,7 @@ static void raise_closed (const char *) Noreturn;
       let c_params =
         match fst style with
         | RLenType | RLenTypeVal -> c_params @ [["&t"; "&len"]]
+        | RLenValue -> c_params @ [["&len"]]
         | _ -> c_params in
       let c_params = List.concat c_params in
 
@@ -1779,6 +1800,10 @@ static void raise_closed (const char *) Noreturn;
             pr "  size_t len;\n";
             pr "  hive_type t;\n";
             "-1"
+        | RLenValue ->
+            pr "  hive_value_h r;\n";
+            pr "  size_t len;\n";
+            "0 && errno != 0"
         | RLenTypeVal ->
             pr "  char *r;\n";
             pr "  size_t len;\n";
@@ -1859,6 +1884,7 @@ static void raise_closed (const char *) Noreturn;
            pr "  for (int i = 0; r[i] != NULL; ++i) free (r[i]);\n";
            pr "  free (r);\n"
        | RLenType -> pr "  rv = copy_type_len (len, t);\n"
+       | RLenValue -> pr "  rv = copy_value_len (r, len);\n"
        | RLenTypeVal ->
            pr "  rv = copy_type_value (r, len, t);\n";
            pr "  free (r);\n"
@@ -1924,7 +1950,7 @@ static hive_type
 HiveType_val (value v)
 {
   if (Is_long (v))
-    return Int_val (v); /* REG_NONE etc. */
+    return Int_val (v); /* REG_NONE etc. */ //AJN Bug?
   else
     return Int32_val (Field (v, 0)); /* REG_UNKNOWN of int32 */
 }
@@ -1981,6 +2007,20 @@ copy_type_len (size_t len, hive_type t)
 }
 
 static value
+copy_value_len (hive_value_h r, size_t len)
+{
+  CAMLparam0 ();
+  CAMLlocal2 (v, rv);
+
+  rv = caml_alloc (2, 0);
+  v = Val_int (r);
+  Store_field (rv, 0, v);
+  v = Val_int (len);
+  Store_field (rv, 1, v);
+  CAMLreturn (rv);
+}
+
+static value
 copy_type_value (const char *r, size_t len, hive_type t)
 {
   CAMLparam0 ();
@@ -2170,6 +2210,7 @@ sub open {
 	 | RString
 	 | RStringList
 	 | RLenType
+	 | RLenValue
 	 | RLenTypeVal
 	 | RInt32
 	 | RInt64 -> ()
@@ -2244,6 +2285,7 @@ and generate_perl_prototype name style =
    | RString -> pr "$string = "
    | RStringList -> pr "@strings = "
    | RLenType -> pr "($type, $len) = "
+   | RLenValue -> pr "($len) = "
    | RLenTypeVal -> pr "($type, $data) = "
    | RInt32 -> pr "$int32 = "
    | RInt64 -> pr "$int64 = "
@@ -2467,6 +2509,7 @@ DESTROY (h)
 	 | RValueList
 	 | RStringList
 	 | RLenType
+	 | RLenValue
 	 | RLenTypeVal -> pr "void\n"
 	 | RInt32 -> pr "SV *\n"
 	 | RInt64 -> pr "SV *\n"
@@ -2639,6 +2682,20 @@ DESTROY (h)
 	     pr "      PUSHs (sv_2mortal (newSViv (type)));\n";
 	     pr "      PUSHs (sv_2mortal (newSViv (len)));\n";
 
+	 | RLenValue ->
+	     pr "PREINIT:\n";
+	     pr "      hive_value_h r;\n";
+	     pr "      size_t len;\n";
+	     pr " PPCODE:\n";
+             pr "      r = hivex_%s (%s, &len);\n"
+	       name (String.concat ", " c_params);
+	     free_args ();
+             pr "      if (r == 0)\n";
+             pr "        croak (\"%%s: \", \"%s\", strerror (errno));\n"
+	       name;
+	     pr "      EXTEND (SP, 2);\n";
+	     pr "      PUSHs (sv_2mortal (newSViv (len)));\n";
+
 	 | RLenTypeVal ->
 	     pr "PREINIT:\n";
 	     pr "      char *r;\n";
@@ -2877,6 +2934,14 @@ put_len_type (size_t len, hive_type t)
 }
 
 static PyObject *
+put_len (size_t len)
+{
+  PyObject *r = PyTuple_New (1);
+  PyTuple_SetItem (r, 0, PyLong_FromLongLong ((long) len));
+  return r;
+}
+
+static PyObject *
 put_val_type (char *val, size_t len, hive_type t)
 {
   PyObject *r = PyTuple_New (2);
@@ -2916,6 +2981,10 @@ put_val_type (char *val, size_t len, hive_type t)
             pr "  size_t len;\n";
             pr "  hive_type t;\n";
             "-1"
+        | RLenValue ->
+            pr "  int r;\n";
+            pr "  size_t len;\n";
+            "0 && errno != 0"
         | RLenTypeVal ->
             pr "  char *r;\n";
             pr "  size_t len;\n";
@@ -2940,6 +3009,7 @@ put_val_type (char *val, size_t len, hive_type t)
       let c_params =
         match fst style with
         | RLenType | RLenTypeVal -> c_params @ ["&t"; "&len"]
+        | RLenValue -> c_params @ ["&len"]
         | _ -> c_params in
 
       List.iter (
@@ -3084,6 +3154,8 @@ put_val_type (char *val, size_t len, hive_type t)
            pr "  free_strings (r);\n"
        | RLenType ->
            pr "  py_r = put_len_type (len, t);\n"
+       | RLenValue ->
+           pr "  py_r = put_len (len);\n"
        | RLenTypeVal ->
            pr "  py_r = put_val_type (r, len, t);\n";
            pr "  free (r);\n"
@@ -3294,6 +3366,7 @@ get_values (VALUE valuesv, size_t *nr_values)
           | RString -> "string"
           | RStringList -> "list"
           | RLenType -> "hash"
+          | RLenValue -> "integer"
           | RLenTypeVal -> "hash"
           | RInt32 -> "integer"
           | RInt64 -> "integer" in
@@ -3392,6 +3465,10 @@ get_values (VALUE valuesv, size_t *nr_values)
             pr "  size_t len;\n";
             pr "  hive_type t;\n";
             "-1"
+        | RLenValue ->
+            pr "  hive_value_h r;\n";
+            pr "  size_t len;\n";
+            "0 && errno != 0"
         | RLenTypeVal ->
             pr "  char *r;\n";
             pr "  size_t len;\n";
@@ -3416,6 +3493,7 @@ get_values (VALUE valuesv, size_t *nr_values)
       let c_params =
         match ret with
         | RLenType | RLenTypeVal -> c_params @ [["&t"; "&len"]]
+        | RLenValue -> c_params @ [["&len"]]
         | _ -> c_params in
       let c_params = List.concat c_params in
 
@@ -3497,6 +3575,11 @@ get_values (VALUE valuesv, size_t *nr_values)
         pr "  rb_hash_aset (rv, ID2SYM (rb_intern (\"len\")), INT2NUM (len));\n";
         pr "  rb_hash_aset (rv, ID2SYM (rb_intern (\"type\")), INT2NUM (t));\n";
         pr "  return rv;\n"
+      | RLenValue ->
+        pr "  VALUE rv = rb_hash_new ();\n";
+        pr "  rb_hash_aset (rv, ID2SYM (rb_intern (\"len\")), INT2NUM (len));\n";
+        pr "  rb_hash_aset (rv, ID2SYM (rb_intern (\"value\")), ULL2NUM (r));\n";
+        pr "  return rv;\n"
       | RLenTypeVal ->
         pr "  VALUE rv = rb_hash_new ();\n";
         pr "  rb_hash_aset (rv, ID2SYM (rb_intern (\"len\")), INT2NUM (len));\n";
diff --git a/lib/hivex.c b/lib/hivex.c
index bf1a860..0363454 100644
--- a/lib/hivex.c
+++ b/lib/hivex.c
@@ -1257,6 +1257,63 @@ hivex_value_type (hive_h *h, hive_value_h value, hive_type *t, size_t *len)
   return 0;
 }
 
+hive_value_h
+hivex_value_data_cell_offset (hive_h *h, hive_value_h value, size_t *len)
+{
+  if (!IS_VALID_BLOCK (h, value) || !BLOCK_ID_EQ (h, value, "vk")) {
+    errno = EINVAL;
+    return 0;
+  }
+
+  if (h->msglvl >= 2)
+    fprintf (stderr, "hivex_data_cell_offset: value=0x%zx\n", value);
+  struct ntreg_vk_record *vk = (struct ntreg_vk_record *) (h->addr + value);
+
+  size_t data_len;
+  int is_inline;
+
+  data_len = le32toh (vk->data_len);
+  is_inline = !!(data_len & 0x80000000);
+  data_len &= 0x7fffffff;
+
+  if (h->msglvl >= 2)
+    fprintf (stderr, "hivex_data_cell_offset: is_inline=%d\n", is_inline);
+
+  if (h->msglvl >= 2)
+    fprintf (stderr, "hivex_data_cell_offset: data_len=%zx\n", data_len);
+
+  if (is_inline && data_len > 4) {
+    errno = ENOTSUP;
+    return 0;
+  }
+
+  if (is_inline) {
+    /* There is no other location for the value data. */
+    if (len)
+      *len = 0;
+    return 0;
+  } else {
+    if (len)
+      *len = data_len + 4;  /* Include 4 header length bytes */
+  }
+
+  size_t data_offset = le32toh (vk->data_offset);
+  data_offset += 0x1000;  /* Add 0x1000 because everything's off by 4KiB */
+  if (!IS_VALID_BLOCK (h, data_offset)) {
+    if (h->msglvl >= 2)
+      fprintf (stderr, "hivex_value_data_cell_offset: returning EFAULT because data "
+               "offset is not a valid block (0x%zx)\n",
+               data_offset);
+    errno = EFAULT;
+    return 0;
+  }
+
+  if (h->msglvl >= 2)
+    fprintf (stderr, "hivex_data_cell_offset: data_offset=%zx\n", data_offset);
+
+  return data_offset;
+}
+
 char *
 hivex_value_value (hive_h *h, hive_value_h value,
                    hive_type *t_rtn, size_t *len_rtn)
diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
index ca4c111..eb49431 100644
--- a/ocaml/Makefile.am
+++ b/ocaml/Makefile.am
@@ -59,6 +59,7 @@ TESTS = \
 	t/hivex_020_root \
 	t/hivex_100_errors \
 	t/hivex_110_gc_handle \
+	t/hivex_120_rlenvalue \
 	t/hivex_200_write \
 	t/hivex_300_fold
 noinst_DATA += $(TESTS)
diff --git a/ocaml/t/hivex_120_rlenvalue.ml b/ocaml/t/hivex_120_rlenvalue.ml
new file mode 100644
index 0000000..14ba2c8
--- /dev/null
+++ b/ocaml/t/hivex_120_rlenvalue.ml
@@ -0,0 +1,37 @@
+(* hivex OCaml bindings
+ * Copyright (C) 2009-2010 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *)
+
+(* Demonstrate value_data_cell_offset by looking at the value at
+ * "\$$$\PROTO.HIV\A\A", verified to be at file offset 297680 (0x48ad0)
+ * of the large test hive. *)
+
+open Unix
+open Printf
+let (//) = Filename.concat
+
+let () =
+  let h = Hivex.open_file ("../images/large") [] in
+  let (data_off, data_len) = Hivex.value_data_cell_offset h (297680:Hivex.value) in
+  printf "Offset and length of value data for value metadata at offset 297680 is %d, %d.\n" (data_off:int) (data_len:int);
+
+  Hivex.close h;
+
+  (* Gc.compact is a good way to ensure we don't have
+   * heap corruption or double-freeing.
+   *)
+  Gc.compact ()
diff --git a/python/t/220-rlenvalue.py b/python/t/220-rlenvalue.py
new file mode 100644
index 0000000..f469c18
--- /dev/null
+++ b/python/t/220-rlenvalue.py
@@ -0,0 +1,59 @@
+# hivex Python bindings
+# Copyright (C) 2010 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+import os
+import hivex
+
+srcdir = os.environ["srcdir"]
+if not srcdir:
+    srcdir = "."
+
+h = hivex.Hivex ("%s/../images/minimal" % srcdir,
+                 write = True, debug = True)
+assert h
+
+root = h.root ()
+assert root
+
+h.node_add_child (root, "B")
+
+b = h.node_get_child (root, "B")
+assert b
+
+values = [
+    { "key": "Key1", "t": 3, "value": "ABC" },
+    { "key": "Key2", "t": 3, "value": "DEF" }
+]
+h.node_set_values (b, values)
+
+value1 = { "key": "Key3", "t": 3, "value": "GHI" }
+h.node_set_value (b, value1)
+
+value1 = { "key": "Key1", "t": 3, "value": "JKL" }
+h.node_set_value (b, value1)
+
+val = h.node_get_value (b, "Key1")
+t_data = h.value_value (val)
+assert t_data[0] == 3
+assert t_data[1] == "JKL"
+
+val = h.node_get_value (b, "Key3")
+t_data = h.value_value (val)
+assert t_data[0] == 3
+assert t_data[1] == "GHI"
+
+r = h.value_data_cell_offset (val)
diff --git a/ruby/tests/tc_030_RLenValue.rb b/ruby/tests/tc_030_RLenValue.rb
new file mode 100644
index 0000000..3dcb6e0
--- /dev/null
+++ b/ruby/tests/tc_030_RLenValue.rb
@@ -0,0 +1,46 @@
+# hivex Ruby bindings -*- ruby -*-
+# Copyright (C) 2009-2011 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+require 'test/unit'
+$:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
+$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "hivex"))
+require 'hivex'
+
+class TestRLenValue < Test::Unit::TestCase
+  def test_RLenValue
+    h = Hivex::open("../images/minimal", {:write => 1, :debug => 1})
+    assert_not_nil (h)
+
+    root = h.root()
+    assert (root)
+
+    values = [
+              { :key => "Key1", :type => 3, :value => "ABC" },
+              { :key => "Key2", :type => 3, :value => "DEF" }
+             ]
+    h.node_set_values(root, values)
+
+    values = h.node_values(root)
+    puts values
+    puts values[0]
+    r = h.value_data_cell_offset(values[0])
+    #puts r
+    # Don't actually commit here because that would overwrite
+    # the original file.
+    # h.commit()
+  end
+end
diff --git a/xml/hivexml.c b/xml/hivexml.c
index 5030c24..278e8de 100644
--- a/xml/hivexml.c
+++ b/xml/hivexml.c
@@ -208,6 +208,33 @@ filetime_to_8601 (int64_t windows_ticks)
   return ret;
 }
 
+#define BYTE_RUN_BUF_LEN 32
+
+static int
+node_byte_runs (hive_h *h, void *writer_v, hive_node_h node)
+{
+  xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
+  char buf[1+BYTE_RUN_BUF_LEN];
+  size_t node_struct_length = hivex_node_struct_length (h, node);
+  if (errno) {
+    if (errno == EINVAL) {
+      fprintf (stderr, "node_byte_runs: Invoked on what does not seem to be a node (%zu).\n", node);
+    }
+    return -1;
+  }
+  /* A node has one byte run. */
+  XML_CHECK (xmlTextWriterStartElement, (writer, BAD_CAST "byte_runs"));
+  XML_CHECK (xmlTextWriterStartElement, (writer, BAD_CAST "byte_run"));
+  memset (buf, 0, 1+BYTE_RUN_BUF_LEN);
+  snprintf (buf, 1+BYTE_RUN_BUF_LEN, "%d", node);
+  XML_CHECK (xmlTextWriterWriteAttribute, (writer, BAD_CAST "file_offset", BAD_CAST buf));
+  snprintf (buf, 1+BYTE_RUN_BUF_LEN, "%d", node_struct_length);
+  XML_CHECK (xmlTextWriterWriteAttribute, (writer, BAD_CAST "len", BAD_CAST buf));
+  XML_CHECK (xmlTextWriterEndElement, (writer));
+  XML_CHECK (xmlTextWriterEndElement, (writer));
+  return 0;
+}
+
 static int
 node_start (hive_h *h, void *writer_v, hive_node_h node, const char *name)
 {
@@ -234,7 +261,8 @@ node_start (hive_h *h, void *writer_v, hive_node_h node, const char *name)
     }
   }
 
-  return 0;
+  ret = node_byte_runs (h, writer_v, node);
+  return ret;
 }
 
 static int
@@ -266,11 +294,52 @@ end_value (xmlTextWriterPtr writer)
 }
 
 static int
+value_byte_runs (hive_h *h, void *writer_v, hive_value_h value) {
+  xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
+  char buf[1+BYTE_RUN_BUF_LEN];
+  size_t value_data_cell_length;
+  size_t value_data_structure_length = hivex_value_struct_length (h, value);
+  if (errno != 0) {
+    if (errno == EINVAL) {
+      fprintf (stderr, "value_byte_runs: Invoked on what does not seem to be a value (%zu).\n", value);
+    }
+    return -1;
+  }
+  hive_value_h value_data_cell_offset = hivex_value_data_cell_offset (h, value, &value_data_cell_length);
+  if (errno != 0)
+    return -1;
+
+  XML_CHECK (xmlTextWriterStartElement, (writer, BAD_CAST "byte_runs"));
+  memset (buf, 0, 1+BYTE_RUN_BUF_LEN);
+
+  /* Write first byte run for data structure */
+  XML_CHECK (xmlTextWriterStartElement, (writer, BAD_CAST "byte_run"));
+  snprintf (buf, 1+BYTE_RUN_BUF_LEN, "%d", value);
+  XML_CHECK (xmlTextWriterWriteAttribute, (writer, BAD_CAST "file_offset", BAD_CAST buf));
+  snprintf (buf, 1+BYTE_RUN_BUF_LEN, "%d", value_data_structure_length);
+  XML_CHECK (xmlTextWriterWriteAttribute, (writer, BAD_CAST "len", BAD_CAST buf));
+  XML_CHECK (xmlTextWriterEndElement, (writer));
+
+  /* Write second byte run for longer values */
+  if (value_data_cell_length > 4) {
+    XML_CHECK (xmlTextWriterStartElement, (writer, BAD_CAST "byte_run"));
+    snprintf (buf, 1+BYTE_RUN_BUF_LEN, "%d", value_data_cell_offset);
+    XML_CHECK (xmlTextWriterWriteAttribute, (writer, BAD_CAST "file_offset", BAD_CAST buf));
+    snprintf (buf, 1+BYTE_RUN_BUF_LEN, "%d", value_data_cell_length);
+    XML_CHECK (xmlTextWriterWriteAttribute, (writer, BAD_CAST "len", BAD_CAST buf));
+    XML_CHECK (xmlTextWriterEndElement, (writer));
+  }
+  XML_CHECK (xmlTextWriterEndElement, (writer));
+  return 0;
+}
+
+static int
 value_string (hive_h *h, void *writer_v, hive_node_h node, hive_value_h value,
               hive_type t, size_t len, const char *key, const char *str)
 {
   xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
   const char *type;
+  int ret = 0;
 
   switch (t) {
   case hive_t_string: type = "string"; break;
@@ -296,8 +365,9 @@ value_string (hive_h *h, void *writer_v, hive_node_h node, hive_value_h value,
   XML_CHECK (xmlTextWriterStartAttribute, (writer, BAD_CAST "value"));
   XML_CHECK (xmlTextWriterWriteString, (writer, BAD_CAST str));
   XML_CHECK (xmlTextWriterEndAttribute, (writer));
+  ret = value_byte_runs (h, writer_v, value);
   end_value (writer);
-  return 0;
+  return ret;
 }
 
 static int
@@ -306,6 +376,7 @@ value_multiple_strings (hive_h *h, void *writer_v, hive_node_h node,
                         const char *key, char **argv)
 {
   xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
+  int ret = 0;
   start_value (writer, key, "string-list", NULL);
 
   size_t i;
@@ -315,8 +386,9 @@ value_multiple_strings (hive_h *h, void *writer_v, hive_node_h node,
     XML_CHECK (xmlTextWriterEndElement, (writer));
   }
 
+  ret = value_byte_runs (h, writer_v, value);
   end_value (writer);
-  return 0;
+  return ret;
 }
 
 static int
@@ -327,6 +399,7 @@ value_string_invalid_utf16 (hive_h *h, void *writer_v, hive_node_h node,
 {
   xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
   const char *type;
+  int ret = 0;
 
   switch (t) {
   case hive_t_string: type = "bad-string"; break;
@@ -352,9 +425,10 @@ value_string_invalid_utf16 (hive_h *h, void *writer_v, hive_node_h node,
   XML_CHECK (xmlTextWriterStartAttribute, (writer, BAD_CAST "value"));
   XML_CHECK (xmlTextWriterWriteBase64, (writer, str, 0, len));
   XML_CHECK (xmlTextWriterEndAttribute, (writer));
+  ret = value_byte_runs (h, writer_v, value);
   end_value (writer);
 
-  return 0;
+  return ret;
 }
 
 static int
@@ -362,10 +436,12 @@ value_dword (hive_h *h, void *writer_v, hive_node_h node, hive_value_h value,
              hive_type t, size_t len, const char *key, int32_t v)
 {
   xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
+  int ret = 0;
   start_value (writer, key, "int32", NULL);
   XML_CHECK (xmlTextWriterWriteFormatAttribute, (writer, BAD_CAST "value", "%" PRIi32, v));
+  ret = value_byte_runs (h, writer_v, value);
   end_value (writer);
-  return 0;
+  return ret;
 }
 
 static int
@@ -373,10 +449,12 @@ value_qword (hive_h *h, void *writer_v, hive_node_h node, hive_value_h value,
              hive_type t, size_t len, const char *key, int64_t v)
 {
   xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
+  int ret = 0;
   start_value (writer, key, "int64", NULL);
   XML_CHECK (xmlTextWriterWriteFormatAttribute, (writer, BAD_CAST "value", "%" PRIi64, v));
+  ret = value_byte_runs (h, writer_v, value);
   end_value (writer);
-  return 0;
+  return ret;
 }
 
 static int
@@ -384,12 +462,14 @@ value_binary (hive_h *h, void *writer_v, hive_node_h node, hive_value_h value,
               hive_type t, size_t len, const char *key, const char *v)
 {
   xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
+  int ret = 0;
   start_value (writer, key, "binary", "base64");
   XML_CHECK (xmlTextWriterStartAttribute, (writer, BAD_CAST "value"));
   XML_CHECK (xmlTextWriterWriteBase64, (writer, v, 0, len));
   XML_CHECK (xmlTextWriterEndAttribute, (writer));
+  ret = value_byte_runs (h, writer_v, value);
   end_value (writer);
-  return 0;
+  return ret;
 }
 
 static int
@@ -397,14 +477,16 @@ value_none (hive_h *h, void *writer_v, hive_node_h node, hive_value_h value,
             hive_type t, size_t len, const char *key, const char *v)
 {
   xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
+  int ret = 0;
   start_value (writer, key, "none", "base64");
   if (len > 0) {
     XML_CHECK (xmlTextWriterStartAttribute, (writer, BAD_CAST "value"));
     XML_CHECK (xmlTextWriterWriteBase64, (writer, v, 0, len));
     XML_CHECK (xmlTextWriterEndAttribute, (writer));
+    ret = value_byte_runs (h, writer_v, value);
   }
   end_value (writer);
-  return 0;
+  return ret;
 }
 
 static int
@@ -413,6 +495,7 @@ value_other (hive_h *h, void *writer_v, hive_node_h node, hive_value_h value,
 {
   xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
   const char *type;
+  int ret = 0;
 
   switch (t) {
   case hive_t_none:
@@ -439,8 +522,9 @@ value_other (hive_h *h, void *writer_v, hive_node_h node, hive_value_h value,
     XML_CHECK (xmlTextWriterStartAttribute, (writer, BAD_CAST "value"));
     XML_CHECK (xmlTextWriterWriteBase64, (writer, v, 0, len));
     XML_CHECK (xmlTextWriterEndAttribute, (writer));
+    ret = value_byte_runs (h, writer_v, value);
   }
   end_value (writer);
 
-  return 0;
+  return ret;
 }
