Despite looking over information on this list, I can’t get ZwCreateFile to open a transport address. The problem seems to be with an incorrectly formed EA address structure, as ZwCreateFile returns STATUS_EA_LIST_INCONSISTENT.
All I want to do is open an address on the local machine on any old non-reserved port number.
Maybe someone has a clear code snipped filling out an EA buffer for opening an address???
Here’s what I’ve got:
OBJECT_ATTRIBUTES objectAttrib;
IO_STATUS_BLOCK ioStatusBlock;
NTSTATUS ntStatus;
PFILE_FULL_EA_INFORMATION eaBuffer;
LONG eaLength;
TA_IP_ADDRESS tAddr;
TDI_ADDRESS_IP tIpAddr;
ANSI_STRING AnsiDeviceName;
UNICODE_STRING UniDeviceName;
RtlInitAnsiString(&AnsiDeviceName, “\Device\Tcp”);
ntStatus = RtlAnsiStringToUnicodeString(&UniDeviceName, &AnsiDeviceName, TRUE);
if ( !NT_SUCCESS(ntStatus) )
{
dprintf(“RtlAnsiStringToUnicodeString failed\n”);
return;
}
tIpAddr.sin_port = 34835;
tIpAddr.in_addr = 0;
RtlZeroMemory(&tIpAddr.sin_zero[0], 8);
tAddr.TAAddressCount = 1;
tAddr.Address[0].AddressLength = 14;
tAddr.Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
RtlCopyMemory(&tAddr.Address[0].Address[0], &tIpAddr, sizeof(TDI_ADDRESS_IP));
eaLength = FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName[0]) +
TDI_TRANSPORT_ADDRESS_LENGTH + sizeof(TA_IP_ADDRESS);
eaBuffer = (PFILE_FULL_EA_INFORMATION)
ExAllocatePool(PagedPoolCacheAligned, eaLength);
if(!eaBuffer) return;
RtlZeroMemory(eaBuffer, eaLength);
eaBuffer->NextEntryOffset = 0;
eaBuffer->Flags = 0;
eaBuffer->EaNameLength = strlen(TdiTransportAddress);
eaBuffer->EaValueLength = sizeof(TA_IP_ADDRESS);
RtlCopyMemory(&eaBuffer->EaName[0], TdiTransportAddress, strlen(TdiTransportAddress) + 1);
RtlCopyMemory(&eaBuffer->EaName[0] + strlen(TdiTransportAddress) + 1,
&tAddr, sizeof(TA_IP_ADDRESS));
InitializeObjectAttributes(&objectAttrib,
&UniDeviceName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
//request an open address handle
ntStatus = ZwCreateFile(&tdiOpenAddress,
GENERIC_READ | GENERIC_WRITE,
&objectAttrib,
&ioStatusBlock,
0L,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN_IF,
0L,
&eaBuffer,
sizeof(eaBuffer));