CodeSampleX

샘플

resedit 1.7.2: NtExecutableResource

검증된 샘플 — npm resedit 1.7.2: NtExecutableResource. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: NtExecutableResource parses resource entries…

sha256:66cda3559ffdf967654d642303f17b9f8ece882b310fcdeb3b1fcc6bd7265e55

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify resedit.NtExecutableResource in pkg:npm/resedit@1.7.2
패키지
심벌
  • resedit.NtExecutableResource
환경
node 22.23.2
생성일
2026-09-06T10:27:19Z

컨트랙트

  1. NtExecutableResource parses resource entries from an NtExecutable instance
  2. NtExecutableResource replaces and retrieves UTF-8 string resources by type, id, and language
  3. NtExecutableResource adds and updates raw binary resource entries
  4. NtExecutableResource writes modified resources into an executable and round-trips through binary generation
  5. NtExecutableResource removes existing resource entries by type, id, and language

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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

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:7650bb67fae8b1b9d25f98a0d8c0fc89ca7a1f3c3dda5b4f102bb22443b21c40","contract":["NtExecutableResource parses resource entries from an NtExecutable instance","NtExecutableResource replaces and retrieves UTF-8 string resources by type, id, and language","NtExecutableResource adds and updates raw binary resource entries","NtExecutableResource writes modified resources into an executable and round-trips through binary generation","NtExecutableResource removes existing resource entries by type, id, and language"],"goal":"verify resedit.NtExecutableResource in pkg:npm/resedit@1.7.2","kind":"HOW","packages":["pkg:npm/resedit@1.7.2"],"schemaVersion":1,"symbols":["resedit.NtExecutableResource"]},"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.NtExecutableResource"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-resedit-nt-executable-resource",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-resedit-nt-executable-resource",
      "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-nt-executable-resource",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for resedit NtExecutableResource",
  "type": "module",
  "main": "src/index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "resedit": "1.7.2"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify resedit.NtExecutableResource in pkg:npm/resedit@1.7.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/resedit@1.7.2"
  ],
  "symbols": [
    "resedit.NtExecutableResource"
  ]
}
src/index.mjs
import { NtExecutable, NtExecutableResource } from 'resedit';

/**
 * Creates an NtExecutableResource instance from an NtExecutable.
 * @param {NtExecutable} exe
 * @returns {NtExecutableResource}
 */
export function createExecutableResource(exe) {
  return NtExecutableResource.from(exe);
}

/**
 * Sets or replaces a UTF-8 string resource entry.
 * @param {NtExecutableResource} res
 * @param {string | number} type
 * @param {string | number} id
 * @param {string | number} lang
 * @param {string} value
 */
export function setStringResource(res, type, id, lang, value) {
  res.replaceResourceEntryFromString(type, id, lang, value);
}

/**
 * Retrieves string resources for given type and id.
 * @param {NtExecutableResource} res
 * @param {string | number} type
 * @param {string | number} id
 * @returns {Array<[string | number, string]>}
 */
export function getStringResources(res, type, id) {
  return res.getResourceEntriesAsString(type, id);
}

/**
 * Sets or replaces a binary resource entry.
 * @param {NtExecutableResource} res
 * @param {string | number} type
 * @param {string | number} id
 * @param {string | number} lang
 * @param {ArrayBuffer | ArrayBufferView} data
 */
export function setBinaryResource(res, type, id, lang, data) {
  const bin = data instanceof ArrayBuffer ? data : data.buffer;
  res.replaceResourceEntry({ type, id, lang, bin });
}

/**
 * Removes a resource entry by type, id, and optional lang.
 * @param {NtExecutableResource} res
 * @param {string | number} type
 * @param {string | number} id
 * @param {string | number} [lang]
 */
export function removeResource(res, type, id, lang) {
  res.removeResourceEntry(type, id, lang);
}

/**
 * Writes the resource section back into the executable.
 * @param {NtExecutableResource} res
 * @param {NtExecutable} exe
 */
export function commitResource(res, exe) {
  res.outputResource(exe);
}

