From 05c4c8324deea2436d4da5992ecc3384a0e16e87 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 7 Feb 2013 11:48:37 -0600 Subject: [PATCH] Implemented convenience function hivex_node_get_child_deep This functions obtains a handle via its node path as a \-separated value, calling hivex_node_get_child iteratively as needed. It should handle invalid inputs for both node and nname OK; invalid nodes will be caught by hivex_node_get_child and the errors will simply be passed-through to the caller. --- lib/hivex.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/hivex.c b/lib/hivex.c index a2bd43b..e65f1a5 100644 --- a/lib/hivex.c +++ b/lib/hivex.c @@ -1031,6 +1031,33 @@ hivex_node_get_child (hive_h *h, hive_node_h node, const char *nname) return ret; } +/* Convenience function to iteratively obtain node from \-separated path + * Error-checking is simply passed-through + */ +hive_node_h +hivex_node_get_child_deep (hive_h *h, hive_node_h node, const char *nname) +{ + if (!nname) return NULL; + + int done = 0; + char *pathBuffer = strdup (nname); + char *stub; + char *letter; + + for (letter = stub = pathBuffer; !done && node; ++letter) + { + if ((*letter == '\\') || (done = *letter == '\0')) + { + *letter = '\0'; + node = hivex_node_get_child (h, node, stub); + stub = letter + 1; + } + } + + free (pathBuffer); + return node; +} + hive_node_h hivex_node_parent (hive_h *h, hive_node_h node) { -- 1.7.10.4