Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by Boguslaw Fries
Fri, 14 Mar 2003 10:18
SystemHandleInformation
Author: Boguslaw Fries
Date: Fri, 14 Mar 2003 10:18
Date: Fri, 14 Mar 2003 10:18
117 lines
4055 bytes
4055 bytes
I did already ask for, but I have some extra observations:
I did:
#define SystemHandleInformation 16
typedef struct _SYSTEM_HANDLE
{
DWORD dwProcessId;
BYTE bObjType;
BYTE bFlags;
WORD uHandle;
DWORD pObject; /*POBJECT*/
ULONG GrantedAccess; /*ACCESS_MASK*/
} SYSTEM_HANDLE, *LPSYSTEM_HANDLE;
typedef struct _SYSTEM_HANDLE
{
DWORD dwProcessId;
BYTE bObjType;
BYTE bFlags;
WORD uHandle;
DWORD pObject; /*POBJECT*/
ULONG GrantedAccess; /*ACCESS_MASK*/
} SYSTEM_HANDLE, *LPSYSTEM_HANDLE;
typedef struct _SYSTEM_HANDLE_INFORMATION
{
DWORD dwNumEntries;
SYSTEM_HANDLE systemHandles[ ANY_SIZE ];
} SYSTEM_HANDLE_INFORMATION, *LPSYSTEM_HANDLE_INFORMATION;
LPSYSTEM_HANDLE lpSystemHandle;
LPSYSTEM_HANDLE_INFORMATION lpSystemHandleInformation;
char szLocalAddr[512];
char szRemoteAddr[512];
int nRet;
SOCKADDR_IN name;
int namelen;
int speernamelen;
int optlen = 4;
int sockType = 0;
SOCKET s;
SOCKADDR_IN speer;
char s_log[ 256 ];
NtQuerySystemInformation( SystemHandleInformation,
lpSystemHandleInformation, dwLength, &dwReturnLength );
lpSystemHandle = ( LPSYSTEM_HANDLE )
lpSystemHandleInformation->systemHandles;
for ( dwCount = 0; dwCount < lpSystemHandleInformation->dwNumEntries;
dwCount++ )
{
hProc = OpenProcess( PROCESS_DUP_HANDLE, 1, lpSystemHandle->dwProcessId;
if ( hProc )
{
DuplicateHandle( hProc, ( HANDLE ) lpSystemHandle->uHandle,
hCurrentProcess, &hDup, STANDARD_RIGHTS_REQUIRED, FALSE, 0 );
CloseHandle( hProc );
}
if ( hDup )
{
name.sin_family = AF_INET;
namelen = sizeof( SOCKADDR_IN );
speernamelen = sizeof( SOCKADDR_IN );
s = ( SOCKET ) hDup;
nRet = getsockname( s, ( SOCKADDR *) &name, &namelen );
if ( nRet != SOCKET_ERROR )
{
nRet = getsockopt( s, SOL_SOCKET, SO_TYPE, (char *) &sockType,
&optlen );
if( ( nRet = getpeername( s, ( SOCKADDR *)&speer,
&speernamelen ) ) != SOCKET_ERROR )
{
sprintf( szRemoteAddr, "%s:%d", inet_ntoa(
speer.sin_addr ), ntohs( speer.sin_port ));
}
else
{
sprintf( szRemoteAddr, " ???.???.???.???:?????
%d\n", WSAGetLastError());
}
sprintf( szLocalAddr, "%s:%d", inet_ntoa(
name.sin_addr ), ntohs( name.sin_port ));
sprintf( s_log, " %d %s %-22s %-22s %d\n",
lpSystemHandle->bObjType, szSockType[ sockType ], szLocalAddr, szRemoteAddr,
lpSystemHandle->dwProcessId );
LogfileWrite( "tcpview.log", s_log ); // my own log
function but in this place doesnt matter
}
CloseHandle( hDup );
}
}
lpSystemHandle++;
}
This is a part of my code
And now my question:
All LocalAddress ARE OK!!! but szSockType[ sockType ] is WRONGLY ALLWAYS
UDP !!!
And szRemoteAddr is ALWAYS ???.???.???.???:????? and error is 10057 , but
of course is allways TRUE
What I did wrong , please help me
Best regards
Boguslaw Fries
Re: SystemHandleInformation
Author: Remy Lebeau (TeamB)
Date: Fri, 14 Mar 2003 20:20
Date: Fri, 14 Mar 2003 20:20
13 lines
1347 bytes
1347 bytes
Have a look at this article (ignore the error messages - focus on the actual code) http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=8622ed6d.02 06170135.202727f2%40posting.google.com Gambit "Boguslaw Fries" <B.Fries@luca-online.de> wrote in message news:3e71ab57@newsgroups.borland.com... > I did already ask for, but I have some extra observations: <snip>
Re: SystemHandleInformation
Author: Boguslaw Fries
Date: Sat, 15 Mar 2003 21:09
Date: Sat, 15 Mar 2003 21:09
87 lines
2110 bytes
2110 bytes
Here is a good code, thank you. I tried to insert this code into my program,
bu the result still the same...
Additionally ,
From this article I copied some part to verify here
bool TTCPViewWindow::AdjustDacl( HANDLE hProcess )
{
char s_message[ 256 ];
SID world = { SID_REVISION, 1, SECURITY_WORLD_SID_AUTHORITY, 0 };
LPTSTR ptstrName = ( LPTSTR ) & world;
EXPLICIT_ACCESS ea =
{
STANDARD_RIGHTS_ALL | SPECIFIC_RIGHTS_ALL,
SET_ACCESS,
NO_INHERITANCE,
{
0,
NO_MULTIPLE_TRUSTEE,
TRUSTEE_IS_SID,
TRUSTEE_IS_USER,
ptstrName
}
};
ACL * pdacl = 0;
if( SetEntriesInAcl( 1, &ea, 0, &pdacl ) != ERROR_SUCCESS )
{
sprintf( s_message, "SetEntriesInAcl Error:%d", GetLastError( ));
ShowMessage( s_message);
return false;
}
if( SetSecurityInfo( hProcess,
SE_KERNEL_OBJECT,
DACL_SECURITY_INFORMATION,
0,
0,
pdacl,
0 ) != ERROR_SUCCESS )
{
sprintf( s_message, "SetSecurityInfo Error:%d", GetLastError( ));
}
LocalFree( pdacl );
return true;
}
The function SetSecurityInfo very often returns NGATIVE result
What is wrong?
Boguslaw Fries
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads