| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <common.h> |
| 23 |
#include <types.h> |
| 24 |
|
| 25 |
#include "pyvhdi_error.h" |
| 26 |
#include "pyvhdi_guid.h" |
| 27 |
#include "pyvhdi_libfguid.h" |
| 28 |
#include "pyvhdi_python.h" |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
PyObject *pyvhdi_string_new_from_guid( |
| 34 |
const uint8_t *guid_buffer, |
| 35 |
size_t guid_buffer_size ) |
| 36 |
{ |
| 37 |
char guid_string[ 48 ]; |
| 38 |
|
| 39 |
libcerror_error_t *error = NULL; |
| 40 |
libfguid_identifier_t *guid = NULL; |
| 41 |
PyObject *string_object = NULL; |
| 42 |
static char *function = "pyvhdi_string_new_from_guid"; |
| 43 |
|
| 44 |
if( libfguid_identifier_initialize( |
| 45 |
&guid, |
| 46 |
&error ) != 1 ) |
| 47 |
{ |
| 48 |
pyvhdi_error_raise( |
| 49 |
error, |
| 50 |
PyExc_IOError, |
| 51 |
"%s: unable to create GUID.", |
| 52 |
function ); |
| 53 |
|
| 54 |
libcerror_error_free( |
| 55 |
&error ); |
| 56 |
|
| 57 |
goto on_error; |
| 58 |
} |
| 59 |
if( libfguid_identifier_copy_from_byte_stream( |
| 60 |
guid, |
| 61 |
guid_buffer, |
| 62 |
guid_buffer_size, |
| 63 |
LIBFGUID_ENDIAN_BIG, |
| 64 |
&error ) != 1 ) |
| 65 |
{ |
| 66 |
pyvhdi_error_raise( |
| 67 |
error, |
| 68 |
PyExc_IOError, |
| 69 |
"%s: unable to copy byte stream to GUID.", |
| 70 |
function ); |
| 71 |
|
| 72 |
libcerror_error_free( |
| 73 |
&error ); |
| 74 |
|
| 75 |
goto on_error; |
| 76 |
} |
| 77 |
if( libfguid_identifier_copy_to_utf8_string( |
| 78 |
guid, |
| 79 |
(uint8_t *) guid_string, |
| 80 |
48, |
| 81 |
LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, |
| 82 |
&error ) != 1 ) |
| 83 |
{ |
| 84 |
pyvhdi_error_raise( |
| 85 |
error, |
| 86 |
PyExc_IOError, |
| 87 |
"%s: unable to copy GUID to string.", |
| 88 |
function ); |
| 89 |
|
| 90 |
libcerror_error_free( |
| 91 |
&error ); |
| 92 |
|
| 93 |
goto on_error; |
| 94 |
} |
| 95 |
if( libfguid_identifier_free( |
| 96 |
&guid, |
| 97 |
&error ) != 1 ) |
| 98 |
{ |
| 99 |
pyvhdi_error_raise( |
| 100 |
error, |
| 101 |
PyExc_IOError, |
| 102 |
"%s: unable to free GUID.", |
| 103 |
function ); |
| 104 |
|
| 105 |
libcerror_error_free( |
| 106 |
&error ); |
| 107 |
|
| 108 |
goto on_error; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
string_object = PyUnicode_DecodeUTF8( |
| 115 |
guid_string, |
| 116 |
(Py_ssize_t) 36, |
| 117 |
NULL ); |
| 118 |
|
| 119 |
return( string_object ); |
| 120 |
|
| 121 |
on_error: |
| 122 |
if( guid != NULL ) |
| 123 |
{ |
| 124 |
libfguid_identifier_free( |
| 125 |
&guid, |
| 126 |
NULL ); |
| 127 |
} |
| 128 |
return( NULL ); |
| 129 |
} |
| 130 |
|