export { NtExecutable, NtExecutableResource };
test/contract.mjs
import assert from 'node:assert';
import {
  NtExecutable,
  NtExecutableResource,
  createExecutableResource,
  setStringResource,
  getStringResources,
  setBinaryResource,
  removeResource,
  commitResource
} from '../src/index.mjs';

// 1. NtExecutableResource parses resource entries from an NtExecutable instance
{
  const exe = NtExecutable.createEmpty(false, false);
  assert.ok(exe, 'NtExecutable instance should be created');

  const res = createExecutableResource(exe);
  assert.ok(res instanceof NtExecutableResource, 'res should be an instance of NtExecutableResource');
  assert.ok(Array.isArray(res.entries), 'res.entries should be an array');
}

// 2. NtExecutableResource replaces and retrieves UTF-8 string resources by type, id, and language
{
  const exe = NtExecutable.createEmpty(false, false);
  const res = createExecutableResource(exe);
  const type = 'CUSTOM_STRING';
  const id = 101;
  const lang = 1033;
  const text = 'Verified CodeSampleX contract string';

  setStringResource(res, type, id, lang, text);
  const results = getStringResources(res, type, id);

  assert.strictEqual(results.length, 1, 'Should find exactly one matching string resource');
  assert.strictEqual(results[0][0], lang, 'Resource language ID should match');
  assert.strictEqual(results[0][1], text, 'Resource string content should match');
}

// 3. NtExecutableResource adds and updates raw binary resource entries
{
  const exe = NtExecutable.createEmpty(false, false);
  const res = createExecutableResource(exe);
  const type = 10; // RT_RCDATA
  const id = 200;
  const lang = 0;
  const payload = new Uint8Array([0xCA, 0xFE, 0xBA, 0xBE]);

  setBinaryResource(res, type, id, lang, payload);

  const entry = res.entries.find((e) => e.type === type && e.id === id && e.lang === lang);
  assert.ok(entry, 'Binary resource entry should exist in entries array');
  assert.deepStrictEqual(new Uint8Array(entry.bin), payload, 'Binary content should match payload');
}

// 4. NtExecutableResource writes modified resources into an executable and round-trips through binary generation
{
  const exe = NtExecutable.createEmpty(false, false);
  const res = createExecutableResource(exe);
  const stringType = 'CONFIG';
  const stringId = 301;
  const lang = 1033;
  const stringVal = 'persistent-configuration-value';

  const binType = 10; // RT_RCDATA
  const binId = 401;
  const binPayload = new Uint8Array([1, 2, 3, 4, 5]);

  setStringResource(res, stringType, stringId, lang, stringVal);
  setBinaryResource(res, binType, binId, lang, binPayload);

  commitResource(res, exe);
  const binary = exe.generate();
  assert.ok(binary.byteLength > 0, 'Generated PE binary should have non-zero size');

  // Reload from generated binary
  const reloadedExe = NtExecutable.from(binary);
  const reloadedRes = createExecutableResource(reloadedExe);

  const reloadedStrings = getStringResources(reloadedRes, stringType, stringId);
  assert.strictEqual(reloadedStrings.length, 1);
  assert.strictEqual(reloadedStrings[0][0], lang);
  assert.strictEqual(reloadedStrings[0][1], stringVal);

  const reloadedBinEntry = reloadedRes.entries.find((e) => e.type === binType && e.id === binId && e.lang === lang);
  assert.ok(reloadedBinEntry, 'Reloaded binary resource should exist');
  assert.deepStrictEqual(new Uint8Array(reloadedBinEntry.bin), binPayload);
}

// 5. NtExecutableResource removes existing resource entries by type, id, and language
{
  const exe = NtExecutable.createEmpty(false, false);
  const res = createExecutableResource(exe);
  const type = 'TEMP_DATA';
  const id = 501;
  const lang = 1033;

  setStringResource(res, type, id, lang, 'temporary payload');
  assert.strictEqual(getStringResources(res, type, id).length, 1);

  removeResource(res, type, id, lang);
  assert.strictEqual(getStringResources(res, type, id).length, 0, 'Resource should be removed');
}

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

오리진 시더

익명