Skip to content

Commit

Permalink
Updated hexagon module for IDAPro v7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nlitsme committed Dec 6, 2017
1 parent ead9f96 commit 6d5a8bd
Show file tree
Hide file tree
Showing 7 changed files with 3,697 additions and 826 deletions.
51 changes: 23 additions & 28 deletions Makefile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,58 @@ all:
# I put some not yet published targets in this optional include
-include Makefile.extra

CXX=clang++
CC=clang
LD=clang++
#CXX=clang++-5.0
#CC=clang-5.0
#LD=clang++-5.0

TARGETS+=hexagon.ilx
TARGETS+=hexagon.so

# where the quicinc objdump source can be found
gnutools= hx/sourceryg++-2012.03-151-hexagon/binutils-hexagon-2012.03

gnutoolsincludes=-I $(gnutools)/include -I $(gnutools)/bfd -I $(gnutools)/include/opcode
gnutoolsincludes+=-I ./build-mac/opcodes -I ./build-mac/bfd
CFLAGS=-g -D__MAC__ -D__IDP__ -I $(idasdk)/include
CFLAGS=-g -D__LINUX__ -D__IDP__ -D__X64__ -I $(idasdk)/include
CFLAGS+=-DUSE_STANDARD_FILE_FUNCTIONS
CFLAGS+=-DUSE_DANGEROUS_FUNCTIONS
CFLAGS+=-D_FORTIFY_SOURCE=0
CFLAGS+=-O0 -g -fpic
CFLAGS+=-fPIC
CFLAGS+=-g $(if $(D),-O0,-O2)

# add this flag when you want verbose logging
#CFLAGS+=-DTRACELOG

all: $(TARGETS)

hexagon.ilx: hexagon.o32 gt_safe-ctype.o32 gt_hexagon-dis.o32 gt_hexagon-opc.o32 gt_hexagon-isa.o32 bfd_funcs.o32 gt_cpu-hexagon.o32 dummy-scan.o32
hexagon.so: hexagon.o gt_safe-ctype.o gt_hexagon-dis.o gt_hexagon-opc.o gt_hexagon-isa.o bfd_funcs.o gt_cpu-hexagon.o dummy-scan.o

cflags_cpu-hexagon= $(gnutoolsincludes)
cflags_hexagon= $(gnutoolsincludes)
cflags_bfd_funcs= $(gnutoolsincludes)

install: hexagon.ilx
install: hexagon.so
cp $^ "$(idabin)/procs"

clean:
$(RM) $(TARGETS) $(wildcard *.o) $(wildcard *.o32)

$(RM) $(TARGETS) $(wildcard *.o) $(wildcard *.o)

%.o32: %.cpp
$(CXX) -m32 -std=c++11 -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(CFLAGS)
%.o32: %.c
$(CC) -m32 -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(CFLAGS)

gt_%.o32: $(gnutools)/libiberty/%.c
$(CC) -m32 -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)
%.o: %.cpp
$(CXX) -std=c++1z -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(CFLAGS)
%.o: %.c
$(CC) -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(CFLAGS)

gt_%.o32: $(gnutools)/opcodes/%.c
$(CC) -m32 -c -Wstrict-prototypes -Wmissing-prototypes -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)
gt_%.o: $(gnutools)/libiberty/%.c
$(CC) -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)

gt_%.o32: $(gnutools)/bfd/%.c
$(CC) -m32 -c -Wstrict-prototypes -Wmissing-prototypes -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)
gt_%.o: $(gnutools)/opcodes/%.c
$(CC) -c -Wstrict-prototypes -Wmissing-prototypes -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)

%.o32: %.s
$(CXX) -c -m32 -o$@ $^
gt_%.o: $(gnutools)/bfd/%.c
$(CC) -c -Wstrict-prototypes -Wmissing-prototypes -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)

%.ilx: %.o32
$(LD) -shared -m32 -o $@ $^ "$(idabin)/libida.so"
%.so: %.o
$(CXX) -shared -o $@ $^ -L$(idabin) -lida

%: %.o
$(CXX) -g -o $@ $^

%32: %.o32
$(CXX) -m32 -g -o $@ $^

65 changes: 36 additions & 29 deletions Makefile.osx
Original file line number Diff line number Diff line change
@@ -1,67 +1,74 @@
include ../idacfg.mk
IDAVER=7

ifeq ($(IDAVER),6)
IMCEXT=.imc
ARCHFLAGS=-m32
endif

