deps,test: update postject to 1.0.0-alpha.5

PR-URL: https://github.com/nodejs/node/pull/46934
Fixes: https://github.com/nodejs/postject/issues/76
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Node.js GitHub Bot 2023-03-03 11:20:06 +00:00 committed by Darshan Sen
parent ab9b4671e4
commit 2deae0c0a9
No known key found for this signature in database
GPG key ID: AF78F02FFD0C0E3C
8 changed files with 56 additions and 23 deletions

View file

@ -12,7 +12,6 @@
#elif defined(__linux__)
#include <elf.h>
#include <link.h>
#include <sys/auxv.h>
#include <sys/param.h>
#elif defined(_WIN32)
#include <windows.h>
@ -44,6 +43,16 @@ static inline bool postject_has_resource() {
return sentinel[sizeof(POSTJECT_SENTINEL_FUSE)] == '1';
}
#if defined(__linux__)
static int postject__dl_iterate_phdr_callback(struct dl_phdr_info* info,
size_t size,
void* data) {
// Snag the dl_phdr_info struct for the main program, then stop iterating
*((struct dl_phdr_info*)data) = *info;
return 1;
}
#endif
static const void* postject_find_resource(
const char* name,
size_t* size,
@ -114,9 +123,12 @@ static const void* postject_find_resource(
name = options->elf_section_name;
}
uintptr_t p = getauxval(AT_PHDR);
size_t n = getauxval(AT_PHNUM);
uintptr_t base_addr = p - sizeof(ElfW(Ehdr));
struct dl_phdr_info main_program_info;
dl_iterate_phdr(postject__dl_iterate_phdr_callback, &main_program_info);
uintptr_t p = (uintptr_t)main_program_info.dlpi_phdr;
size_t n = main_program_info.dlpi_phnum;
uintptr_t base_addr = main_program_info.dlpi_addr;
// iterate program header
for (; n > 0; n--, p += sizeof(ElfW(Phdr))) {

View file

@ -13,9 +13,9 @@
}
},
"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==",
"version": "1.0.0-alpha.5",
"resolved": "https://registry.npmjs.org/postject/-/postject-1.0.0-alpha.5.tgz",
"integrity": "sha512-XDgGD+iKg3jSv+is2En18/lFkcu3sx6KhxD3DO25QT3Nca0QCrxVQj6uMTmMgVcaO7N6n8ne2+a04yX0N9RwgQ==",
"dependencies": {
"commander": "^9.4.0"
},

File diff suppressed because one or more lines are too long

View file

@ -5,6 +5,12 @@ const { constants, promises: fs } = require("fs");
const path = require("path");
const { inject } = require("./api.js");
const logger = {
info: (message) => console.log("\x1b[36m%s\x1b[0m", message),
success: (message) => console.log("\x1b[32m%s\x1b[0m", message),
error: (message) => console.log("\x1b[31mError: %s\x1b[0m", message),
};
async function main(filename, resourceName, resource, options) {
if (options.outputApiHeader) {
// Handles --output-api-header.
@ -20,18 +26,22 @@ async function main(filename, resourceName, resource, options) {
await fs.access(resource, constants.R_OK);
resourceData = await fs.readFile(resource);
} catch {
console.log("Can't read resource file");
logger.error("Can't read resource file");
process.exit(1);
}
try {
logger.info(
"Start injection of " + resourceName + " in " + filename + "..."
);
await inject(filename, resourceName, resourceData, {
machoSegmentName: options.machoSegmentName,
overwrite: options.overwrite,
sentinelFuse: options.sentinelFuse,
});
logger.success("💉 Injection done!");
} catch (err) {
console.log(err.message);
logger.error(err.message);
process.exit(1);
}
}

View file

@ -12,7 +12,6 @@
#elif defined(__linux__)
#include <elf.h>
#include <link.h>
#include <sys/auxv.h>
#include <sys/param.h>
#elif defined(_WIN32)
#include <windows.h>
@ -44,6 +43,16 @@ static inline bool postject_has_resource() {
return sentinel[sizeof(POSTJECT_SENTINEL_FUSE)] == '1';
}
#if defined(__linux__)
static int postject__dl_iterate_phdr_callback(struct dl_phdr_info* info,
size_t size,
void* data) {
// Snag the dl_phdr_info struct for the main program, then stop iterating
*((struct dl_phdr_info*)data) = *info;
return 1;
}
#endif
static const void* postject_find_resource(
const char* name,
size_t* size,
@ -114,9 +123,12 @@ static const void* postject_find_resource(
name = options->elf_section_name;
}
uintptr_t p = getauxval(AT_PHDR);
size_t n = getauxval(AT_PHNUM);
uintptr_t base_addr = p - sizeof(ElfW(Ehdr));
struct dl_phdr_info main_program_info;
dl_iterate_phdr(postject__dl_iterate_phdr_callback, &main_program_info);
uintptr_t p = (uintptr_t)main_program_info.dlpi_phdr;
size_t n = main_program_info.dlpi_phnum;
uintptr_t base_addr = main_program_info.dlpi_addr;
// iterate program header
for (; n > 0; n--, p += sizeof(ElfW(Phdr))) {

View file

@ -1,6 +1,6 @@
{
"name": "postject",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.5",
"description": "Easily inject arbitrary read-only resources into executable formats (Mach-O, PE, ELF) and use it at runtime.",
"license": "MIT",
"engines": {
@ -8,10 +8,9 @@
},
"repository": {
"type": "git",
"url": "git@github.com:postmanlabs/postject.git"
"url": "git@github.com:nodejs/postject.git"
},
"homepage": "https://github.com/postmanlabs/postject#readme",
"author": "Postman Labs <help@postman.com> (=)",
"homepage": "https://github.com/nodejs/postject#readme",
"bin": {
"postject": "./dist/cli.js"
},

View file

@ -9,7 +9,7 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"postject": "^1.0.0-alpha.4"
"postject": "^1.0.0-alpha.5"
}
},
"node_modules/commander": {
@ -21,9 +21,9 @@
}
},
"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==",
"version": "1.0.0-alpha.5",
"resolved": "https://registry.npmjs.org/postject/-/postject-1.0.0-alpha.5.tgz",
"integrity": "sha512-XDgGD+iKg3jSv+is2En18/lFkcu3sx6KhxD3DO25QT3Nca0QCrxVQj6uMTmMgVcaO7N6n8ne2+a04yX0N9RwgQ==",
"dependencies": {
"commander": "^9.4.0"
},

View file

@ -10,6 +10,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"postject": "^1.0.0-alpha.4"
"postject": "^1.0.0-alpha.5"
}
}