From 96b5118388bd0a11d6fcd6e81a58493815f67243 Mon Sep 17 00:00:00 2001
From: Jason Hiser <jdhiser@gmail.com>
Date: Fri, 30 Jun 2023 17:38:14 -0400
Subject: [PATCH] in progress

---
 src/arm_ehp.cpp  | 35 +++++++++++++++++++++++++----------
 src/ehp_priv.hpp | 48 +++++++++++++++++++++++++++---------------------
 test/test.cpp    |  4 ++++
 3 files changed, 56 insertions(+), 31 deletions(-)

diff --git a/src/arm_ehp.cpp b/src/arm_ehp.cpp
index d353e04..5cd61d0 100644
--- a/src/arm_ehp.cpp
+++ b/src/arm_ehp.cpp
@@ -54,20 +54,20 @@ bool split_arm_eh_frame_impl_t<ptrsize>::parse(const bool is_be)
 		{
 			// fetch the first word of the lsda.
 			throw_assert(extab_scoop->getStart() <= lsda_addr && lsda_addr <= extab_scoop->getEnd());
-			cout << "Found out-of-line unwind info." << endl << hex;
+			// cout << "Found out-of-line unwind info." << endl << hex;
 			unwind_pgm=parse_arm_eh_pgm(lsda_addr,extab_scoop.get(),fde, is_be);
 		}
 		if(contains_inline_unwind_entry )
 		{
-			cout << "Found inline_entry:"  << endl << hex;
+			// cout << "Found inline_entry:"  << endl << hex;
 			unwind_pgm=parse_arm_eh_pgm(current_address+4,exidx_scoop.get(),fde, is_be);
 		}
-		cout << "\tFde ("<< fde.getStartAddress();
-		cout << "Unwind pgm = " << hex << endl;
-		for(auto byte : unwind_pgm)
-		{
-			cout << "\t" << +byte << endl;
-		}
+		//cout << "\tFde ("<< fde.getStartAddress();
+		//cout << "Unwind pgm = " << hex << endl;
+		//for(auto byte : unwind_pgm)
+		//{
+			//cout << "\t" << +byte << endl;
+		//}
 		fde.setProgram(arm_eh_program_t<ptrsize>{unwind_pgm});
 		local_fdes.push_back(fde);
 
