[IronPython] Opening a process for mem reads ?

Richard Steventon steventon at gmail.com
Thu Sep 23 03:16:37 CEST 2010

So, I decided to give it a go.  This is the cpython code:

  info = GetSecurityInfo(GetCurrentProcess(),6,0)
  SetSecurityInfo(process, 6, win32.win32security.DACL_SECURITY_INFORMATION |
None, None, info.GetSecurityDescriptorDacl(), info.GetSecurityDescriptorGroup())

When I run in IronPython, the following happens:

GetSecurityInfo returns an integer.  This means I cannot do
info.GetSecurityDescriptorDacl() etc

If I leave out the last two (optional) parameters to SetSecurityInfo, I get a
return code of 998.  Looking this up in winerror.h gives
ERROR_NOACCESS.  This is not a rights problem afaik, since I am
running ipy with Admin rights.

Ok, so at this point, I thought "screw it, I'll do it in C#".

So, my C# code is simple for testing:
using System;
namespace UnmanagedCode
    public class processSecurity
        public int getValue(int value)
        {  return value + 1;  }

I compile it in VS2010 Express as a .NET Framework 4.0.  I end up with
a DLL file.  I then copy that DLL into a clean directory, and launch
ipy.exe in that directory.

IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.4952
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> clr.AddReferenceToFile("UnmanagedCode.dll")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: System.IO.IOException: Could not add reference to assembly

So, I imported sys, and checked the path... the current directory is
in the path.  At this point, I cannot figure out wtf is wrong.  I have
looked and read and googled etc but the examples all seem to be
outdated and 'just work'... but not when I attempt them!

Some pointers as to how to get this working would be nice !


On Wed, Sep 22, 2010 at 2:20 PM, Lukas Cenovsky <cenovsky at bakalari.cz> wrote:
> On 22.9.2010 20:03, Jeff Hardy wrote:
> On Wed, Sep 22, 2010 at 11:36 AM, Richard Steventon <steventon at gmail.com>
> wrote:
> Next question in my quest to open a process and read its memory:
> from win32.win32security import GetSecurityInfo, SetSecurityInfo
> How do I get access to those in IronPython ?
> Unfortunately, I don't think anyone has ported the win32 module to
> IronPython yet (it's a big, complicated module).
> You could use ctypes:
>     ctypes.windll.advapi32.GetSecurityInfo(...)
> GetSecurityInfo has a fairly complicated signature (see
> http://msdn.microsoft.com/en-us/library/aa446654(VS.85).aspx) that
> will probably require working fairly closely with ctypes
> (http://docs.python.org/library/ctypes.html) to get it to work.
> Unfortunately, out of the box, that's all the IronPython provides.
> - Jeff
> P.S. If you need to know the DLL to use with ctypes.windll, look up
> the function on MSDN and look for the DLL name near the bottom of the
> page.
> You can use clrtype instead of ctypes to call native functions - see
> (Sample) ClrType.zip.
> --
> -- Lukáš
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

More information about the Ironpython-users mailing list