Skip to content

Make parser parse to json #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions fuzzer/src/bin/parse_track_file.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
extern crate angora;
extern crate angora_common;
use angora::track::*;
use angora::{track::*, cond_stmt::CondStmt};
use angora_common::defs;
use std::{env, path::PathBuf};

fn main() {
// Usage: path_to_file output_format [pin_mode]
let args: Vec<String> = env::args().collect();
if args.len() <= 2 {
println!("Wrong command!");
return;
}

let mut output_format = "json";
if args.len() > 2 {
output_format = match args[2].as_str() {
"line" => "line",
"json_real" => "json_real",
_ => "json"
};
}

let mut pin_mode = false;
if args.len() > 3 {
pin_mode = match args[3].as_str() {
"pin" => true,
_ => false
};
}

let path = PathBuf::from(&args[1]);

// let t = load_track_data(path.as_path(), 0, 0, 0, 0);
let t = match read_and_parse(path.as_path(), true, false) {
let t = match read_and_parse(path.as_path(), pin_mode, false) {
Result::Ok(val) => val,
Result::Err(err) => panic!("parse track file error!! {:?}", err),
};

let mut output_format = "json";
if args.len() > 2 {
if args[2] == "line" {
output_format = "line";
}
}

if output_format == "line" {
for cond in t {
// println!("{:?}", cond.base);
Expand All @@ -44,7 +55,18 @@ fn main() {
);
}
}
} else if output_format == "json_real" {
let json = get_json(&t);
println!("{}", json);
} else {
print!("{:#?}", t);
}
}

pub fn get_json(t: &Vec<CondStmt>) -> String {
match serde_json::to_string(&t) {
Result::Ok(val) => return val,
Result::Err(err) => panic!("Failed to serialize to json!! {:?}", err),
};
}

3 changes: 2 additions & 1 deletion fuzzer/src/cond_stmt/cond_state.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{cond_stmt::CondStmt, mut_input::offsets::*};
use angora_common::{config, defs};
use std;
use serde_derive::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub enum CondState {
Offset,
OffsetOpt,
Expand Down
3 changes: 2 additions & 1 deletion fuzzer/src/cond_stmt/cond_stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use super::CondState;
use crate::fuzz_type::FuzzType;
use angora_common::{cond_stmt_base::CondStmtBase, defs, tag::TagSeg};
use std::hash::{Hash, Hasher};
use serde_derive::{Deserialize, Serialize};

#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Deserialize, Serialize)]
pub struct CondStmt {
pub base: CondStmtBase,
pub offsets: Vec<TagSeg>,
Expand Down
2 changes: 1 addition & 1 deletion fuzzer/src/cond_stmt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod cond_state;
mod cond_stmt;
pub mod cond_stmt;
mod output;
mod shm_conds;

Expand Down
2 changes: 1 addition & 1 deletion fuzzer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate log;
extern crate derive_more;

mod branches;
mod cond_stmt;
pub mod cond_stmt;
mod depot;
pub mod executor;
mod mut_input;
Expand Down