Skip to content

Commit

Permalink
Applied updates and code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Mar 3, 2024
1 parent 01c0dc5 commit 93847ab
Show file tree
Hide file tree
Showing 13 changed files with 454 additions and 186 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ([2.71])

AC_INIT(
[libregf],
[20240214],
[20240303],
[joachim.metz@gmail.com])

AC_CONFIG_SRCDIR(
Expand Down
30 changes: 30 additions & 0 deletions include/libregf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -532,16 +532,31 @@ int libregf_key_get_number_of_values(
libregf_error_t **error );

/* Retrieves the value
*
* This function deprecated use libregf_key_get_value_by_index
*
* Creates a new value
* Returns 1 if successful or -1 on error
*/
LIBREGF_DEPRECATED \
LIBREGF_EXTERN \
int libregf_key_get_value(
libregf_key_t *key,
int value_index,
libregf_value_t **value,
libregf_error_t **error );

/* Retrieves the value
* Creates a new value
* Returns 1 if successful or -1 on error
*/
LIBREGF_EXTERN \
int libregf_key_get_value_by_index(
libregf_key_t *key,
int value_index,
libregf_value_t **value,
libregf_error_t **error );

/* Retrieves the value for the specific UTF-8 encoded name
* To retrieve the default value specify value name as NULL and its length as 0
* Creates a new value
Expand Down Expand Up @@ -578,16 +593,31 @@ int libregf_key_get_number_of_sub_keys(
libregf_error_t **error );

/* Retrieves a specific sub key
*
* This function deprecated use libregf_key_get_sub_key_by_index
*
* Creates a new key
* Returns 1 if successful or -1 on error
*/
LIBREGF_DEPRECATED \
LIBREGF_EXTERN \
int libregf_key_get_sub_key(
libregf_key_t *key,
int sub_key_index,
libregf_key_t **sub_key,
libregf_error_t **error );

/* Retrieves a specific sub key
* Creates a new key
* Returns 1 if successful or -1 on error
*/
LIBREGF_EXTERN \
int libregf_key_get_sub_key_by_index(
libregf_key_t *key,
int sub_key_index,
libregf_key_t **sub_key,
libregf_error_t **error );

/* Retrieves the sub key for the specific UTF-8 encoded name
* Creates a new key
* Returns 1 if successful, 0 if no such sub key or -1 on error
Expand Down
227 changes: 227 additions & 0 deletions libregf/libregf_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,104 @@ int libregf_key_get_value(
return( result );
}

/* Retrieves the value
* Creates a new value
* Returns 1 if successful or -1 on error
*/
int libregf_key_get_value_by_index(
libregf_key_t *key,
int value_index,
libregf_value_t **value,
libcerror_error_t **error )
{
libregf_internal_key_t *internal_key = NULL;
static char *function = "libregf_key_get_value_by_index";
int result = 1;

if( key == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid key.",
function );

return( -1 );
}
internal_key = (libregf_internal_key_t *) key;

if( value == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid value.",
function );

return( -1 );
}
if( *value != NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
"%s: value already set.",
function );

return( -1 );
}
#if defined( HAVE_LIBREGF_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_grab_for_write(
internal_key->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to grab read/write lock for writing.",
function );

return( -1 );
}
#endif
if( libregf_internal_key_get_value(
internal_key,
value_index,
value,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_GET_FAILED,
"%s: unable to retrieve value: %d.",
function,
value_index );

result = -1;
}
#if defined( HAVE_LIBREGF_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_release_for_write(
internal_key->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to release read/write lock for writing.",
function );

return( -1 );
}
#endif
return( result );
}

/* Retrieves the value for the specific UTF-8 encoded name
* To retrieve the default value specify value name as NULL and its length as 0
* Creates a new value
Expand Down Expand Up @@ -2798,6 +2896,135 @@ int libregf_key_get_sub_key(
return( result );
}

/* Retrieves a specific sub key
* Creates a new key
* Returns 1 if successful or -1 on error
*/
int libregf_key_get_sub_key_by_index(
libregf_key_t *key,
int sub_key_index,
libregf_key_t **sub_key,
libcerror_error_t **error )
{
libregf_internal_key_t *internal_key = NULL;
libregf_key_descriptor_t *sub_key_descriptor = NULL;
static char *function = "libregf_key_get_sub_key_by_index";
int result = 1;

if( key == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid key.",
function );

return( -1 );
}
internal_key = (libregf_internal_key_t *) key;

