@@ -8,7 +8,7 @@ use std::fmt;
8
8
9
9
#[ cfg( feature = "color" ) ]
10
10
use crate :: colorize_bool;
11
- // use crate::shared::{Rpath, VecRpath};
11
+ use crate :: shared:: { Rpath , VecRpath } ;
12
12
13
13
const MH_ALLOW_STACK_EXECUTION : u32 = 0x0002_0000 ;
14
14
const MH_PIE : u32 = 0x0020_0000 ;
@@ -55,8 +55,7 @@ pub struct CheckSecResults {
55
55
/// Restrict segment
56
56
pub restrict : bool ,
57
57
/// Load Command @rpath
58
- //rpath: VecRpath,
59
- pub rpath : bool ,
58
+ pub rpath : VecRpath ,
60
59
}
61
60
impl CheckSecResults {
62
61
#[ must_use]
@@ -127,8 +126,7 @@ impl fmt::Display for CheckSecResults {
127
126
"Restrict:" . bold( ) ,
128
127
colorize_bool!( self . restrict) ,
129
128
"RPath:" . bold( ) ,
130
- //self.rpath
131
- colorize_bool!( self . rpath)
129
+ self . rpath,
132
130
)
133
131
}
134
132
}
@@ -152,9 +150,9 @@ impl fmt::Display for CheckSecResults {
152
150
/// }
153
151
/// ```
154
152
pub trait Properties {
155
- /// check import names for `_objc_release`
153
+ /// check symbol names for `_objc_release` or `_swift_release `
156
154
fn has_arc ( & self ) -> bool ;
157
- /// check import names for `___stack_chk_fail` or `___stack_chk_guard `
155
+ /// check symbol names for `___stack_chk_fail` `___stack_chk_guard` or `___chkstk_darwin `
158
156
fn has_canary ( & self ) -> bool ;
159
157
/// check data size of code signature in load commands
160
158
fn has_code_signature ( & self ) -> bool ;
@@ -173,28 +171,25 @@ pub trait Properties {
173
171
fn has_pie ( & self ) -> bool ;
174
172
/// check for `___restrict` segment name
175
173
fn has_restrict ( & self ) -> bool ;
176
- //fn has_rpath(&self) -> VecRpath;
177
174
/// check for `RPath` in load commands
178
- fn has_rpath ( & self ) -> bool ;
175
+ fn has_rpath ( & self ) -> VecRpath ;
179
176
}
180
177
impl Properties for MachO < ' _ > {
181
178
fn has_arc ( & self ) -> bool {
182
- if let Ok ( imports) = self . imports ( ) {
183
- for import in & imports {
184
- if import. name == "_objc_release" {
185
- return true ;
186
- }
179
+ for ( symbol, _) in self . symbols ( ) . flatten ( ) {
180
+ match symbol {
181
+ "_objc_release" | "_swift_release" => return true ,
182
+ _ => continue ,
187
183
}
188
184
}
189
185
false
190
186
}
191
187
fn has_canary ( & self ) -> bool {
192
- if let Ok ( imports) = self . imports ( ) {
193
- for import in & imports {
194
- match import. name {
195
- "___stack_chk_fail" | "___stack_chk_guard" => return true ,
196
- _ => continue ,
197
- }
188
+ for ( symbol, _) in self . symbols ( ) . flatten ( ) {
189
+ match symbol {
190
+ "___stack_chk_fail" | "___stack_chk_guard"
191
+ | "___chkstk_darwin" => return true ,
192
+ _ => continue ,
198
193
}
199
194
}
200
195
false
@@ -264,18 +259,14 @@ impl Properties for MachO<'_> {
264
259
}
265
260
false
266
261
}
267
- //fn has_rpath(&self) -> VecRpath {
268
- fn has_rpath ( & self ) -> bool {
269
- // simply check for existence of @rpath command for now
270
- // parse out rpath entries similar to elf later
271
- // paths separated by `;` instead of `:` like the elf counterpart
272
- for loadcmd in & self . load_commands {
273
- if let CommandVariant :: Rpath ( _) = loadcmd. command {
274
- return true ;
275
- //return VecRpath::new(vec![Rpath::Yes("true".to_string())]);
276
- }
262
+ fn has_rpath ( & self ) -> VecRpath {
263
+ if self . rpaths . is_empty ( ) {
264
+ return VecRpath :: new ( vec ! [ Rpath :: None ] ) ;
277
265
}
278
- //VecRpath::new(vec![Rpath::None])
279
- false
266
+ let mut rpath_vec = Vec :: with_capacity ( self . rpaths . len ( ) ) ;
267
+ for i in & self . rpaths {
268
+ rpath_vec. push ( Rpath :: Yes ( ( * i) . to_string ( ) ) ) ;
269
+ }
270
+ VecRpath :: new ( rpath_vec)
280
271
}
281
272
}
0 commit comments