mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Document the functions the delay-load change touches
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
1e00b7e91c
commit
5272d227c6
3 files changed
+7
No files matched your search
@@ -5,6 +5,7 @@
|
||||
//! unless `PHOTOCRAFT_REQUIRE_WINRES=1` (set by the release packaging script) turns it into a
|
||||
//! build error.
|
||||
|
||||
/// Embeds the Windows resources and delay-loads the print-only system DLLs (#8272).
|
||||
fn main() -> std::io::Result<()> {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
println!("cargo:rerun-if-changed=../../assets/app-icon/photocraft.ico");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
//! cross-compile from macOS or Linux still links, unless `PHOTOCRAFT_REQUIRE_WINRES=1` (set by the
|
||||
//! release workflow) turns it into an error.
|
||||
|
||||
/// Embeds the Windows resources and delay-loads the print-only system DLLs (#5884, #8272).
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
println!("cargo:rerun-if-changed=../../assets/app-icon/photocraft.ico");
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
/// Loaded on first use by the print commands, which check them first.
|
||||
const PRINT_ONLY: [&str; 2] = ["windows.data.pdf.dll", "prntvpt.dll"];
|
||||
|
||||
/// The built exe names each print-only DLL in its delay-load table, never its import table.
|
||||
#[test]
|
||||
fn print_only_system_dlls_are_delay_loaded() {
|
||||
let exe = std::fs::read(env!("CARGO_BIN_EXE_photocraft")).unwrap();
|
||||
@@ -30,6 +31,7 @@ struct Pe<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Pe<'a> {
|
||||
/// Reads the PE headers and section table of a PE32+ image, panicking (a test) on any other.
|
||||
fn parse(bytes: &'a [u8]) -> Self {
|
||||
let pe = u32_at(bytes, 0x3c) as usize;
|
||||
assert_eq!(&bytes[pe..pe + 4], b"PE\0\0");
|
||||
@@ -48,6 +50,7 @@ impl<'a> Pe<'a> {
|
||||
Pe { bytes, sections, directories: optional + 112 }
|
||||
}
|
||||
|
||||
/// The file offset of relative virtual address `rva`, through the section that holds it.
|
||||
fn offset(&self, rva: u32) -> usize {
|
||||
let &(va, _, raw) = self.sections.iter().find(|&&(va, size, _)| rva >= va && rva < va + size).unwrap();
|
||||
(rva - va + raw) as usize
|
||||
@@ -73,10 +76,12 @@ impl<'a> Pe<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The little-endian `u16` at byte offset `at`.
|
||||
fn u16_at(b: &[u8], at: usize) -> u16 {
|
||||
u16::from_le_bytes([b[at], b[at + 1]])
|
||||
}
|
||||
|
||||
/// The little-endian `u32` at byte offset `at`.
|
||||
fn u32_at(b: &[u8], at: usize) -> u32 {
|
||||
u32::from_le_bytes([b[at], b[at + 1], b[at + 2], b[at + 3]])
|
||||
}
|
||||
Reference in new issue
Block a user