Hello there,
I hope someone here can provide me an answer to this. Is there any strtok equivalent function that can be used for windows kernel mode? I’ve read that the this function has no StrSafe equivalent function for security reason. I want to have a function similar with this that will break the strings of the full file name to distinguish foldername and once foldername are distinguish, I want to create each folder strings to other drives.
Hope someone can help me about this, Im newbie to windows kernel mode.
Write it yourself, it is trivial.
–
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
wrote in message news:xxxxx@ntdev…
> Hello there,
>
> I hope someone here can provide me an answer to this. Is there any strtok
equivalent function that can be used for windows kernel mode? I’ve read that
the this function has no StrSafe equivalent function for security reason. I
want to have a function similar with this that will break the strings of the
full file name to distinguish foldername and once foldername are distinguish, I
want to create each folder strings to other drives.
>
> Hope someone can help me about this, Im newbie to windows kernel mode.
>
>
xxxxx@gmail.com wrote:
Is there any strtok equivalent function that can be used for windows
kernel mode?
cf. Google “safe strtok kernel”
I already search the net about this but to safe equivalent is available.
They banned this function for security reasons.
OK, I’ll have to create this myself.
xxxxx@gmail.com wrote:
I already search the net about this but to safe equivalent is available.
They banned this function for security reasons.
That’s not true. strtok might bring up a “deprecated” warning, but it
is still available, and it still works.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Hello Tim,
I hope you can help me with this if you succeeded using this function or its equivalent in windows kernel mode. Im still newbie for this kind of development. I also tried wcstok but still got no luck. My program won’t link.
Why don’t you step back and explain what problem in the kernel needs text
processing routines? If just to parse pathnames, there is some support for
that in the kernel file system support functions and it is easy to just
search for the separator character.
wrote in message news:xxxxx@ntdev…
> Hello Tim,
>
> I hope you can help me with this if you succeeded using this function or
> its equivalent in windows kernel mode. Im still newbie for this kind of
> development. I also tried wcstok but still got no luck. My program won’t
> link.
>
Hello David,
Thanks for the reply.
Maybe you can advise me on this through another method.
What I want is that I have a UNICODE_STRING data that contains the
full pathname of the file. I want to get each foldername from the
specified pathname so that I can create a duplicate directory
structure of the samefile to another drive. What I have in mind is to
use strtok/wcstok to parse each foldername and create the foldername
to other drive location.
In this way I can create a duplicate files with its folder where it
was stored but on the other drives. And also, Im not sure if creating
directory with the pathname “<drive letter>\folder1\folder2” can be
implemented on one call. If not, then the method that I mentioned is
the one that I have to implement.
Do you know any other way to do this?
Thanks,
xyber
On Feb 6, 2008 2:31 PM, David Craig wrote:
> Why don’t you step back and explain what problem in the kernel needs text
> processing routines? If just to parse pathnames, there is some support for
> that in the kernel file system support functions and it is easy to just
> search for the separator character.
>
> wrote in message news:xxxxx@ntdev…
>
> > Hello Tim,
> >
> > I hope you can help me with this if you succeeded using this function or
> > its equivalent in windows kernel mode. Im still newbie for this kind of
> > development. I also tried wcstok but still got no luck. My program won’t
> > link.
> >
>
>
>
> —
> NTDEV is sponsored by OSR
>
> 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
>
–
If you want to become somebody
Display your best ability
This is computer science 101. Just parse the name from the beginning after
skipping over the mount point name. Put your mount point name in another
buffer and keep appending each directory one at a time until you get to the
filename portion. You should scan from the end to determine the first
character of the file name. Make sure you validate the code using prefast
and sdv. Step through that code many times using windbg until you know it
backwards and forwards. It isn’t that difficult unless you are
inexperienced and forget about buffer overruns or underruns. If it is for
release, a good code review with at least four experienced developers will
help.
“Xyber Blue” wrote in message news:xxxxx@ntdev…
> Hello David,
>
> Thanks for the reply.
>
> Maybe you can advise me on this through another method.
> What I want is that I have a UNICODE_STRING data that contains the
> full pathname of the file. I want to get each foldername from the
> specified pathname so that I can create a duplicate directory
> structure of the samefile to another drive. What I have in mind is to
> use strtok/wcstok to parse each foldername and create the foldername
> to other drive location.
> In this way I can create a duplicate files with its folder where it
> was stored but on the other drives. And also, Im not sure if creating
> directory with the pathname “<drive letter>\folder1\folder2” can be
> implemented on one call. If not, then the method that I mentioned is
> the one that I have to implement.
>
> Do you know any other way to do this?
>
> Thanks,
> xyber
>
> On Feb 6, 2008 2:31 PM, David Craig wrote:
>> Why don’t you step back and explain what problem in the kernel needs text
>> processing routines? If just to parse pathnames, there is some support
>> for
>> that in the kernel file system support functions and it is easy to just
>> search for the separator character.
>>
>> wrote in message news:xxxxx@ntdev…
>>
>> > Hello Tim,
>> >
>> > I hope you can help me with this if you succeeded using this function
>> > or
>> > its equivalent in windows kernel mode. Im still newbie for this kind of
>> > development. I also tried wcstok but still got no luck. My program
>> > won’t
>> > link.
>> >
>>
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> 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
>>
>
>
>
> –
> If you want to become somebody
> Display your best ability
>
So you mean I have to implement it on my own. That’s what in my mind
also since I can’t use the strtok/wcstok equivalent in windows kernel
mode. Im just looking through here if someone did these by using
special API’s just to break the strings given a token string. Thanks
for the idea by the way.
On Feb 6, 2008 4:41 PM, David Craig wrote:
> This is computer science 101. Just parse the name from the beginning after
> skipping over the mount point name. Put your mount point name in another
> buffer and keep appending each directory one at a time until you get to the
> filename portion. You should scan from the end to determine the first
> character of the file name. Make sure you validate the code using prefast
> and sdv. Step through that code many times using windbg until you know it
> backwards and forwards. It isn’t that difficult unless you are
> inexperienced and forget about buffer overruns or underruns. If it is for
> release, a good code review with at least four experienced developers will
> help.
>
> “Xyber Blue” wrote in message news:xxxxx@ntdev…
> > Hello David,
> >
> > Thanks for the reply.
> >
> > Maybe you can advise me on this through another method.
> > What I want is that I have a UNICODE_STRING data that contains the
> > full pathname of the file. I want to get each foldername from the
> > specified pathname so that I can create a duplicate directory
> > structure of the samefile to another drive. What I have in mind is to
> > use strtok/wcstok to parse each foldername and create the foldername
> > to other drive location.
> > In this way I can create a duplicate files with its folder where it
> > was stored but on the other drives. And also, Im not sure if creating
> > directory with the pathname “<drive letter>\folder1\folder2” can be
> > implemented on one call. If not, then the method that I mentioned is
> > the one that I have to implement.
> >
> > Do you know any other way to do this?
> >
> > Thanks,
> > xyber
> >
> > On Feb 6, 2008 2:31 PM, David Craig wrote:
>
> >> Why don’t you step back and explain what problem in the kernel needs text
> >> processing routines? If just to parse pathnames, there is some support
> >> for
> >> that in the kernel file system support functions and it is easy to just
> >> search for the separator character.
> >>
> >> wrote in message news:xxxxx@ntdev…
> >>
> >> > Hello Tim,
> >> >
> >> > I hope you can help me with this if you succeeded using this function
> >> > or
> >> > its equivalent in windows kernel mode. Im still newbie for this kind of
> >> > development. I also tried wcstok but still got no luck. My program
> >> > won’t
> >> > link.
> >> >
> >>
> >>
> >>
> >> —
> >> NTDEV is sponsored by OSR
> >>
> >> 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
> >>
> >
> >
> >
> > –
> > If you want to become somebody
> > Display your best ability
> >
>
>
>
>
> —
> NTDEV is sponsored by OSR
>
> 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
>
–
If you want to become somebody
Display your best ability
Xyber Blue wrote:
So you mean I have to implement it on my own.
cf. Google “safe strtok kernel”. Please do it this time.
One of the links is to a ReactOS implementation of strtok that handles
unicode and claims to be thread safe.
If you ask for entry-level help in NTDEV, be so kind as to at least
check out the pointers you are given. Otherwise people will probably
only help you once, then not bother anymore.
Im sorry for that statement and for my poor english. I mean nothing
with that. Thanks for the reminder and also for the help. I’ll check
the ReactOS about this. Thanks again for the pointers.
On Feb 6, 2008 6:27 PM, Hagen Patzke wrote:
> Xyber Blue wrote:
> > So you mean I have to implement it on my own.
> If you ask for entry-level help in NTDEV, be so kind as to at least
> check out the pointers you are given. Otherwise people will probably
> only help you once, then not bother anymore.
>
>
> —
> NTDEV is sponsored by OSR
>
> 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
>
–
If you want to become somebody
Display your best ability
Hello,
Thanks again for the help. I think this is the link that Hagen is talking about.
http://www.koders.com/c/fid4BE42498019181532F7F7A05702D7120CDE48B38.aspx
This the one that I need. Thanks again for the help and hoping to
receive some helpful comments for my questions in the future.
Thanks,
xyber
On Feb 6, 2008 6:49 PM, Xyber Blue wrote:
> Im sorry for that statement and for my poor english. I mean nothing
> with that. Thanks for the reminder and also for the help. I’ll check
> the ReactOS about this. Thanks again for the pointers.
>
> On Feb 6, 2008 6:27 PM, Hagen Patzke wrote:
> > Xyber Blue wrote:
> > > So you mean I have to implement it on my own.
> > If you ask for entry-level help in NTDEV, be so kind as to at least
> > check out the pointers you are given. Otherwise people will probably
> > only help you once, then not bother anymore.
> >
> >
> > —
> > NTDEV is sponsored by OSR
> >
> > 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
> >
>
>
>
>
> –
> If you want to become somebody
> Display your best ability
>
–
If you want to become somebody
Display your best ability
strtok was always a problem because it modified the string being parsed in
most implementations, inserting nulls as it went along. This is generally a
bad thing to do, and one of the reasons it isn’t particularly safe. Of
course, the standard implementation could also run off the end of the string
easily enough.
As David states, this is an absolutely trivial routine to write in C, and it
isn’t made any more complicated as far as I can see by having to be done in
wide characters. The only thing you get from strtok is being able to find
the backslashes in the file name. You can do that in a for or while loop
trivially.
Just off the top of my head I’d do something like
int len = strlen (string);
for (int i = len-1; i >= 0 && string[i] != ‘\’; i–) // find last
backslash
continue;
int fname_start = i; // filename starts here
int parse_start;
if (string[0] != ‘\’ && string[1] == ‘:’)
parse_start = 2;
else
{
if (string[0] == ‘\’ && string[1] == ‘\’)
parse_start = 2;
else
if (sting[1] == ‘\’)
parse_start = 1;
else
parse_start = 0;
}
if (parse_start > 0)
cd_to_or_create_drive (string, parse_start); // deal with drive
for (i = parse_start; i <= fname_start; )
{
for (int j = 0; string[i+j] != ‘\’; j++)
continue;
cd_to_or_create_dir (string, i+j); // deal with this level of
directory
i += j + 1;
}
open_or_create_file (string); // path known to exist, deal with the
file name
There are probably a couple bugs in that, for instance not properly handling
a file path with multiple backslashes in a row in it. Or what you want to
do if there is no path in front of the file name. But those are pretty
trivial to cover with a few lines of code. There are also choices about
what the heck you actually want to do with each level of the directory path,
and if you want to handle the first level in some special manner, like
turning it into a directory level with some other disk path under it. Those
are things you have to decide for yourself; we can’t help you there.
Loren
Look at FsRtlDissectName that is what it does, you do not need strtok the
kernel has a support mechanism for you.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
“Xyber Blue” wrote in message news:xxxxx@ntdev…
> Hello David,
>
> Thanks for the reply.
>
> Maybe you can advise me on this through another method.
> What I want is that I have a UNICODE_STRING data that contains the
> full pathname of the file. I want to get each foldername from the
> specified pathname so that I can create a duplicate directory
> structure of the samefile to another drive. What I have in mind is to
> use strtok/wcstok to parse each foldername and create the foldername
> to other drive location.
> In this way I can create a duplicate files with its folder where it
> was stored but on the other drives. And also, Im not sure if creating
> directory with the pathname “<drive letter>\folder1\folder2” can be
> implemented on one call. If not, then the method that I mentioned is
> the one that I have to implement.
>
> Do you know any other way to do this?
>
> Thanks,
> xyber
>
> On Feb 6, 2008 2:31 PM, David Craig wrote:
>> Why don’t you step back and explain what problem in the kernel needs text
>> processing routines? If just to parse pathnames, there is some support
>> for
>> that in the kernel file system support functions and it is easy to just
>> search for the separator character.
>>
>> wrote in message news:xxxxx@ntdev…
>>
>> > Hello Tim,
>> >
>> > I hope you can help me with this if you succeeded using this function
>> > or
>> > its equivalent in windows kernel mode. Im still newbie for this kind of
>> > development. I also tried wcstok but still got no luck. My program
>> > won’t
>> > link.
>> >
>>
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> 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
>>
>
>
>
> –
> If you want to become somebody
> Display your best ability
>
xxxxx@gmail.com wrote:
Hello Tim,
I hope you can help me with this if you succeeded using this function or its equivalent in windows kernel mode. Im still newbie for this kind of development. I also tried wcstok but still got no luck. My program won’t link.
Did you add this to your sources file:
TARGETLIBS = %DDK_LIB_PATH%\libcntpr.lib
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Hello Tim,
I follow what you suggest, I added the TARGETLIBS code you mentioned
but still it won’t link.
Im using the Windows Driver Kit version 1.0.6001.100 for XP SP2
On Feb 7, 2008 2:51 AM, Tim Roberts wrote:
> xxxxx@gmail.com wrote:
> > Hello Tim,
> >
> > I hope you can help me with this if you succeeded using this function or its equivalent in windows kernel mode. Im still newbie for this kind of development. I also tried wcstok but still got no luck. My program won’t link.
> >
>
> Did you add this to your sources file:
> TARGETLIBS = %DDK_LIB_PATH%\libcntpr.lib
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
>
> NTDEV is sponsored by OSR
>
> 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
>
–
If you want to become somebody
Display your best ability