cli: dump non-upgradeable programs (#15598) (#15612)

(cherry picked from commit fbb1012584)

Co-authored-by: Jack May <jack@solana.com>
This commit is contained in:
mergify[bot]
2021-03-01 22:23:46 -08:00
committed by GitHub
parent c82c750091
commit f0afbf4948

View File

@ -988,6 +988,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()
@ -999,13 +1004,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(
@ -1022,6 +1031,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())
} }