Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 2 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ repository = "https://github.com/denoland/sui"
[dependencies]
image = { version = "0.25", default-features = false, features = ["bmp", "ico", "png"] }
libc = "0.2"
editpe = { version = "0.1.0", default-features = false }
# The PE resource writer was reduced from the unmaintained editpe crate into
# pe_edit.rs (see pe_edit.rs and LICENSE-editpe). Its resource writer miscomputed
# SizeOfImage; we own it now.
indexmap = "2.1"
thiserror = "1.0"
zerocopy = { version = "0.7", features = ["derive"] }
sha2 = "0.10"
object = { version = "=0.36.3", default-features = false, features = ["build", "read_core", "elf", "std"] }
Expand Down
20 changes: 20 additions & 0 deletions LICENSE-editpe
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2020 Christian Sdunek <me@systemcluster.me> and the editpe contributors

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials provided with
the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 changes: 14 additions & 11 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@
//! unpacker stub at startup. See the project README for per-format details.

use core::mem::size_of;
use editpe::{
constants::{CODE_PAGE_ID_EN_US, RT_GROUP_ICON, RT_ICON, RT_RCDATA},
types::{IconDirectory, IconDirectoryEntry},
ResourceData, ResourceEntry, ResourceEntryName, ResourceTable,
use pe_edit::{
IconDirectory, IconDirectoryEntry, ResourceData, ResourceEntry, ResourceEntryName,
ResourceTable, CODE_PAGE_ID_EN_US, RT_GROUP_ICON, RT_ICON, RT_RCDATA,
};
use image::{imageops::FilterType::Lanczos3, ImageFormat, ImageReader};
use std::io::Cursor;
Expand All @@ -82,6 +81,10 @@ use zerocopy::{AsBytes, FromBytes, FromZeroes};
pub mod apple_codesign;
pub mod intel_mac;

// libsui's own minimal PE resource writer, reduced from the BSD-2-Clause
// `editpe` crate. See pe_edit.rs and LICENSE-editpe.
mod pe_edit;

#[cfg(all(unix, not(target_vendor = "apple")))]
pub use elf::find_section;
#[cfg(all(unix, not(target_vendor = "apple")))]
Expand Down Expand Up @@ -133,18 +136,18 @@ impl std::error::Error for Error {}
/// Build a new PE from existing PE and write auxillary data as
/// a resource in the .rsrc section.
pub struct PortableExecutable<'a> {
image: editpe::Image<'a>,
resource_dir: editpe::ResourceDirectory,
image: pe_edit::Image<'a>,
resource_dir: pe_edit::ResourceDirectory,
icons: Vec<IconDirectoryEntry>,
}

impl<'a> PortableExecutable<'a> {
/// Parse from a PE file
pub fn from(data: &'a [u8]) -> Result<Self, Error> {
Ok(Self {
image: editpe::Image::parse(data)
image: pe_edit::Image::parse(data)
.map_err(|_| Error::InvalidObject("Failed to parse PE"))?,
resource_dir: editpe::ResourceDirectory::default(),
resource_dir: pe_edit::ResourceDirectory::default(),
icons: Vec::new(),
})
}
Expand All @@ -169,20 +172,20 @@ impl<'a> PortableExecutable<'a> {
};
let name = name.to_uppercase();
rc_table.insert(
editpe::ResourceEntryName::from_string(name.clone()),
pe_edit::ResourceEntryName::from_string(name.clone()),
ResourceEntry::Table(ResourceTable::default()),
);

let rc_table = match rc_table
.get_mut(editpe::ResourceEntryName::from_string(name))
.get_mut(pe_edit::ResourceEntryName::from_string(name))
.unwrap()
{
ResourceEntry::Table(table) => table,
ResourceEntry::Data(_) => {
return Err(Error::InvalidObject("Resource entry is not a table"));
}
};
let mut entry = editpe::ResourceData::default();
let mut entry = pe_edit::ResourceData::default();
entry.set_data(sectdata);

rc_table.insert(ResourceEntryName::ID(0), ResourceEntry::Data(entry));
Expand Down
Loading
Loading