From c7f53e193aa173ccfe9c052c706d3ebe2818a2b3 Mon Sep 17 00:00:00 2001 From: belliash Date: Mon, 26 Sep 2022 16:53:58 +0200 Subject: [PATCH] Implement RtlWideStringLength() routine --- sdk/xtdk/rtlfuncs.h | 5 +++++ xtoskrnl/rtl/widestr.c | 44 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/sdk/xtdk/rtlfuncs.h b/sdk/xtdk/rtlfuncs.h index 01c0bd3..e74d710 100644 --- a/sdk/xtdk/rtlfuncs.h +++ b/sdk/xtdk/rtlfuncs.h @@ -73,6 +73,11 @@ RtlWideStringCompare(IN CONST PWCHAR String1, IN CONST PWCHAR String2, IN CONST ULONG Length); +XTCDECL +SIZE_T +RtlWideStringLength(IN CONST PWCHAR String, + IN SIZE_T MaxLength); + XTCDECL PWCHAR RtlWideStringTokenize(IN PWCHAR String, diff --git a/xtoskrnl/rtl/widestr.c b/xtoskrnl/rtl/widestr.c index 8e6baa6..b75b19d 100644 --- a/xtoskrnl/rtl/widestr.c +++ b/xtoskrnl/rtl/widestr.c @@ -19,7 +19,7 @@ * Wide string to be compared. * * @param Length - * Maximum number of characters to compare. + * Maximum number of characters to compare. If no limit set, it compares whole strings. * * @return Integral value indicating the relationship between the wide strings. * @@ -61,6 +61,48 @@ RtlWideStringCompare(IN CONST PWCHAR String1, return 0; } +/** + * Calculates the length of a given wide string. + * + * @param String + * Pointer to the null-terminated wide string to be examined. + * + * @param MaxLength + * Maximum number of wide characters to examine. If no limit set, it examines whole string. + * + * @return The length of the null-terminated wide string. + * + * @since: XT 1.0 + */ +XTCDECL +SIZE_T +RtlWideStringLength(IN CONST PWCHAR String, + IN SIZE_T MaxLength) +{ + SIZE_T Length; + + /* Check if NULL pointer passed */ + if(String == NULL) + { + return 0; + } + + /* Iterate through the wide string */ + for(Length = 0; ; Length++) + { + + /* Check if NULL found or max length limit reached */ + if((Length != 0 && Length == MaxLength) || !String[Length]) + { + /* Finish examination */ + break; + } + } + + /* Return wide string length */ + return Length; +} + /** * Finds the next token in a null-terminated wide string. *