CodeSampleX

示例

object 0.37.3

已验证示例 — cargo object 0.37.3. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: FileKind parses binary headers to identify ELF64, ELF32, Mach-O and…

sha256:b360194d28e5afcd64dfae00d43580d7322e496bc66f8099ce01b03fb7994cf5

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux · alpine · musl x64 cargo

验证运行环境

环境 契约 阶段 运行日期
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-09-19

案例

HOW
目标
verify pkg:cargo/object@0.37.3
包
创建时间
2026-09-18T18:20:28Z

契约

  1. FileKind parses binary headers to identify ELF64, ELF32, Mach-O and Archive formats
  2. File parses ELF64 binaries and provides format, architecture, and endianness information
  3. File parses ELF32 binaries and provides format, architecture, and 32-bit classification
  4. File parses Mach-O 64-bit binaries and reports MachO format and architecture
  5. FileKind and File reject truncated or invalid binary data with an error

文件

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

下载源代码构件 (tar.gz)

源代码

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "adler2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"

[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"

[[package]]
name = "crc32fast"
version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01a7799fd6b852db0e61728dde9a204c423b44d689dbd432522543614b490e78"
dependencies = [
 "cfg-if",
]

[[package]]
name = "flate2"
version = "1.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb"
dependencies = [
 "crc32fast",
 "miniz_oxide",
 "zlib-rs",
]

[[package]]
name = "memchr"
version = "2.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"

[[package]]
name = "miniz_oxide"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
dependencies = [
 "adler2",
 "simd-adler32",
]

[[package]]
name = "object"
version = "0.37.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
dependencies = [
 "flate2",
 "memchr",
 "ruzstd",
]

[[package]]
name = "ruzstd"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7c1c839d570d835527c9a5e4db7cb2198683a988cb9d7293fc8674e6bd58fc8"
dependencies = [
 "twox-hash",
]

[[package]]
name = "sample-object"
version = "1.0.0"
dependencies = [
 "object",
]

[[package]]
name = "simd-adler32"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"

[[package]]
name = "twox-hash"
version = "2.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5283634e518fe9e82c7b20520bb4bc209009fd16c82077c802f8111ecbb0117a"

[[package]]
name = "zlib-rs"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
Cargo.toml
[package]
name = "sample-object"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
object = "=0.37.3"

[[bin]]
name = "contract"
path = "test/contract.rs"
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:cargo/object@0.37.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/object@0.37.3

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:8de5109a4cc1fb7af406597d6c76469667f1c0d4ed783944abfb1065c1acdecd","contract":["FileKind parses binary headers to identify ELF64, ELF32, Mach-O and Archive formats","File parses ELF64 binaries and provides format, architecture, and endianness information","File parses ELF32 binaries and provides format, architecture, and 32-bit classification","File parses Mach-O 64-bit binaries and reports MachO format and architecture","FileKind and File reject truncated or invalid binary data with an error"],"goal":"verify pkg:cargo/object@0.37.3","kind":"HOW","packages":["pkg:cargo/object@0.37.3"],"schemaVersion":1},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/object@0.37.3"],"schemaVersion":1,"subject":"pkg:cargo/object@0.37.3","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/object@0.37.3",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/object@0.37.3"
  ]
}
src/lib.rs
//! Clean-room verification sample for object.

pub use object::*;
test/contract.rs
use object::read::{File, Object};
use object::{Architecture, BinaryFormat, Endianness, FileKind};

