CodeSampleX

Exemplo

resedit 1.7.2: Format

Amostra verificada para npm resedit 1.7.2: Format. O contrato rodou em node 22 · linux debian/x64 · docker e passou: assert resedit.Format.getImageDosHeader…

sha256:625d561b38f561d4dc1ce4dc1f505741f9b2bdfce6d5a1dce9aff76b97963e40

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-06

Caso

HOW
Objetivo
verify resedit.Format in pkg:npm/resedit@1.7.2
Pacotes
Símbolos
  • resedit.Format
Criado
2026-09-06T11:46:12Z

Contrato

  1. assert resedit.Format.getImageDosHeader parses DOS header from PE binary returning valid ImageDosHeader with MZ magic
  2. assert resedit.Format.getImageNtHeadersByDosHeader parses NT headers returning valid ImageNtHeaders with PE signature and 64-bit detection
  3. assert resedit.Format.getImageNtHeadersByDosHeader correctly identifies 32-bit PE binaries with PE32 magic 267 and is32bit true
  4. assert resedit.Format.getImageSectionHeadersByNtHeaders returns ImageSectionHeaderArray matching numberOfSections
  5. assert resedit.Format.findImageSectionBlockByDirectoryEntry returns null for unpopulated directory entries

Arquivos

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 resedit.Format in pkg:npm/resedit@1.7.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/resedit@1.7.2
Demonstrate these symbols/APIs:
  - resedit.Format

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:1c295398fb3e261768511bc9448a1c4db1c5e3ec9550136e3bfe806e04ab4369","contract":["assert resedit.Format.getImageDosHeader parses DOS header from PE binary returning valid ImageDosHeader with MZ magic","assert resedit.Format.getImageNtHeadersByDosHeader parses NT headers returning valid ImageNtHeaders with PE signature and 64-bit detection","assert resedit.Format.getImageNtHeadersByDosHeader correctly identifies 32-bit PE binaries with PE32 magic 267 and is32bit true","assert resedit.Format.getImageSectionHeadersByNtHeaders returns ImageSectionHeaderArray matching numberOfSections","assert resedit.Format.findImageSectionBlockByDirectoryEntry returns null for unpopulated directory entries"],"goal":"verify resedit.Format in pkg:npm/resedit@1.7.2","kind":"HOW","packages":["pkg:npm/resedit@1.7.2"],"schemaVersion":1,"symbols":["resedit.Format"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/resedit@1.7.2"],"schemaVersion":1,"subject":"pkg:npm/resedit@1.7.2","symbols":["resedit.Format"],"verifierAdapter":"node-typescript@1"}
index.js
const { NtExecutable, Format } = require('resedit');

function parseDosHeader(bin) {
  const dos = Format.getImageDosHeader(bin);
  return {
    isValid: dos.isValid(),
    magic: dos.magic,
    newHeaderAddress: dos.newHeaderAddress,
  };
}

function parseNtHeaders(bin, dosHeader) {
  const nt = Format.getImageNtHeadersByDosHeader(bin, dosHeader);
  return {
    isValid: nt.isValid(),
    is32bit: nt.is32bit(),
    signature: nt.signature,
    machine: nt.fileHeader.machine,
    numberOfSections: nt.fileHeader.numberOfSections,
    optionalMagic: nt.optionalHeader.magic,
    dataDirectoryCount: nt.optionalHeaderDataDirectory.length,
  };
}

function getSectionHeaders(bin, dosHeader, ntHeaders) {
  return Format.getImageSectionHeadersByNtHeaders(bin, dosHeader, ntHeaders);
}

function findSectionByEntry(bin, dosHeader, ntHeaders, entryType) {
  return Format.findImageSectionBlockByDirectoryEntry(bin, dosHeader, ntHeaders, entryType);
}

