Skip to content

Check when a HRESULT is a Win32 code and fetch it#9

Open
zeroSteiner wants to merge 1 commit into
rapid7:masterfrom
zeroSteiner:feat/win32-hresults
Open

Check when a HRESULT is a Win32 code and fetch it#9
zeroSteiner wants to merge 1 commit into
rapid7:masterfrom
zeroSteiner:feat/win32-hresults

Conversation

@zeroSteiner

Copy link
Copy Markdown
Contributor

This fixes an error that was privately reported to me where Metasploit's icpr_cert module was not fetching an error code and then crashing with a stack trace because the HRESULT definition didn't exist. The code in question was 0x80070547 which should map to the win32 ERROR_CANT_ACCESS_DOMAIN_INFO code.

There's also some extra require statements, so consumers can just require 'windows_error/h_result'.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Win32-aware HRESULT lookup so callers can resolve FACILITY_WIN32 HRESULTs (e.g., 0x80070547) to the underlying Win32 error code, and makes it easier to require submodules directly.

Changes:

  • Ensure windows_error/win32 and windows_error/nt_status can be required standalone by requiring the base windows_error definitions.
  • Add Facility.find_by_h_result and harden facility constant iteration to only consider FacilityCode instances.
  • Teach HResult.find_by_retval to detect FACILITY_WIN32 and delegate to Win32.find_by_retval(retval & 0xffff).

Impact Analysis:

  • Blast radius: medium; affects consumers of WindowsError::HResult.find_by_retval and anyone requiring windows_error/h_result, plus standalone require paths for windows_error/win32 and windows_error/nt_status.
  • Data and contract effects: HResult.find_by_retval may now return Win32 WindowsError::ErrorCode instances (not HResultCode) for FACILITY_WIN32 HRESULTs, which changes the effective return-type contract for that method.
  • Rollback and test focus: rollback is straightforward (revert), but validation should focus on FACILITY_WIN32 mapping cases (e.g., 0x80070547 -> ERROR_CANT_ACCESS_DOMAIN_INFO) and confirming non-WIN32 HRESULT lookups remain unchanged.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/windows_error/win32.rb Require base library so Win32 constants can be loaded via standalone require.
lib/windows_error/nt_status.rb Require base library so NTSTATUS constants can be loaded via standalone require.
lib/windows_error/h_result/facility.rb Add find_by_h_result and skip non-FacilityCode constants during lookup.
lib/windows_error/h_result.rb Require Win32 and map FACILITY_WIN32 HRESULTs to Win32 error codes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -15,6 +17,11 @@ module HResult
# @return [Array<HResultCode>] all Win32 ErrorCodes that matched
Comment on lines +21 to +23
if Facility.find_by_h_result(retval) == Facility::FACILITY_WIN32.value
return Win32.find_by_retval(retval & 0xffff)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants