views:

39

answers:

2

I have to open a file using ZwOpenFile API. This is my requirement. When I set the path in object name parameter. I could see fields Length and maximumlength in the object name.

Length is just length of the path and I usually keep maximumlength as the value of Length.

It worked mostly, however some times it doesnot work. In some cases I solved it via maximumlength = length *2. Even this computation doesn't work for few other cases.

I am very much puzzled with the Maximumlength value computation.

Can some one help.

A: 

Initially i converted the ntpath name manually with /??/. this was not worked out.

Then I tried it using RTL_dospathnametontpathname_u, which yielded me an unicode string. Then it is worked for my case. Also normaly rtlinitunitcodestring api would be used ot initalise as "Will A" suggested.

Thanks.

Beetle
A: 

Look at UNICODE_STRING structure definition: link

Length is wcslen(str.Buffer) * sizeof(WCHAR) == * 2

MaximumLength field may be Length + sizeof(WCHAR) == Length + 2

ZwOpenFile will not write to this string, so we shouldn't care about capacity of string.

Abyx
I append a virtual path in the incoming path of zwopenfile. hence I have to edit the object attribute in it. However the calculation you have shown will work. thanks
Beetle
I hooked zwopenfile. hence i will be inside the implementation, to edit its parameter to my need.
Beetle