TeamFAPS / PSVita-RE-tools

A bundle of RE tools for analyzing and modding PSVita OS
GNU General Public License v3.0
321 stars 35 forks source link

VitaDecompilerMod will not decompile elfs with size smaller than 4096 bytes #17

Open GrapheneCt opened 4 years ago

GrapheneCt commented 4 years ago

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.

CelesteBlue-dev commented 4 years ago

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);

CelesteBlue-dev commented 4 years ago

@dots-tb ping

CelesteBlue-dev commented 1 year ago

@Princess-of-Sleeping told that this was fixed in vitasdk on Sep 16, 2020 by commit https://github.com/vitasdk/vita-toolchain/commit/389826ea2637ddedfce7812961e1e6d8af948725

@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.

GrapheneCt commented 1 year ago

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

Princess-of-Sleeping commented 1 year ago

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