如何拒绝与CAS断言?(How to deny Assert with CAS?)
在这段代码中,我希望禁止ReadFileSystem方法断言文件系统的权限。
我预计这会抛出fileIo.Assert(),但它不会。 为什么?
using System.Security.Permissions; static void Main(string[] args) { var fileIo = new FileIOPermission(PermissionState.Unrestricted); var secuPerm = new SecurityPermission(SecurityPermissionFlag.Assertion); PermissionSet set = new PermissionSet(PermissionState.Unrestricted); set.AddPermission(fileIo); set.AddPermission(secuPerm); set.Deny(); ReadFileSystem(); Console.Read(); } private static void ReadFileSystem() { var fileIo = newFileIOPermission(PermissionState.Unrestricted); fileIo.Assert(); DirectoryInfo dir = new DirectoryInfo("C:/"); dir.GetDirectories(); }
更新
这里有很好的CAS链接: http : //blogs.msdn.com/shawnfa/archive/2004/08/25/220458.aspx
In this code, I'd like the ReadFileSystem method to be forbidden to Assert a permission on the filesystem.
I expected this will throw at fileIo.Assert(), but it doesn't. Why?
using System.Security.Permissions; static void Main(string[] args) { var fileIo = new FileIOPermission(PermissionState.Unrestricted); var secuPerm = new SecurityPermission(SecurityPermissionFlag.Assertion); PermissionSet set = new PermissionSet(PermissionState.Unrestricted); set.AddPermission(fileIo); set.AddPermission(secuPerm); set.Deny(); ReadFileSystem(); Console.Read(); } private static void ReadFileSystem() { var fileIo = newFileIOPermission(PermissionState.Unrestricted); fileIo.Assert(); DirectoryInfo dir = new DirectoryInfo("C:/"); dir.GetDirectories(); }
Update
Great link here on CAS : http://blogs.msdn.com/shawnfa/archive/2004/08/25/220458.aspx
原文:https://stackoverflow.com/questions/604450
最满意答案
尝试使用ReadConsoleInput以避免cooked模式,并使用GetNumberOfConsoleInputEvents来避免阻塞。
Try ReadConsoleInput to avoid cooked mode, and GetNumberOfConsoleInputEvents to avoid blocking.
相关问答
更多-
你的问题听起来有点困惑。 select()用于阻塞,直到输入可用。 但是你用正常的文件读取功能(如read , fread , fgetc等)来做实际的读取。 这是一个简单的例子。 它阻塞,直到stdin至少有一个可供阅读的字符。 但是,当然,除非您将终端更改为某种未烹饪的模式,否则它会阻塞,直到您按下回车键,当任何键入的字符被刷新到文件缓冲区(从某个终端缓冲区中)时。 #include
#include int main(void) { fd_s ... -
C无阻塞键盘输入(C non-blocking keyboard input)[2023-12-04]
如上所述,您可以使用sigaction来捕获ctrl-c,或者select捕获任何标准输入。 但是请注意,使用后一种方法,您还需要设置TTY,使其处于一个字符的时间,而不是一时一行的模式。 后者是默认值 - 如果您输入一行文本,则不会将其发送到正在运行的程序的stdin,直到您按Enter键。 您需要使用tcsetattr()函数关闭ICANON模式,也可能会禁用ECHO。 从内存中,当程序退出时,您还必须将终端设置为ICANON模式! 只是为了完整,这里有一些我刚刚敲下的代码(nb:没有错误检查!),它设 ... -
不,输入设备模拟非常特定于平台,即使在单一平台上也很挑剔。 它不是用于任何目的的强大技术,因此您将找不到好的库来实现它。 一旦掌握了基本API,最困难的部分就是让设备看起来更加逼真。 您希望逐渐鼠标移动更新以中等高频率发送,就像鼠标一样,以及点击和按键之间的合理延迟。 执行事件的时间轴和执行基本几何可能会得到像SDL这样的游戏库的帮助。 如果您忽略计时,操作系统可能会扼杀鼠标移动,去抖动按钮,重新排列动作和点击的顺序,在使用触控板时忽略按键等等。我差不多10年前写过这样一个工具。 No, input dev ...
-
问题是游戏正在通过DirectX运行,这阻止了虚拟键盘敲击。 通过从sys系统中直接渲染游戏,它避免了所有的一起使用并且工作得很好:) The problem was that the game was running though DirectX, which prevented virtual keyboard strokes. By rending the game right from the sys, it avoided directx all together and worked fine ...
-
答案由Hans Passant提供( https://stackoverflow.com/users/17034/hans-passant ): 此事件公开了在物理键盘上键入的字符: http : //msdn.microsoft.com/en-us/library/windows.ui.core.corewindow.characterreceived.aspx Answer provided by Hans Passant (https://stackoverflow.com/users/17034/h ...
-
正如hyde的帖子中所述,我可以使用Lua包装器为ncurses获取输入。 除此之外,我可以将其功能用于我的代码的其他部分,无论如何我将自己编程。 As stated in the comments of my post by hyde, I can use a Lua wrapper for ncurses to get input. In addition to this, I can use its features for some other parts of my code that I was ...
-
我设法以某种方式解决我使用此功能的特定问题 extern GetAsyncKeyState 它有一些选项可以在按下按键时返回给定值,也可以选择自上次调用函数后按下该按键时的值 - 所以我在程序开始时调用该函数一次,然后检查自那时起是否调用了该函数。 然而,使用这种方法时存在很多问题,所以我会检查其他人很快提出的问题,并可能会发布更好的解决方案。 I managed to somehow solve my particular problem using this function extern GetAsy ...
-
尝试一下: import os from subprocess import Popen, PIPE cmd = r"C:\LTR_STRUC\LTR_STRUC_1_1.exe" app = Popen(cmd, stdin=PIPE, shell=True) app.stdin.write("y" + os.linesep) ... 此外,如果您想要响应提示,您也可以PIPE stdout并通过以下方式访问它: app.stdout.read() 参考: https : //docs.python ...
-
显然是跳过输入操作的原因很可能是(这意味着,忽略了一个bugsy XCode IDE的可能特性),你之前已经执行了一些输入并在输入缓冲区中留下了一个换行符 。 要解决这个问题,请确保在逻辑上应该消耗输入行的每个输入操作之后清空了输入缓冲区。 一种简单的方法是始终将getline用于string ,然后如果要将数字规范转换为数字类型,则使用例如istringstream 。 干杯&hth。, The reason that the input operation apparently is skipped, ...
-
尝试不阻塞地读取键盘输入(Windows,C ++)(Trying to read keyboard input without blocking (Windows, C++))[2021-08-21]
尝试使用ReadConsoleInput以避免cooked模式,并使用GetNumberOfConsoleInputEvents来避免阻塞。 Try ReadConsoleInput to avoid cooked mode, and GetNumberOfConsoleInputEvents to avoid blocking.