|
|
dd89bb |
/********************************************************/
|
|
|
dd89bb |
/* ntapi: Native API core library */
|
|
|
4256e2 |
/* Copyright (C) 2013--2016 Z. Gilboa */
|
|
|
dd89bb |
/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
|
|
|
dd89bb |
/********************************************************/
|
|
|
dd89bb |
|
|
|
dd89bb |
#include <psxtypes/psxtypes.h>
|
|
|
dd89bb |
#include <ntapi/nt_object.h>
|
|
|
dd89bb |
#include <ntapi/nt_file.h>
|
|
|
dd89bb |
#include <ntapi/nt_socket.h>
|
|
|
dd89bb |
#include <ntapi/ntapi.h>
|
|
|
dd89bb |
#include "ntapi_impl.h"
|
|
|
dd89bb |
|
|
|
dd89bb |
typedef struct _nt_socket_attr {
|
|
|
dd89bb |
uint32_t datagram;
|
|
|
dd89bb |
uint32_t unknown;
|
|
|
dd89bb |
uint32_t domain;
|
|
|
dd89bb |
uint32_t type;
|
|
|
dd89bb |
uint32_t protocol;
|
|
|
dd89bb |
} nt_socket_attr;
|
|
|
dd89bb |
|
|
|
dd89bb |
typedef struct _nt_afd_socket_ea {
|
|
|
dd89bb |
uint32_t next_entry_offset;
|
|
|
dd89bb |
unsigned char ea_flags;
|
|
|
dd89bb |
unsigned char ea_name_length;
|
|
|
dd89bb |
uint16_t ea_value_length;
|
|
|
dd89bb |
char afd_open_packet[16];
|
|
|
dd89bb |
nt_socket_attr sattr;
|
|
|
dd89bb |
uint32_t ea_ext[4];
|
|
|
dd89bb |
} nt_afd_socket_ea;
|
|
|
dd89bb |
|
|
|
dd89bb |
int32_t __cdecl __ntapi_sc_socket_v2(
|
|
|
dd89bb |
__out nt_socket * hssocket,
|
|
|
dd89bb |
__in uint16_t domain,
|
|
|
dd89bb |
__in uint16_t type,
|
|
|
dd89bb |
__in uint32_t protocol,
|
|
|
dd89bb |
__in uint32_t desired_access __optional,
|
|
|
dd89bb |
__in nt_sqos * sqos __optional,
|
|
|
dd89bb |
__out nt_io_status_block * iosb __optional)
|
|
|
dd89bb |
{
|
|
|
dd89bb |
int32_t status;
|
|
|
dd89bb |
nt_object_attributes oa;
|
|
|
dd89bb |
nt_io_status_block siosb;
|
|
|
dd89bb |
nt_sqos ssqos;
|
|
|
dd89bb |
nt_unicode_string nt_afdep;
|
|
|
dd89bb |
uint32_t ea_length;
|
|
|
dd89bb |
void * _hsocket;
|
|
|
dd89bb |
|
|
|
dd89bb |
wchar16_t afd_end_point[] = {
|
|
|
dd89bb |
'\\','D','e','v','i','c','e',
|
|
|
dd89bb |
'\\','A','f','d',
|
|
|
dd89bb |
'\\','E','n','d','P','o','i','n','t',
|
|
|
dd89bb |
0};
|
|
|
dd89bb |
|
|
|
dd89bb |
nt_afd_socket_ea afd_ea = {
|
|
|
dd89bb |
0,
|
|
|
dd89bb |
0,
|
|
|
dd89bb |
0x0f,
|
|
|
dd89bb |
0x20,
|
|
|
dd89bb |
{'A','f','d','O','p','e','n','P','a','c','k','e','t','X','X',0},
|
|
|
dd89bb |
{0},
|
|
|
dd89bb |
{0}};
|
|
|
dd89bb |
|
|
|
dd89bb |
ea_length = sizeof(afd_ea);
|
|
|
dd89bb |
|
|
|
dd89bb |
afd_ea.sattr.domain = domain;
|
|
|
dd89bb |
afd_ea.sattr.type = type;
|
|
|
dd89bb |
afd_ea.sattr.protocol = protocol;
|
|
|
dd89bb |
|
|
|
dd89bb |
afd_ea.sattr.datagram = (type == NT_SOCK_DGRAM) ? protocol : 0;
|
|
|
dd89bb |
|
|
|
dd89bb |
__ntapi->rtl_init_unicode_string(&nt_afdep,afd_end_point);
|
|
|
dd89bb |
|
|
|
dd89bb |
if (!desired_access)
|
|
|
dd89bb |
desired_access = NT_GENERIC_READ \
|
|
|
dd89bb |
| NT_GENERIC_WRITE \
|
|
|
dd89bb |
| NT_SEC_SYNCHRONIZE \
|
|
|
dd89bb |
| NT_SEC_WRITE_DAC;
|
|
|
dd89bb |
|
|
|
dd89bb |
if (!sqos) {
|
|
|
dd89bb |
ssqos.length = sizeof(ssqos);
|
|
|
dd89bb |
ssqos.impersonation_level = NT_SECURITY_IMPERSONATION;
|
|
|
dd89bb |
ssqos.context_tracking_mode = NT_SECURITY_TRACKING_DYNAMIC;
|
|
|
dd89bb |
ssqos.effective_only = 1;
|
|
|
dd89bb |
sqos = &ssqos;
|
|
|
dd89bb |
}
|
|
|
dd89bb |
|
|
|
dd89bb |
oa.len = sizeof(oa);
|
|
|
dd89bb |
oa.root_dir = (void *)0;
|
|
|
dd89bb |
oa.obj_name = &nt_afdep;
|
|
|
dd89bb |
oa.obj_attr = NT_OBJ_CASE_INSENSITIVE | NT_OBJ_INHERIT;
|
|
|
dd89bb |
oa.sec_desc = (nt_security_descriptor *)0;
|
|
|
dd89bb |
oa.sec_qos = sqos;
|
|
|
dd89bb |
|
|
|
dd89bb |
iosb = iosb ? iosb : &siosb;
|
|
|
dd89bb |
|
|
|
dd89bb |
if ((status = __ntapi->zw_create_file(
|
|
|
dd89bb |
&_hsocket,
|
|
|
dd89bb |
desired_access,
|
|
|
dd89bb |
&oa,
|
|
|
dd89bb |
iosb,
|
|
|
dd89bb |
0,
|
|
|
dd89bb |
0,
|
|
|
dd89bb |
NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
|
|
|
dd89bb |
NT_FILE_OPEN_IF,
|
|
|
dd89bb |
0,
|
|
|
dd89bb |
&afd_ea,
|
|
|
dd89bb |
ea_length)))
|
|
|
dd89bb |
return status;
|
|
|
dd89bb |
|
|
|
dd89bb |
oa.obj_name = 0;
|
|
|
dd89bb |
oa.obj_attr = 0;
|
|
|
dd89bb |
|
|
|
dd89bb |
hssocket->hsocket = _hsocket;
|
|
|
dd89bb |
hssocket->ntflags = 0;
|
|
|
dd89bb |
hssocket->domain = domain;
|
|
|
dd89bb |
hssocket->type = type;
|
|
|
dd89bb |
hssocket->protocol = protocol;
|
|
|
dd89bb |
hssocket->timeout.quad = 0;
|
|
|
dd89bb |
hssocket->iostatus = NT_STATUS_SUCCESS;
|
|
|
dd89bb |
hssocket->waitstatus = NT_STATUS_SUCCESS;
|
|
|
dd89bb |
|
|
|
dd89bb |
return status;
|
|
|
dd89bb |
}
|