我成功地从 C# 调用了 advapi32 的 LsaEnumerateAccountRights()。现在如何解组它返回的 LSA_UNICODE_STRING 数组?
它是一个指向 LSA_UNICODE_STRING
结构。我发现了一些执行相反操作的代码,即从 C# 字符串创建
LSA_UNICODE_STRING
。您可以在下面的帮助程序代码部分中看到这一点。
我所要做的,包括对 LsaEnumerateAccountRights() 的调用,似乎工作得很好。返回数组指针和计数的合理值。
我不知道如何获取那些该死的字符串。请帮忙?请问漂亮吗?
更新: nobugz 在下面的回答中的辅助函数几乎是正确的,您只需将长度除以 UnicodeEncoding.CharSize
即可。感谢他,我现在可以看到数组中的第一个字符串。请参阅下面两个代码部分末尾的更新。
现在,我该如何进行指针算术呢?
更新2.5:请参阅功能代码的答案。我丢失了旧的“错误”代码。
It's a pointer to an array of LSA_UNICODE_STRING
structures. I found some code that does the inverse, i.e., create a LSA_UNICODE_STRING
from a C# string. You can see that in the helper code section below.
What I have up to and including the call to LsaEnumerateAccountRights()
seems to work just fine. Sensible values are returned for the array pointer and for the count.
I am at a loss as to how to get at those blasted strings. Help please? Pretty please?
UPDATE: nobugz's helper function in his answer below is ALMOST right, you only have to divide the length by UnicodeEncoding.CharSize
. Thanks to him, I can now see the FIRST string in the array. See the updates at the end of both code sections below.
Now, how the netherworld do I do pointer arithmetic?
UPDATE 2.5: See answer for the functioning code. I lost the old, "wrong" code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到了!在这篇博文中。现在下面修改后的代码可以正常工作了。它甚至是 64 位安全的!
主要代码:
辅助函数、导入等:
Found it! In this blog post. Now the amended code below works fully. It's even 64-bit safe!
The main code:
The helper functions, imports etc:
这应该对你有用:
This ought to work for you: