pub struct Disassembler { /* private fields */ }Expand description
Parses Java class files into a structured reverse-engineering model.
The default instance uses RecoveryMode::BestEffort. It preserves a readable class-file
header and records a Diagnostic when complete decoding cannot continue.
Implementations§
Source§impl Disassembler
impl Disassembler
Sourcepub fn builder() -> DisassemblerBuilder
pub fn builder() -> DisassemblerBuilder
Creates a builder for configuring a disassembler.
The builder starts with RecoveryMode::BestEffort.
Sourcepub fn new(options: DisassemblerOptions) -> Self
pub fn new(options: DisassemblerOptions) -> Self
Creates a disassembler with the supplied options.
Sourcepub fn options(&self) -> &DisassemblerOptions
pub fn options(&self) -> &DisassemblerOptions
Returns the options used by this disassembler.
Sourcepub fn parse(&self, bytes: &[u8]) -> Result<Disassembly, FerroBabeError>
pub fn parse(&self, bytes: &[u8]) -> Result<Disassembly, FerroBabeError>
Parses one complete Java class-file byte sequence.
In best-effort mode, an error after the class-file header is read returns a partial
Disassembly with diagnostics. In strict mode, the same decoding failure is returned as
FerroBabeError. Invalid, incomplete, or unsupported headers always return an error.
§Errors
Returns an error when the input has no readable supported class-file header, or when strict recovery is selected and decoding fails.
Sourcepub fn parse_reader<R: Read>(
&self,
reader: R,
) -> Result<Disassembly, FerroBabeError>
pub fn parse_reader<R: Read>( &self, reader: R, ) -> Result<Disassembly, FerroBabeError>
Reads and parses one Java class file from reader.
The complete reader is buffered before parsing, so the returned Disassembly does not
borrow from reader.
§Errors
Returns FerroBabeError::InputRead when reading fails, or any error documented by
Self::parse after the bytes have been read.
Examples found in repository?
17fn run() -> Result<ExitCode, String> {
18 let path = class_path()?;
19 let file =
20 File::open(&path).map_err(|error| format!("could not open {}: {error}", path.display()))?;
21 let disassembly = Disassembler::default()
22 .parse_reader(file)
23 .map_err(|error| format!("could not parse {}: {error}", path.display()))?;
24
25 let version = disassembly.version();
26 let Some(class) = disassembly.class() else {
27 println!(
28 "partial class file v{}.{}",
29 version.major(),
30 version.minor()
31 );
32 for diagnostic in disassembly.diagnostics() {
33 print_diagnostic(diagnostic);
34 }
35 return Ok(ExitCode::from(2));
36 };
37
38 let output = FerroFormatter
39 .format(class)
40 .map_err(|error| format!("could not format {}: {error}", path.display()))?;
41 print!("{output}");
42
43 Ok(ExitCode::SUCCESS)
44}Sourcepub fn disassemble(&self, bytes: &[u8]) -> Result<String, FerroBabeError>
pub fn disassemble(&self, bytes: &[u8]) -> Result<String, FerroBabeError>
Parses bytes and renders a complete class with FerroFormatter.
§Errors
Returns parse errors, FerroBabeError::IncompleteDisassembly for a recovered partial
result, or a formatting error from the default formatter.
Sourcepub fn disassemble_with<F: Formatter>(
&self,
bytes: &[u8],
formatter: &F,
) -> Result<String, FerroBabeError>
pub fn disassemble_with<F: Formatter>( &self, bytes: &[u8], formatter: &F, ) -> Result<String, FerroBabeError>
Parses bytes and renders the resulting complete class with formatter.
formatter receives the same Class view available through Disassembly::class.
§Errors
Returns parse errors, FerroBabeError::IncompleteDisassembly for a partial result, or
FerroBabeError::Format when formatter cannot write its output.
Trait Implementations§
Source§impl Clone for Disassembler
impl Clone for Disassembler
Source§fn clone(&self) -> Disassembler
fn clone(&self) -> Disassembler
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more