Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Commit

Permalink
Fix wrong section detection
Browse files Browse the repository at this point in the history
old vita-make-self used header_len value for second elf starting offset.
and this value [always set 0x1000][1].

but compressed case, section can allocate inside of header part.

this change introduced [vitasdk/vita-toolchain@49ea8ff24][2].

[1]: https://github.com/vitasdk/vita-toolchain/blob/2f11d0e/src/vita-make-fself.c#L107
[2]: vitasdk/vita-toolchain@49ea8ff246e6
  • Loading branch information
d3m3vilurr committed Dec 27, 2016
1 parent 5f4656c commit f0a9325
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions archive.c
Expand Up @@ -65,22 +65,19 @@ int archiveCheckFilesForUnsafeFself() {
archiveFileRead(ARCHIVE_FD, &dummy, sizeof(uint32_t));
}

// ELF header starts at header_len, so let's seek to there
uint64_t header_len = *(uint64_t *)(sce_header + 0xC);
char elf1[header_len - elf1_offset];
archiveFileRead(ARCHIVE_FD, elf1, header_len - elf1_offset);

// Check imports
char *buffer = malloc(archive_entry->size);
if (buffer) {
int size = archiveFileRead(ARCHIVE_FD, buffer, archive_entry->size);
if (buffer[0] == 0x78) {
char *uncompressed_buffer = uncompressBuffer(
(Elf32_Ehdr*)elf1,
(Elf32_Phdr*)(elf1 + phdr_offset - elf1_offset),
(segment_info*)(elf1 + section_info_offset - elf1_offset),
buffer
);

Elf32_Ehdr *elf1 = (Elf32_Ehdr*)buffer;
Elf32_Phdr *phdr = (Elf32_Phdr*)buffer + phdr_offset - elf1_offset;
segment_info *info = (segment_info*)(buffer + section_info_offset - elf1_offset);
char *segment = buffer + info->offset;

// zlib compress magic
if (segment[0] == 0x78) {
char *uncompressed_buffer = uncompressBuffer(elf1, phdr, info, segment);
if (uncompressed_buffer) {
free(buffer);
buffer = uncompressed_buffer;
Expand Down

0 comments on commit f0a9325

Please sign in to comment.