mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Detect universal binaries and +x them
This commit is contained in:
7
src/Rust/Cargo.lock
generated
7
src/Rust/Cargo.lock
generated
@@ -122,12 +122,6 @@ version = "0.21.7"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bindet"
|
|
||||||
version = "0.3.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5afee99ef5f7527f3944f2bf4f5d443749fa47d43eb1d4f83a36e839be7900a3"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
@@ -1575,7 +1569,6 @@ name = "velopack"
|
|||||||
version = "0.0.0-local"
|
version = "0.0.0-local"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bindet",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"derivative",
|
"derivative",
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ time = "0.3"
|
|||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
native-dialog = "0.7"
|
native-dialog = "0.7"
|
||||||
waitpid-any = "0.2"
|
waitpid-any = "0.2"
|
||||||
bindet = "0.3"
|
|
||||||
dialog = "0.3"
|
dialog = "0.3"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
|
||||||
|
|||||||
@@ -305,21 +305,11 @@ impl BundleInfo<'_> {
|
|||||||
// on macos, we need to chmod +x the executable files
|
// on macos, we need to chmod +x the executable files
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
if let Ok(file) = std::fs::OpenOptions::new().read(true).open(&file_path_on_disk) {
|
if let Ok(true) = super::macho::is_macho_image(&file_path_on_disk) {
|
||||||
let buf = std::io::BufReader::new(file);
|
if let Err(e) = std::fs::set_permissions(&file_path_on_disk, std::fs::Permissions::from_mode(0o755)) {
|
||||||
if let Ok(det) = bindet::detect(buf).map_err(|e| e.kind()) {
|
warn!("Failed to set executable permissions on '{}': {}", file_path_on_disk.to_string_lossy(), e);
|
||||||
if let Some(matches) = det {
|
} else {
|
||||||
for m in matches.likely_to_be {
|
info!(" {} Set executable permissions on '{}'", i, file_path_on_disk.to_string_lossy());
|
||||||
if m == bindet::FileType::Mach {
|
|
||||||
if let Err(e) = std::fs::set_permissions(&file_path_on_disk, std::fs::Permissions::from_mode(0o755)) {
|
|
||||||
warn!("Failed to set executable permissions on '{}': {}", file_path_on_disk.to_string_lossy(), e);
|
|
||||||
} else {
|
|
||||||
info!(" {} Set executable permissions on '{}'", i, file_path_on_disk.to_string_lossy());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
44
src/Rust/src/shared/macho.rs
Normal file
44
src/Rust/src/shared/macho.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, Read};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
enum MagicMachO {
|
||||||
|
MH_MAGIC = 0xfeedface,
|
||||||
|
MH_CIGAM = 0xcefaedfe,
|
||||||
|
MH_MAGIC_64 = 0xfeedfacf,
|
||||||
|
MH_CIGAM_64 = 0xcffaedfe,
|
||||||
|
// https://developer.apple.com/documentation/kernel/fat_header/1558632-magic/
|
||||||
|
// https://opensource.apple.com/source/file/file-80.40.2/file/magic/Magdir/cafebabe.auto.html
|
||||||
|
FAT_MAGIC = 0xcafebabe,
|
||||||
|
FAT_CIGAM = 0xbebafeca,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MagicMachO {
|
||||||
|
fn from_u32(value: u32) -> Option<Self> {
|
||||||
|
match value {
|
||||||
|
0xfeedface => Some(MagicMachO::MH_MAGIC),
|
||||||
|
0xcefaedfe => Some(MagicMachO::MH_CIGAM),
|
||||||
|
0xfeedfacf => Some(MagicMachO::MH_MAGIC_64),
|
||||||
|
0xcffaedfe => Some(MagicMachO::MH_CIGAM_64),
|
||||||
|
0xcafebabe => Some(MagicMachO::FAT_MAGIC),
|
||||||
|
0xbebafeca => Some(MagicMachO::FAT_CIGAM),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_macho_image<P: AsRef<Path>>(file_path: P) -> io::Result<bool> {
|
||||||
|
let file_path = file_path.as_ref();
|
||||||
|
let mut file = File::open(file_path)?;
|
||||||
|
let mut buffer = [0; 4];
|
||||||
|
|
||||||
|
if file.metadata()?.len() < 256 {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
file.read_exact(&mut buffer)?;
|
||||||
|
let magic = u32::from_be_bytes(buffer);
|
||||||
|
Ok(MagicMachO::from_u32(magic).is_some())
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
pub mod bundle;
|
pub mod bundle;
|
||||||
pub mod download;
|
pub mod download;
|
||||||
|
pub mod macho;
|
||||||
|
|
||||||
mod dialogs_const;
|
mod dialogs_const;
|
||||||
mod dialogs_common;
|
mod dialogs_common;
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ public class MachO
|
|||||||
MH_MAGIC = 0xfeedface,
|
MH_MAGIC = 0xfeedface,
|
||||||
MH_CIGAM = 0xcefaedfe,
|
MH_CIGAM = 0xcefaedfe,
|
||||||
MH_MAGIC_64 = 0xfeedfacf,
|
MH_MAGIC_64 = 0xfeedfacf,
|
||||||
MH_CIGAM_64 = 0xcffaedfe
|
MH_CIGAM_64 = 0xcffaedfe,
|
||||||
|
// https://developer.apple.com/documentation/kernel/fat_header/1558632-magic/
|
||||||
|
// https://opensource.apple.com/source/file/file-80.40.2/file/magic/Magdir/cafebabe.auto.html
|
||||||
|
FAT_MAGIC = 0xcafebabe,
|
||||||
|
FAT_CIGAM = 0xbebafeca,
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsMachOImage(string filePath)
|
public static bool IsMachOImage(string filePath)
|
||||||
|
|||||||
Reference in New Issue
Block a user