Expand description
Fetch a Solana on-chain program and return its raw ELF
bytes. Strips the loader-state header so the resulting bytes
feed straight into ud_translate::decompile::decompile.
Solana stores SBF programs under one of three loaders, each with its own account-data layout:
BPFLoader2111…(non-upgradeable, legacy). The program’s account data IS the ELF — no header to strip.BPFLoaderUpgradeab1e…(today’s default). Two accounts: the Program account holds a 36-byteUpgradeableLoaderState::Program(a Borsh enum tag of 2 plus a 32-byte pubkey pointing at the ProgramData account). The ProgramData account starts with anUpgradeableLoaderState::ProgramDataheader (45 bytes when an upgrade authority is set, 13 bytes when it’sNone) followed by the ELF.LoaderV411…(Agave’s newer loader). ALoaderV4Stateof 48 bytes (slot + authority pubkey + 8-byte status) followed by the ELF.
All three are recognised here. The strip routine validates
that the bytes immediately after the header carry the ELF
magic (\x7fELF), so a mismatched layout fails loudly
rather than producing garbage.
Fetching uses Solana’s standard JSON-RPC getAccountInfo
method against a public mainnet endpoint by default; the
caller can override with --rpc. Fetched ELFs are cached
under ~/.cache/univdreams/solana/ keyed by program ID
(and, for upgradeable programs, the ProgramData slot —
upgrades invalidate the cache).
Constants§
- DEFAULT_
RPC - Default RPC endpoint when
--rpcisn’t given. Solana’s public mainnet endpoint — heavily rate-limited but the universally-known fallback.
Functions§
- fetch_
program_ elf - Fetch the raw ELF bytes for
program_id, caching under~/.cache/univdreams/solana/. Withuse_cache = false, the cached copy is ignored and overwritten.