Dealing with UNICODE_STRING for string manipulation

Hello,

I am trying to understand what is a good practice to deal and manipulate UNICODE_STRING strings (~ find substrins, regex etc…).
Since it is not guaranteed the buffer in UNICODE_STRING will be null-terminated, it is not safe to use the standard str/wstr functions on their buffer.

Although I saw there a some safestr.h functions that deals directly with UNICODE_STRING struct, they are not provide comparison, strstr like functionality etc…

Can someone shed some light about that ?
I found very few references regarding dealing with UNICDE_STRING online.

Thanks.
Idan

There are RtlXXX functions (
https://msdn.microsoft.com/en-us/library/windows/hardware/ff563638(v=vs.85).aspx)
that deal with comparison, concatenation, and other basic functions but for
the most part, you’ll have to write your own routines to do anything else.
And you don’t need to worry about null termination because the
UNICODE_STRING structure has Length and MaxLength fields. You use those to
determine the actual size when manipulating the buffer.

On Wed, Nov 25, 2015 at 4:23 PM, wrote:

> Hello,
>
> I am trying to understand what is a good practice to deal and manipulate
> UNICODE_STRING strings (~ find substrins, regex etc…).
> Since it is not guaranteed the buffer in UNICODE_STRING will be
> null-terminated, it is not safe to use the standard str/wstr functions on
> their buffer.
>
> Although I saw there a some safestr.h functions that deals directly with
> UNICODE_STRING struct, they are not provide comparison, strstr like
> functionality etc…
>
> Can someone shed some light about that ?
> I found very few references regarding dealing with UNICDE_STRING online.
>
> Thanks.
> Idan
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Thanks Peter.
I’m using those Rtl* functions.
Also, I’m talking about user mode code so, I thought there must be some
better API to handle those tasks.

Also I thought about making the buffer null-terminated (copy it to a new a
Len+2 buffer) then use wcs* functions on it .

בתאריך יום ה׳, 26 בנוב׳ 2015 ב-1:45 מאת Paul :

> There are RtlXXX functions (
> https://msdn.microsoft.com/en-us/library/windows/hardware/ff563638(v=vs.85).aspx)
> that deal with comparison, concatenation, and other basic functions but for
> the most part, you’ll have to write your own routines to do anything else.
> And you don’t need to worry about null termination because the
> UNICODE_STRING structure has Length and MaxLength fields. You use those to
> determine the actual size when manipulating the buffer.
>
> On Wed, Nov 25, 2015 at 4:23 PM, wrote:
>
>> Hello,
>>
>> I am trying to understand what is a good practice to deal and manipulate
>> UNICODE_STRING strings (~ find substrins, regex etc…).
>> Since it is not guaranteed the buffer in UNICODE_STRING will be
>> null-terminated, it is not safe to use the standard str/wstr functions on
>> their buffer.
>>
>> Although I saw there a some safestr.h functions that deals directly with
>> UNICODE_STRING struct, they are not provide comparison, strstr like
>> functionality etc…
>>
>> Can someone shed some light about that ?
>> I found very few references regarding dealing with UNICDE_STRING online.
>>
>> Thanks.
>> Idan
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>>
>> OSR is HIRING!! See http://www.osr.com/careers
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>
> — NTDEV is sponsored by OSR Visit the list at:
> http://www.osronline.com/showlists.cfm?list=ntdev OSR is HIRING!! See
> http://www.osr.com/careers For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

RtlXxxUnicodeString, or write your own.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntdev…
> Hello,
>
> I am trying to understand what is a good practice to deal and manipulate UNICODE_STRING strings (~ find substrins, regex etc…).
> Since it is not guaranteed the buffer in UNICODE_STRING will be null-terminated, it is not safe to use the standard str/wstr functions on their buffer.
>
> Although I saw there a some safestr.h functions that deals directly with UNICODE_STRING struct, they are not provide comparison, strstr like functionality etc…
>
> Can someone shed some light about that ?
> I found very few references regarding dealing with UNICDE_STRING online.
>
> Thanks.
> Idan
>
>

Better rewrite wcsXXX functions of your own
“Idan Freiberg” wrote in message news:xxxxx@ntdev…
Thanks Peter.
I’m using those Rtl* functions.
Also, I’m talking about user mode code so, I thought there must be some better API to handle those tasks.

Also I thought about making the buffer null-terminated (copy it to a new a Len+2 buffer) then use wcs* functions on it .

בתאריך יום ה׳, 26 בנוב׳ 2015 ב-1:45 מאת Paul :

There are RtlXXX functions (https://msdn.microsoft.com/en-us/library/windows/hardware/ff563638(v=vs.85).aspx) that deal with comparison, concatenation, and other basic functions but for the most part, you’ll have to write your own routines to do anything else. And you don’t need to worry about null termination because the UNICODE_STRING structure has Length and MaxLength fields. You use those to determine the actual size when manipulating the buffer.

On Wed, Nov 25, 2015 at 4:23 PM, wrote:

Hello,

I am trying to understand what is a good practice to deal and manipulate UNICODE_STRING strings (~ find substrins, regex etc…).
Since it is not guaranteed the buffer in UNICODE_STRING will be null-terminated, it is not safe to use the standard str/wstr functions on their buffer.

Although I saw there a some safestr.h functions that deals directly with UNICODE_STRING struct, they are not provide comparison, strstr like functionality etc…

Can someone shed some light about that ?
I found very few references regarding dealing with UNICDE_STRING online.

Thanks.
Idan


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev OSR is HIRING!! See http://www.osr.com/careers For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

On Nov 26, 2015, at 12:22 AM, Idan Freiberg wrote:
>
> Thanks Peter.
> I’m using those Rtl* functions.
> Also, I’m talking about user mode code so, I thought there must be some better API to handle those tasks.

Where, in a user-mode environment, are you coming across UNICODE_STRINGs? Usually, you only encounter those in kernel code.

Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Hi Tim,

When writing LSA extensions, such as Password filter.
Their supply everything string in that structure.

בתאריך שבת, 28 בנוב׳ 2015 ב-9:03 מאת Tim Roberts :

> On Nov 26, 2015, at 12:22 AM, Idan Freiberg wrote:
> >
> > Thanks Peter.
> > I’m using those Rtl* functions.
> > Also, I’m talking about user mode code so, I thought there must be some
> better API to handle those tasks.
>
> Where, in a user-mode environment, are you coming across UNICODE_STRINGs?
> Usually, you only encounter those in kernel code.
> —
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

They supply every string*
בתאריך שבת, 28 בנוב׳ 2015 ב-9:19 מאת Idan Freiberg :

> Hi Tim,
>
> When writing LSA extensions, such as Password filter.
> Their supply everything string in that structure.
>
> בתאריך שבת, 28 בנוב׳ 2015 ב-9:03 מאת Tim Roberts :
>
>> On Nov 26, 2015, at 12:22 AM, Idan Freiberg wrote:
>> >
>> > Thanks Peter.
>> > I’m using those Rtl* functions.
>> > Also, I’m talking about user mode code so, I thought there must be some
>> better API to handle those tasks.
>>
>> Where, in a user-mode environment, are you coming across
>> UNICODE_STRINGs? Usually, you only encounter those in kernel code.
>> —
>> Tim Roberts, xxxxx@probo.com
>> Providenza & Boekelheide, Inc.
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>>
>> OSR is HIRING!! See http://www.osr.com/careers
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
>