Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • opensrc/libehp
1 result
Show changes
Commits on Source (7)
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
// @HEADER_END // @HEADER_END
// testing -- edit
#ifndef ehp_hpp #ifndef ehp_hpp
#define ehp_hpp #define ehp_hpp
...@@ -151,14 +152,14 @@ class LSDA_t ...@@ -151,14 +152,14 @@ class LSDA_t
virtual uint8_t getTTEncoding() const =0; virtual uint8_t getTTEncoding() const =0;
virtual void print() const=0; virtual void print() const=0;
virtual uint64_t getLandingPadBaseAddress() const = 0; virtual uint64_t getLandingPadBaseAddress() const = 0;
virtual const CallSiteVector_t* getCallSites() const =0; virtual const CallSiteVector_t* getCallSites() const =0;
virtual uint64_t getCallSiteTableAddress() const = 0; virtual uint64_t getCallSiteTableAddress() const = 0;
virtual uint64_t getCallSiteTableAddressLocation() const = 0; virtual uint64_t getCallSiteTableAddressLocation() const = 0;
virtual uint8_t getCallSiteTableEncoding() const = 0; virtual uint8_t getCallSiteTableEncoding() const = 0;
virtual const TypeTableVector_t* getTypeTable() const =0; virtual const TypeTableVector_t* getTypeTable() const =0;
virtual uint64_t getTypeTableAddress() const = 0; virtual uint64_t getTypeTableAddress() const = 0;
virtual uint64_t getTypeTableAddressLocation() const = 0; virtual uint64_t getTypeTableAddressLocation() const = 0;
virtual uint64_t getCallSiteTableLength() const = 0; virtual uint64_t getCallSiteTableLength() const = 0;
virtual uint8_t getTypeTableEncoding() const = 0; virtual uint8_t getTypeTableEncoding() const = 0;
unique_ptr<LSDA_t> factory(const string lsda_data, const uint64_t lsda_start_addr); unique_ptr<LSDA_t> factory(const string lsda_data, const uint64_t lsda_start_addr);
}; };
...@@ -181,15 +182,16 @@ class FDEContents_t ...@@ -181,15 +182,16 @@ class FDEContents_t
virtual const LSDA_t* getLSDA() const =0; virtual const LSDA_t* getLSDA() const =0;
virtual uint64_t getLSDAAddress() const =0; virtual uint64_t getLSDAAddress() const =0;
virtual uint64_t getStartAddressPosition() const = 0; virtual uint64_t getStartAddressPosition() const = 0;
virtual uint64_t getEndAddressPosition() const = 0; virtual uint64_t getEndAddressPosition() const = 0;
virtual uint64_t getEndAddressSize() const = 0; virtual uint64_t getEndAddressSize() const = 0;
virtual uint64_t getLSDAAddressPosition() const = 0; virtual uint64_t getLSDAAddressPosition() const = 0;
virtual uint64_t getLSDAAddressSize() const = 0; virtual uint64_t getLSDAAddressSize() const = 0;
virtual void print() const=0; // move to ostream? toString? virtual void print() const=0; // move to ostream? toString?
}; };
using EHPEndianness_t = enum EHPEndianness { HOST, BIG, LITTLE } ;
using FDEVector_t = vector<const FDEContents_t*>; using FDEVector_t = vector<const FDEContents_t*>;
using CIEVector_t = vector<const CIEContents_t*>; using CIEVector_t = vector<const CIEContents_t*>;
class EHFrameParser_t class EHFrameParser_t
...@@ -197,9 +199,9 @@ class EHFrameParser_t ...@@ -197,9 +199,9 @@ class EHFrameParser_t
protected: protected:
EHFrameParser_t() {} EHFrameParser_t() {}
EHFrameParser_t(const EHFrameParser_t&) {} EHFrameParser_t(const EHFrameParser_t&) {}
virtual bool parse(const bool is_be)=0;
public: public:
virtual ~EHFrameParser_t() {} virtual ~EHFrameParser_t() {}
virtual bool parse()=0;
virtual void print() const=0; virtual void print() const=0;
virtual const FDEVector_t* getFDEs() const =0; virtual const FDEVector_t* getFDEs() const =0;
virtual const CIEVector_t* getCIEs() const =0; virtual const CIEVector_t* getCIEs() const =0;
...@@ -208,8 +210,10 @@ class EHFrameParser_t ...@@ -208,8 +210,10 @@ class EHFrameParser_t
#if USE_ELFIO #if USE_ELFIO
static unique_ptr<const EHFrameParser_t> factory(const string filename); static unique_ptr<const EHFrameParser_t> factory(const string filename);
#endif #endif
static unique_ptr<const EHFrameParser_t> factory( static unique_ptr<const EHFrameParser_t> factory(
uint8_t ptrsize, uint8_t ptrsize,
EHPEndianness_t endian_style,
const string eh_frame_data, const uint64_t eh_frame_data_start_addr, const string eh_frame_data, const uint64_t eh_frame_data_start_addr,
const string eh_frame_hdr_data, const uint64_t eh_frame_hdr_data_start_addr, const string eh_frame_hdr_data, const uint64_t eh_frame_hdr_data_start_addr,
const string gcc_except_table_data, const uint64_t gcc_except_table_data_start_addr const string gcc_except_table_data, const uint64_t gcc_except_table_data_start_addr
......
...@@ -54,18 +54,44 @@ using namespace ELFIO; ...@@ -54,18 +54,44 @@ using namespace ELFIO;
template <int ptrsize> template <int ptrsize>
template <class T> template <class T>
bool eh_frame_util_t<ptrsize>::read_type(T &value, uint64_t &position, const uint8_t* const data, const uint64_t max) bool eh_frame_util_t<ptrsize>::read_type(T &value, uint64_t &position, const uint8_t* const data, const uint64_t max, const bool is_be)
{ {
if(position + sizeof(T) > max) return true; if(position + sizeof(T) > max) return true;
// typecast to the right type // typecast to the right type
auto ptr=(const T*)&data[position]; const auto ptr=reinterpret_cast<const T*>(&data[position]);
// set output parameters // set output parameters
position+=sizeof(T); position+=sizeof(T);
value=*ptr; value=*ptr;
switch(sizeof(T))
{
case 1:
break;
case 2:
if(is_be)
value=be16toh(value);
else
value=le16toh(value);
break;
case 4:
if(is_be)
value=be32toh(value);
else
value=le32toh(value);
break;
case 8:
if(is_be)
value=be64toh(value);
else
value=le64toh(value);
break;
default:
throw invalid_argument("Unknown integer size");
}
return false; return false;
} }
...@@ -76,7 +102,8 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding ...@@ -76,7 +102,8 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding
uint64_t &position, uint64_t &position,
const uint8_t* const data, const uint8_t* const data,
const uint64_t max, const uint64_t max,
const uint64_t section_start_addr ) const uint64_t section_start_addr,
const bool is_be)
{ {
auto orig_position=position; auto orig_position=position;
auto encoding_lower8=encoding&0xf; auto encoding_lower8=encoding&0xf;
...@@ -105,7 +132,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding ...@@ -105,7 +132,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding
case DW_EH_PE_udata2 : case DW_EH_PE_udata2 :
{ {
auto newval=uint16_t(0); auto newval=uint16_t(0);
if(eh_frame_util_t<ptrsize>::read_type(newval,position,data,max)) if(eh_frame_util_t<ptrsize>::read_type(newval,position,data,max, is_be))
return true; return true;
value=newval; value=newval;
break; break;
...@@ -113,7 +140,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding ...@@ -113,7 +140,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding
case DW_EH_PE_udata4 : case DW_EH_PE_udata4 :
{ {
auto newval=uint32_t(0); auto newval=uint32_t(0);
if(eh_frame_util_t<ptrsize>::read_type(newval,position,data,max)) if(eh_frame_util_t<ptrsize>::read_type(newval,position,data,max, is_be))
return true; return true;
value=newval; value=newval;
break; break;
...@@ -121,7 +148,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding ...@@ -121,7 +148,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding
case DW_EH_PE_udata8 : case DW_EH_PE_udata8 :
{ {
auto newval=uint64_t(0); auto newval=uint64_t(0);
if(eh_frame_util_t<ptrsize>::read_type(newval,position,data,max)) if(eh_frame_util_t<ptrsize>::read_type(newval,position,data,max, is_be))
return true; return true;
value=newval; value=newval;
break; break;
...@@ -130,23 +157,23 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding ...@@ -130,23 +157,23 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding
{ {
if(ptrsize==8) if(ptrsize==8)
{ {
if(eh_frame_util_t<ptrsize>::read_type_with_encoding(DW_EH_PE_udata8, value, position, data, max, section_start_addr)) if(eh_frame_util_t<ptrsize>::read_type_with_encoding(DW_EH_PE_udata8, value, position, data, max, section_start_addr, is_be))
return true; return true;
break;
} }
else if(ptrsize==4) else if(ptrsize==4)
{ {
if(eh_frame_util_t<ptrsize>::read_type_with_encoding(DW_EH_PE_udata4, value, position, data, max, section_start_addr)) if(eh_frame_util_t<ptrsize>::read_type_with_encoding(DW_EH_PE_udata4, value, position, data, max, section_start_addr, is_be))
return true; return true;
break;
} }
throw_assert(0); else
throw invalid_argument("Cannot detect pointer size");
break;
} }
case DW_EH_PE_sdata2 : case DW_EH_PE_sdata2 :
{ {
auto newval=int16_t(0); auto newval=int16_t(0);
if(eh_frame_util_t<ptrsize>::read_type(newval,position,data,max)) if(eh_frame_util_t<ptrsize>::read_type(newval,position,data,max, is_be))
return true; return true;
value=newval; value=newval;
break; break;
...@@ -154,7 +181,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding ...@@ -154,7 +181,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding
case DW_EH_PE_sdata4 : case DW_EH_PE_sdata4 :
{ {
auto newval=int32_t(0); auto newval=int32_t(0);
if(eh_frame_util_t<ptrsize>::read_type(newval,position,data,max)) if(eh_frame_util_t<ptrsize>::read_type(newval,position,data,max, is_be))
return true; return true;
value=newval; value=newval;
break; break;
...@@ -162,7 +189,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding ...@@ -162,7 +189,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding
case DW_EH_PE_sdata8 : case DW_EH_PE_sdata8 :
{ {
auto newval=int64_t(0); auto newval=int64_t(0);
if(read_type(newval,position,data,max)) if(read_type(newval,position,data,max, is_be))
return true; return true;
value=newval; value=newval;
break; break;
...@@ -170,7 +197,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding ...@@ -170,7 +197,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding
case DW_EH_PE_signed : case DW_EH_PE_signed :
default: default:
throw_assert(0); throw invalid_argument("Cannot detect encoding of requested value");
}; };
switch(encoding_upper8) switch(encoding_upper8)
...@@ -186,7 +213,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding ...@@ -186,7 +213,7 @@ bool eh_frame_util_t<ptrsize>::read_type_with_encoding
case DW_EH_PE_aligned: case DW_EH_PE_aligned:
case DW_EH_PE_indirect: case DW_EH_PE_indirect:
default: default:
throw_assert(0); throw invalid_argument("Cannot detect encoding of requested value");
return true; return true;
} }
return false; return false;
...@@ -267,17 +294,19 @@ bool eh_frame_util_t<ptrsize>::read_length( ...@@ -267,17 +294,19 @@ bool eh_frame_util_t<ptrsize>::read_length(
uint64_t &act_length, uint64_t &act_length,
uint64_t &position, uint64_t &position,
const uint8_t* const data, const uint8_t* const data,
const uint64_t max) const uint64_t max,
const bool is_be
)
{ {
auto eh_frame_scoop_data=data; auto eh_frame_scoop_data=data;
auto length=uint32_t(0); auto length=uint32_t(0);
auto length_64bit=uint64_t(0); auto length_64bit=uint64_t(0);
if(read_type(length,position, eh_frame_scoop_data, max)) if(read_type(length,position, eh_frame_scoop_data, max, is_be))
return true; return true;
if(length==0xffffffff) if(length==0xffffffff)
{ {
if(read_type(length_64bit,position, eh_frame_scoop_data, max)) if(read_type(length_64bit,position, eh_frame_scoop_data, max, is_be))
return true; return true;
act_length=length_64bit; act_length=length_64bit;
} }
...@@ -701,7 +730,9 @@ bool eh_program_insn_t<ptrsize>::parse_insn( ...@@ -701,7 +730,9 @@ bool eh_program_insn_t<ptrsize>::parse_insn(
uint8_t opcode, uint8_t opcode,
uint64_t &pos, uint64_t &pos,
const uint8_t* const data, const uint8_t* const data,
const uint64_t &max) const uint64_t &max,
const bool is_be
)
{ {
auto &eh_insn = *this; auto &eh_insn = *this;
auto insn_start=pos-1; auto insn_start=pos-1;
...@@ -1026,7 +1057,9 @@ template <int ptrsize> ...@@ -1026,7 +1057,9 @@ template <int ptrsize>
bool eh_program_t<ptrsize>::parse_program( bool eh_program_t<ptrsize>::parse_program(
const uint64_t& program_start_position, const uint64_t& program_start_position,
const uint8_t* const data, const uint8_t* const data,
const uint64_t &max_program_pos) const uint64_t &max_program_pos,
const bool is_be
)
{ {
eh_program_t &eh_pgm=*this; eh_program_t &eh_pgm=*this;
auto max=max_program_pos; auto max=max_program_pos;
...@@ -1034,15 +1067,13 @@ bool eh_program_t<ptrsize>::parse_program( ...@@ -1034,15 +1067,13 @@ bool eh_program_t<ptrsize>::parse_program(
while(pos < max_program_pos) while(pos < max_program_pos)
{ {
auto opcode=uint8_t(0); auto opcode=uint8_t(0);
if(eh_frame_util_t<ptrsize>::read_type(opcode,pos,data,max)) if(eh_frame_util_t<ptrsize>::read_type(opcode,pos,data,max, is_be))
return true; return true;
eh_program_insn_t<ptrsize> eh_insn; eh_program_insn_t<ptrsize> eh_insn;
if(eh_insn.parse_insn(opcode,pos,data,max)) if(eh_insn.parse_insn(opcode,pos,data,max, is_be))
return true; return true;
eh_pgm.push_insn(eh_insn); eh_pgm.push_insn(eh_insn);
} }
return false; return false;
...@@ -1108,24 +1139,25 @@ bool cie_contents_t<ptrsize>::parse_cie( ...@@ -1108,24 +1139,25 @@ bool cie_contents_t<ptrsize>::parse_cie(
const uint64_t &cie_position, const uint64_t &cie_position,
const uint8_t* const data, const uint8_t* const data,
const uint64_t max, const uint64_t max,
const uint64_t eh_addr) const uint64_t eh_addr,
const bool is_be)
{ {
auto &c=*this; auto &c=*this;
const auto eh_frame_scoop_data= data; const auto eh_frame_scoop_data= data;
auto position=cie_position; auto position=cie_position;
auto length= uint64_t(0); auto length= uint64_t(0);
if(this->read_length(length, position, eh_frame_scoop_data, max)) if(this->read_length(length, position, eh_frame_scoop_data, max, is_be))
return true; return true;
auto end_pos=position+length; auto end_pos=position+length;
auto cie_id=uint32_t(0); auto cie_id=uint32_t(0);
if(this->read_type(cie_id, position, eh_frame_scoop_data, max)) if(this->read_type(cie_id, position, eh_frame_scoop_data, max, is_be))
return true; return true;
auto cie_version=uint8_t(0); auto cie_version=uint8_t(0);
if(this->read_type(cie_version, position, eh_frame_scoop_data, max)) if(this->read_type(cie_version, position, eh_frame_scoop_data, max, is_be))
return true; return true;
if(cie_version==1) if(cie_version==1)
...@@ -1153,7 +1185,7 @@ bool cie_contents_t<ptrsize>::parse_cie( ...@@ -1153,7 +1185,7 @@ bool cie_contents_t<ptrsize>::parse_cie(
if(cie_version==1) if(cie_version==1)
{ {
auto return_address_register_column_8=uint8_t(0); auto return_address_register_column_8=uint8_t(0);
if(this->read_type(return_address_register_column_8, position, eh_frame_scoop_data, max)) if(this->read_type(return_address_register_column_8, position, eh_frame_scoop_data, max, is_be))
return true; return true;
return_address_register_column=return_address_register_column_8; return_address_register_column=return_address_register_column_8;
} }
...@@ -1179,7 +1211,7 @@ bool cie_contents_t<ptrsize>::parse_cie( ...@@ -1179,7 +1211,7 @@ bool cie_contents_t<ptrsize>::parse_cie(
auto personality_pointer_size=uint64_t(0); auto personality_pointer_size=uint64_t(0);
if(augmentation.find("P") != string::npos) if(augmentation.find("P") != string::npos)
{ {
if(this->read_type(personality_encoding, position, eh_frame_scoop_data, max)) if(this->read_type(personality_encoding, position, eh_frame_scoop_data, max, is_be))
return true; return true;
personality_pointer_position=position; personality_pointer_position=position;
...@@ -1187,7 +1219,7 @@ bool cie_contents_t<ptrsize>::parse_cie( ...@@ -1187,7 +1219,7 @@ bool cie_contents_t<ptrsize>::parse_cie(
// we just need to record what's in the CIE, regardless of whether it's the actual // we just need to record what's in the CIE, regardless of whether it's the actual
// personality routine or it's the pointer to the personality routine. // personality routine or it's the pointer to the personality routine.
auto personality_encoding_sans_indirect = personality_encoding&(~DW_EH_PE_indirect); auto personality_encoding_sans_indirect = personality_encoding&(~DW_EH_PE_indirect);
if(this->read_type_with_encoding(personality_encoding_sans_indirect, personality, position, eh_frame_scoop_data, max, eh_addr)) if(this->read_type_with_encoding(personality_encoding_sans_indirect, personality, position, eh_frame_scoop_data, max, eh_addr, is_be))
return true; return true;
personality_pointer_size=position - personality_pointer_position; personality_pointer_size=position - personality_pointer_position;
} }
...@@ -1195,16 +1227,16 @@ bool cie_contents_t<ptrsize>::parse_cie( ...@@ -1195,16 +1227,16 @@ bool cie_contents_t<ptrsize>::parse_cie(
auto lsda_encoding=uint8_t(DW_EH_PE_omit); auto lsda_encoding=uint8_t(DW_EH_PE_omit);
if(augmentation.find("L") != string::npos) if(augmentation.find("L") != string::npos)
{ {
if(this->read_type(lsda_encoding, position, eh_frame_scoop_data, max)) if(this->read_type(lsda_encoding, position, eh_frame_scoop_data, max, is_be))
return true; return true;
} }
auto fde_encoding=uint8_t(DW_EH_PE_omit); auto fde_encoding=uint8_t(DW_EH_PE_omit);
if(augmentation.find("R") != string::npos) if(augmentation.find("R") != string::npos)
{ {
if(this->read_type(fde_encoding, position, eh_frame_scoop_data, max)) if(this->read_type(fde_encoding, position, eh_frame_scoop_data, max, is_be))
return true; return true;
} }
if(eh_pgm.parse_program(position, eh_frame_scoop_data, end_pos)) if(eh_pgm.parse_program(position, eh_frame_scoop_data, end_pos, is_be))
return true; return true;
...@@ -1261,7 +1293,7 @@ int64_t lsda_call_site_action_t<ptrsize>::getAction() const { return action;} ...@@ -1261,7 +1293,7 @@ int64_t lsda_call_site_action_t<ptrsize>::getAction() const { return action;}
template <int ptrsize> template <int ptrsize>
bool lsda_call_site_action_t<ptrsize>::parse_lcsa(uint64_t &pos, const uint8_t* const data, const uint64_t max, bool &end) bool lsda_call_site_action_t<ptrsize>::parse_lcsa(uint64_t &pos, const uint8_t* const data, const uint64_t max, bool &end, const bool is_be)
{ {
end=false; end=false;
if(this->read_sleb128(action, pos, data, max)) if(this->read_sleb128(action, pos, data, max))
...@@ -1314,7 +1346,8 @@ bool lsda_type_table_entry_t<ptrsize>::parse( ...@@ -1314,7 +1346,8 @@ bool lsda_type_table_entry_t<ptrsize>::parse(
const uint64_t index, const uint64_t index,
const uint8_t* const data, const uint8_t* const data,
const uint64_t max, const uint64_t max,
const uint64_t data_addr const uint64_t data_addr,
const bool is_be
) )
{ {
tt_encoding=p_tt_encoding; tt_encoding=p_tt_encoding;
...@@ -1339,7 +1372,7 @@ bool lsda_type_table_entry_t<ptrsize>::parse( ...@@ -1339,7 +1372,7 @@ bool lsda_type_table_entry_t<ptrsize>::parse(
} }
const auto orig_act_pos=uint64_t(tt_pos+(-static_cast<int64_t>(index)*tt_encoding_size)); const auto orig_act_pos=uint64_t(tt_pos+(-static_cast<int64_t>(index)*tt_encoding_size));
auto act_pos=uint64_t(tt_pos+(-static_cast<int64_t>(index)*tt_encoding_size)); auto act_pos=uint64_t(tt_pos+(-static_cast<int64_t>(index)*tt_encoding_size));
if(this->read_type_with_encoding(tt_encoding_sans_indir_sans_pcrel, pointer_to_typeinfo, act_pos, data, max, data_addr)) if(this->read_type_with_encoding(tt_encoding_sans_indir_sans_pcrel, pointer_to_typeinfo, act_pos, data, max, data_addr, is_be))
return true; return true;
// check if there's a 0 in the field // check if there's a 0 in the field
...@@ -1380,12 +1413,6 @@ const LSDACallSiteActionVector_t* lsda_call_site_t<ptrsize>::getActionTable() co ...@@ -1380,12 +1413,6 @@ const LSDACallSiteActionVector_t* lsda_call_site_t<ptrsize>::getActionTable() co
transform(ALLOF(action_table), back_inserter(action_table_cache), [](const lsda_call_site_action_t<ptrsize> &a) { return &a;}); transform(ALLOF(action_table), back_inserter(action_table_cache), [](const lsda_call_site_action_t<ptrsize> &a) { return &a;});
} }
return &action_table_cache; return &action_table_cache;
#if 0
auto ret=shared_ptr<LSDACallSiteActionVector_t>(new LSDACallSiteActionVector_t());
transform(ALLOF(action_table), back_inserter(*ret),
[](const lsda_call_site_action_t<ptrsize> &a) { return shared_ptr<LSDACallSiteAction_t>(new lsda_call_site_action_t<ptrsize>(a));});
return shared_ptr<LSDACallSiteActionVector_t>(ret);
#endif
} }
...@@ -1401,21 +1428,23 @@ bool lsda_call_site_t<ptrsize>::parse_lcs( ...@@ -1401,21 +1428,23 @@ bool lsda_call_site_t<ptrsize>::parse_lcs(
const uint64_t cs_max, /* call site table max */ const uint64_t cs_max, /* call site table max */
const uint64_t data_addr, const uint64_t data_addr,
const uint64_t landing_pad_base_addr, const uint64_t landing_pad_base_addr,
const uint64_t gcc_except_table_max) const uint64_t gcc_except_table_max,
const bool is_be
)
{ {
const auto smallest_max = min(cs_max,gcc_except_table_max); const auto smallest_max = min(cs_max,gcc_except_table_max);
call_site_addr_position = pos + data_addr; call_site_addr_position = pos + data_addr;
if(this->read_type_with_encoding(cs_table_encoding, call_site_offset, pos, data, smallest_max, data_addr)) if(this->read_type_with_encoding(cs_table_encoding, call_site_offset, pos, data, smallest_max, data_addr, is_be))
return true; return true;
call_site_addr=landing_pad_base_addr+call_site_offset; call_site_addr=landing_pad_base_addr+call_site_offset;
call_site_end_addr_position = pos + data_addr; call_site_end_addr_position = pos + data_addr;
if(this->read_type_with_encoding(cs_table_encoding, call_site_length, pos, data, smallest_max, data_addr)) if(this->read_type_with_encoding(cs_table_encoding, call_site_length, pos, data, smallest_max, data_addr, is_be))
return true; return true;
call_site_end_addr=call_site_addr+call_site_length; call_site_end_addr=call_site_addr+call_site_length;
landing_pad_addr_position = pos + data_addr; landing_pad_addr_position = pos + data_addr;
if(this->read_type_with_encoding(cs_table_encoding, landing_pad_offset, pos, data, smallest_max, data_addr)) if(this->read_type_with_encoding(cs_table_encoding, landing_pad_offset, pos, data, smallest_max, data_addr, is_be))
return true; return true;
landing_pad_addr_end_position = pos + data_addr; landing_pad_addr_end_position = pos + data_addr;
...@@ -1441,7 +1470,7 @@ bool lsda_call_site_t<ptrsize>::parse_lcs( ...@@ -1441,7 +1470,7 @@ bool lsda_call_site_t<ptrsize>::parse_lcs(
while(!end) while(!end)
{ {
lsda_call_site_action_t<ptrsize> lcsa; lsda_call_site_action_t<ptrsize> lcsa;
if(lcsa.parse_lcsa(act_table_pos, data, gcc_except_table_max, end)) /* expect action table after cs_max */ if(lcsa.parse_lcsa(act_table_pos, data, gcc_except_table_max, end, is_be)) /* expect action table after cs_max */
return true; return true;
action_table.push_back(lcsa); action_table.push_back(lcsa);
...@@ -1504,7 +1533,8 @@ bool lsda_t<ptrsize>::parse_lsda( ...@@ -1504,7 +1533,8 @@ bool lsda_t<ptrsize>::parse_lsda(
const uint64_t lsda_addr, const uint64_t lsda_addr,
//const DataScoop_t* gcc_except_scoop, //const DataScoop_t* gcc_except_scoop,
const ScoopReplacement_t *gcc_except_scoop, const ScoopReplacement_t *gcc_except_scoop,
const uint64_t fde_region_start const uint64_t fde_region_start,
const bool is_be
) )
{ {
// make sure there's a scoop and that we're in the range. // make sure there's a scoop and that we're in the range.
...@@ -1521,17 +1551,17 @@ bool lsda_t<ptrsize>::parse_lsda( ...@@ -1521,17 +1551,17 @@ bool lsda_t<ptrsize>::parse_lsda(
auto pos=uint64_t(lsda_addr-data_addr); auto pos=uint64_t(lsda_addr-data_addr);
auto start_pos=pos; auto start_pos=pos;
if(this->read_type(landing_pad_base_encoding, pos, (const uint8_t* const)data.data(), max)) if(this->read_type(landing_pad_base_encoding, pos, (const uint8_t* const)data.data(), max, is_be))
return true; return true;
if(landing_pad_base_encoding!=DW_EH_PE_omit) if(landing_pad_base_encoding!=DW_EH_PE_omit)
{ {
if(this->read_type_with_encoding(landing_pad_base_encoding,landing_pad_base_addr, pos, (const uint8_t* const)data.data(), max, data_addr)) if(this->read_type_with_encoding(landing_pad_base_encoding,landing_pad_base_addr, pos, (const uint8_t* const)data.data(), max, data_addr, is_be))
return true; return true;
} }
else else
landing_pad_base_addr=fde_region_start; landing_pad_base_addr=fde_region_start;
if(this->read_type(type_table_encoding, pos, (const uint8_t* const)data.data(), max)) if(this->read_type(type_table_encoding, pos, (const uint8_t* const)data.data(), max, is_be))
return true; return true;
auto type_table_pos=uint64_t(0); auto type_table_pos=uint64_t(0);
...@@ -1549,7 +1579,7 @@ bool lsda_t<ptrsize>::parse_lsda( ...@@ -1549,7 +1579,7 @@ bool lsda_t<ptrsize>::parse_lsda(
type_table_addr_location=0; type_table_addr_location=0;
} }
if(this->read_type(cs_table_encoding, pos, (const uint8_t* const)data.data(), max)) if(this->read_type(cs_table_encoding, pos, (const uint8_t* const)data.data(), max, is_be))
return true; return true;
cs_table_start_addr_location = pos + data_addr; cs_table_start_addr_location = pos + data_addr;
...@@ -1567,8 +1597,18 @@ bool lsda_t<ptrsize>::parse_lsda( ...@@ -1567,8 +1597,18 @@ bool lsda_t<ptrsize>::parse_lsda(
while(1) while(1)
{ {
lsda_call_site_t<ptrsize> lcs; lsda_call_site_t<ptrsize> lcs;
if(lcs.parse_lcs(action_table_start_addr, if(lcs.parse_lcs(
cs_table_start_addr,cs_table_encoding, pos, (const uint8_t* const)data.data(), cs_table_end, data_addr, landing_pad_base_addr, max)) action_table_start_addr,
cs_table_start_addr,
cs_table_encoding,
pos,
reinterpret_cast<const uint8_t* const>(data.data()),
cs_table_end, data_addr,
landing_pad_base_addr,
max,
is_be
)
)
{ {
return true; return true;
} }
...@@ -1591,7 +1631,7 @@ bool lsda_t<ptrsize>::parse_lsda( ...@@ -1591,7 +1631,7 @@ bool lsda_t<ptrsize>::parse_lsda(
// cout<<"Parsing TypeTable at -"<<index<<endl; // cout<<"Parsing TypeTable at -"<<index<<endl;
// 1-based indexing because of odd backwards indexing of type table. // 1-based indexing because of odd backwards indexing of type table.
lsda_type_table_entry_t <ptrsize> ltte; lsda_type_table_entry_t <ptrsize> ltte;
if(ltte.parse(type_table_encoding, type_table_pos, index, (const uint8_t* const)data.data(), max, data_addr )) if(ltte.parse(type_table_encoding, type_table_pos, index, (const uint8_t* const)data.data(), max, data_addr, is_be ))
return true; return true;
type_table.resize(std::max((size_t)index,(size_t)type_table.size())); type_table.resize(std::max((size_t)index,(size_t)type_table.size()));
type_table.at(index-1)=ltte; type_table.at(index-1)=ltte;
...@@ -1690,18 +1730,19 @@ bool fde_contents_t<ptrsize>::parse_fde( ...@@ -1690,18 +1730,19 @@ bool fde_contents_t<ptrsize>::parse_fde(
const uint8_t* const data, const uint8_t* const data,
const uint64_t max, const uint64_t max,
const uint64_t eh_addr, const uint64_t eh_addr,
const ScoopReplacement_t* gcc_except_scoop) const ScoopReplacement_t* gcc_except_scoop,
// const DataScoop_t* gcc_except_scoop) const bool is_be
)
{ {
auto &c=*this; auto &c=*this;
const auto eh_frame_scoop_data=data; const auto eh_frame_scoop_data=data;
if(cie_info.parse_cie(cie_position, data, max, eh_addr)) if(cie_info.parse_cie(cie_position, data, max, eh_addr, is_be))
return true; return true;
auto pos=fde_position; auto pos=fde_position;
auto length=uint64_t(0); auto length=uint64_t(0);
if(this->read_length(length, pos, eh_frame_scoop_data, max)) if(this->read_length(length, pos, eh_frame_scoop_data, max, is_be))
return true; return true;
...@@ -1709,17 +1750,17 @@ bool fde_contents_t<ptrsize>::parse_fde( ...@@ -1709,17 +1750,17 @@ bool fde_contents_t<ptrsize>::parse_fde(
//auto end_length_position=pos; //auto end_length_position=pos;
auto cie_id=uint32_t(0); auto cie_id=uint32_t(0);
if(this->read_type(cie_id, pos, eh_frame_scoop_data, max)) if(this->read_type(cie_id, pos, eh_frame_scoop_data, max, is_be))
return true; return true;
auto fde_start_addr=uint64_t(0); auto fde_start_addr=uint64_t(0);
auto fde_start_addr_position = pos; auto fde_start_addr_position = pos;
if(this->read_type_with_encoding(c.getCIE().getFDEEncoding(),fde_start_addr, pos, eh_frame_scoop_data, max, eh_addr)) if(this->read_type_with_encoding(c.getCIE().getFDEEncoding(),fde_start_addr, pos, eh_frame_scoop_data, max, eh_addr, is_be))
return true; return true;
auto fde_range_len=uint64_t(0); auto fde_range_len=uint64_t(0);
auto fde_end_addr_position = pos; auto fde_end_addr_position = pos;
if(this->read_type_with_encoding(c.getCIE().getFDEEncoding() & 0xf /* drop pc-rel bits */,fde_range_len, pos, eh_frame_scoop_data, max, eh_addr)) if(this->read_type_with_encoding(c.getCIE().getFDEEncoding() & 0xf /* drop pc-rel bits */,fde_range_len, pos, eh_frame_scoop_data, max, eh_addr, is_be))
return true; return true;
auto fde_end_addr=fde_start_addr+fde_range_len; auto fde_end_addr=fde_start_addr+fde_range_len;
...@@ -1735,15 +1776,15 @@ bool fde_contents_t<ptrsize>::parse_fde( ...@@ -1735,15 +1776,15 @@ bool fde_contents_t<ptrsize>::parse_fde(
auto fde_lsda_addr_size = uint64_t(0); auto fde_lsda_addr_size = uint64_t(0);
if(c.getCIE().getLSDAEncoding()!= DW_EH_PE_omit) if(c.getCIE().getLSDAEncoding()!= DW_EH_PE_omit)
{ {
if(this->read_type_with_encoding(c.getCIE().getLSDAEncoding(), lsda_addr, pos, eh_frame_scoop_data, max, eh_addr)) if(this->read_type_with_encoding(c.getCIE().getLSDAEncoding(), lsda_addr, pos, eh_frame_scoop_data, max, eh_addr, is_be))
return true; return true;
fde_lsda_addr_size = pos - fde_lsda_addr_position; fde_lsda_addr_size = pos - fde_lsda_addr_position;
if(lsda_addr!=0) if(lsda_addr!=0)
if(c.lsda.parse_lsda(lsda_addr,gcc_except_scoop, fde_start_addr)) if(c.lsda.parse_lsda(lsda_addr,gcc_except_scoop, fde_start_addr, is_be))
return true; return true;
} }
if(c.eh_pgm.parse_program(pos, eh_frame_scoop_data, end_pos)) if(c.eh_pgm.parse_program(pos, eh_frame_scoop_data, end_pos, is_be))
return true; return true;
c.fde_position = fde_position + eh_addr; c.fde_position = fde_position + eh_addr;
...@@ -1788,7 +1829,7 @@ void fde_contents_t<ptrsize>::print() const ...@@ -1788,7 +1829,7 @@ void fde_contents_t<ptrsize>::print() const
template <int ptrsize> template <int ptrsize>
bool split_eh_frame_impl_t<ptrsize>::iterate_fdes() bool split_eh_frame_impl_t<ptrsize>::iterate_fdes(const bool is_be)
{ {
auto eh_frame_scoop_str=eh_frame_scoop->getContents(); auto eh_frame_scoop_str=eh_frame_scoop->getContents();
auto eh_frame_scoop_data=(const uint8_t* const)eh_frame_scoop_str.c_str(); auto eh_frame_scoop_data=(const uint8_t* const)eh_frame_scoop_str.c_str();
...@@ -1803,7 +1844,7 @@ bool split_eh_frame_impl_t<ptrsize>::iterate_fdes() ...@@ -1803,7 +1844,7 @@ bool split_eh_frame_impl_t<ptrsize>::iterate_fdes()
auto old_position=position; auto old_position=position;
auto act_length=uint64_t(0); auto act_length=uint64_t(0);
if(eh_frame_util_t<ptrsize>::read_length(act_length, position, eh_frame_scoop_data, max)) if(eh_frame_util_t<ptrsize>::read_length(act_length, position, eh_frame_scoop_data, max, is_be))
break; break;
// length field has to be meaningful, 0 or -1 indicates end of segment // length field has to be meaningful, 0 or -1 indicates end of segment
...@@ -1815,7 +1856,7 @@ bool split_eh_frame_impl_t<ptrsize>::iterate_fdes() ...@@ -1815,7 +1856,7 @@ bool split_eh_frame_impl_t<ptrsize>::iterate_fdes()
auto cie_offset=uint32_t(0); auto cie_offset=uint32_t(0);
auto cie_offset_position=position; auto cie_offset_position=position;
if(eh_frame_util_t<ptrsize>::read_type(cie_offset,position, eh_frame_scoop_data, max)) if(eh_frame_util_t<ptrsize>::read_type(cie_offset,position, eh_frame_scoop_data, max, is_be))
break; break;
//cout << " [ " << setw(6) << hex << old_position << "] " ; //cout << " [ " << setw(6) << hex << old_position << "] " ;
...@@ -1828,7 +1869,7 @@ bool split_eh_frame_impl_t<ptrsize>::iterate_fdes() ...@@ -1828,7 +1869,7 @@ bool split_eh_frame_impl_t<ptrsize>::iterate_fdes()
{ {
//cout << "CIE length="<< dec << act_length << endl; //cout << "CIE length="<< dec << act_length << endl;
cie_contents_t<ptrsize> c; cie_contents_t<ptrsize> c;
if(c.parse_cie(old_position, data, max, eh_addr)) if(c.parse_cie(old_position, data, max, eh_addr, is_be))
return true; return true;
cies.push_back(c); cies.push_back(c);
} }
...@@ -1837,7 +1878,7 @@ bool split_eh_frame_impl_t<ptrsize>::iterate_fdes() ...@@ -1837,7 +1878,7 @@ bool split_eh_frame_impl_t<ptrsize>::iterate_fdes()
fde_contents_t<ptrsize> f; fde_contents_t<ptrsize> f;
auto cie_position = cie_offset_position - cie_offset; auto cie_position = cie_offset_position - cie_offset;
//cout << "FDE length="<< dec << act_length << " cie=[" << setw(6) << hex << cie_position << "]" << endl; //cout << "FDE length="<< dec << act_length << " cie=[" << setw(6) << hex << cie_position << "]" << endl;
if(f.parse_fde(old_position, cie_position, data, max, eh_addr, gcc_except_table_scoop.get())) if(f.parse_fde(old_position, cie_position, data, max, eh_addr, gcc_except_table_scoop.get(), is_be))
return true; return true;
//const auto old_fde_size=fdes.size(); //const auto old_fde_size=fdes.size();
fdes.insert(f); fdes.insert(f);
...@@ -1854,13 +1895,13 @@ bool split_eh_frame_impl_t<ptrsize>::iterate_fdes() ...@@ -1854,13 +1895,13 @@ bool split_eh_frame_impl_t<ptrsize>::iterate_fdes()
template <int ptrsize> template <int ptrsize>
bool split_eh_frame_impl_t<ptrsize>::parse() bool split_eh_frame_impl_t<ptrsize>::parse(const bool is_be)
{ {
if(eh_frame_scoop==NULL) if(eh_frame_scoop==NULL)
return true; // no frame info in this binary return true; // no frame info in this binary
if(iterate_fdes()) if(iterate_fdes(is_be))
return true; return true;
return false; return false;
...@@ -1889,13 +1930,6 @@ const EHProgramInstructionVector_t* eh_program_t<ptrsize>::getInstructions() con ...@@ -1889,13 +1930,6 @@ const EHProgramInstructionVector_t* eh_program_t<ptrsize>::getInstructions() con
transform(ALLOF(instructions), back_inserter(instructions_cache), [](const eh_program_insn_t<ptrsize> &a) { return &a;}); transform(ALLOF(instructions), back_inserter(instructions_cache), [](const eh_program_insn_t<ptrsize> &a) { return &a;});
} }
return &instructions_cache; return &instructions_cache;
#if 0
auto ret=shared_ptr<EHProgramInstructionVector_t>(new EHProgramInstructionVector_t());
transform(ALLOF(getInstructionsInternal()), back_inserter(*ret),
[](const eh_program_insn_t<ptrsize> &a) { return shared_ptr<EHProgramInstruction_t>(new eh_program_insn_t<ptrsize>(a));});
return shared_ptr<EHProgramInstructionVector_t>(ret);
#endif
} }
template <int ptrsize> template <int ptrsize>
...@@ -1906,12 +1940,6 @@ const TypeTableVector_t* lsda_t<ptrsize>::getTypeTable() const ...@@ -1906,12 +1940,6 @@ const TypeTableVector_t* lsda_t<ptrsize>::getTypeTable() const
transform(ALLOF(type_table), back_inserter(type_table_cache), [](const lsda_type_table_entry_t<ptrsize> &a) { return &a; }); transform(ALLOF(type_table), back_inserter(type_table_cache), [](const lsda_type_table_entry_t<ptrsize> &a) { return &a; });
} }
return &type_table_cache; return &type_table_cache;
#if 0
auto ret=shared_ptr<TypeTableVector_t>(new TypeTableVector_t());
transform(ALLOF(type_table), back_inserter(*ret),
[](const lsda_type_table_entry_t<ptrsize> &a) { return shared_ptr<LSDATypeTableEntry_t>(new lsda_type_table_entry_t<ptrsize>(a));});
return shared_ptr<TypeTableVector_t>(ret);
#endif
} }
...@@ -1923,12 +1951,6 @@ const CallSiteVector_t* lsda_t<ptrsize>::getCallSites() const ...@@ -1923,12 +1951,6 @@ const CallSiteVector_t* lsda_t<ptrsize>::getCallSites() const
transform(ALLOF(call_site_table), back_inserter(call_site_table_cache), [](const lsda_call_site_t<ptrsize> &a) { return &a;}); transform(ALLOF(call_site_table), back_inserter(call_site_table_cache), [](const lsda_call_site_t<ptrsize> &a) { return &a;});
} }
return &call_site_table_cache; return &call_site_table_cache;
#if 0
auto ret=shared_ptr<CallSiteVector_t>(new CallSiteVector_t());
transform(ALLOF(call_site_table), back_inserter(*ret),
[](const lsda_call_site_t<ptrsize> &a) { return shared_ptr<LSDACallSite_t>(new lsda_call_site_t<ptrsize>(a));});
return shared_ptr<CallSiteVector_t>(ret);
#endif
} }
...@@ -1940,12 +1962,6 @@ const FDEVector_t* split_eh_frame_impl_t<ptrsize>::getFDEs() const ...@@ -1940,12 +1962,6 @@ const FDEVector_t* split_eh_frame_impl_t<ptrsize>::getFDEs() const
transform(ALLOF(fdes), back_inserter(fdes_cache), [](const fde_contents_t<ptrsize> &a) { return &a; }); transform(ALLOF(fdes), back_inserter(fdes_cache), [](const fde_contents_t<ptrsize> &a) { return &a; });
} }
return &fdes_cache; return &fdes_cache;
#if 0
auto ret=shared_ptr<FDEVector_t>(new FDEVector_t());
transform(ALLOF(fdes), back_inserter(*ret),
[](const fde_contents_t<ptrsize> &a) { return shared_ptr<FDEContents_t>(new fde_contents_t<ptrsize>(a));});
return shared_ptr<FDEVector_t>(ret);
#endif
} }
template <int ptrsize> template <int ptrsize>
...@@ -1956,12 +1972,6 @@ const CIEVector_t* split_eh_frame_impl_t<ptrsize>::getCIEs() const ...@@ -1956,12 +1972,6 @@ const CIEVector_t* split_eh_frame_impl_t<ptrsize>::getCIEs() const
transform(ALLOF(cies), back_inserter(cies_cache), [](const cie_contents_t<ptrsize> &a) { return &a; }); transform(ALLOF(cies), back_inserter(cies_cache), [](const cie_contents_t<ptrsize> &a) { return &a; });
} }
return &cies_cache; return &cies_cache;
#if 0
auto ret=shared_ptr<CIEVector_t>(new CIEVector_t());
transform(ALLOF(cies), back_inserter(*ret),
[](const cie_contents_t<ptrsize> &a){ return shared_ptr<CIEContents_t>(new cie_contents_t<ptrsize>(a));});
return ret;
#endif
} }
template <int ptrsize> template <int ptrsize>
...@@ -2002,10 +2012,17 @@ unique_ptr<const EHFrameParser_t> EHFrameParser_t::factory(const string filename ...@@ -2002,10 +2012,17 @@ unique_ptr<const EHFrameParser_t> EHFrameParser_t::factory(const string filename
const auto ptrsize = elfiop->get_class()==ELFCLASS64 ? 8 : const auto ptrsize = elfiop->get_class()==ELFCLASS64 ? 8 :
elfiop->get_class()==ELFCLASS32 ? 4 : elfiop->get_class()==ELFCLASS32 ? 4 :
0; 0;
const auto file_endianness =
elfiop->get_encoding() == ELFDATA2LSB ? LITTLE :
elfiop->get_encoding() == ELFDATA2MSB ? BIG :
throw invalid_argument("Cannot detect endianness of binary file");
if(ptrsize==0) if(ptrsize==0)
throw invalid_argument(string() + "Invalid ELF class in : " + filename); throw invalid_argument(string() + "Invalid ELF class in : " + filename);
return EHFrameParser_t::factory(ptrsize, return EHFrameParser_t::factory(ptrsize, file_endianness,
eh_frame_section.first, eh_frame_section.second, eh_frame_section.first, eh_frame_section.second,
eh_frame_hdr_section.first, eh_frame_hdr_section.second, eh_frame_hdr_section.first, eh_frame_hdr_section.second,
gcc_except_table_section.first, gcc_except_table_section.second); gcc_except_table_section.first, gcc_except_table_section.second);
...@@ -2015,6 +2032,7 @@ unique_ptr<const EHFrameParser_t> EHFrameParser_t::factory(const string filename ...@@ -2015,6 +2032,7 @@ unique_ptr<const EHFrameParser_t> EHFrameParser_t::factory(const string filename
unique_ptr<const EHFrameParser_t> EHFrameParser_t::factory( unique_ptr<const EHFrameParser_t> EHFrameParser_t::factory(
uint8_t ptrsize, uint8_t ptrsize,
EHPEndianness_t endian_type,
const string eh_frame_data, const uint64_t eh_frame_data_start_addr, const string eh_frame_data, const uint64_t eh_frame_data_start_addr,
const string eh_frame_hdr_data, const uint64_t eh_frame_hdr_data_start_addr, const string eh_frame_hdr_data, const uint64_t eh_frame_hdr_data_start_addr,
const string gcc_except_table_data, const uint64_t gcc_except_table_data_start_addr const string gcc_except_table_data, const uint64_t gcc_except_table_data_start_addr
...@@ -2031,7 +2049,21 @@ unique_ptr<const EHFrameParser_t> EHFrameParser_t::factory( ...@@ -2031,7 +2049,21 @@ unique_ptr<const EHFrameParser_t> EHFrameParser_t::factory(
else else
throw out_of_range("ptrsize must be 4 or 8"); throw out_of_range("ptrsize must be 4 or 8");
ret_val->parse();
const auto is_big_endian = [] () -> bool
{
union
{
uint32_t i;
char c[4];
} bint = {0x01020304};
return bint.c[0] == 1;
};
const auto is_be = endian_type == BIG || ( is_big_endian() && endian_type == HOST) ;
ret_val->parse(is_be);
return unique_ptr<const EHFrameParser_t>(ret_val); return unique_ptr<const EHFrameParser_t>(ret_val);
} }
......
...@@ -49,17 +49,20 @@ class eh_frame_util_t ...@@ -49,17 +49,20 @@ class eh_frame_util_t
{ {
public: public:
template <class T> template <class T>
static bool read_type(T &value, uint64_t &position, const uint8_t* const data, const uint64_t max); static bool read_type(T &value, uint64_t &position, const uint8_t* const data, const uint64_t max, const bool is_be);
template <class T> template <class T>
static bool read_type_with_encoding static bool read_type_with_encoding (
(const uint8_t encoding, T &value, const uint8_t encoding, T &value,
uint64_t &position, uint64_t &position,
const uint8_t* const data, const uint8_t* const data,
const uint64_t max, const uint64_t max,
const uint64_t section_start_addr ); const uint64_t section_start_addr,
const bool is_be
);
static bool read_string static bool read_string (
(string &s, string &s,
uint64_t &position, uint64_t &position,
const uint8_t* const data, const uint8_t* const data,
const uint64_t max); const uint64_t max);
...@@ -67,23 +70,28 @@ class eh_frame_util_t ...@@ -67,23 +70,28 @@ class eh_frame_util_t
// see https://en.wikipedia.org/wiki/LEB128 // see https://en.wikipedia.org/wiki/LEB128
static bool read_uleb128 static bool read_uleb128
( uint64_t &result, (
uint64_t &result,
uint64_t &position, uint64_t &position,
const uint8_t* const data, const uint8_t* const data,
const uint64_t max); const uint64_t max
);
// see https://en.wikipedia.org/wiki/LEB128 // see https://en.wikipedia.org/wiki/LEB128
static bool read_sleb128 ( static bool read_sleb128 (
int64_t &result, int64_t &result,
uint64_t &position, uint64_t &position,
const uint8_t* const data, const uint8_t* const data,
const uint64_t max); const uint64_t max
);
static bool read_length( static bool read_length(
uint64_t &act_length, uint64_t &act_length,
uint64_t &position, uint64_t &position,
const uint8_t* const data, const uint8_t* const data,
const uint64_t max); const uint64_t max,
const bool is_be
);
}; };
template <int ptrsize> template <int ptrsize>
...@@ -113,7 +121,9 @@ class eh_program_insn_t : public EHProgramInstruction_t ...@@ -113,7 +121,9 @@ class eh_program_insn_t : public EHProgramInstruction_t
uint8_t opcode, uint8_t opcode,
uint64_t &pos, uint64_t &pos,
const uint8_t* const data, const uint8_t* const data,
const uint64_t &max); const uint64_t &max,
const bool is_be
);
bool isNop() const ; bool isNop() const ;
bool isDefCFAOffset() const ; bool isDefCFAOffset() const ;
...@@ -144,7 +154,9 @@ class eh_program_t : public EHProgram_t ...@@ -144,7 +154,9 @@ class eh_program_t : public EHProgram_t
bool parse_program( bool parse_program(
const uint64_t& program_start_position, const uint64_t& program_start_position,
const uint8_t* const data, const uint8_t* const data,
const uint64_t &max_program_pos); const uint64_t &max_program_pos,
const bool is_be
);
virtual const EHProgramInstructionVector_t* getInstructions() const ; virtual const EHProgramInstructionVector_t* getInstructions() const ;
vector<eh_program_insn_t <ptrsize> >& getInstructionsInternal() ; vector<eh_program_insn_t <ptrsize> >& getInstructionsInternal() ;
const vector<eh_program_insn_t <ptrsize> >& getInstructionsInternal() const ; const vector<eh_program_insn_t <ptrsize> >& getInstructionsInternal() const ;
...@@ -163,19 +175,19 @@ class cie_contents_t : public CIEContents_t, private eh_frame_util_t<ptrsize> ...@@ -163,19 +175,19 @@ class cie_contents_t : public CIEContents_t, private eh_frame_util_t<ptrsize>
private: private:
uint64_t cie_position; uint64_t cie_position;
uint64_t length; uint64_t length;
uint8_t cie_id; uint8_t cie_id;
uint8_t cie_version; uint8_t cie_version;
string augmentation; string augmentation;
uint64_t code_alignment_factor; uint64_t code_alignment_factor;
int64_t data_alignment_factor; int64_t data_alignment_factor;
uint64_t return_address_register_column; uint64_t return_address_register_column;
uint64_t augmentation_data_length; uint64_t augmentation_data_length;
uint8_t personality_encoding; uint8_t personality_encoding;
uint64_t personality; uint64_t personality;
uint64_t personality_pointer_position; uint64_t personality_pointer_position;
uint64_t personality_pointer_size; uint64_t personality_pointer_size;
uint8_t lsda_encoding; uint8_t lsda_encoding;
uint8_t fde_encoding; uint8_t fde_encoding;
eh_program_t<ptrsize> eh_pgm; eh_program_t<ptrsize> eh_pgm;
public: public:
...@@ -186,8 +198,8 @@ class cie_contents_t : public CIEContents_t, private eh_frame_util_t<ptrsize> ...@@ -186,8 +198,8 @@ class cie_contents_t : public CIEContents_t, private eh_frame_util_t<ptrsize>
uint64_t getPosition() const { return cie_position; } uint64_t getPosition() const { return cie_position; }
uint64_t getLength() const { return length; } uint64_t getLength() const { return length; }
uint64_t getCAF() const ; uint64_t getCAF() const ;
int64_t getDAF() const ; int64_t getDAF() const ;
uint8_t getPersonalityEncoding() const { return personality_encoding; } uint8_t getPersonalityEncoding() const { return personality_encoding; }
uint64_t getPersonality() const ; uint64_t getPersonality() const ;
uint64_t getPersonalityPointerPosition() const { return personality_pointer_position; }; uint64_t getPersonalityPointerPosition() const { return personality_pointer_position; };
uint64_t getPersonalityPointerSize() const { return personality_pointer_size; }; uint64_t getPersonalityPointerSize() const { return personality_pointer_size; };
...@@ -201,7 +213,9 @@ class cie_contents_t : public CIEContents_t, private eh_frame_util_t<ptrsize> ...@@ -201,7 +213,9 @@ class cie_contents_t : public CIEContents_t, private eh_frame_util_t<ptrsize>
const uint64_t &cie_position, const uint64_t &cie_position,
const uint8_t* const data, const uint8_t* const data,
const uint64_t max, const uint64_t max,
const uint64_t eh_addr); const uint64_t eh_addr,
const bool is_be
);
void print(const uint64_t startAddr) const ; void print(const uint64_t startAddr) const ;
}; };
...@@ -215,7 +229,7 @@ class lsda_call_site_action_t : public LSDACallSiteAction_t, private eh_frame_ut ...@@ -215,7 +229,7 @@ class lsda_call_site_action_t : public LSDACallSiteAction_t, private eh_frame_ut
lsda_call_site_action_t() ; lsda_call_site_action_t() ;
int64_t getAction() const ; int64_t getAction() const ;
bool parse_lcsa(uint64_t &pos, const uint8_t* const data, const uint64_t max, bool &end); bool parse_lcsa(uint64_t &pos, const uint8_t* const data, const uint64_t max, bool &end, const bool is_be);
void print() const; void print() const;
}; };
...@@ -243,7 +257,8 @@ class lsda_type_table_entry_t: public LSDATypeTableEntry_t, private eh_frame_uti ...@@ -243,7 +257,8 @@ class lsda_type_table_entry_t: public LSDATypeTableEntry_t, private eh_frame_uti
const uint64_t index, const uint64_t index,
const uint8_t* const data, const uint8_t* const data,
const uint64_t max, const uint64_t max,
const uint64_t data_addr const uint64_t data_addr,
const bool is_be
); );
void print() const; void print() const;
...@@ -295,7 +310,9 @@ class lsda_call_site_t : public LSDACallSite_t, private eh_frame_util_t<ptrsize> ...@@ -295,7 +310,9 @@ class lsda_call_site_t : public LSDACallSite_t, private eh_frame_util_t<ptrsize>
const uint64_t max, /* call site table max */ const uint64_t max, /* call site table max */
const uint64_t data_addr, const uint64_t data_addr,
const uint64_t landing_pad_base_addr, const uint64_t landing_pad_base_addr,
const uint64_t gcc_except_table_max); const uint64_t gcc_except_table_max,
const bool is_be
);
void print() const; void print() const;
...@@ -345,7 +362,8 @@ class lsda_t : public LSDA_t, private eh_frame_util_t<ptrsize> ...@@ -345,7 +362,8 @@ class lsda_t : public LSDA_t, private eh_frame_util_t<ptrsize>
uint8_t getTTEncoding() const ; uint8_t getTTEncoding() const ;
bool parse_lsda(const uint64_t lsda_addr, bool parse_lsda(const uint64_t lsda_addr,
const ScoopReplacement_t* gcc_except_scoop_data, const ScoopReplacement_t* gcc_except_scoop_data,
const uint64_t fde_region_start const uint64_t fde_region_start,
const bool is_be
); );
void print() const; void print() const;
uint64_t getLandingPadBaseAddress() const { return landing_pad_base_addr; } uint64_t getLandingPadBaseAddress() const { return landing_pad_base_addr; }
...@@ -370,16 +388,16 @@ class fde_contents_t : public FDEContents_t, eh_frame_util_t<ptrsize> ...@@ -370,16 +388,16 @@ class fde_contents_t : public FDEContents_t, eh_frame_util_t<ptrsize>
uint64_t fde_position; uint64_t fde_position;
uint64_t cie_position; uint64_t cie_position;
uint64_t length; uint64_t length;
uint8_t id; uint8_t id;
uint64_t fde_start_addr; uint64_t fde_start_addr;
uint64_t fde_end_addr; uint64_t fde_end_addr;
uint64_t fde_range_len; uint64_t fde_range_len;
uint64_t lsda_addr; uint64_t lsda_addr;
uint64_t fde_start_addr_position; uint64_t fde_start_addr_position;
uint64_t fde_end_addr_position; uint64_t fde_end_addr_position;
uint64_t fde_end_addr_size; uint64_t fde_end_addr_size;
uint64_t fde_lsda_addr_position; uint64_t fde_lsda_addr_position;
uint64_t fde_lsda_addr_size; uint64_t fde_lsda_addr_size;
lsda_t<ptrsize> lsda; lsda_t<ptrsize> lsda;
eh_program_t<ptrsize> eh_pgm; eh_program_t<ptrsize> eh_pgm;
...@@ -409,10 +427,10 @@ class fde_contents_t : public FDEContents_t, eh_frame_util_t<ptrsize> ...@@ -409,10 +427,10 @@ class fde_contents_t : public FDEContents_t, eh_frame_util_t<ptrsize>
const LSDA_t* getLSDA() const { return &lsda; } // shared_ptr<LSDA_t>(new lsda_t<ptrsize>(lsda)) ; } const LSDA_t* getLSDA() const { return &lsda; } // shared_ptr<LSDA_t>(new lsda_t<ptrsize>(lsda)) ; }
const lsda_t<ptrsize>& getLSDAInternal() const { return lsda; } const lsda_t<ptrsize>& getLSDAInternal() const { return lsda; }
uint64_t getLSDAAddress() const { return lsda_addr; } uint64_t getLSDAAddress() const { return lsda_addr; }
uint64_t getStartAddressPosition() const { return fde_start_addr_position; } uint64_t getStartAddressPosition() const { return fde_start_addr_position; }
uint64_t getEndAddressPosition() const { return fde_end_addr_position; } uint64_t getEndAddressPosition() const { return fde_end_addr_position; }
uint64_t getEndAddressSize() const { return fde_end_addr_size; } uint64_t getEndAddressSize() const { return fde_end_addr_size; }
uint64_t getLSDAAddressPosition() const { return fde_lsda_addr_position; } uint64_t getLSDAAddressPosition() const { return fde_lsda_addr_position; }
uint64_t getLSDAAddressSize() const { return fde_lsda_addr_size; } uint64_t getLSDAAddressSize() const { return fde_lsda_addr_size; }
...@@ -422,7 +440,8 @@ class fde_contents_t : public FDEContents_t, eh_frame_util_t<ptrsize> ...@@ -422,7 +440,8 @@ class fde_contents_t : public FDEContents_t, eh_frame_util_t<ptrsize>
const uint8_t* const data, const uint8_t* const data,
const uint64_t max, const uint64_t max,
const uint64_t eh_addr, const uint64_t eh_addr,
const ScoopReplacement_t *gcc_except_scoop); const ScoopReplacement_t *gcc_except_scoop,
const bool is_be);
void print() const; void print() const;
...@@ -449,7 +468,7 @@ class split_eh_frame_impl_t : public EHFrameParser_t ...@@ -449,7 +468,7 @@ class split_eh_frame_impl_t : public EHFrameParser_t
mutable FDEVector_t fdes_cache; mutable FDEVector_t fdes_cache;
bool iterate_fdes(); bool iterate_fdes(const bool is_be);
public: public:
...@@ -466,7 +485,7 @@ class split_eh_frame_impl_t : public EHFrameParser_t ...@@ -466,7 +485,7 @@ class split_eh_frame_impl_t : public EHFrameParser_t
{ {
} }
bool parse(); bool parse(const bool is_be);
void print() const; void print() const;
virtual const FDEVector_t* getFDEs() const; virtual const FDEVector_t* getFDEs() const;
......