module.exports = {
  NtExecutable,
  Format,
  parseDosHeader,
  parseNtHeaders,
  getSectionHeaders,
  findSectionByEntry,
};
package-lock.json
{
  "name": "sample-resedit-format",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-resedit-format",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "resedit": "1.7.2"
      }
    },
    "node_modules/pe-library": {
      "version": "0.4.1",
      "resolved": "https://registry.npmjs.org/pe-library/-/pe-library-0.4.1.tgz",
      "integrity": "sha512-eRWB5LBz7PpDu4PUlwT0PhnQfTQJlDDdPa35urV4Osrm0t0AqQFGn+UIkU3klZvwJ8KPO3VbBFsXquA6p6kqZw==",
      "license": "MIT",
      "engines": {
        "node": ">=12",
        "npm": ">=6"
      },
      "funding": {
        "type": "github",
        "url": "https://github.com/sponsors/jet2jet"
      }
    },
    "node_modules/resedit": {
      "version": "1.7.2",
      "resolved": "https://registry.npmjs.org/resedit/-/resedit-1.7.2.tgz",
      "integrity": "sha512-vHjcY2MlAITJhC0eRD/Vv8Vlgmu9Sd3LX9zZvtGzU5ZImdTN3+d6e/4mnTyV8vEbyf1sgNIrWxhWlrys52OkEA==",
      "license": "MIT",
      "dependencies": {
        "pe-library": "^0.4.1"
      },
      "engines": {
        "node": ">=12",
        "npm": ">=6"
      },
      "funding": {
        "type": "github",
        "url": "https://github.com/sponsors/jet2jet"
      }
    }
  }
}
package.json
{
  "name": "sample-resedit-format",
  "version": "1.0.0",
  "description": "Minimal clean-room sample verifying resedit.Format in resedit",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "resedit": "1.7.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify resedit.Format in pkg:npm/resedit@1.7.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/resedit@1.7.2"
  ],
  "symbols": [
    "resedit.Format"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import {
  NtExecutable,
  Format,
  parseDosHeader,
  parseNtHeaders,
  getSectionHeaders,
  findSectionByEntry,
} from '../index.js';

// ---------------------------------------------------------------------------
// 1. assert resedit.Format.getImageDosHeader parses DOS header from PE binary returning valid ImageDosHeader with MZ magic
// ---------------------------------------------------------------------------
const exe64 = NtExecutable.createEmpty(false, false);
const bin64 = exe64.generate();

const dos64 = Format.getImageDosHeader(bin64);
assert.strictEqual(dos64.isValid(), true, 'DOS header must be valid for PE executable');
assert.strictEqual(dos64.magic, Format.ImageDosHeader.DEFAULT_MAGIC, 'DOS header magic must be 0x5A4D (23117)');
assert(dos64.newHeaderAddress > 0, 'newHeaderAddress must point to NT headers offset');

const parsedDos = parseDosHeader(bin64);
assert.strictEqual(parsedDos.isValid, true, 'parsedDos must be valid');
assert.strictEqual(parsedDos.magic, 23117, 'parsedDos magic must be 23117');

// ---------------------------------------------------------------------------
// 2. assert resedit.Format.getImageNtHeadersByDosHeader parses NT headers returning valid ImageNtHeaders with PE signature and 64-bit detection
// ---------------------------------------------------------------------------
const nt64 = Format.getImageNtHeadersByDosHeader(bin64, dos64);
assert.strictEqual(nt64.isValid(), true, 'NT headers must be valid');
assert.strictEqual(nt64.signature, Format.ImageNtHeaders.DEFAULT_SIGNATURE, 'NT headers signature must be 0x4550 (17744)');
assert.strictEqual(nt64.is32bit(), false, 'is32bit() must return false for 64-bit executable');
assert.strictEqual(nt64.fileHeader.machine, 34404, 'Machine type must be IMAGE_FILE_MACHINE_AMD64 (0x8664 / 34404)');
assert.strictEqual(nt64.optionalHeader.magic, Format.ImageOptionalHeader64.DEFAULT_MAGIC, 'Optional header magic must be 523 (PE32+)');
assert.strictEqual(nt64.optionalHeaderDataDirectory.length, 16, 'Standard PE executable must have 16 data directory entries');

const parsedNt64 = parseNtHeaders(bin64, dos64);
assert.strictEqual(parsedNt64.isValid, true, 'parsedNt64 must be valid');
assert.strictEqual(parsedNt64.is32bit, false, 'parsedNt64 must be 64-bit');
assert.strictEqual(parsedNt64.signature, 17744, 'parsedNt64 signature must be 17744');
assert.strictEqual(parsedNt64.optionalMagic, 523, 'parsedNt64 optionalMagic must be 523');
assert.strictEqual(parsedNt64.dataDirectoryCount, 16, 'parsedNt64 directory count must be 16');

// ---------------------------------------------------------------------------
// 3. assert resedit.Format.getImageNtHeadersByDosHeader correctly identifies 32-bit PE binaries with PE32 magic 267 and is32bit true
// ---------------------------------------------------------------------------
const exe32 = NtExecutable.createEmpty(true, false);
const bin32 = exe32.generate();
const dos32 = Format.getImageDosHeader(bin32);
const nt32 = Format.getImageNtHeadersByDosHeader(bin32, dos32);
assert.strictEqual(nt32.isValid(), true, '32-bit NT headers must be valid');
assert.strictEqual(nt32.is32bit(), true, 'is32bit() must return true for 32-bit executable');
assert.strictEqual(nt32.fileHeader.machine, 332, 'Machine type must be IMAGE_FILE_MACHINE_I386 (0x14c / 332)');
assert.strictEqual(nt32.optionalHeader.magic, Format.ImageOptionalHeader.DEFAULT_MAGIC, 'Optional header magic must be 267 (PE32)');

const parsedNt32 = parseNtHeaders(bin32, dos32);
assert.strictEqual(parsedNt32.isValid, true, 'parsedNt32 must be valid');
assert.strictEqual(parsedNt32.is32bit, true, 'parsedNt32 must be 32-bit');
assert.strictEqual(parsedNt32.machine, 332, 'parsedNt32 machine must be 332');
assert.strictEqual(parsedNt32.optionalMagic, 267, 'parsedNt32 optionalMagic must be 267');

// ---------------------------------------------------------------------------
// 4. assert resedit.Format.getImageSectionHeadersByNtHeaders returns ImageSectionHeaderArray matching numberOfSections
// ---------------------------------------------------------------------------
const sections = getSectionHeaders(bin64, dos64, nt64);
assert.strictEqual(typeof sections.length, 'number', 'sections must have length property');
assert.strictEqual(sections.length, nt64.fileHeader.numberOfSections, 'Section count must match numberOfSections');

// ---------------------------------------------------------------------------
// 5. assert resedit.Format.findImageSectionBlockByDirectoryEntry returns null for unpopulated directory entries
// ---------------------------------------------------------------------------
const resourceSection = findSectionByEntry(bin64, dos64, nt64, Format.ImageDirectoryEntry.Resource);
assert.strictEqual(resourceSection, null, 'Unpopulated resource directory entry must return null block');

const exportSection = findSectionByEntry(bin64, dos64, nt64, Format.ImageDirectoryEntry.Export);
assert.strictEqual(exportSection, null, 'Unpopulated export directory entry must return null block');

console.log('All resedit.Format contract assertions passed successfully.');

Seeder de origem

anônimo