TeamFAPS / PSVita-RE-tools

A bundle of RE tools for analyzing and modding PSVita OS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

VitaDecompilerMod will not decompile elfs with size smaller than 4096 bytes

GrapheneCt opened this issue · comments

Trying to decompile elfs with file size smaller than 4096 bytes will result in error "Unexpected end of file".

Currently can be bypassed by adding 0 padding at the end of the elf file until its size is bigger than 4096 bytes.

Thanks.
To fix need to either, change the file read size:
https://github.com/CelesteBlue-dev/PSVita-RE-tools/blob/d5af8750e373d78097fd91290dc2d287754cc12f/vitadecompiler-mod/src/main.cpp#L1131
or change the SELF header size:
https://github.com/CelesteBlue-dev/PSVita-RE-tools/blob/d5af8750e373d78097fd91290dc2d287754cc12f/vitadecompiler-mod/src/self.h#L106

The best way might be to do:
buf = malloc(HEADER_LEN);
fread(fd, buf, filesize < HEADER_LEN ? filesize : HEADER_LEN);

@Princess-of-Sleeping told that this was fixed in vitasdk on Sep 16, 2020 by commit vitasdk/vita-toolchain@389826e

@GrapheneCt Were you trying to decompile an ELF built with the old version of vitasdk or with another SDK? If the bug was vitasdk specific we can close this issue, but if the bug also affects genuine ELFs then we have to fix VitaDecompiler.

This bug is not specific to vitasdk elfs. Can be verified with bgapputil.suprx.

I think bgallutil.suprx is fine

D:\desktop\PSVita-RE-tools-master\vitadecompiler-mod\build>vitadecompiler.exe "D:\desktop\PSVita-RE-tools-master\vitadecompiler-mod\build\bgapputil.suprx" db.yml
(81000000 - 810003b0)(FILE OFF: 10e0)(FILE SZ: 3b0)(MEM SZ: 3b0)
The segment is compressed
Setting Text Segment to Segment 0
(0 - 0)(FILE OFF: 1340)(FILE SZ: 0)(MEM SZ: 0)
The segment is compressed
Warning: could not uncompress segment (No segment?): -3
Setting Data Segment to Segment 1
(0 - 0)(FILE OFF: 1340)(FILE SZ: f8)(MEM SZ: 0)
The segment is compressed
(0 - 0)(FILE OFF: 1000)(FILE SZ: 0)(MEM SZ: 0)
The segment is compressed
Warning: could not uncompress segment (No segment?): -3
(0 - 0)(FILE OFF: 1000)(FILE SZ: 0)(MEM SZ: 0)
The segment is compressed
Warning: could not uncompress segment (No segment?): -3
Entry Point: (164)(FILE OFF:1244)
Module name: SceBgAppUtil
Exporting NIDS file to: D:\desktop\PSVita-RE-tools-master\vitadecompiler-mod\build\bgapputil.suprx.nids.txt
Exporting db_lookup file to: SceBgAppUtil.yml
Exporting source file to: D:\desktop\PSVita-RE-tools-master\vitadecompiler-mod\build\bgapputil.suprx.c
Analysing symbols...
Analysing arguments...
Analysing code...
Decompiling...
Exporting header file to: D:\desktop\PSVita-RE-tools-master\vitadecompiler-mod\build\bgapputil.suprx.h
Finished.

D:\desktop\PSVita-RE-tools-master\vitadecompiler-mod\build>pause