From e2c3c6edfaa0bc4ec11b962a180eaf4797aef8f5 Mon Sep 17 00:00:00 2001 From: Alwin Berger Date: Wed, 9 Nov 2022 08:44:41 +0100 Subject: [PATCH] init --- .envrc | 1 + .gitignore | 6 ++ .gitmodules | 6 ++ LibAFL | 1 + edge_compare/.gitignore | 6 ++ edge_compare/Cargo.lock | 220 +++++++++++++++++++++++++++++++++++++++ edge_compare/Cargo.toml | 17 +++ edge_compare/src/main.rs | 71 +++++++++++++ flake.lock | 94 +++++++++++++++++ flake.nix | 65 ++++++++++++ qemu-libafl-bridge | 1 + shell.nix | 7 ++ 12 files changed, 495 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 .gitmodules create mode 160000 LibAFL create mode 100644 edge_compare/.gitignore create mode 100644 edge_compare/Cargo.lock create mode 100644 edge_compare/Cargo.toml create mode 100644 edge_compare/src/main.rs create mode 100644 flake.lock create mode 100644 flake.nix create mode 160000 qemu-libafl-bridge create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..9800a71 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use_nix shell.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0840a76 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.env +.direnv +.ccls-cache +.cache +.vscode +qemu diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b8b7ed1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "LibAFL"] + path = LibAFL + url = https://github.com/AFLplusplus/LibAFL +[submodule "qemu-libafl-bridge"] + path = qemu-libafl-bridge + url = https://github.com/AFLplusplus/qemu-libafl-bridge diff --git a/LibAFL b/LibAFL new file mode 160000 index 0000000..79fc952 --- /dev/null +++ b/LibAFL @@ -0,0 +1 @@ +Subproject commit 79fc952f530369a8820790e6e13008de13fd02f2 diff --git a/edge_compare/.gitignore b/edge_compare/.gitignore new file mode 100644 index 0000000..f153339 --- /dev/null +++ b/edge_compare/.gitignore @@ -0,0 +1,6 @@ +*.axf +*.qcow2 +demo +*.ron +*.bsp +target diff --git a/edge_compare/Cargo.lock b/edge_compare/Cargo.lock new file mode 100644 index 0000000..c802628 --- /dev/null +++ b/edge_compare/Cargo.lock @@ -0,0 +1,220 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "clap" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d76c22c9b9b215eeb8d016ad3a90417bd13cb24cf8142756e6472445876cab7" +dependencies = [ + "atty", + "bitflags", + "indexmap", + "os_str_bytes", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "edge_compare" +version = "0.1.0" +dependencies = [ + "clap", + "ron", + "serde", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "indexmap" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "libc" +version = "0.2.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] + +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ron" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b861ecaade43ac97886a512b360d01d66be9f41f3c61088b42cedf92e03d678" +dependencies = [ + "base64", + "bitflags", + "serde", +] + +[[package]] +name = "serde" +version = "1.0.136" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.136" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/edge_compare/Cargo.toml b/edge_compare/Cargo.toml new file mode 100644 index 0000000..48cb0b8 --- /dev/null +++ b/edge_compare/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "edge_compare" +version = "0.1.0" +authors = [ "Alwin Berger " ] +edition = "2021" + +[features] +default = ["std"] +std = [] + +[profile.release] +debug = true + +[dependencies] +clap = { version = "3.1.1", features = ["default"] } +serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib +ron = "0.7" # write serialized data - including hashmaps \ No newline at end of file diff --git a/edge_compare/src/main.rs b/edge_compare/src/main.rs new file mode 100644 index 0000000..4e42fcb --- /dev/null +++ b/edge_compare/src/main.rs @@ -0,0 +1,71 @@ +use std::collections::HashMap; +use std::path::PathBuf; +use clap::Arg; +use clap::App; +use std::{env,fs}; + +fn main() { + let res = match App::new("edge_compare") + .version("0.1.0") + .author("Alwin Berger") + .about("Compare Serialized Edge-Maps.") + .arg( + Arg::new("a") + .short('a') + .long("map-a") + .required(true) + .takes_value(true), + ) + .arg( + Arg::new("b") + .short('b') + .long("map-b") + .required(true) + .takes_value(true), + ) + .try_get_matches_from(env::args()) + { + Ok(res) => res, + Err(err) => { + println!( + "Syntax: {}, --map-a --map-b \n{:?}", + env::current_exe() + .unwrap_or_else(|_| "fuzzer".into()) + .to_string_lossy(), + err.info, + ); + return; + } + }; + + let path_a = PathBuf::from(res.value_of("a").unwrap().to_string()); + let path_b = PathBuf::from(res.value_of("b").unwrap().to_string()); + + let raw_a = fs::read(path_a).expect("Can not read dumped edges a"); + let hmap_a : HashMap<(u64,u64),u64> = ron::from_str(&String::from_utf8_lossy(&raw_a)).expect("Can not parse HashMap"); + + let raw_b = fs::read(path_b).expect("Can not read dumped edges b"); + let hmap_b : HashMap<(u64,u64),u64> = ron::from_str(&String::from_utf8_lossy(&raw_b)).expect("Can not parse HashMap"); + + let mut a_and_b = Vec::<((u64,u64),u64)>::new(); + let mut a_and_b_differ = Vec::<((u64,u64),(u64,u64))>::new(); + let mut a_sans_b = Vec::<((u64,u64),u64)>::new(); + + for i_a in hmap_a.clone() { + match hmap_b.get(&i_a.0) { + None => a_sans_b.push(i_a), + Some(x) => if i_a.1 == *x { + a_and_b.push(i_a); + } else { + a_and_b_differ.push((i_a.0,(i_a.1,*x))); + } + } + } + let b_sans_a : Vec<((u64,u64),u64)> = hmap_b.into_iter().filter(|x| !hmap_a.contains_key(&x.0) ).collect(); + + println!("a_sans_b: {:#?}\na_and_b_differ: {:#?}\nb_sans_a: {:#?}",&a_sans_b,&a_and_b_differ,&b_sans_a); + println!("Stats: a\\b: {} a&=b: {} a&!=b: {} b\\a: {} avb: {} jaccarde: {}", + a_sans_b.len(),a_and_b.len(),a_and_b_differ.len(),b_sans_a.len(), + a_and_b.len()+a_and_b_differ.len()+a_sans_b.len()+b_sans_a.len(), + (a_and_b.len()+a_and_b_differ.len())as f64/(a_and_b.len()+a_and_b_differ.len()+a_sans_b.len()+b_sans_a.len()) as f64); +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..592677b --- /dev/null +++ b/flake.lock @@ -0,0 +1,94 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1637014545, + "narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1641230035, + "narHash": "sha256-hFyqihERaTbLxCOlugy/rpp22VLtLh8SPRnA2uu3F/8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "78cd22c1b8604de423546cd49bfe264b786eca13", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1637453606, + "narHash": "sha256-Gy6cwUswft9xqsjWxFYEnx/63/qzaFUwatcbV5GF/GQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8afc4e543663ca0a6a4f496262cd05233737e732", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1641177598, + "narHash": "sha256-ixQ72QmhIfb7bAzvLUn6GtjpoMA/N3V1PBwjZQQyc1k=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "d93e905bc0d36508590b6ec0e2e6e92d2cf8289a", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..885362e --- /dev/null +++ b/flake.nix @@ -0,0 +1,65 @@ +{ + description = "A devShell example"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + myrust = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override { + extensions = [ "rls" "rust-analysis" "rust-src" "rust-docs" ]; + }); + in + with pkgs; + rec { + devShell = mkShell.override {stdenv = llvmPackages_14.stdenv;} { # LibAFL needs LLVM + buildInputs = [ + # rust-bin.nightly.latest.default + myrust + # für qemu + python3 + ninja + pkgconfig + glib + pixman + # für analyse der in-/outputs + xxd + # FreeRTOS + gcc-arm-embedded + # generate bindings from RTOS to Rust + rust-bindgen + # compare libafl edges + packages.edge_compare + # Debugging + ddd + # visualization + graphviz + rstudioWrapper + R + ]; + + shellHook = '' + ''; + }; + + packages = { + edge_compare=rustPlatform.buildRustPackage rec { + pname = "edge_compare"; + version = "0.1.0"; + + src = ./edge_compare; + + cargoSha256 = "sha256-47THUU9aKhAwb2Tz8bJWDmVhDokpr+DOiFNZhmsN8Gk="; + }; + }; + } + ); +} diff --git a/qemu-libafl-bridge b/qemu-libafl-bridge new file mode 160000 index 0000000..ddb71cf --- /dev/null +++ b/qemu-libafl-bridge @@ -0,0 +1 @@ +Subproject commit ddb71cf43844f8848ae655ca696bdfc3fb7839f1 diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..99fd077 --- /dev/null +++ b/shell.nix @@ -0,0 +1,7 @@ +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).shellNix \ No newline at end of file