#define DRD64_SRC_LIBGOBLIN_DWARF_COMMON
#include"drd64_libgoblin.h"
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBGOBLIN_DWARF_COMMON_EXTERN
+Byte *
+ LibGoblin_DwarfCommon_Read_Byte(
+ Byte *pb_value,
+ Byte *pb_src,
+ QWord *pqw_size )
+{
+ if( 1 > *pqw_size ) { return NULL; }
+
+ *pb_value = *((Byte *)pb_src);
+ pb_src += 1;
+ *pqw_size -= 1;
+
+ return pb_src;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBGOBLIN_DWARF_COMMON_EXTERN
+Byte *
+ LibGoblin_DwarfCommon_Read_Word(
+ Word *pw_value,
+ Byte *pb_src,
+ QWord *pqw_size )
+{
+ if( 2 > *pqw_size ) { return NULL; }
+
+ *pw_value = *((Word *)pb_src);
+ pb_src += 2;
+ *pqw_size -= 2;
+
+ return pb_src;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBGOBLIN_DWARF_COMMON_EXTERN
+Byte *
+ LibGoblin_DwarfCommon_Read_DWord(
+ DWord *pdw_value,
+ Byte *pb_src,
+ QWord *pqw_size )
+{
+ if( 4 > *pqw_size ) { return NULL; }
+
+ *pdw_value = *((DWord *)pb_src);
+ pb_src += 4;
+ *pqw_size -= 4;
+
+ return pb_src;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBGOBLIN_DWARF_COMMON_EXTERN
+Byte *
+ LibGoblin_DwarfCommon_Read_QWord(
+ QWord *pqw_value,
+ Byte *pb_src,
+ QWord *pqw_size )
+{
+ if( 8 > *pqw_size ) { return NULL; }
+
+ *pqw_value = *((QWord *)pb_src);
+ pb_src += 8;
+ *pqw_size -= 8;
+
+ return pb_src;
+}
+
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
LIBGOBLIN_DWARF_COMMON_EXTERN
-int
+Byte *
LibGoblin_DwarfCommon_Read_CUHeader(
LibGoblin_DwarfCommon_CUHeader *p_cuhead,
Byte *pb_data,
i_bitflag = 32;
/* Read unit_length (4Byte + 8Byte(64bit)) */
- if( 4 > qw_size_info ) { return -0x01; }
- dw_dword = *((DWord *)pb_data);
- pb_data += 4;
- qw_size_info -= 4;
- i_readbytes += 4;
+ pb_data = LibGoblin_DwarfCommon_Read_DWord(
+ &dw_dword, pb_data, &qw_size_info );
+ if( NULL == pb_data ) { return NULL; }
if( ((DWord)0xffffffff) == dw_dword ) {
- if( 8 > qw_size_info ) { return -0x01; }
- qw_qword = *((QWord *)pb_data);
- pb_data += 8;
- qw_size_info -= 8;
- i_readbytes += 8;
+ pb_data = LibGoblin_DwarfCommon_Read_QWord(
+ &qw_qword, pb_data, &qw_size_info );
+ if( NULL == pb_data ) { return NULL; }
- i_bitflag = 64;
p_cuhead->qw_unitsize = (QWord)qw_qword;
+ i_bitflag = 64;
}
else {
p_cuhead->qw_unitsize = (QWord)dw_dword;
}
/* Read version (2Byte) */
- if( 2 > qw_size_info ) { return -0x01; }
- p_cuhead->w_version = *((Word *)pb_data);
- pb_data += 2;
- qw_size_info -= 2;
- i_readbytes += 2;
+ pb_data = LibGoblin_DwarfCommon_Read_Word(
+ &(p_cuhead->w_version), pb_data, &qw_size_info );
+ if( NULL == pb_data ) { return NULL; }
/* Read abbrev_offset (4Byte(32bit), 8Byte(64bit)) */
if( 64 == i_bitflag ) {
- if( 8 > qw_size_info ) { return -0x01; }
- qw_qword = *((QWord *)pb_data);
- pb_data += 8;
- qw_size_info -= 8;
- i_readbytes += 8;
-
+ pb_data = LibGoblin_DwarfCommon_Read_QWord(
+ &qw_qword, pb_data, &qw_size_info );
+ if( NULL == pb_data ) { return NULL; }
+
p_cuhead->qw_abbrev_offset = qw_qword;
}
else {
- if( 4 > qw_size_info ) { return -0x01; }
- dw_dword = *((DWord *)pb_data);
- pb_data += 4;
- qw_size_info -= 4;
- i_readbytes += 4;
+ pb_data = LibGoblin_DwarfCommon_Read_DWord(
+ &dw_dword, pb_data, &qw_size_info );
+ if( NULL == pb_data ) { return NULL; }
p_cuhead->qw_abbrev_offset = (QWord)dw_dword;
}
/* Read address_size (1Byte) */
- if( 1 > qw_size_info ) { return -0x01; }
- p_cuhead->b_pointersize = *pb_data;
- pb_data += 1;
- qw_size_info -= 1;
- i_readbytes += 1;
+ pb_data = LibGoblin_DwarfCommon_Read_Byte(
+ &(p_cuhead->b_pointersize), pb_data, &qw_size_info);
+ if( NULL == pb_data ) { return NULL; }
- return i_readbytes;
+ return pb_data;
}
if( 0 == qw_size_info ) { return -0x01; }
/* Read Compile Unit Header */
- i_readbytes = LibGoblin_DwarfCommon_Read_CUHeader(
+ pb_data = LibGoblin_DwarfCommon_Read_CUHeader(
&t_cuheader, pb_data, qw_size_info);
- if( 0 > i_readbytes ) { return -0x02; }
+ if( NULL == pb_data ) { return -0x02; }
+
+ qw_size_info = t_cuheader.qw_unitsize;
/*printf( "size: %ld, ver:%d, abbrev off.:%ld, addr.size: %d\n",
t_cuheader.qw_unitsize,
t_cuheader.w_version,
t_cuheader.qw_abbrev_offset,
- t_cuheader.b_pointersize);*/
+ t_cuheader.b_pointersize); */
+
+ do {
+
+ }while( 0 == qw_size_info);
puts( "OKOK");