refactor(patcher): separate linux and windows elf patchers
This commit is contained in:
parent
007ba188bb
commit
0a44083bbf
|
|
@ -1,6 +1,7 @@
|
|||
add_executable(relinker
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/elfpatcher/src/ElfPatcher.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/elfpatcher/src/linux/LinuxElfPatcher.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/elfpatcher/src/windows/WindowsElfPatcher.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/elfpatcher/src/filtering/SegmentFilter.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/elfpatcher/src/stub/EntryStubBuilder.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/elfpatcher/src/layout/ProgramHeaderLayoutBuilder.cpp
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef ELFPATCHER_ELFPATCHER_HPP
|
||||
#define ELFPATCHER_ELFPATCHER_HPP
|
||||
#ifndef ELFPATCHER_LINUX_LINUXELFPATCHER_HPP
|
||||
#define ELFPATCHER_LINUX_LINUXELFPATCHER_HPP
|
||||
|
||||
#include <elfpatcher/IElfPatcher.hpp>
|
||||
#include <elfpatcher/domain/IEntryStubBuilder.hpp>
|
||||
|
|
@ -8,11 +8,11 @@
|
|||
#include <io/IByteWriter.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Elfpatcher {
|
||||
namespace Elfpatcher::Linux {
|
||||
|
||||
class ElfPatcher : public IElfPatcher {
|
||||
class LinuxElfPatcher : public IElfPatcher {
|
||||
public:
|
||||
ElfPatcher(
|
||||
LinuxElfPatcher(
|
||||
std::shared_ptr<IEntryStubBuilder> entryStubBuilder,
|
||||
std::shared_ptr<IProgramHeaderLayoutBuilder> programHeaderLayoutBuilder,
|
||||
std::shared_ptr<ISectionHeaderTableBuilder> sectionHeaderTableBuilder,
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef ELFPATCHER_WINDOWS_WINDOWSELFPATCHER_HPP
|
||||
#define ELFPATCHER_WINDOWS_WINDOWSELFPATCHER_HPP
|
||||
|
||||
#include <elfpatcher/IElfPatcher.hpp>
|
||||
#include <elfpatcher/domain/IEntryStubBuilder.hpp>
|
||||
#include <elfpatcher/domain/IProgramHeaderLayoutBuilder.hpp>
|
||||
#include <elfpatcher/domain/ISectionHeaderTableBuilder.hpp>
|
||||
#include <io/IByteWriter.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Elfpatcher::Windows {
|
||||
|
||||
class WindowsElfPatcher : public IElfPatcher {
|
||||
public:
|
||||
WindowsElfPatcher(
|
||||
std::shared_ptr<IEntryStubBuilder> entryStubBuilder,
|
||||
std::shared_ptr<IProgramHeaderLayoutBuilder> programHeaderLayoutBuilder,
|
||||
std::shared_ptr<ISectionHeaderTableBuilder> sectionHeaderTableBuilder,
|
||||
std::shared_ptr<Io::IByteWriter> byteWriter
|
||||
);
|
||||
|
||||
std::vector<std::uint8_t> Patch(
|
||||
const std::vector<std::uint8_t>& sourceElf,
|
||||
const std::vector<Domain::ProgramHeader>& originalHeaders,
|
||||
const Domain::SysVDynamicSection& dynamicSection
|
||||
) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<IEntryStubBuilder> _entryStubBuilder;
|
||||
std::shared_ptr<IProgramHeaderLayoutBuilder> _programHeaderLayoutBuilder;
|
||||
std::shared_ptr<ISectionHeaderTableBuilder> _sectionHeaderTableBuilder;
|
||||
std::shared_ptr<Io::IByteWriter> _byteWriter;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
#include <elfpatcher/ElfPatcher.hpp>
|
||||
#include <elfpatcher/linux/LinuxElfPatcher.hpp>
|
||||
#include <elfpatcher/domain/ElfConstants.hpp>
|
||||
#include <elfpatcher/domain/ProgramHeaderLayoutRequest.hpp>
|
||||
#include <elfpatcher/domain/SectionHeaderTableRequest.hpp>
|
||||
|
||||
namespace Elfpatcher {
|
||||
namespace Elfpatcher::Linux {
|
||||
|
||||
ElfPatcher::ElfPatcher(
|
||||
LinuxElfPatcher::LinuxElfPatcher(
|
||||
std::shared_ptr<IEntryStubBuilder> entryStubBuilder,
|
||||
std::shared_ptr<IProgramHeaderLayoutBuilder> programHeaderLayoutBuilder,
|
||||
std::shared_ptr<ISectionHeaderTableBuilder> sectionHeaderTableBuilder,
|
||||
|
|
@ -18,12 +18,12 @@ ElfPatcher::ElfPatcher(
|
|||
{
|
||||
}
|
||||
|
||||
void ElfPatcher::_appendDynEntry(std::vector<std::uint8_t>& buf, std::int64_t tag, std::uint64_t val) const {
|
||||
void LinuxElfPatcher::_appendDynEntry(std::vector<std::uint8_t>& buf, std::int64_t tag, std::uint64_t val) const {
|
||||
_byteWriter->AppendI64(buf, tag);
|
||||
_byteWriter->AppendU64(buf, val);
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> ElfPatcher::Patch(
|
||||
std::vector<std::uint8_t> LinuxElfPatcher::Patch(
|
||||
const std::vector<std::uint8_t>& sourceElf,
|
||||
const std::vector<Domain::ProgramHeader>& originalHeaders,
|
||||
const Domain::SysVDynamicSection& dynSection)
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#include <elfpatcher/windows/WindowsElfPatcher.hpp>
|
||||
#include <domain/Types.hpp>
|
||||
|
||||
namespace Elfpatcher::Windows {
|
||||
|
||||
WindowsElfPatcher::WindowsElfPatcher(
|
||||
std::shared_ptr<IEntryStubBuilder> entryStubBuilder,
|
||||
std::shared_ptr<IProgramHeaderLayoutBuilder> programHeaderLayoutBuilder,
|
||||
std::shared_ptr<ISectionHeaderTableBuilder> sectionHeaderTableBuilder,
|
||||
std::shared_ptr<Io::IByteWriter> byteWriter
|
||||
)
|
||||
: _entryStubBuilder(std::move(entryStubBuilder))
|
||||
, _programHeaderLayoutBuilder(std::move(programHeaderLayoutBuilder))
|
||||
, _sectionHeaderTableBuilder(std::move(sectionHeaderTableBuilder))
|
||||
, _byteWriter(std::move(byteWriter))
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> WindowsElfPatcher::Patch(
|
||||
const std::vector<std::uint8_t>& sourceElf,
|
||||
const std::vector<Domain::ProgramHeader>& originalHeaders,
|
||||
const Domain::SysVDynamicSection& dynamicSection)
|
||||
{
|
||||
throw Domain::RelinkerException("Not implemented");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#include <domain/Types.hpp>
|
||||
#include <io/FileReader.hpp>
|
||||
#include <io/FileWriter.hpp>
|
||||
#include <elfpatcher/ElfPatcher.hpp>
|
||||
#include <elfpatcher/linux/LinuxElfPatcher.hpp>
|
||||
#include <elfpatcher/filtering/SegmentFilter.hpp>
|
||||
#include <elfpatcher/stub/EntryStubBuilder.hpp>
|
||||
#include <elfpatcher/layout/ProgramHeaderLayoutBuilder.hpp>
|
||||
|
|
@ -71,7 +71,7 @@ int main(const int argc, char* argv[]) {
|
|||
}
|
||||
|
||||
auto byteWriter = std::make_shared<Io::ByteWriter>();
|
||||
Elfpatcher::ElfPatcher elfPatcher(
|
||||
Elfpatcher::Linux::LinuxElfPatcher elfPatcher(
|
||||
std::make_shared<Elfpatcher::EntryStubBuilder>(),
|
||||
std::make_shared<Elfpatcher::ProgramHeaderLayoutBuilder>(
|
||||
std::make_shared<Elfpatcher::SegmentFilter>(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue