2 bita839 Bita839 于 2016.09.09 13:49 提问

C# 评测C++程序

最近想编一个C++评测软件,但不知道如何设置Process启动的程序的文件访问权限,曾经看过一个人写的,运用反射,把Process中的m_ProcessAccess改为0x0001(不知道有没有记错),就可以防止启动的线程调用或更改外部文件,但不懂什么意思,求大神帮忙!!! (在线等)

1个回答

caozhy
caozhy   Ds   Rxr 2016.09.09 23:14

看.net源代码

    [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MonitoringDescription(SR.ProcessHandle)]
    public IntPtr Handle {
        [ResourceExposure(ResourceScope.Machine)]
        [ResourceConsumption(ResourceScope.Machine)]
        get {
            EnsureState(State.Associated);
            return OpenProcessHandle(this.m_processAccess).DangerousGetHandle();
        }
    }

再查msdn的api函数定义
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684320(v=vs.85).aspx

dwDesiredAccess [in]
The access to the process object. This access right is checked against the security descriptor for the process. This parameter can be one or more of the process access rights.
If the caller has enabled the SeDebugPrivilege privilege, the requested access is granted regardless of the contents of the security descriptor.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx
PROCESS_TERMINATE (0x0001)

0x0001使得对于这个handle只有终止进程的权限。

Csdn user default icon
上传中...
上传图片
插入图片