Implement C-style printf specifiers and BeaconFormat API suite#6
Open
chvancooten wants to merge 1 commit intopraetorian-inc:mainfrom
Open
Implement C-style printf specifiers and BeaconFormat API suite#6chvancooten wants to merge 1 commit intopraetorian-inc:mainfrom
chvancooten wants to merge 1 commit intopraetorian-inc:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR significantly improves the compatibility and output quality of the Beacon API implementation. It addresses artifacting issues in
BeaconPrintfoutput and implements the missingBeaconFormat*API suite, which is required by some modern BOFs (e.g., ChromeKatz).Problem
The previous
BeaconPrintfimplementation used a primitive manual parser that only explicitly handled%sand%p, falling back to Go's defaultfmt.Sprintffor other specifiers. Since arguments are passed asuintptrvalues, specifiers like%S(wide strings) or%i(integers) would print the raw memory address (e.g.,%!S(uintptr=...)) instead of the intended value.Furthermore, the
BeaconFormat*functions were stubs that fell through to default handlers, causing BOFs that rely on dynamic output buffering to fail or crash.Changes
1. Robust Printf Parsing (
formatPrintf)Implemented a comprehensive C-style printf parser that supports:
%s,%S,%c,%C,%p,%d,%i,%u,%x,%X,%o,%f, etc.%S(and%ls/%ws) by utilizing a fixedReadWStringFromPtrto decode UTF-16 code units.+,-,#,0, space) and dynamic*width/precision.2. BeaconFormat API Suite
Fully implemented the dynamic buffer management suite:
BeaconFormatAlloc: Allocates a managed buffer for output assembly.BeaconFormatReset&BeaconFormatFree: Proper lifecycle management for temporary buffers.BeaconFormatAppend&BeaconFormatPrintf: Methods to populate the buffer, with the latter utilizing the new robust printf logic.BeaconFormatToString: Retrieves the final assembled string pointer.BeaconFormatInt: Appends a 4-byte integer in the expected big-endian format.3. Memory Access Improvements
ReadWStringFromPtrto correctly decode UTF-16 code units instead of raw byte concatenation, ensuring proper representation of multi-byte characters.4. COFF Symbol Resolution
BeaconFormat*symbols to their new Go implementations.Validation
Case 1: locale.x64.o (Formatting Fix)
This BOF uses
%Sextensively for locale information.Output Before:
Output After:
Case 2: ChromeKatz (Compatibility Fix)
ChromeKatz utilizes
BeaconFormatPrintfandBeaconFormatToStringfor its credential output.BeaconFormat*implementations.