Skip to content

Commit

Permalink
Display strings in disassembler
Browse files Browse the repository at this point in the history
  • Loading branch information
tzakian committed Sep 25, 2023
1 parent 64df54b commit dd11fb1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions external-crates/move/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions external-crates/move/tools/move-disassembler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ move-binary-format = { path = "../../move-binary-format" }
move-coverage = { path = "../move-coverage" }
move-compiler = { path = "../../move-compiler" }

bcs.workspace = true
clap.workspace = true
hex = "0.4.3"

Expand Down
13 changes: 12 additions & 1 deletion external-crates/move/tools/move-disassembler/src/disassembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,19 @@ impl<'a> Disassembler<'a> {
constant_index: usize,
Constant { type_, data }: &Constant,
) -> Result<String> {
let data_str = match type_ {
SignatureToken::Vector(x) if x.as_ref() == &SignatureToken::U8 => {
match bcs::from_bytes::<Vec<u8>>(data)
.ok()
.and_then(|data| String::from_utf8(data).ok())
{
Some(str) => "\"".to_owned() + &str + "\" // interpreted as UTF8 string",
None => hex::encode(data),
}
}
_ => hex::encode(data),
};
let type_str = self.disassemble_sig_tok(type_.clone(), &[])?;
let data_str = hex::encode(data);
Ok(format!("\t{constant_index} => {}: {}", type_str, data_str))
}

Expand Down

0 comments on commit dd11fb1

Please sign in to comment.