CodeSampleX

Sample

resedit 1.7.2: NtExecutable

Verified sample for npm resedit 1.7.2: NtExecutable. The contract ran on node 22 · linux debian/x64 · docker and passed: NtExecutable.createEmpty creates…

sha256:d5b080f7befd61a24ad7f30900da95d8d97ab6927bc5c9dc6e9c2bfdbaf0fc03

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify resedit.NtExecutable in pkg:npm/resedit@1.7.2
Packages
Symbols
  • resedit.NtExecutable
Environment
node 22.23.2
Created
2026-09-06T09:43:56Z

Contract

  1. NtExecutable.createEmpty creates 32-bit and 64-bit PE executable headers with valid DOS and NT signatures
  2. NtExecutable.setExtraData appends custom overlay payload data and getExtraData retrieves the binary overlay
  3. NtExecutable.getAllSections and getSectionByEntry query executable sections including resource directory entries
  4. NtExecutable.generate serializes the PE structure to an ArrayBuffer and NtExecutable.from re-parses identical header properties and sections

Files

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

Download the source artifact (tar.gz)

Source

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.NtExecutable 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.NtExecutable

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:d56075f1e181551acd33e5c7ce2586094d7bf236888f4766c5e8f29923341a2b","contract":["NtExecutable.createEmpty creates 32-bit and 64-bit PE executable headers with valid DOS and NT signatures","NtExecutable.setExtraData appends custom overlay payload data and getExtraData retrieves the binary overlay","NtExecutable.getAllSections and getSectionByEntry query executable sections including resource directory entries","NtExecutable.generate serializes the PE structure to an ArrayBuffer and NtExecutable.from re-parses identical header properties and sections"],"goal":"verify resedit.NtExecutable in pkg:npm/resedit@1.7.2","kind":"HOW","packages":["pkg:npm/resedit@1.7.2"],"schemaVersion":1,"symbols":["resedit.NtExecutable"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/resedit@1.7.2"],"schemaVersion":1,"subject":"pkg:npm/resedit@1.7.2","symbols":["resedit.NtExecutable"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-resedit-ntexecutable",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-resedit-ntexecutable",
      "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-ntexecutable",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "resedit": "1.7.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify resedit.NtExecutable in pkg:npm/resedit@1.7.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/resedit@1.7.2"
  ],
  "symbols": [
    "resedit.NtExecutable"
  ]
}
src/index.mjs
import { NtExecutable, NtExecutableResource, Format } from 'resedit';

/**
 * Creates an empty PE executable structure.
 *
 * @param {Object} [options]
 * @param {boolean} [options.is32Bit=false] - Whether to create a 32-bit (PE32) executable instead of 64-bit (PE32+).
 * @param {boolean} [options.isDLL=false] - Whether to create a DLL instead of an EXE.
 * @returns {NtExecutable}
 */
export function createExecutable(options = {}) {
  const is32Bit = Boolean(options.is32Bit);
  const isDLL = Boolean(options.isDLL);
  return NtExecutable.createEmpty(is32Bit, isDLL);
}

/**
 * Sets binary extra data (overlay data appended to the executable).
 *
 * @param {NtExecutable} exe - The NtExecutable instance.
 * @param {ArrayBuffer|ArrayBufferView|null} data - Overlay binary data to attach.
 */
export function setExecutableOverlay(exe, data) {
  exe.setExtraData(data);
}

/**
 * Retrieves binary extra data (overlay data) from the executable.
 *
 * @param {NtExecutable} exe - The NtExecutable instance.
 * @returns {ArrayBuffer|null}
 */
export function getExecutableOverlay(exe) {
  return exe.getExtraData();
}

/**
 * Retrieves section information by directory entry enum value.
 *
 * @param {NtExecutable} exe - The NtExecutable instance.
 * @param {number} entry - Directory entry enum value (e.g. Format.ImageDirectoryEntry.Resource).
 * @returns {{ name: string, virtualSize: number, sizeOfRawData: number, byteLength: number } | null}
 */
export function getSectionByEntry(exe, entry) {
  const section = exe.getSectionByEntry(entry);
  if (!section) {
    return null;
  }
  return {
    name: section.info.name,
    virtualSize: section.info.virtualSize,
    sizeOfRawData: section.info.sizeOfRawData,
    byteLength: section.data ? section.data.byteLength : 0
  };
}

/**
 * Serializes an NtExecutable to an ArrayBuffer and re-parses it back to a new NtExecutable instance.
 *
 * @param {NtExecutable} exe - The NtExecutable instance to serialize.
 * @param {number} [paddingSize] - Optional section alignment padding size.
 * @returns {{ binary: ArrayBuffer, parsedExe: NtExecutable }}
 */
export function roundtripExecutable(exe, paddingSize) {
  const binary = exe.generate(paddingSize);
  const parsedExe = NtExecutable.from(binary);
  return { binary, parsedExe };
}

export { NtExecutable, NtExecutableResource, Format };
test/contract.mjs
import assert from 'node:assert/strict';
import { NtExecutable, NtExecutableResource, Format, Resource } from 'resedit';
import {
  createExecutable,
  setExecutableOverlay,
  getExecutableOverlay,
  getSectionByEntry,
  roundtripExecutable
} from '../src/index.mjs';

