├── .gitignore ├── CMakeLists.txt ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md └── src └── lib.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .idea 3 | /idb_import_plugin.pdb 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9 FATAL_ERROR) 2 | 3 | project(idb_import_plugin) 4 | 5 | file(GLOB PLUGIN_SOURCES 6 | ${PROJECT_SOURCE_DIR}/Cargo.toml 7 | ${PROJECT_SOURCE_DIR}/src/*.rs) 8 | 9 | if(CMAKE_BUILD_TYPE MATCHES Debug) 10 | set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/debug) 11 | set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target) 12 | else() 13 | set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/release) 14 | set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target --release) 15 | endif() 16 | 17 | set(OUTPUT_FILE ${CMAKE_SHARED_LIBRARY_PREFIX}idb_import_plugin${CMAKE_SHARED_LIBRARY_SUFFIX}) 18 | set(OUTPUT_PDB ${CMAKE_SHARED_LIBRARY_PREFIX}idb_import_plugin.pdb) 19 | set(OUTPUT_PATH ${BN_CORE_PLUGIN_DIR}/${OUTPUT_FILE}) 20 | 21 | add_custom_target(idb_import_plugin ALL DEPENDS ${OUTPUT_PATH}) 22 | add_dependencies(idb_import_plugin binaryninjaapi) 23 | get_target_property(BN_API_SOURCE_DIR binaryninjaapi SOURCE_DIR) 24 | list(APPEND CMAKE_MODULE_PATH "${BN_API_SOURCE_DIR}/cmake") 25 | find_package(BinaryNinjaCore REQUIRED) 26 | 27 | # Add the whole api to the depends too 28 | file(GLOB_RECURSE API_SOURCES 29 | ${BN_API_SOURCE_DIR}/rust/src/*.rs 30 | ${BN_API_SOURCE_DIR}/rust/binaryninjacore-sys/src/*.rs) 31 | 32 | find_program(RUSTUP_PATH rustup REQUIRED HINTS ~/.cargo/bin) 33 | set(RUSTUP_COMMAND ${RUSTUP_PATH} run ${CARGO_STABLE_VERSION} cargo) 34 | 35 | if(APPLE) 36 | if(UNIVERSAL) 37 | if(CMAKE_BUILD_TYPE MATCHES Debug) 38 | set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/debug/${OUTPUT_FILE}) 39 | set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/debug/${OUTPUT_FILE}) 40 | else() 41 | set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/release/${OUTPUT_FILE}) 42 | set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release/${OUTPUT_FILE}) 43 | endif() 44 | 45 | add_custom_command( 46 | OUTPUT ${OUTPUT_PATH} 47 | COMMAND ${CMAKE_COMMAND} -E env 48 | MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BN_INSTALL_BIN_DIR} 49 | ${RUSTUP_COMMAND} clean --target=aarch64-apple-darwin ${CARGO_OPTS} 50 | COMMAND ${CMAKE_COMMAND} -E env 51 | MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BN_INSTALL_BIN_DIR} 52 | ${RUSTUP_COMMAND} clean --target=x86_64-apple-darwin ${CARGO_OPTS} 53 | COMMAND ${CMAKE_COMMAND} -E env 54 | MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BN_INSTALL_BIN_DIR} 55 | ${RUSTUP_COMMAND} build --target=aarch64-apple-darwin ${CARGO_OPTS} 56 | COMMAND ${CMAKE_COMMAND} -E env 57 | MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BN_INSTALL_BIN_DIR} 58 | ${RUSTUP_COMMAND} build --target=x86_64-apple-darwin ${CARGO_OPTS} 59 | COMMAND lipo -create ${AARCH64_LIB_PATH} ${X86_64_LIB_PATH} -output ${OUTPUT_PATH} 60 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 61 | DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES} 62 | ) 63 | else() 64 | if(CMAKE_BUILD_TYPE MATCHES Debug) 65 | set(LIB_PATH ${PROJECT_BINARY_DIR}/target/debug/${OUTPUT_FILE}) 66 | else() 67 | set(LIB_PATH ${PROJECT_BINARY_DIR}/target/release/${OUTPUT_FILE}) 68 | endif() 69 | 70 | add_custom_command( 71 | OUTPUT ${OUTPUT_PATH} 72 | COMMAND ${CMAKE_COMMAND} -E env 73 | MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BN_INSTALL_BIN_DIR} 74 | ${RUSTUP_COMMAND} clean ${CARGO_OPTS} 75 | COMMAND ${CMAKE_COMMAND} -E env 76 | MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BN_INSTALL_BIN_DIR} 77 | ${RUSTUP_COMMAND} build ${CARGO_OPTS} 78 | COMMAND ${CMAKE_COMMAND} -E copy ${LIB_PATH} ${OUTPUT_PATH} 79 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 80 | DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES} 81 | ) 82 | endif() 83 | elseif(WIN32) 84 | add_custom_command( 85 | OUTPUT ${OUTPUT_PATH} 86 | COMMAND ${CMAKE_COMMAND} -E env BINARYNINJADIR=${BN_INSTALL_BIN_DIR} ${RUSTUP_COMMAND} clean ${CARGO_OPTS} 87 | COMMAND ${CMAKE_COMMAND} -E env BINARYNINJADIR=${BN_INSTALL_BIN_DIR} ${RUSTUP_COMMAND} build ${CARGO_OPTS} 88 | COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_DIR}/${OUTPUT_FILE} ${OUTPUT_PATH} 89 | COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_DIR}/${OUTPUT_PDB} ${OUTPUT_PDB} 90 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 91 | DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES} 92 | ) 93 | else() 94 | add_custom_command( 95 | OUTPUT ${OUTPUT_PATH} 96 | COMMAND ${CMAKE_COMMAND} -E env BINARYNINJADIR=${BN_INSTALL_BIN_DIR} ${RUSTUP_COMMAND} clean ${CARGO_OPTS} 97 | COMMAND ${CMAKE_COMMAND} -E env BINARYNINJADIR=${BN_INSTALL_BIN_DIR} ${RUSTUP_COMMAND} build ${CARGO_OPTS} 98 | COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_DIR}/${OUTPUT_FILE} ${OUTPUT_PATH} 99 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 100 | DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES} 101 | ) 102 | endif() 103 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "adler" 7 | version = "1.0.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" 10 | 11 | [[package]] 12 | name = "aho-corasick" 13 | version = "1.1.2" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" 16 | dependencies = [ 17 | "memchr", 18 | ] 19 | 20 | [[package]] 21 | name = "array-init" 22 | version = "2.1.0" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc" 25 | 26 | [[package]] 27 | name = "binaryninja" 28 | version = "0.1.0" 29 | dependencies = [ 30 | "binaryninjacore-sys", 31 | "lazy_static", 32 | "libc", 33 | "log", 34 | ] 35 | 36 | [[package]] 37 | name = "binaryninjacore-sys" 38 | version = "0.1.0" 39 | dependencies = [ 40 | "bindgen", 41 | ] 42 | 43 | [[package]] 44 | name = "bindgen" 45 | version = "0.66.1" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" 48 | dependencies = [ 49 | "bitflags", 50 | "cexpr", 51 | "clang-sys", 52 | "lazy_static", 53 | "lazycell", 54 | "log", 55 | "peeking_take_while", 56 | "prettyplease", 57 | "proc-macro2", 58 | "quote", 59 | "regex", 60 | "rustc-hash", 61 | "shlex", 62 | "syn 2.0.41", 63 | "which", 64 | ] 65 | 66 | [[package]] 67 | name = "binrw" 68 | version = "0.8.4" 69 | source = "registry+https://github.com/rust-lang/crates.io-index" 70 | checksum = "a13d2fa8772b88ee64a0d84602c636ad2bae9c176873f6c440e2b0a1df4c8c43" 71 | dependencies = [ 72 | "array-init", 73 | "binrw_derive", 74 | ] 75 | 76 | [[package]] 77 | name = "binrw_derive" 78 | version = "0.8.4" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "193bcff2709da50edf2e9a89e0f9a2118eea70f257b1f4380ccf27d3d8578302" 81 | dependencies = [ 82 | "owo-colors", 83 | "proc-macro2", 84 | "quote", 85 | "syn 1.0.109", 86 | ] 87 | 88 | [[package]] 89 | name = "bitflags" 90 | version = "2.4.1" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" 93 | 94 | [[package]] 95 | name = "cexpr" 96 | version = "0.6.0" 97 | source = "registry+https://github.com/rust-lang/crates.io-index" 98 | checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" 99 | dependencies = [ 100 | "nom", 101 | ] 102 | 103 | [[package]] 104 | name = "cfg-if" 105 | version = "1.0.0" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 108 | 109 | [[package]] 110 | name = "clang-sys" 111 | version = "1.3.3" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b" 114 | dependencies = [ 115 | "glob", 116 | "libc", 117 | "libloading", 118 | ] 119 | 120 | [[package]] 121 | name = "either" 122 | version = "1.9.0" 123 | source = "registry+https://github.com/rust-lang/crates.io-index" 124 | checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" 125 | 126 | [[package]] 127 | name = "glob" 128 | version = "0.3.1" 129 | source = "registry+https://github.com/rust-lang/crates.io-index" 130 | checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" 131 | 132 | [[package]] 133 | name = "idb-import-plugin" 134 | version = "0.1.0" 135 | dependencies = [ 136 | "binaryninja", 137 | "idb-parser", 138 | "log", 139 | ] 140 | 141 | [[package]] 142 | name = "idb-parser" 143 | version = "0.1.0" 144 | source = "git+https://github.com/Vector35/idb-parser-rs.git#7ff21084534b17e4f801cfab33eda7f8d445dab6" 145 | dependencies = [ 146 | "binrw", 147 | "miniz_oxide", 148 | ] 149 | 150 | [[package]] 151 | name = "lazy_static" 152 | version = "1.4.0" 153 | source = "registry+https://github.com/rust-lang/crates.io-index" 154 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 155 | 156 | [[package]] 157 | name = "lazycell" 158 | version = "1.3.0" 159 | source = "registry+https://github.com/rust-lang/crates.io-index" 160 | checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" 161 | 162 | [[package]] 163 | name = "libc" 164 | version = "0.2.126" 165 | source = "registry+https://github.com/rust-lang/crates.io-index" 166 | checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" 167 | 168 | [[package]] 169 | name = "libloading" 170 | version = "0.7.4" 171 | source = "registry+https://github.com/rust-lang/crates.io-index" 172 | checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" 173 | dependencies = [ 174 | "cfg-if", 175 | "winapi", 176 | ] 177 | 178 | [[package]] 179 | name = "log" 180 | version = "0.4.20" 181 | source = "registry+https://github.com/rust-lang/crates.io-index" 182 | checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" 183 | 184 | [[package]] 185 | name = "memchr" 186 | version = "2.6.4" 187 | source = "registry+https://github.com/rust-lang/crates.io-index" 188 | checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" 189 | 190 | [[package]] 191 | name = "minimal-lexical" 192 | version = "0.2.1" 193 | source = "registry+https://github.com/rust-lang/crates.io-index" 194 | checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" 195 | 196 | [[package]] 197 | name = "miniz_oxide" 198 | version = "0.5.4" 199 | source = "registry+https://github.com/rust-lang/crates.io-index" 200 | checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" 201 | dependencies = [ 202 | "adler", 203 | ] 204 | 205 | [[package]] 206 | name = "nom" 207 | version = "7.1.3" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" 210 | dependencies = [ 211 | "memchr", 212 | "minimal-lexical", 213 | ] 214 | 215 | [[package]] 216 | name = "owo-colors" 217 | version = "3.5.0" 218 | source = "registry+https://github.com/rust-lang/crates.io-index" 219 | checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" 220 | 221 | [[package]] 222 | name = "peeking_take_while" 223 | version = "0.1.2" 224 | source = "registry+https://github.com/rust-lang/crates.io-index" 225 | checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" 226 | 227 | [[package]] 228 | name = "prettyplease" 229 | version = "0.2.15" 230 | source = "registry+https://github.com/rust-lang/crates.io-index" 231 | checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" 232 | dependencies = [ 233 | "proc-macro2", 234 | "syn 2.0.41", 235 | ] 236 | 237 | [[package]] 238 | name = "proc-macro2" 239 | version = "1.0.70" 240 | source = "registry+https://github.com/rust-lang/crates.io-index" 241 | checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" 242 | dependencies = [ 243 | "unicode-ident", 244 | ] 245 | 246 | [[package]] 247 | name = "quote" 248 | version = "1.0.33" 249 | source = "registry+https://github.com/rust-lang/crates.io-index" 250 | checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" 251 | dependencies = [ 252 | "proc-macro2", 253 | ] 254 | 255 | [[package]] 256 | name = "regex" 257 | version = "1.10.2" 258 | source = "registry+https://github.com/rust-lang/crates.io-index" 259 | checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" 260 | dependencies = [ 261 | "aho-corasick", 262 | "memchr", 263 | "regex-automata", 264 | "regex-syntax", 265 | ] 266 | 267 | [[package]] 268 | name = "regex-automata" 269 | version = "0.4.3" 270 | source = "registry+https://github.com/rust-lang/crates.io-index" 271 | checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" 272 | dependencies = [ 273 | "aho-corasick", 274 | "memchr", 275 | "regex-syntax", 276 | ] 277 | 278 | [[package]] 279 | name = "regex-syntax" 280 | version = "0.8.2" 281 | source = "registry+https://github.com/rust-lang/crates.io-index" 282 | checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" 283 | 284 | [[package]] 285 | name = "rustc-hash" 286 | version = "1.1.0" 287 | source = "registry+https://github.com/rust-lang/crates.io-index" 288 | checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" 289 | 290 | [[package]] 291 | name = "shlex" 292 | version = "1.2.0" 293 | source = "registry+https://github.com/rust-lang/crates.io-index" 294 | checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" 295 | 296 | [[package]] 297 | name = "syn" 298 | version = "1.0.109" 299 | source = "registry+https://github.com/rust-lang/crates.io-index" 300 | checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" 301 | dependencies = [ 302 | "proc-macro2", 303 | "quote", 304 | "unicode-ident", 305 | ] 306 | 307 | [[package]] 308 | name = "syn" 309 | version = "2.0.41" 310 | source = "registry+https://github.com/rust-lang/crates.io-index" 311 | checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" 312 | dependencies = [ 313 | "proc-macro2", 314 | "quote", 315 | "unicode-ident", 316 | ] 317 | 318 | [[package]] 319 | name = "unicode-ident" 320 | version = "1.0.12" 321 | source = "registry+https://github.com/rust-lang/crates.io-index" 322 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 323 | 324 | [[package]] 325 | name = "which" 326 | version = "4.2.5" 327 | source = "registry+https://github.com/rust-lang/crates.io-index" 328 | checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" 329 | dependencies = [ 330 | "either", 331 | "lazy_static", 332 | "libc", 333 | ] 334 | 335 | [[package]] 336 | name = "winapi" 337 | version = "0.3.9" 338 | source = "registry+https://github.com/rust-lang/crates.io-index" 339 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 340 | dependencies = [ 341 | "winapi-i686-pc-windows-gnu", 342 | "winapi-x86_64-pc-windows-gnu", 343 | ] 344 | 345 | [[package]] 346 | name = "winapi-i686-pc-windows-gnu" 347 | version = "0.4.0" 348 | source = "registry+https://github.com/rust-lang/crates.io-index" 349 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 350 | 351 | [[package]] 352 | name = "winapi-x86_64-pc-windows-gnu" 353 | version = "0.4.0" 354 | source = "registry+https://github.com/rust-lang/crates.io-index" 355 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 356 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "idb-import-plugin" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | crate-type = ["cdylib"] 8 | 9 | [dependencies] 10 | log = "0.4" 11 | idb-parser = {git = "https://github.com/Vector35/idb-parser-rs.git"} 12 | binaryninja = {path = "../../api/rust"} 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #### ⚠️ DEPRECATED INCLUDED BY DEFAULT NOW https://github.com/Vector35/binaryninja-api/tree/dev/rust/examples/idb_import ⚠️ 2 | 3 | # idb-import-plugin 4 | IDA Database Importer plugin for Binary Ninja written in Rust 5 | 6 | --- 7 | 8 | ## Developing 9 | 10 | If you download this repo to make changes to it yourself, you'll need to change the Binary Ninja dependency in `Cargo.toml` to: 11 | 12 | ``` 13 | binaryninja = {git = "https://github.com/Vector35/binaryninja-api.git", branch = "dev"} 14 | ``` 15 | 16 | --- 17 | 18 | #### Attribution 19 | 20 | This project makes use of: 21 | - [log] ([log license] - MIT) 22 | 23 | [log]: https://github.com/rust-lang/log 24 | [log license]: https://github.com/rust-lang/log/blob/master/LICENSE-MIT 25 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | use binaryninja::rc::Ref; 2 | use binaryninja::types::{Conf, NamedTypeReferenceClass, QualifiedName, StructureType, Type}; 3 | use binaryninja::{ 4 | binaryninjacore_sys::{BNMemberAccess, BNMemberScope}, 5 | binaryview::{BinaryView, BinaryViewExt}, 6 | debuginfo::{CustomDebugInfoParser, DebugInfo, DebugInfoParser}, 7 | interaction::get_open_filename_input, 8 | logger, 9 | }; 10 | use idb_parser::{TILBucket, TILBucketType, TILOrdinal, TILSection, TILTypeInfo, Types, IDB}; 11 | use log::error; 12 | use std::fmt::{Debug, Display, Formatter}; 13 | 14 | struct IDBParser; 15 | struct TILParser; 16 | 17 | #[derive(Debug)] 18 | enum TypeError<'a> { 19 | FailedToParse(&'a [u8]), 20 | } 21 | 22 | impl<'a> Display for TypeError<'a> { 23 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { 24 | match *self { 25 | TypeError::FailedToParse(err) => write!( 26 | f, 27 | "Failed to parse type: {:?}", 28 | std::str::from_utf8(err).unwrap() 29 | ), 30 | } 31 | } 32 | } 33 | 34 | impl<'a> std::error::Error for TypeError<'a> { 35 | fn description(&self) -> &str { 36 | match *self { 37 | TypeError::FailedToParse(err) => std::str::from_utf8(err).unwrap(), 38 | } 39 | } 40 | } 41 | 42 | impl TILParser { 43 | fn parse_all_types<'a>( 44 | &'a self, 45 | bv: &BinaryView, 46 | til: &'a TILSection, 47 | ) -> Option), TypeError>>> 48 | { 49 | match &til.types { 50 | TILBucketType::Default(default) => Some( 51 | default 52 | .type_info 53 | .iter() 54 | .map(|x| { 55 | if let Some(bn_type) = 56 | IDBParser::create_bn_type_from_idb(bv, default, x, &x.tinfo) 57 | { 58 | Ok((x.name.0.as_slice(), bn_type)) 59 | } else { 60 | Err(TypeError::FailedToParse(x.name.0.as_slice())) 61 | } 62 | }) 63 | .collect(), 64 | ), 65 | TILBucketType::Zip(zip) => { 66 | let unzip = zip.unzip(); 67 | Some( 68 | zip.type_info 69 | .iter() 70 | .map(|x| { 71 | if let Some(bn_type) = 72 | IDBParser::create_bn_type_from_idb(bv, &unzip, x, &x.tinfo) 73 | { 74 | Ok((x.name.0.as_slice(), bn_type)) 75 | } else { 76 | Err(TypeError::FailedToParse(x.name.0.as_slice())) 77 | } 78 | }) 79 | .collect(), 80 | ) 81 | } 82 | } 83 | } 84 | } 85 | 86 | impl IDBParser { 87 | fn create_bn_type_from_idb( 88 | bv: &BinaryView, 89 | bucket: &TILBucket, 90 | tinfo: &TILTypeInfo, 91 | ty: &Types, 92 | ) -> Option> { 93 | match ty { 94 | Types::Unset(mdata) => match mdata.get_base_type_flag().0 { 95 | 0x01 => Some(Type::void()), 96 | 0x02 => Some(Type::int(1, mdata.get_type_flag().is_signed())), 97 | 0x03 => Some(Type::int(2, mdata.get_type_flag().is_signed())), 98 | 0x04 => Some(Type::int(4, mdata.get_type_flag().is_signed())), 99 | 0x05 => Some(Type::int(8, mdata.get_type_flag().is_signed())), 100 | 0x06 => Some(Type::int(16, mdata.get_type_flag().is_signed())), 101 | // not too sure about this one. 102 | 0x07 => Some(Type::int(4, mdata.get_type_flag().is_signed())), 103 | 0x08 => Some(Type::bool()), 104 | 0x09 => match mdata.get_type_flag().0 { 105 | 0x00 => Some(Type::float(4)), 106 | 0x10 => Some(Type::float(8)), 107 | // TODO: (LONG DOUBLE) LOOK AT THIS L8R BUT THIS IS DEBATABLE SO WE ARE DOING 8 108 | 0x20 => Some(Type::float(8)), 109 | _ => None, 110 | }, 111 | _ => None, 112 | }, 113 | Types::Pointer(ptr) => { 114 | if let Some(arch) = bv.default_arch() { 115 | Self::create_bn_type_from_idb(bv, bucket, tinfo, &ptr.typ) 116 | .map(|ty| Type::pointer(&arch, &*ty)) 117 | } else { 118 | None 119 | } 120 | } 121 | Types::Function(fun) => { 122 | if let Some(return_ty) = Self::create_bn_type_from_idb(bv, bucket, tinfo, &fun.ret) 123 | { 124 | let mut vec = Vec::new(); 125 | for (t, str) in std::iter::zip(&fun.args, &tinfo.fields.0) { 126 | if let Some(f) = Self::create_bn_type_from_idb(bv, bucket, tinfo, &t.0) { 127 | vec.push(binaryninja::types::FunctionParameter::new( 128 | f, 129 | str.as_str(), 130 | None, 131 | )); 132 | } 133 | } 134 | 135 | Some(Type::function( 136 | Conf::new(&*return_ty, 100), 137 | vec.as_slice(), 138 | false, 139 | )) 140 | } else { 141 | None 142 | } 143 | } 144 | Types::Array(arr) => Self::create_bn_type_from_idb(bv, bucket, tinfo, &arr.elem_type) 145 | .map(|t| Type::array(Conf::new(&*t, 100), arr.nelem as u64)), 146 | Types::Typedef(tdef) => { 147 | if tdef.is_ordref { 148 | if let Some(lookup) = bucket 149 | .type_info 150 | .iter() 151 | .find(|x| match x.ordinal { 152 | TILOrdinal::U32(t) => {t as u64} 153 | TILOrdinal::U64(t) => {t} 154 | } == tdef.ordinal.0 as u64) 155 | { 156 | Self::create_bn_type_from_idb(bv, bucket, tinfo, &lookup.tinfo).map(|typ| Type::named_type_from_type( 157 | std::str::from_utf8(tinfo.name.0.as_slice()).unwrap(), 158 | &typ, 159 | )) 160 | } else { 161 | None 162 | } 163 | } else if bucket 164 | .type_info 165 | .iter() 166 | .any(|x| x.name.0.as_slice() == tdef.name.as_bytes()) 167 | { 168 | Some(Type::named_type( 169 | &binaryninja::types::NamedTypeReference::new( 170 | NamedTypeReferenceClass::UnknownNamedTypeClass, 171 | QualifiedName::from(tdef.name.as_str()), 172 | ), 173 | )) 174 | } else { 175 | match tdef.name.as_str() { 176 | "int8_t" => Some(Type::int(1, true)), 177 | "int16_t" => Some(Type::int(2, true)), 178 | "int32_t" => Some(Type::int(4, true)), 179 | "int64_t" => Some(Type::int(8, true)), 180 | "int128_t" => Some(Type::int(16, true)), 181 | _ => { 182 | error!("Failed to find typedef: {}", tdef.name.as_str()); 183 | None 184 | } 185 | } 186 | } 187 | } 188 | Types::Struct(str) => { 189 | if str.is_ref { 190 | Self::create_bn_type_from_idb(bv, bucket, tinfo, &str.ref_type.0).map( 191 | |ref_type| { 192 | Type::named_type_from_type( 193 | std::str::from_utf8(tinfo.name.0.as_slice()).unwrap(), 194 | &ref_type, 195 | ) 196 | }, 197 | ) 198 | } else { 199 | let structure = binaryninja::types::StructureBuilder::new(); 200 | for (member, name) in std::iter::zip(&str.members, &tinfo.fields.0) { 201 | if let Some(mem) = 202 | Self::create_bn_type_from_idb(bv, bucket, tinfo, &member.0) 203 | { 204 | structure.append( 205 | mem.as_ref(), 206 | name.as_str(), 207 | BNMemberAccess::NoAccess, 208 | BNMemberScope::NoScope, 209 | ); 210 | } 211 | } 212 | let str_ref = structure.finalize(); 213 | Some(Type::structure(&str_ref)) 214 | } 215 | } 216 | Types::Union(uni) => { 217 | if uni.is_ref { 218 | Self::create_bn_type_from_idb(bv, bucket, tinfo, &uni.ref_type.0).map( 219 | |ref_type| { 220 | Type::named_type_from_type( 221 | std::str::from_utf8(tinfo.name.0.as_slice()).unwrap(), 222 | &ref_type, 223 | ) 224 | }, 225 | ) 226 | } else { 227 | let structure = binaryninja::types::StructureBuilder::new(); 228 | for (member, name) in std::iter::zip(&uni.members, &tinfo.fields.0) { 229 | if let Some(mem) = 230 | Self::create_bn_type_from_idb(bv, bucket, tinfo, &member.0) 231 | { 232 | structure.append( 233 | mem.as_ref(), 234 | name.as_str(), 235 | BNMemberAccess::NoAccess, 236 | BNMemberScope::NoScope, 237 | ); 238 | } 239 | } 240 | structure.set_structure_type(StructureType::UnionStructureType); 241 | let str_ref = structure.finalize(); 242 | Some(binaryninja::types::Type::structure(&str_ref)) 243 | } 244 | } 245 | Types::Enum(enu) => { 246 | if enu.is_ref { 247 | Self::create_bn_type_from_idb(bv, bucket, tinfo, &enu.ref_type.0).map( 248 | |ref_type| { 249 | binaryninja::types::Type::named_type_from_type( 250 | std::str::from_utf8(tinfo.name.0.as_slice()).unwrap(), 251 | &ref_type, 252 | ) 253 | }, 254 | ) 255 | } else { 256 | let eb = binaryninja::types::EnumerationBuilder::new(); 257 | for (member, name) in std::iter::zip(&enu.members, &tinfo.fields.0) { 258 | eb.insert(name.as_str(), member.0); 259 | } 260 | Some(binaryninja::types::Type::enumeration( 261 | &eb.finalize(), 262 | enu.bytesize as usize, 263 | Conf::new(false, 0), 264 | )) 265 | } 266 | } 267 | Types::Bitfield(_) => { 268 | error!("Bitfields are not supported"); 269 | None 270 | } 271 | Types::Unknown(_) => None, 272 | } 273 | } 274 | 275 | fn parse_all_types<'a>( 276 | &'a self, 277 | bv: &BinaryView, 278 | idb: &'a IDB, 279 | ) -> Option), TypeError>>> 280 | { 281 | if let Some(til) = &idb.til { 282 | match &til.types { 283 | TILBucketType::Default(default) => Some( 284 | default 285 | .type_info 286 | .iter() 287 | .map(|x| { 288 | if let Some(bn_type) = 289 | Self::create_bn_type_from_idb(bv, default, x, &x.tinfo) 290 | { 291 | Ok((x.name.0.as_slice(), bn_type)) 292 | } else { 293 | Err(TypeError::FailedToParse(x.name.0.as_slice())) 294 | } 295 | }) 296 | .collect(), 297 | ), 298 | TILBucketType::Zip(zip) => { 299 | let unzip = zip.unzip(); 300 | Some( 301 | zip.type_info 302 | .iter() 303 | .map(|x| { 304 | if let Some(bn_type) = 305 | Self::create_bn_type_from_idb(bv, &unzip, x, &x.tinfo) 306 | { 307 | Ok((x.name.0.as_slice(), bn_type)) 308 | } else { 309 | Err(TypeError::FailedToParse(x.name.0.as_slice())) 310 | } 311 | }) 312 | .collect(), 313 | ) 314 | } 315 | } 316 | } else { 317 | None 318 | } 319 | } 320 | 321 | // fn parse_type_by_name( 322 | // &self, 323 | // bv: &BinaryView, 324 | // name: String, 325 | // idb: &IDB, 326 | // ) -> Option<(String, binaryninja::rc::Ref)> { 327 | // if let Some(til) = &idb.til { 328 | // match &til.types { 329 | // TILBucketType::Default(default) => { 330 | // if let Some(located) = default 331 | // .type_info 332 | // .iter() 333 | // .find(|ty| ty.name.clone().into_string() == name) 334 | // { 335 | // if let Some(bn_type) = 336 | // Self::create_bn_type_from_idb(bv, &default, &located, &located.tinfo) 337 | // { 338 | // Some((located.name.clone().into_string(), bn_type)) 339 | // } else { 340 | // None 341 | // } 342 | // } else { 343 | // None 344 | // } 345 | // } 346 | // TILBucketType::Zip(zip) => None, 347 | // _ => None, 348 | // } 349 | // } else { 350 | // None 351 | // } 352 | // } 353 | } 354 | 355 | impl CustomDebugInfoParser for IDBParser { 356 | fn is_valid(&self, view: &BinaryView) -> bool { 357 | view.file().filename().ends_with(".i64") 358 | } 359 | 360 | fn parse_info( 361 | &self, 362 | debug_info: &mut DebugInfo, 363 | _bv: &BinaryView, 364 | debug_file: &BinaryView, 365 | _progress: Box Result<(), ()>>, 366 | ) -> bool { 367 | if let Some(idb_file) = get_open_filename_input("Select IDB", "*.i64") { 368 | if let Ok(path) = idb_file.into_os_string().into_string() { 369 | if let Ok(idb) = IDB::parse_from_file(path) { 370 | if let Some(types) = self.parse_all_types(debug_file, &idb) { 371 | types.iter().for_each(|x| match x { 372 | Ok((str, ty)) => { 373 | debug_info.add_type(std::str::from_utf8(str).unwrap(), ty); 374 | } 375 | Err(err) => { 376 | error!("{}", err); 377 | } 378 | }); 379 | return true; 380 | } 381 | } 382 | } 383 | } 384 | false 385 | } 386 | } 387 | 388 | impl CustomDebugInfoParser for TILParser { 389 | fn is_valid(&self, view: &BinaryView) -> bool { 390 | view.file().filename().ends_with(".i64") 391 | } 392 | 393 | fn parse_info( 394 | &self, 395 | debug_info: &mut DebugInfo, 396 | _bv: &BinaryView, 397 | debug_file: &BinaryView, 398 | _progress: Box Result<(), ()>>, 399 | ) -> bool { 400 | if let Some(idb_file) = get_open_filename_input("Select IDB", "*.til") { 401 | if let Ok(path) = idb_file.into_os_string().into_string() { 402 | if let Ok(til) = TILSection::parse_from_file(path) { 403 | if let Some(types) = self.parse_all_types(debug_file, &til) { 404 | types.iter().for_each(|x| match x { 405 | Ok((str, ty)) => { 406 | debug_info.add_type(std::str::from_utf8(str).unwrap(), ty); 407 | } 408 | Err(err) => { 409 | error!("{}", err); 410 | } 411 | }); 412 | return true; 413 | } 414 | } 415 | } 416 | } 417 | false 418 | } 419 | } 420 | 421 | #[no_mangle] 422 | pub extern "C" fn CorePluginInit() -> bool { 423 | let _logger = logger::init(log::LevelFilter::Debug); 424 | DebugInfoParser::register("IDB Parser", IDBParser {}); 425 | DebugInfoParser::register("TIL Parser", TILParser {}); 426 | true 427 | } 428 | --------------------------------------------------------------------------------