cli: dump non-upgradeable programs (#15598)

This commit is contained in:
Jack May 2021-03-01 18:11:45 -08:00 committed by GitHub
parent 55f357153a
commit fbb1012584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 25 deletions

View File

@ -998,6 +998,11 @@ fn process_dump(
.get_account_with_commitment(&account_pubkey, config.commitment)? .get_account_with_commitment(&account_pubkey, config.commitment)?
.value .value
{ {
if account.owner == bpf_loader::id() || account.owner == bpf_loader_deprecated::id() {
let mut f = File::create(output_location)?;
f.write_all(&account.data)?;
Ok(format!("Wrote program to {}", output_location))
} else if account.owner == bpf_loader_upgradeable::id() {
if let Ok(UpgradeableLoaderState::Program { if let Ok(UpgradeableLoaderState::Program {
programdata_address, programdata_address,
}) = account.state() }) = account.state()
@ -1009,13 +1014,17 @@ fn process_dump(
if let Ok(UpgradeableLoaderState::ProgramData { .. }) = if let Ok(UpgradeableLoaderState::ProgramData { .. }) =
programdata_account.state() programdata_account.state()
{ {
let offset = UpgradeableLoaderState::programdata_data_offset().unwrap_or(0); let offset =
UpgradeableLoaderState::programdata_data_offset().unwrap_or(0);
let program_data = &programdata_account.data[offset..]; let program_data = &programdata_account.data[offset..];
let mut f = File::create(output_location)?; let mut f = File::create(output_location)?;
f.write_all(&program_data)?; f.write_all(&program_data)?;
Ok(format!("Wrote program to {}", output_location)) Ok(format!("Wrote program to {}", output_location))
} else { } else {
Err("Invalid associated ProgramData account found for the program".into()) Err(
"Invalid associated ProgramData account found for the program"
.into(),
)
} }
} else { } else {
Err( Err(
@ -1032,6 +1041,9 @@ fn process_dump(
} else { } else {
Err("Not a buffer or program account".into()) Err("Not a buffer or program account".into())
} }
} else {
Err("Accont is not a BPF program".into())
}
} else { } else {
Err("Unable to find the account".into()) Err("Unable to find the account".into())
} }