diff --git a/src/postject.cpp b/src/postject.cpp index f47c855..cc937ab 100644 --- a/src/postject.cpp +++ b/src/postject.cpp @@ -7,7 +7,8 @@ #include "./postject.hpp" -postject::ExecutableFormat postject::get_executable_format(const std::vector& executable) { +postject::ExecutableFormat postject::get_executable_format( + const std::vector& executable) { if (LIEF::ELF::is_elf(executable)) { return ExecutableFormat::kELF; } else if (LIEF::MachO::is_macho(executable)) { @@ -19,10 +20,11 @@ postject::ExecutableFormat postject::get_executable_format(const std::vector& executable, - const std::string& note_name, - const std::vector& data, - bool overwrite) { +postject::InjectResult postject::inject_into_elf( + const std::vector& executable, + const std::string& note_name, + const std::vector& data, + bool overwrite) { InjectResult result; std::unique_ptr binary = LIEF::ELF::Parser::parse(executable); @@ -59,11 +61,12 @@ postject::InjectResult postject::inject_into_elf(const std::vector& exe return result; } -postject::InjectResult postject::inject_into_macho(const std::vector& executable, - const std::string& segment_name, - const std::string& section_name, - const std::vector& data, - bool overwrite) { +postject::InjectResult postject::inject_into_macho( + const std::vector& executable, + const std::string& segment_name, + const std::string& section_name, + const std::vector& data, + bool overwrite) { InjectResult result; std::unique_ptr fat_binary = LIEF::MachO::Parser::parse(executable); @@ -80,7 +83,6 @@ postject::InjectResult postject::inject_into_macho(const std::vector& e if (existing_section) { if (!overwrite) { - result.type = InjectResultType::kAlreadyExists; return result; } @@ -115,10 +117,11 @@ postject::InjectResult postject::inject_into_macho(const std::vector& e return result; } -postject::InjectResult postject::inject_into_pe(const std::vector& executable, - const std::string& resource_name, - const std::vector& data, - bool overwrite) { +postject::InjectResult postject::inject_into_pe( + const std::vector& executable, + const std::string& resource_name, + const std::vector& data, + bool overwrite) { InjectResult result; std::unique_ptr binary = diff --git a/src/postject_wasm.cpp b/src/postject_wasm.cpp index f39cff4..3125446 100644 --- a/src/postject_wasm.cpp +++ b/src/postject_wasm.cpp @@ -3,7 +3,6 @@ #include "./postject.hpp" - std::vector vec_from_val(const emscripten::val& value) { // We are using `convertJSArrayToNumberVector()` instead of `vecFromJSArray()` // because it is faster. It is okay if we use it without additional type @@ -13,7 +12,8 @@ std::vector vec_from_val(const emscripten::val& value) { return emscripten::convertJSArrayToNumberVector(value); } -postject::ExecutableFormat get_executable_format(const emscripten::val& executable) { +postject::ExecutableFormat get_executable_format( + const emscripten::val& executable) { return postject::get_executable_format(vec_from_val(executable)); } @@ -24,14 +24,14 @@ emscripten::val inject_result_to_val(postject::InjectResult injectResult) { std::vector output = std::move(injectResult.output); emscripten::val view{ emscripten::typed_memory_view(output.size(), output.data())}; - auto output_data = emscripten::val::global("Uint8Array").new_(output.size()); + auto output_data = + emscripten::val::global("Uint8Array").new_(output.size()); output_data.call("set", view); object.set("data", emscripten::val(output_data)); } else { object.set("data", emscripten::val::undefined()); } return object; - } emscripten::val inject_into_elf(const emscripten::val& executable, @@ -39,11 +39,7 @@ emscripten::val inject_into_elf(const emscripten::val& executable, const emscripten::val& data, bool overwrite) { return inject_result_to_val(postject::inject_into_elf( - vec_from_val(executable), - note_name, - vec_from_val(data), - overwrite - )); + vec_from_val(executable), note_name, vec_from_val(data), overwrite)); } emscripten::val inject_into_macho(const emscripten::val& executable, @@ -51,13 +47,9 @@ emscripten::val inject_into_macho(const emscripten::val& executable, const std::string& section_name, const emscripten::val& data, bool overwrite) { - return inject_result_to_val(postject::inject_into_macho( - vec_from_val(executable), - segment_name, - section_name, - vec_from_val(data), - overwrite - )); + return inject_result_to_val( + postject::inject_into_macho(vec_from_val(executable), segment_name, + section_name, vec_from_val(data), overwrite)); } emscripten::val inject_into_pe(const emscripten::val& executable, @@ -65,11 +57,7 @@ emscripten::val inject_into_pe(const emscripten::val& executable, const emscripten::val& data, bool overwrite) { return inject_result_to_val(postject::inject_into_pe( - vec_from_val(executable), - resource_name, - vec_from_val(data), - overwrite - )); + vec_from_val(executable), resource_name, vec_from_val(data), overwrite)); } EMSCRIPTEN_BINDINGS(postject) {