11#include " calculator.h"
22
3+ #include " log.h"
4+
35/* *
46 * Do not update those routines!
57 * Those should simulate how PS4 handles maths
@@ -52,7 +54,8 @@ s64 nearest_dirent(const char* buffer, s64 size, s64 offset) {
5254 for (s64 out_offset = offset_adj; out_offset <= offset_adj + max_advance; out_offset += 8 ) {
5355 const OrbisInternals::FolderDirent* tested_dirent = reinterpret_cast <const OrbisInternals::FolderDirent*>(buffer + out_offset);
5456 status = validate_pfs_getdirentries_dirent (tested_dirent);
55- // LogError("Testing", out_offset, status);
57+ LogWarning (GetSt (Style::BOLD), " Testing" , out_offset - offset, GetSt (Style::RESET), " =" , GetSt (Style::FG_MAGENTA), status);
58+
5659 if (status < 0 ) continue ;
5760
5861 // LogError("Found a match forward at", out_offset);
@@ -81,19 +84,31 @@ void calculate_pfs_getdirentries(OrbisInternals::DirentCombinationGetdirentries*
8184 s64 apparent_end = offset + count;
8285 s64 apparent_end_down = ALDN (apparent_end, 512 );
8386 s64 file_offset_down = ALDN (offset, 512 );
87+ s64 file_offset_up = ALDN (offset, 512 );
8488 s64 directory_size = ALUP (size, 0x10000 );
8589
8690 // within the same sector or worse
8791 if (apparent_end_down <= file_offset_down) {
88- spec->expected_result = s64 (einval_int);
89- spec->expected_errno = EINVAL;
92+ spec->expected_basep = 0 ;
93+ spec->expected_result = s64 (einval_int);
94+ spec->expected_end_position = offset;
95+ spec->expected_errno = EINVAL;
96+ return ;
97+ }
98+
99+ if ((apparent_end_down == file_offset_up) && (count < 512 )) {
100+ spec->expected_basep = offset;
101+ spec->expected_result = 0 ;
102+ spec->expected_end_position = offset;
103+ spec->expected_errno = 0 ;
104+ // LogError("qweqweqwe");
90105 return ;
91106 }
92107
93108 if (offset >= size) {
94- spec->expected_end_position = directory_size;
95109 spec->expected_basep = offset;
96110 spec->expected_result = 0 ;
111+ spec->expected_end_position = directory_size;
97112 // LogError("qweqweqwe");
98113 return ;
99114 }
@@ -119,18 +134,23 @@ void calculate_pfs_getdirentries(OrbisInternals::DirentCombinationGetdirentries*
119134 s64 bytes_written = 0 ;
120135 s64 buffer_position = offset;
121136
122- while (buffer_position < apparent_end) {
123- const OrbisInternals::FolderDirent* pfs_dirent = reinterpret_cast <const OrbisInternals::FolderDirent*>(buffer + buffer_position + dirent_offset);
137+ while (bytes_written < count) {
138+ if (ALDN (buffer_position + dirent_offset, 8 ) >= apparent_end_down) {
139+ LogError (" QQWWERRR" );
140+ break ;
141+ }
124142
125- if (pfs_dirent->d_reclen == 0 ) break ;
126- if ((bytes_written + dirent_offset + pfs_dirent->d_reclen ) > count) break ;
127- // without dirent offset i think
128- // it sometimes underreads data at this line
129- //
130- if ((buffer_position + dirent_offset + pfs_dirent->d_reclen ) >= apparent_end_down) {
131- LogError (" XVFED" );
143+ const OrbisInternals::FolderDirent* pfs_dirent = reinterpret_cast <const OrbisInternals::FolderDirent*>(buffer + buffer_position + dirent_offset);
144+ if ((bytes_written + dirent_offset + pfs_dirent->d_reclen ) >= count) {
145+ LogError (" AAAQWEEEEE" );
132146 break ;
133147 }
148+ if (pfs_dirent->d_reclen == 0 ) break ;
149+
150+ // if ((buffer_position + dirent_offset + pfs_dirent->d_reclen) >= apparent_end_down) {
151+ // LogError("XVFED");
152+ // break;
153+ // }
134154
135155 // align to 65536 when dir size is bigger?
136156 // if (Common::AlignUp(buffer_position, count) !=
0 commit comments