Skip to content

Commit

Permalink
ida9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
srgblv committed Oct 10, 2024
1 parent 45e36c1 commit 491f0e8
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 30 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ cd src
git clone https://github.com/abdes/cryptopp-cmake
```

* Copy `IDA_DIR/plugins/hexrays_sdk/include/hexrays.hpp` file to the `include` directory of the IDA SDK.
* Copy `IDA_DIR/plugins/hexrays_sdk/include/hexrays.hpp` file to the `include` directory of the IDA SDK. (Not necessary for IDA 9.0)
* Edit `hrtng/src/CMakeLists.txt` file to set correct path and version of used IDA SDK. To build later with another SDK version you may change cmake's `IDASDK_VER` variable with using `cmake -D`, `ccmake` or `cmake-gui` tools.
* Create build directory, go into it, configure and build cmake project
```
Expand Down
13 changes: 11 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.9)
project(hrtng)

#run ccmake to change IDASDK_VER
SET(IDASDK_VER "_pro84" CACHE STRING "_pro84" )
SET(IDASDK_VER "90" CACHE STRING "90" )
SET(IDASDK_DIR ${CMAKE_SOURCE_DIR}/../../idasdk${IDASDK_VER})
MESSAGE("${PROJECT_NAME}")
MESSAGE("Using IDA SDK dir: ${IDASDK_DIR}")
MESSAGE("-------------------")

IF (${IDASDK_VER} STREQUAL "90")
SET(UNI64 1)
ELSE()
SET(UNI64 0)
ENDIF ()

