Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cseagle committed Nov 30, 2019
0 parents commit aaffd3c
Show file tree
Hide file tree
Showing 204 changed files with 125,935 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# backup files
*.bak

# build residue
/.vs/*
/x86/*
/obj32/*
/obj64/*
/bin/*

# Compiled Object files
*.slo
*.lo

# Object files
*.o
*.ko
*.obj
*.elf

# Libraries
*.lai
*.la
*.lib
*.a

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Chris Eagle, cseagle at gmail d0t com
317 changes: 317 additions & 0 deletions COPYING

Large diffs are not rendered by default.

339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

146 changes: 146 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#Set this variable to point to your SDK directory
IDA_SDK=../../

SDKVER=$(shell pwd | grep -o -E "idasdk[0-9]{2,3}" | cut -c 7-)
IDAVER=$(shell pwd | grep -o -E "idasdk[0-9]{2,3}" | cut -c 7- | sed 's/\(.\)\(.\)/\1\.\2/')
IDAVER_MAJOR=$(shell pwd | grep -o -E "idasdk[0-9]{2,3}" | cut -c 7)

PLATFORM=$(shell uname | cut -f 1 -d _)

#Set this variable to the desired name of your compiled plugin
PROC=blc

ifeq "$(PLATFORM)" "Linux"
IDA=/opt/ida-$(IDAVER)
HAVE_IDA64=$(shell if [ -f $(IDA)/libida64.so ]; then echo -n yes; fi)
PLATFORM_CFLAGS=-D__LINUX__ -D__UNIX__
PLATFORM_LDFLAGS=-shared -s
IDADIR=-L$(IDA)

ifeq "$(IDAVER_MAJOR)" "6"
PLUGIN_EXT32=.plx
PLUGIN_EXT64=.plx64
else
PLUGIN_EXT32=.so
PLUGIN_EXT64=64.so
endif

IDALIB32=-lida
IDALIB64=-lida64

else ifeq "$(PLATFORM)" "Darwin"

IDAHOME=/Applications/IDA Pro $(IDAVER)

ifeq "$(IDAVER_MAJOR)" "6"
IDA=$(shell dirname "`find "$(IDAHOME)" -name idaq | tail -n 1`")
PLUGIN_EXT32=.pmc
PLUGIN_EXT64=.pmc64
else
IDA=$(shell dirname "`find "$(IDAHOME)" -name ida | tail -n 1`")
PLUGIN_EXT32=.dylib
PLUGIN_EXT64=64.dylib
endif

HAVE_IDA64=$(shell find "$(IDA)" -name libida64.dylib -exec echo -n yes \;)
PLATFORM_CFLAGS=-D__MAC__ -D__UNIX__
PLATFORM_LDFLAGS=-dynamiclib
IDADIR=-L"$(IDA)"

IDALIB32=-lida
IDALIB64=-lida64
endif

ifeq "$(IDAVER_MAJOR)" "6"
CFLAGS=-Wextra -Os $(PLATFORM_CFLAGS) -m32 -fPIC
LDFLAGS=$(PLATFORM_LDFLAGS) -m32
else
CFLAGS=-Wextra -Os $(PLATFORM_CFLAGS) -D__X64__ -m64 -fPIC
LDFLAGS=$(PLATFORM_LDFLAGS) -m64
endif

ifeq ($(shell test $(SDKVER) -gt 72; echo $$?),0)
CFLAGS+= -std=c++11
endif

# Destination directory for compiled plugins
OUTDIR=./bin/

OBJDIR32=obj32
OBJDIR64=obj64

SRCS=action.cc address.cc architecture.cc ast.cc \
block.cc blockaction.cc capability.cc cast.cc \
comment.cc condexe.cc context.cc coreaction.cc \
cover.cc cpool.cc crc32.cc database.cc double.cc \
dynamic.cc emulate.cc emulateutil.cc filemanage.cc \
float.cc flow.cc fspec.cc funcdata.cc funcdata_block.cc \
funcdata_op.cc funcdata_varnode.cc globalcontext.cc \
graph.cc heritage.cc ida_arch.cc ida_load_image.cc \
ida_scope.cc inject_sleigh.cc jumptable.cc libdecomp.cc \
loadimage.cc memstate.cc merge.cc op.cc opbehavior.cc \
opcodes.cc options.cc override.cc paramid.cc \
pcodecompile.cc pcodeinject.cc pcodeparse.tab.cc \
pcoderaw.cc plugin.cc prefersplit.cc prettyprint.cc \
printc.cc printjava.cc printlanguage.cc rangeutil.cc \
ruleaction.cc run.cc semantics.cc sleigh.cc \
sleigh_arch.cc sleighbase.cc slghpatexpress.cc \
slghpattern.cc slghsymbol.cc space.cc subflow.cc \
translate.cc type.cc typeop.cc userop.cc variable.cc \
varmap.cc varnode.cc xml.tab.cc

OBJS32 := $(patsubst %.cc, $(OBJDIR32)/%.o, $(SRCS) )
OBJS64 := $(patsubst %.cc, $(OBJDIR64)/%.o, $(SRCS) )

BINARY32=$(OUTDIR)$(PROC)$(PLUGIN_EXT32)
BINARY64=$(OUTDIR)$(PROC)$(PLUGIN_EXT64)

ifdef HAVE_IDA64

all: $(OUTDIR) $(BINARY32) $(BINARY64)

clean:
-@rm $(OBJS32)
-@rm $(OBJS64)
-@rm $(BINARY32)
-@rm $(BINARY64)

else

all: $(OUTDIR) $(BINARY32)

clean:
-@rm $(OBJS32)
-@rm $(BINARY32)

endif

$(OUTDIR):
-@mkdir -p $(OUTDIR)

$(OBJDIR32):
-@mkdir -p $(OBJDIR32)

$(OBJDIR64):
-@mkdir -p $(OBJDIR64)

CC=g++
INC=-I$(IDA_SDK)include/ -I./include/

LD=g++

$(OBJDIR32)/%.o: %.cc
$(CC) -c $(CFLAGS) $(INC) $< -o $@

$(OBJDIR64)/%.o: %.cc
$(CC) -c $(CFLAGS) $(INC) $< -o $@

$(BINARY32): $(OBJDIR32) $(OBJS32) $(SRCS)
$(LD) $(LDFLAGS) -o $@ $(CFLAGS) $(SRCS) $(INC) $(IDADIR) $(IDALIB32) $(EXTRALIBS)

ifdef HAVE_IDA64

$(BINARY64): $(OBJDIR64) $(OBJS64) $(SRCS)
$(LD) $(LDFLAGS) -o $@ -D__EA64__ $(CFLAGS) $(SRCS) $(INC) $(IDADIR) $(IDALIB64) $(EXTRALIBS)

endif
124 changes: 124 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
## WARNING: THIS CODE IS VERY RAW AND PROBABLY VERY BUGGY!

## Introduction

This is the blc (Binary Lifting Component) plugin for IDA Pro. It is the Bastard
love child of Ghidra's decompiler with Ida Pro.

The plugin integrates Ghidra's decompiler code into an Ida plugin an provides a
basic decompiler capability for all platforms support by both Ida and Ghidra. It
provides a basic source code display that attempts to mimic that of the Hex-Rays
decompiler. It has only been written with Ida 7.x in mind.

## BUILDING:

On all platforms you should clone blc into your IDA SDK's plugins sub-directory
so that you end up with `<sdkdir>/plugins/blc`. This is because the build files
all use relative paths to find necessary IDA header files and link libraries.

### Build blc for Linux / OS X:

Use the include Makefile to build the plugin. You may need to adjust the paths
that get searched to find your IDA installation (`/Applications/IDA Pro N.NN` is
assumed on OSX and `/opt/ida-N.NN` is assumed on Linux, were N.NN is derived from
the name of your IDA SDK directory eg `idasdk73` associates with `7.3` and should
match your IDA version number). This is required to successfully link the plugin.

```
$ cd <sdkdir>/plugins/blc
$ make
```

Compiled binaries will end up in `<sdkdir>/plugins/blc/bin`

```
LINUX
-------------------------------------------
| ida | ida64 |
-------------------------------------------
IDA 7.x | | |
plugin | blc.so | blc64.so |
-------------------------------------------
OS/X
-------------------------------------------
| ida | ida64 |
-------------------------------------------
IDA 7.x | | | |
plugin | blc.dylib | blc64.dylib |
-------------------------------------------
```

Copy the plugin(s) into your `<IDADIR>/plugins` directory and blc should be
listed as an available plugin for all architectures supported both Ida
and Ghidra.

### Build blc for Windows

Build with Visual Studio C++ 2017 or later using the included solution (`.sln`)
file (`blc.sln`). Two build targets are available depending on which version
of IDA you are using:

```
-----------------------------------------
| ida | ida64 |
-----------------------------------------
IDA 7.x | Release/x64 | Release64/x64 |
plugin | blc.dll | blc64.dll |
-----------------------------------------
```

Copy the plugin(s) into your `<IDADIR>/plugins` directory and blc should be
listed as an available plugin for all architectures supported by both Ida
and Ghidra.

## INSTALLATION

Assuming you have installed IDA to `<idadir>`, install the plugin by copying the
compiled binaries from `<sdkdir>/plugins/blc/bin` to `<idadir>/plugins` (Linux/Windows)
or `<idadir>/idabin/plugins` (OS X).

The plugin is dependent on Ghira processor specifications which you will need to
copy over from your own Ghidra installation. Installing Ghidra is a simple matter
of unzipping the latest Ghidra release, for example: https://ghidra-sre.org/ghidra_9.1_PUBLIC_20191023.zip
Within the extracted Ghidra foler, you will find a `Ghidra` subdirectory which,
in turn, contains a `Processors` subdirectory. The decompiler needs access to
files contained under `Ghidra/Processors`. By default the plugin looks for the
environment variable `$GHIDRA_DIR` which it expects to point at your Ghidra
installation folder such that `$GHIDRA_DIR/Ghidra/Processors` exists. If
`$GHIDRA_DIR` is not set, then the plugin expects to find `<idadir>/plugins/Ghidra/Processors`
which you may create with a symlink or by copying the approprate directories
from your Ghidra installation.

### Pre-built binaries:

As an alternative to building the plugin yourself, pre-built binaries for
IDA 7.x (Windows, Linux, OS X) are available in the `blc/bins` directory.

## USING THE PLUGIN

With the plugin installed, open a binary of interest in IDA. In order for the
plugin to be become available, the binary's architecture must be supported by
both Ida and Ghidra.

With the cursor placed inside the body of an Ida function, select
`Edit/Plugins/Ghidra Decompiler`. A successful decompilation (which may take a bit
of time, will open a new window containing the C source generated by Ghidra's
decompiler. Within the source window, you may double click on a function name to
decompile tht function. Double clicking on a global data name will navigate you
to that symbol in the Ida disassembly view. The `ESC` key will navigate back to a
previous function, or close the source viewer if there is no previous function.

The `N` hot key may be used to rename any symbol in the source view. When a symbol
in the source view corresponds to a symbol in the Ida disassembly, the symbol will
also be renamed in the disassembly.

## POTENTIAL FUTURE WORK

* Allow user to set data types for symbols in the source view
* Provide IDA derived type information to the decompiler so that it can
do a better job with things like structures and pointer dereferencing
* Better (at least some) support for string literals
* Investigate what settings/info are necessary to get this standalone decompiler
to yield results identical to Ghidra's. Is this symbol information? Type information?
arch/platform/compiler settings?
Loading

0 comments on commit aaffd3c

Please sign in to comment.