Skip to content

Commit ab04458

Browse files
authored
[move-diassembler][small] Display strings in disassembler (#13956)
## Description Tries to determine if a constant in the constant pool can be interpreted as a utf8 string. If it can it displays it as such, and adds a comment saying it's interpreted the data that way. ## Test Plan Tested locally: ```rust module 0x1::M { const X: vector<u8> = b"hello world"; public fun use_X(): vector<u8> { X } } ``` ```rust $ move disassemble --name M // Move bytecode v6 module 1.M { public use_X(): vector<u8> { B0: 0: LdConst[0](Vector(U8): 0b68656c..) 1: Ret } Constants [ 0 => vector<u8>: "hello world" // interpreted as UTF8 string ] } ``` --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [x] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes Updated display of constants in disassembled Move bytecode to try and show the deserialized string if the constant is a `vector<u8>` that is valid utf8.
1 parent 351a263 commit ab04458

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/move-disassembler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ move-binary-format = { path = "../../move-binary-format" }
1919
move-coverage = { path = "../move-coverage" }
2020
move-compiler = { path = "../../move-compiler" }
2121

22+
bcs.workspace = true
2223
clap.workspace = true
2324
hex = "0.4.3"
2425

tools/move-disassembler/src/disassembler.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,19 @@ impl<'a> Disassembler<'a> {
12601260
constant_index: usize,
12611261
Constant { type_, data }: &Constant,
12621262
) -> Result<String> {
1263+
let data_str = match type_ {
1264+
SignatureToken::Vector(x) if x.as_ref() == &SignatureToken::U8 => {
1265+
match bcs::from_bytes::<Vec<u8>>(data)
1266+
.ok()
1267+
.and_then(|data| String::from_utf8(data).ok())
1268+
{
1269+
Some(str) => "\"".to_owned() + &str + "\" // interpreted as UTF8 string",
1270+
None => hex::encode(data),
1271+
}
1272+
}
1273+
_ => hex::encode(data),
1274+
};
12631275
let type_str = self.disassemble_sig_tok(type_.clone(), &[])?;
1264-
let data_str = hex::encode(data);
12651276
Ok(format!("\t{constant_index} => {}: {}", type_str, data_str))
12661277
}
12671278

0 commit comments

Comments
 (0)