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,39 +998,51 @@ fn process_dump(
.get_account_with_commitment(&account_pubkey, config.commitment)? .get_account_with_commitment(&account_pubkey, config.commitment)?
.value .value
{ {
if let Ok(UpgradeableLoaderState::Program { if account.owner == bpf_loader::id() || account.owner == bpf_loader_deprecated::id() {
programdata_address, let mut f = File::create(output_location)?;
}) = account.state() f.write_all(&account.data)?;
{ Ok(format!("Wrote program to {}", output_location))
if let Some(programdata_account) = rpc_client } else if account.owner == bpf_loader_upgradeable::id() {
.get_account_with_commitment(&programdata_address, config.commitment)? if let Ok(UpgradeableLoaderState::Program {
.value programdata_address,
}) = account.state()
{ {
if let Ok(UpgradeableLoaderState::ProgramData { .. }) = if let Some(programdata_account) = rpc_client
programdata_account.state() .get_account_with_commitment(&programdata_address, config.commitment)?
.value
{ {
let offset = UpgradeableLoaderState::programdata_data_offset().unwrap_or(0); if let Ok(UpgradeableLoaderState::ProgramData { .. }) =
let program_data = &programdata_account.data[offset..]; programdata_account.state()
let mut f = File::create(output_location)?; {
f.write_all(&program_data)?; let offset =
Ok(format!("Wrote program to {}", output_location)) UpgradeableLoaderState::programdata_data_offset().unwrap_or(0);
let program_data = &programdata_account.data[offset..];
let mut f = File::create(output_location)?;
f.write_all(&program_data)?;
Ok(format!("Wrote program to {}", output_location))
} else {
Err(
"Invalid associated ProgramData account found for the program"
.into(),
)
}
} else { } else {
Err("Invalid associated ProgramData account found for the program".into()) Err(
}
} else {
Err(
"Failed to find associated ProgramData account for the provided program" "Failed to find associated ProgramData account for the provided program"
.into(), .into(),
) )
}
} else if let Ok(UpgradeableLoaderState::Buffer { .. }) = account.state() {
let offset = UpgradeableLoaderState::buffer_data_offset().unwrap_or(0);
let program_data = &account.data[offset..];
let mut f = File::create(output_location)?;
f.write_all(&program_data)?;
Ok(format!("Wrote program to {}", output_location))
} else {
Err("Not a buffer or program account".into())
} }
} else if let Ok(UpgradeableLoaderState::Buffer { .. }) = account.state() {
let offset = UpgradeableLoaderState::buffer_data_offset().unwrap_or(0);
let program_data = &account.data[offset..];
let mut f = File::create(output_location)?;
f.write_all(&program_data)?;
Ok(format!("Wrote program to {}", output_location))
} else { } else {
Err("Not a buffer or program account".into()) Err("Accont is not a BPF program".into())
} }
} else { } else {
Err("Unable to find the account".into()) Err("Unable to find the account".into())