Skip to content

feat: make postject faster #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/postject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ enum class ExecutableFormat { kELF, kMachO, kPE, kUnknown };
enum class InjectResult { kAlreadyExists, kError, kSuccess };

std::vector<uint8_t> vec_from_val(const emscripten::val& value) {
// TODO(dsanders11) - vecFromJSArray incurs a copy, so memory usage is higher
// than it needs to be. Explore ways to access the memory
// directly and avoid the copy.
return emscripten::vecFromJSArray<uint8_t>(value);
// We are using `convertJSArrayToNumberVector()` instead of `vecFromJSArray()`
// because it is faster. It is okay if we use it without additional type
// checking because this function is only called on Node.js Buffer instances
// which is expected to contain elements that are safe to pass to the JS
// function, `Number()`.
return emscripten::convertJSArrayToNumberVector<uint8_t>(value);
}

ExecutableFormat get_executable_format(const emscripten::val& executable) {
Expand Down
8 changes: 4 additions & 4 deletions test/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("postject CLI", () => {
expect(status).to.equal(0);
expect(stdout).to.have.string(resourceContents);
}
}).timeout(3_00_000);
}).timeout(15_000);

it("should display an error message when filename doesn't exist", async () => {
{
Expand All @@ -137,7 +137,7 @@ describe("postject CLI", () => {
expect(stdout).to.not.have.string("Injection done!");
expect(status).to.equal(1);
}
}).timeout(3_00_000);
}).timeout(15_000);

it("should display an error message when the file is not a supported executable type", async () => {
const bogusFile = path.join(tempDir, "bogus.exe");
Expand All @@ -160,7 +160,7 @@ describe("postject CLI", () => {
);
expect(stdout).to.not.have.string("Injection done!");
expect(status).to.equal(1);
}).timeout(3_00_000);
}).timeout(15_000);
});

describe("postject API", () => {
Expand Down Expand Up @@ -234,7 +234,7 @@ describe("postject API", () => {
expect(status).to.equal(0);
expect(stdout).to.have.string(resourceContents);
}
}).timeout(3_00_000);
}).timeout(15_000);
});

describe("api.js should not contain __filename and __dirname", () => {
Expand Down