Accessing windows structures through ctypes.

Discussion in 'Python' started by Rajat, Jul 2, 2009.

  1. Rajat

    Rajat Guest

    Hi,

    Using ctypes can I access the windows structures like:

    PROCESS_INFORMATION_BLOCK, Process Environment Block(PEB),
    PEB_LDR_DATA, etc?


    Regards,
    Rajat
     
    Rajat, Jul 2, 2009
    #1
    1. Advertising

  2. Rajat

    alex23 Guest

    alex23, Jul 2, 2009
    #2
    1. Advertising

  3. Rajat

    Rajat Guest


    > > Using ctypes can I access the windows structures like:

    >
    > > PROCESS_INFORMATION_BLOCK, Process Environment Block(PEB),
    > > PEB_LDR_DATA, etc?

    >
    > ctypes.wintypes lists all of the Windows structures included with the
    > module.
    >
    > You should be able to use ctypes.Structure class to roll your own:


    Thanks Alex. As you suggested, I'm trying to implemenet the below
    structure, windows PEB, in Python:

    typedef struct _PEB {
    BYTE Reserved1[2];
    BYTE BeingDebugged;
    BYTE Reserved2[21];
    PPEB_LDR_DATA LoaderData;
    PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
    BYTE Reserved3[520];
    PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine;
    BYTE Reserved4[136];
    ULONG SessionId;
    } PEB;

    My equivalent Python structure is:
    class PEB(Structure):
    _fields_ = [("Reserved1", wintypes.BYTE * 2),
    ("BeingDebugged", wintypes.BYTE),
    ("Reserved2", wintypes.BYTE * 2),
    ("Reserved3", c_void_p),
    ("Ldr", pointer(PEB_LDR_DATA)),
    ("ProcessParameters", pointer
    (RTL_USER_PROCESS_PARAMETERS)),
    ("Reserved4", wintypes.BYTE * 104),
    ("Reserved5", c_void_p),
    (),
    ("Reserved6", wintypes.BYTE),
    ("Reserved7", c_void_p),
    ("SessionId", c_ulong)]

    I'm not sure what needs to go in the above empty tuple for
    "PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine" (in Original
    PEB).

    Please suggest.
     
    Rajat, Jul 2, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henk Punt
    Replies:
    0
    Views:
    428
    Henk Punt
    Jul 23, 2004
  2. Alfonso Morra
    Replies:
    11
    Views:
    755
    Emmanuel Delahaye
    Sep 24, 2005
  3. Replies:
    0
    Views:
    539
  4. Gabriele Modena

    ctypes: nested structures and pointers

    Gabriele Modena, Jan 18, 2010, in forum: Python
    Replies:
    0
    Views:
    524
    Gabriele Modena
    Jan 18, 2010
  5. andreadr
    Replies:
    0
    Views:
    1,047
    andreadr
    Dec 7, 2011
Loading...

Share This Page