Skip to content

Commit de2c270

Browse files
committed
port etke#45 by @titison
1 parent fa9132c commit de2c270

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ See [examples/](https://github.com/etke/checksec.rs/tree/master/examples) for li
141141
* Rpath RW
142142
* Platform independent checks
143143
* MachO
144-
* `@rpath` contents into `shared::VecRpath` similar to `DT_RPATH`/`DT_RUNPATH` on ELFs
145144
* Code signature validation
146145

147146
### checksec todos

src/macho.rs

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::fmt;
88

99
#[cfg(feature = "color")]
1010
use crate::colorize_bool;
11-
//use crate::shared::{Rpath, VecRpath};
11+
use crate::shared::{Rpath, VecRpath};
1212

1313
const MH_ALLOW_STACK_EXECUTION: u32 = 0x0002_0000;
1414
const MH_PIE: u32 = 0x0020_0000;
@@ -55,8 +55,7 @@ pub struct CheckSecResults {
5555
/// Restrict segment
5656
pub restrict: bool,
5757
/// Load Command @rpath
58-
//rpath: VecRpath,
59-
pub rpath: bool,
58+
pub rpath: VecRpath,
6059
}
6160
impl CheckSecResults {
6261
#[must_use]
@@ -127,8 +126,7 @@ impl fmt::Display for CheckSecResults {
127126
"Restrict:".bold(),
128127
colorize_bool!(self.restrict),
129128
"RPath:".bold(),
130-
//self.rpath
131-
colorize_bool!(self.rpath)
129+
self.rpath,
132130
)
133131
}
134132
}
@@ -152,9 +150,9 @@ impl fmt::Display for CheckSecResults {
152150
/// }
153151
/// ```
154152
pub trait Properties {
155-
/// check import names for `_objc_release`
153+
/// check symbol names for `_objc_release` or `_swift_release`
156154
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`
158156
fn has_canary(&self) -> bool;
159157
/// check data size of code signature in load commands
160158
fn has_code_signature(&self) -> bool;
@@ -173,28 +171,25 @@ pub trait Properties {
173171
fn has_pie(&self) -> bool;
174172
/// check for `___restrict` segment name
175173
fn has_restrict(&self) -> bool;
176-
//fn has_rpath(&self) -> VecRpath;
177174
/// check for `RPath` in load commands
178-
fn has_rpath(&self) -> bool;
175+
fn has_rpath(&self) -> VecRpath;
179176
}
180177
impl Properties for MachO<'_> {
181178
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,
187183
}
188184
}
189185
false
190186
}
191187
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,
198193
}
199194
}
200195
false
@@ -264,18 +259,14 @@ impl Properties for MachO<'_> {
264259
}
265260
false
266261
}
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]);
277265
}
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)
280271
}
281272
}

0 commit comments

Comments
 (0)