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
13 changes: 8 additions & 5 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ jobs:
shell: bash
run: RUSTFLAGS="-D warnings" cargo check --workspace

# fails due to `_Unwind_RaiseException`
# - name: Run cargo test
# shell: bash
# run: RUSTFLAGS="-D warnings" cargo test --workspace
- name: Run cargo test
shell: bash
run: RUSTFLAGS="-D warnings" cargo test --workspace --target 'x86_64-unknown-linux-gnu'

- name: Run cargo build (release)
run: cargo build --verbose --release
run: cargo build --verbose --release --package 'zipfixup' --package 'zippatch'
shell: bash

- name: Run export checker
run: cargo run --package 'export-check' --target 'x86_64-unknown-linux-gnu'
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
run: rustup show

- name: Build release binary
run: cargo build --verbose --release
run: cargo build --verbose --release --package 'zipfixup' --package 'zippatch'
shell: bash

- name: Build archive
Expand Down
73 changes: 73 additions & 0 deletions Cargo.lock

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

15 changes: 15 additions & 0 deletions crates/export-check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "export-check"
version.workspace = true

description.workspace = true
authors.workspace = true
repository.workspace = true
readme.workspace = true
license.workspace = true

edition.workspace = true
publish.workspace = true

[dependencies]
object = "0.37.1"
133 changes: 133 additions & 0 deletions crates/export-check/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
use object::read::pe::{ExportTarget, PeFile32};

const EXPECTED_EXPORTS: &[&str] = &["DllMain", "GetTickCount"];
const EXPECTED_FORWARDS: &[&str] = &[
"CloseHandle",
"CompareFileTime",
"CreateDirectoryA",
"CreateEventA",
"CreateFileA",
"CreateMutexA",
"CreateThread",
"DeleteCriticalSection",
"DeleteFileA",
"EnterCriticalSection",
"EnumResourceNamesA",
"ExitProcess",
"FindClose",
"FindFirstFileA",
"FindNextFileA",
"FindResourceExA",
"FormatMessageA",
"FreeLibrary",
"GetCommandLineA",
"GetCurrentDirectoryA",
"GetCurrentThread",
"GetDriveTypeA",
"GetFileSize",
"GetFileTime",
"GetLastError",
"GetLogicalDriveStringsA",
"GetModuleHandleA",
"GetProcAddress",
"GetStartupInfoA",
"GetSystemDefaultLangID",
"GetTempPathA",
"GetThreadPriority",
"GetVersionExA",
"GlobalMemoryStatus",
"InitializeCriticalSection",
"InterlockedDecrement",
"InterlockedIncrement",
"LeaveCriticalSection",
"LoadLibraryA",
"LoadResource",
"LocalFree",
"LockResource",
"lstrlenA",
"MoveFileA",
"OutputDebugStringA",
"OutputDebugStringW",
"QueryPerformanceCounter",
"QueryPerformanceFrequency",
"ReadFile",
"ReleaseMutex",
"ResetEvent",
"SetCurrentDirectoryA",
"SetEvent",
"SetFilePointer",
"SetThreadPriority",
"SizeofResource",
"Sleep",
"WaitForMultipleObjects",
"WaitForSingleObject",
"WriteFile",
];

fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let contents = std::fs::read("target/i686-pc-windows-gnu/release/zipfixup.dll")?;
let data = contents.as_slice();

let pe = PeFile32::parse(data)?;
let table = pe.export_table()?.ok_or("no export table")?;
let exported = table.exports()?;

let mut exports = Vec::new();
let mut forwards = Vec::new();
for export in &exported {
let name = export
.name
.ok_or_else(|| format!("export has no name: {:?}", export))?;
let name = str::from_utf8(name)?;

match export.target {
ExportTarget::ForwardByName(module, forward) => {
if module != b"KERNEL32" {
return Err(format!("expected forward to KERNEL32: {:?}", export).into());
}
if name.as_bytes() != forward {
return Err(format!(
"forward name mismatch `{}` != `{}`",
name,
forward.escape_ascii()
)
.into());
}
forwards.push(name);
}
ExportTarget::Address(_addr) => {
exports.push(name);
}
ExportTarget::ForwardByOrdinal(module, _ordinal) => {
if module != b"KERNEL32" {
return Err(format!("expected forward to KERNEL32: {:?}", export).into());
}
return Err(format!("unexpected forward by ordinal: {:?}", export).into());
}
}
}
exports.sort();
forwards.sort();

for name in exports.iter().copied() {
println!("{}", name);
}

for name in forwards.iter().copied() {
println!("KERNEL32.{}", name);
}

for expected in EXPECTED_EXPORTS {
if !exports.contains(expected) {
return Err(format!("missing export `{}`", expected).into());
}
}

for expected in EXPECTED_FORWARDS {
if !forwards.contains(expected) {
return Err(format!("missing forward `{}`", expected).into());
}
}

Ok(())
}
Loading