@@ -9,6 +9,10 @@ use heimdall_config::parse_url_arg;
9
9
after_help = "For more information, read the wiki: https://jbecker.dev/r/heimdall-rs/wiki" ,
10
10
override_usage = "heimdall disassemble <TARGET> [OPTIONS]"
11
11
) ]
12
+ /// Arguments for the disassembly operation
13
+ ///
14
+ /// This struct contains all the configuration parameters needed to disassemble
15
+ /// a contract's bytecode into human-readable assembly.
12
16
pub struct DisassemblerArgs {
13
17
/// The target to disassemble, either a file, bytecode, contract address, or ENS name.
14
18
#[ clap( required = true ) ]
@@ -33,6 +37,10 @@ pub struct DisassemblerArgs {
33
37
}
34
38
35
39
#[ derive( Debug , Clone ) ]
40
+ /// Builder for DisassemblerArgs
41
+ ///
42
+ /// This struct provides a builder pattern for creating DisassemblerArgs instances
43
+ /// with a fluent API.
36
44
pub struct DisassemblerArgsBuilder {
37
45
/// The target to disassemble, either a file, bytecode, contract address, or ENS name.
38
46
target : Option < String > ,
@@ -51,6 +59,13 @@ pub struct DisassemblerArgsBuilder {
51
59
}
52
60
53
61
impl DisassemblerArgs {
62
+ /// Retrieves the bytecode for the specified target
63
+ ///
64
+ /// This method fetches the bytecode from a file, address, or directly from a hex string,
65
+ /// depending on the target type provided in the arguments.
66
+ ///
67
+ /// # Returns
68
+ /// The raw bytecode as a vector of bytes
54
69
pub async fn get_bytecode ( & self ) -> Result < Vec < u8 > > {
55
70
get_bytecode_from_target ( & self . target , & self . rpc_url ) . await
56
71
}
@@ -63,6 +78,7 @@ impl Default for DisassemblerArgsBuilder {
63
78
}
64
79
65
80
impl DisassemblerArgsBuilder {
81
+ /// Creates a new DisassemblerArgsBuilder with default values
66
82
pub fn new ( ) -> Self {
67
83
Self {
68
84
target : Some ( String :: new ( ) ) ,
@@ -73,31 +89,40 @@ impl DisassemblerArgsBuilder {
73
89
}
74
90
}
75
91
92
+ /// Sets the target for disassembly (address, file, or bytecode)
76
93
pub fn target ( & mut self , target : String ) -> & mut Self {
77
94
self . target = Some ( target) ;
78
95
self
79
96
}
80
97
98
+ /// Sets the RPC URL for fetching bytecode if the target is an address
81
99
pub fn rpc_url ( & mut self , rpc_url : String ) -> & mut Self {
82
100
self . rpc_url = Some ( rpc_url) ;
83
101
self
84
102
}
85
103
104
+ /// Sets whether to use decimal (true) or hexadecimal (false) for program counter
86
105
pub fn decimal_counter ( & mut self , decimal_counter : bool ) -> & mut Self {
87
106
self . decimal_counter = Some ( decimal_counter) ;
88
107
self
89
108
}
90
109
110
+ /// Sets the name for the output file
91
111
pub fn name ( & mut self , name : String ) -> & mut Self {
92
112
self . name = Some ( name) ;
93
113
self
94
114
}
95
115
116
+ /// Sets the output directory or 'print' to print to console
96
117
pub fn output ( & mut self , output : String ) -> & mut Self {
97
118
self . output = Some ( output) ;
98
119
self
99
120
}
100
121
122
+ /// Builds the DisassemblerArgs from the builder
123
+ ///
124
+ /// # Returns
125
+ /// A Result containing the built DisassemblerArgs or an error if required fields are missing
101
126
pub fn build ( & self ) -> eyre:: Result < DisassemblerArgs > {
102
127
Ok ( DisassemblerArgs {
103
128
target : self . target . clone ( ) . ok_or_else ( || eyre:: eyre!( "target is required" ) ) ?,
0 commit comments