CodeSampleX

Exemplo

resedit 1.7.2

Amostra verificada para npm resedit 1.7.2. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: NtExecutable.createEmpty creates an empty PE…

sha256:a23436f8759a50a5fea9a7d79b8be363d60557e20b6ad4a8865acdf2f9f5b784

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 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-28

Caso

HOW
Objetivo
verify pkg:npm/resedit@1.7.2
Pacotes
Ambiente
node 22.23.2
Criado
2026-08-28T05:14:14Z

Contrato

  1. NtExecutable.createEmpty creates an empty PE executable structure and NtExecutableResource manages its resource entries
  2. Resource.VersionInfo sets file version, product version, and string table metadata in executable resources
  3. Resource.StringTable adds localized string table entries by integer ID into executable resources
  4. NtExecutable.generate produces a PE binary containing resource entries and NtExecutable.from re-parses identical resources from binary

Arquivos

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

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

Use EXACTLY these public packages and versions:
  - pkg:npm/resedit@1.7.2

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:e9b38c81623fe0c3b7283aea4a720a8e3019b2fdc7167bd7aa623067e5fbb660","contract":["NtExecutable.createEmpty creates an empty PE executable structure and NtExecutableResource manages its resource entries","Resource.VersionInfo sets file version, product version, and string table metadata in executable resources","Resource.StringTable adds localized string table entries by integer ID into executable resources","NtExecutable.generate produces a PE binary containing resource entries and NtExecutable.from re-parses identical resources from binary"],"goal":"verify pkg:npm/resedit@1.7.2","kind":"HOW","packages":["pkg:npm/resedit@1.7.2"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","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","verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const ResEdit = require('resedit');

/**
 * Creates an empty PE executable structure and populates it with VersionInfo and StringTable resources.
 *
 * @param {Object} [options]
 * @param {boolean} [options.is32Bit=false]
 * @param {boolean} [options.isDLL=false]
 * @param {number} [options.lang=1033]
 * @param {number} [options.codepage=1200]
 * @param {Object} [options.versionNumbers]
 * @param {Object} [options.stringValues]
 * @param {Object} [options.tableStrings]
 * @returns {{ exe: ResEdit.NtExecutable, res: ResEdit.NtExecutableResource, binary: ArrayBuffer }}
 */
function createExecutableWithResources(options = {}) {
  const is32Bit = options.is32Bit || false;
  const isDLL = options.isDLL || false;
  const lang = options.lang !== undefined ? options.lang : 1033;
  const codepage = options.codepage !== undefined ? options.codepage : 1200;

  const exe = ResEdit.NtExecutable.createEmpty(is32Bit, isDLL);
  const res = ResEdit.NtExecutableResource.from(exe);

  if (options.versionNumbers || options.stringValues) {
    const vi = ResEdit.Resource.VersionInfo.createEmpty();
    vi.lang = lang;

    if (options.versionNumbers) {
      const { fileVersion, productVersion } = options.versionNumbers;
      if (fileVersion) {
        vi.setFileVersion(
          fileVersion.major || 0,
          fileVersion.minor || 0,
          fileVersion.patch || 0,
          fileVersion.build || 0,
          lang
        );
      }
      if (productVersion) {
        vi.setProductVersion(
          productVersion.major || 0,
          productVersion.minor || 0,
          productVersion.patch || 0,
          productVersion.build || 0,
          lang
        );
      }
    }

    if (options.stringValues) {
      vi.setStringValues({ lang, codepage }, options.stringValues);
    }

    vi.outputToResourceEntries(res.entries);
  }

  if (options.tableStrings) {
    const st = new ResEdit.Resource.StringTable();
    st.lang = lang;
    for (const [idStr, text] of Object.entries(options.tableStrings)) {
      st.setById(Number(idStr), text);
    }
    st.replaceStringEntriesForExecutable(res);
  }

  res.outputResource(exe);
  const binary = exe.generate();

  return { exe, res, binary };
}

/**
 * Parses a PE binary and extracts its VersionInfo and StringTable resources.
 *
 * @param {ArrayBuffer|Buffer} binary
 * @param {number} [lang=1033]
 * @param {number} [codepage=1200]
 * @returns {{ versionInfo: Object|null, stringTable: Object }}
 */
function readExecutableResources(binary, lang = 1033, codepage = 1200) {
  const exe = ResEdit.NtExecutable.from(binary);
  const res = ResEdit.NtExecutableResource.from(exe);

  const viList = ResEdit.Resource.VersionInfo.fromEntries(res.entries);
  let versionInfo = null;
  if (viList.length > 0) {
    const vi = viList[0];
    versionInfo = {
      fixedInfo: {
        fileVersionMS: vi.fixedInfo.fileVersionMS,
        fileVersionLS: vi.fixedInfo.fileVersionLS,
        productVersionMS: vi.fixedInfo.productVersionMS,
        productVersionLS: vi.fixedInfo.productVersionLS
      },
      strings: vi.getStringValues({ lang, codepage })
    };
  }

  const st = ResEdit.Resource.StringTable.fromEntries(lang, res.entries);
  const strings = {};
  for (const item of st.getAllStrings()) {
    strings[item.id] = item.text;
  }

  return { versionInfo, stringTable: strings };
}

