From 348cdd27a02304827a825c2953d27ceb4a88ba10 Mon Sep 17 00:00:00 2001
From: Jason Hiser <jdhiser@gmail.com>
Date: Wed, 13 Feb 2019 11:22:09 -0500
Subject: [PATCH] Updates to move SDK-ify the dollops

---
 include/plugin_man.h          |   2 +-
 include/sizer/sizer_arm64.hpp |   6 +-
 include/sizer/sizer_base.hpp  |   4 +-
 include/sizer/sizer_x86.hpp   |   2 +-
 include/zipr_all.h            |   2 +
 include/zipr_dollop.h         | 122 +++++++++++++++++++++++++++++++
 src/dollop.cpp                | 131 +++++++++++++++++++++++-----------
 src/pinner_arm64.cpp          |   2 +-
 src/pinner_x86.cpp            |  13 ++--
 src/plugin_man.cpp            |   6 +-
 src/sizer_arm64.cpp           |   6 +-
 src/sizer_base.cpp            |  10 ++-
 src/sizer_x86.cpp             |   6 +-
 src/zipr.cpp                  |  48 ++++++-------
 src/zipr_dollop_man.cpp       |  76 +++++++++-----------
 15 files changed, 293 insertions(+), 143 deletions(-)
 create mode 100644 include/zipr_dollop.h

diff --git a/include/plugin_man.h b/include/plugin_man.h
index a90efc215..6a1b10abc 100644
--- a/include/plugin_man.h
+++ b/include/plugin_man.h
@@ -45,7 +45,7 @@ class ZiprPluginManager_t : public ZiprPluginInterface_t
 
 		virtual bool DoPluginsPlop(IRDB_SDK::Instruction_t*,std::list<DLFunctionHandle_t>&);
 
-		virtual bool DoesPluginAddress(const Dollop_t *, const RangeAddress_t &, Range_t &, bool &coalesce, bool &fallthrough_allowed, DLFunctionHandle_t &);
+		virtual bool DoesPluginAddress(const Zipr_SDK::Dollop_t *, const RangeAddress_t &, Range_t &, bool &coalesce, bool &fallthrough_allowed, DLFunctionHandle_t &);
 		virtual bool DoesPluginRetargetCallback(const RangeAddress_t &, const DollopEntry_t *, RangeAddress_t &, DLFunctionHandle_t &) ;
 		virtual bool DoesPluginRetargetPin(const RangeAddress_t &, const Dollop_t *, RangeAddress_t &, DLFunctionHandle_t &) ;
 
diff --git a/include/sizer/sizer_arm64.hpp b/include/sizer/sizer_arm64.hpp
index f85dc4cb5..797738276 100644
--- a/include/sizer/sizer_arm64.hpp
+++ b/include/sizer/sizer_arm64.hpp
@@ -4,13 +4,13 @@
 class ZiprSizerARM64_t : public ZiprSizerBase_t
 {
 	private:
-	RangeAddress_t TBZPlopDollopEntryWithTarget    (DollopEntry_t *entry, RangeAddress_t override_place, RangeAddress_t override_target) const;
-	RangeAddress_t DefaultPlopDollopEntryWithTarget(DollopEntry_t *entry, RangeAddress_t override_place, RangeAddress_t override_target) const;
+	RangeAddress_t TBZPlopDollopEntryWithTarget    (Zipr_SDK::DollopEntry_t *entry, RangeAddress_t override_place, RangeAddress_t override_target) const;
+	RangeAddress_t DefaultPlopDollopEntryWithTarget(Zipr_SDK::DollopEntry_t *entry, RangeAddress_t override_place, RangeAddress_t override_target) const;
 
 	public:
 	ZiprSizerARM64_t(Zipr_SDK::Zipr_t* p_zipr_obj);
 	size_t DetermineInsnSize(IRDB_SDK::Instruction_t*, bool account_for_jump = true) const override;
-	virtual RangeAddress_t PlopDollopEntryWithTarget(DollopEntry_t *entry, RangeAddress_t override_place, RangeAddress_t override_target) const override;
+	virtual RangeAddress_t PlopDollopEntryWithTarget(Zipr_SDK::DollopEntry_t *entry, RangeAddress_t override_place, RangeAddress_t override_target) const override;
 
 
 };
diff --git a/include/sizer/sizer_base.hpp b/include/sizer/sizer_base.hpp
index 6d20bf2b7..2dbbe71de 100644
--- a/include/sizer/sizer_base.hpp
+++ b/include/sizer/sizer_base.hpp
@@ -24,10 +24,10 @@ class ZiprSizerBase_t
 		 * makes sure not to overcalculate the trampoline
 		 * space to accomodate for the fallthroughs.
 		 */
-		virtual size_t DetermineDollopSizeInclFallthrough(Dollop_t *dollop) const;
+		virtual size_t DetermineDollopSizeInclFallthrough(Zipr_SDK::Dollop_t *dollop) const;
 		virtual size_t DetermineInsnSize(IRDB_SDK::Instruction_t*, bool account_for_jump = true) const =0;
 		virtual Range_t DoPlacement(size_t pminimum_valid_req_size) const;
-		virtual RangeAddress_t PlopDollopEntryWithTarget( DollopEntry_t *entry, RangeAddress_t override_place, RangeAddress_t override_target) const =0;
+		virtual RangeAddress_t PlopDollopEntryWithTarget(Zipr_SDK::DollopEntry_t *entry, RangeAddress_t override_place, RangeAddress_t override_target) const =0;
 
 		// maybe try to make these private/protected and provide getters eventually.
 		const size_t CALLBACK_TRAMPOLINE_SIZE;
diff --git a/include/sizer/sizer_x86.hpp b/include/sizer/sizer_x86.hpp
index 30897406a..69b51796d 100644
--- a/include/sizer/sizer_x86.hpp
+++ b/include/sizer/sizer_x86.hpp
@@ -7,7 +7,7 @@ class ZiprSizerX86_t  : public ZiprSizerBase_t
 	public:
 		ZiprSizerX86_t(Zipr_SDK::Zipr_t* p_zipr_obj);
                 size_t DetermineInsnSize(IRDB_SDK::Instruction_t*, bool account_for_jump = true) const override;
