gpt4 book ai didi

c++ - 在 UNICODE_STRING 中搜索字符

转载 作者:行者123 更新时间:2023-11-28 01:19:54 25 4
gpt4 key购买 nike

有一个 UNICODE_STRING,我想检查其中是否有定义的字符(最好是 $ 在末尾)。

我们正在使用 OpenPasswordFilter并想检查提交的帐户是用户还是计算机。如果是计算机,以'$'末尾定义,则检查应省略。

NTSTATUS PsamPasswordNotificationRoutine(
PUNICODE_STRING UserName,
ULONG RelativeId,
PUNICODE_STRING NewPassword
)
{...}

来自 https://learn.microsoft.com/en-us/windows/win32/api/ntsecapi/nc-ntsecapi-psam_password_notification_routine

在 c# 中我会使用类似的东西:

char lastchar = UserName[UserName.Length - 1];
if (lastchar <> '$') {
....

最佳答案

UNICODE_STRING::Buffer 是指向 wchar_t[] 数组的指针。你可以直接查看Buffer的内容,例如:

enum eAccountType {atUnknown, atUser, atComputer};

eAccountType GetAccountType(const wchar_t *UserName, int Length)
{
return ((UserName) && (Length > 0))
? ((UserName[Length-1] == L'$') ? atComputer : atUser)
: atUnknown;
}

eAccountType GetAccountType(const UNICODE_STRING &UserName)
{
// UNICODE_STRING::Length is expressed in bytes, not in characters...
return GetAccountType(UserName.Buffer, UserName.Length / sizeof(wchar_t));
}

NTSTATUS PsamPasswordNotificationRoutine(
PUNICODE_STRING UserName,
ULONG RelativeId,
PUNICODE_STRING NewPassword
)
{
...
if ((UserName) && (GetAccountType(*UserName) == atUser))
{
...
}
...
}

关于c++ - 在 UNICODE_STRING 中搜索字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56951342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com