module.exports = {
  createExecutableWithResources,
  readExecutableResources,
  ResEdit
};
package-lock.json
{
  "name": "sample-resedit",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-resedit",
      "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",
  "version": "1.0.0",
  "private": true,
  "description": "verify pkg:npm/resedit@1.7.2",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "resedit": "1.7.2"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/resedit@1.7.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/resedit@1.7.2"
  ]
}
test/contract.js
'use strict';

const assert = require('assert');
const ResEdit = require('resedit');
const { createExecutableWithResources, readExecutableResources } = require('../index.js');

async function testResEditContract() {
  // 1. Contract: NtExecutable.createEmpty creates an empty PE executable structure and NtExecutableResource manages its resource entries
  const exe = ResEdit.NtExecutable.createEmpty(false, false);
  assert.ok(exe, 'NtExecutable.createEmpty must return an executable instance');
  const res = ResEdit.NtExecutableResource.from(exe);
  assert.ok(res, 'NtExecutableResource.from must return a resource instance');
  assert.ok(Array.isArray(res.entries), 'res.entries must be an array');

  // 2. Contract: Resource.VersionInfo sets file version, product version, and string table metadata in executable resources
  const vi = ResEdit.Resource.VersionInfo.createEmpty();
  vi.lang = 1033;
  vi.setFileVersion(2, 4, 6, 8, 1033);
  vi.setProductVersion(1, 0, 0, 1, 1033);
  vi.setStringValues(
    { lang: 1033, codepage: 1200 },
    {
      FileDescription: 'Sample ResEdit Executable',
      ProductName: 'CodeSampleX ResEdit Tool',
      FileVersion: '2.4.6.8',
      ProductVersion: '1.0.0.1',
      CompanyName: 'Example Org'
    }
  );
  vi.outputToResourceEntries(res.entries);

  // 3. Contract: Resource.StringTable adds localized string table entries by integer ID into executable resources
  const st = new ResEdit.Resource.StringTable();
  st.lang = 1033;
  st.setById(101, 'Hello from ResEdit string table');
  st.setById(202, 'Resource string 202');
  st.replaceStringEntriesForExecutable(res);

  // 4. Contract: NtExecutable.generate produces a PE binary containing resource entries and NtExecutable.from re-parses identical resources from binary
  res.outputResource(exe);
  const binary = exe.generate();
  assert.ok(binary instanceof ArrayBuffer, 'exe.generate must return an ArrayBuffer');
  assert.ok(binary.byteLength > 0, 'generated binary must not be empty');

  const parsedExe = ResEdit.NtExecutable.from(binary);
  const parsedRes = ResEdit.NtExecutableResource.from(parsedExe);

  const parsedViList = ResEdit.Resource.VersionInfo.fromEntries(parsedRes.entries);
  assert.strictEqual(parsedViList.length, 1, 'parsed binary must contain exactly one VersionInfo resource');
  const parsedVi = parsedViList[0];
  const parsedStrings = parsedVi.getStringValues({ lang: 1033, codepage: 1200 });
  assert.strictEqual(parsedStrings.FileDescription, 'Sample ResEdit Executable');
  assert.strictEqual(parsedStrings.ProductName, 'CodeSampleX ResEdit Tool');
  assert.strictEqual(parsedStrings.FileVersion, '2.4.6.8');
  assert.strictEqual(parsedStrings.ProductVersion, '1.0.0.1');
  assert.strictEqual(parsedStrings.CompanyName, 'Example Org');

  // Verify fixed version numbers (HIWORD / LOWORD representation)
  assert.strictEqual(parsedVi.fixedInfo.fileVersionMS, (2 << 16) | 4);
  assert.strictEqual(parsedVi.fixedInfo.fileVersionLS, (6 << 16) | 8);

  const parsedSt = ResEdit.Resource.StringTable.fromEntries(1033, parsedRes.entries);
  assert.strictEqual(parsedSt.getById(101), 'Hello from ResEdit string table');
  assert.strictEqual(parsedSt.getById(202), 'Resource string 202');
  assert.strictEqual(parsedSt.getById(999), null, 'non-existent ID must return null');

  // 5. Verify helper functions from index.js
  const helperResult = createExecutableWithResources({
    lang: 1033,
    codepage: 1200,
    versionNumbers: {
      fileVersion: { major: 3, minor: 1, patch: 4, build: 1 },
      productVersion: { major: 3, minor: 0, patch: 0, build: 0 }
    },
    stringValues: {
      FileDescription: 'Helper Generated App',
      ProductName: 'Helper Product'
    },
    tableStrings: {
      301: 'Helper String 301',
      302: 'Helper String 302'
    }
  });

  const readBack = readExecutableResources(helperResult.binary, 1033, 1200);
  assert.ok(readBack.versionInfo, 'versionInfo must be parsed');
  assert.strictEqual(readBack.versionInfo.strings.FileDescription, 'Helper Generated App');
  assert.strictEqual(readBack.versionInfo.strings.ProductName, 'Helper Product');
  assert.strictEqual(readBack.stringTable[301], 'Helper String 301');
  assert.strictEqual(readBack.stringTable[302], 'Helper String 302');

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

testResEditContract().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Seeder de origem

anônimo