ifeq ($(IDAVER),7)
IMCEXT=.dylib
ARCHFLAGS=-m64 -D__X64__
endif


all:

# I put some not yet published targets in this optional include
-include Makefile.extra
#-include Makefile.extra

CXX=clang++
CC=clang
LD=clang++

TARGETS+=hexagon.imc
TARGETS+=hexagon$(IMCEXT)

# where the quicinc objdump source can be found
gnutools= hx/sourceryg++-2012.03-151-hexagon/binutils-hexagon-2012.03
gnutools=hx/sourceryg++-2012.03-151-hexagon/binutils-hexagon-2012.03

gnutoolsincludes=-I $(gnutools)/include -I $(gnutools)/bfd -I $(gnutools)/include/opcode
gnutoolsincludes+=-I ./build-mac/opcodes -I ./build-mac/bfd
CFLAGS=-g -D__MAC__ -D__IDP__ -I $(idasdk)/include
CFLAGS=-D__MAC__ -D__IDP__ -I $(idasdk)/include
CFLAGS+=-DUSE_STANDARD_FILE_FUNCTIONS
CFLAGS+=-DUSE_DANGEROUS_FUNCTIONS
CFLAGS+=-D_FORTIFY_SOURCE=0
CFLAGS+=-O0 -g
CFLAGS+=-g $(if $(D),-O0,-O2)
LDFLAGS+=-g

# add this flag when you want verbose logging
#CFLAGS+=-DTRACELOG
CFLAGS+=$(if $(LOG),-DTRACELOG)

all: $(TARGETS)

hexagon.imc: hexagon.o32 gt_safe-ctype.o32 gt_hexagon-dis.o32 gt_hexagon-opc.o32 gt_hexagon-isa.o32 bfd_funcs.o32 gt_cpu-hexagon.o32 dummy-scan.o32
hexagon$(IMCEXT): hexagon.obj gt_safe-ctype.obj gt_hexagon-dis.obj gt_hexagon-opc.obj gt_hexagon-isa.obj bfd_funcs.obj gt_cpu-hexagon.obj dummy-scan.obj
$(LD) $(LDFLAGS) -dynamiclib $(ARCHFLAGS) -o $@ $^ "$(idabin)/libida.dylib"

cflags_cpu-hexagon= $(gnutoolsincludes)
cflags_hexagon= $(gnutoolsincludes)
cflags_bfd_funcs= $(gnutoolsincludes)

install: hexagon.imc
install: hexagon$(IMCEXT)
cp $^ "$(idabin)/procs"

clean:
$(RM) $(TARGETS) $(wildcard *.o) $(wildcard *.o32)


%.o32: %.cpp
$(CXX) -m32 -std=c++11 -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(CFLAGS)
%.o32: %.c
$(CC) -m32 -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(CFLAGS)
$(RM) $(TARGETS) $(wildcard *.obj)

gt_%.o32: $(gnutools)/libiberty/%.c
$(CC) -m32 -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)

gt_%.o32: $(gnutools)/opcodes/%.c
$(CC) -m32 -c -Wstrict-prototypes -Wmissing-prototypes -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)
%.obj: %.cpp
$(CXX) $(ARCHFLAGS) -std=c++1z -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(CFLAGS)
%.obj: %.c
$(CC) $(ARCHFLAGS) -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(CFLAGS)

gt_%.o32: $(gnutools)/bfd/%.c
$(CC) -m32 -c -Wstrict-prototypes -Wmissing-prototypes -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)
gt_%.obj: $(gnutools)/libiberty/%.c
$(CC) $(ARCHFLAGS) -c -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)

%.o32: %.s
$(CXX) -c -m32 -o$@ $^
gt_%.obj: $(gnutools)/opcodes/%.c
$(CC) $(ARCHFLAGS) -c -Wstrict-prototypes -Wmissing-prototypes -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)

%.imc: %.o32
$(LD) -dynamiclib -m32 -o $@ $^ "$(idabin)/libida.dylib"
gt_%.obj: $(gnutools)/bfd/%.c
$(CC) $(ARCHFLAGS) -c -Wstrict-prototypes -Wmissing-prototypes -o$@ $^ $(cflags_$(basename $(notdir $@))) $(gnutoolsincludes) $(CFLAGS)

%: %.o
$(CXX) -g -o $@ $^
%.obj: %.s
$(CXX) -c $(ARCHFLAGS) -o$@ $^

