Skip to content
Snippets Groups Projects
Commit 565f8905 authored by Ann Priestman's avatar Ann Priestman
Browse files

Minor fixes to GPT processing

parent ff0f0200
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,9 @@ extern "C" { ...@@ -67,6 +67,9 @@ extern "C" {
uint16_t); uint16_t);
extern uint8_t tsk_guess_end_u32(TSK_ENDIAN_ENUM *, uint8_t *, extern uint8_t tsk_guess_end_u32(TSK_ENDIAN_ENUM *, uint8_t *,
uint32_t); uint32_t);
extern uint8_t tsk_guess_end_u64(TSK_ENDIAN_ENUM *, uint8_t *,
uint64_t);
/** \internal /** \internal
* Read a 16-bit unsigned value. * Read a 16-bit unsigned value.
......
...@@ -74,3 +74,29 @@ tsk_guess_end_u32(TSK_ENDIAN_ENUM * flag, uint8_t * x, uint32_t val) ...@@ -74,3 +74,29 @@ tsk_guess_end_u32(TSK_ENDIAN_ENUM * flag, uint8_t * x, uint32_t val)
return 1; return 1;
} }
/** \internal
* same idea as tsk_guess_end_u16 except that val is a 64-bit value
*
* @param flag Pointer to location where proper endian flag should be stored.
* @param x Pointer to array of bytes to analyze.
* @param val Target value to compare to
* @returns 1 if match cannot be made, 0 if it can.
*/
uint8_t
tsk_guess_end_u64(TSK_ENDIAN_ENUM * flag, uint8_t * x, uint64_t val)
{
/* try little */
if (tsk_getu64(TSK_LIT_ENDIAN, x) == val) {
*flag = TSK_LIT_ENDIAN;
return 0;
}
/* ok, big now */
if (tsk_getu64(TSK_BIG_ENDIAN, x) == val) {
*flag = TSK_BIG_ENDIAN;
return 0;
}
return 1;
}
...@@ -239,6 +239,8 @@ extern "C" { ...@@ -239,6 +239,8 @@ extern "C" {
tsk_guess_end_u16(&(fs->endian), (x), (mag)) tsk_guess_end_u16(&(fs->endian), (x), (mag))
#define tsk_fs_guessu32(fs, x, mag) \ #define tsk_fs_guessu32(fs, x, mag) \
tsk_guess_end_u32(&(fs->endian), (x), (mag)) tsk_guess_end_u32(&(fs->endian), (x), (mag))
#define tsk_fs_guessu64(fs, x, mag) \
tsk_guess_end_u64(&(fs->endian), (x), (mag))
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* */ #endif /* */
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* It is loaded into the internal sorted list * It is loaded into the internal sorted list
*/ */
static uint8_t static uint8_t
gpt_load_table(TSK_VS_INFO * vs, GPT_TYPE_ENUM gpt_type) gpt_load_table(TSK_VS_INFO * vs, GPT_LOCATION_ENUM gpt_type)
{ {
gpt_head *head; gpt_head *head;
gpt_entry *ent; gpt_entry *ent;
...@@ -35,12 +35,8 @@ gpt_load_table(TSK_VS_INFO * vs, GPT_TYPE_ENUM gpt_type) ...@@ -35,12 +35,8 @@ gpt_load_table(TSK_VS_INFO * vs, GPT_TYPE_ENUM gpt_type)
TSK_DADDR_T max_addr = (vs->img_info->size - vs->offset) / vs->block_size; // max sector TSK_DADDR_T max_addr = (vs->img_info->size - vs->offset) / vs->block_size; // max sector
TSK_DADDR_T gpt_relative_addr; TSK_DADDR_T gpt_relative_addr;
TSK_DADDR_T gpt_absolute_addr; TSK_DADDR_T gpt_absolute_addr;
TSK_DADDR_T dos_sect_relative_addr;
TSK_DADDR_T dos_sect_absolute_addr;
if(gpt_type == PRIMARY_TABLE){ if(gpt_type == PRIMARY_TABLE){
dos_sect_relative_addr = GPT_PART_SOFFSET;
dos_sect_absolute_addr = vs->offset / vs->block_size + GPT_PART_SOFFSET;
gpt_relative_addr = GPT_PART_SOFFSET + 1; gpt_relative_addr = GPT_PART_SOFFSET + 1;
gpt_absolute_addr = vs->offset / vs->block_size + GPT_PART_SOFFSET + 1; gpt_absolute_addr = vs->offset / vs->block_size + GPT_PART_SOFFSET + 1;
} else { } else {
...@@ -48,7 +44,6 @@ gpt_load_table(TSK_VS_INFO * vs, GPT_TYPE_ENUM gpt_type) ...@@ -48,7 +44,6 @@ gpt_load_table(TSK_VS_INFO * vs, GPT_TYPE_ENUM gpt_type)
gpt_absolute_addr = (vs->img_info->size / vs->block_size) - 1; gpt_absolute_addr = (vs->img_info->size / vs->block_size) - 1;
} }
if (tsk_verbose) if (tsk_verbose)
tsk_fprintf(stderr, "gpt_load_table: Sector: %" PRIuDADDR "\n", tsk_fprintf(stderr, "gpt_load_table: Sector: %" PRIuDADDR "\n",
gpt_absolute_addr); gpt_absolute_addr);
...@@ -57,6 +52,8 @@ gpt_load_table(TSK_VS_INFO * vs, GPT_TYPE_ENUM gpt_type) ...@@ -57,6 +52,8 @@ gpt_load_table(TSK_VS_INFO * vs, GPT_TYPE_ENUM gpt_type)
return 1; return 1;
if(gpt_type == PRIMARY_TABLE){ if(gpt_type == PRIMARY_TABLE){
TSK_DADDR_T dos_sect_relative_addr = GPT_PART_SOFFSET;
TSK_DADDR_T dos_sect_absolute_addr = vs->offset / vs->block_size + GPT_PART_SOFFSET;
dos_part = (dos_sect *) sect_buf; dos_part = (dos_sect *) sect_buf;
cnt = tsk_vs_read_block cnt = tsk_vs_read_block
...@@ -113,10 +110,13 @@ gpt_load_table(TSK_VS_INFO * vs, GPT_TYPE_ENUM gpt_type) ...@@ -113,10 +110,13 @@ gpt_load_table(TSK_VS_INFO * vs, GPT_TYPE_ENUM gpt_type)
/* Do the endianness test for the secondary table since the test in the dos safety table was skipped */ /* Do the endianness test for the secondary table since the test in the dos safety table was skipped */
if(gpt_type == SECONDARY_TABLE){ if(gpt_type == SECONDARY_TABLE){
if(tsk_getu64(TSK_BIG_ENDIAN, head->head_lba) == gpt_relative_addr){ if (tsk_vs_guessu64(vs, head->signature, GPT_HEAD_SIG)) {
vs->endian = TSK_BIG_ENDIAN; tsk_error_reset();
} else { tsk_error_set_errno(TSK_ERR_VS_MAGIC);
vs->endian = TSK_LIT_ENDIAN; tsk_error_set_errstr("GPT Header: %" PRIx64, tsk_getu64(vs->endian,
&head->signature));
free(sect_buf);
return 1;
} }
} }
......
...@@ -60,7 +60,7 @@ extern "C" { ...@@ -60,7 +60,7 @@ extern "C" {
typedef enum { typedef enum {
PRIMARY_TABLE, PRIMARY_TABLE,
SECONDARY_TABLE, SECONDARY_TABLE,
} GPT_TYPE_ENUM; } GPT_LOCATION_ENUM;
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -41,4 +41,8 @@ extern void tsk_vs_part_free(TSK_VS_INFO *); ...@@ -41,4 +41,8 @@ extern void tsk_vs_part_free(TSK_VS_INFO *);
#define tsk_vs_guessu32(vs, x, mag) \ #define tsk_vs_guessu32(vs, x, mag) \
tsk_guess_end_u32(&(vs->endian), (x), (mag)) tsk_guess_end_u32(&(vs->endian), (x), (mag))
#define tsk_vs_guessu64(vs, x, mag) \
tsk_guess_end_u64(&(vs->endian), (x), (mag))
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment