-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from FuzzingLabs/feat/decompiler_output
Improve decompiler output
- Loading branch information
Showing
8 changed files
with
185 additions
and
55 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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,44 @@ | ||
use lazy_static::lazy_static; | ||
use regex::Regex; | ||
|
||
lazy_static! { | ||
/// Those libfuncs id patterns are blacklisted from the regular decompiler output (not the verbose) | ||
/// to make it more readable | ||
/// | ||
/// We use lazy_static for performances issues | ||
// Variable drop | ||
pub static ref DROP_REGEX: Regex = Regex::new(r"drop(<.*>)?").unwrap(); | ||
|
||
// Store temporary variable | ||
pub static ref STORE_TEMP_REGEX: Regex = Regex::new(r"store_temp(<.*>)?").unwrap(); | ||
|
||
/// These are libfuncs id patterns whose representation in the decompiler output can be improved | ||
// User defined function call | ||
pub static ref FUNCTION_CALL_REGEX: Regex = Regex::new(r"function_call<(.*)>").unwrap(); | ||
|
||
// Arithmetic operations | ||
pub static ref ADDITION_REGEX: Regex = Regex::new(r"(felt|u)_?(8|16|32|64|128|252)(_overflowing)?_add").unwrap(); | ||
pub static ref SUBSTRACTION_REGEX: Regex = Regex::new(r"(felt|u)_?(8|16|32|64|128|252)(_overflowing)?_sub").unwrap(); | ||
pub static ref MULTIPLICATION_REGEX: Regex = Regex::new(r"(felt|u)_?(8|16|32|64|128|252)(_overflowing)?_mul").unwrap(); | ||
|
||
// Variable duplication | ||
pub static ref DUP_REGEX: Regex = Regex::new(r"dup(<.*>)?").unwrap(); | ||
|
||
// Variable renaming | ||
pub static ref VARIABLE_ASSIGNMENT_REGEX: Vec<Regex> = vec![ | ||
Regex::new(r"rename<.+>").unwrap(), | ||
Regex::new(r"store_temp<.+>").unwrap() | ||
]; | ||
|
||
// Check if an integer is 0 | ||
pub static ref IS_ZERO_REGEX: Regex = Regex::new(r"(felt|u)_?(8|16|32|64|128|252)_is_zero").unwrap(); | ||
|
||
// Consts declarations | ||
pub static ref CONST_REGEXES: Vec<Regex> = vec![ | ||
Regex::new(r"const_as_immediate<Const<.+, (?P<const>-?[0-9]+)>>").unwrap(), | ||
Regex::new(r"storage_base_address_const<(?P<const>-?[0-9]+)>").unwrap(), | ||
Regex::new(r"(felt|u)_?(8|16|32|64|128|252)_const<(?P<const>-?[0-9]+)>").unwrap(), | ||
]; | ||
} |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
pub mod cfg; | ||
pub mod decompiler; | ||
pub mod function; | ||
pub mod libfuncs_patterns; | ||
pub mod macros; | ||
pub mod utils; |
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 @@ | ||
use num_bigint::BigInt; | ||
use std::str; | ||
|
||
/// Convert an integer to it's string value or hex value | ||
/// Used to decode consts | ||
pub fn decode_hex_bigint(bigint: &BigInt) -> Option<String> { | ||
// Convert the BigInt to a hexadecimal string | ||
let hex_string = format!("{:x}", bigint); | ||
|
||
// Decode the hexadecimal string to a byte vector | ||
let bytes = hex::decode(hex_string.clone()).ok()?; | ||
|
||
// Convert the byte vector to a string or hex value | ||
let string = match str::from_utf8(&bytes) { | ||
Ok(s) => Some(s.to_string()), | ||
Err(_) => Some(format!("0x{hex_string}")), | ||
}; | ||
|
||
string | ||
} |
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