1
- use std:: path:: PathBuf ;
1
+ use std:: path:: { Path , PathBuf } ;
2
2
3
3
macro_rules! exit {
4
4
( $code: expr => $( $arg: tt) * ) => { {
@@ -13,51 +13,28 @@ USAGE: bite [options] <OBJECT>
13
13
14
14
OPTIONS:
15
15
-H, --help Print usage information
16
- -L, --libs Print linked shared libraries
17
- -N, --names Print all symbols exposed by object
18
- -S, --simplify Replace common types with shortened paths
19
16
-D, --disassemble Path to object you're disassembling
20
- -T, --tracing Trace all syscalls performed
21
17
-C, --config Path to config used for disassembling
22
- -B, --debug Enable extra debug information " ;
18
+ -B, --debug Enable verbose internal info " ;
23
19
24
- const ABBRV : & [ & str ] = & [ "-H" , "-L" , "-S" , "- D", "-C" , "-T ", "-B" ] ;
20
+ const ABBRV : & [ & str ] = & [ "-H" , "-D" , "-C" , "-B" ] ;
25
21
const NAMES : & [ & str ] = & [
26
22
"--help" ,
27
- "--libs" ,
28
- "--names" ,
29
- "--simplify" ,
30
23
"--disassemble" ,
31
- "--tracing" ,
32
24
"--config" ,
33
25
"--debug" ,
34
26
] ;
35
27
36
28
#[ derive( Default , Debug , Clone ) ]
37
29
pub struct Cli {
38
- /// Print shared libraries the object is linked against.
39
- pub libs : bool ,
40
-
41
- /// Print all symbols exposed by object.
42
- pub names : bool ,
43
-
44
- /// Strip symbols into a simpler format.
45
- pub simplify : bool ,
46
-
47
- /// Disassemble object into `readable` assembly,
48
- pub disassemble : bool ,
49
-
50
- /// Record syscalls.
51
- pub tracing : bool ,
52
-
53
- /// Show egui debug overlay.
54
- pub debug : bool ,
55
-
56
30
/// Path to symbol being disassembled.
57
- pub path : Option < PathBuf > ,
31
+ pub path : PathBuf ,
58
32
59
33
/// Optional path to config.
60
34
pub config : Option < PathBuf > ,
35
+
36
+ /// Show egui debug overlay.
37
+ pub debug : bool ,
61
38
}
62
39
63
40
impl Cli {
@@ -68,36 +45,32 @@ impl Cli {
68
45
while let Some ( arg) = args. next ( ) {
69
46
match arg. as_str ( ) {
70
47
"-H" | "--help" => exit ! ( 0 => "{HELP}" ) ,
71
- "-S" | "--simplify" => cli. simplify = true ,
72
- "-N" | "--names" => {
73
- cli. names = true ;
74
-
48
+ "-D" | "--disassemble" => {
75
49
if let Some ( path) = args. next ( ) . as_deref ( ) {
76
50
if !NAMES . contains ( & path) && !ABBRV . contains ( & path) {
77
- cli. path = Some ( PathBuf :: from ( path) ) ;
51
+ if cli. path != Path :: new ( "" ) {
52
+ exit ! ( 1 => "Path to object already given." ) ;
53
+ }
54
+ cli. path = PathBuf :: from ( path) ;
78
55
}
79
56
}
80
- }
81
- "-L" | "--libs" => {
82
- cli. libs = true ;
83
-
57
+ } ,
58
+ "-C" | "--config" => {
84
59
if let Some ( path) = args. next ( ) . as_deref ( ) {
85
60
if !NAMES . contains ( & path) && !ABBRV . contains ( & path) {
86
- cli. path = Some ( PathBuf :: from ( path) ) ;
61
+ if cli. config . is_some ( ) {
62
+ exit ! ( 1 => "Path to config already given." ) ;
63
+ }
64
+ cli. config = Some ( PathBuf :: from ( path) ) ;
87
65
}
88
66
}
89
- }
90
- "-D" | "--disassemble" => {
91
- cli. disassemble = true ;
92
-
93
- if let Some ( path) = args. next ( ) . as_deref ( ) {
94
- if !NAMES . contains ( & path) && !ABBRV . contains ( & path) {
95
- cli. path = Some ( PathBuf :: from ( path) ) ;
96
- }
67
+ } ,
68
+ "-B" | "--debug" => {
69
+ if cli. debug {
70
+ exit ! ( 1 => "Debug flag already set." ) ;
97
71
}
72
+ cli. debug = true
98
73
}
99
- "-T" | "--tracing" => cli. tracing = true ,
100
- "-B" | "--debug" => cli. debug = true ,
101
74
unknown => {
102
75
let mut distance = u32:: MAX ;
103
76
let mut best_guess = "" ;
@@ -124,22 +97,18 @@ impl Cli {
124
97
}
125
98
126
99
fn validate_args ( & mut self ) {
127
- if self . disassemble || self . libs || self . names {
128
- if self . path . is_none ( ) {
129
- exit ! ( 1 => "Missing path to an object." ) ;
130
- }
131
- } else {
132
- // no action arguments were given
133
- self . disassemble = true ;
134
- return ;
100
+ if self . path == Path :: new ( "" ) {
101
+ exit ! ( 1 => "You must provide a path to disassemble." ) ;
135
102
}
136
103
137
- if self . tracing && !self . disassemble {
138
- exit ! ( 1 => "Invalid combination of arguements. \n \n {HELP}" ) ;
104
+ if !self . path . exists ( ) {
105
+ exit ! ( 1 => "Object {:?} does not exist." , self . path ) ;
139
106
}
140
107
141
- if self . disassemble as usize + self . libs as usize + self . names as usize > 1 {
142
- exit ! ( 1 => "Invalid combination of arguements.\n \n {HELP}" ) ;
108
+ if let Some ( ref cfg) = self . config {
109
+ if !cfg. exists ( ) {
110
+ exit ! ( 1 => "Config {cfg:?} does not exist." ) ;
111
+ }
143
112
}
144
113
}
145
114
}
0 commit comments