Tom_lyd
驱动大牛
驱动大牛
  • 注册日期2001-09-02
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分10分
  • 威望1点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
阅读:1432回复:4

内核字符串处理

楼主#
更多 发布于:2002-05-24 21:35
WDM极不赞成在内核中使用C/C++ Run time library函数,因此,DDK自身提供了许多RtlXXX函数来代替这些功能。
在处理字符串的时候,在应用程序层可以方便是使用诸如:strcpy,strlen,strcat等,而这些RTL函数在驱动程序中都对应着什么呢?有没有相应的RtlXXX函数?如果没有则使用strcpy,strlen等函数在内核中是不是安全的呢?
虽然File monitor中广泛采用了这些函数,但这明显不符合WDM的编程思想。
Tom_lyd
.X.T.I.M.
驱动大牛
驱动大牛
  • 注册日期2001-09-22
  • 最后登录2021-08-25
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望10点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2002-05-24 22:07
有啊!RtlCopyString、RtlEqualString、RtlUpperString好多啦~~DDK里面有啦!就算没有的就自己写一个啊~~我都经常用自己写的字处理函数来处理字符!strcpy,strlen,strcat这写函数的源代码在VC6的Program Files\\Microsoft Visual Studio\\VC98\\CRT\\SRC或VC7。NET的C:\\Program Files\\Microsoft Visual Studio .NET\\Vc7\\crt\\src里面都是有代码的!很多C的东西那里都有~~去看看看吧~~
<IMG src="http://www.microsoft.com/traincert/images/logos/mcp.gif" border=0> <IMG src="http://www.microsoft.com/traincert/images/logos/mcdba.gif" border=0><br> <IMG src="http://www.microsoft.com/traincert/images/logos/mcse.gif" border=0> <IMG src="http://www.microsoft.com/traincert/images/logos/mcsd.gif" border=0>
du_lin
驱动小牛
驱动小牛
  • 注册日期2002-01-26
  • 最后登录2005-08-22
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2002-05-24 22:11
内核中大多是UNICODE_STRING和ANSI_STRING的结构
strlen可以省略,
RtlMoveMemory,
RtlMemoryCopy,
RtlCopyByte,
RtlCopyString
很丰富,在内核,能不用strcpy尽量不用.我也是初步了解,希望高手能讲一讲用strcpy的危害和原因.
.X.T.I.M.
驱动大牛
驱动大牛
  • 注册日期2001-09-22
  • 最后登录2021-08-25
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望10点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2002-05-24 22:16
我们先来看看你代码好了!
/***
*strcat.c - contains strcat() and strcpy()
*
*       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
*
*Purpose:
*       Strcpy() copies one string onto another.
*
*       Strcat() concatenates (appends) a copy of the source string to the
*       end of the destination string, returning the destination string.
*
*******************************************************************************/

#include <cruntime.h>
#include <string.h>

#ifndef _MBSCAT
#ifdef _MSC_VER
#pragma function(strcat,strcpy)
#endif  /* _MSC_VER */
#endif  /* _MBSCAT */

/***
*char *strcat(dst, src) - concatenate (append) one string to another
*
*Purpose:
*       Concatenates src onto the end of dest.  Assumes enough
*       space in dest.
*
*Entry:
*       char *dst - string to which \"src\" is to be appended
*       const char *src - string to be appended to the end of \"dst\"
*
*Exit:
*       The address of \"dst\"
*
*Exceptions:
*
*******************************************************************************/

char * __cdecl strcat (
        char * dst,
        const char * src
        )
{
        char * cp = dst;

        while( *cp )
                cp++;                   /* find end of dst */

        while( *cp++ = *src++ ) ;       /* Copy src to end of dst */

        return( dst );                  /* return dst */

}


/***
*char *strcpy(dst, src) - copy one string over another
*
*Purpose:
*       Copies the string src into the spot specified by
*       dest; assumes enough room.
*
*Entry:
*       char * dst - string over which \"src\" is to be copied
*       const char * src - string to be copied over \"dst\"
*
*Exit:
*       The address of \"dst\"
*
*Exceptions:
*******************************************************************************/

char * __cdecl strcpy(char * dst, const char * src)
{
        char * cp = dst;

        while( *cp++ = *src++ )
                ;               /* Copy src over dst */

        return( dst );
}

<IMG src="http://www.microsoft.com/traincert/images/logos/mcp.gif" border=0> <IMG src="http://www.microsoft.com/traincert/images/logos/mcdba.gif" border=0><br> <IMG src="http://www.microsoft.com/traincert/images/logos/mcse.gif" border=0> <IMG src="http://www.microsoft.com/traincert/images/logos/mcsd.gif" border=0>
.X.T.I.M.
驱动大牛
驱动大牛
  • 注册日期2001-09-22
  • 最后登录2021-08-25
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望10点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2002-05-24 22:21
  char * __cdecl strcpy(char * dst, const char * src)
{
char * cp = dst;

while( *cp++ = *src++ )
; /* Copy src over dst */

return( dst );
}


看到没有?直接while( *cp++ = *src++ )而已!我想这个函数用应该还是没有什么大问题的~~
<IMG src="http://www.microsoft.com/traincert/images/logos/mcp.gif" border=0> <IMG src="http://www.microsoft.com/traincert/images/logos/mcdba.gif" border=0><br> <IMG src="http://www.microsoft.com/traincert/images/logos/mcse.gif" border=0> <IMG src="http://www.microsoft.com/traincert/images/logos/mcsd.gif" border=0>
游客

返回顶部