Skip to content

Commit

Permalink
Some I/O fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
momo5502 committed Nov 5, 2024
1 parent b49f9f6 commit 74ec07c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/windows-emulator/handles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ constexpr auto CONSOLE_SERVER = make_pseudo_handle(0x1338, handle_types::section
constexpr auto CM_API = make_pseudo_handle(0x1338, handle_types::file);
constexpr auto KSEC_DD = make_pseudo_handle(0x1339, handle_types::file);
constexpr auto AFD_ENDPOINT = make_pseudo_handle(0x133A, handle_types::file);
constexpr auto CNG = make_pseudo_handle(0x133B, handle_types::file);

constexpr auto CONSOLE_HANDLE = make_pseudo_handle(0x1, handle_types::file);
constexpr auto STDOUT_HANDLE = make_pseudo_handle(0x2, handle_types::file);
Expand Down
39 changes: 37 additions & 2 deletions src/windows-emulator/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,7 @@ namespace
const emulator_object<OBJECT_ATTRIBUTES> object_attributes,
const emulator_object<IO_STATUS_BLOCK> /*io_status_block*/,
const emulator_object<LARGE_INTEGER> /*allocation_size*/, ULONG /*file_attributes*/,
ULONG /*share_access*/, ULONG create_disposition, ULONG /*create_options*/,
ULONG /*share_access*/, ULONG create_disposition, ULONG create_options,
uint64_t /*ea_buffer*/,
ULONG /*ea_length*/)
{
Expand Down Expand Up @@ -2058,6 +2058,12 @@ namespace
return STATUS_SUCCESS;
}

if (filename == L"\\Device\\CNG")
{
file_handle.write(CNG.bits);
return STATUS_SUCCESS;
}

if (filename.starts_with(L"\\Device\\Afd\\Endpoint"))
{
file_handle.write(AFD_ENDPOINT.bits);
Expand Down Expand Up @@ -2093,10 +2099,25 @@ namespace

printer.cancel();

if (f.name.ends_with(L"\\"))
if (f.name.ends_with(L"\\") || create_options & FILE_DIRECTORY_FILE)
{
c.win_emu.logger.print(color::dark_gray, "--> Opening folder: %S\n", f.name.c_str());

if (create_disposition & FILE_CREATE)
{
std::error_code ec{};
std::filesystem::create_directory(f.name, ec);

if (ec)
{
return STATUS_ACCESS_DENIED;
}
}
else if (!std::filesystem::is_directory(f.name))
{
return STATUS_OBJECT_NAME_NOT_FOUND;
}

const auto handle = c.proc.files.store(std::move(f));
file_handle.write(handle.bits);

Expand All @@ -2107,6 +2128,11 @@ namespace

const auto* mode = map_mode(desired_access, create_disposition);

if (!mode || wcslen(mode) == 0)
{
return STATUS_NOT_SUPPORTED;
}

FILE* file{};
const auto error = _wfopen_s(&file, f.name.c_str(), mode);

Expand Down Expand Up @@ -2476,6 +2502,14 @@ namespace

return STATUS_SUCCESS;
}

NTSTATUS handle_NtGetCurrentProcessorNumberEx(const syscall_context& c,
const emulator_object<PROCESSOR_NUMBER> processor_number)
{
constexpr PROCESSOR_NUMBER number{};
processor_number.write(number);
return STATUS_SUCCESS;
}
}

void syscall_dispatcher::add_handlers(std::map<std::string, syscall_handler>& handler_mapping)
Expand Down Expand Up @@ -2569,6 +2603,7 @@ void syscall_dispatcher::add_handlers(std::map<std::string, syscall_handler>& ha
add_handler(NtAccessCheck);
add_handler(NtCreateKey);
add_handler(NtNotifyChangeKey);
add_handler(NtGetCurrentProcessorNumberEx);

#undef add_handler
}

0 comments on commit 74ec07c

Please sign in to comment.