diff --git a/src/xenia/kernel/fs/devices/disc_image_entry.cc b/src/xenia/kernel/fs/devices/disc_image_entry.cc index aa7aba7e5..049da7c64 100644 --- a/src/xenia/kernel/fs/devices/disc_image_entry.cc +++ b/src/xenia/kernel/fs/devices/disc_image_entry.cc @@ -67,11 +67,7 @@ X_STATUS DiscImageEntry::QueryInfo(XFileInfo* out_info) { X_STATUS DiscImageEntry::QueryDirectory( XDirectoryInfo* out_info, size_t length, bool restart) { XEASSERTNOTNULL(out_info); - if (length < sizeof(XDirectoryInfo)) { - return X_STATUS_INFO_LENGTH_MISMATCH; - } - - memset(out_info, 0, length); + xe_zero_struct(out_info, length); if (restart == true && gdfx_entry_iterator_ != gdfx_entry_->children.end()) { gdfx_entry_iterator_ = gdfx_entry_->children.end(); @@ -82,21 +78,18 @@ X_STATUS DiscImageEntry::QueryDirectory( if (gdfx_entry_iterator_ == gdfx_entry_->children.end()) { return X_STATUS_UNSUCCESSFUL; } - } - else { + } else { ++gdfx_entry_iterator_; if (gdfx_entry_iterator_ == gdfx_entry_->children.end()) { return X_STATUS_UNSUCCESSFUL; } } - XDirectoryInfo* current; - auto current_buf = (uint8_t*)out_info; auto end = current_buf + length; - current = (XDirectoryInfo*)current_buf; - if (((uint8_t*)¤t->file_name[0]) + strlen((*gdfx_entry_iterator_)->name.c_str()) > end) { + XDirectoryInfo* current = (XDirectoryInfo*)current_buf; + if (((uint8_t*)¤t->file_name[0]) + xestrlena((*gdfx_entry_iterator_)->name.c_str()) > end) { gdfx_entry_iterator_ = gdfx_entry_->children.end(); return X_STATUS_UNSUCCESSFUL; } @@ -105,7 +98,7 @@ X_STATUS DiscImageEntry::QueryDirectory( auto entry = *gdfx_entry_iterator_; auto file_name = entry->name.c_str(); - size_t file_name_length = strlen(file_name); + size_t file_name_length = xestrlena(file_name); if (((uint8_t*)&((XDirectoryInfo*)current_buf)->file_name[0]) + file_name_length > end) { break; } @@ -128,7 +121,8 @@ X_STATUS DiscImageEntry::QueryDirectory( current->next_entry_offset = (uint32_t)(next_buf - current_buf); current_buf = next_buf; - } while (current_buf < end && (++gdfx_entry_iterator_) != gdfx_entry_->children.end()); + } while (current_buf < end && + (++gdfx_entry_iterator_) != gdfx_entry_->children.end()); current->next_entry_offset = 0; return X_STATUS_SUCCESS; } diff --git a/src/xenia/kernel/fs/devices/host_path_entry.cc b/src/xenia/kernel/fs/devices/host_path_entry.cc index 7f5cb2836..19678f83f 100644 --- a/src/xenia/kernel/fs/devices/host_path_entry.cc +++ b/src/xenia/kernel/fs/devices/host_path_entry.cc @@ -76,11 +76,7 @@ X_STATUS HostPathEntry::QueryInfo(XFileInfo* out_info) { X_STATUS HostPathEntry::QueryDirectory( XDirectoryInfo* out_info, size_t length, bool restart) { XEASSERTNOTNULL(out_info); - if (length < sizeof(XDirectoryInfo)) { - return X_STATUS_INFO_LENGTH_MISMATCH; - } - - memset(out_info, 0, length); + xe_zero_struct(out_info, length); WIN32_FIND_DATA ffd; diff --git a/src/xenia/kernel/fs/devices/stfs_container_entry.cc b/src/xenia/kernel/fs/devices/stfs_container_entry.cc index 1cc1a95ea..0bfe7ceb9 100644 --- a/src/xenia/kernel/fs/devices/stfs_container_entry.cc +++ b/src/xenia/kernel/fs/devices/stfs_container_entry.cc @@ -22,6 +22,7 @@ STFSContainerEntry::STFSContainerEntry( Type type, Device* device, const char* path, xe_mmap_ref mmap, STFSEntry* stfs_entry) : stfs_entry_(stfs_entry), + stfs_entry_iterator_(stfs_entry->children.end()), Entry(type, device, path) { mmap_ = xe_mmap_retain(mmap); } @@ -42,9 +43,67 @@ X_STATUS STFSContainerEntry::QueryInfo(XFileInfo* out_info) { return X_STATUS_SUCCESS; } -X_STATUS STFSContainerEntry::QueryDirectory(XDirectoryInfo* out_info, size_t length, bool restart) { - XEASSERTALWAYS(); - return X_STATUS_UNSUCCESSFUL; +X_STATUS STFSContainerEntry::QueryDirectory( + XDirectoryInfo* out_info, size_t length, bool restart) { + XEASSERTNOTNULL(out_info); + xe_zero_struct(out_info, length); + + if (restart && stfs_entry_iterator_ != stfs_entry_->children.end()) { + stfs_entry_iterator_ = stfs_entry_->children.end(); + } + + if (stfs_entry_iterator_ == stfs_entry_->children.end()) { + stfs_entry_iterator_ = stfs_entry_->children.begin(); + if (stfs_entry_iterator_ == stfs_entry_->children.end()) { + return X_STATUS_UNSUCCESSFUL; + } + } else { + ++stfs_entry_iterator_; + if (stfs_entry_iterator_ == stfs_entry_->children.end()) { + return X_STATUS_UNSUCCESSFUL; + } + } + + auto current_buf = (uint8_t*)out_info; + auto end = current_buf + length; + + XDirectoryInfo* current = (XDirectoryInfo*)current_buf; + if (((uint8_t*)¤t->file_name[0]) + xestrlena((*stfs_entry_iterator_)->name.c_str()) > end) { + stfs_entry_iterator_ = stfs_entry_->children.end(); + return X_STATUS_UNSUCCESSFUL; + } + + do { + auto entry = *stfs_entry_iterator_; + + auto file_name = entry->name.c_str(); + size_t file_name_length = xestrlena(file_name); + if (((uint8_t*)&((XDirectoryInfo*)current_buf)->file_name[0]) + file_name_length > end) { + break; + } + + current = (XDirectoryInfo*)current_buf; + current->file_index = 0xCDCDCDCD; + current->creation_time = entry->update_timestamp; + current->last_access_time = entry->access_timestamp; + current->last_write_time = entry->update_timestamp; + current->change_time = entry->update_timestamp; + current->end_of_file = entry->size; + current->allocation_size = 4096; + current->attributes = entry->attributes; + + current->file_name_length = (uint32_t)file_name_length; + memcpy(current->file_name, file_name, file_name_length); + + auto next_buf = (((uint8_t*)¤t->file_name[0]) + file_name_length); + next_buf += 8 - ((uint8_t)next_buf % 8); + + current->next_entry_offset = (uint32_t)(next_buf - current_buf); + current_buf = next_buf; + } while (current_buf < end && + (++stfs_entry_iterator_) != stfs_entry_->children.end()); + current->next_entry_offset = 0; + return X_STATUS_SUCCESS; } X_STATUS STFSContainerEntry::Open( diff --git a/src/xenia/kernel/fs/devices/stfs_container_entry.h b/src/xenia/kernel/fs/devices/stfs_container_entry.h index 4d24b3f90..b35573672 100644 --- a/src/xenia/kernel/fs/devices/stfs_container_entry.h +++ b/src/xenia/kernel/fs/devices/stfs_container_entry.h @@ -43,6 +43,7 @@ public: private: xe_mmap_ref mmap_; STFSEntry* stfs_entry_; + std::vector::iterator stfs_entry_iterator_; }; diff --git a/src/xenia/kernel/util/xex2.cc b/src/xenia/kernel/util/xex2.cc index 082287b45..5532200d8 100644 --- a/src/xenia/kernel/util/xex2.cc +++ b/src/xenia/kernel/util/xex2.cc @@ -148,15 +148,6 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length, const uint8_t *pp = p + opt_header->offset; switch (opt_header->key) { - default: - XELOGW("Unknown XEX header key %.8X", opt_header->key); - break; - case XEX_HEADER_CHECKSUM_TIMESTAMP: - case XEX_HEADER_ORIGINAL_PE_NAME: - case XEX_HEADER_LAN_KEY: - case XEX_HEADER_XBOX360_LOGO: - // Ignored. - break; case XEX_HEADER_SYSTEM_FLAGS: header->system_flags = (xe_xex2_system_flags)data_offset; break;