News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Expanding\Adding sections to a PS2 ELF?  (Read 958 times)

Krisan Thyme

  • Jr. Member
  • **
  • Posts: 14
    • View Profile
Expanding\Adding sections to a PS2 ELF?
« on: October 24, 2017, 09:32:43 am »
Does anyone have any experience with adding an additional section to a PS2 ELF? Or expanding an existing section? I'm working on a translation project at the moment, and while it's moved along rather smoothly thus far, it would be an incredible boon to have additional free space added to the ELF.

I've tried doing this manually via good ol' fashioned hex'ing, but while I've succeeded at producing a bootable ELF, it doesn't seem as though the additional space is accessible.. In fact anything immediately after the existing sections seems reserved for the stack. If I set the memory address to something that's free, it just.. never seems to load into memory, not sure why. I was wondering if there were any tools similar to objcopy that works with PS2\MIPS ELF's, or if anyone more experienced in the field would be willing to give me some advice? I'd really like to know what I'm missing here, as this would really be helpful to my project.
« Last Edit: October 24, 2017, 07:13:47 pm by Krisan Thyme »

neige

  • Jr. Member
  • **
  • Posts: 35
    • View Profile
Re: Expanding\Adding sections to a PS2 ELF?
« Reply #1 on: October 24, 2017, 08:46:14 pm »
First of all, the PS2 ignores the section headers, you can ignore or even remove them without problem.

If you want to add data, you have to edit or add an entry in the program headers.

As to where the stack and heap are located, check near the entry point for a bit of code similar to this:

Code: [Select]
00100198 7D 00 04 3C  lui     $a0, 0x7D           # gp
0010019C F6 01 05 3C  lui     $a1, 0x1F6          # stack
001001A0 0A 00 06 3C  lui     $a2, 0xA            # stack_size
001001A4 96 00 07 3C  lui     $a3, 0x96           # args
001001A8 10 00 08 3C  lui     $t0, 0x10           # root_func
001001AC F0 4B 84 24  la      $a0, unk_7D4BF0     # gp
001001B0 00 00 A5 24  li      $a1, 0x1F60000      # stack
001001B4 00 00 C6 24  li      $a2, 0xA0000        # stack_size
001001B8 80 E1 E7 24  la      $a3, dword_95E180   # args
001001BC 20 02 08 25  la      $t0, sub_100220     # root_func
001001C0 25 E0 80 00  or      $gp, $a0
001001C4 3C 00 03 24  li      $v1, 60             # SetupThread
001001C8 0C 00 00 00  syscall 0

001001D0 9B 00 04 3C  lui     $a0, 0x9B           # heap_start
001001D4 00 00 05 3C  lui     $a1, 0              # heap_size
001001D8 80 EB 84 24  la      $a0, 0x9AEB80       # heap_start
001001DC FF FF A5 24  li      $a1, 0xFFFFFFFF     # heap_size
001001E0 3D 00 03 24  li      $v1, 61             # SetupHeap
001001E4 0C 00 00 00  syscall 0

You may need to edit this code if you expand the loaded segment into the heap.

Krisan Thyme

  • Jr. Member
  • **
  • Posts: 14
    • View Profile
Re: Expanding\Adding sections to a PS2 ELF?
« Reply #2 on: October 24, 2017, 08:50:47 pm »
First of all, the PS2 ignores the section headers, you can ignore or even remove them without problem.

If you want to add data, you have to edit or add an entry in the program headers.

As to where the stack and heap are located, check near the entry point for a bit of code similar to this:

Code: [Select]
00100198 7D 00 04 3C  lui     $a0, 0x7D           # gp
0010019C F6 01 05 3C  lui     $a1, 0x1F6          # stack
001001A0 0A 00 06 3C  lui     $a2, 0xA            # stack_size
001001A4 96 00 07 3C  lui     $a3, 0x96           # args
001001A8 10 00 08 3C  lui     $t0, 0x10           # root_func
001001AC F0 4B 84 24  la      $a0, unk_7D4BF0     # gp
001001B0 00 00 A5 24  li      $a1, 0x1F60000      # stack
001001B4 00 00 C6 24  li      $a2, 0xA0000        # stack_size
001001B8 80 E1 E7 24  la      $a3, dword_95E180   # args
001001BC 20 02 08 25  la      $t0, sub_100220     # root_func
001001C0 25 E0 80 00  or      $gp, $a0
001001C4 3C 00 03 24  li      $v1, 60             # SetupThread
001001C8 0C 00 00 00  syscall 0

001001D0 9B 00 04 3C  lui     $a0, 0x9B           # heap_start
001001D4 00 00 05 3C  lui     $a1, 0              # heap_size
001001D8 80 EB 84 24  la      $a0, 0x9AEB80       # heap_start
001001DC FF FF A5 24  li      $a1, 0xFFFFFFFF     # heap_size
001001E0 3D 00 03 24  li      $v1, 61             # SetupHeap
001001E4 0C 00 00 00  syscall 0

You may need to edit this code if you expand the loaded segment into the heap.
You have no idea how grateful I am for this and any help anyone provides - finding people who seem to know anything about PS2 hacking these days is darn near impossible.. A lot of PS2 resources just fell off the web sometime in the mid 2000's and it's been hell finding resources alone..

Anyway, thank you! I will see what I can gleam from this ASAP.