@@ -117,7 +117,7 @@ vector<uint8_t> split_arm_eh_frame_impl_t<ptrsize>::parse_arm_eh_pgm(const uint6
 		const auto byte3 = (first_word >> 16)&0xff;
 		const auto byte4 = (first_word >> 24)&0xff;
 		const auto personality_index = byte4 & 0xf;
-		cout << "Found arm32-specific personality routine, pr" << hex << personality_index << endl; 
+		// cout << "Found arm32-specific personality routine, pr" << hex << personality_index << endl; 
 		switch(personality_index)
 		{
 			case 0:
@@ -155,7 +155,7 @@ vector<uint8_t> split_arm_eh_frame_impl_t<ptrsize>::parse_arm_eh_pgm(const uint6
 		const auto offset_to_personality_routine = handle_pcrel31(first_word);
 		const auto personality_routine_addr=lsda_addr+offset_to_personality_routine;
 		fde.setPersonality(personality_routine_addr);
-		cout << "Found generic model with personality = " << hex << personality_routine_addr << endl; 
+		// cout << "Found generic model with personality = " << hex << personality_routine_addr << endl; 
 		const auto second_word = *reinterpret_cast<const uint32_t*>(&contents[start_offset+4]);
 		const auto byte1 = (second_word >> 0 )&0xff;
 		const auto byte2 = (second_word >> 8 )&0xff;
@@ -366,3 +366,18 @@ void arm_eh_program_insn_t<ptrsize>::print(uint64_t &pc, int64_t caf) const
 	cout << endl;
 }
 
+
+
+template <int ptrsize>
+void arm_fde_contents_t<ptrsize>::print() const
+{
+
+        cout << "start_addr = " << hex << fde_start_addr << endl;
+        cout << "end_addr   = " << hex << fde_end_addr << endl;
+        cout << "lsda_addr  = " << hex << fde_lsda_addr << endl;
+        cout << "can_unwind = " << boolalpha << can_unwind << endl;
+//        lsda_t<ptrsize> lsda;
+//        arm_eh_program_t<ptrsize> eh_pgm;
+//        arm_cie_contents_t<ptrsize> cie;
+}
+
diff --git a/src/ehp_priv.hpp b/src/ehp_priv.hpp
index 7ac9f9a..ab5721a 100644
--- a/src/ehp_priv.hpp
+++ b/src/ehp_priv.hpp
@@ -524,23 +524,29 @@ class arm_cie_contents_t : public CIEContents_t, private eh_frame_util_t<ptrsize
 	private:
 	uint64_t personality;
 
+	// there's not really a CIE on arm mode,  so there's no pgm.
+	// but we declare one so people cna inspect that it's empty.
+	const eh_program_t<ptrsize> pgm; 
 	public:
 
-	arm_cie_contents_t() {};
+	arm_cie_contents_t() 
+		: personality(0)
+	{
+	}
 	
-	const eh_program_t<ptrsize>& getProgram() const { throw std::runtime_error( " not implimented"); }
-	uint64_t getPosition() const { throw std::runtime_error( " not implimented"); }
-	uint64_t getLength() const { throw std::runtime_error( " not implimented"); }
-	uint64_t getCAF() const { throw std::runtime_error( " not implimented"); }
-	int64_t  getDAF() const { throw std::runtime_error( " not implimented"); }
-	uint8_t  getPersonalityEncoding() const { throw std::runtime_error( " not implimented"); }
+	const eh_program_t<ptrsize>& getProgram() const { return pgm; } 
+	uint64_t getPosition() const { throw std::runtime_error( " not implemented"); }
+	uint64_t getLength() const { throw std::runtime_error( " not implemented"); }
+	uint64_t getCAF() const { return 4; }
+	int64_t  getDAF() const { return 4; }
+	uint8_t  getPersonalityEncoding() const { return 0; }
 	uint64_t getPersonality() const { return personality; }
-	uint64_t getPersonalityPointerPosition() const  { throw std::runtime_error( " not implimented"); }
-	uint64_t getPersonalityPointerSize() const  { throw std::runtime_error( " not implimented"); }
-	uint64_t getReturnRegister() const  { throw std::runtime_error( " not implimented"); }
-	string getAugmentation() const  { throw std::runtime_error( " not implimented"); }
-	uint8_t getLSDAEncoding() const  { throw std::runtime_error( " not implimented"); }
-	uint8_t getFDEEncoding() const  { throw std::runtime_error( " not implimented"); }
+	uint64_t getPersonalityPointerPosition() const  { throw std::runtime_error( " not implemented"); }
+	uint64_t getPersonalityPointerSize() const  { throw std::runtime_error( " not implemented"); }
+	uint64_t getReturnRegister() const  { return 0; }
+	string getAugmentation() const  { throw std::runtime_error( " not implemented"); }
+	uint8_t getLSDAEncoding() const  { throw std::runtime_error( " not implemented"); }
+	uint8_t getFDEEncoding() const  { throw std::runtime_error( " not implemented"); }
 
 	virtual void print(const uint64_t startAddr) const
 	{
@@ -573,7 +579,7 @@ class arm_eh_program_insn_t  : public EHProgramInstruction_t
         virtual bool isRestoreState() const { return false; }
         virtual bool isRememberState() const { return false; }
         virtual const EHProgramInstructionByteVector_t& getBytes() const { return program_bytes; }
-        virtual bool advance(uint64_t &cur_addr, uint64_t CAF)     const { throw std::runtime_error("not implemented");  }
+        virtual bool advance(uint64_t &cur_addr, uint64_t CAF)     const { return false; /* no advance operations for arm */ }
 
 	private:
 
@@ -618,7 +624,7 @@ class arm_fde_contents_t : public FDEContents_t, eh_frame_util_t<ptrsize>
 		fde_end_addr(end_addr)
 	{} 
 
-        virtual uint64_t getPosition() const { throw std::runtime_error( " not implimented"); }
+        virtual uint64_t getPosition() const { throw std::runtime_error( " not implemented"); }
         virtual uint64_t getLength() const { return fde_end_addr-fde_start_addr+1; }
         virtual uint64_t getStartAddress() const { return fde_start_addr; }
         virtual uint64_t getEndAddress() const { return fde_end_addr; }
@@ -628,12 +634,12 @@ class arm_fde_contents_t : public FDEContents_t, eh_frame_util_t<ptrsize>
         virtual const EHProgram_t& getProgram() const { return eh_pgm; }
         virtual const LSDA_t* getLSDA() const { return &lsda; }
         virtual uint64_t getLSDAAddress() const { return fde_lsda_addr; }
-        virtual uint64_t getStartAddressPosition() const { throw std::runtime_error(" not implimented"); }
-        virtual uint64_t getEndAddressPosition() const { throw std::runtime_error(" not implimented"); }
-        virtual uint64_t getEndAddressSize() const { throw std::runtime_error(" not implimented"); }
-        virtual uint64_t getLSDAAddressPosition() const { throw std::runtime_error(" not implimented"); }
-        virtual uint64_t getLSDAAddressSize() const { throw std::runtime_error(" not implimented"); }
-        virtual void print() const { throw std::runtime_error(" not implimented"); }
+        virtual uint64_t getStartAddressPosition() const { throw std::runtime_error(" not implemented"); }
+        virtual uint64_t getEndAddressPosition() const { throw std::runtime_error(" not implemented"); }
+        virtual uint64_t getEndAddressSize() const { throw std::runtime_error(" not implemented"); }
+        virtual uint64_t getLSDAAddressPosition() const { throw std::runtime_error(" not implemented"); }
+        virtual uint64_t getLSDAAddressSize() const { throw std::runtime_error(" not implemented"); }
+        virtual void print() const ;
 
 	void setEndAddress(uint64_t end) { fde_end_addr = end; }
 	bool getCanUnwind() const { return can_unwind; }
diff --git a/test/test.cpp b/test/test.cpp
index 8924267..1ca43c4 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -38,7 +38,11 @@ void print_lps(const EHFrameParser_t* ehp)
 	for(const auto fde : *fdes)
 	{
 		cout<<"Found FDE at : " << fde->getStartAddress() << "-"<<fde->getEndAddress()<<endl;
+		fde->print();
 		fde->getProgram().print(fde->getStartAddress(),1);
+		const auto &cie=fde->getCIE();
+		const auto &personality=cie.getPersonality();
+		cout << "Personality: " << hex << personality << endl;
 		const auto lsda=fde->getLSDA();
 		assert(lsda);
 		lsda->print();
-- 
GitLab