Replace most magic numbers from previous commit with named constants, if the constants names are known.

Instead of low 32 bits of ptr, use hash of file path for sector information.
This commit is contained in:
chss95cs@gmail.com 2023-05-01 09:32:33 -04:00
parent b270c59d0c
commit dcb98683cf
4 changed files with 18 additions and 10 deletions

View File

@ -54,8 +54,12 @@ struct X_FILE_FS_ATTRIBUTE_INFORMATION {
};
static_assert_size(X_FILE_FS_ATTRIBUTE_INFORMATION, 16);
enum X_FILE_DEVICE_TYPE : uint32_t {
FILE_DEVICE_UNKNOWN = 0x22
};
struct X_FILE_FS_DEVICE_INFORMATION {
be<uint32_t> device_type;
be<X_FILE_DEVICE_TYPE> device_type;
be<uint32_t> characteristics;
};
static_assert_size(X_FILE_FS_DEVICE_INFORMATION, 8);

View File

@ -418,7 +418,12 @@ dword_result_t XamAlloc_entry(dword_t flags, dword_t size, lpdword_t out_ptr) {
}
DECLARE_XAM_EXPORT1(XamAlloc, kMemory, kImplemented);
static const unsigned short XamPhysicalProtTable[4] = {2, 516, 4, 1028};
static const unsigned short XamPhysicalProtTable[4] = {
X_PAGE_READONLY,
X_PAGE_READWRITE | X_PAGE_NOCACHE,
X_PAGE_READWRITE,
X_PAGE_WRITECOMBINE | X_PAGE_READWRITE
};
dword_result_t XamAllocEx_entry(dword_t phys_flags, dword_t flags, dword_t size,
lpdword_t out_ptr, const ppc_context_t& ctx) {
@ -428,6 +433,7 @@ dword_result_t XamAllocEx_entry(dword_t phys_flags, dword_t flags, dword_t size,
uint32_t flags_remapped = phys_flags;
if ((phys_flags & 0xF000000) == 0) {
// setting default alignment
flags_remapped = 0xC000000 | phys_flags & 0xF0FFFFFF;
}

View File

@ -97,10 +97,9 @@ dword_result_t NtQueryInformationFile_entry(
// arbitrary 4 byte integer most of the time
XELOGW("Stub XFileSectorInformation!");
auto info = info_ptr.as<uint32_t*>();
//low 32 bits of ptr. todo: maybe hash name?
*info = static_cast<uint32_t>(
reinterpret_cast<uintptr_t>(file->file()->entry()));
out_length = 4;
size_t fname_hash = xe::memory::hash_combine(82589933LL, file->path());
*info = static_cast<uint32_t>(fname_hash ^ (fname_hash >> 32));
out_length = sizeof(uint32_t);
break;
}
case XFileXctdCompressionInformation: {
@ -347,10 +346,9 @@ dword_result_t NtQueryVolumeInformationFile_entry(
auto info = info_ptr.as<X_FILE_FS_DEVICE_INFORMATION*>();
auto file_device = file->device();
XELOGW("Stub XFileFsDeviceInformation!");
//FILE_DEVICE_UNKNOWN
info->device_type = 0x22; // 415608D8 checks for 0x46;
info->device_type = FILE_DEVICE_UNKNOWN; // 415608D8 checks for 0x46;
info->characteristics = 0;
out_length = 8;
out_length = sizeof(X_FILE_FS_DEVICE_INFORMATION);
break;
}
default: {

View File

@ -449,7 +449,7 @@ dword_result_t RtlImageDirectoryEntryToData_entry(dword_t Base, dword_t MappedAs
if (!nt_header) {
return 0;
}
if (nt_header->OptionalHeader.Magic != 0x10B) {
if (nt_header->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
return 0;
}
if (DirectoryEntry >= nt_header->OptionalHeader.NumberOfRvaAndSizes) {