// 1. NtExecutable.createEmpty creates 32-bit and 64-bit PE executable headers with valid DOS and NT signatures
{
  const exe64 = NtExecutable.createEmpty(false, false);
  assert.equal(exe64.is32bit(), false);
  assert.equal(exe64.dosHeader.magic, 0x5A4D); // 'MZ'
  assert.equal(exe64.newHeader.signature, 0x4550); // 'PE\0\0'
  assert.equal(exe64.newHeader.optionalHeader.magic, 0x20B); // PE32+
  assert.ok(exe64.getTotalHeaderSize() > 0);
  assert.ok(exe64.getImageBase() > 0);

  const exe32 = NtExecutable.createEmpty(true, true);
  assert.equal(exe32.is32bit(), true);
  assert.equal(exe32.dosHeader.magic, 0x5A4D);
  assert.equal(exe32.newHeader.signature, 0x4550);
  assert.equal(exe32.newHeader.optionalHeader.magic, 0x10B); // PE32

  const helperExe = createExecutable({ is32Bit: false, isDLL: false });
  assert.equal(helperExe.is32bit(), false);
  assert.equal(helperExe.dosHeader.magic, 0x5A4D);
}

// 2. NtExecutable.setExtraData appends custom overlay payload data and getExtraData retrieves the binary overlay
{
  const exe = NtExecutable.createEmpty(false, false);
  assert.equal(exe.getExtraData(), null);

  const payload = new Uint8Array([0xAA, 0xBB, 0xCC, 0xDD, 0x11, 0x22, 0x33, 0x44]);
  exe.setExtraData(payload);

  const retrieved = exe.getExtraData();
  assert.ok(retrieved instanceof ArrayBuffer);
  assert.deepEqual(new Uint8Array(retrieved), payload);

  setExecutableOverlay(exe, null);
  assert.equal(getExecutableOverlay(exe), null);

  setExecutableOverlay(exe, payload);
  const helperRetrieved = getExecutableOverlay(exe);
  assert.ok(helperRetrieved instanceof ArrayBuffer);
  assert.deepEqual(new Uint8Array(helperRetrieved), payload);
}

// 3. NtExecutable.getAllSections and getSectionByEntry query executable sections including resource directory entries
{
  const exe = NtExecutable.createEmpty(false, false);
  assert.equal(exe.getAllSections().length, 0);
  assert.equal(exe.getSectionByEntry(Format.ImageDirectoryEntry.Resource), null);
  assert.equal(getSectionByEntry(exe, Format.ImageDirectoryEntry.Resource), null);

  const res = NtExecutableResource.from(exe);
  const st = new Resource.StringTable();
  st.lang = 1033;
  st.setById(1, 'Sample Entry');
  st.replaceStringEntriesForExecutable(res);
  res.outputResource(exe);

  const sections = exe.getAllSections();
  assert.equal(sections.length, 1);
  assert.equal(sections[0].info.name, '.rsrc');

  const rsrcSection = exe.getSectionByEntry(Format.ImageDirectoryEntry.Resource);
  assert.ok(rsrcSection);
  assert.equal(rsrcSection.info.name, '.rsrc');
  assert.ok(rsrcSection.data instanceof ArrayBuffer);
  assert.ok(rsrcSection.data.byteLength > 0);

  const details = getSectionByEntry(exe, Format.ImageDirectoryEntry.Resource);
  assert.ok(details);
  assert.equal(details.name, '.rsrc');
  assert.equal(details.byteLength > 0, true);
}

// 4. NtExecutable.generate serializes the PE structure to an ArrayBuffer and NtExecutable.from re-parses identical header properties and sections
{
  const exe = NtExecutable.createEmpty(false, false);
  const payload = new Uint8Array([0x50, 0x45, 0x5F, 0x44, 0x41, 0x54, 0x41]);
  exe.setExtraData(payload);

  const res = NtExecutableResource.from(exe);
  const st = new Resource.StringTable();
  st.lang = 1033;
  st.setById(42, 'Answer');
  st.replaceStringEntriesForExecutable(res);
  res.outputResource(exe);

  const binary = exe.generate();
  assert.ok(binary instanceof ArrayBuffer);
  assert.ok(binary.byteLength > 0);

  const parsed = NtExecutable.from(binary);
  assert.equal(parsed.is32bit(), false);
  assert.equal(parsed.getImageBase(), exe.getImageBase());
  assert.equal(parsed.getFileAlignment(), exe.getFileAlignment());
  assert.equal(parsed.getSectionAlignment(), exe.getSectionAlignment());
  assert.equal(parsed.dosHeader.magic, 0x5A4D);
  assert.equal(parsed.newHeader.signature, 0x4550);

  const parsedRsrc = parsed.getSectionByEntry(Format.ImageDirectoryEntry.Resource);
  assert.ok(parsedRsrc);
  assert.equal(parsedRsrc.info.name, '.rsrc');

  const parsedExtra = parsed.getExtraData();
  assert.ok(parsedExtra instanceof ArrayBuffer);
  assert.deepEqual(new Uint8Array(parsedExtra), payload);

  const roundtripResult = roundtripExecutable(exe);
  assert.ok(roundtripResult.binary instanceof ArrayBuffer);
  assert.equal(roundtripResult.parsedExe.is32bit(), false);
  assert.equal(roundtripResult.parsedExe.dosHeader.magic, 0x5A4D);
}

console.log('Contract tests passed successfully.');

Origin Seeder

anonymous