From e5679ece867e51bf63a3d14f4e60da9bcd1c259f Mon Sep 17 00:00:00 2001
From: jdh8d <jdh8d@git.zephyr-software.com>
Date: Sat, 7 Feb 2015 00:44:26 +0000
Subject: [PATCH] refactored into SDK, plugin, callback modules.

---
 .gitattributes                               |   9 +-
 configure                                    | 287 +++++++++--------
 configure.in                                 |   6 +-
 include/nonce_relocs.h                       |  85 -----
 include/plugin_man.h                         |  53 ++++
 include/range.h                              |  60 ----
 include/zipr.h                               |  17 +-
 include/zipr_all.h                           |  11 +-
 include/{memory_space.h => zipr_mem_space.h} |  17 +-
 include/{zipr_options.h => zipr_opts.h}      |   6 +-
 include/zipr_stats.h                         |   2 +-
 src/Makefile.in                              |   6 +-
 src/main.cpp                                 |   4 +-
 src/memory_space.cpp                         |  30 +-
 src/nonce_relocs.cpp                         | 317 -------------------
 src/plugin_man.cpp                           | 152 +++++++++
 src/zipr.cpp                                 |  21 +-
 src/zipr_options.cpp                         |   8 +-
 src/zipr_stats.cpp                           |   2 +-
 19 files changed, 437 insertions(+), 656 deletions(-)
 delete mode 100644 include/nonce_relocs.h
 create mode 100644 include/plugin_man.h
 delete mode 100644 include/range.h
 rename include/{memory_space.h => zipr_mem_space.h} (91%)
 rename include/{zipr_options.h => zipr_opts.h} (94%)
 delete mode 100644 src/nonce_relocs.cpp
 create mode 100644 src/plugin_man.cpp

diff --git a/.gitattributes b/.gitattributes
index 129404700..dcb265841 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -3,19 +3,18 @@
 /Makefile.in -text
 /configure -text
 /configure.in -text
-include/memory_space.h -text
-include/nonce_relocs.h -text
-include/range.h -text
+include/plugin_man.h -text
 include/unresolved.h -text
 include/zipr.h -text
 include/zipr_all.h -text
+include/zipr_mem_space.h -text
 include/zipr_optimizations.h -text
-include/zipr_options.h -text
+include/zipr_opts.h -text
 include/zipr_stats.h -text
 src/Makefile.in -text
 src/main.cpp -text
 src/memory_space.cpp -text
-src/nonce_relocs.cpp -text
+src/plugin_man.cpp -text
 src/zipr.cpp -text
 src/zipr_options.cpp -text
 src/zipr_stats.cpp -text
diff --git a/configure b/configure
index 57f6a1ac9..1da6c3c47 100755
--- a/configure
+++ b/configure
@@ -1,9 +1,11 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for myconfig version-0.1.
+# Generated by GNU Autoconf 2.68 for myconfig version-0.1.
 #
 #
-# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
+# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
+# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
+# Foundation, Inc.
 #
 #
 # This configure script is free software; the Free Software Foundation
@@ -132,31 +134,6 @@ export LANGUAGE
 # CDPATH.
 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
 
-# Use a proper internal environment variable to ensure we don't fall
-  # into an infinite loop, continuously re-executing ourselves.
-  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
-    _as_can_reexec=no; export _as_can_reexec;
-    # We cannot yet assume a decent shell, so we have to provide a
-# neutralization value for shells without unset; and this also
-# works around shells that cannot unset nonexistent variables.
-# Preserve -v and -x to the replacement shell.
-BASH_ENV=/dev/null
-ENV=/dev/null
-(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
-case $- in # ((((
-  *v*x* | *x*v* ) as_opts=-vx ;;
-  *v* ) as_opts=-v ;;
-  *x* ) as_opts=-x ;;
-  * ) as_opts= ;;
-esac
-exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
-# Admittedly, this is quite paranoid, since all the known shells bail
-# out after a failed `exec'.
-$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
-as_fn_exit 255
-  fi
-  # We don't want this to propagate to other subprocesses.
-          { _as_can_reexec=; unset _as_can_reexec;}
 if test "x$CONFIG_SHELL" = x; then
   as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
   emulate sh
@@ -190,8 +167,7 @@ if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
 else
   exitcode=1; echo positional parameters were not saved.
 fi
-test x\$exitcode = x0 || exit 1
-test -x / || exit 1"
+test x\$exitcode = x0 || exit 1"
   as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
   as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
   eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
@@ -235,25 +211,21 @@ IFS=$as_save_IFS
 
 
       if test "x$CONFIG_SHELL" != x; then :
-  export CONFIG_SHELL
-             # We cannot yet assume a decent shell, so we have to provide a
-# neutralization value for shells without unset; and this also
-# works around shells that cannot unset nonexistent variables.
-# Preserve -v and -x to the replacement shell.
-BASH_ENV=/dev/null
-ENV=/dev/null
-(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
-case $- in # ((((
-  *v*x* | *x*v* ) as_opts=-vx ;;
-  *v* ) as_opts=-v ;;
-  *x* ) as_opts=-x ;;
-  * ) as_opts= ;;
-esac
-exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
-# Admittedly, this is quite paranoid, since all the known shells bail
-# out after a failed `exec'.
-$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
-exit 255
+  # We cannot yet assume a decent shell, so we have to provide a
+	# neutralization value for shells without unset; and this also
+	# works around shells that cannot unset nonexistent variables.
+	# Preserve -v and -x to the replacement shell.
+	BASH_ENV=/dev/null
+	ENV=/dev/null
+	(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+	export CONFIG_SHELL
+	case $- in # ((((
+	  *v*x* | *x*v* ) as_opts=-vx ;;
+	  *v* ) as_opts=-v ;;
+	  *x* ) as_opts=-x ;;
+	  * ) as_opts= ;;
+	esac
+	exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"}
 fi
 
     if test x$as_have_required = xno; then :
@@ -355,14 +327,6 @@ $as_echo X"$as_dir" |
 
 
 } # as_fn_mkdir_p
-
-# as_fn_executable_p FILE
-# -----------------------
-# Test if FILE is an executable regular file.
-as_fn_executable_p ()
-{
-  test -f "$1" && test -x "$1"
-} # as_fn_executable_p
 # as_fn_append VAR VALUE
 # ----------------------
 # Append the text in VALUE to the end of the definition contained in VAR. Take
@@ -484,10 +448,6 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits
   chmod +x "$as_me.lineno" ||
     { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
 
-  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
-  # already done that, so ensure we don't try to do so again and fall
-  # in an infinite loop.  This has already happened in practice.
-  _as_can_reexec=no; export _as_can_reexec
   # Don't try to exec as it changes $[0], causing all sort of problems
   # (the dirname of $[0] is not the place where we might find the
   # original and so on.  Autoconf is especially sensitive to this).
@@ -522,16 +482,16 @@ if (echo >conf$$.file) 2>/dev/null; then
     # ... but there are two gotchas:
     # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
     # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -pR'.
+    # In both cases, we have to default to `cp -p'.
     ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -pR'
+      as_ln_s='cp -p'
   elif ln conf$$.file conf$$ 2>/dev/null; then
     as_ln_s=ln
   else
-    as_ln_s='cp -pR'
+    as_ln_s='cp -p'
   fi
 else
-  as_ln_s='cp -pR'
+  as_ln_s='cp -p'
 fi
 rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
 rmdir conf$$.dir 2>/dev/null
@@ -543,8 +503,28 @@ else
   as_mkdir_p=false
 fi
 
-as_test_x='test -x'
-as_executable_p=as_fn_executable_p
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+	test -d "$1/.";
+      else
+	case $1 in #(
+	-*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
 
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -590,6 +570,8 @@ ARCH
 ASFLAGS
 AS
 LD
+CXXFLAGS
+CXX
 DIRS
 LTLIBOBJS
 LIBOBJS
@@ -1107,6 +1089,8 @@ target=$target_alias
 if test "x$host_alias" != x; then
   if test "x$build_alias" = x; then
     cross_compiling=maybe
+    $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host.
+    If a cross compiler is detected then cross compile mode will be used" >&2
   elif test "x$build_alias" != "x$host_alias"; then
     cross_compiling=yes
   fi
@@ -1340,9 +1324,9 @@ test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
 myconfig configure version-0.1
-generated by GNU Autoconf 2.69
+generated by GNU Autoconf 2.68
 
-Copyright (C) 2012 Free Software Foundation, Inc.
+Copyright (C) 2010 Free Software Foundation, Inc.
 This configure script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it.
 _ACEOF
@@ -1395,7 +1379,7 @@ This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
 It was created by myconfig $as_me version-0.1, which was
-generated by GNU Autoconf 2.69.  Invocation command line was
+generated by GNU Autoconf 2.68.  Invocation command line was
 
   $ $0 $@
 
@@ -1767,7 +1751,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_CC="${ac_tool_prefix}gcc"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -1807,7 +1791,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_ac_ct_CC="gcc"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -1860,7 +1844,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_CC="${ac_tool_prefix}cc"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -1901,7 +1885,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
        ac_prog_rejected=yes
        continue
@@ -1959,7 +1943,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -2003,7 +1987,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_ac_ct_CC="$ac_prog"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -2449,7 +2433,8 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <stdarg.h>
 #include <stdio.h>
-struct stat;
+#include <sys/types.h>
+#include <sys/stat.h>
 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
 struct buf { int x; };
 FILE * (*rcsopen) (struct buf *, struct stat *, int);
@@ -2556,7 +2541,9 @@ fi
 LIB=$ZIPR_HOME/callbacks/lib/callbacks.a
 AR=ar
 CC=gcc
-CFLAGS="$OPTIMIZE -fPIE -fPIC -I$ZIPR_HOME/include "
+CXX=g++
+CFLAGS="$OPTIMIZE -fPIE -fPIC -I$ZIPR_HOME/include -I$ZIPR_HOME/third_party/ELFIO/elfio-2.2/ -I$ZIPR_SDK/include -I$SECURITY_TRANSFORMS_HOME/libIRDB/include -I$SECURITY_TRANSFORMS_HOME/beaengine/include -I$SECURITY_TRANSFORMS_HOME/include -I$SECURITY_TRANSFORMS_HOME/tools/transforms"
+CXXFLAGS="$CFLAGS"
 LD=gcc
 LDFLAGS=""
 AS=nasm
@@ -3014,16 +3001,16 @@ if (echo >conf$$.file) 2>/dev/null; then
     # ... but there are two gotchas:
     # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
     # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -pR'.
+    # In both cases, we have to default to `cp -p'.
     ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -pR'
+      as_ln_s='cp -p'
   elif ln conf$$.file conf$$ 2>/dev/null; then
     as_ln_s=ln
   else
-    as_ln_s='cp -pR'
+    as_ln_s='cp -p'
   fi
 else
-  as_ln_s='cp -pR'
+  as_ln_s='cp -p'
 fi
 rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
 rmdir conf$$.dir 2>/dev/null
@@ -3083,16 +3070,28 @@ else
   as_mkdir_p=false
 fi
 
-
-# as_fn_executable_p FILE
-# -----------------------
-# Test if FILE is an executable regular file.
-as_fn_executable_p ()
-{
-  test -f "$1" && test -x "$1"
-} # as_fn_executable_p
-as_test_x='test -x'
-as_executable_p=as_fn_executable_p
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+	test -d "$1/.";
+      else
+	case $1 in #(
+	-*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
 
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -3114,7 +3113,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # values after options handling.
 ac_log="
 This file was extended by myconfig $as_me version-0.1, which was
-generated by GNU Autoconf 2.69.  Invocation command line was
+generated by GNU Autoconf 2.68.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
@@ -3167,10 +3166,10 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
 myconfig config.status version-0.1
-configured by $0, generated by GNU Autoconf 2.69,
+configured by $0, generated by GNU Autoconf 2.68,
   with options \\"\$ac_cs_config\\"
 
-Copyright (C) 2012 Free Software Foundation, Inc.
+Copyright (C) 2010 Free Software Foundation, Inc.
 This config.status script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it."
 
@@ -3247,7 +3246,7 @@ fi
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 if \$ac_cs_recheck; then
-  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
   shift
   \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
   CONFIG_SHELL='$SHELL'
@@ -4171,16 +4170,16 @@ if (echo >conf$$.file) 2>/dev/null; then
     # ... but there are two gotchas:
     # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
     # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -pR'.
+    # In both cases, we have to default to `cp -p'.
     ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -pR'
+      as_ln_s='cp -p'
   elif ln conf$$.file conf$$ 2>/dev/null; then
     as_ln_s=ln
   else
-    as_ln_s='cp -pR'
+    as_ln_s='cp -p'
   fi
 else
-  as_ln_s='cp -pR'
+  as_ln_s='cp -p'
 fi
 rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
 rmdir conf$$.dir 2>/dev/null
@@ -4240,16 +4239,28 @@ else
   as_mkdir_p=false
 fi
 
-
-# as_fn_executable_p FILE
-# -----------------------
-# Test if FILE is an executable regular file.
-as_fn_executable_p ()
-{
-  test -f "$1" && test -x "$1"
-} # as_fn_executable_p
-as_test_x='test -x'
-as_executable_p=as_fn_executable_p
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+	test -d "$1/.";
+      else
+	case $1 in #(
+	-*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
 
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -4271,7 +4282,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # values after options handling.
 ac_log="
 This file was extended by myconfig $as_me version-0.1, which was
-generated by GNU Autoconf 2.69.  Invocation command line was
+generated by GNU Autoconf 2.68.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
@@ -4324,10 +4335,10 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
 myconfig config.status version-0.1
-configured by $0, generated by GNU Autoconf 2.69,
+configured by $0, generated by GNU Autoconf 2.68,
   with options \\"\$ac_cs_config\\"
 
-Copyright (C) 2012 Free Software Foundation, Inc.
+Copyright (C) 2010 Free Software Foundation, Inc.
 This config.status script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it."
 
@@ -4404,7 +4415,7 @@ fi
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 if \$ac_cs_recheck; then
-  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
   shift
   \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
   CONFIG_SHELL='$SHELL'
@@ -4896,6 +4907,8 @@ fi
 
 
 
+
+
 OPTIMIZE=$OPTIMIZE
 
 echo prefix=$prefix
@@ -5345,16 +5358,16 @@ if (echo >conf$$.file) 2>/dev/null; then
     # ... but there are two gotchas:
     # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
     # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -pR'.
+    # In both cases, we have to default to `cp -p'.
     ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -pR'
+      as_ln_s='cp -p'
   elif ln conf$$.file conf$$ 2>/dev/null; then
     as_ln_s=ln
   else
-    as_ln_s='cp -pR'
+    as_ln_s='cp -p'
   fi
 else
-  as_ln_s='cp -pR'
+  as_ln_s='cp -p'
 fi
 rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
 rmdir conf$$.dir 2>/dev/null
@@ -5414,16 +5427,28 @@ else
   as_mkdir_p=false
 fi
 
-
-# as_fn_executable_p FILE
-# -----------------------
-# Test if FILE is an executable regular file.
-as_fn_executable_p ()
-{
-  test -f "$1" && test -x "$1"
-} # as_fn_executable_p
-as_test_x='test -x'
-as_executable_p=as_fn_executable_p
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+	test -d "$1/.";
+      else
+	case $1 in #(
+	-*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
 
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -5445,7 +5470,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # values after options handling.
 ac_log="
 This file was extended by myconfig $as_me version-0.1, which was
-generated by GNU Autoconf 2.69.  Invocation command line was
+generated by GNU Autoconf 2.68.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
@@ -5498,10 +5523,10 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
 myconfig config.status version-0.1
-configured by $0, generated by GNU Autoconf 2.69,
+configured by $0, generated by GNU Autoconf 2.68,
   with options \\"\$ac_cs_config\\"
 
-Copyright (C) 2012 Free Software Foundation, Inc.
+Copyright (C) 2010 Free Software Foundation, Inc.
 This config.status script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it."
 
@@ -5578,7 +5603,7 @@ fi
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 if \$ac_cs_recheck; then
-  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
   shift
   \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
   CONFIG_SHELL='$SHELL'
diff --git a/configure.in b/configure.in
index e6f71762d..2a01bb84e 100644
--- a/configure.in
+++ b/configure.in
@@ -18,7 +18,9 @@ fi
 LIB=$ZIPR_HOME/callbacks/lib/callbacks.a
 AR=ar
 CC=gcc
-CFLAGS="$OPTIMIZE -fPIE -fPIC -I$ZIPR_HOME/include "
+CXX=g++
+CFLAGS="$OPTIMIZE -fPIE -fPIC -I$ZIPR_HOME/include -I$ZIPR_HOME/third_party/ELFIO/elfio-2.2/ -I$ZIPR_SDK/include -I$SECURITY_TRANSFORMS_HOME/libIRDB/include -I$SECURITY_TRANSFORMS_HOME/beaengine/include -I$SECURITY_TRANSFORMS_HOME/include -I$SECURITY_TRANSFORMS_HOME/tools/transforms"
+CXXFLAGS="$CFLAGS"
 LD=gcc
 LDFLAGS=""
 AS=nasm
@@ -37,6 +39,8 @@ AC_OUTPUT(src/Makefile)
 AC_SUBST(DIRS)
 AC_SUBST(CC)
 AC_SUBST(CFLAGS)
+AC_SUBST(CXX)
+AC_SUBST(CXXFLAGS)
 AC_SUBST(LD)
 AC_SUBST(LDFLAGS)
 AC_SUBST(AS)
diff --git a/include/nonce_relocs.h b/include/nonce_relocs.h
deleted file mode 100644
index ad36b8943..000000000
--- a/include/nonce_relocs.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/***************************************************************************
- * Copyright (c)  2014  Zephyr Software LLC. All rights reserved.
- *
- * This software is furnished under a license and/or other restrictive
- * terms and may be used and copied only in accordance with such terms
- * and the inclusion of the above copyright notice. This software or
- * any other copies thereof may not be provided or otherwise made
- * available to any other person without the express written consent
- * of an authorized representative of Zephyr Software LCC. Title to,
- * ownership of, and all rights in the software is retained by
- * Zephyr Software LCC.
- *
- * Zephyr Software LLC. Proprietary Information
- *
- * Unless otherwise specified, the information contained in this
- * directory, following this legend, and/or referenced herein is
- * Zephyr Software LLC. (Zephyr) Proprietary Information.
- *
- * CONTACT
- *
- * For technical assistance, contact Zephyr Software LCC. at:
- *
- *
- * Zephyr Software, LLC
- * 2040 Tremont Rd
- * Charlottesville, VA 22911
- *
- * E-mail: jwd@zephyr-software.com
- **************************************************************************/
-
-#ifndef nonce_relocs_h
-#define nonce_relocs_h
-
-
-class NonceRelocs_t
-{
-	public:
-	
-		// constructors
-		NonceRelocs_t(MemorySpace_t &p_ms, ELFIO::elfio& p_elfio, libIRDB::FileIR_t& p_firp, Options_t& p_opts) :
-			m_memory_space(p_ms), 
-			m_elfio(p_elfio),
-			m_firp(p_firp),
-			m_opts(p_opts)
-		{
-		}
-
-		// main workhorse
-		void HandleNonceRelocs();
-		void UpdateAddrRanges(std::map<libIRDB::Instruction_t*,RangeAddress_t> &final_insn_locations);
-
-	private:
-
-		// helpers
-		int GetNonceValue(libIRDB::Relocation_t& reloc);
-		int GetNonceSize(libIRDB::Relocation_t& reloc);
-		bool IsNonceRelocation(libIRDB::Relocation_t& reloc);
-		libIRDB::Relocation_t* FindRelocation(libIRDB::Instruction_t* insn, std::string type);
-		libIRDB::Relocation_t* FindNonceRelocation(libIRDB::Instruction_t* insn);
-		libIRDB::Relocation_t* FindSlowpathRelocation(libIRDB::Instruction_t* insn);
-
-		// major workhorses
-		void HandleNonceRelocation(libIRDB::Instruction_t& insn, libIRDB::Relocation_t& reloc);
-		void AddSlowPathInstructions();
-
-		// references to input
-		MemorySpace_t &m_memory_space;	
-		ELFIO::elfio&  m_elfio;
-		libIRDB::FileIR_t& m_firp;
-		Options_t& m_opts;
-
-		// local data.
-
-		// the set of instructions where we were asked to insert a nonce, but 
-		// couldn't.  This will be necessary when we need to emit code for the slow path 
-		libIRDB::InstructionSet_t slow_path_nonces;
-
-
-		// max_addr_updates
-		libIRDB::InstructionSet_t max_addr_update;
-		libIRDB::InstructionSet_t min_addr_update;
-
-};
-
-#endif
diff --git a/include/plugin_man.h b/include/plugin_man.h
new file mode 100644
index 000000000..ac3764e3a
--- /dev/null
+++ b/include/plugin_man.h
@@ -0,0 +1,53 @@
+
+
+typedef Zipr_SDK::ZiprPluginInterface_t* DLFunctionHandle_t;
+typedef std::set<DLFunctionHandle_t> DLFunctionHandleSet_t;
+
+typedef Zipr_SDK::ZiprPluginInterface_t* (*GetPluginInterface_t)(
+        Zipr_SDK::MemorySpace_t *p_ms,
+        ELFIO::elfio *p_elfio,
+        libIRDB::FileIR_t *p_firp,
+        Zipr_SDK::Options_t *p_opts,
+        Zipr_SDK::InstructionLocationMap_t *p_fil
+	);
+
+
+class ZiprPluginManager_t : public ZiprPluginInterface_t
+{
+	public:
+		ZiprPluginManager_t
+			(
+        		 Zipr_SDK::MemorySpace_t *p_ms,
+        		 ELFIO::elfio *p_elfio,
+        		 libIRDB::FileIR_t *p_firp,
+        		 Zipr_SDK::Options_t *p_opts,
+        		 Zipr_SDK::InstructionLocationMap_t *p_fil
+			)
+			: m_opts(p_opts)
+			{ open_plugins(p_ms,p_elfio,p_firp,p_opts,p_fil); }
+
+        	virtual void PinningBegin();
+        	virtual void PinningEnd();
+	
+        	virtual void DollopBegin();
+        	virtual void DollopEnd();
+	
+        	virtual void CallbackLinkingBegin();
+        	virtual void CallbackLinkingEnd();
+
+	private:
+
+		Options_t *m_opts;
+		void open_plugins
+			(
+        		 Zipr_SDK::MemorySpace_t *p_ms,
+        		 ELFIO::elfio *p_elfio,
+        		 libIRDB::FileIR_t *p_firp,
+        		 Zipr_SDK::Options_t *p_opts,
+        		 Zipr_SDK::InstructionLocationMap_t *p_fil
+			);
+
+		// storage for handles that've been dlopened()
+		DLFunctionHandleSet_t m_handleList;
+
+};
diff --git a/include/range.h b/include/range.h
deleted file mode 100644
index ce8b45bad..000000000
--- a/include/range.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/***************************************************************************
- * Copyright (c)  2014  Zephyr Software LLC. All rights reserved.
- *
- * This software is furnished under a license and/or other restrictive
- * terms and may be used and copied only in accordance with such terms
- * and the inclusion of the above copyright notice. This software or
- * any other copies thereof may not be provided or otherwise made
- * available to any other person without the express written consent
- * of an authorized representative of Zephyr Software LCC. Title to,
- * ownership of, and all rights in the software is retained by
- * Zephyr Software LCC.
- *
- * Zephyr Software LLC. Proprietary Information
- *
- * Unless otherwise specified, the information contained in this
- * directory, following this legend, and/or referenced herein is
- * Zephyr Software LLC. (Zephyr) Proprietary Information. 
- *
- * CONTACT
- *
- * For technical assistance, contact Zephyr Software LCC. at:
- *      
- *
- * Zephyr Software, LLC
- * 2040 Tremont Rd
- * Charlottesville, VA 22911
- *
- * E-mail: jwd@zephyr-software.com
- **************************************************************************/
-
-#ifndef range_h
-#define range_h
-
-
-typedef uintptr_t RangeAddress_t;
-
-class Range_t
-{
-	public:
-		Range_t(RangeAddress_t p_s, RangeAddress_t p_e) : m_start(p_s), m_end(p_e) { }
-		Range_t() : m_start(0), m_end(0) { }
-
-		RangeAddress_t GetStart() const { return m_start; }
-		RangeAddress_t GetEnd() const { return m_end; }
-
-		bool Is2ByteRange()
-		{
-			return (m_end - m_start) == 2;
-		};
-		bool Is5ByteRange()
-		{
-			return (m_end - m_start) == 5;
-		};
-
-	protected:
-
-		RangeAddress_t m_start, m_end;
-};
-
-#endif
diff --git a/include/zipr.h b/include/zipr.h
index dde547879..eb294d6a2 100644
--- a/include/zipr.h
+++ b/include/zipr.h
@@ -31,19 +31,20 @@
 #ifndef zipr_h
 #define zipr_h
 
-class Options_t;
+class ZiprOptions_t;
 class Stats_t;
 
 class Zipr_t
 {
 	public:
-		Zipr_t(libIRDB::FileIR_t* p_firp, Options_t &p_opts) : 
+		Zipr_t(libIRDB::FileIR_t* p_firp, ZiprOptions_t &p_opts) : 
 			m_firp(p_firp), 
 			m_opts(p_opts), 
 			memory_space(&p_opts), 
 			m_stats(NULL), 
-			elfiop(NULL), 
-			start_of_new_space(0)
+			elfiop(new ELFIO::elfio), 
+			start_of_new_space(0),
+			plugman(&memory_space, elfiop, p_firp, (Zipr_SDK::Options_t*)&p_opts, &final_insn_locations)
 		{ 
 			bss_needed=0;
 			use_stratafier_mode=false;
@@ -51,11 +52,11 @@ class Zipr_t
 
 		void CreateBinaryFile(const std::string &name);
 
-	protected:
+	private:
 
 		// data for the stuff we're rewriting.
 		libIRDB::FileIR_t* m_firp;
-		Options_t& m_opts;
+		ZiprOptions_t& m_opts;
 		Stats_t *m_stats;
 
 		// phases of rewriting.
@@ -133,11 +134,13 @@ class Zipr_t
 		// records where we will insert extra bytes into the program.
 		RangeAddress_t start_of_new_space;
 
-		MemorySpace_t memory_space;
+		ZiprMemorySpace_t memory_space;
 
 	        RangeAddress_t bss_needed;
 		bool use_stratafier_mode;
 
+		ZiprPluginManager_t plugman;
+
 };
 
 #endif
diff --git a/include/zipr_all.h b/include/zipr_all.h
index 96e583951..bcd6c641a 100644
--- a/include/zipr_all.h
+++ b/include/zipr_all.h
@@ -43,17 +43,20 @@
 #include "elfio/elfio_dump.hpp"
 
 
+#include <zipr_sdk.h>
+
 namespace zipr
 {
 
-#include <range.h>
+using namespace Zipr_SDK;
+
 #include <unresolved.h>
-#include <memory_space.h>
+#include <zipr_mem_space.h>
+#include <plugin_man.h>
 #include <zipr.h>
 #include <zipr_optimizations.h>
-#include <zipr_options.h>
+#include <zipr_opts.h>
 #include <zipr_stats.h>
-#include <nonce_relocs.h>
 
 };
 
diff --git a/include/memory_space.h b/include/zipr_mem_space.h
similarity index 91%
rename from include/memory_space.h
rename to include/zipr_mem_space.h
index 38f6b827c..118621768 100644
--- a/include/memory_space.h
+++ b/include/zipr_mem_space.h
@@ -31,22 +31,13 @@
 #ifndef memory_space_h
 #define memory_space_h
 
-class Options_t;
-
-struct Range_tCompare
-{
-	bool operator()(const Range_t first, const Range_t second)
-	{
-		return first.GetEnd() < second.GetStart();
-	}
-};
-
+class ZiprOptions_t;
 
 // a memory space _is_ a map of range addres to char, with additional functionality.
-class MemorySpace_t : public std::map<RangeAddress_t,char>
+class ZiprMemorySpace_t : public MemorySpace_t
 {
 	public:
-		MemorySpace_t(Options_t *opts) :
+		ZiprMemorySpace_t(ZiprOptions_t *opts) :
 			m_opts(opts)
 		{ 
 		}
@@ -93,7 +84,7 @@ class MemorySpace_t : public std::map<RangeAddress_t,char>
 
 	protected:
 		std::set<Range_t, Range_tCompare> free_ranges;   // keep ordered
-		Options_t *m_opts;
+		ZiprOptions_t *m_opts;
 
 	private:
 		RangeAddress_t min_plopped;
diff --git a/include/zipr_options.h b/include/zipr_opts.h
similarity index 94%
rename from include/zipr_options.h
rename to include/zipr_opts.h
index 1595316cb..71b4c1bcd 100644
--- a/include/zipr_options.h
+++ b/include/zipr_opts.h
@@ -36,10 +36,10 @@
 #include <unistd.h>
 #include <libIRDB-core.hpp>
 
-class Options_t 
+class ZiprOptions_t : public Options_t
 {
 	public:
-		Options_t() : 
+		ZiprOptions_t() : 
 			m_outname("b.out"), 
 			m_objcopy_path("/usr/bin/objcopy")
 		{
@@ -48,7 +48,7 @@ class Options_t
 			m_architecture=-1;
 		}
 
-		static Options_t* parse_args(int p_argc, char* p_argv[]);
+		static ZiprOptions_t* parse_args(int p_argc, char* p_argv[]);
 		static void print_usage(int p_argc, char *p_argv[]);
 
 		std::string GetOutputFileName(libIRDB::File_t* p_file) { return m_outname; }
diff --git a/include/zipr_stats.h b/include/zipr_stats.h
index 3121b66fd..fcdcc76e1 100644
--- a/include/zipr_stats.h
+++ b/include/zipr_stats.h
@@ -41,7 +41,7 @@ class Stats_t
 			total_free_ranges = 0;
 		};
 
-		void PrintStats(Options_t opts, std::ostream &out);
+		void PrintStats(ZiprOptions_t &opts, std::ostream &out);
 
 		/*
 		 * General stats tracking.
diff --git a/src/Makefile.in b/src/Makefile.in
index 5d32614e6..4a6c10f1c 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -3,12 +3,12 @@ INC=-I../include -I../third_party/ELFIO/elfio-2.2 -I$(SECURITY_TRANSFORMS_HOME)/
 
 
 
-SRCS=zipr.cpp zipr_options.cpp zipr_stats.cpp memory_space.cpp main.cpp nonce_relocs.cpp
+SRCS=zipr.cpp zipr_options.cpp zipr_stats.cpp memory_space.cpp main.cpp plugin_man.cpp
 OBJS=$(subst .cpp,.o, $(SRCS))
 EXE=zipr.exe
 
-CXX=g++
-CXXFLAGS=$(INC) @OPTIMIZE@
+CXX=@CXX@
+CXXFLAGS=@CXXFLAGS@ @OPTIMIZE@
 LDFLAGS=-L$(SECURITY_TRANSFORMS_HOME)/lib
 LIBS=-lpqxx -lpq -lIRDB-core -lBeaEngine_s_d -ltransform ${SECURITY_TRANSFORMS_HOME}/tools/transforms/Rewrite_Utility.o
 
diff --git a/src/main.cpp b/src/main.cpp
index 07f9d08b1..d9db6489e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -47,7 +47,7 @@ using namespace std;
 
 int main(int argc, char* argv[])
 {
-	Options_t *options=Options_t::parse_args(argc,argv);
+	ZiprOptions_t *options=ZiprOptions_t::parse_args(argc,argv);
 
 
         VariantID_t *pidp=NULL;
@@ -55,7 +55,7 @@ int main(int argc, char* argv[])
 
 	if (options->GetVariantID() == -1)
 	{
-		Options_t::print_usage(argc, argv);
+		ZiprOptions_t::print_usage(argc, argv);
 		return 1;
 	}
 
diff --git a/src/memory_space.cpp b/src/memory_space.cpp
index ddb96b64a..1fa8cc988 100644
--- a/src/memory_space.cpp
+++ b/src/memory_space.cpp
@@ -26,9 +26,9 @@
 using namespace zipr;
 using namespace std;
 
-void MemorySpace_t::SplitFreeRange(RangeAddress_t addr)
+void ZiprMemorySpace_t::SplitFreeRange(RangeAddress_t addr)
 {
-	std::set<Range_t>::iterator it=FindFreeRange(addr);
+	RangeSet_t::iterator it=FindFreeRange(addr);
 	assert(IsValidRange(it));
 
 	Range_t r=*it;
@@ -55,7 +55,7 @@ void MemorySpace_t::SplitFreeRange(RangeAddress_t addr)
 	}
 }
 
-void MemorySpace_t::MergeFreeRange(RangeAddress_t addr)
+void ZiprMemorySpace_t::MergeFreeRange(RangeAddress_t addr)
 {
 	/*
 	 * Make a new range of one byte.
@@ -68,7 +68,7 @@ void MemorySpace_t::MergeFreeRange(RangeAddress_t addr)
 
 	Range_t nr(addr, addr);
 	bool merged = false;
-	std::set<Range_t>::iterator it=free_ranges.begin();
+	RangeSet_t::iterator it=free_ranges.begin();
 
 	for(;it!=free_ranges.end();++it)
 	{
@@ -163,9 +163,9 @@ void MemorySpace_t::MergeFreeRange(RangeAddress_t addr)
 	}
 }
 
-void MemorySpace_t::PrintMemorySpace(std::ostream &out)
+void ZiprMemorySpace_t::PrintMemorySpace(std::ostream &out)
 {
-	for( std::set<Range_t>::iterator it=free_ranges.begin();
+	for( RangeSet_t::iterator it=free_ranges.begin();
 		it!=free_ranges.end();
 		++it)
 	{
@@ -174,20 +174,20 @@ void MemorySpace_t::PrintMemorySpace(std::ostream &out)
 	}
 }
 
-std::set<Range_t>::iterator MemorySpace_t::FindFreeRange(RangeAddress_t addr)
+RangeSet_t::iterator ZiprMemorySpace_t::FindFreeRange(RangeAddress_t addr)
 {
-	std::set<Range_t>::iterator freer = free_ranges.find(Range_t(addr, addr)); 
+	RangeSet_t::iterator freer = free_ranges.find(Range_t(addr, addr)); 
 	return freer;
 }
 
-bool MemorySpace_t::IsValidRange(std::set<Range_t>::iterator it)
+bool ZiprMemorySpace_t::IsValidRange(RangeSet_t::iterator it)
 {
 	return it!=free_ranges.end();
 }
 
-Range_t MemorySpace_t::GetFreeRange(int size)
+Range_t ZiprMemorySpace_t::GetFreeRange(int size)
 {
-	for( std::set<Range_t>::iterator it=free_ranges.begin();
+	for( RangeSet_t::iterator it=free_ranges.begin();
 		it!=free_ranges.end();
 		++it)
 	{
@@ -199,7 +199,7 @@ Range_t MemorySpace_t::GetFreeRange(int size)
 }
 
 // queries about free areas.
-bool MemorySpace_t::AreBytesFree(RangeAddress_t addr, int num_bytes)
+bool ZiprMemorySpace_t::AreBytesFree(RangeAddress_t addr, int num_bytes)
 {
 	for(int i=0;i<num_bytes;i++)
 		if(!IsByteFree(addr+i))
@@ -207,18 +207,18 @@ bool MemorySpace_t::AreBytesFree(RangeAddress_t addr, int num_bytes)
 	return true;
 }
 
-bool MemorySpace_t::IsByteFree(RangeAddress_t addr)
+bool ZiprMemorySpace_t::IsByteFree(RangeAddress_t addr)
 {
 	if (IsValidRange(FindFreeRange(addr)))
 		return true;
 	return false;
 }
 
-void MemorySpace_t::AddFreeRange(Range_t newRange)
+void ZiprMemorySpace_t::AddFreeRange(Range_t newRange)
 {
 	free_ranges.insert(Range_t(newRange.GetStart(), newRange.GetEnd()));
 }
-int MemorySpace_t::GetRangeCount()
+int ZiprMemorySpace_t::GetRangeCount()
 {
 	return free_ranges.size();
 }
diff --git a/src/nonce_relocs.cpp b/src/nonce_relocs.cpp
deleted file mode 100644
index b50e4d553..000000000
--- a/src/nonce_relocs.cpp
+++ /dev/null
@@ -1,317 +0,0 @@
-
-#include <zipr_all.h>
-#include <string>
-#include <algorithm>
-#include "utils.hpp"
-#include "Rewrite_Utility.hpp"
-
-
-using namespace libIRDB;
-using namespace std;
-using namespace zipr;
-using namespace ELFIO;
-
-
-static Instruction_t* addNewAssembly(FileIR_t* firp, Instruction_t *p_instr, string p_asm)
-{
-        Instruction_t* newinstr;
-        if (p_instr)
-                newinstr = allocateNewInstruction(firp,p_instr->GetAddress()->GetFileID(), p_instr->GetFunction());
-        else
-                newinstr = allocateNewInstruction(firp,BaseObj_t::NOT_IN_DATABASE, NULL);
-
-        firp->RegisterAssembly(newinstr, p_asm);
-
-        if (p_instr)
-        {
-                newinstr->SetFallthrough(p_instr->GetFallthrough());
-                p_instr->SetFallthrough(newinstr);
-        }
-
-        return newinstr;
-}
-
-
-
-bool NonceRelocs_t::IsNonceRelocation(Relocation_t& reloc)
-{
-	if(strstr(reloc.GetType().c_str(),"cfi_nonce=")==NULL)
-		return false;
-	return true;
-}
-
-
-int NonceRelocs_t::GetNonceValue(Relocation_t& reloc)
-{
-	int value=0;
-	size_t loc=reloc.GetType().find('=');
-
-	// get the tail of the string starting a position "loc"
-	string nonce_value=reloc.GetType().substr(loc+1,reloc.GetType().size()-loc-1);
-
-//cout<<"Nonce string is "<<nonce_value<<endl;;
-
-	return (int)strtol(nonce_value.c_str(),0,10);	
-}
-
-int NonceRelocs_t::GetNonceSize(Relocation_t& reloc)
-{
-	int size=-reloc.GetOffset();
-	return size;
-}
-
-void NonceRelocs_t::HandleNonceRelocation(Instruction_t &insn, Relocation_t& reloc)
-{
-	int size=GetNonceSize(reloc);
-	int value=GetNonceValue(reloc);
-
-	assert(insn.GetIndirectBranchTargetAddress());
-	RangeAddress_t addr=insn.GetIndirectBranchTargetAddress()->GetVirtualOffset()-size;
-
-	
-	if(!m_memory_space.AreBytesFree(addr,size))
-	{
-		cout<<"Cannot insert nonce at "<<std::hex<<addr<<" because memory is already busy"<<endl;
-		slow_path_nonces.insert(&insn);
-		return;
-	}
-
-	// for each byte of the nonce, plop down the values
-	cout<<"Plopping nonce "<<std::hex<<value<<" at "<<std::hex<<addr<<endl;
-	for(int i=0;i<size;i++)
-	{ 
-		cout<<"Plopping "<<std::hex<<(value&0xff)<<" at "<<std::hex<<(addr+i)<<endl;
-		m_memory_space.PlopByte(addr+i,value&0xff);
-		value=value>>8;
-	}
-
-	// plop bytes for nonce into exe
-
-}
-
-void NonceRelocs_t::AddSlowPathInstructions()
-{
-
-	// optimization
-	// find out if slow path insns are even needed!
-	InstructionSet_t::iterator it;
-        for( it=m_firp.GetInstructions().begin(); it!=m_firp.GetInstructions().end(); ++it)
-        {
-                Instruction_t* insn=*it;
-                Relocation_t* reloc=FindSlowpathRelocation(insn);
-                if(reloc)
-                        break;
-        }
-	// exited loop normally, or hit the break statement?
-	if(it==m_firp.GetInstructions().end())
-	{
-		cout<<"Found no slow paths to link, skipping slow-path code."<<endl;
-		return;
-	}
-	
-
-
-	Instruction_t* slow_path=NULL, *exit_node=NULL, *tmp=NULL;
-	string reg="ecx";
-	if(m_firp.GetArchitectureBitWidth()==64)
-		reg="rcx";
-
-	// call exit -- note we can use 32-bit regs as they're valid on 64-bit machines and still get the 64-bit reg with the right value.
-	exit_node=
-	slow_path=
-		  tmp = addNewAssembly(&m_firp, NULL, "mov eax, 1");		// SYS_exit
-#ifndef CGC	// any exit code is OK for CGC, save an instruction.
-		  tmp = insertAssemblyAfter(&m_firp, tmp, "mov ebx, 199");	// exit code 199
-#endif
-	          tmp = insertAssemblyAfter(&m_firp,tmp,"int 0x80");	// make syscall
-
-	for(it=slow_path_nonces.begin(); it!=slow_path_nonces.end(); ++it)
-	{
-		Instruction_t* insn=*it;
-		Relocation_t* reloc=FindNonceRelocation(insn);
-		assert(reloc);
-
-		string assembly="cmp "+reg+", "+to_string(insn->GetIndirectBranchTargetAddress()->GetVirtualOffset());
-		cout<<"Inserting slow-path comparison: "<<assembly<<endl; 
-		// insert before acts weird, and really does enough bookkeeping to insert-after in a way to mimic insert before.
-        	Instruction_t* after = insertAssemblyBefore(&m_firp,slow_path,assembly);
-		Instruction_t* jne   = insertAssemblyAfter(&m_firp, slow_path, "je 0", insn);
-		exit_node=after;
-	}
-
-
-
-	// we need a dispatch handler in case the range check fails
-	// for now, just assume that cross-library jumps are safe
-	// we'll come back later and fix this to check better:  FIXME.
-	Instruction_t* out_of_range_handler=NULL;
-#ifdef CGC
-	out_of_range_handler=exit_node;	 // cgc is statically linked, so we can just go to the exit node.
-#else
-	
-	out_of_range_handler = addNewAssembly(&m_firp, NULL, "jmp "+reg);	// jmp rcx
-#endif
-
-	// before the individual checks on the slow path
-	// we want to insert a range check.
-	//	cmp rcx, start_segement_addr
-	//	jlt out_of_range_handler
-	//	cmp rcx, end_segment_addr
-	//	jgt out_of_range_handler
-
-#ifdef CGC
-	// CGC  needs to keep from faulting, so we have to check to make sure the IB is an intra-module IB.
-	// if not, we terminate immediately.
-	// we aren't doing the pop/cmp before jumping to the slow path, so we have to do it here.
-	Instruction_t* after = insertAssemblyBefore(&m_firp,slow_path,"pop "+reg); // 	pop ecx (get ret addr)
-	tmp = insertAssemblyAfter(&m_firp,slow_path,"cmp "+reg+", 0x12345678");
-	out_of_range_handler=exit_node;	 // cgc is statically linked, so we can just go to the exit node.
-#else
-
-	Instruction_t* after = insertAssemblyBefore(&m_firp,slow_path,"cmp "+reg+", 0x12345678");
-	tmp=slow_path;
-#endif
-	min_addr_update.insert(tmp);
-        tmp = insertAssemblyAfter(&m_firp,tmp,"jl 0",out_of_range_handler);        // cross library jump detected
-	tmp = insertAssemblyAfter(&m_firp,tmp,"cmp "+reg+", 0x87654321");
-	max_addr_update.insert(tmp);
-        tmp = insertAssemblyAfter(&m_firp,tmp,"jg 0",out_of_range_handler);        // cross library jump detected
-#ifdef CGC
-	// After we're sure it's in this segment, we can 
-	// go ahead and check for a nonce that we layed down previously.
-	// 	cmp byte [rcx-1], 0xf4
-	// 	jeq slow_path
-        tmp = insertAssemblyAfter(&m_firp,tmp,"cmp byte ["+reg+"-1], 0xf4");
-        tmp = insertAssemblyAfter(&m_firp,tmp,"jne 0",after);       // finally, go to the slow path checks when a nonce didn't work.
-        tmp = insertAssemblyAfter(&m_firp,tmp,"jmp "+reg);
-#endif // CGC
-
-
-	m_firp.AssembleRegistry();	// resolve all assembly into actual bits.
-
-	assert(slow_path);
-	cout<<"Slow path insn is "<<slow_path->getDisassembly()<<endl;
-
-	for( it=m_firp.GetInstructions().begin(); it!=m_firp.GetInstructions().end(); ++it)
-	{
-		Instruction_t* insn=*it;
-		Relocation_t* reloc=FindSlowpathRelocation(insn);
-		if(reloc)
-			insn->SetTarget(slow_path);	
-	}
-
-	m_firp.SetBaseIDS();		// assign a unique ID to each insn.
-}
-
-Relocation_t* NonceRelocs_t::FindRelocation(Instruction_t* insn, string type)
-{
-	Instruction_t* first_slow_path_insn=NULL;
-	RelocationSet_t::iterator rit;
-	for( rit=insn->GetRelocations().begin(); rit!=insn->GetRelocations().end(); ++rit)
-	{
-		Relocation_t& reloc=*(*rit);
-		if(reloc.GetType()==type)
-		{
-			return &reloc;
-		}
-	}
-	return NULL;
-}
-
-Relocation_t* NonceRelocs_t::FindSlowpathRelocation(Instruction_t* insn)
-{
-	return FindRelocation(insn,"slow_cfi_path");
-}
-
-Relocation_t* NonceRelocs_t::FindNonceRelocation(Instruction_t* insn)
-{
-	Instruction_t* first_slow_path_insn=NULL;
-	RelocationSet_t::iterator rit;
-	for( rit=insn->GetRelocations().begin(); rit!=insn->GetRelocations().end(); ++rit)
-	{
-		Relocation_t& reloc=*(*rit);
-		if(IsNonceRelocation(reloc))
-		{
-			return &reloc;
-		}
-	}
-	return NULL;
-}
-
-void NonceRelocs_t::HandleNonceRelocs()
-{
-	int handled=0;
-	int insns=0;
-	int relocs=0;
-	// for each instruction 
-	InstructionSet_t::iterator iit;
-	for(iit=m_firp.GetInstructions().begin(); iit!=m_firp.GetInstructions().end(); ++iit)
-	{
-		Instruction_t& insn=*(*iit);
-		insns++;
-
-		Relocation_t* reloc=FindNonceRelocation(&insn);
-		if(reloc)
-		{
-			HandleNonceRelocation(insn,*reloc);
-			handled++;
-
-			assert(insn.GetIndirectBranchTargetAddress());
-			
-		}
-	}
-
-	AddSlowPathInstructions();
-
-	cout<<"#ATTRIBUTE nonce_references="<< std::dec<<handled<<endl;
-	cout<<"#ATTRIBUTE instructions="<< std::dec<<insns<<endl;
-	cout<<"#ATTRIBUTE slow_path_nonces="<< std::dec<<slow_path_nonces.size()<<endl;
-
-}
-
-
-void NonceRelocs_t::UpdateAddrRanges(std::map<libIRDB::Instruction_t*,RangeAddress_t> &final_insn_locations)
-{
-	RangeAddress_t  min_addr=m_memory_space.GetMinPlopped();
-	RangeAddress_t  max_addr=m_memory_space.GetMaxPlopped();
-
-	int offset=0;	// deal with REX prefix for 64-bit mode.
-	if(m_firp.GetArchitectureBitWidth()==64)
-		offset=1;
-
-	InstructionSet_t::iterator it;
-	for(it=min_addr_update.begin(); it!=min_addr_update.end(); ++it)
-	{
-		Instruction_t& insn=*(*it);
-		RangeAddress_t insn_addr=final_insn_locations[&insn];
-		if(insn_addr)
-		{
-			cout<<"Updating min_addr at "<<hex<<insn_addr<<" to compare to "<<min_addr<<endl;
-			m_memory_space.PlopBytes(insn_addr+2+offset,(const char*)&min_addr,4); // cmp insn has a 4 byte immed.
-		}
-		else
-		{
-			cout<<"No addr for  min_addr at "<<hex<<insn_addr<<" to compare to "<<min_addr<<endl;
-		}
-	}
-
-	for(it=max_addr_update.begin(); it!=max_addr_update.end(); ++it)
-	{
-
-		Instruction_t& insn=*(*it);
-		RangeAddress_t insn_addr=final_insn_locations[&insn];
-		assert(insn_addr);
-		if(insn_addr)
-		{
-			cout<<"Updating max_addr at "<<hex<<insn_addr<<" to compare to "<<max_addr<<endl;
-			m_memory_space.PlopBytes(insn_addr+2+offset,(const char*)&max_addr,4);	// cmp insn with a 4-byte immed
-		}
-		else
-		{
-			cout<<"No addr for  max_addr at "<<hex<<insn_addr<<" to compare to "<<max_addr<<endl;
-		}
-	}
-
-
-	
-}
diff --git a/src/plugin_man.cpp b/src/plugin_man.cpp
new file mode 100644
index 000000000..f681d73db
--- /dev/null
+++ b/src/plugin_man.cpp
@@ -0,0 +1,152 @@
+/***************************************************************************
+ * Copyright (c)  2014  Zephyr Software LLC. All rights reserved.
+ *
+ * This software is furnished under a license and/or other restrictive
+ * terms and may be used and copied only in accordance with such terms
+ * and the inclusion of the above copyright notice. This software or
+ * any other copies thereof may not be provided or otherwise made
+ * available to any other person without the express written consent
+ * of an authorized representative of Zephyr Software LCC. Title to,
+ * ownership of, and all rights in the software is retained by
+ * Zephyr Software LCC.
+ *
+ * Zephyr Software LLC. Proprietary Information
+ *
+ * Unless otherwise specified, the information contained in this
+ * directory, following this legend, and/or referenced herein is
+ * Zephyr Software LLC. (Zephyr) Proprietary Information.
+ *
+ * CONTACT
+ *
+ * For technical assistance, contact Zephyr Software LCC. at:
+ *
+ *
+ * Zephyr Software, LLC
+ * 2040 Tremont Rd
+ * Charlottesville, VA 22911
+ *
+ * E-mail: jwd@zephyr-software.com
+ **************************************************************************/
+
+#include <zipr_all.h>
+
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <errno.h>
+#include <vector>
+#include <string>
+#include <iostream>
+
+
+
+using namespace std;
+using namespace Zipr_SDK;
+using namespace libIRDB;
+using namespace zipr;
+
+
+#define dispatch_to(func) \
+for(DLFunctionHandleSet_t::iterator it=m_handleList.begin(); it!=m_handleList.end();++it) \
+{ \
+	ZiprPluginInterface_t* zpi=(ZiprPluginInterface_t*)*it; \
+	zpi->func(); \
+} 
+ 
+void ZiprPluginManager_t::PinningBegin()
+{
+	dispatch_to(PinningBegin);
+}
+
+void ZiprPluginManager_t::PinningEnd()
+{
+	dispatch_to(PinningEnd);
+}
+
+void ZiprPluginManager_t::DollopBegin()
+{
+	dispatch_to(DollopBegin);
+}
+
+void ZiprPluginManager_t::DollopEnd()
+{
+	dispatch_to(DollopEnd);
+}
+void ZiprPluginManager_t::CallbackLinkingBegin()
+{
+	dispatch_to(CallbackLinkingBegin);
+}
+void ZiprPluginManager_t::CallbackLinkingEnd()
+{
+	dispatch_to(CallbackLinkingEnd);
+}
+
+void ZiprPluginManager_t::open_plugins
+                        (
+                         Zipr_SDK::MemorySpace_t *p_ms,
+                         ELFIO::elfio *p_elfio,
+                         libIRDB::FileIR_t *p_firp,
+                         Zipr_SDK::Options_t *p_opts,
+                         Zipr_SDK::InstructionLocationMap_t *p_fil
+                        )
+{
+	char* zinst=getenv("ZIPR_INSTALL");
+
+	if(!zinst)
+	{
+		cerr<<"Cannot fid $ZIPR_INSTALL environment variable.  Please set properly."<<endl;
+	}
+
+	string dir=string(zinst)+"/plugins/";
+
+    	DIR *dp;
+    	struct dirent *dirp;
+    	if((dp  = opendir(dir.c_str())) == NULL) 
+	{
+        	cout << "Error(" << errno << ") opening plugins directory: " << dir << endl;
+		exit(1);
+    	}
+
+    	while ((dirp = readdir(dp)) != NULL) 
+	{
+        	string name=dir+string(dirp->d_name);
+		string zpi(".zpi");
+
+		string extension=name.substr(name.size() - zpi.length());
+		if(extension!=zpi)
+		{
+			cout<<"File ("<<name<<") does not have proper extension, skipping."<<endl;
+			continue; // try next file
+		}
+		cout<<"Attempting load of file ("<<name<<")."<<endl;
+
+		void* handle=dlopen(name.c_str(), RTLD_LAZY|RTLD_GLOBAL);
+		if(!handle)
+		{
+			cerr<<"Failed to open file ("<<name<<"), error code: "<<dlerror()<<endl;
+			exit(1);
+		}
+		dlerror();
+
+		void* sym=dlsym(handle,"GetPluginInterface");
+		if(!sym)
+		{
+			cerr<<"Failed to find GetPluginInterface from file ("<<name<<"), error code: "<<dlerror()<<endl;
+			exit(1);
+		}
+
+		GetPluginInterface_t GetPluginInterface=(GetPluginInterface_t)sym;
+		Zipr_SDK::ZiprPluginInterface_t *interface=(*GetPluginInterface)(p_ms,p_elfio,p_firp,p_opts,p_fil);
+
+		if(!interface)
+		{
+			cerr<<"Failed to get interface from file ("<<name<<")"<<endl;
+			exit(1);
+		}
+
+		m_handleList.insert(interface);
+		
+    	}
+    	closedir(dp);
+    	return;
+}
diff --git a/src/zipr.cpp b/src/zipr.cpp
index 111b71466..21aaf47df 100644
--- a/src/zipr.cpp
+++ b/src/zipr.cpp
@@ -95,6 +95,8 @@ void Zipr_t::CreateBinaryFile(const std::string &name)
 	// create ranges, including extra range that's def. big enough.
 	FindFreeRanges(name);
 
+	plugman.PinningBegin();
+
 	// add pinned instructions
 	AddPinnedInstructions();
 
@@ -134,21 +136,32 @@ void Zipr_t::CreateBinaryFile(const std::string &name)
 	}
 
 
+
 	// Convert all 5-byte pins into full fragments
 	OptimizePinnedInstructions();
 
-	NonceRelocs_t nr(memory_space,*elfiop, *m_firp, m_opts);
-	nr.HandleNonceRelocs();
+	// tell plugins we are done pinning.
+	plugman.PinningEnd();
+
+//	NonceRelocs_t nr(memory_space,*elfiop, *m_firp, m_opts);
+//	nr.HandleNonceRelocs();
 
 	// now that pinning is done, start emitting unpinnned instructions, and patching where needed.
 	PlopTheUnpinnedInstructions();
 
+	// tell plugins we are done plopping and about to link callbacks.
+	plugman.CallbackLinkingBegin();
+
 	// now that all instructions are put down, we can figure out where the callbacks for this file wil go.
 	// go ahead and update any callback sites with the new locations 
 	UpdateCallbacks();
 
+
+	// ask plugman to inform the plugins we are done linking callbacks
+	plugman.CallbackLinkingEnd();
+
 	// tell the Nonce class to update it's range of high/low addrs if it used any.
-	nr.UpdateAddrRanges(final_insn_locations);
+//	nr.UpdateAddrRanges(final_insn_locations);
 
 	m_stats->total_free_ranges = memory_space.GetRangeCount();
 
@@ -199,7 +212,7 @@ RangeAddress_t Zipr_t::extend_section(ELFIO::section *sec, ELFIO::section *next_
 void Zipr_t::FindFreeRanges(const std::string &name)
 {
 	/* use ELFIO to load the sections */
-	elfiop=new ELFIO::elfio;
+//	elfiop=new ELFIO::elfio;
 
 	assert(elfiop);
 	elfiop->load(name);
diff --git a/src/zipr_options.cpp b/src/zipr_options.cpp
index 67ea6ee1d..c947acc4f 100644
--- a/src/zipr_options.cpp
+++ b/src/zipr_options.cpp
@@ -25,7 +25,7 @@
 
 using namespace zipr;
 
-void Options_t::print_usage(int p_argc, char *p_argv[])
+void ZiprOptions_t::print_usage(int p_argc, char *p_argv[])
 {
 	printf("%s [options]\n", p_argv[0]);
 	printf("\t-v variant-id\t--variant variant-id: "
@@ -46,9 +46,9 @@ void Options_t::print_usage(int p_argc, char *p_argv[])
 		"Quiet the verbose output. \n");
 }
 
-Options_t* Options_t::parse_args(int p_argc, char* p_argv[])
+ZiprOptions_t* ZiprOptions_t::parse_args(int p_argc, char* p_argv[])
 {
-	Options_t *opt=new Options_t;
+	ZiprOptions_t *opt=new ZiprOptions_t;
 	opt->SetVerbose(true);
 	extern char *optarg;
 	extern int optind, opterr, optopt;
@@ -164,7 +164,7 @@ Options_t* Options_t::parse_args(int p_argc, char* p_argv[])
 	return opt;
 }
 
-int Options_t::GetArchitecture() {
+int ZiprOptions_t::GetArchitecture() {
 	/*
 	 * If the user specified an architecture, return it.
 	 * Otherwise, return the one detected.
diff --git a/src/zipr_stats.cpp b/src/zipr_stats.cpp
index 477f1b535..c0da8be36 100644
--- a/src/zipr_stats.cpp
+++ b/src/zipr_stats.cpp
@@ -35,7 +35,7 @@ static void PrintStat(std::ostream &out, std::string description, double value)
 	out << description << ": " << std::dec << value << std::endl;
 }
 
-void Stats_t::PrintStats(Options_t opts, std::ostream &out)
+void Stats_t::PrintStats(ZiprOptions_t &opts, std::ostream &out)
 {
 	PrintStat(out, "Total dollops", total_dollops);
 	PrintStat(out, "Total dollop size", total_dollop_space);
-- 
GitLab