%32: %.o32
$(CXX) -m32 -g -o $@ $^

29 changes: 11 additions & 18 deletions Makefile.w32
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@ include ../idacfg.mk

all:

#vc=c:/Program Files/Microsoft Visual Studio 8/VC
#winsdk=$(vc)/platformsdk
vc=c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC
winsdk=C:/Program Files (x86)/Windows Kits/10
CXX=$(vc)/bin/cl.exe
CC=$(vc)/bin/cl.exe
LD=$(vc)/bin/link.exe
CXX=cl.exe
CC=cl.exe
LD=link.exe

TARGETS+=hexagon.w32
TARGETS+=hexagon.dll

# where the quicinc objdump source can be found
gnutools= hx/sourceryg++-2012.03-151-hexagon/binutils-hexagon-2012.03

gnutoolsincludes=-I $(gnutools)/include -I $(gnutools)/bfd -I $(gnutools)/include/opcode
gnutoolsincludes+=-I build-win/opcodes -I build-win/bfd
CFLAGS=-EHsc -GR -Gz -nologo -Zi -D__NT__ -D__IDP__ -I $(idasdk)/include -I $(BOOST)
CFLAGS+=-I "$(vc)/include" -I "$(winsdk)/include" -D_WIN32 -DWIN32 -D_USRDLL -DMAXSTR=1024
CFLAGS+=-O2
CFLAGS=-EHsc -GR -Gz -nologo -Zi -D__NT__ -D__X64__ -D__IDP__ -I $(idasdk)/include
CFLAGS+=-D_WIN32 -DWIN32 -D_USRDLL -DMAXSTR=1024
CFLAGS+=-O2 -std:c++17

LDLIBS=$(idasdk)/lib/x86_win_vc_32/ida.lib
LDLIBS+=-libpath:"$(vc)/lib" -libpath:"$(winsdk)/lib"
LDLIBS=$(idasdk)/lib/x64_win_vc_32/ida.lib
LDFLAGS=-debug -nologo -dll -export:LPH -stub:$(idasdk)/module/stub


Expand All @@ -31,19 +26,17 @@ LDFLAGS=-debug -nologo -dll -export:LPH -stub:$(idasdk)/module/stub

all: $(TARGETS)

hexagon.w32: hexagon.obj gt_safe-ctype.obj gt_hexagon-dis.obj gt_hexagon-opc.obj bfd_funcs.obj gt_hexagon-isa.obj gt_cpu-hexagon.obj dummy-scan.obj
hexagon.dll: hexagon.obj gt_safe-ctype.obj gt_hexagon-dis.obj gt_hexagon-opc.obj bfd_funcs.obj gt_hexagon-isa.obj gt_cpu-hexagon.obj dummy-scan.obj
cflags_hexagon= $(gnutoolsincludes)
cflags_bfd_funcs= $(gnutoolsincludes)

install: hexagon.w32
install: hexagon.dll
cp $^ "$(idabin)/procs"

clean:
$(RM) $(TARGETS) $(wildcard *.obj) $(GENERATEDFILES) hexagon.exp hexagon.ilk hexagon.lib hexagon.pdb vc140.pdb




%.obj: %.cpp
"$(CXX)" -c -Fo$@ $^ $(cflags_$(basename $(notdir $@))) $(CFLAGS) $(CXXFLAGS)
%.obj: %.c
Expand All @@ -61,6 +54,6 @@ gt_%.obj: $(gnutools)/bfd/%.c
%.obj: %.s
"$(CXX)" -c -Fo$@ $^

%.w32: %.obj
%.dll: %.obj
"$(LD)" $(LDFLAGS) -out:$@ $^ $(LDLIBS)

