generated from PoCInnovation/open-source-project-template
-
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.
Merge pull request #24 from PoCInnovation/syntax_check
added real slightly better syntax checks and better error display
- Loading branch information
Showing
5 changed files
with
115 additions
and
45 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
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,28 @@ | ||
use super::Obfuscator; | ||
use super::Result; | ||
use std::process::Command; | ||
|
||
impl Obfuscator { | ||
pub fn is_syntax_ok(&self) -> Result<bool> { | ||
let cmd_status = Command::new("python3") | ||
.stdout(std::process::Stdio::null()) | ||
.stderr(std::process::Stdio::null()) | ||
.arg("-Bc") | ||
.arg(format!( | ||
"compile(r\'\'\'{}\'\'\',\"\", \"exec\")", | ||
self.code | ||
)) | ||
.status(); | ||
|
||
let cmd_res = match cmd_status { | ||
Ok(val) => val, | ||
Err(err) => return Err(super::error::ObfuscatorError::PythonSyntaxCheck(err)), | ||
}; | ||
|
||
if cmd_res.success() { | ||
Ok(true) | ||
} else { | ||
Ok(false) | ||
} | ||
} | ||
} |