fn main() {
    // 1. FileKind parses binary headers to identify ELF64, ELF32, Mach-O and Archive formats
    let mut elf64_hdr = vec![0u8; 64];
    elf64_hdr[0..4].copy_from_slice(b"\x7fELF");
    elf64_hdr[4] = 2; // ELFCLASS64
    elf64_hdr[5] = 1; // ELFDATA2LSB
    elf64_hdr[6] = 1; // EV_CURRENT
    elf64_hdr[16..18].copy_from_slice(&1u16.to_le_bytes()); // ET_REL
    elf64_hdr[18..20].copy_from_slice(&62u16.to_le_bytes()); // EM_X86_64
    elf64_hdr[20..24].copy_from_slice(&1u32.to_le_bytes()); // EV_CURRENT
    elf64_hdr[52..54].copy_from_slice(&64u16.to_le_bytes()); // e_ehsize = 64

    let mut elf32_hdr = vec![0u8; 52];
    elf32_hdr[0..4].copy_from_slice(b"\x7fELF");
    elf32_hdr[4] = 1; // ELFCLASS32
    elf32_hdr[5] = 1; // ELFDATA2LSB
    elf32_hdr[6] = 1; // EV_CURRENT
    elf32_hdr[16..18].copy_from_slice(&2u16.to_le_bytes()); // ET_EXEC
    elf32_hdr[18..20].copy_from_slice(&3u16.to_le_bytes()); // EM_386
    elf32_hdr[20..24].copy_from_slice(&1u32.to_le_bytes()); // EV_CURRENT
    elf32_hdr[40..42].copy_from_slice(&52u16.to_le_bytes()); // e_ehsize = 52

    let mut macho_hdr = vec![0u8; 32];
    macho_hdr[0..4].copy_from_slice(&0xfeedfacfu32.to_ne_bytes()); // MH_MAGIC_64
    macho_hdr[4..8].copy_from_slice(&0x01000007u32.to_ne_bytes()); // CPU_TYPE_X86_64
    macho_hdr[8..12].copy_from_slice(&3u32.to_ne_bytes()); // CPU_SUBTYPE_X86_64_ALL
    macho_hdr[12..16].copy_from_slice(&2u32.to_ne_bytes()); // MH_EXECUTE

    let mut arch_hdr = vec![0u8; 16];
    arch_hdr[..8].copy_from_slice(b"!<arch>\n");

    assert_eq!(FileKind::parse(&elf64_hdr[..]).unwrap(), FileKind::Elf64);
    assert_eq!(FileKind::parse(&elf32_hdr[..]).unwrap(), FileKind::Elf32);
    assert_eq!(FileKind::parse(&macho_hdr[..]).unwrap(), FileKind::MachO64);
    assert_eq!(FileKind::parse(&arch_hdr[..]).unwrap(), FileKind::Archive);

    // 2. File parses ELF64 binaries and provides format, architecture, and endianness information
    let elf64 = File::parse(&elf64_hdr[..]).expect("ELF64 parse failed");
    assert_eq!(elf64.format(), BinaryFormat::Elf);
    assert_eq!(elf64.architecture(), Architecture::X86_64);
    assert_eq!(elf64.endianness(), Endianness::Little);
    assert!(elf64.is_64());
    assert!(elf64.is_little_endian());
    assert_eq!(elf64.entry(), 0);

    // 3. File parses ELF32 binaries and provides format, architecture, and 32-bit classification
    let elf32 = File::parse(&elf32_hdr[..]).expect("ELF32 parse failed");
    assert_eq!(elf32.format(), BinaryFormat::Elf);
    assert_eq!(elf32.architecture(), Architecture::I386);
    assert!(!elf32.is_64());
    assert!(elf32.is_little_endian());

    // 4. File parses Mach-O 64-bit binaries and reports MachO format and architecture
    let macho = File::parse(&macho_hdr[..]).expect("Mach-O parse failed");
    assert_eq!(macho.format(), BinaryFormat::MachO);
    assert_eq!(macho.architecture(), Architecture::X86_64);

    // 5. FileKind and File reject truncated or invalid binary data with an error
    let invalid_data = b"NOT AN OBJECT FILE";
    assert!(FileKind::parse(&invalid_data[..]).is_err());
    assert!(File::parse(&invalid_data[..]).is_err());

    let short_data = b"\x7fELF";
    assert!(FileKind::parse(&short_data[..]).is_err());
    assert!(File::parse(&short_data[..]).is_err());

    println!("All object contract assertions passed successfully.");
}

原始种子者

匿名