43 changes: 33 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ or Galaxy S5 ( SM-G900F )
Several versions of the programmers reference manual can be found online:
* [80-NB419-1 Rev. A Hexagon V2 Programmer’s Reference Manual](https://developer.qualcomm.com/download/80-nb419-1ahexagonv2programmersref.pdf)
* 80-N2040-9 Rev. A Hexagon V4 Programmer’s Reference Manual
* 80-N2040-8 Rev. A Hexagon V5/V55 Programmer’s Reference Manual
* 80-N2040-8 Rev. H Hexagon V5/V55 Programmer’s Reference Manual
* both the v4 and v5 refman can be found in this [zip](https://developer.qualcomm.com/download/hexagon/hexagon-sdk-programmers-reference.zip)
* 80-N2040-9 Rev. F Hexagon V5x Programmer’s Reference Manual
* 80-N2040-33 Rev. B Hexagon V6x Programmer’s Reference Manual
* both the v5.x and v6.x refman can be found in the Hexagon LLVM Tools 7.2.x Document Bundle, which is installed as part of the [Add-On for HVX](https://developer.qualcomm.com/download/hexagon/hexagon-sdk-addon-hvx-linux.bin)
* 80-N2040-33 Rev. D Hexagon V6x Programmer’s Reference Manual
* both the v5.x and v6.x refman can be found in the Hexagon LLVM Tools 8.0 Document Bundle, which is installed as part of the [Hexagon SDK](https://developer.qualcomm.com/download/hexagon/)
* 80-N2040-30 Rev B Hexagon V60 HVX Programmer's Reference Manual
* 80-N2040-37 Rev A Hexagon V62 HVX Programmer's Reference Manual
* 80-N2040-36 Rev B Hexagon V62 Programmer's Reference Manual

check out https://developer.qualcomm.com/hexagon-processor for updates from qualcomm.

Expand All @@ -38,15 +41,16 @@ Binary download
-------

Binaries for OSX, Linux and Windows can be found under [releases](https://github.com/gsmk/hexagon/releases):
* [OS X](https://github.com/gsmk/hexagon/releases/download/v1.1/hexagon.imc)
* [Linux](https://github.com/gsmk/hexagon/releases/download/v1.1/hexagon.ilx)
* [Windows](https://github.com/gsmk/hexagon/releases/download/v1.1/hexagon.w32)
* [OS X](https://github.com/gsmk/hexagon/releases/download/v1.2/hexagon.dylib)
* [Windows](https://github.com/gsmk/hexagon/releases/download/v1.2/hexagon.dll)
* [Linux](https://github.com/gsmk/hexagon/releases/download/v1.2/hexagon.so)


Installation
-------

Copy the hexagon.{imc,w32,ilx} file to the procs subdirectory of your IDA installation.
This module can also be used with the [IDA 6.8 Evaluation](https://www.hex-rays.com/products/ida/support/download_demo.shtml) version.
Copy the hexagon.{dylib,dll,so} file to the procs subdirectory of your IDA installation.
This module can probably also be used with the [IDA Evaluation](https://www.hex-rays.com/products/ida/support/download_demo.shtml) version.


Usage
Expand All @@ -64,15 +68,19 @@ Compiling

Separate makefiles exist for OSX (Makefile.osx), Windows (Makefile.w32) and Linux (Makefile.linux).

You need the [IDASDK](https://www.hex-rays.com/products/ida/support/ida/idasdk69.zip) ( Password protected ).
You need the [IDASDK](https://www.hex-rays.com/products/ida/support/ida/idasdk70.zip) ( Password protected ).
The sourcery hexagon gnutools, install them in a subdirectory named `hx/sourceryg++-2012.03-151-hexagon/binutils-hexagon-2012.03`.
You need a c++11 compiler, like visualstudio 2015, or any recent gcc or clang.
You need a c++17 compiler, like visualstudio 2017, or any recent gcc or clang.

Create a `idacfg.mk` file, containing the following variables:

* `idasdk`, pointing to your IDASDK directory
* `idabin`, pointing to your IDA binaries directory

On windows, first run the following command, to setup the right visualstudio environment.

vsdevcmd -arch=amd64

Bugs
-------

Expand All @@ -83,6 +91,16 @@ Bugs
* Indirect jumps and calls are not yet marked as such
* basic block ends are not correct in graph view
* processor type is fixed to v5.5
* module may crash when encountering some invalid instructions ( lumia 820 modem )
* 'loop' instruction should have a code xref, instead of a data xref.


Other Hexagon Processor modules
===============================

* [nogaxeh](https://github.com/ANSSI-FR/nogaxeh)
* [hexag00n](https://github.com/programa-stic/hexag00n)


Author
=======
Expand All @@ -93,6 +111,11 @@ History
-------
2013-06-10 version 1.0
2016-02-01 version 1.1
2017-12-05 version 1.2 - for idapro v7

* fixed incorrect code ref from `memw` instruction
* fixed incorrect label for some `jump` instructions
* now using changed plugin architecture for IDA7.

License
-------
Expand Down
Loading

0 comments on commit 6d5a8bd

Please sign in to comment.