if( sub_key == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid sub key.",
function );

return( -1 );
}
if( *sub_key != NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
"%s: sub key already set.",
function );

return( -1 );
}
#if defined( HAVE_LIBREGF_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_grab_for_write(
internal_key->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to grab read/write lock for writing.",
function );

return( -1 );
}
#endif
if( libregf_key_item_get_sub_key_descriptor_by_index(
internal_key->key_item,
sub_key_index,
&sub_key_descriptor,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_GET_FAILED,
"%s: unable to retrieve sub key: %d descriptor.",
function,
sub_key_index );

result = -1;
}
else if( sub_key_descriptor == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid sub key: %d descriptor.",
function,
sub_key_index );

result = -1;
}
else if( libregf_key_initialize(
sub_key,
internal_key->io_handle,
internal_key->file_io_handle,
sub_key_descriptor->key_offset,
internal_key->hive_bins_list,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to initialize sub key: %d.",
function,
sub_key_index );

result = -1;
}
#if defined( HAVE_LIBREGF_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_release_for_write(
internal_key->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to release read/write lock for writing.",
function );

return( -1 );
}
#endif
return( result );
}

/* Retrieves the sub key for the specific UTF-8 encoded name
* Creates a new key
* Returns 1 if successful, 0 if no such sub key or -1 on error
Expand Down
14 changes: 14 additions & 0 deletions libregf/libregf_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ int libregf_key_get_value(
libregf_value_t **value,
libcerror_error_t **error );

LIBREGF_EXTERN \
int libregf_key_get_value_by_index(
libregf_key_t *key,
int value_index,
libregf_value_t **value,
libcerror_error_t **error );

int libregf_internal_key_get_value_by_utf8_name(
libregf_internal_key_t *internal_key,
const uint8_t *utf8_string,
Expand Down Expand Up @@ -252,6 +259,13 @@ int libregf_key_get_sub_key(
libregf_key_t **sub_key,
libcerror_error_t **error );

LIBREGF_EXTERN \
int libregf_key_get_sub_key_by_index(
libregf_key_t *key,
int sub_key_index,
libregf_key_t **sub_key,
libcerror_error_t **error );

int libregf_internal_key_get_sub_key_by_utf8_name(
libregf_internal_key_t *internal_key,
const uint8_t *utf8_string,
Expand Down
6 changes: 3 additions & 3 deletions manuals/libregf.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.Dd July 13, 2019
.Dd March 3, 2024
.Dt libregf 3
.Os libregf
.Sh NAME
Expand Down Expand Up @@ -125,15 +125,15 @@ Key functions
.Ft int
.Fn libregf_key_get_number_of_values "libregf_key_t *key" "int *number_of_values" "libregf_error_t **error"
.Ft int
.Fn libregf_key_get_value "libregf_key_t *key" "int value_index" "libregf_value_t **value" "libregf_error_t **error"
.Fn libregf_key_get_value_by_index "libregf_key_t *key" "int value_index" "libregf_value_t **value" "libregf_error_t **error"
.Ft int
.Fn libregf_key_get_value_by_utf8_name "libregf_key_t *key" "const uint8_t *utf8_string" "size_t utf8_string_length" "libregf_value_t **value" "libregf_error_t **error"
.Ft int
.Fn libregf_key_get_value_by_utf16_name "libregf_key_t *key" "const uint16_t *utf16_string" "size_t utf16_string_length" "libregf_value_t **value" "libregf_error_t **error"
.Ft int
.Fn libregf_key_get_number_of_sub_keys "libregf_key_t *key" "int *number_of_sub_keys" "libregf_error_t **error"
.Ft int
.Fn libregf_key_get_sub_key "libregf_key_t *key" "int sub_key_index" "libregf_key_t **sub_key" "libregf_error_t **error"
.Fn libregf_key_get_sub_key_by_index "libregf_key_t *key" "int sub_key_index" "libregf_key_t **sub_key" "libregf_error_t **error"
.Ft int
.Fn libregf_key_get_sub_key_by_utf8_name "libregf_key_t *key" "const uint8_t *utf8_string" "size_t utf8_string_length" "libregf_key_t **sub_key" "libregf_error_t **error"
.Ft int
Expand Down
Loading

0 comments on commit 93847ab

Please sign in to comment.