Skip to content

Commit

Permalink
DotNet MetadataToken Wildcarding
Browse files Browse the repository at this point in the history
- Better DotNet MetadataToken wildcarding
- Does not wildcard the last byte as it is representing the table entry
in the stream
  • Loading branch information
c3rb3ru5d3d53c committed Dec 14, 2024
1 parent 2cb76ad commit d8929fd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/disassemblers/custom/cil/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ impl <'instruction> Instruction <'instruction> {

pub fn pattern(&self) -> String {
if self.is_wildcard() { return "??".repeat(self.size()); }
if self.is_metadata_token_wildcard_instruction() {
let mut pattern = Binary::to_hex(&self.mnemonic_bytes());
pattern.push_str(&"??".repeat(self.operand_size() - 1));
pattern.push_str(&Binary::to_hex(&vec![*self.operand_bytes().last().unwrap()]));
return pattern;
}
let mut pattern = Binary::to_hex(&self.mnemonic_bytes());
pattern.push_str(&"??".repeat(self.operand_size()));
pattern
Expand Down Expand Up @@ -330,6 +336,17 @@ impl <'instruction> Instruction <'instruction> {
}
}

pub fn is_metadata_token_wildcard_instruction(&self) -> bool {
match self.mnemonic {
Mnemonic::Call => true,
Mnemonic::CallVirt => true,
Mnemonic::LdSFld => true,
Mnemonic::LdFld => true,
Mnemonic::NewObj => true,
_ => false,
}
}

pub fn get_call_metadata_token(&self) -> Option<u32> {
if matches!(self.mnemonic, Mnemonic::Call | Mnemonic::CallVirt) {
let operand_bytes = self.operand_bytes();
Expand Down

0 comments on commit d8929fd

Please sign in to comment.