gammaray
gammaray copied to clipboard
Correctly print gpt UTF-16LE partition_name
Migrated from: https://github.com/wenluhu/gammaray-android/issues/18
Can likely be done with the iconv
library.
The following's resulting in a segfault, likely due to the
cast from a *uint8_t[72]
to char**
.
struct gpt_partition_table_entry
{
uint8_t partition_type_guid[16];
uint8_t unique_partition_guid[16];
uint64_t first_lba;
uint64_t last_lba;
uint64_t attribute_flags;
uint8_t partition_name[72]; // 36 UTF-16LE code units.
}__attribute__((packed));
iconv_t cd = iconv_open("US-ASCII", "UTF-16");
size_t name_cstr_len = 36;
char* partition_name_cstr = (char*) malloc(sizeof(char)*name_cstr_len);
size_t name_utf16_len = name_cstr_len*2;
int err = iconv(cd, (char**) &gpt_pe.partition_name, &name_utf16_len,
&partition_name_cstr, &name_cstr_len);
printf("err: %d\n", err);
fprintf_green(stdout, "Partition Name: '%s'\n",
partition_name_cstr);
iconv_close(cd);