2007-10-20 09:03:51 +02:00
|
|
|
#!/usr/bin/env python
|
2010-04-26 22:13:11 +02:00
|
|
|
#---------------------------------------------------------------------
|
2011-10-14 16:24:38 +02:00
|
|
|
# IDAPython - Python plugin for Interactive Disassembler
|
2007-10-20 09:03:51 +02:00
|
|
|
#
|
2011-10-14 16:24:38 +02:00
|
|
|
# (c) The IDAPython Team <idapython@googlegroups.com>
|
2007-10-20 09:03:51 +02:00
|
|
|
#
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# For detailed copyright information see the file COPYING in
|
|
|
|
# the root of the distribution archive.
|
2010-04-26 22:13:11 +02:00
|
|
|
#---------------------------------------------------------------------
|
2007-10-20 09:03:51 +02:00
|
|
|
# build.py - Custom build script
|
2010-04-26 22:13:11 +02:00
|
|
|
#---------------------------------------------------------------------
|
2008-08-15 22:59:06 +02:00
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
import types
|
2008-08-15 22:51:16 +02:00
|
|
|
import zipfile
|
2010-06-28 14:36:40 +02:00
|
|
|
import glob
|
2007-10-20 09:03:51 +02:00
|
|
|
from distutils import sysconfig
|
|
|
|
|
|
|
|
# Start of user configurable options
|
|
|
|
VERBOSE = True
|
2010-06-28 14:36:40 +02:00
|
|
|
|
2010-11-10 14:58:08 +01:00
|
|
|
IDA_MAJOR_VERSION = 6
|
2013-12-30 02:34:23 +01:00
|
|
|
IDA_MINOR_VERSION = 5
|
2010-06-28 14:36:40 +02:00
|
|
|
|
2009-10-17 22:54:08 +02:00
|
|
|
if 'IDA' in os.environ:
|
2009-10-16 14:07:18 +02:00
|
|
|
IDA_SDK = os.environ['IDA']
|
|
|
|
else:
|
2011-10-14 16:24:38 +02:00
|
|
|
IDA_SDK = os.path.join("..", "swigsdk-versions", ("%d.%d" % (IDA_MAJOR_VERSION, IDA_MINOR_VERSION)))
|
2009-10-16 14:07:18 +02:00
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
# End of user configurable options
|
|
|
|
|
|
|
|
# IDAPython version
|
2008-10-01 17:03:57 +02:00
|
|
|
VERSION_MAJOR = 1
|
2013-12-30 02:34:23 +01:00
|
|
|
VERSION_MINOR = 6
|
|
|
|
VERSION_PATCH = 0
|
2007-10-20 09:03:51 +02:00
|
|
|
|
|
|
|
# Determine Python version
|
|
|
|
PYTHON_MAJOR_VERSION = int(platform.python_version()[0])
|
|
|
|
PYTHON_MINOR_VERSION = int(platform.python_version()[2])
|
|
|
|
|
|
|
|
# Find Python headers
|
|
|
|
PYTHON_INCLUDE_DIRECTORY = sysconfig.get_config_var('INCLUDEPY')
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
S_EA64 = 'ea64'
|
|
|
|
S_WITH_HEXRAYS = 'with-hexrays'
|
|
|
|
S_NO_OPT = 'no-opt'
|
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
# Swig command-line parameters
|
2013-12-30 02:34:23 +01:00
|
|
|
SWIG_OPTIONS = '-modern -python -threads -c++ -w451 -shadow -D__GNUC__'
|
2007-10-20 09:03:51 +02:00
|
|
|
|
|
|
|
# Common macros for all compilations
|
|
|
|
COMMON_MACROS = [
|
|
|
|
("VER_MAJOR", "%d" % VERSION_MAJOR),
|
|
|
|
("VER_MINOR", "%d" % VERSION_MINOR),
|
|
|
|
("VER_PATCH", "%d" % VERSION_PATCH),
|
|
|
|
"__IDP__",
|
|
|
|
("MAXSTR", "1024"),
|
|
|
|
"USE_DANGEROUS_FUNCTIONS",
|
|
|
|
"USE_STANDARD_FILE_FUNCTIONS" ]
|
|
|
|
|
|
|
|
# Common includes for all compilations
|
|
|
|
COMMON_INCLUDES = [ ".", "swig" ]
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
2007-10-20 09:03:51 +02:00
|
|
|
# List files for the binary distribution
|
|
|
|
BINDIST_MANIFEST = [
|
|
|
|
"README.txt",
|
|
|
|
"COPYING.txt",
|
|
|
|
"CHANGES.txt",
|
2010-07-16 14:07:49 +02:00
|
|
|
"AUTHORS.txt",
|
2007-10-20 09:03:51 +02:00
|
|
|
"STATUS.txt",
|
2011-04-18 18:07:00 +02:00
|
|
|
"python.cfg",
|
2007-10-20 09:03:51 +02:00
|
|
|
"docs/notes.txt",
|
|
|
|
"examples/chooser.py",
|
2008-09-28 10:56:48 +02:00
|
|
|
"examples/colours.py",
|
2011-10-14 16:24:38 +02:00
|
|
|
"examples/ex_idphook_asm.py",
|
|
|
|
"examples/ex_uirequests.py",
|
2008-05-04 11:43:57 +02:00
|
|
|
"examples/debughook.py",
|
2010-07-16 14:07:49 +02:00
|
|
|
"examples/ex_cli.py",
|
2007-10-20 09:03:51 +02:00
|
|
|
"examples/ex1.idc",
|
2010-07-16 14:07:49 +02:00
|
|
|
"examples/ex_custdata.py",
|
2007-10-20 09:03:51 +02:00
|
|
|
"examples/ex1_idaapi.py",
|
2008-09-28 10:56:48 +02:00
|
|
|
"examples/ex1_idautils.py",
|
2008-10-01 17:03:57 +02:00
|
|
|
"examples/hotkey.py",
|
2008-09-28 10:56:48 +02:00
|
|
|
"examples/structure.py",
|
2009-09-16 16:00:31 +02:00
|
|
|
"examples/ex_gdl_qflow_chart.py",
|
|
|
|
"examples/ex_strings.py",
|
2010-06-28 14:36:40 +02:00
|
|
|
"examples/ex_add_menu_item.py",
|
2009-09-24 16:20:29 +02:00
|
|
|
"examples/ex_func_chooser.py",
|
|
|
|
"examples/ex_choose2.py",
|
2009-10-02 19:40:26 +02:00
|
|
|
"examples/ex_debug_names.py",
|
2009-10-16 14:07:18 +02:00
|
|
|
"examples/ex_graph.py",
|
2011-10-14 16:24:38 +02:00
|
|
|
"examples/ex_hotkey.py",
|
|
|
|
"examples/ex_patch.py",
|
|
|
|
"examples/ex_expr.py",
|
|
|
|
"examples/ex_timer.py",
|
2010-03-05 12:18:25 +01:00
|
|
|
"examples/ex_dbg.py",
|
2010-03-22 15:19:43 +01:00
|
|
|
"examples/ex_custview.py",
|
2010-10-07 11:47:04 +02:00
|
|
|
"examples/ex_prefix_plugin.py",
|
2010-11-10 14:58:08 +01:00
|
|
|
"examples/ex_pyside.py",
|
|
|
|
"examples/ex_pyqt.py",
|
2011-04-18 18:07:00 +02:00
|
|
|
"examples/ex_askusingform.py",
|
|
|
|
"examples/ex_uihook.py",
|
2011-10-14 16:24:38 +02:00
|
|
|
"examples/ex_idphook_asm.py",
|
2010-03-05 12:18:25 +01:00
|
|
|
"examples/ex_imports.py"
|
2008-08-15 22:59:06 +02:00
|
|
|
]
|
2007-10-20 09:03:51 +02:00
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
2007-10-20 09:03:51 +02:00
|
|
|
# List files for the source distribution (appended to binary list)
|
|
|
|
SRCDIST_MANIFEST = [
|
|
|
|
"BUILDING.txt",
|
|
|
|
"python.cpp",
|
|
|
|
"basetsd.h",
|
|
|
|
"build.py",
|
2011-04-18 18:07:00 +02:00
|
|
|
"python.cfg",
|
2008-07-17 20:46:46 +02:00
|
|
|
"swig/allins.i",
|
2009-05-23 16:40:01 +02:00
|
|
|
"swig/area.i",
|
2007-10-20 09:03:51 +02:00
|
|
|
"swig/auto.i",
|
|
|
|
"swig/bytes.i",
|
|
|
|
"swig/dbg.i",
|
|
|
|
"swig/diskio.i",
|
|
|
|
"swig/entry.i",
|
|
|
|
"swig/enum.i",
|
|
|
|
"swig/expr.i",
|
|
|
|
"swig/fixup.i",
|
|
|
|
"swig/frame.i",
|
|
|
|
"swig/funcs.i",
|
2009-05-23 16:40:01 +02:00
|
|
|
"swig/gdl.i",
|
2007-10-20 09:03:51 +02:00
|
|
|
"swig/ida.i",
|
|
|
|
"swig/idaapi.i",
|
2009-05-23 16:40:01 +02:00
|
|
|
"swig/idd.i",
|
2007-10-20 09:03:51 +02:00
|
|
|
"swig/idp.i",
|
|
|
|
"swig/ints.i",
|
|
|
|
"swig/kernwin.i",
|
|
|
|
"swig/lines.i",
|
|
|
|
"swig/loader.i",
|
|
|
|
"swig/moves.i",
|
|
|
|
"swig/nalt.i",
|
|
|
|
"swig/name.i",
|
2008-10-01 17:03:57 +02:00
|
|
|
"swig/netnode.i",
|
2007-10-20 09:03:51 +02:00
|
|
|
"swig/offset.i",
|
|
|
|
"swig/pro.i",
|
|
|
|
"swig/queue.i",
|
|
|
|
"swig/search.i",
|
|
|
|
"swig/segment.i",
|
|
|
|
"swig/srarea.i",
|
|
|
|
"swig/strlist.i",
|
|
|
|
"swig/struct.i",
|
|
|
|
"swig/typeconv.i",
|
|
|
|
"swig/typeinf.i",
|
|
|
|
"swig/ua.i",
|
|
|
|
"swig/xref.i",
|
2009-10-02 19:40:26 +02:00
|
|
|
"swig/graph.i",
|
2009-10-29 12:37:24 +01:00
|
|
|
"swig/fpro.i",
|
2013-07-03 03:40:54 +02:00
|
|
|
"swig/hexrays.i",
|
2008-06-25 23:03:38 +02:00
|
|
|
"tools/gendocs.py",
|
2007-10-20 09:03:51 +02:00
|
|
|
]
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
def parse_options(args):
|
|
|
|
"""Parse arguments and returned a dictionary of options"""
|
|
|
|
|
|
|
|
no_opt = '--' + S_NO_OPT in sys.argv
|
|
|
|
ea64 = '--' + S_EA64 in sys.argv
|
|
|
|
with_hexrays = '--' + S_WITH_HEXRAYS in sys.argv
|
|
|
|
|
|
|
|
return {
|
2013-12-30 02:34:23 +01:00
|
|
|
S_EA64: ea64,
|
|
|
|
S_WITH_HEXRAYS: with_hexrays,
|
2013-07-03 03:40:54 +02:00
|
|
|
S_NO_OPT: no_opt
|
|
|
|
}
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------
|
2007-10-20 09:03:51 +02:00
|
|
|
class BuilderBase:
|
|
|
|
""" Base class for builders """
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
def compile(self, source, objectname=None, includes=[], macros=[]):
|
|
|
|
"""
|
|
|
|
Compile the source file
|
|
|
|
"""
|
|
|
|
allmacros = []
|
|
|
|
allmacros.extend(COMMON_MACROS)
|
|
|
|
allmacros.extend(self.basemacros)
|
|
|
|
allmacros.extend(macros)
|
|
|
|
macrostring = self._build_command_string(allmacros, self.macro_delimiter)
|
|
|
|
|
|
|
|
allincludes = []
|
|
|
|
allincludes.extend(COMMON_INCLUDES)
|
|
|
|
allincludes.extend(includes)
|
|
|
|
includestring = self._build_command_string(allincludes, self.include_delimiter)
|
|
|
|
|
|
|
|
if not objectname:
|
|
|
|
objectname = source + self.object_extension
|
|
|
|
|
|
|
|
cmdstring = "%s %s %s %s %s %s" % (self.compiler,
|
|
|
|
self.compiler_parameters,
|
|
|
|
self.compiler_out_string(objectname),
|
|
|
|
self.compiler_in_string(source + self.source_extension),
|
|
|
|
includestring,
|
|
|
|
macrostring)
|
|
|
|
|
2010-06-28 14:36:40 +02:00
|
|
|
if VERBOSE:
|
|
|
|
print cmdstring
|
2007-10-20 09:03:51 +02:00
|
|
|
return os.system(cmdstring)
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
def link(self, objects, outfile, libpaths=[], libraries=[], extra_parameters=None):
|
|
|
|
""" Link the binary from objects and libraries """
|
|
|
|
cmdstring = "%s %s %s" % (self.linker,
|
|
|
|
self.linker_parameters,
|
|
|
|
self.linker_out_string(outfile))
|
|
|
|
|
|
|
|
for objectfile in objects:
|
2010-03-22 15:19:43 +01:00
|
|
|
cmdstring = "%s %s" % (cmdstring, objectfile + self.object_extension)
|
2007-10-20 09:03:51 +02:00
|
|
|
for libpath in libpaths:
|
|
|
|
cmdstring = "%s %s%s" % (cmdstring, self.libpath_delimiter, libpath)
|
|
|
|
for library in libraries:
|
|
|
|
cmdstring = "%s %s" % (cmdstring, library)
|
|
|
|
if extra_parameters:
|
|
|
|
cmdstring = "%s %s" % (cmdstring, extra_parameters)
|
|
|
|
|
|
|
|
if VERBOSE: print cmdstring
|
|
|
|
return os.system(cmdstring)
|
|
|
|
|
|
|
|
def _build_command_string(self, macros, argument_delimiter):
|
|
|
|
macrostring = ""
|
|
|
|
|
|
|
|
for item in macros:
|
|
|
|
if type(item) == types.TupleType:
|
|
|
|
macrostring += '%s%s="%s" ' % (argument_delimiter, item[0], item[1])
|
|
|
|
else:
|
|
|
|
macrostring += '%s%s ' % (argument_delimiter, item)
|
|
|
|
|
|
|
|
return macrostring
|
2010-03-22 15:19:43 +01:00
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
2007-10-20 09:03:51 +02:00
|
|
|
class GCCBuilder(BuilderBase):
|
|
|
|
""" Generic GCC compiler class """
|
|
|
|
def __init__(self):
|
|
|
|
self.include_delimiter = "-I"
|
|
|
|
self.macro_delimiter = "-D"
|
|
|
|
self.libpath_delimiter = "-L"
|
2011-10-14 16:24:38 +02:00
|
|
|
self.compiler_parameters = "-fpermissive -Wno-write-strings"
|
2007-10-20 09:03:51 +02:00
|
|
|
self.linker_parameters = "-shared"
|
|
|
|
self.basemacros = [ ]
|
2009-04-21 18:48:47 +02:00
|
|
|
self.compiler = "g++ -m32"
|
|
|
|
self.linker = "g++ -m32"
|
2007-10-20 09:03:51 +02:00
|
|
|
self.source_extension = ".cpp"
|
|
|
|
self.object_extension = ".o"
|
|
|
|
|
|
|
|
def compiler_in_string(self, filename):
|
|
|
|
return "-c %s" % filename
|
|
|
|
|
|
|
|
def compiler_out_string(self, filename):
|
|
|
|
return "-o %s" % filename
|
|
|
|
|
|
|
|
def linker_out_string(self, filename):
|
|
|
|
return "-o %s" % filename
|
|
|
|
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
2007-10-20 09:03:51 +02:00
|
|
|
class MSVCBuilder(BuilderBase):
|
2009-05-23 16:40:01 +02:00
|
|
|
""" Generic Visual C compiler class """
|
2007-10-20 09:03:51 +02:00
|
|
|
def __init__(self):
|
|
|
|
self.include_delimiter = "/I"
|
|
|
|
self.macro_delimiter = "/D"
|
|
|
|
self.libpath_delimiter = "/LIBPATH:"
|
|
|
|
self.compiler_parameters = "/nologo /EHsc"
|
|
|
|
self.linker_parameters = "/nologo /dll /export:PLUGIN"
|
|
|
|
self.basemacros = [ "WIN32",
|
|
|
|
"_USRDLL",
|
|
|
|
"__NT__" ]
|
|
|
|
self.compiler = "cl"
|
|
|
|
self.linker = "link"
|
|
|
|
self.source_extension = ".cpp"
|
|
|
|
self.object_extension = ".obj"
|
2009-09-16 16:00:31 +02:00
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
def compiler_in_string(self, filename):
|
|
|
|
return "/c %s" % filename
|
2009-09-16 16:00:31 +02:00
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
def compiler_out_string(self, filename):
|
|
|
|
return "/Fo%s" % filename
|
|
|
|
|
|
|
|
def linker_out_string(self, filename):
|
|
|
|
return "/out:%s" % filename
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
2009-05-23 16:40:01 +02:00
|
|
|
def build_distribution(manifest, distrootdir, ea64, nukeold):
|
|
|
|
""" Create a distibution to a directory and a ZIP file """
|
|
|
|
# (Re)create the output directory
|
2007-10-20 09:03:51 +02:00
|
|
|
if os.path.exists(distrootdir):
|
2009-05-23 16:40:01 +02:00
|
|
|
if nukeold:
|
|
|
|
shutil.rmtree(distrootdir)
|
|
|
|
os.makedirs(distrootdir)
|
|
|
|
else:
|
|
|
|
os.makedirs(distrootdir)
|
2008-08-15 22:51:16 +02:00
|
|
|
|
|
|
|
# Also make a ZIP archive of the build
|
|
|
|
zippath = distrootdir + ".zip"
|
2009-05-23 16:40:01 +02:00
|
|
|
zip = zipfile.ZipFile(zippath, nukeold and "w" or "a", zipfile.ZIP_DEFLATED)
|
2009-09-16 16:00:31 +02:00
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
# Copy files, one by one
|
|
|
|
for f in manifest:
|
|
|
|
if type(f) == types.TupleType:
|
|
|
|
srcfilepath = f[0]
|
|
|
|
srcfilename = os.path.basename(srcfilepath)
|
2011-10-14 16:24:38 +02:00
|
|
|
dstdir = os.path.join(distrootdir, f[1])
|
|
|
|
dstfilepath = os.path.join(dstdir, srcfilename)
|
2007-10-20 09:03:51 +02:00
|
|
|
else:
|
|
|
|
srcfilepath = f
|
|
|
|
srcfilename = os.path.basename(f)
|
|
|
|
srcdir = os.path.dirname(f)
|
|
|
|
if srcdir == "":
|
|
|
|
dstdir = distrootdir
|
|
|
|
else:
|
2011-10-14 16:24:38 +02:00
|
|
|
dstdir = os.path.join(distrootdir, srcdir)
|
2009-05-23 16:41:26 +02:00
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
if not os.path.exists(dstdir):
|
|
|
|
os.makedirs(dstdir)
|
2009-09-16 16:00:31 +02:00
|
|
|
|
2011-10-14 16:24:38 +02:00
|
|
|
dstfilepath = os.path.join(dstdir, srcfilename)
|
2007-10-20 09:03:51 +02:00
|
|
|
shutil.copyfile(srcfilepath, dstfilepath)
|
2008-08-15 22:51:16 +02:00
|
|
|
zip.write(dstfilepath)
|
2007-10-20 09:03:51 +02:00
|
|
|
|
2008-08-15 22:51:16 +02:00
|
|
|
zip.close()
|
2007-10-20 09:03:51 +02:00
|
|
|
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
def build_plugin(
|
2013-12-30 02:34:23 +01:00
|
|
|
platform,
|
|
|
|
idasdkdir,
|
|
|
|
plugin_name,
|
2013-07-03 03:40:54 +02:00
|
|
|
options):
|
|
|
|
|
|
|
|
# Get the arguments
|
|
|
|
ea64 = options[S_EA64]
|
|
|
|
with_hexrays = options[S_WITH_HEXRAYS]
|
|
|
|
|
2009-10-02 19:40:26 +02:00
|
|
|
global SWIG_OPTIONS
|
2009-05-23 16:40:01 +02:00
|
|
|
""" Build the plugin from the SWIG wrapper and plugin main source """
|
|
|
|
# Path to the IDA SDK headers
|
2011-10-14 16:24:38 +02:00
|
|
|
ida_include_directory = os.path.join(idasdkdir, "include")
|
2007-10-20 09:03:51 +02:00
|
|
|
|
2009-05-23 16:40:01 +02:00
|
|
|
builder = None
|
2007-10-20 09:03:51 +02:00
|
|
|
# Platform-specific settings for the Linux build
|
2009-05-23 16:40:01 +02:00
|
|
|
if platform == "linux":
|
2007-10-20 09:03:51 +02:00
|
|
|
builder = GCCBuilder()
|
|
|
|
platform_macros = [ "__LINUX__" ]
|
2011-10-14 16:24:38 +02:00
|
|
|
python_libpath = os.path.join(sysconfig.EXEC_PREFIX, "lib")
|
2012-06-24 22:49:11 +02:00
|
|
|
python_library = "-Bdynamic -lpython%d.%d" % (PYTHON_MAJOR_VERSION, PYTHON_MINOR_VERSION)
|
2011-04-18 18:07:00 +02:00
|
|
|
ida_libpath = os.path.join(idasdkdir, "lib", ea64 and "x86_linux_gcc_64" or "x86_linux_gcc_32")
|
2007-10-20 09:03:51 +02:00
|
|
|
ida_lib = ""
|
2012-06-24 22:49:11 +02:00
|
|
|
extra_link_parameters = " -s"
|
|
|
|
builder.compiler_parameters += " -O2"
|
2007-10-20 09:03:51 +02:00
|
|
|
# Platform-specific settings for the Windows build
|
2009-10-02 19:40:26 +02:00
|
|
|
elif platform == "win32":
|
2007-10-20 09:03:51 +02:00
|
|
|
builder = MSVCBuilder()
|
|
|
|
platform_macros = [ "__NT__" ]
|
2011-10-14 16:24:38 +02:00
|
|
|
python_libpath = os.path.join(sysconfig.EXEC_PREFIX, "libs")
|
2007-10-20 09:03:51 +02:00
|
|
|
python_library = "python%d%d.lib" % (PYTHON_MAJOR_VERSION, PYTHON_MINOR_VERSION)
|
2011-04-18 18:07:00 +02:00
|
|
|
ida_libpath = os.path.join(idasdkdir, "lib", ea64 and "x86_win_vc_64" or "x86_win_vc_32")
|
2007-10-20 09:03:51 +02:00
|
|
|
ida_lib = "ida.lib"
|
2009-10-02 19:40:26 +02:00
|
|
|
SWIG_OPTIONS += " -D__NT__ "
|
2009-05-21 21:32:16 +02:00
|
|
|
extra_link_parameters = ""
|
2013-07-03 03:40:54 +02:00
|
|
|
if not options[S_NO_OPT]:
|
|
|
|
builder.compiler_parameters += " -Ox"
|
2009-05-23 16:40:01 +02:00
|
|
|
# Platform-specific settings for the Mac OS X build
|
2009-10-02 19:40:26 +02:00
|
|
|
elif platform == "macosx":
|
2007-10-20 09:03:51 +02:00
|
|
|
builder = GCCBuilder()
|
|
|
|
builder.linker_parameters = "-dynamiclib"
|
|
|
|
platform_macros = [ "__MAC__" ]
|
|
|
|
python_libpath = "."
|
|
|
|
python_library = "-framework Python"
|
2011-04-18 18:07:00 +02:00
|
|
|
ida_libpath = os.path.join(idasdkdir, "lib", ea64 and "x86_mac_gcc_64" or "x86_mac_gcc_32")
|
2009-05-23 16:40:01 +02:00
|
|
|
ida_lib = ea64 and "-lida64" or "-lida"
|
2012-06-24 22:49:11 +02:00
|
|
|
extra_link_parameters = " -s"
|
|
|
|
builder.compiler_parameters += " -O3"
|
2007-10-20 09:03:51 +02:00
|
|
|
|
2009-05-23 16:40:01 +02:00
|
|
|
assert builder, "Unknown platform! No idea how to build here..."
|
|
|
|
|
|
|
|
# Enable EA64 for the compiler if necessary
|
|
|
|
if ea64:
|
|
|
|
platform_macros.append("__EA64__")
|
2007-10-20 09:03:51 +02:00
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# Build with Hex-Rays decompiler
|
|
|
|
if with_hexrays:
|
|
|
|
platform_macros.append("WITH_HEXRAYS")
|
|
|
|
SWIG_OPTIONS += ' -DWITH_HEXRAYS '
|
|
|
|
|
2012-06-24 22:49:11 +02:00
|
|
|
platform_macros.append("NDEBUG")
|
|
|
|
|
2010-01-05 19:24:04 +01:00
|
|
|
if not '--no-early-load' in sys.argv:
|
2009-10-29 12:37:24 +01:00
|
|
|
platform_macros.append("PLUGINFIX")
|
|
|
|
|
2013-06-28 03:32:56 +02:00
|
|
|
# Turn off obsolete functions
|
2013-12-30 02:34:23 +01:00
|
|
|
#platform_macros.append("NO_OBSOLETE_FUNCS")
|
2013-06-28 03:32:56 +02:00
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
# Build the wrapper from the interface files
|
2009-05-23 16:40:01 +02:00
|
|
|
ea64flag = ea64 and "-D__EA64__" or ""
|
|
|
|
swigcmd = "swig %s -Iswig -o idaapi.cpp %s -I%s idaapi.i" % (SWIG_OPTIONS, ea64flag, ida_include_directory)
|
2007-10-20 09:03:51 +02:00
|
|
|
if VERBOSE: print swigcmd
|
|
|
|
res = os.system(swigcmd)
|
2009-05-23 16:40:01 +02:00
|
|
|
assert res == 0, "Failed to build the wrapper with SWIG"
|
2007-10-20 09:03:51 +02:00
|
|
|
|
|
|
|
# Compile the wrapper
|
|
|
|
res = builder.compile("idaapi",
|
|
|
|
includes=[ PYTHON_INCLUDE_DIRECTORY, ida_include_directory ],
|
|
|
|
macros=platform_macros)
|
2009-05-23 16:40:01 +02:00
|
|
|
assert res == 0, "Failed to build the wrapper module"
|
2007-10-20 09:03:51 +02:00
|
|
|
|
|
|
|
# Compile the main plugin source
|
|
|
|
res = builder.compile("python",
|
|
|
|
includes=[ PYTHON_INCLUDE_DIRECTORY, ida_include_directory ],
|
|
|
|
macros=platform_macros)
|
2009-05-23 16:40:01 +02:00
|
|
|
assert res == 0, "Failed to build the main plugin object"
|
2007-10-20 09:03:51 +02:00
|
|
|
|
|
|
|
# Link the final binary
|
|
|
|
res = builder.link( ["idaapi", "python"],
|
|
|
|
plugin_name,
|
|
|
|
[ python_libpath, ida_libpath ],
|
|
|
|
[ python_library, ida_lib ],
|
|
|
|
extra_link_parameters)
|
2009-05-23 16:40:01 +02:00
|
|
|
assert res == 0, "Failed to link the plugin binary"
|
2007-10-20 09:03:51 +02:00
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
2009-10-19 09:21:22 +02:00
|
|
|
def detect_platform(ea64):
|
2007-10-20 09:03:51 +02:00
|
|
|
# Detect the platform
|
|
|
|
system = platform.system()
|
|
|
|
|
2007-12-06 14:56:20 +01:00
|
|
|
if system == "Windows" or system == "Microsoft":
|
2009-04-26 20:36:35 +02:00
|
|
|
system = "Windows"
|
2007-10-20 09:03:51 +02:00
|
|
|
platform_string = "win32"
|
2009-05-23 16:40:01 +02:00
|
|
|
plugin_name = ea64 and "python.p64" or "python.plw"
|
2009-09-16 16:00:31 +02:00
|
|
|
|
2009-10-19 09:21:22 +02:00
|
|
|
elif system == "Linux":
|
2007-10-20 09:03:51 +02:00
|
|
|
platform_string = "linux"
|
2009-05-23 16:40:01 +02:00
|
|
|
plugin_name = ea64 and "python.plx64" or "python.plx"
|
2007-10-20 09:03:51 +02:00
|
|
|
|
2009-10-19 09:21:22 +02:00
|
|
|
elif system == "Darwin":
|
2007-10-20 09:03:51 +02:00
|
|
|
platform_string = "macosx"
|
2009-05-23 16:40:01 +02:00
|
|
|
plugin_name = ea64 and "python.pmc64" or "python.pmc"
|
2009-10-19 09:21:22 +02:00
|
|
|
else:
|
|
|
|
print "Unknown platform!"
|
|
|
|
sys.exit(-1)
|
2009-05-23 16:40:01 +02:00
|
|
|
|
2009-10-19 09:21:22 +02:00
|
|
|
return (system, platform_string, plugin_name)
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
def build_binary_package(options, nukeold):
|
|
|
|
ea64 = options[S_EA64]
|
2009-10-19 09:21:22 +02:00
|
|
|
system, platform_string, plugin_name = detect_platform(ea64)
|
2009-09-16 16:00:31 +02:00
|
|
|
BINDISTDIR = "idapython-%d.%d.%d_ida%d.%d_py%d.%d_%s" % (VERSION_MAJOR,
|
|
|
|
VERSION_MINOR,
|
|
|
|
VERSION_PATCH,
|
|
|
|
IDA_MAJOR_VERSION,
|
2008-08-15 22:59:06 +02:00
|
|
|
IDA_MINOR_VERSION,
|
|
|
|
PYTHON_MAJOR_VERSION,
|
|
|
|
PYTHON_MINOR_VERSION,
|
|
|
|
platform_string)
|
2007-10-20 09:03:51 +02:00
|
|
|
# Build the plugin
|
2013-07-03 03:40:54 +02:00
|
|
|
build_plugin(platform_string, IDA_SDK, plugin_name, options)
|
2013-12-30 02:34:23 +01:00
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
# Build the binary distribution
|
|
|
|
binmanifest = []
|
2009-05-23 16:40:01 +02:00
|
|
|
if nukeold:
|
|
|
|
binmanifest.extend(BINDIST_MANIFEST)
|
2013-12-30 02:34:23 +01:00
|
|
|
|
2011-12-02 16:42:36 +01:00
|
|
|
if not ea64 or nukeold:
|
|
|
|
binmanifest.extend([(x, "python") for x in "python/init.py", "python/idc.py", "python/idautils.py", "idaapi.py"])
|
2013-12-30 02:34:23 +01:00
|
|
|
|
2007-10-20 09:03:51 +02:00
|
|
|
binmanifest.append((plugin_name, "plugins"))
|
2013-12-30 02:34:23 +01:00
|
|
|
|
2009-05-23 16:40:01 +02:00
|
|
|
build_distribution(binmanifest, BINDISTDIR, ea64, nukeold)
|
2007-10-20 09:03:51 +02:00
|
|
|
|
2009-05-23 16:40:01 +02:00
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
2009-05-23 16:40:01 +02:00
|
|
|
def build_source_package():
|
|
|
|
""" Build a directory and a ZIP file with all the sources """
|
2009-09-16 16:00:31 +02:00
|
|
|
SRCDISTDIR = "idapython-%d.%d.%d" % (VERSION_MAJOR,
|
|
|
|
VERSION_MINOR,
|
|
|
|
VERSION_PATCH)
|
2009-05-23 16:40:01 +02:00
|
|
|
# Build the source distribution
|
2007-10-20 09:03:51 +02:00
|
|
|
srcmanifest = []
|
|
|
|
srcmanifest.extend(BINDIST_MANIFEST)
|
|
|
|
srcmanifest.extend(SRCDIST_MANIFEST)
|
2009-05-23 16:40:01 +02:00
|
|
|
srcmanifest.extend([(x, "python") for x in "python/init.py", "python/idc.py", "python/idautils.py"])
|
|
|
|
build_distribution(srcmanifest, SRCDISTDIR, ea64=False, nukeold=True)
|
2007-10-20 09:03:51 +02:00
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
2010-06-28 14:36:40 +02:00
|
|
|
def gen_docs(z = False):
|
|
|
|
print "Generating documentation....."
|
|
|
|
old_dir = os.getcwd()
|
|
|
|
try:
|
|
|
|
curdir = os.getcwd() + os.sep
|
|
|
|
docdir = 'idapython-reference-%d.%d.%d' % (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
|
|
|
|
sys.path.append(curdir + 'python')
|
|
|
|
sys.path.append(curdir + 'tools')
|
|
|
|
sys.path.append(curdir + 'docs')
|
|
|
|
import epydoc.cli
|
|
|
|
import swigdocs
|
|
|
|
os.chdir('docs')
|
|
|
|
PYWRAPS_FN = 'pywraps'
|
|
|
|
swigdocs.gen_docs(outfn = PYWRAPS_FN + '.py')
|
|
|
|
epydoc.cli.optparse.sys.argv = [ 'epydoc',
|
|
|
|
'--no-sourcecode',
|
|
|
|
'-u', 'http://code.google.com/p/idapython/',
|
|
|
|
'--navlink', '<a href="http://www.hex-rays.com/idapro/idapython_docs/">IDAPython Reference</a>',
|
|
|
|
'--no-private',
|
|
|
|
'--simple-term',
|
|
|
|
'-o', docdir,
|
|
|
|
'--html',
|
|
|
|
'idc', 'idautils', PYWRAPS_FN, 'idaapi']
|
|
|
|
# Generate the documentation
|
|
|
|
epydoc.cli.cli()
|
|
|
|
|
|
|
|
print "Documentation generated!"
|
|
|
|
|
|
|
|
# Clean temp files
|
|
|
|
for f in [PYWRAPS_FN + '.py', PYWRAPS_FN + '.pyc']:
|
|
|
|
if os.path.exists(f):
|
|
|
|
os.unlink(f)
|
|
|
|
|
|
|
|
if z:
|
|
|
|
z = docdir + '-doc.zip'
|
|
|
|
zip = zipfile.ZipFile(z, "w", zipfile.ZIP_DEFLATED)
|
|
|
|
for fn in glob.glob(docdir + os.sep + '*'):
|
|
|
|
zip.write(fn)
|
|
|
|
zip.close()
|
|
|
|
print "Documentation compressed to", z
|
|
|
|
except Exception, e:
|
|
|
|
print 'Failed to generate documentation:', e
|
|
|
|
finally:
|
|
|
|
os.chdir(old_dir)
|
|
|
|
return
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
2010-06-28 14:36:40 +02:00
|
|
|
def usage():
|
|
|
|
print """IDAPython build script.
|
|
|
|
|
|
|
|
Available switches:
|
|
|
|
--doc:
|
|
|
|
Generate documentation into the 'docs' directory
|
|
|
|
--zip:
|
|
|
|
Used with '--doc' switch. It will compress the generated documentation
|
|
|
|
--ea64:
|
|
|
|
Builds also the 64bit version of the plugin
|
2013-07-03 03:40:54 +02:00
|
|
|
--with-hexrays:
|
|
|
|
Build with the Hex-Rays Decompiler wrappings
|
2010-06-28 14:36:40 +02:00
|
|
|
--no-early-load:
|
|
|
|
The plugin will be compiled as normal plugin
|
|
|
|
This switch disables processor, plugin and loader scripts
|
|
|
|
"""
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
2009-10-19 09:21:22 +02:00
|
|
|
def main():
|
2010-06-28 14:36:40 +02:00
|
|
|
if '--help' in sys.argv:
|
|
|
|
return usage()
|
|
|
|
elif '--doc' in sys.argv:
|
|
|
|
return gen_docs(z = '--zip' in sys.argv)
|
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# Parse options
|
|
|
|
options = parse_options(sys.argv)
|
|
|
|
ea64 = options[S_EA64]
|
|
|
|
|
|
|
|
# Always build the non __EA64__ version
|
|
|
|
options[S_EA64] = False
|
|
|
|
build_binary_package(options, nukeold=True)
|
|
|
|
|
|
|
|
# Rebuild package with __EA64__ if needed
|
2009-05-23 18:55:49 +02:00
|
|
|
if ea64:
|
2013-07-03 03:40:54 +02:00
|
|
|
options[S_EA64] = True
|
|
|
|
build_binary_package(options, nukeold=False)
|
|
|
|
|
|
|
|
# Always build the source package
|
2009-05-23 16:40:01 +02:00
|
|
|
build_source_package()
|
2009-10-19 09:21:22 +02:00
|
|
|
|
2013-07-03 03:40:54 +02:00
|
|
|
# -----------------------------------------------------------------------
|
2009-10-19 09:21:22 +02:00
|
|
|
if __name__ == "__main__":
|
2013-03-08 20:33:51 +01:00
|
|
|
main()
|