注册 登录
编程论坛 VB6论坛

怎样转换出 UNICODE_STRING 中的字符串

月下鸢尾 发布于 2015-12-27 12:52, 1380 次点击
我HOOK了NtCreateMutant想判断互斥体名称,但是不知道怎么转换UNICODE_STRING的字符串,假如我要判断的互斥体名称为ABCD,,我该怎么判断呢?
程序代码:
Private Function MyNtCreateMutant(ByVal MutantHandle As Long, ByVal DesiredAccess As Long, ObjectAttributes As POBJECT_ATTRIBUTES, ByVal InitialOwner As Long) As Long
    Dim Ret As Long

    Dim strObjectName As String
    Dim strUnicode As UNICODE_STRING
    'MsgBox ObjectAttributes.ObjectName.Buffer
    'RtlInitUnicodeString strUnicode, StrPtr(strObjectName) '初始化Unicode字符串
    'MsgBox GetStr(ObjectAttributes.ObjectName)

    RtlInitUnicodeString VarPtr(strUnicode), StrPtr(strObjectName)
    ObjectAttributes.ObjectName = VarPtr(strUnicode)
   
    'MsgBox strObjectName
    ‘这里怎么转换出ObjectAttributes 中的UNICODE_STRING字符串呢?头要炸了
   
    UnHookNtCreateMutant
    MyNtCreateMutant = NtCreateMutant(MutantHandle, DesiredAccess, ObjectAttributes, InitialOwner)
    MsgBox strObjectName
    HookNtCreateMutant
End Function


[此贴子已经被作者于2015-12-27 12:53编辑过]

1 回复
#2
风吹过b2015-12-27 16:43
你  UNICODE_STRING 的定义是什么?
----------------------
我百度到了C++ 的定义
UNICODE_STRING:

typedef struct _UNICODE_STRING {
  USHORT  Length;     //UNICODE占用的内存字节数,个数*2;
  USHORT  MaximumLength;
  PWSTR  Buffer;
} UNICODE_STRING ,*PUNICODE_STRING;

参数定义:
Length-----buffer的字节长度,不包括终止符“NULL”
MaximumLength---buffer的的总的字节大小。Up to MaximumLength bytes may be written into the                  buffer without trampling memory.
Buffer---Pointer to a wide-character string指向宽字符串的指针

按C++里的定义,直接使用 成员 Buffer 就可以了,VB会自动引用。
当然,你需要判断一下长度,VB里按是字符串的长度来决定字符串是事结束,而C里是用 终止符 NULL 。
1