1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use std::path::Path;
fn main() {
let source_path = Path::new("ghidra/Ghidra/Features/Decompiler/src/decompile/cpp");
// The following sources were pulled from the Makefile
const LIBSLA_SOURCE_FILES: &[&str] = &[
// CORE= xml marshal space float address pcoderaw translate opcodes globalcontext
"xml.cc",
"marshal.cc",
"space.cc",
"float.cc",
"address.cc",
"pcoderaw.cc",
"translate.cc",
"opcodes.cc",
"globalcontext.cc",
// SLEIGH= sleigh pcodeparse pcodecompile sleighbase slghsymbol \
// slghpatexpress slghpattern semantics context slaformat compression filemanage
"sleigh.cc",
"pcodeparse.cc",
"pcodecompile.cc",
"sleighbase.cc",
"slghsymbol.cc",
"slghpatexpress.cc",
"slghpattern.cc",
"semantics.cc",
"context.cc",
"slaformat.cc",
"compression.cc",
"filemanage.cc",
// LIBSLA_NAMES
"loadimage.cc",
"memstate.cc",
"emulate.cc",
"opbehavior.cc",
// SLACOMP=slgh_compile slghparse slghscan
// Omitting slgh_compile since it defines main function
"slghparse.cc",
"slghscan.cc",
];
let zlib_path = Path::new("ghidra/Ghidra/Features/Decompiler/src/decompile/zlib");
const ZLIB_SOURCE_FILES: &[&str] = &[
"adler32.c",
"deflate.c",
"inffast.c",
"inflate.c",
"inftrees.c",
"trees.c",
"zutil.c",
];
cxx_build::bridge("src/sys.rs")
.define("LOCAL_ZLIB", "1")
.define("NO_GZIP", "1")
.flag_if_supported("-std=c++14")
.files(LIBSLA_SOURCE_FILES.iter().map(|s| source_path.join(s)))
.files(ZLIB_SOURCE_FILES.iter().map(|s| zlib_path.join(s)))
.file("src/cpp/bridge.cc")
.include(source_path) // Header files coexist with cpp files
.warnings(false) // Not interested in the warnings for Ghidra code
.compile("sla");
// Rerun if any of the C++ to Rust bindings have changed
println!("cargo:rerun-if-changed=src/sys.rs");
// Rerun if any of the C++ bridge code has changed
println!("cargo:rerun-if-changed=src/cpp");
}