From 88fa13bbdd3ec512b8a60f36e6c1d77788403298 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Wed, 4 Oct 2017 22:21:29 +0100 Subject: [PATCH] Allow count to be specified as a parameter. --- volatility/framework/objects/utility.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/volatility/framework/objects/utility.py b/volatility/framework/objects/utility.py index a6c8fa370..55b08cac5 100644 --- a/volatility/framework/objects/utility.py +++ b/volatility/framework/objects/utility.py @@ -1,12 +1,15 @@ from volatility.framework import objects -def array_to_string(array, errors = 'replace'): +def array_to_string(array, count = None, errors = 'replace'): """Takes a volatility Array of characters and returns a string""" # TODO: Consider checking the Array's target is a native char + if count is None: + count = array.vol.count if not isinstance(array, objects.Array): raise TypeError("Array_to_string takes an Array of char") - return array.cast("string", max_length = array.vol.count, errors = errors) + return array.cast("string", max_length = count, errors = errors) + def pointer_to_string(pointer, count, errors = 'replace'): """Takes a volatility Pointer to characters and returns a string""" @@ -15,4 +18,4 @@ def pointer_to_string(pointer, count, errors = 'replace'): if count < 1: raise ValueError("pointer_to_string requires a positive count") char = pointer.dereference() - return char.cast("string", max_length = count, errors=errors) + return char.cast("string", max_length = count, errors = errors)