X-Git-Url: https://git.distorted.org.uk/~mdw/termux-packages/blobdiff_plain/59f0d218a6ff34c80cf898f6d7ac62555ba8eb11..8272bfb20e0064b48dfbc72572450927d4916ab9:/packages/termux-tools/termux-elf-cleaner.cpp diff --git a/packages/termux-tools/termux-elf-cleaner.cpp b/packages/termux-tools/termux-elf-cleaner.cpp index b760deab..d232b016 100644 --- a/packages/termux-tools/termux-elf-cleaner.cpp +++ b/packages/termux-tools/termux-elf-cleaner.cpp @@ -23,14 +23,14 @@ template elf_file_size) { - fprintf(stderr, "ERROR: Elf header would end at %lu but file size only %lu\n", sizeof(ElfSectionHeaderType), elf_file_size); + fprintf(stderr, "ERROR: Elf header would end at %zu but file size only %zu\n", sizeof(ElfSectionHeaderType), elf_file_size); return false; } ElfHeaderType* elf_hdr = reinterpret_cast(bytes); size_t last_section_header_byte = elf_hdr->e_shoff + sizeof(ElfSectionHeaderType) * elf_hdr->e_shnum; if (last_section_header_byte > elf_file_size) { - fprintf(stderr, "ERROR: Section header would end at %lu but file size only %lu\n", last_section_header_byte, elf_file_size); + fprintf(stderr, "ERROR: Section header would end at %zu but file size only %zu\n", last_section_header_byte, elf_file_size); return false; } ElfSectionHeaderType* section_header_table = reinterpret_cast(bytes + elf_hdr->e_shoff); @@ -40,7 +40,7 @@ bool process_elf(uint8_t* bytes, size_t elf_file_size) if (section_header_entry->sh_type == SHT_DYNAMIC) { size_t const last_dynamic_section_byte = section_header_entry->sh_offset + section_header_entry->sh_size; if (last_dynamic_section_byte > elf_file_size) { - fprintf(stderr, "ERROR: Dynamic section would end at %lu but file size only %lu\n", last_dynamic_section_byte, elf_file_size); + fprintf(stderr, "ERROR: Dynamic section would end at %zu but file size only %zu\n", last_dynamic_section_byte, elf_file_size); return false; } @@ -59,24 +59,20 @@ bool process_elf(uint8_t* bytes, size_t elf_file_size) for (unsigned int j = 0; j < dynamic_section_entries; j++) { ElfDynamicSectionEntryType* dynamic_section_entry = dynamic_section + j; + char const* removed_name = nullptr; switch (dynamic_section_entry->d_tag) { - case DT_VERNEEDED: - case DT_VERNEEDNUM: - case DT_RPATH: - case DT_RUNPATH: - char const* removed_name; - switch (dynamic_section_entry->d_tag) { - case DT_VERNEEDED: removed_name = "DT_VERNEEDED"; break; - case DT_VERNEEDNUM: removed_name = "DT_VERNEEDNUM"; break; - case DT_RPATH: removed_name = "DT_RPATH"; break; - case DT_RUNPATH: removed_name = "DT_RUNPATH"; break; - } - printf("Removing the %s dynamic section entry\n", removed_name); - // Tag the entry with DT_NULL and put it last: - dynamic_section_entry->d_tag = DT_NULL; - // Decrease j to process new entry index: - std::swap(dynamic_section[j--], dynamic_section[last_nonnull_entry_idx--]); - break; + case DT_VERNEEDED: removed_name = "DT_VERNEEDED"; break; + case DT_VERNEEDNUM: removed_name = "DT_VERNEEDNUM"; break; + case DT_RPATH: removed_name = "DT_RPATH"; break; + case DT_RUNPATH: removed_name = "DT_RUNPATH"; break; + } + if (removed_name != nullptr) { + printf("Removing the %s dynamic section entry\n", removed_name); + // Tag the entry with DT_NULL and put it last: + dynamic_section_entry->d_tag = DT_NULL; + // Decrease j to process new entry index: + std::swap(dynamic_section[j--], dynamic_section[last_nonnull_entry_idx--]); + break; } } }