-		virtual RangeAddress_t PlopDollopEntryWithTarget( DollopEntry_t *entry, RangeAddress_t override_place, RangeAddress_t override_target) const override;
+		virtual RangeAddress_t PlopDollopEntryWithTarget(Zipr_SDK::DollopEntry_t *entry, RangeAddress_t override_place, RangeAddress_t override_target) const override;
 
 
 };
diff --git a/include/zipr_all.h b/include/zipr_all.h
index 5a18a3609..e099029ee 100644
--- a/include/zipr_all.h
+++ b/include/zipr_all.h
@@ -72,4 +72,6 @@ using namespace Zipr_SDK;
 
 };
 
+#include <zipr_dollop.h>
+
 #endif
diff --git a/include/zipr_dollop.h b/include/zipr_dollop.h
new file mode 100644
index 000000000..3d55476bc
--- /dev/null
+++ b/include/zipr_dollop.h
@@ -0,0 +1,122 @@
+#include <assert.h>
+#include <list>
+
+namespace zipr
+{
+	using namespace std;
+	using namespace IRDB_SDK;
+
+	class Dollop_t;
+	class DollopManager_t;
+
+	class Placeable_t  : virtual public Zipr_SDK::Placeable_t
+	{
+		public:
+			Placeable_t() : m_is_placed(false), m_placed_address(0) {}
+			void Place(RangeAddress_t place) {
+					assert(!m_is_placed);
+					m_is_placed = true;
+					m_placed_address = place;
+			};
+			RangeAddress_t getPlace() const { return m_placed_address; }
+			bool isPlaced() const { return m_is_placed; }
+		protected:
+			bool m_is_placed;
+			RangeAddress_t m_placed_address;
+
+		friend ostream &operator<<(ostream &, const Placeable_t &);
+	};
+
+
+	class DollopPatch_t : virtual public Zipr_SDK::DollopPatch_t, public Placeable_t 
+	{
+		public:
+			DollopPatch_t(Zipr_SDK::Dollop_t *target) : m_target(target) {};
+			DollopPatch_t() : m_target(NULL) { };
+
+			Zipr_SDK::Dollop_t *getTarget() const { return m_target; }
+			void setTarget(Zipr_SDK::Dollop_t *target) { m_target = target; }
+
+			friend ostream &operator<<(ostream &, const DollopPatch_t &);
+		private:
+			Zipr_SDK::Dollop_t *m_target;
+	};
+
+	class DollopEntry_t : virtual public Zipr_SDK::DollopEntry_t, public Placeable_t 
+	{
+		public:
+			DollopEntry_t(Instruction_t *insn, Zipr_SDK::Dollop_t *member_of);
+			Instruction_t *getInstruction() const { return m_instruction; }
+			void setTargetDollop(Zipr_SDK::Dollop_t *target) { m_target_dollop = target; }
+			Zipr_SDK::Dollop_t *getTargetDollop() const { return m_target_dollop; }
+			Zipr_SDK::Dollop_t *getMemberOfDollop() const { return m_member_of_dollop; }
+			void MemberOfDollop(Zipr_SDK::Dollop_t *member_of) { m_member_of_dollop = member_of; }
+
+			bool operator==(const DollopEntry_t &);
+			bool operator!=(const DollopEntry_t &);
+		private:
+			Instruction_t *m_instruction;
+			Zipr_SDK::Dollop_t *m_target_dollop, *m_member_of_dollop;
+
+		friend ostream &operator<<(ostream &, const DollopEntry_t &);
+	};
+
+	class Dollop_t : virtual public Zipr_SDK::Dollop_t, public Placeable_t
+	{
+		public:
+			Dollop_t(Instruction_t *start, Zipr_SDK::DollopManager_t *);
+			Dollop_t() :
+				m_size(0),
+				m_fallthrough_dollop(NULL),
+				m_fallback_dollop(NULL),
+				m_fallthrough_patched(false),
+				m_coalesced(false),
+				m_was_truncated(false),
+				m_dollop_mgr(NULL) {}
+
+			void setDollopManager(Zipr_SDK::DollopManager_t *mgr) { m_dollop_mgr = mgr; }
+
+			size_t getSize() const {
+				return m_size;
+			}
+			void setSize(size_t size) {
+				m_size = size;
+			}
+
+			size_t getDollopEntryCount() const {
+				return size();
+			}
+
+			Zipr_SDK::Dollop_t *split(Instruction_t *split_point);
+			void removeDollopEntries(Zipr_SDK::DollopEntryList_t::iterator, Zipr_SDK::DollopEntryList_t::iterator);
+
+			void setFallbackDollop(Zipr_SDK::Dollop_t *fallback) { m_fallback_dollop = fallback; }
+			Zipr_SDK::Dollop_t *getFallbackDollop(void) const { return m_fallback_dollop; }
+
+			void setFallthroughDollop(Zipr_SDK::Dollop_t *fallthrough) { m_fallthrough_dollop = fallthrough; }
+			Zipr_SDK::Dollop_t *getFallthroughDollop(void) const { return m_fallthrough_dollop; }
+
+			bool isFallthroughPatched(void) const { return m_fallthrough_patched; }
+			void setFallthroughPatched(bool patched);
+
+			Zipr_SDK::DollopEntry_t *setFallthroughDollopEntry(Zipr_SDK::DollopEntry_t *) const;
+
+			void wasTruncated(bool truncated) { m_was_truncated = truncated; }
+			bool wasTruncated(void) const { return m_was_truncated; }
+
+			void setCoalesced(bool coalesced);
+			bool wasCoalesced(void) const { return m_coalesced; }
+
+			void reCalculateSize();
+		private:
+			size_t CalculateSize();
+			size_t m_size;
+			Zipr_SDK::Dollop_t *m_fallthrough_dollop, *m_fallback_dollop;
+			bool m_fallthrough_patched;
+			bool m_coalesced;
+			bool m_was_truncated;
+			Zipr_SDK::DollopManager_t *m_dollop_mgr;
+
+		friend ostream &operator<<(ostream &, const Dollop_t &);
+	};
+}
diff --git a/src/dollop.cpp b/src/dollop.cpp
index 2a046e3bd..61a4d7bac 100644
--- a/src/dollop.cpp
+++ b/src/dollop.cpp
@@ -3,7 +3,55 @@
 
 #define ALLOF(a) std::begin((a)),std::end((a))
 
