FsRtlIsNameInExpression永远不匹配任何东西

时间:2012-05-08 03:22:04

标签: c string-matching windows-kernel

我使用Boyer-Moore algorithm在内核驱动程序中进行字符串匹配,但我还需要实现基本的通配符支持。 This answer on SO提到了FsRtlIsNameInExpression函数,它看起来恰好满足了我的需求。它甚至看起来像处理Unicode字符串的大小写不敏感。

但它甚至无法让它与一个简单的字符串匹配。

我尝试了一些东西,但FsRtlIsNameInExpression永远不会匹配任何东西。以下是我用来测试的一些代码(我在MyTest例程结束时调用了DriverEntry

NTSTATUS MyTest()
{
    int matches = 0;

    UNICODE_STRING a3times;
    UNICODE_STRING A5times;
    UNICODE_STRING bbb;
    UNICODE_STRING patterna;
    UNICODE_STRING patternb;

    RtlInitUnicodeString(&a3times, L"aaa");
    RtlInitUnicodeString(&A5times, L"AAAAA");
    RtlInitUnicodeString(&bbb, L"bbb");

    RtlInitUnicodeString(&patterna, L"a*a");
    RtlInitUnicodeString(&patternb, L"b*");

    if(FsRtlIsNameInExpression(&patterna, &a3times, TRUE, 0)) 
        ++matches;            // a*a should match aaa

    if(FsRtlIsNameInExpression(&patterna, &A5times, FALSE, 0))
        ++matches;            // a*a should match (insensitive) AAAAA

    if(FsRtlIsNameInExpression(&a3times, &a3times, TRUE, 0))
        ++matches;            //aaa should match aaa

    if(FsRtlIsNameInExpression(&patternb, &bbb, TRUE, 0))
        ++matches;            //b* should match bbb

    return matches;   //Should be 4, but is 0
}

记录:

  • 我正在使用WDK版本7600.16385.1,检查版本(我的代码,而不是Windows)
  • 驱动程序在我的Windows 7 Ultimate 64位上以Virtual Box托管的Windows 7 Pro 64位运行
  • 驱动程序由测试证书签名
  • 我在内核调试器中跟踪代码
  • 代码不会崩溃,但无法在用户模式下调用

我失踪的显而易见的是什么?

1 个答案:

答案 0 :(得分:1)

文档说

  

如果IgnoreCaseTRUE,则Expression必须为大写。

请注意,根据您的评论,您误解了区分大小写的参数。它是IgnoreCase而不是CaseSensitive

至于结果:

  1. IgnoreCase设置为TRUE的小写表达式无效
  2. 小写表达式,IgnoreCase设置为FALSE大写模式 - 将不匹配
  3. IgnoreCase设置为TRUE的小写表达式无效
  4. IgnoreCase设置为TRUE的小写表达式无效
  5. 真是运气不好,没有一个人工作:)