pub enum Token {
StringExpandable(StringExpandableToken),
String(String),
Expression(ExpressionToken),
Method(MethodToken),
Command(CommandToken),
}Expand description
Represents a parsed token from a PowerShell script.
Tokens are the building blocks of parsed PowerShell code and are used for syntax analysis, deobfuscation, and code transformation.
Right now 4 token types are supported:
- String: Representation of single quoted PowerShell strings (e.g.,
'hello world') - StringExpandable: Representation of double quoted PowerShell strings
with variable expansion (e.g.,
"Hello $name") - Expression: Parsed PowerShell expressions with their evaluated results
(e.g.,
$a + $b) - Function: PowerShell function definitions and calls
Each token type stores both the original source code and its processed/evaluated form, making it useful for deobfuscation and analysis purposes.
§Examples
use ps_parser::PowerShellSession;
let mut session = PowerShellSession::new();
let script_result = session.parse_input("$var = 123").unwrap();
// Inspect the tokens
for token in script_result.tokens().all() {
println!("Token: {:?}", token);
}Variants§
StringExpandable(StringExpandableToken)
String(String)
Expression(ExpressionToken)
Method(MethodToken)
Command(CommandToken)
Implementations§
Source§impl Token
impl Token
pub fn method( token: String, self_: PsValue, name: String, arguments: Vec<PsValue>, ) -> Self
pub fn command(token: String, name: String, arguments: Vec<String>) -> Self
pub fn expression(token: String, value: PsValue) -> Self
pub fn string_expandable(token: String, value: String) -> Self
Trait Implementations§
impl StructuralPartialEq for Token
Auto Trait Implementations§
impl Freeze for Token
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnwindSafe for Token
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more