-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 64aa057
Showing
71 changed files
with
6,682 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[env] | ||
# HACK: To get the workspace directory. (See: https://github.com/rust-lang/cargo/issues/3946#issuecomment-973132993) | ||
# TODO: If we had &[u8] api in flatbuffers-build we could include the file with relative path like that. | ||
CARGO_WORKSPACE_DIR = { value = "", relative = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Binaries for programs and dependencies | ||
/target/ | ||
**/target/ | ||
|
||
# Remove Cargo.lock from gitignore if it's already checked in | ||
Cargo.lock | ||
|
||
# Best practice for something like this, the python scripts are not meant to be "deployed" from this repo state. | ||
poetry.lock | ||
|
||
gen_flatbuffers | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# Temporary files generated by editors | ||
*~ | ||
*.swp | ||
*.swo | ||
|
||
# IntelliJ and CLion directories | ||
.idea/ | ||
*.iml | ||
*.iws | ||
*.ipr | ||
|
||
# MacOS specific ignores | ||
.DS_Store | ||
._* | ||
|
||
# Rust documentations | ||
/target/doc/ | ||
|
||
# Build files | ||
**/build/ | ||
|
||
# Generated files and directories | ||
generated/ | ||
|
||
# Node.js directories (if any) | ||
/node_modules/ | ||
|
||
# Logs | ||
*.log | ||
|
||
# Output directories | ||
*.out | ||
*.log.* | ||
|
||
**/[Tt]humbs.db | ||
**/[Dd]esktop.ini | ||
|
||
**/ubuntu | ||
**/downloads | ||
**/msvc | ||
**/windows | ||
|
||
**/out | ||
|
||
*.vsix | ||
*.deb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"fbcg_rust", | ||
"sigem", | ||
"signaturebuild", | ||
"sigview", | ||
"symbolbuild", | ||
"typebuild", | ||
"warp_binja" | ||
] | ||
|
||
[profile.release] | ||
panic = "abort" | ||
lto = true | ||
debug = "full" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "fbcg_rust" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
flatbuffers = "24.3.25" | ||
|
||
[build-dependencies] | ||
flatbuffers-build = "0.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use flatbuffers_build::BuilderOptions; | ||
use std::path::PathBuf; | ||
|
||
pub fn main() { | ||
// Remove leftover symlink dir. | ||
let _ = std::fs::remove_dir_all("src/gen_flatbuffers"); | ||
let workspace_dir: PathBuf = env!("CARGO_WORKSPACE_DIR").into(); | ||
BuilderOptions::new_with_files([ | ||
workspace_dir.join("type.fbs"), | ||
workspace_dir.join("symbol.fbs"), | ||
workspace_dir.join("signature.fbs"), | ||
]) | ||
.set_symlink_directory("src/gen_flatbuffers") | ||
.compile() | ||
.expect("flatbuffer compilation failed"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#[allow(warnings)] | ||
pub mod gen_flatbuffers; | ||
|
||
pub use gen_flatbuffers::sig_bin as fb_sig; | ||
pub use gen_flatbuffers::symbol_bin as fb_symbol; | ||
pub use gen_flatbuffers::type_bin as fb_type; | ||
|
||
impl From<u16> for gen_flatbuffers::type_bin::BitWidth { | ||
fn from(value: u16) -> Self { | ||
Self::new(value) | ||
} | ||
} | ||
|
||
impl From<&gen_flatbuffers::type_bin::BitWidth> for u16 { | ||
fn from(value: &gen_flatbuffers::type_bin::BitWidth) -> Self { | ||
value.value() | ||
} | ||
} | ||
|
||
impl From<u64> for gen_flatbuffers::type_bin::BitSize { | ||
fn from(value: u64) -> Self { | ||
Self::new(value) | ||
} | ||
} | ||
|
||
impl From<&gen_flatbuffers::type_bin::BitSize> for u64 { | ||
fn from(value: &gen_flatbuffers::type_bin::BitSize) -> Self { | ||
value.value() | ||
} | ||
} | ||
|
||
impl From<u64> for gen_flatbuffers::type_bin::UnsignedBitOffset { | ||
fn from(value: u64) -> Self { | ||
Self::new(value) | ||
} | ||
} | ||
|
||
impl From<&gen_flatbuffers::type_bin::UnsignedBitOffset> for u64 { | ||
fn from(value: &gen_flatbuffers::type_bin::UnsignedBitOffset) -> Self { | ||
value.value() | ||
} | ||
} | ||
|
||
impl From<i64> for gen_flatbuffers::type_bin::BitOffset { | ||
fn from(value: i64) -> Self { | ||
Self::new(value) | ||
} | ||
} | ||
|
||
impl From<&gen_flatbuffers::type_bin::BitOffset> for i64 { | ||
fn from(value: &gen_flatbuffers::type_bin::BitOffset) -> Self { | ||
value.value() | ||
} | ||
} | ||
|
||
impl From<i64> for gen_flatbuffers::type_bin::BitShift { | ||
fn from(value: i64) -> Self { | ||
Self::new(value) | ||
} | ||
} | ||
|
||
impl From<&gen_flatbuffers::type_bin::BitShift> for i64 { | ||
fn from(value: &gen_flatbuffers::type_bin::BitShift) -> Self { | ||
value.value() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[tool.poetry] | ||
name = "typebin" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Mason Reed <[email protected]>"] | ||
readme = "README.md" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.9" | ||
aiohttp = "^3.10.8" | ||
beautifulsoup4 = "^4.12.3" | ||
ar = "^1.0.0" | ||
zstandard = "^0.23.0" | ||
xtarfile = "^0.2.1" | ||
|
||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "sigem" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
binaryninja = { path = "../../binaryninja/api/rust", features = ["rayon"] } | ||
binaryninjacore-sys = { path = "../../binaryninja/api/rust/binaryninjacore-sys" } | ||
env_logger = "0.11.5" | ||
log = "0.4" | ||
signaturebuild = { path = "../signaturebuild" } | ||
warp_binja = { path = "../warp_binja" } | ||
clap = { version = "4.5.16", features = ["derive"] } | ||
rayon = "1.10.0" | ||
ar = { git = "https://github.com/mdsteele/rust-ar" } | ||
tempdir = "0.3.7" | ||
serde_json = "1.0.132" | ||
|
||
|
||
[build-dependencies] | ||
cc = "1.1.28" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
fn compile_rust(file: PathBuf) -> bool { | ||
let out_dir = std::env::var_os("OUT_DIR").unwrap(); | ||
let rustc = std::env::var_os("RUSTC").unwrap(); | ||
let rustc = rustc.to_str().unwrap(); | ||
let mut rustc = rustc.split('\x1f'); | ||
let mut cmd = Command::new(rustc.next().unwrap()); | ||
cmd.args(rustc) | ||
.arg("--crate-type=rlib") | ||
.arg("--out-dir") | ||
.arg(out_dir) | ||
.arg(file); | ||
cmd.status().expect("failed to invoke rustc").success() | ||
} | ||
|
||
fn main() { | ||
let link_path = | ||
std::env::var_os("DEP_BINARYNINJACORE_PATH").expect("DEP_BINARYNINJACORE_PATH specified"); | ||
let out_dir = std::env::var_os("OUT_DIR").expect("OUT_DIR specified"); | ||
let out_dir_path = PathBuf::from(out_dir); | ||
|
||
println!("cargo::rustc-link-lib=dylib=binaryninjacore"); | ||
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap()); | ||
|
||
#[cfg(not(target_os = "windows"))] | ||
{ | ||
println!( | ||
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}", | ||
link_path.to_string_lossy() | ||
); | ||
} | ||
|
||
// Copy all binaries to OUT_DIR for unit tests. | ||
let bin_dir: PathBuf = "fixtures/bin".into(); | ||
if let Ok(entries) = std::fs::read_dir(bin_dir) { | ||
for entry in entries { | ||
let entry = entry.unwrap(); | ||
let path = entry.path(); | ||
if path.is_file() { | ||
let file_name = path.file_name().unwrap(); | ||
let dest_path = out_dir_path.join(file_name); | ||
std::fs::copy(&path, &dest_path).expect("failed to copy binary to OUT_DIR"); | ||
} | ||
} | ||
} | ||
|
||
// Compile all .c files in fixtures/src directory for unit tests. | ||
let src_dir: PathBuf = "fixtures/src".into(); | ||
if let Ok(entries) = std::fs::read_dir(src_dir) { | ||
for entry in entries { | ||
let entry = entry.unwrap(); | ||
let path = entry.path(); | ||
match path.extension().map(|s| s.to_str().unwrap()) { | ||
Some("c") => { | ||
cc::Build::new() | ||
.file(&path) | ||
.compile(path.file_stem().unwrap().to_str().unwrap()); | ||
} | ||
Some("rs") => { | ||
compile_rust(path); | ||
} | ||
_ => {} | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <stdio.h> | ||
|
||
#include "library.h" | ||
|
||
int myFunction(int x) | ||
{ | ||
printf("%d\n", x); | ||
return x; | ||
} | ||
|
||
int recursiveFunc(int x); | ||
int otherFunction(int x) | ||
{ | ||
x += 5; | ||
if (x < 10) return otherFunction(x); | ||
return recursiveFunc(x); | ||
} | ||
|
||
int recursiveFunc(int x) | ||
{ | ||
if (x <= 0) return 0; | ||
return x + otherFunction(x - 1); | ||
} | ||
|
||
struct MyStruct myFunction2(int x) | ||
{ | ||
printf("MyStruct %d\n", x); | ||
struct MyStruct myStruct; | ||
myStruct.a = recursiveFunc(x); | ||
myStruct.b = x * 10; | ||
myStruct.c = "my struct"; | ||
return myStruct; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
struct MyStruct { | ||
int a; | ||
int b; | ||
const char* c; | ||
struct MyStruct* d; | ||
}; | ||
|
||
int myFunction(int x); | ||
struct MyStruct myFunction2(int x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#[derive(Debug, Hash, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] | ||
pub struct MyStruct { | ||
a: i32, | ||
b: u32, | ||
c: *mut MyStruct, | ||
} | ||
|
||
impl MyStruct { | ||
pub fn new(a: i32, b: u32, c: *mut MyStruct) -> MyStruct { | ||
MyStruct { a, b, c } | ||
} | ||
|
||
pub fn hello(&self) { | ||
println!("hello from MyStruct! a: {} b: {}", self.a, self.b); | ||
} | ||
} | ||
|
||
pub fn main() { | ||
let my_struct = MyStruct::new(1, 2, 0xfffff as *mut MyStruct); | ||
my_struct.hello(); | ||
println!("{:#?}", my_struct); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdio.h> | ||
|
||
#include "library.h" | ||
|
||
int simple() { | ||
printf("This is main!\n"); | ||
|
||
printf("calling myFunction\n"); | ||
int returnVal = myFunction(55); | ||
|
||
printf("calling myFunction2\n"); | ||
struct MyStruct myStruct = myFunction2(returnVal); | ||
|
||
return myStruct.b; | ||
} |
Oops, something went wrong.