-namespace Zipr_SDK {
+namespace Zipr_SDK
+{
+	bool DollopEntry_t::operator==(const  DollopEntry_t &comp) 
+	{
+		return 
+			make_tuple(     getInstruction(),      getTargetDollop()) == 
+			make_tuple(comp.getInstruction(), comp.getTargetDollop()) ;
+	}
+
+	bool DollopEntry_t::operator!=(const Zipr_SDK::DollopEntry_t &comp) 
+	{
+		return !operator==(comp);
+	}
+	Zipr_SDK::Dollop_t *Dollop_t::createNewDollop(IRDB_SDK::Instruction_t *start, Zipr_SDK::DollopManager_t *mgr) 
+	{
+		return new zipr::Dollop_t(start, mgr);
+	}
+
+	ostream &operator<<(ostream &out, const Zipr_SDK::Dollop_t &d) 
+	{
+
+		//for (it = d.begin(), it_end = d.end(); it != it_end; it++) 
+		for (auto entry : d) 
+		{
+			out << hex << *(entry) << endl;
+		}
+		auto fallback = d.getFallbackDollop();
+		if ( fallback != nullptr)
+			out << "Fallback: " << hex << fallback << endl;
+		auto fallthrough = d.getFallthroughDollop();
+		if ( fallthrough != nullptr)
+			out << "Fallthrough: " << hex << fallthrough << endl;
+		return out;
+	}
+
+	ostream &operator<<(ostream &out, const DollopPatch_t &p) {
+		out << hex << &p << ":" << hex << p.getTarget();
+		return out;
+	}
+
+	ostream &operator<<(ostream &out, const DollopEntry_t &p) {
+		out << "Instruction: " << hex << p.getInstruction() << endl;
+		out << "Target Dollop: " << hex << p.getTargetDollop() << endl;
+		return out;
+	}
+}
+
+namespace zipr 
+{
 	using namespace IRDB_SDK;
 	using namespace zipr;
 	using namespace std;
@@ -68,7 +116,7 @@ namespace Zipr_SDK {
 		assert(l_zipr_impl);
 		return 	total_dollop_entry_size + l_zipr_impl->getSizer()->TRAMPOLINE_SIZE;
 	}
-	DollopEntry_t *Dollop_t::setFallthroughDollopEntry(DollopEntry_t *entry) const
+	Zipr_SDK::DollopEntry_t *Dollop_t::setFallthroughDollopEntry(Zipr_SDK::DollopEntry_t *entry) const
 	{
 		const auto found_entry = find(ALLOF(*this), entry);
 		if (found_entry == end())
@@ -89,19 +137,19 @@ namespace Zipr_SDK {
 		m_size = CalculateSize();
 	}
 
-	Dollop_t *Dollop_t::split(IRDB_SDK::Instruction_t *split_point) {
+	Zipr_SDK::Dollop_t *Dollop_t::split(IRDB_SDK::Instruction_t *split_point) 
+	{
 		/*
 		 * 1. Find the matching dollop entry.
 		 */
 		DollopEntry_t query(split_point, nullptr);
-		std::list<DollopEntry_t *>::iterator de_split_point, de_it;
 		Dollop_t *new_dollop = nullptr;
 
-		de_split_point = find_if(begin(),end(),
-			[&query](const DollopEntry_t *p) {
-//				std::cout << "Checking "
-//				          << std::hex << query.Instruction() << " ?= "
-//									<< std::hex << p->Instruction() << "." << std::endl;
+		auto de_split_point = find_if(begin(),end(),
+			[&query](const Zipr_SDK::DollopEntry_t *p) {
+//				cout << "Checking "
+//				          << hex << query.Instruction() << " ?= "
+//									<< hex << p->Instruction() << "." << endl;
 				return query.getInstruction() == p->getInstruction();
 			});
 		/*
@@ -132,13 +180,13 @@ namespace Zipr_SDK {
 		/*
 		 * 2. Remove them from this one
 		 */
-		de_it = de_split_point;
+		auto de_it = de_split_point;
 		while (de_it != end()) {
 		/*
 		 * 3. Move them to a new one
 		 */
-			DollopEntry_t *to_move = *de_it;
-			std::list<DollopEntry_t*>::iterator moved_it = de_it;
+			auto to_move = *de_it;
+			auto moved_it = de_it;
 
 			de_it++;
 
@@ -156,13 +204,14 @@ namespace Zipr_SDK {
 	}
 
 	void Dollop_t::removeDollopEntries(
-		std::list<DollopEntry_t*>::iterator first_to_remove, 
-		std::list<DollopEntry_t*>::iterator last_to_remove) {
+		Zipr_SDK::DollopEntryList_t::iterator first_to_remove, 
+		Zipr_SDK::DollopEntryList_t::iterator last_to_remove) 
+	{
 		erase(first_to_remove, last_to_remove);
 		m_size = CalculateSize();
 	}
 
-	DollopEntry_t::DollopEntry_t(IRDB_SDK::Instruction_t *insn,Dollop_t *member_of)
+	DollopEntry_t::DollopEntry_t(IRDB_SDK::Instruction_t *insn, Zipr_SDK::Dollop_t *member_of)
 	{
 		/*
 		 * NB: This does not link if the insn has a target.
@@ -172,15 +221,15 @@ namespace Zipr_SDK {
 		m_member_of_dollop = member_of;
 	}
 
-	bool DollopEntry_t::operator==(const DollopEntry_t &comp) {
-		std::cout << "operator==s being invoked "
-		          << "(" << std::hex << m_instruction
-		          << ", " << std::hex << comp.m_instruction
+	bool DollopEntry_t::operator==(const  DollopEntry_t &comp) {
+		cout << "operator==s being invoked "
+		          << "(" << hex << m_instruction
+		          << ", " << hex << comp.m_instruction
 							<< ") "
-		          << "(" << std::hex << m_target_dollop
-		          << ", " << std::hex << comp.m_target_dollop
+		          << "(" << hex << m_target_dollop
+		          << ", " << hex << comp.m_target_dollop
 							<< ") "
-							<< std::endl;
+							<< endl;
 		return comp.m_instruction == m_instruction &&
 		       comp.m_target_dollop == m_target_dollop;
 	}
@@ -189,35 +238,33 @@ namespace Zipr_SDK {
 		return !operator==(comp);
 	}
 
-	Dollop_t *Dollop_t::createNewDollop(IRDB_SDK::Instruction_t *start,
-	                                    Zipr_SDK::DollopManager_t *mgr) {
-		return new Zipr_SDK::Dollop_t(start, mgr);
-	}
 
-	std::ostream &operator<<(std::ostream &out, const Dollop_t &d) {
-		std::list<DollopEntry_t*>::const_iterator it, it_end;
-		Dollop_t *fallthrough = nullptr, *fallback = nullptr;
 
-		for (it = d.begin(), it_end = d.end();
-		     it != it_end;
-				 it++) {
-			out << std::hex << *(*it) << std::endl;
+	ostream &operator<<(ostream &out, const Dollop_t &d) 
+	{
+
+		//for (it = d.begin(), it_end = d.end(); it != it_end; it++) 
+		for (auto entry : d) 
+		{
+			out << hex << *(entry) << endl;
 		}
-		if ((fallback = d.getFallbackDollop()) != nullptr)
-			out << "Fallback: " << std::hex << fallback << std::endl;
-		if ((fallthrough = d.getFallthroughDollop()) != nullptr)
-			out << "Fallthrough: " << std::hex << fallthrough << std::endl;
+		auto fallback = d.getFallbackDollop();
+		if ( fallback != nullptr)
+			out << "Fallback: " << hex << fallback << endl;
+		auto fallthrough = d.getFallthroughDollop();
+		if ( fallthrough != nullptr)
+			out << "Fallthrough: " << hex << fallthrough << endl;
 		return out;
 	}
 
-	std::ostream &operator<<(std::ostream &out, const DollopPatch_t &p) {
-		out << std::hex << &p << ":" << std::hex << p.getTarget();
+	ostream &operator<<(ostream &out, const DollopPatch_t &p) {
+		out << hex << &p << ":" << hex << p.getTarget();
 		return out;
 	}
 
-	std::ostream &operator<<(std::ostream &out, const DollopEntry_t &p) {
-		out << "Instruction: " << std::hex << p.getInstruction() << std::endl;
-		out << "Target Dollop: " << std::hex << p.getTargetDollop() << std::endl;
+	ostream &operator<<(ostream &out, const DollopEntry_t &p) {
+		out << "Instruction: " << hex << p.getInstruction() << endl;
+		out << "Target Dollop: " << hex << p.getTargetDollop() << endl;
 		return out;
 	}
 }
diff --git a/src/pinner_arm64.cpp b/src/pinner_arm64.cpp
index 420aea1e2..3220d9b17 100644
--- a/src/pinner_arm64.cpp
+++ b/src/pinner_arm64.cpp
@@ -35,7 +35,7 @@ void  ZiprPinnerARM64_t::doPinning()
                         // Unpinned IBT. Create dollop and add it to placement
                         // queue straight away--there are no pinning considerations.
                         auto newDoll=m_dollop_mgr.addNewDollops(insn);
-                        placement_queue.insert(pair<Dollop_t*,RangeAddress_t>(newDoll, 0));
+                        placement_queue.insert({newDoll, 0});
                         continue;
                 }
 
diff --git a/src/pinner_x86.cpp b/src/pinner_x86.cpp
index 755794e1e..b7b8c07d8 100644
--- a/src/pinner_x86.cpp
+++ b/src/pinner_x86.cpp
@@ -100,13 +100,8 @@ void ZiprPinnerX86_t::AddPinnedInstructions()
 	 */
 	RecordPinnedInsnAddrs();
 
-	for(
-	    set<Instruction_t*>::const_iterator it=m_firp->getInstructions().begin();
-	    it!=m_firp->getInstructions().end();
-	    ++it
-	   )
+	for(auto insn : m_firp->getInstructions())
 	{
-		Instruction_t* insn=*it;
 		assert(insn);
 
 		if(insn->getIndirectBranchTargetAddress()==nullptr)
@@ -116,8 +111,8 @@ void ZiprPinnerX86_t::AddPinnedInstructions()
                 {
                         // Unpinned IBT. Create dollop and add it to placement
                         // queue straight away--there are no pinning considerations.
-                        Dollop_t *newDoll=m_dollop_mgr.addNewDollops(insn);
-			placement_queue.insert(pair<Dollop_t*,RangeAddress_t>(newDoll, 0));
+                        auto newDoll=m_dollop_mgr.addNewDollops(insn);
+			placement_queue.insert({newDoll, 0});
 			continue;
                 }
 
@@ -128,7 +123,7 @@ void ZiprPinnerX86_t::AddPinnedInstructions()
 			next_pin_addr+=5;// sizeof pin
 		}
 
-		unresolved_pinned_addrs.insert(UnresolvedPinned_t(insn));
+		unresolved_pinned_addrs.insert({insn});
 	}
 }
 
diff --git a/src/plugin_man.cpp b/src/plugin_man.cpp
index 66bb0b752..5d8e3aa43 100644
--- a/src/plugin_man.cpp
+++ b/src/plugin_man.cpp
@@ -117,7 +117,7 @@ RangeAddress_t ZiprPluginManager_t::PlaceScoopsEnd(const RangeAddress_t max_addr
 }
 
 
-bool ZiprPluginManager_t::DoesPluginAddress(const Dollop_t *dollop, const RangeAddress_t &source, Range_t &place, bool &coalesce, bool &fallthrough_allowed, DLFunctionHandle_t &placer)
+bool ZiprPluginManager_t::DoesPluginAddress(const Zipr_SDK::Dollop_t *dollop, const RangeAddress_t &source, Range_t &place, bool &coalesce, bool &fallthrough_allowed, DLFunctionHandle_t &placer)
 {
 	DLFunctionHandleSet_t::iterator it=m_handleList.begin();
 	for(m_handleList.begin();it!=m_handleList.end();++it)
@@ -148,7 +148,7 @@ bool ZiprPluginManager_t::DoPluginsPlop(Instruction_t *insn, std::list<DLFunctio
 	return a_plugin_does_plop;
 }
 
-bool ZiprPluginManager_t::DoesPluginRetargetCallback(const RangeAddress_t &callback_addr, const DollopEntry_t *callback_entry, RangeAddress_t &target_address, DLFunctionHandle_t &patcher)
+bool ZiprPluginManager_t::DoesPluginRetargetCallback(const RangeAddress_t &callback_addr, const Zipr_SDK::DollopEntry_t *callback_entry, RangeAddress_t &target_address, DLFunctionHandle_t &patcher)
 {
 	DLFunctionHandleSet_t::iterator it=m_handleList.begin();
 	for(m_handleList.begin();it!=m_handleList.end();++it)
@@ -163,7 +163,7 @@ bool ZiprPluginManager_t::DoesPluginRetargetCallback(const RangeAddress_t &callb
 	return false;
 }
 
-bool ZiprPluginManager_t::DoesPluginRetargetPin(const RangeAddress_t &patch_addr, const Dollop_t *target_dollop, RangeAddress_t &target_address, DLFunctionHandle_t &patcher) 
+bool ZiprPluginManager_t::DoesPluginRetargetPin(const RangeAddress_t &patch_addr, const Zipr_SDK::Dollop_t *target_dollop, RangeAddress_t &target_address, DLFunctionHandle_t &patcher) 
 {
 	DLFunctionHandleSet_t::iterator it=m_handleList.begin();
 	for(m_handleList.begin();it!=m_handleList.end();++it)
diff --git a/src/sizer_arm64.cpp b/src/sizer_arm64.cpp
index cf407f41f..e439e9cc9 100644
--- a/src/sizer_arm64.cpp
+++ b/src/sizer_arm64.cpp
@@ -30,7 +30,7 @@ size_t ZiprSizerARM64_t::DetermineInsnSize(Instruction_t* insn, bool account_for
 }
 
 RangeAddress_t ZiprSizerARM64_t::PlopDollopEntryWithTarget(
-        DollopEntry_t *entry,
+        Zipr_SDK::DollopEntry_t *entry,
         RangeAddress_t override_place,
         RangeAddress_t override_target) const
 {
@@ -41,7 +41,7 @@ RangeAddress_t ZiprSizerARM64_t::PlopDollopEntryWithTarget(
 }
 
 RangeAddress_t ZiprSizerARM64_t::TBZPlopDollopEntryWithTarget(
-        DollopEntry_t *entry,
+        Zipr_SDK::DollopEntry_t *entry,
         RangeAddress_t override_place,
         RangeAddress_t override_target) const
 {
@@ -75,7 +75,7 @@ RangeAddress_t ZiprSizerARM64_t::TBZPlopDollopEntryWithTarget(
 
 
 RangeAddress_t ZiprSizerARM64_t::DefaultPlopDollopEntryWithTarget(
-        DollopEntry_t *entry,
+        Zipr_SDK::DollopEntry_t *entry,
         RangeAddress_t override_place,
         RangeAddress_t override_target) const
 {
diff --git a/src/sizer_base.cpp b/src/sizer_base.cpp
index dc682b292..1d5847c4c 100644
--- a/src/sizer_base.cpp
+++ b/src/sizer_base.cpp
@@ -51,13 +51,11 @@ Range_t ZiprSizerBase_t::DoPlacement(const size_t size) const
 }
 
 
-size_t ZiprSizerBase_t::DetermineDollopSizeInclFallthrough(Dollop_t *dollop) const
+size_t ZiprSizerBase_t::DetermineDollopSizeInclFallthrough(Zipr_SDK::Dollop_t *dollop) const
 {
-        size_t fallthroughs_wcds = 0;
-        Dollop_t *fallthrough_it = nullptr;
-        for (fallthrough_it = dollop;
-             fallthrough_it != nullptr;
-                         fallthrough_it = fallthrough_it->getFallthroughDollop())
+        auto fallthroughs_wcds = 0;
+	auto fallthrough_it = dollop;
+        for ( /* empty */ ; fallthrough_it != nullptr; fallthrough_it = fallthrough_it->getFallthroughDollop())
         {
                 if (fallthrough_it->isPlaced())
                         /*
diff --git a/src/sizer_x86.cpp b/src/sizer_x86.cpp
index e9ea19815..ae3302137 100644
--- a/src/sizer_x86.cpp
+++ b/src/sizer_x86.cpp
@@ -81,7 +81,7 @@ size_t ZiprSizerX86_t::DetermineInsnSize(Instruction_t* insn, bool account_for_j
 }
 
 RangeAddress_t ZiprSizerX86_t::PlopDollopEntryWithTarget(
-        DollopEntry_t *entry,
+        Zipr_SDK::DollopEntry_t *entry,
         RangeAddress_t override_place,
         RangeAddress_t override_target) const
 {
@@ -160,9 +160,7 @@ RangeAddress_t ZiprSizerX86_t::PlopDollopEntryWithTarget(
                         // jmp fallthrough
                         // +5: jmp target
                         char bytes[]={0,0x5};
-                        DollopEntry_t *fallthrough_de = nullptr;
-
-                        fallthrough_de = entry->getMemberOfDollop()->setFallthroughDollopEntry(entry);
+                        auto fallthrough_de = entry->getMemberOfDollop()->setFallthroughDollopEntry(entry);
 
                         /*
                          * This means that we have a fallthrough for this dollop entry
diff --git a/src/zipr.cpp b/src/zipr.cpp
index dbcb816a7..856f6224a 100644
--- a/src/zipr.cpp
+++ b/src/zipr.cpp
@@ -861,7 +861,7 @@ void ZiprImpl_t::PlaceDollops()
 		auto target_dollop = m_dollop_mgr.getContainingDollop(target_insn);
 		assert(target_dollop);
 
-		placement_queue.insert(pair<Dollop_t*,RangeAddress_t>(target_dollop,patch.getAddress()));
+		placement_queue.insert({target_dollop,patch.getAddress()});
 		if (m_verbose) 
 		{
 			cout << "Original: " << hex << target_insn-> getAddress()-> getVirtualOffset() << " "
@@ -888,7 +888,7 @@ void ZiprImpl_t::PlaceDollops()
                         assert(containing!=nullptr);
                         if(!containing->isPlaced())
                         {
-                        	placement_queue.insert(pair<Dollop_t*, RangeAddress_t>( containing, wrt_insn->getAddress()->getVirtualOffset()));
+                        	placement_queue.insert({containing, wrt_insn->getAddress()->getVirtualOffset()});
                         }
                 }
         };
@@ -905,7 +905,7 @@ void ZiprImpl_t::PlaceDollops()
 		auto placed = false;
 		auto cur_addr = RangeAddress_t(0);
 		auto has_fallthrough = false;
-		auto fallthrough = (Dollop_t*)(nullptr);
+		auto fallthrough = (Zipr_SDK::Dollop_t*)(nullptr);
 		auto continue_placing = false;
 		auto initial_placement_abuts_pin = false;
 		auto initial_placement_abuts_fallthrough = false;
@@ -1190,7 +1190,7 @@ void ZiprImpl_t::PlaceDollops()
 			auto dit_end = to_place->end();
 			for ( /* empty */; dit != dit_end; dit++)
 			{
-				DollopEntry_t *dollop_entry = *dit;	
+				auto dollop_entry = *dit;	
 								
 				/*
 				 * There are several ways that a dollop could end:
@@ -1299,9 +1299,7 @@ void ZiprImpl_t::PlaceDollops()
 						if (m_vverbose)
 							cout << "Adding " << std::hex << dollop_entry->getTargetDollop()
 							     << " to placement queue." << endl;
-						placement_queue.insert(pair<Dollop_t*, RangeAddress_t>(
-								dollop_entry->getTargetDollop(),
-								cur_addr));
+						placement_queue.insert({dollop_entry->getTargetDollop(), cur_addr});
 					}
 				}
 				else
@@ -1397,7 +1395,7 @@ void ZiprImpl_t::PlaceDollops()
 					 */
 					if (!to_place->getFallthroughDollop()->isPlaced())
 					{
-						placement_queue.insert(pair<Dollop_t*, RangeAddress_t>( to_place->getFallthroughDollop(), cur_addr));
+						placement_queue.insert({to_place->getFallthroughDollop(), cur_addr});
 					}
 					m_stats->total_did_not_coalesce++;
 					break;
@@ -1435,8 +1433,8 @@ void ZiprImpl_t::PlaceDollops()
 				{
 
 					string patch_jump_string;
-					Instruction_t *patch = archhelper->createNewJumpInstruction(m_firp, nullptr);
-					DollopEntry_t *patch_de = new DollopEntry_t(patch, to_place);
+					auto patch = archhelper->createNewJumpInstruction(m_firp, nullptr);
+					auto patch_de = new DollopEntry_t(patch, to_place);
 
 					patch_de->setTargetDollop(fallthrough);
 					patch_de->Place(cur_addr);
@@ -1455,7 +1453,7 @@ void ZiprImpl_t::PlaceDollops()
 						     << "to fallthrough dollop (" << std::hex 
 						     << fallthrough << ")." << endl;
 
-					placement_queue.insert(pair<Dollop_t*, RangeAddress_t>( fallthrough, cur_addr));
+					placement_queue.insert({fallthrough, cur_addr});
 					/*
 					 * Since we inserted a new instruction, we should
 					 * check to see whether a plugin wants to plop it.
@@ -1540,7 +1538,7 @@ void ZiprImpl_t::PatchCall(RangeAddress_t at_addr, RangeAddress_t to_addr)
 	patcher->PatchCall(at_addr,to_addr);
 }
 
-size_t ZiprImpl_t::DetermineDollopEntrySize(DollopEntry_t *entry, bool account_for_fallthrough)
+size_t ZiprImpl_t::DetermineDollopEntrySize(Zipr_SDK::DollopEntry_t *entry, bool account_for_fallthrough)
 {
 	std::map<Instruction_t*,unique_ptr<list<DLFunctionHandle_t>>>::const_iterator plop_it;
 	size_t opening_size = 0, closing_size = 0;
@@ -1652,8 +1650,8 @@ void ZiprImpl_t::UpdatePins()
 	{
 		UnresolvedUnpinned_t uu=(*patch_list.begin()).first;
 		Patch_t p=(*patch_list.begin()).second;
-		Dollop_t *target_dollop = nullptr;
-		DollopEntry_t *target_dollop_entry = nullptr;
+		Zipr_SDK::Dollop_t *target_dollop = nullptr;
+		Zipr_SDK::DollopEntry_t *target_dollop_entry = nullptr;
 		Instruction_t *target_dollop_entry_instruction = nullptr;
 		RangeAddress_t patch_addr, target_addr;
 		target_dollop = m_dollop_mgr.getContainingDollop(uu.getInstrution());
@@ -1745,7 +1743,7 @@ void ZiprImpl_t::PatchInstruction(RangeAddress_t from_addr, Instruction_t* to_in
 	}
 }
 
-RangeAddress_t ZiprImpl_t::_PlopDollopEntry(DollopEntry_t *entry, RangeAddress_t override_address)
+RangeAddress_t ZiprImpl_t::_PlopDollopEntry(Zipr_SDK::DollopEntry_t *entry, RangeAddress_t override_address)
 {
 	const auto insn = entry->getInstruction();
 	const auto insn_wcis = DetermineInsnSize(insn, false);
@@ -1824,7 +1822,7 @@ RangeAddress_t ZiprImpl_t::_PlopDollopEntry(DollopEntry_t *entry, RangeAddress_t
 }
 
 RangeAddress_t ZiprImpl_t::PlopDollopEntry(
-	DollopEntry_t *entry,
+	Zipr_SDK::DollopEntry_t *entry,
 	RangeAddress_t override_place,
 	RangeAddress_t override_target)
 {
@@ -1893,7 +1891,7 @@ RangeAddress_t ZiprImpl_t::PlopDollopEntry(
 }
 
 RangeAddress_t ZiprImpl_t::PlopDollopEntryWithTarget(
-	DollopEntry_t *entry,
+	Zipr_SDK::DollopEntry_t *entry,
 	RangeAddress_t override_place,
 	RangeAddress_t override_target)
 {
@@ -1901,7 +1899,7 @@ RangeAddress_t ZiprImpl_t::PlopDollopEntryWithTarget(
 }
 
 RangeAddress_t ZiprImpl_t::PlopDollopEntryWithCallback(
-	DollopEntry_t *entry,
+	Zipr_SDK::DollopEntry_t *entry,
 	RangeAddress_t override_place)
 {
 	auto at = entry->getPlace();
@@ -1914,7 +1912,7 @@ RangeAddress_t ZiprImpl_t::PlopDollopEntryWithCallback(
 	{
 	char bytes[]={(char)0xe8,(char)0,(char)0,(char)0,(char)0}; // call rel32
 	memory_space.PlopBytes(at, bytes, sizeof(bytes));
-	unpatched_callbacks.insert(pair<DollopEntry_t*,RangeAddress_t>(entry,at));
+	unpatched_callbacks.insert({entry,at});
 	at+=sizeof(bytes);
 	}
 
@@ -2424,19 +2422,15 @@ RangeAddress_t ZiprImpl_t::FindCallbackAddress(RangeAddress_t end_of_new_space,
 void ZiprImpl_t::UpdateCallbacks()
 {
 	// first byte of this range is the last used byte.
-	RangeSet_t::iterator range_it=memory_space.FindFreeRange((RangeAddress_t) -1);
+	const auto range_it=memory_space.FindFreeRange((RangeAddress_t) -1);
 	assert(memory_space.IsValidRange(range_it));
 
-	set<std::pair<DollopEntry_t*,RangeAddress_t> >::iterator it, it_end;
 
-	for(it=unpatched_callbacks.begin(), it_end=unpatched_callbacks.end();
-	    it!=it_end;
-	    it++
-	   )
+	for(const auto &p : unpatched_callbacks)
 	{
-		DollopEntry_t *entry=it->first;
+		auto entry=p.first;
 		Instruction_t *insn = entry->getInstruction();
-		RangeAddress_t at=it->second;
+		RangeAddress_t at=p.second;
 		RangeAddress_t to=0x0;//FindCallbackAddress(end_of_new_space,start_addr,insn->getCallback());
 		DLFunctionHandle_t patcher = nullptr;
 
diff --git a/src/zipr_dollop_man.cpp b/src/zipr_dollop_man.cpp
index 9a512e5c8..016086c44 100644
--- a/src/zipr_dollop_man.cpp
+++ b/src/zipr_dollop_man.cpp
@@ -7,11 +7,13 @@ using namespace std;
 using namespace Zipr_SDK;
 using namespace IRDB_SDK;
 
+#define ALLOF(a) std::begin(a),std::end(a)
+
 namespace zipr {
 
-	Dollop_t *ZiprDollopManager_t::AddNewDollops(Instruction_t *start) {
-		Dollop_t *new_dollop = nullptr;
-		Dollop_t *existing_dollop = getContainingDollop(start);
+	Zipr_SDK::Dollop_t *ZiprDollopManager_t::AddNewDollops(Instruction_t *start) {
+		Zipr_SDK::Dollop_t *new_dollop = nullptr;
+		auto existing_dollop = getContainingDollop(start);
 
 		/*
 		 * This is the target dollop *only*
@@ -37,12 +39,13 @@ namespace zipr {
 				return new_dollop;
 			}
 		}
-		else {
+		else 
+		{
 			/*
 			 * There is no target dollop. Let's create one!
 			 */
-			std::list<DollopEntry_t*>::iterator it, it_end;
-			Dollop_t *original_new_dollop = nullptr, *previous_dollop = nullptr;
+			DollopEntryList_t::iterator it, it_end;
+			Zipr_SDK::Dollop_t *original_new_dollop = nullptr, *previous_dollop = nullptr;
 			Instruction_t *fallthrough = nullptr;
 			original_new_dollop = new_dollop = Dollop_t::createNewDollop(start,this);
 
@@ -50,10 +53,9 @@ namespace zipr {
 			     it != it_end;
 					 it++)
 			{
-				Dollop_t *containing_dollop = getContainingDollop((*it)->getInstruction());
+				auto containing_dollop = getContainingDollop((*it)->getInstruction());
 				if (containing_dollop) 
 				{
-					Dollop_t *fallthrough_dollop = nullptr;
 					if (true)
 						cout << "Found an instruction in a new dollop that "
 						     << "is already in a dollop: " << std::hex
@@ -63,7 +65,7 @@ namespace zipr {
 					/*
 					 * Reliably get a pointer to the containing dollop.
 					 */
-					fallthrough_dollop = addNewDollops((*it)->getInstruction());
+					auto fallthrough_dollop = addNewDollops((*it)->getInstruction());
 					
 					/*
 					 * Link this dollop to that one. Do this before
@@ -109,7 +111,7 @@ namespace zipr {
 				 * means that it is the first instruction
 				 * in the containing dollop.
 				 */
-				Dollop_t *existing_dollop = getContainingDollop(fallthrough);
+				auto existing_dollop = getContainingDollop(fallthrough);
 				if (existing_dollop)
 				{
 					assert(existing_dollop->front()->getInstruction() == fallthrough);
@@ -137,7 +139,7 @@ namespace zipr {
 		}
 	}
 
-	size_t ZiprDollopManager_t::DetermineDollopEntrySize(DollopEntry_t *entry) 
+	size_t ZiprDollopManager_t::DetermineDollopEntrySize(Zipr_SDK::DollopEntry_t *entry) 
 	{
 		const auto l_zipr=dynamic_cast<ZiprImpl_t*>(m_zipr);
 		const auto sizer=l_zipr->getSizer();
@@ -148,16 +150,16 @@ namespace zipr {
 	}
 
 	void ZiprDollopManager_t::PrintDollopPatches(const ostream &out) {
-		std::list<DollopPatch_t*>::const_iterator patch_it, patch_it_end;
+		// std::list<DollopPatch_t*>::const_iterator patch_it, patch_it_end;
 
-		for (patch_it = m_patches.begin(), patch_it_end = m_patches.end();
+		for (auto patch_it = m_patches.begin(), patch_it_end = m_patches.end();
 		     patch_it != patch_it_end;
 				 patch_it++) {
 			cout << *(*patch_it) << endl;
 		}
 	}
 
-	Dollop_t *ZiprDollopManager_t::getContainingDollop(IRDB_SDK::Instruction_t *insn) {
+	Zipr_SDK::Dollop_t *ZiprDollopManager_t::getContainingDollop(IRDB_SDK::Instruction_t *insn) {
 		InsnToDollopMap_t::iterator it=m_insn_to_dollop.find(insn);
 		if(it!=m_insn_to_dollop.end())
 			return it->second;
@@ -165,8 +167,8 @@ namespace zipr {
 			
 	}
 
-	void ZiprDollopManager_t::AddDollops(Dollop_t *dollop_head) {
-		Dollop_t *dollop = dollop_head;
+	void ZiprDollopManager_t::AddDollops(Zipr_SDK::Dollop_t *dollop_head) {
+		auto dollop = dollop_head;
 		while (dollop != nullptr)
 		{
 			addDollop(dollop);
@@ -182,7 +184,7 @@ namespace zipr {
 	 * sure to test whether or not the instruction-to-dollop map
 	 * is properly updated in all cases.
 	 */
-	void ZiprDollopManager_t::addDollop(Dollop_t *dollop) {
+	void ZiprDollopManager_t::addDollop(Zipr_SDK::Dollop_t *dollop) {
 		/*
 		 * We always want to update the isntruction-to-dollop map.
 		 * However, we might not always want to push it on to the
@@ -191,8 +193,8 @@ namespace zipr {
 		/*
 		 * Populate/update the instruction-to-dollop map.
 		 */
-		std::list<DollopEntry_t*>::iterator it, it_end;
-		for (it = dollop->begin(), it_end = dollop->end();
+		// std::list<DollopEntry_t*>::iterator it, it_end;
+		for (auto it = dollop->begin(), it_end = dollop->end();
 		     it != it_end;
 				 it++) {
 			m_insn_to_dollop[(*it)->getInstruction()] = dollop;
@@ -205,9 +207,9 @@ namespace zipr {
 		m_refresh_stats = true;
 	}
 
-	bool ZiprDollopManager_t::UpdateTargets(Dollop_t *dollop) {
+	bool ZiprDollopManager_t::UpdateTargets(Zipr_SDK::Dollop_t *dollop) {
 		auto changed = false;
-		const auto local_dollop=list<DollopEntry_t*>(dollop->begin(), dollop->end());
+		const auto local_dollop=DollopEntryList_t(ALLOF(*dollop));
 		for (auto &entry : local_dollop )
 		{
 			auto insn=entry->getInstruction();
@@ -281,7 +283,7 @@ namespace zipr {
 		for (it = dollop_man.m_dollops.begin(), it_end = dollop_man.m_dollops.end();
 		     it != it_end;
 				 it++) {
-			Dollop_t *entry = *it;
+			auto entry = *it;
 			out << std::hex << entry << std::endl;
 			out << *entry << std::endl;
 		}
@@ -294,12 +296,8 @@ namespace zipr {
 		m_total_dollop_entries = 0;
 		m_total_dollops = Size();
 
-		DollopList_t::iterator dollop_it, dollop_it_end;
-		for (dollop_it = m_dollops.begin(), dollop_it_end = m_dollops.end();
-		     dollop_it != m_dollops.end();
-				 dollop_it++)
+		for (auto dollop : m_dollops ) 
 		{
-			Dollop_t *dollop = *dollop_it;
 			m_total_dollop_entries += dollop->getDollopEntryCount();
 			if (dollop->wasTruncated())
 				m_truncated_dollops++;
@@ -330,17 +328,16 @@ namespace zipr {
 		const MemorySpace_t &_memory_space,
 		const std::string &map_filename)
 	{
-		const ZiprMemorySpace_t &memory_space = static_cast<const ZiprMemorySpace_t &>(_memory_space);
-		RangeSet_t original_ranges = memory_space.getOriginalFreeRanges();
-		RangeSet_t::const_iterator range_it, range_it_end;
-		ofstream map_output(map_filename.c_str(), std::ofstream::out);
+		const auto &memory_space = static_cast<const ZiprMemorySpace_t &>(_memory_space);
+		auto original_ranges = memory_space.getOriginalFreeRanges();
 
+		ofstream map_output(map_filename.c_str(), std::ofstream::out);
 		if (!map_output.is_open())
 			return;
 		/*
 		 * Loop through the original ranges.
 		 */
-		for (range_it=original_ranges.begin(), range_it_end=original_ranges.end();
+		for (auto range_it=original_ranges.begin(), range_it_end=original_ranges.end();
 		     range_it != range_it_end;
 				 range_it++)
 		{
@@ -348,19 +345,16 @@ namespace zipr {
 			 * Now loop through the dollops and
 			 * record those contained in this range.
 			 */
-			DollopList_t::iterator dollop_it, dollop_it_end;
-			Range_t current_range = *range_it;
-			map<RangeAddress_t, Dollop_t*> dollops_in_range;
-			map<RangeAddress_t, Dollop_t*>::const_iterator dollops_in_range_it,
-			                                               dollops_in_range_end;
+			auto current_range = *range_it;
+			map<RangeAddress_t, Zipr_SDK::Dollop_t*> dollops_in_range;
 			RangeAddress_t previous_dollop_end = 0;
-			Dollop_t *dollop_to_print = nullptr;
+			Zipr_SDK::Dollop_t *dollop_to_print = nullptr;
 
-			for (dollop_it = m_dollops.begin(), dollop_it_end = m_dollops.end();
+			for (auto dollop_it = m_dollops.begin(), dollop_it_end = m_dollops.end();
 			     dollop_it != dollop_it_end;
 					 dollop_it++)
 			{
-				Dollop_t *dollop = (*dollop_it);
+				auto dollop = (*dollop_it);
 				if (current_range.getStart() <= dollop->getPlace() &&
 				    current_range.getEnd() >= dollop->getPlace())
 					dollops_in_range[dollop->getPlace()] = dollop;
@@ -373,7 +367,7 @@ namespace zipr {
 			
 			previous_dollop_end = current_range.getStart();
 			unsigned byte_print_counter = 0;
-			for (dollops_in_range_it = dollops_in_range.begin(),
+			for (auto dollops_in_range_it = dollops_in_range.begin(),
 			     dollops_in_range_end = dollops_in_range.end();
 			     dollops_in_range_it != dollops_in_range_end;
 					 dollops_in_range_it++)
-- 
GitLab