IF( NOT CMAKE_BUILD_TYPE )
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
ENDIF()
Expand Down Expand Up @@ -43,5 +49,8 @@ endif()
set(CRYPTOPP_BUILD_TESTING OFF CACHE BOOL "Build library tests")
add_subdirectory(cryptopp-cmake)
INCLUDE_DIRECTORIES(${cryptopp_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(hrtng_64 cryptopp)

IF(NOT ${UNI64})
TARGET_LINK_LIBRARIES(hrtng_64 cryptopp)
ENDIF()
TARGET_LINK_LIBRARIES(hrtng cryptopp)
16 changes: 16 additions & 0 deletions src/comhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ struct ida_local guid_ex_t {

qvector<guid_ex_t> guids;

#if IDA_SDK_VERSION < 900
const char * idaapi read_ioports_cb(const ioports_t &ports, const char *line)
#else //IDA_SDK_VERSION >= 900
struct read_ioports_cb_t : public ioports_fallback_t
{
virtual bool handle(qstring *errbuf, const ioports_t &ports, const char *line)
#endif //IDA_SDK_VERSION < 900
{
guid_ex_t guid;
uint32 d5[6];
Expand All @@ -101,8 +107,14 @@ const char * idaapi read_ioports_cb(const ioports_t &ports, const char *line)
guid.uid.u.m1.d4 = swap16(guid.uid.u.m1.d4);
guid.name = name;
guids.push_back(guid);
#if IDA_SDK_VERSION < 900
return NULL;
}
#else //IDA_SDK_VERSION >= 900
return true;
}
};
#endif //IDA_SDK_VERSION < 900

static bool bImported = false;
void com_init()
Expand All @@ -111,6 +123,10 @@ void com_init()
return;
ioports_t ioports;
qstring device;
#if IDA_SDK_VERSION >= 900
read_ioports_cb_t riopcb;
read_ioports_cb_t *read_ioports_cb = &riopcb;
#endif //IDA_SDK_VERSION >= 900
read_ioports(&ioports, &device, "clsid.cfg", read_ioports_cb);

if (!bImported) {
Expand Down
2 changes: 1 addition & 1 deletion src/deinline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ struct ida_local sBBGrpMatcher {
bool replaceInlines(mbl_array_t *mba)
{
bool cm_changed = false;
cm_changed = mba->combine_blocks();// does not work
cm_changed = mba->merge_blocks();// does not work
mba->dump_mba(false, "[hrt] before replaceInlines");
std::set<mblock_t *> removeBlocks;
bbs_t processedBBs;
Expand Down
1 change: 1 addition & 0 deletions src/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#define interactive_graph_t mutable_graph_t
#define get_named_type_tid(x) get_struc_id(x)
#define get_tid_name(x, y) get_struc_name(x, y)
#define merge_blocks combine_blocks
#endif // IDA_SDK_VERSION < 900

#if IDA_SDK_VERSION < 840
Expand Down
14 changes: 11 additions & 3 deletions src/hrtng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ void declSpoiledRegs(cfuncptr_t cfunc, func_type_data_t *fti)
// this informnation is stored in mba->procinf->sregs NOT publicly declared part of mba_t structure
// so, the only way I've found to get it - parse full mba dump
qstring s;
qstr_printer_t p(s, false, 2); // FIXME: need only second line of the dump
qstr_printer_t p(s, false, 2); // need only second line of the dump
mba->print(p); //mba->get_mblock(0)->print(p); //single block print skips header
//msg("[hrt] %a mba:\n%s\n", cfunc->entry_ea, s.c_str());

Expand All @@ -742,7 +742,15 @@ void declSpoiledRegs(cfuncptr_t cfunc, func_type_data_t *fti)
qstring sr = s.substr(srb + 11, s.find('\n', srb));
tag_remove(&sr, 1);
qstrvec_t rnames;
sr.split(&rnames, ",", SSF_DROP_EMPTY);
const char *from = sr.begin();
const char *end = sr.end();
while(from < end) {
const char *to = qstrchr(from, ',');
if(!to)
to = end;
rnames.push_back().append(from, to - from);
from = to + 1;
}
for(size_t i = 0; i < rnames.size(); i++) {
size_t dot = rnames[i].find('.');
if(dot != qstring::npos) {
Expand Down Expand Up @@ -2131,7 +2139,7 @@ ACT_DEF(searchNpatch)
#if IDA_SDK_VERSION < 900
found_ea = bin_search2(found_ea, eaEnd, key, BIN_SEARCH_CASE | BIN_SEARCH_FORWARD);
#else //IDA_SDK_VERSION >= 900
found_ea = bin_search3(found_ea, eaEnd, key, BIN_SEARCH_CASE | BIN_SEARCH_FORWARD);
found_ea = bin_search(found_ea, eaEnd, key, BIN_SEARCH_CASE | BIN_SEARCH_FORWARD);
#endif //IDA_SDK_VERSION < 900
if(found_ea == BADADDR)
break;
Expand Down
57 changes: 36 additions & 21 deletions src/ida_plugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ function (ADD_IDA_PLUGIN target_name )
INCLUDE_DIRECTORIES(${IDASDK_DIR}/include)

ADD_LIBRARY(${target_name} SHARED ${ARGN} )
ADD_LIBRARY(${target_name}_64 SHARED ${ARGN} )

#remove 'lib' prefix
SET_TARGET_PROPERTIES(${target_name} PROPERTIES PREFIX "" )
SET_TARGET_PROPERTIES(${target_name}_64 PROPERTIES PREFIX "" )

IF(NOT ${UNI64})
ADD_LIBRARY(${target_name}_64 SHARED ${ARGN} )
SET_TARGET_PROPERTIES(${target_name}_64 PROPERTIES PREFIX "" )
ENDIF()

SET(CMAKE_CXX_STANDARD 11)
SET(OPT_CXX_FLAGS "-std=c++11 -flto -fvisibility=hidden -fvisibility-inlines-hidden")
Expand All @@ -21,34 +22,48 @@ ENDIF ()

IF(MSVC)
SET(COMMON_FLAGS "${CMAKE_CXX_FLAGS} -D __NT__ ${IDA_COMMON_CXX_FLAGS} ")
SET_TARGET_PROPERTIES(${target_name} PROPERTIES COMPILE_FLAGS ${COMMON_FLAGS})
SET_TARGET_PROPERTIES(${target_name}_64 PROPERTIES COMPILE_FLAGS "${COMMON_FLAGS} -D__EA64__")
SET_TARGET_PROPERTIES(${target_name} PROPERTIES OUTPUT_NAME "${target_name}" )
SET_TARGET_PROPERTIES(${target_name}_64 PROPERTIES OUTPUT_NAME "${target_name}64" )
IF(${UNI64})
TARGET_LINK_LIBRARIES(${target_name} ${IDASDK_DIR}/lib/x64_win_vc_64${PRO}/ida.lib)
ELSE()
TARGET_LINK_LIBRARIES(${target_name} ${IDASDK_DIR}/lib/x64_win_vc_32${PRO}/ida.lib)
TARGET_LINK_LIBRARIES(${target_name}_64 ${IDASDK_DIR}/lib/x64_win_vc_64${PRO}/ida.lib)
ENDIF()
ELSEIF(APPLE)
SET(COMMON_FLAGS "${CMAKE_CXX_FLAGS} -D__MAC__ ${IDA_COMMON_CXX_FLAGS} ${OPT_CXX_FLAGS}")
SET_TARGET_PROPERTIES(${target_name} PROPERTIES COMPILE_FLAGS ${COMMON_FLAGS})
SET_TARGET_PROPERTIES(${target_name}_64 PROPERTIES COMPILE_FLAGS "${COMMON_FLAGS} -D__EA64__")
SET_TARGET_PROPERTIES(${target_name} PROPERTIES OUTPUT_NAME "${target_name}" )
SET_TARGET_PROPERTIES(${target_name}_64 PROPERTIES OUTPUT_NAME "${target_name}64" )
IF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
IF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
IF(${UNI64})
TARGET_LINK_LIBRARIES(${target_name} ${IDASDK_DIR}/lib/arm64_mac_clang_64${PRO}/libida.dylib -s -flto)
ELSE()
TARGET_LINK_LIBRARIES(${target_name} ${IDASDK_DIR}/lib/arm64_mac_clang_32${PRO}/libida.dylib -s -flto)
TARGET_LINK_LIBRARIES(${target_name}_64 ${IDASDK_DIR}/lib/arm64_mac_clang_64${PRO}/libida64.dylib -s -flto)
ELSE()
ENDIF()
ELSE()
IF(${UNI64})
TARGET_LINK_LIBRARIES(${target_name} ${IDASDK_DIR}/lib/x64_mac_clang_64${PRO}/libida.dylib -s -flto)
ELSE()
TARGET_LINK_LIBRARIES(${target_name} ${IDASDK_DIR}/lib/x64_mac_clang_32${PRO}/libida.dylib -s -flto)
TARGET_LINK_LIBRARIES(${target_name}_64 ${IDASDK_DIR}/lib/x64_mac_clang_64${PRO}/libida64.dylib -s -flto)
ENDIF()
ENDIF()
ENDIF()
ELSEIF ( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
SET(COMMON_FLAGS "${CMAKE_CXX_FLAGS} -D__LINUX__ ${IDA_COMMON_CXX_FLAGS} ${OPT_CXX_FLAGS}")
SET(GCC_LINK_FLAGS "-Wl,--version-script=${IDASDK_DIR}/plugins/exports.def -Wl,--strip-debug,--discard-all,--strip-all,--discard-locals -flto=auto")
SET_TARGET_PROPERTIES(${target_name} PROPERTIES COMPILE_FLAGS ${COMMON_FLAGS})
SET(COMMON_FLAGS "${CMAKE_CXX_FLAGS} -D__LINUX__ ${IDA_COMMON_CXX_FLAGS} ${OPT_CXX_FLAGS}")
SET(GCC_LINK_FLAGS "-Wl,--version-script=${IDASDK_DIR}/plugins/exports.def -Wl,--strip-debug,--discard-all,--strip-all,--discard-locals -flto=auto")
IF(${UNI64})
TARGET_LINK_LIBRARIES(${target_name} ${IDASDK_DIR}/lib/x64_linux_gcc_64/libida.so ${OPT_CXX_FLAGS} ${GCC_LINK_FLAGS})
ELSE()
TARGET_LINK_LIBRARIES(${target_name} ${IDASDK_DIR}/lib/x64_linux_gcc_32${PRO}/libida.so ${OPT_CXX_FLAGS} ${GCC_LINK_FLAGS})
TARGET_LINK_LIBRARIES(${target_name}_64 ${IDASDK_DIR}/lib/x64_linux_gcc_64${PRO}/libida64.so ${OPT_CXX_FLAGS} ${GCC_LINK_FLAGS})
ENDIF()
ENDIF ()

IF(${UNI64})
SET_TARGET_PROPERTIES(${target_name} PROPERTIES COMPILE_FLAGS "${COMMON_FLAGS} -D__EA64__")
SET_TARGET_PROPERTIES(${target_name} PROPERTIES OUTPUT_NAME "${target_name}" )
ELSE()
SET_TARGET_PROPERTIES(${target_name} PROPERTIES COMPILE_FLAGS ${COMMON_FLAGS})
SET_TARGET_PROPERTIES(${target_name}_64 PROPERTIES COMPILE_FLAGS "${COMMON_FLAGS} -D__EA64__")
SET_TARGET_PROPERTIES(${target_name} PROPERTIES OUTPUT_NAME "${target_name}" )
SET_TARGET_PROPERTIES(${target_name}_64 PROPERTIES OUTPUT_NAME "${target_name}64" )
TARGET_LINK_LIBRARIES(${target_name} ${IDASDK_DIR}/lib/x64_linux_gcc_32${PRO}/libida.so ${OPT_CXX_FLAGS} ${GCC_LINK_FLAGS})
TARGET_LINK_LIBRARIES(${target_name}_64 ${IDASDK_DIR}/lib/x64_linux_gcc_64${PRO}/libida64.so ${OPT_CXX_FLAGS} ${GCC_LINK_FLAGS})
ENDIF ()
ENDIF()

endfunction()
4 changes: 2 additions & 2 deletions src/unflat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,8 +1054,8 @@ bool RemoveSingleGotos(mbl_array_t* mba)
mba->dump_mba(true, "[hrt] after RemoveSingleGotos");
#else
mba->dump_mba(true, "[hrt] after RemoveSingleGotos");
// combine_blocks or remove_empty_and_unreachable_blocks produce itsown dumps
mba->combine_blocks(); //mba->remove_empty_and_unreachable_blocks();
// merge_blocks (combine_blocks) or remove_empty_and_unreachable_blocks produce itsown dumps
mba->merge_blocks(); //mba->remove_empty_and_unreachable_blocks();
#endif //IDA_SDK_VERSION < 760
}
return iRetVal != 0;
Expand Down

0 comments on commit 491f0e8

Please sign in to comment.