Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ELF inject when sections offsets are not in ascending order #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Nik-RE-dev
Copy link

Here's structure of ELF segments in the file I was working with:

Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x0000e0 0x81000000 0x00000000 0x234c04 0x234c04 R E 0x10
LOAD 0x234cf0 0x81235000 0x00000000 0x0be60 0x3c918 RW 0x10
LOOS+0 0x242ce0 0x00000000 0x00000000 0x59040 0x00000 0x10
LOOS+0 0x29bd20 0x00000000 0x00000000 0x02d3c 0x00000 0x10
LOOS+0xfffff01 0x240b50 0x00000000 0x00000000 0x02186 0x00000 0x10

LOOS+0 is PT_SCE_RELA
LOOS+0xfffff01 is PT_SCE_LIBVERSION

Offsets of segments here is not in ascending order and the same mapping used in SELF container.
But current implementation of elf_injector tool implicitly relies on ascending order of offsets when applying offset correction.
In my case when offsets of 2-nd PT_LOAD and 1-st PT_SCE_RELA were corrected, writing compressed PT_SCE_LIBVERSION segment could overwrite already written PT_LOAD/PT_SCE_RELA segments.

I implemented sorting of compressed segments by offsets before computing offset correction.

@CelesteBlue-dev
Copy link
Contributor

Hello. Thank you for fixing that bug. What is the TITLEID of that testcase ELF so that I can reproduce the bug and test the fix?

@Nik-RE-dev
Copy link
Author

It's PCSG00246.
Bug happened for me then I made enough changes in 1-st PT_SCE_RELA.

@CelesteBlue-dev CelesteBlue-dev added the bug Something isn't working label Dec 27, 2022
@CelesteBlue-dev CelesteBlue-dev self-assigned this Dec 27, 2022
@CelesteBlue-dev CelesteBlue-dev removed their assignment Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants