| 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. *)
| 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 "
) (snd style);
(match fst style with
| RLenType | RLenTypeVal -> pr ", hive_type *t, size_t *len"
+ | RLenValue -> pr ", size_t *len"
| _ -> ()
);
pr ");\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>).
| RString -> pr "string"
| RStringList -> pr "string array"
| RLenType -> pr "hive_type * int"
+ | RLenValue -> pr "int * value"
| RLenTypeVal -> pr "hive_type * string"
| RInt32 -> pr "int32"
| RInt64 -> pr "int64"
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_len_value (size_t, hive_value_h);
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;
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
pr " size_t len;\n";
pr " hive_type t;\n";
"-1"
+ | RLenValue ->
+ pr " errno = 0;";
+ pr " hive_value_h r;\n";
+ pr " size_t len;\n";
+ "0 && errno != 0"
| RLenTypeVal ->
pr " char *r;\n";
pr " size_t len;\n";
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_len_value (len, r);\n"
| RLenTypeVal ->
pr " rv = copy_type_value (r, len, t);\n";
pr " free (r);\n"
}
static value
+copy_len_value (size_t len, hive_value_h r)
+{
+ CAMLparam0 ();
+ CAMLlocal2 (v, rv);
+
+ rv = caml_alloc (2, 0);
+ v = Val_int (len);
+ Store_field (rv, 0, v);
+ v = Val_int (r);
+ Store_field (rv, 1, v);
+ CAMLreturn (rv);
+}
+
+static value
copy_type_value (const char *r, size_t len, hive_type t)
{
CAMLparam0 ();
| RString
| RStringList
| RLenType
+ | RLenValue
| RLenTypeVal
| RInt32
| RInt64 -> ()
| RString -> pr "$string = "
| RStringList -> pr "@strings = "
| RLenType -> pr "($type, $len) = "
+ | RLenValue -> pr "($len, $value) = "
| RLenTypeVal -> pr "($type, $data) = "
| RInt32 -> pr "$int32 = "
| RInt64 -> pr "$int64 = "
| RValueList
| RStringList
| RLenType
+ | RLenValue
| RLenTypeVal -> pr "void\n"
| RInt32 -> pr "SV *\n"
| RInt64 -> pr "SV *\n"
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 " errno = 0;\n";
+ pr " r = hivex_%s (%s, &len);\n"
+ name (String.concat ", " c_params);
+ free_args ();
+ pr " if (r == 0 && errno)\n";
+ pr " croak (\"%%s: \", \"%s\", strerror (errno));\n"
+ name;
+ pr " EXTEND (SP, 2);\n";
+ pr " PUSHs (sv_2mortal (newSViv (len)));\n";
+ pr " PUSHs (sv_2mortal (newSViv (r)));\n";
+
| RLenTypeVal ->
pr "PREINIT:\n";
pr " char *r;\n";
}
static PyObject *
+put_len_val (size_t len, hive_value_h value)
+{
+ PyObject *r = PyTuple_New (2);
+ PyTuple_SetItem (r, 0, PyLong_FromLongLong ((long) len));
+ PyTuple_SetItem (r, 1, PyLong_FromLongLong ((long) value));
+ return r;
+}
+
+static PyObject *
put_val_type (char *val, size_t len, hive_type t)
{
PyObject *r = PyTuple_New (2);
pr " size_t len;\n";
pr " hive_type t;\n";
"-1"
+ | RLenValue ->
+ pr " errno = 0;\n";
+ pr " int r;\n";
+ pr " size_t len;\n";
+ "0 && errno != 0"
| RLenTypeVal ->
pr " char *r;\n";
pr " size_t len;\n";
let c_params =
match fst style with
| RLenType | RLenTypeVal -> c_params @ ["&t"; "&len"]
+ | RLenValue -> c_params @ ["&len"]
| _ -> c_params in
List.iter (
pr " free_strings (r);\n"
| RLenType ->
pr " py_r = put_len_type (len, t);\n"
+ | RLenValue ->
+ pr " py_r = put_len_val (len, r);\n"
| RLenTypeVal ->
pr " py_r = put_val_type (r, len, t);\n";
pr " free (r);\n"
| RString -> "string"
| RStringList -> "list"
| RLenType -> "hash"
+ | RLenValue -> "integer"
| RLenTypeVal -> "hash"
| RInt32 -> "integer"
| RInt64 -> "integer" in
pr " size_t len;\n";
pr " hive_type t;\n";
"-1"
+ | RLenValue ->
+ pr " errno = 0;\n";
+ pr " hive_value_h r;\n";
+ pr " size_t len;\n";
+ "0 && errno != 0"
| RLenTypeVal ->
pr " char *r;\n";
pr " size_t len;\n";
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
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 (\"off\")), 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";