It is currently Sat May 18, 2013 12:52 pm



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: C# GetProcTable
PostPosted: Sun Jul 29, 2012 5:35 pm 
Offline

Joined: Sun Jul 29, 2012 5:15 pm
Posts: 2
Hi,

I've been struggling with this for a few days now, I'm writing an app for myself to monitor process bandwidth usage, but I cannot get the NtTdiApi.GetProcTable() to work, and would really appreciate it if someone could point me in the right direction!

PInvoke in the api wrapper:
============================================
[DllImport("NtTdiApi.Dll",SetLastError=true)]
public static extern bool GetProcTable(
[In] int hOpen,
//[In, Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)]
IntPtr pProcTable,
[In, Out] ref int pdwSize
);

=============================================
c# code:
-----------
int tablesize = 1024;
IntPtr pProcTable = Marshal.AllocHGlobal(new IntPtr(tablesize));
while (!NtTdiApi.GetProcTable(hDriver, pProcTable, ref tablesize))
{
pProcTable = Marshal.AllocHGlobal(new IntPtr(tablesize));
}
NTTDI_PROCESS_TABLE ProcTable = (NTTDI_PROCESS_TABLE)Marshal.PtrToStructure(pProcTable, typeof(NTTDI_PROCESS_TABLE));

if (ProcTable.m_NumEntries > 0)
{
//NTTDI_PROCESS_ENTRY ProcessEntry = (NTTDI_PROCESS_ENTRY)ProcTable.m_Table;
// NTTDI_PROCESS_ENTRY ProcessEntry = (NTTDI_PROCESS_ENTRY)Marshal.PtrToStructure(ProcTable.m_Table, typeof(NTTDI_PROCESS_ENTRY));
//NTTDI_PROCESS_ENTRY[] ProcessEntry1 = (NTTDI_PROCESS_ENTRY[])Marshal.PtrToStructure(ProcTable.m_Table, typeof(NTTDI_PROCESS_ENTRY[]));
}

==========================================
According to the API :

struct _NTTDI_PROCESS_TABLE
{
unsigned long m_TableSize;
unsigned long m_NumEntries;
NTTDI_PROCESS_ENTRY m_Table[0];
}NTTDI_PROCESS_TABLE,*PNTTDI_PROCESS_TABLE;
-------------
m_table:
A pointer to an array of NTTDI_PROCESS_ENTRY structures.
-------------

I did check, the m_NumEntries are the same amount as my open processes, so i am getting a valid NTTDI_PROCESS_TABLE object.

I'm not familiar with c++ so i don't know what i'm doing wrong :(.
None of the three casts inside "if (ProcTable.m_NumEntries > 0)" work...

Thanks in advance!
Chris


Top
 Profile  
 
 Post subject: Re: C# GetProcTable
PostPosted: Tue Jul 31, 2012 5:42 pm 
Offline

Joined: Sun Jul 29, 2012 5:15 pm
Posts: 2
bump


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Theme designed by stylerbb.net © 2008
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All times are UTC + 2 hours