From 1287031389d91d1e8282093c2b7dd9f2045b7ec9 Mon Sep 17 00:00:00 2001 From: "Node.js GitHub Bot" Date: Sat, 14 Jan 2023 23:24:39 +0000 Subject: [PATCH] test: update postject to 1.0.0-alpha.4 PR-URL: https://github.com/nodejs/node/pull/46212 Reviewed-By: Darshan Sen Reviewed-By: Robert Nagy Reviewed-By: Matteo Collina Reviewed-By: Joyee Cheung Reviewed-By: Ruben Bridgewater Reviewed-By: Tierney Cyren --- .../postject-copy/node_modules/.bin/postject | 1 - .../node_modules/.package-lock.json | 30 +++++ .../node_modules/commander/Readme.md | 13 +- .../node_modules/commander/lib/command.js | 19 +++ .../node_modules/commander/lib/help.js | 71 ++++++++-- .../node_modules/commander/package.json | 126 +++++++----------- .../node_modules/commander/typings/index.d.ts | 12 +- .../node_modules/postject/CODE_OF_CONDUCT.md | 6 + .../node_modules/postject/CONTRIBUTING.md | 32 +++++ .../node_modules/postject/README.markdown | 9 ++ .../node_modules/postject/dist/api.js | 33 ++++- .../node_modules/postject/dist/cli.js | 6 + .../node_modules/postject/dist/postject-api.h | 25 +++- .../node_modules/postject/package.json | 81 ++++------- test/fixtures/postject-copy/package-lock.json | 39 ++++-- test/fixtures/postject-copy/package.json | 2 +- 16 files changed, 340 insertions(+), 165 deletions(-) delete mode 120000 test/fixtures/postject-copy/node_modules/.bin/postject create mode 100644 test/fixtures/postject-copy/node_modules/.package-lock.json create mode 100644 test/fixtures/postject-copy/node_modules/postject/CODE_OF_CONDUCT.md create mode 100644 test/fixtures/postject-copy/node_modules/postject/CONTRIBUTING.md diff --git a/test/fixtures/postject-copy/node_modules/.bin/postject b/test/fixtures/postject-copy/node_modules/.bin/postject deleted file mode 120000 index 3123676caa2cea..00000000000000 --- a/test/fixtures/postject-copy/node_modules/.bin/postject +++ /dev/null @@ -1 +0,0 @@ -../postject/dist/cli.js \ No newline at end of file diff --git a/test/fixtures/postject-copy/node_modules/.package-lock.json b/test/fixtures/postject-copy/node_modules/.package-lock.json new file mode 100644 index 00000000000000..3407b01d4719e4 --- /dev/null +++ b/test/fixtures/postject-copy/node_modules/.package-lock.json @@ -0,0 +1,30 @@ +{ + "name": "postject-copy", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "node_modules/commander": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "engines": { + "node": "^12.20.0 || >=14" + } + }, + "node_modules/postject": { + "version": "1.0.0-alpha.4", + "resolved": "https://registry.npmjs.org/postject/-/postject-1.0.0-alpha.4.tgz", + "integrity": "sha512-CdGzQJWzB2btwUQdrVJtpcHLldK4yclZyvYu6eZdEspd8bUq4zmhuT1y75ccE2QOpUpvFw/PuzpmbFwyIX9sLQ==", + "dependencies": { + "commander": "^9.4.0" + }, + "bin": { + "postject": "dist/cli.js" + }, + "engines": { + "node": ">=14.0.0" + } + } + } +} diff --git a/test/fixtures/postject-copy/node_modules/commander/Readme.md b/test/fixtures/postject-copy/node_modules/commander/Readme.md index 39c248b0439789..ed19cff6332b4f 100644 --- a/test/fixtures/postject-copy/node_modules/commander/Readme.md +++ b/test/fixtures/postject-copy/node_modules/commander/Readme.md @@ -543,6 +543,8 @@ Configuration options can be passed with the call to `.command()` and `.addComma remove the command from the generated help output. Specifying `isDefault: true` will run the subcommand if no other subcommand is specified ([example](./examples/defaultCommand.js)). +You can add alternative names for a command with `.alias()`. ([example](./examples/alias.js)) + For safety, `.addCommand()` does not automatically copy the inherited settings from the parent command. There is a helper routine `.copyInheritedSettings()` for copying the settings when they are wanted. ### Command-arguments @@ -915,6 +917,7 @@ The data properties are: - `helpWidth`: specify the wrap width, useful for unit tests - `sortSubcommands`: sort the subcommands alphabetically - `sortOptions`: sort the options alphabetically +- `showGlobalOptions`: show a section with the global options from the parent command(s) There are methods getting the visible lists of arguments, options, and subcommands. There are methods for formatting the items in the lists, with each item having a _term_ and _description_. Take a look at `.formatHelp()` to see how they are used. @@ -1011,7 +1014,15 @@ program ### TypeScript -If you use `ts-node` and stand-alone executable subcommands written as `.ts` files, you need to call your program through node to get the subcommands called correctly. e.g. +extra-typings: There is an optional project to infer extra type information from the option and argument definitions. +This adds strong typing to the options returned by `.opts()` and the parameters to `.action()`. +See [commander-js/extra-typings](https://github.com/commander-js/extra-typings) for more. + +``` +import { Command } from '@commander-js/extra-typings'; +``` + +ts-node: If you use `ts-node` and stand-alone executable subcommands written as `.ts` files, you need to call your program through node to get the subcommands called correctly. e.g. ```sh node -r ts-node/register pm.ts diff --git a/test/fixtures/postject-copy/node_modules/commander/lib/command.js b/test/fixtures/postject-copy/node_modules/commander/lib/command.js index 9284ec39f3f4f3..7a637cb77450f7 100644 --- a/test/fixtures/postject-copy/node_modules/commander/lib/command.js +++ b/test/fixtures/postject-copy/node_modules/commander/lib/command.js @@ -814,6 +814,25 @@ Expecting one of '${allowedValues.join("', '")}'`); return this._optionValueSources[key]; } + /** + * Get source of option value. See also .optsWithGlobals(). + * Expected values are default | config | env | cli | implied + * + * @param {string} key + * @return {string} + */ + + getOptionValueSourceWithGlobals(key) { + // global overwrites local, like optsWithGlobals + let source; + getCommandAndParents(this).forEach((cmd) => { + if (cmd.getOptionValueSource(key) !== undefined) { + source = cmd.getOptionValueSource(key); + } + }); + return source; + } + /** * Get user arguments from implied or explicit arguments. * Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches. diff --git a/test/fixtures/postject-copy/node_modules/commander/lib/help.js b/test/fixtures/postject-copy/node_modules/commander/lib/help.js index 9c7fb1ecdf63bc..90d9d68cc7c875 100644 --- a/test/fixtures/postject-copy/node_modules/commander/lib/help.js +++ b/test/fixtures/postject-copy/node_modules/commander/lib/help.js @@ -16,6 +16,7 @@ class Help { this.helpWidth = undefined; this.sortSubcommands = false; this.sortOptions = false; + this.showGlobalOptions = false; } /** @@ -45,6 +46,21 @@ class Help { return visibleCommands; } + /** + * Compare options for sort. + * + * @param {Option} a + * @param {Option} b + * @returns number + */ + compareOptions(a, b) { + const getSortKey = (option) => { + // WYSIWYG for order displayed in help. Short used for comparison if present. No special handling for negated. + return option.short ? option.short.replace(/^-/, '') : option.long.replace(/^--/, ''); + }; + return getSortKey(a).localeCompare(getSortKey(b)); + } + /** * Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one. * @@ -69,17 +85,32 @@ class Help { visibleOptions.push(helpOption); } if (this.sortOptions) { - const getSortKey = (option) => { - // WYSIWYG for order displayed in help with short before long, no special handling for negated. - return option.short ? option.short.replace(/^-/, '') : option.long.replace(/^--/, ''); - }; - visibleOptions.sort((a, b) => { - return getSortKey(a).localeCompare(getSortKey(b)); - }); + visibleOptions.sort(this.compareOptions); } return visibleOptions; } + /** + * Get an array of the visible global options. (Not including help.) + * + * @param {Command} cmd + * @returns {Option[]} + */ + + visibleGlobalOptions(cmd) { + if (!this.showGlobalOptions) return []; + + const globalOptions = []; + for (let parentCmd = cmd.parent; parentCmd; parentCmd = parentCmd.parent) { + const visibleOptions = parentCmd.options.filter((option) => !option.hidden); + globalOptions.push(...visibleOptions); + } + if (this.sortOptions) { + globalOptions.sort(this.compareOptions); + } + return globalOptions; + } + /** * Get an array of the arguments if any have a description. * @@ -168,6 +199,20 @@ class Help { }, 0); } + /** + * Get the longest global option term length. + * + * @param {Command} cmd + * @param {Help} helper + * @returns {number} + */ + + longestGlobalOptionTermLength(cmd, helper) { + return helper.visibleGlobalOptions(cmd).reduce((max, option) => { + return Math.max(max, helper.optionTerm(option).length); + }, 0); + } + /** * Get the longest argument term length. * @@ -216,7 +261,7 @@ class Help { /** * Get the subcommand summary to show in the list of subcommands. - * (Fallback to description for backwards compatiblity.) + * (Fallback to description for backwards compatibility.) * * @param {Command} cmd * @returns {string} @@ -341,6 +386,15 @@ class Help { output = output.concat(['Options:', formatList(optionList), '']); } + if (this.showGlobalOptions) { + const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => { + return formatItem(helper.optionTerm(option), helper.optionDescription(option)); + }); + if (globalOptionList.length > 0) { + output = output.concat(['Global Options:', formatList(globalOptionList), '']); + } + } + // Commands const commandList = helper.visibleCommands(cmd).map((cmd) => { return formatItem(helper.subcommandTerm(cmd), helper.subcommandDescription(cmd)); @@ -363,6 +417,7 @@ class Help { padWidth(cmd, helper) { return Math.max( helper.longestOptionTermLength(cmd, helper), + helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper) ); diff --git a/test/fixtures/postject-copy/node_modules/commander/package.json b/test/fixtures/postject-copy/node_modules/commander/package.json index 8f44c7165a63ef..60f5ccefd95cf6 100644 --- a/test/fixtures/postject-copy/node_modules/commander/package.json +++ b/test/fixtures/postject-copy/node_modules/commander/package.json @@ -1,37 +1,50 @@ { - "_from": "commander@^9.4.0", - "_id": "commander@9.4.1", - "_inBundle": false, - "_integrity": "sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw==", - "_location": "/commander", - "_phantomChildren": {}, - "_requested": { - "type": "range", - "registry": true, - "raw": "commander@^9.4.0", - "name": "commander", - "escapedName": "commander", - "rawSpec": "^9.4.0", - "saveSpec": null, - "fetchSpec": "^9.4.0" - }, - "_requiredBy": [ - "/postject" + "name": "commander", + "version": "9.5.0", + "description": "the complete solution for node.js command-line programs", + "keywords": [ + "commander", + "command", + "option", + "parser", + "cli", + "argument", + "args", + "argv" ], - "_resolved": "https://registry.npmjs.org/commander/-/commander-9.4.1.tgz", - "_shasum": "d1dd8f2ce6faf93147295c0df13c7c21141cfbdd", - "_spec": "commander@^9.4.0", - "_where": "/Users/raisinten/Desktop/git/node/test/fixtures/postject-copy/node_modules/postject", - "author": { - "name": "TJ Holowaychuk", - "email": "tj@vision-media.ca" + "author": "TJ Holowaychuk ", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/tj/commander.js.git" }, - "bugs": { - "url": "https://github.com/tj/commander.js/issues" + "scripts": { + "lint": "npm run lint:javascript && npm run lint:typescript", + "lint:javascript": "eslint index.js esm.mjs \"lib/*.js\" \"tests/**/*.js\"", + "lint:typescript": "eslint typings/*.ts tests/*.ts", + "test": "jest && npm run test-typings", + "test-esm": "node --experimental-modules ./tests/esm-imports-test.mjs", + "test-typings": "tsd", + "typescript-checkJS": "tsc --allowJS --checkJS index.js lib/*.js --noEmit", + "test-all": "npm run test && npm run lint && npm run typescript-checkJS && npm run test-esm" + }, + "files": [ + "index.js", + "lib/*.js", + "esm.mjs", + "typings/index.d.ts", + "package-support.json" + ], + "type": "commonjs", + "main": "./index.js", + "exports": { + ".": { + "types": "./typings/index.d.ts", + "require": "./index.js", + "import": "./esm.mjs" + }, + "./esm.mjs": "./esm.mjs" }, - "bundleDependencies": false, - "deprecated": false, - "description": "the complete solution for node.js command-line programs", "devDependencies": { "@types/jest": "^28.1.4", "@types/node": "^16.11.15", @@ -49,25 +62,7 @@ "tsd": "^0.22.0", "typescript": "^4.7.4" }, - "engines": { - "node": "^12.20.0 || >=14" - }, - "exports": { - ".": { - "types": "./typings/index.d.ts", - "require": "./index.js", - "import": "./esm.mjs" - }, - "./esm.mjs": "./esm.mjs" - }, - "files": [ - "index.js", - "lib/*.js", - "esm.mjs", - "typings/index.d.ts", - "package-support.json" - ], - "homepage": "https://github.com/tj/commander.js#readme", + "types": "typings/index.d.ts", "jest": { "testEnvironment": "node", "collectCoverage": true, @@ -78,35 +73,8 @@ "/node_modules/" ] }, - "keywords": [ - "commander", - "command", - "option", - "parser", - "cli", - "argument", - "args", - "argv" - ], - "license": "MIT", - "main": "./index.js", - "name": "commander", - "repository": { - "type": "git", - "url": "git+https://github.com/tj/commander.js.git" - }, - "scripts": { - "lint": "npm run lint:javascript && npm run lint:typescript", - "lint:javascript": "eslint index.js esm.mjs \"lib/*.js\" \"tests/**/*.js\"", - "lint:typescript": "eslint typings/*.ts tests/*.ts", - "test": "jest && npm run test-typings", - "test-all": "npm run test && npm run lint && npm run typescript-checkJS && npm run test-esm", - "test-esm": "node --experimental-modules ./tests/esm-imports-test.mjs", - "test-typings": "tsd", - "typescript-checkJS": "tsc --allowJS --checkJS index.js lib/*.js --noEmit" + "engines": { + "node": "^12.20.0 || >=14" }, - "support": true, - "type": "commonjs", - "types": "typings/index.d.ts", - "version": "9.4.1" + "support": true } diff --git a/test/fixtures/postject-copy/node_modules/commander/typings/index.d.ts b/test/fixtures/postject-copy/node_modules/commander/typings/index.d.ts index b69ea910411022..e9a5e4b36f5453 100644 --- a/test/fixtures/postject-copy/node_modules/commander/typings/index.d.ts +++ b/test/fixtures/postject-copy/node_modules/commander/typings/index.d.ts @@ -199,6 +199,7 @@ export class Help { helpWidth?: number; sortSubcommands: boolean; sortOptions: boolean; + showGlobalOptions: boolean; constructor(); @@ -224,6 +225,8 @@ export class Help { visibleCommands(cmd: Command): Command[]; /** Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one. */ visibleOptions(cmd: Command): Option[]; + /** Get an array of the visible global options. (Not including help.) */ + visibleGlobalOptions(cmd: Command): Option[]; /** Get an array of the arguments which have descriptions. */ visibleArguments(cmd: Command): Argument[]; @@ -231,6 +234,8 @@ export class Help { longestSubcommandTermLength(cmd: Command, helper: Help): number; /** Get the longest option term length. */ longestOptionTermLength(cmd: Command, helper: Help): number; + /** Get the longest global option term length. */ + longestGlobalOptionTermLength(cmd: Command, helper: Help): number; /** Get the longest argument term length. */ longestArgumentTermLength(cmd: Command, helper: Help): number; /** Calculate the pad width from the maximum term length. */ @@ -595,10 +600,15 @@ export class Command { setOptionValueWithSource(key: string, value: unknown, source: OptionValueSource): this; /** - * Retrieve option value source. + * Get source of option value. */ getOptionValueSource(key: string): OptionValueSource | undefined; + /** + * Get source of option value. See also .optsWithGlobals(). + */ + getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined; + /** * Alter parsing of short flags with optional values. * diff --git a/test/fixtures/postject-copy/node_modules/postject/CODE_OF_CONDUCT.md b/test/fixtures/postject-copy/node_modules/postject/CODE_OF_CONDUCT.md new file mode 100644 index 00000000000000..b3db25d2f6e7e0 --- /dev/null +++ b/test/fixtures/postject-copy/node_modules/postject/CODE_OF_CONDUCT.md @@ -0,0 +1,6 @@ +# Code of Conduct + +Postject is committed to upholding the Node.js Code of Conduct. + +The Node.js Code of Conduct document can be found at +https://github.com/nodejs/admin/blob/main/CODE_OF_CONDUCT.md diff --git a/test/fixtures/postject-copy/node_modules/postject/CONTRIBUTING.md b/test/fixtures/postject-copy/node_modules/postject/CONTRIBUTING.md new file mode 100644 index 00000000000000..3c547fbbba336b --- /dev/null +++ b/test/fixtures/postject-copy/node_modules/postject/CONTRIBUTING.md @@ -0,0 +1,32 @@ +# Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +* (a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + +* (b) The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the same open source license (unless I am + permitted to submit under a different license), as indicated + in the file; or + +* (c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +* (d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it, including my sign-off) is + maintained indefinitely and may be redistributed consistent with + this project or the open source license(s) involved. + +## Moderation Policy + +The [Node.js Moderation Policy] applies to this project. + +[Node.js Moderation Policy]: +https://github.com/nodejs/admin/blob/main/Moderation-Policy.md diff --git a/test/fixtures/postject-copy/node_modules/postject/README.markdown b/test/fixtures/postject-copy/node_modules/postject/README.markdown index 7892f37ad97228..4acacb20cb3d33 100644 --- a/test/fixtures/postject-copy/node_modules/postject/README.markdown +++ b/test/fixtures/postject-copy/node_modules/postject/README.markdown @@ -75,6 +75,15 @@ ability to inject the resources into pre-built executables, with the goal that the end result should be as close as possible to what is obtained by embedding them at build-time. +Note: Other runtime injection implementers should search the binary +compiled with `postject-api.h` for the +`POSTJECT_SENTINEL_fce680ab2cc467b6e072b8b5df1996b2:0` fuse and +flip the last character to `1` to indicate that a resource has been +injected. A different fuse can also be used by defining the +`POSTJECT_SENTINEL_FUSE` macro before including `postject-api.h` and +passing the same string to postject with +`--sentinel-fuse `. + ### Windows For PE executables, the resources are added into the `.rsrc` section, diff --git a/test/fixtures/postject-copy/node_modules/postject/dist/api.js b/test/fixtures/postject-copy/node_modules/postject/dist/api.js index bce6b2110e7d91..d79ce04ccfa7d6 100644 --- a/test/fixtures/postject-copy/node_modules/postject/dist/api.js +++ b/test/fixtures/postject-copy/node_modules/postject/dist/api.js @@ -5058,6 +5058,7 @@ var loadPostjectModule = require_postject(); async function inject(filename, resourceName, resourceData, options) { const machoSegmentName = options?.machoSegmentName || "__POSTJECT"; const overwrite = options?.overwrite || false; + let sentinelFuse = options?.sentinelFuse || "POSTJECT_SENTINEL_fce680ab2cc467b6e072b8b5df1996b2"; if (!Buffer.isBuffer(resourceData)) { throw new TypeError("resourceData must be a buffer"); } @@ -5140,8 +5141,38 @@ Use --overwrite to overwrite the existing content` if (result !== postject.InjectResult.kSuccess) { throw new Error("Error when injecting resource"); } + const buffer = Buffer.from(data.buffer); + const firstSentinel = buffer.indexOf(sentinelFuse); + if (firstSentinel === -1) { + throw new Error( + `Could not find the sentinel ${sentinelFuse} in the binary` + ); + } + const lastSentinel = buffer.lastIndexOf(sentinelFuse); + if (firstSentinel !== lastSentinel) { + throw new Error( + `Multiple occurences of sentinel "${sentinelFuse}" found in the binary` + ); + } + const colonIndex = firstSentinel + sentinelFuse.length; + if (buffer[colonIndex] !== ":".charCodeAt(0)) { + throw new Error( + `Value at index ${colonIndex} must be ':' but '${buffer[colonIndex].charCodeAt(0)}' was found` + ); + } + const hasResourceIndex = firstSentinel + sentinelFuse.length + 1; + const hasResourceValue = buffer[hasResourceIndex]; + if (hasResourceValue === "0".charCodeAt(0)) { + buffer[hasResourceIndex] = "1".charCodeAt(0); + } else if (hasResourceValue != "1".charCodeAt(0)) { + throw new Error( + `Value at index ${hasResourceIndex} must be '0' or '1' but '${hasResourceValue.charCodeAt( + 0 + )}' was found` + ); + } try { - await fs.writeFile(filename, data); + await fs.writeFile(filename, buffer); } catch { throw new Error("Couldn't write executable"); } diff --git a/test/fixtures/postject-copy/node_modules/postject/dist/cli.js b/test/fixtures/postject-copy/node_modules/postject/dist/cli.js index b68f17cb3da524..d963ad438c1c21 100755 --- a/test/fixtures/postject-copy/node_modules/postject/dist/cli.js +++ b/test/fixtures/postject-copy/node_modules/postject/dist/cli.js @@ -28,6 +28,7 @@ async function main(filename, resourceName, resource, options) { await inject(filename, resourceName, resourceData, { machoSegmentName: options.machoSegmentName, overwrite: options.overwrite, + sentinelFuse: options.sentinelFuse, }); } catch (err) { console.log(err.message); @@ -52,6 +53,11 @@ if (require.main === module) { "Name for the Mach-O segment", "__POSTJECT" ) + .option( + "--sentinel-fuse ", + "Sentinel fuse for resource presence detection", + "POSTJECT_SENTINEL_fce680ab2cc467b6e072b8b5df1996b2" + ) .option("--output-api-header", "Output the API header to stdout") .option("--overwrite", "Overwrite the resource if it already exists") .action(main) diff --git a/test/fixtures/postject-copy/node_modules/postject/dist/postject-api.h b/test/fixtures/postject-copy/node_modules/postject/dist/postject-api.h index 14899ee1cba87e..4ec1f64faaf245 100644 --- a/test/fixtures/postject-copy/node_modules/postject/dist/postject-api.h +++ b/test/fixtures/postject-copy/node_modules/postject/dist/postject-api.h @@ -1,8 +1,7 @@ -// Copyright (c) 2022 Postman, Inc. - #ifndef POSTJECT_API_H_ #define POSTJECT_API_H_ +#include #include #include #include @@ -19,6 +18,11 @@ #include #endif +#ifndef POSTJECT_SENTINEL_FUSE +#define POSTJECT_SENTINEL_FUSE \ + "POSTJECT_SENTINEL_fce680ab2cc467b6e072b8b5df1996b2" +#endif + struct postject_options { const char* elf_section_name; const char* macho_framework_name; @@ -27,7 +31,7 @@ struct postject_options { const char* pe_resource_name; }; -static void postject_options_init(struct postject_options* options) { +inline void postject_options_init(struct postject_options* options) { options->elf_section_name = NULL; options->macho_framework_name = NULL; options->macho_section_name = NULL; @@ -35,6 +39,11 @@ static void postject_options_init(struct postject_options* options) { options->pe_resource_name = NULL; } +static inline bool postject_has_resource() { + static const volatile char* sentinel = POSTJECT_SENTINEL_FUSE ":0"; + return sentinel[sizeof(POSTJECT_SENTINEL_FUSE)] == '1'; +} + static const void* postject_find_resource( const char* name, size_t* size, @@ -67,12 +76,19 @@ static const void* postject_find_resource( unsigned long section_size; char* ptr = NULL; if (options != NULL && options->macho_framework_name != NULL) { +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#endif ptr = getsectdatafromFramework(options->macho_framework_name, segment_name, section_name != NULL ? section_name : name, §ion_size); } else { ptr = getsectdata(segment_name, section_name != NULL ? section_name : name, §ion_size); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif if (ptr != NULL) { // Add the "virtual memory address slide" amount to ensure a valid pointer @@ -93,7 +109,6 @@ static const void* postject_find_resource( return ptr; #elif defined(__linux__) - void* ptr = NULL; if (options != NULL && options->elf_section_name != NULL) { name = options->elf_section_name; @@ -151,7 +166,7 @@ static const void* postject_find_resource( if (resource_name == NULL) { return NULL; } - strcpy(resource_name, name); + strcpy_s(resource_name, strlen(name) + 1, name); CharUpperA(resource_name); // Uppercases inplace } diff --git a/test/fixtures/postject-copy/node_modules/postject/package.json b/test/fixtures/postject-copy/node_modules/postject/package.json index 26b8bc05e04fb5..f792bd0a44186f 100644 --- a/test/fixtures/postject-copy/node_modules/postject/package.json +++ b/test/fixtures/postject-copy/node_modules/postject/package.json @@ -1,45 +1,35 @@ { - "_from": "postject", - "_id": "postject@1.0.0-alpha.3", - "_inBundle": false, - "_integrity": "sha512-AIattc/qdnUi3jLVWE0mVgzReLAExaWHhe3PAiztjVsjD/5sWxfAWsLd5FwXLU0iM3l9viMmFlOxEcsMqI/JYQ==", - "_location": "/postject", - "_phantomChildren": {}, - "_requested": { - "type": "tag", - "registry": true, - "raw": "postject", - "name": "postject", - "escapedName": "postject", - "rawSpec": "", - "saveSpec": null, - "fetchSpec": "latest" + "name": "postject", + "version": "1.0.0-alpha.4", + "description": "Easily inject arbitrary read-only resources into executable formats (Mach-O, PE, ELF) and use it at runtime.", + "license": "MIT", + "engines": { + "node": ">=14.0.0" }, - "_requiredBy": [ - "#USER", - "/" - ], - "_resolved": "https://registry.npmjs.org/postject/-/postject-1.0.0-alpha.3.tgz", - "_shasum": "6d20a9ce18279587e0ac024756c7f75070d0fef6", - "_spec": "postject", - "_where": "/Users/raisinten/Desktop/git/node/test/fixtures/postject-copy", - "author": { - "name": "Postman Labs", - "email": "help@postman.com", - "url": "=" + "repository": { + "type": "git", + "url": "git@github.com:postmanlabs/postject.git" }, + "homepage": "https://github.com/postmanlabs/postject#readme", + "author": "Postman Labs (=)", "bin": { - "postject": "dist/cli.js" + "postject": "./dist/cli.js" }, - "bugs": { - "url": "https://github.com/postmanlabs/postject/issues" + "main": "dist/api.js", + "scripts": { + "build": "zx ./scripts/build.mjs", + "clean": "rimraf ./build", + "format": "npm run format:cpp && npm run format:js", + "format:cpp": "clang-format -style=chromium -i postject-api.h src/**.cpp test/**.c test/**.cpp", + "format:js": "prettier --write src/**.js scripts/**.mjs test/**.mjs", + "lint": "npm run lint:cpp && npm run lint:js", + "lint:cpp": "clang-format -style=chromium --dry-run --Werror postject-api.h src/**.cpp test/**.c test/**.cpp", + "lint:js": "prettier --check src/**.js scripts/**.mjs test/**.mjs", + "test": "mocha" }, - "bundleDependencies": false, "dependencies": { "commander": "^9.4.0" }, - "deprecated": false, - "description": "Easily inject arbitrary read-only resources into executable formats (Mach-O, PE, ELF) and use it at runtime.", "devDependencies": { "chai": "^4.3.6", "chai-as-promised": "^7.1.1", @@ -52,28 +42,5 @@ "rimraf": "^3.0.2", "tempy": "^3.0.0", "zx": "^7.0.8" - }, - "engines": { - "node": ">=14.0.0" - }, - "homepage": "https://github.com/postmanlabs/postject#readme", - "license": "MIT", - "main": "dist/api.js", - "name": "postject", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/postmanlabs/postject.git" - }, - "scripts": { - "build": "zx ./scripts/build.mjs", - "clean": "rimraf ./build", - "format": "npm run format:cpp && npm run format:js", - "format:cpp": "clang-format -style=chromium -i postject-api.h src/**.cpp test/**.c test/**.cpp", - "format:js": "prettier --write src/**.js scripts/**.mjs test/**.mjs", - "lint": "npm run lint:cpp && npm run lint:js", - "lint:cpp": "clang-format -style=chromium --dry-run --Werror postject-api.h src/**.cpp test/**.c test/**.cpp", - "lint:js": "prettier --check src/**.js scripts/**.mjs test/**.mjs", - "test": "mocha" - }, - "version": "1.0.0-alpha.3" + } } diff --git a/test/fixtures/postject-copy/package-lock.json b/test/fixtures/postject-copy/package-lock.json index f4a54c686f7a52..ffaba9038a45ae 100644 --- a/test/fixtures/postject-copy/package-lock.json +++ b/test/fixtures/postject-copy/package-lock.json @@ -1,20 +1,37 @@ { "name": "postject-copy", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 3, "requires": true, - "dependencies": { - "commander": { - "version": "9.4.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-9.4.1.tgz", - "integrity": "sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw==" + "packages": { + "": { + "name": "postject-copy", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "postject": "^1.0.0-alpha.4" + } + }, + "node_modules/commander": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "engines": { + "node": "^12.20.0 || >=14" + } }, - "postject": { - "version": "1.0.0-alpha.3", - "resolved": "https://registry.npmjs.org/postject/-/postject-1.0.0-alpha.3.tgz", - "integrity": "sha512-AIattc/qdnUi3jLVWE0mVgzReLAExaWHhe3PAiztjVsjD/5sWxfAWsLd5FwXLU0iM3l9viMmFlOxEcsMqI/JYQ==", - "requires": { + "node_modules/postject": { + "version": "1.0.0-alpha.4", + "resolved": "https://registry.npmjs.org/postject/-/postject-1.0.0-alpha.4.tgz", + "integrity": "sha512-CdGzQJWzB2btwUQdrVJtpcHLldK4yclZyvYu6eZdEspd8bUq4zmhuT1y75ccE2QOpUpvFw/PuzpmbFwyIX9sLQ==", + "dependencies": { "commander": "^9.4.0" + }, + "bin": { + "postject": "dist/cli.js" + }, + "engines": { + "node": ">=14.0.0" } } } diff --git a/test/fixtures/postject-copy/package.json b/test/fixtures/postject-copy/package.json index 34338c81a26cd3..0877d5266dfb41 100644 --- a/test/fixtures/postject-copy/package.json +++ b/test/fixtures/postject-copy/package.json @@ -10,6 +10,6 @@ "author": "", "license": "ISC", "dependencies": { - "postject": "^1.0.0-alpha.3" + "postject": "^1.0.0-alpha.4" } }