fix(elfpatcher): use original dt pltgot vaddr
This commit is contained in:
parent
8236d4e1a2
commit
f786ea6576
|
|
@ -14,7 +14,8 @@ public:
|
|||
virtual std::vector<std::uint8_t> Patch(
|
||||
const std::vector<std::uint8_t>& sourceElf,
|
||||
const std::vector<Domain::ProgramHeader>& originalHeaders,
|
||||
const Domain::SysVDynamicSection& dynamicSection
|
||||
const Domain::SysVDynamicSection& dynamicSection,
|
||||
std::uint64_t originalPltGotVaddr
|
||||
) = 0;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ public:
|
|||
std::vector<std::uint8_t> Patch(
|
||||
const std::vector<std::uint8_t>& sourceElf,
|
||||
const std::vector<Domain::ProgramHeader>& originalHeaders,
|
||||
const Domain::SysVDynamicSection& dynamicSection
|
||||
const Domain::SysVDynamicSection& dynamicSection,
|
||||
std::uint64_t originalPltGotVaddr
|
||||
) override;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ public:
|
|||
std::vector<std::uint8_t> Patch(
|
||||
const std::vector<std::uint8_t>& sourceElf,
|
||||
const std::vector<Domain::ProgramHeader>& originalHeaders,
|
||||
const Domain::SysVDynamicSection& dynamicSection
|
||||
const Domain::SysVDynamicSection& dynamicSection,
|
||||
std::uint64_t originalPltGotVaddr
|
||||
) override;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ void LinuxElfPatcher::_appendDynEntry(std::vector<std::uint8_t>& buf, std::int64
|
|||
std::vector<std::uint8_t> LinuxElfPatcher::Patch(
|
||||
const std::vector<std::uint8_t>& sourceElf,
|
||||
const std::vector<Domain::ProgramHeader>& originalHeaders,
|
||||
const Domain::SysVDynamicSection& dynSection)
|
||||
const Domain::SysVDynamicSection& dynSection,
|
||||
const std::uint64_t originalPltGotVaddr)
|
||||
{
|
||||
std::vector<std::uint8_t> buf = sourceElf;
|
||||
|
||||
|
|
@ -67,11 +68,6 @@ std::vector<std::uint8_t> LinuxElfPatcher::Patch(
|
|||
buf.push_back(b);
|
||||
alignBuf(buf, kRelaPltAlignment);
|
||||
|
||||
alignBuf(buf, kGotAlignment);
|
||||
const auto gotOff = static_cast<std::uint64_t>(buf.size());
|
||||
for (std::size_t i = 0; i < kGotReservedSlots; ++i)
|
||||
_byteWriter->AppendU64(buf, 0);
|
||||
|
||||
const std::uint64_t extraBlockOff = dynStrOff;
|
||||
const std::uint64_t extraBlockVaddr = _programHeaderLayoutBuilder->ComputeExtraBlockVaddr(originalHeaders, extraBlockOff);
|
||||
|
||||
|
|
@ -97,7 +93,7 @@ std::vector<std::uint8_t> LinuxElfPatcher::Patch(
|
|||
_appendDynEntry(dynSegBuf, DT_JMPREL, vaddrOfExtraBlockOffset(relaPltOff));
|
||||
_appendDynEntry(dynSegBuf, DT_PLTRELSZ, dynSection.RelaPltData.size());
|
||||
_appendDynEntry(dynSegBuf, DT_PLTREL, static_cast<std::uint64_t>(DT_RELA));
|
||||
_appendDynEntry(dynSegBuf, DT_PLTGOT, vaddrOfExtraBlockOffset(gotOff));
|
||||
_appendDynEntry(dynSegBuf, DT_PLTGOT, originalPltGotVaddr);
|
||||
}
|
||||
_appendDynEntry(dynSegBuf, DT_NULL, 0);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ WindowsElfPatcher::WindowsElfPatcher(
|
|||
std::vector<std::uint8_t> WindowsElfPatcher::Patch(
|
||||
const std::vector<std::uint8_t>& sourceElf,
|
||||
const std::vector<Domain::ProgramHeader>& originalHeaders,
|
||||
const Domain::SysVDynamicSection& dynamicSection)
|
||||
const Domain::SysVDynamicSection& dynamicSection,
|
||||
std::uint64_t originalPltGotVaddr)
|
||||
{
|
||||
throw Domain::RelinkerException("Not implemented");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ int main(const int argc, char* argv[]) {
|
|||
std::make_shared<Elfpatcher::SectionHeaderTableBuilder>(byteWriter),
|
||||
byteWriter
|
||||
);
|
||||
auto patchedElf = elfPatcher.Patch(sourceBytes, result.OriginalHeaders, result.DynamicSection);
|
||||
auto patchedElf = elfPatcher.Patch(sourceBytes, result.OriginalHeaders, result.DynamicSection, result.OriginalPltGotVaddr);
|
||||
fileWriter.Write(outputElfPath, patchedElf);
|
||||
|
||||
} catch (const Domain::RelinkerException& e) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ struct RelinkResult {
|
|||
std::vector<CallRegistryEntry> RegistryEntries;
|
||||
std::vector<ProgramHeader> OriginalHeaders;
|
||||
SysVDynamicSection DynamicSection;
|
||||
VirtualAddress OriginalPltGotVaddr;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ RelinkResult RelinkerPipeline::Relink(const std::vector<std::uint8_t>& sourceElf
|
|||
|
||||
std::cout << "OK: " << entries.size() << " NID references processed\n";
|
||||
|
||||
return RelinkResult{std::move(entries), std::move(programHeaders), std::move(dynSection)};
|
||||
return RelinkResult{std::move(entries), std::move(programHeaders), std::move(dynSection), gotVAddr};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue