Skip to content
Snippets Groups Projects
Commit 0a37e8c0 authored by whh8b's avatar whh8b
Browse files

Add source/header/build files for large only plugin.

parent 0787a58c
No related branches found
No related tags found
No related merge requests found
......@@ -9,3 +9,7 @@
/set_ida_server -text
/start_dev.sh -text
/svn.externals.uva_dev -text
zipr_large_only_plugin/SConscript -text
zipr_large_only_plugin/SConstruct -text
zipr_large_only_plugin/large_only.cpp -text
zipr_large_only_plugin/large_only.h -text
import shutil
import os
import tarfile
Import('env')
#print 'env='
#print env.Dump()
myenv=env
myenv.Replace(SECURITY_TRANSFORMS_HOME=os.environ['SECURITY_TRANSFORMS_HOME'])
myenv.Replace(ZIPR_HOME=os.environ['ZIPR_HOME'])
myenv.Replace(ZIPR_SDK=os.environ['ZIPR_SDK'])
myenv.Replace(ZIPR_INSTALL=os.environ['ZIPR_INSTALL'])
myenv.Replace(do_cgc=ARGUMENTS.get("do_cgc",0))
if 'do_cgc' in env and int(env['do_cgc']) == 1:
myenv.Append(CFLAGS=" -DCGC ")
myenv.Append(CCFLAGS=" -DCGC ")
files= '''
large_only.cpp
'''
# ELFIO needs to be first so we get the zipr version instead of the sectrans version. the zipr version is modified to include get_offset.
cpppath='''
.
$ZIPR_HOME/third_party/ELFIO/elfio-2.2
$SECURITY_TRANSFORMS_HOME/include/
$SECURITY_TRANSFORMS_HOME/libIRDB/include/
$SECURITY_TRANSFORMS_HOME/beaengine/include
$SECURITY_TRANSFORMS_HOME/beaengine/beaengineSources/Includes/
$SECURITY_TRANSFORMS_HOME/tools/transforms
$ZIPR_HOME/include/
$ZIPR_SDK/include/
'''
libs='''
'''
libpath='''
$SECURITY_TRANSFORMS_HOME/lib
'''
myenv.Append(CCFLAGS=" -Wall ")
myenv=myenv.Clone(CPPPATH=Split(cpppath), LIBS=Split(libs), LIBPATH=Split(libpath), SHLIBSUFFIX=".zpi", SHLIBPREFIX="")
lib=myenv.SharedLibrary("large_only", Split(files))
install=myenv.Install("$ZIPR_INSTALL/plugins/", lib)
Default(install)
import os
import sys
env=Environment()
# default build options
env.Replace(CFLAGS="-fPIC -w ")
env.Replace(CXXFLAGS="-fPIC -w ")
env.Replace(LINKFLAGS="-fPIC ")
# parse arguments
env.Replace(SECURITY_TRANSFORMS_HOME=os.environ['SECURITY_TRANSFORMS_HOME'])
env.Replace(ZIPR_HOME=os.environ['ZIPR_HOME'])
env.Replace(ZIPR_INSTALL=os.environ['ZIPR_INSTALL'])
env.Replace(ZIPR_SDK=os.environ['ZIPR_SDK'])
env.Replace(debug=ARGUMENTS.get("debug",0))
env.Replace(do_64bit_build=ARGUMENTS.get("do_64bit_build",0))
if int(env['debug']) == 1:
print "Setting debug mode"
env.Append(CFLAGS=" -g")
env.Append(CXXFLAGS=" -g")
env.Append(LINKFLAGS=" -g")
else:
print "Setting release mode"
env.Append(CFLAGS=" -O3")
env.Append(CXXFLAGS=" -O3")
env.Append(LINKFLAGS=" -O3")
#env.Append(CXXFLAGS=" -std=c++0x")
# set 32/64 bit build properly
#print "env[64bit]="+str(env['do_64bit_build'])
#if env['do_64bit_build'] is None:
# print 'Defaulting to default compilation size.'
#elif int(env['do_64bit_build']) == 1:
# print 'Using 64-bit compilation size.'
# env.Append(CFLAGS=" -m64")
# env.Append(CXXFLAGS=" -m64")
# env.Append(LINKFLAGS=" -m64")
# env.Append(SHLINKFLAGS=" -m64")
#else:
# print 'Using 32-bit compilation size.'
# env.Append(CFLAGS=" -m32")
# env.Append(CXXFLAGS=" -m32")
# env.Append(LINKFLAGS=" -m32")
# env.Append(SHLINKFLAGS=" -m32")
env['build_appfw']=0
env['build_tools']=0
Export('env')
SConscript("SConscript", variant_dir='build')
/***************************************************************************
* 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_sdk.h>
#include <string>
#include <algorithm>
#include "utils.hpp"
#include "Rewrite_Utility.hpp"
#include "large_only.h"
using namespace libIRDB;
using namespace std;
using namespace Zipr_SDK;
using namespace ELFIO;
LargeOnly_t::LargeOnly_t(MemorySpace_t *p_ms,
elfio *p_elfio,
FileIR_t *p_firp,
Options_t *p_opts,
InstructionLocationMap_t *p_fil) :
m_memory_space(*p_ms),
m_elfio(*p_elfio),
m_firp(*p_firp),
m_opts(*p_opts),
final_insn_locations(*p_fil)
{
}
void LargeOnly_t::RemoveSmallMemorySpaces(void)
{
Range_t removableRange;
Range_t largeRange;
cout << "Starting to remove all small memory spaces." << endl;
while (m_memory_space.GetRangeCount() != 0)
{
removableRange = m_memory_space.GetFreeRange(0);
cout << "Removing: " << removableRange.GetStart() << " - " << removableRange.GetEnd() << endl;
if (removableRange.GetEnd() == -1)
largeRange = removableRange;
m_memory_space.RemoveFreeRange(removableRange);
cout << "Memory space size: " << m_memory_space.GetRangeCount() << endl;
}
m_memory_space.AddFreeRange(largeRange);
if (m_opts.GetVerbose())
{
cout << "After removing all small memory spaces:" << endl;
m_memory_space.PrintMemorySpace(cout);
}
}
extern "C"
Zipr_SDK::ZiprPluginInterface_t* GetPluginInterface(
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)
{
return new LargeOnly_t(p_ms,p_elfio,p_firp,p_opts,p_fil);
}
/***************************************************************************
* 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 large_only_h
#define large_only_h
#include <libIRDB-core.hpp>
class LargeOnly_t : public Zipr_SDK::ZiprPluginInterface_t
{
public:
LargeOnly_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);
virtual void PinningBegin()
{
}
virtual void PinningEnd()
{
cout<<"Push64Plugin: Ending pinning, applying push64 relocs."<<endl;
RemoveSmallMemorySpaces();
}
virtual void DollopBegin()
{
}
virtual void DollopEnd()
{
}
virtual void CallbackLinkingBegin()
{
}
virtual void CallbackLinkingEnd()
{
}
private:
void RemoveSmallMemorySpaces(void);
// references to input
Zipr_SDK::MemorySpace_t &m_memory_space;
ELFIO::elfio& m_elfio;
libIRDB::FileIR_t& m_firp;
Zipr_SDK::Options_t& m_opts;
Zipr_SDK::InstructionLocationMap_t &final_insn_locations;
// local data.
libIRDB::InstructionSet_t plopped_relocs;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment