Насколько я понимаю, каждый раздел имеет определенный размер, и если новые данные превышают размер раздела, это может привести к повреждению. другие данные в файле elf. Нужно ли мне найти смещение этого раздела и его размер, а затем попытаться изменить данные в памяти? Могу ли я добиться этого, используя библиотеку ELFIO?
Это мой код для добавления нового раздела и данных в файл elf:
Код: Выделить всё
void writeToELF(std::string& filePath, std::string& str) {
ELFIO::elfio writer;
if (!writer.load(filePath)) {
throw std::runtime_error("Can't find or load ELF file.");
}
const std::string sectionName = ".random";
ELFIO::section* newSection = writer.sections.add(sectionName.c_str());
newSection->set_type(ELFIO::SHT_PROGBITS);
newSection->set_flags(ELFIO::SHF_WRITE | ELFIO::SHF_ALLOC);
newSection->set_addr_align(0x4);
newSection->set_data(str.data(), str.size());
writer.set_entry(newSection->get_address());
const std::string modifiedELF = "modified_" + filePath;
if (!writer.save(modifiedELF.c_str())) {
throw std::runtime_error("Error saving modified file.");
}
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78479284/how-can-i-modify-the-content-of-an-elf-file-section-using-elfio-in-c[/url]
Мобильная версия