Skip to content

Commit

Permalink
made transpiling the only option
Browse files Browse the repository at this point in the history
  • Loading branch information
linux-techtips committed Jan 8, 2022
1 parent 385549c commit fe5b46b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 35 deletions.
13 changes: 2 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,13 @@ use transpiler::{Args, micro_ducky_transpiler::transpile, parser::parse_payload}
mod errors;
use errors::DuckyError;


fn main() -> Result<(), DuckyError> {
let args: Args = Args::new();

if !args.transpile && !args.compile {
println!("[ERROR] Must provide a compilation type.\nRun rusty_ducky with the -h flag to see more info.\nEx: ./rusty_ducky -h");
return Ok(());
}

let report_buf = match parse_payload(&args) {
Ok(r) => r,
Err(e) => {println!("{:?}", e); vec![[0, 0, 0, 0, 0, 0, 0, 0]]}
};
let report_buf = parse_payload(&args)?;

if args.transpile { transpile(&args, &report_buf)? }
if args.compile { todo!() }
//if args.compile { todo!() }

Ok(())

Expand Down
45 changes: 23 additions & 22 deletions src/transpiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ impl Args {
{
let app = App::new("rusty_ducky")
.version("0.4")
.about("A Rust transpiler and compiler for keystroke injections on imbedded devices.")
.about("rusty_ducky is a DuckyScript keystroke injection toolkit for microcontrollers that support Circuit Python.")
.author("Carter Vavra");

let payload_file_option = Arg::new("payload")
.long("payload")
.short('p')
.takes_value(true)
.help("Points rusty ducky to a payload file to transpile.\nDefault is payload.txt")
.help("Points rusty ducky to a payload file to transpile.")
.default_value("payload.txt")
.required(false);
let app = app.arg(payload_file_option);
Expand All @@ -63,7 +63,7 @@ impl Args {
.long("output")
.short('o')
.takes_value(true)
.help("Specify a name for the transpiled cuircut python file.")
.help("Specify a name for the transpiled circuit python file.")
.default_value("Code.py")
.required(false);
let app = app.arg(output_file_option);
Expand All @@ -77,21 +77,21 @@ impl Args {
.required(false);
let app = app.arg(keyboard_language_option);

let compile_option = Arg::new("compile")
.long("compile")
.short('c')
.takes_value(false)
.help("Tells rusty ducky to compile the payload file. [NOT IMPLEMENTED YET!]")
.required(false);
let app = app.arg(compile_option);

let transpile_option = Arg::new("transpile")
.long("transpile")
.short('t')
.takes_value(false)
.help("Tells rusty ducky to transpile the payload file to cuircut python.")
.required(false);
let app = app.arg(transpile_option);
// let compile_option = Arg::new("compile")
// .long("compile")
// .short('c')
// .takes_value(false)
// .help("Tells rusty ducky to compile the payload file. [NOT IMPLEMENTED YET!]")
// .required(false);
// let app = app.arg(compile_option);

// let transpile_option = Arg::new("transpile")
// .long("transpile")
// .short('t')
// .takes_value(false)
// .help("Tells rusty ducky to transpile the payload file to cuircut python.")
// .required(false);
// let app = app.arg(transpile_option);

let verbose_option = Arg::new("verbose")
.long("verbose")
Expand All @@ -113,8 +113,8 @@ impl Args {
.value_of("language")
.unwrap();
let verbose = matches.is_present("verbose");
let compiled = matches.is_present("compile");
let transpiled = matches.is_present("transpile");
//let compiled = matches.is_present("compile");
//let transpiled = matches.is_present("transpile");

let mut template: Option<String> = None;
if matches.is_present("template") { template = Some(matches.value_of("template").unwrap().to_string())}
Expand All @@ -124,8 +124,9 @@ impl Args {
output_file: output_file.to_string(),
template_file: template,
keyboard_language: keyboard_language.to_string(),
compile: compiled,
transpile: transpiled,
// change when compile is implemented
compile: false,
transpile: true,
verbose: verbose
} )
}
Expand Down
3 changes: 1 addition & 2 deletions src/transpiler/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use crate::DuckyError;
use super::{KeyCode, KeyReport, RELEASE, Args};

fn load_layout(args: &Args) -> Result<Value, DuckyError> {
let file_location: String = format!("keyboard_layouts/{}.json", &args.keyboard_language.to_uppercase());
let layout_file = match File::open(file_location) {
let layout_file = match File::open(&args.keyboard_language) {
Ok(f) => Ok(f),
Err(e) => {
let verbose_error = format!("{}", e);
Expand Down

0 comments on commit fe5b46b

Please sign in to comment.