⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jwawindns.pas

📁 比较全面的win32api开发包
💻 PAS
📖 第 1 页 / 共 5 页
字号:
//

type
  PDNS_MESSAGE_BUFFER = ^DNS_MESSAGE_BUFFER;
  {$EXTERNALSYM PDNS_MESSAGE_BUFFER}
  _DNS_MESSAGE_BUFFER = record
    MessageHead: DNS_HEADER;
    MessageBody: array [0..0] of CHAR;
  end;
  {$EXTERNALSYM _DNS_MESSAGE_BUFFER}
  DNS_MESSAGE_BUFFER = _DNS_MESSAGE_BUFFER;
  {$EXTERNALSYM DNS_MESSAGE_BUFFER}
  TDnsMessageBuffer = DNS_MESSAGE_BUFFER;
  PDnsMessageBuffer = PDNS_MESSAGE_BUFFER;

function DnsWriteQuestionToBuffer_W(pDnsBuffer: PDNS_MESSAGE_BUFFER; pdwBufferSize: LPDWORD; pszName: LPWSTR; wType: WORD; Xid: WORD; fRecursionDesired: BOOL): BOOL; stdcall;
{$EXTERNALSYM DnsWriteQuestionToBuffer_W}

function DnsWriteQuestionToBuffer_UTF8(pDnsBuffer: PDNS_MESSAGE_BUFFER; pdwBufferSize: LPDWORD; pszName: LPSTR; wType: WORD; Xid: WORD; fRecursionDesired: BOOL): BOOL; stdcall;
{$EXTERNALSYM DnsWriteQuestionToBuffer_UTF8}

function DnsExtractRecordsFromMessage_W(pDnsBuffer: PDNS_MESSAGE_BUFFER; wMessageLength: WORD; ppRecord: PPDNS_RECORD): DNS_STATUS; stdcall;
{$EXTERNALSYM DnsExtractRecordsFromMessage_W}

function DnsExtractRecordsFromMessage_UTF8(pDnsBuffer: PDNS_MESSAGE_BUFFER; wMessageLength: WORD; ppRecord: PPDNS_RECORD): DNS_STATUS; stdcall;
{$EXTERNALSYM DnsExtractRecordsFromMessage_UTF8}

implementation

const
  dnsapi = 'dnsapi.dll';

procedure INLINE_WORD_FLIP(var Out: WORD; In_: WORD);
begin
  Out := (In_ shl 8) or (In_ shr 8);
end;

procedure INLINE_HTONS(var Out: WORD; In_: WORD);
begin
  INLINE_WORD_FLIP(Out, In_);
end;

procedure INLINE_NTOHS(var Out: WORD; In_: WORD);
begin
  INLINE_WORD_FLIP(Out, In_);
end;

procedure INLINE_DWORD_FLIP(var Out: DWORD; In_: DWORD);
begin
  Out := ((In_ shl 8) and $00ff0000) or (In_ shl 24) or
    ((In_ shr 8) and $0000ff00) or (In_ shr 24);
end;

procedure INLINE_NTOHL(var Out: DWORD; In_: DWORD);
begin
  INLINE_DWORD_FLIP(Out, In_);
end;

procedure INLINE_HTONL(var Out: DWORD; In_: DWORD);
begin
  INLINE_DWORD_FLIP(Out, In_);
end;

procedure INLINE_WRITE_FLIPPED_WORD(pout: PWORD; In_: WORD);
begin
  INLINE_WORD_FLIP(pout^, In_);
end;

procedure INLINE_WRITE_FLIPPED_DWORD(pout: PDWORD; In_: DWORD);
begin
  INLINE_DWORD_FLIP(pout^, In_);
end;

function DNS_HEADER_FLAGS(pHead: PDNS_HEADER): WORD;
begin
  Result := PWORD(Integer(pHead) + SizeOf(WORD))^;
end;

procedure DNS_BYTE_FLIP_HEADER_COUNTS(var pHeader: PDNS_HEADER);
var
  _head: PDNS_HEADER;
begin
  _head := pHeader;
  INLINE_HTONS(_head^.Xid, _head^.Xid);
  INLINE_HTONS(_head^.QuestionCount, _head^.QuestionCount);
  INLINE_HTONS(_head^.AnswerCount, _head^.AnswerCount);
  INLINE_HTONS(_head^.NameServerCount, _head^.NameServerCount);
  INLINE_HTONS(_head^.AdditionalCount, _head^.AdditionalCount);
end;

{
#define DNS_QUESTION_NAME_FROM_HEADER( _pHeader_ ) \
            ( (PCHAR)( (PDNS_HEADER)(_pHeader_) + 1 ) )

#define DNS_ANSWER_FROM_QUESTION( _pQuestion_ ) \
            ( (PCHAR)( (PDNS_QUESTION)(_pQuestion_) + 1 ) )
}

function IS_WORD_ALIGNED(P: Pointer): BOOL;
begin
  Result := (Integer(P) and 1) = 0;
end;

function IS_DWORD_ALIGNED(P: Pointer): BOOL;
begin
  Result := (Integer(P) and 3) = 0;
end;

function IS_QWORD_ALIGNED(P: Pointer): BOOL;
begin
  Result := (Integer(P) and 7) = 0;
end;


{$IFDEF DYNAMIC_LINK}
var
  _DnsQueryConfig: Pointer;

function DnsQueryConfig;
begin
  GetProcedureAddress(_DnsQueryConfig, dnsapi, 'DnsQueryConfig');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsQueryConfig]
  end;
end;
{$ELSE}
function DnsQueryConfig; external dnsapi name 'DnsQueryConfig';
{$ENDIF DYNAMIC_LINK}

function DNS_TEXT_RECORD_LENGTH(StringCount: Integer): Integer;
begin
  Result := SizeOf(DWORD) + ((StringCount) * SizeOf(PChar));
end;

function DNS_NULL_RECORD_LENGTH(ByteCount: Integer): Integer;
begin
  Result := SizeOf(DWORD) + (ByteCount);
end;

function DNS_WKS_RECORD_LENGTH(ByteCount: Integer): Integer;
begin
  Result := SizeOf(DNS_WKS_DATA) + (ByteCount - 1);
end;

//#define DNS_WINS_RECORD_LENGTH(IpCount) \
//            (FIELD_OFFSET(DNS_WINS_DATA, WinsServers) + ((IpCount) * sizeof(IP4_ADDRESS)))


procedure DNS_RRSET_INIT(rrset: PDnsRRSet);
begin
  rrset^.pFirstRR := nil;
  rrset^.pLastRR := (@rrset^.pFirstRR);
end;

//#define DNS_RRSET_ADD( rrset, pnewRR )          \
//        {                                       \
//            PDNS_RRSET  _prrset = &(rrset);     \
//            PDNS_RECORD _prrnew = (pnewRR);     \
//            _prrset->pLastRR->pNext = _prrnew;  \
//            _prrset->pLastRR = _prrnew;         \
//        }

procedure DNS_RRSET_TERMINATE(rrset: PDnsRRSet);
begin
  rrset^.pLastRR^.pNext := nil;
end;


{$IFDEF DYNAMIC_LINK}
var
  _DnsRecordCopyEx: Pointer;

function DnsRecordCopyEx;
begin
  GetProcedureAddress(_DnsRecordCopyEx, dnsapi, 'DnsRecordCopyEx');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsRecordCopyEx]
  end;
end;
{$ELSE}
function DnsRecordCopyEx; external dnsapi name 'DnsRecordCopyEx';
{$ENDIF DYNAMIC_LINK}

{$IFDEF DYNAMIC_LINK}
var
  _DnsRecordSetCopyEx: Pointer;

function DnsRecordSetCopyEx;
begin
  GetProcedureAddress(_DnsRecordSetCopyEx, dnsapi, 'DnsRecordSetCopyEx');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsRecordSetCopyEx]
  end;
end;
{$ELSE}
function DnsRecordSetCopyEx; external dnsapi name 'DnsRecordSetCopyEx';
{$ENDIF DYNAMIC_LINK}
{$IFDEF UNICODE}
function DnsRecordCopy(pRR: PDNS_RECORD): PDNS_RECORD;
begin
  Result := DnsRecordCopyEx(pRR, DnsCharSetUnicode, DnsCharSetUnicode);
end;

function DnsRecordSetCopy(pRR: PDNS_RECORD): PDNS_RECORD;
begin
  Result := DnsRecordSetCopyEx(pRR, DnsCharSetUnicode, DnsCharSetUnicode);
end;
{$ELSE}
function DnsRecordCopy(pRR: PDNS_RECORD): PDNS_RECORD;
begin
  Result := DnsRecordCopyEx(pRR, DnsCharSetAnsi, DnsCharSetAnsi);
end;

function DnsRecordSetCopy(pRR: PDNS_RECORD): PDNS_RECORD;
begin
  Result := DnsRecordSetCopyEx(pRR, DnsCharSetAnsi, DnsCharSetAnsi);
end;
{$ENDIF}

{$IFDEF DYNAMIC_LINK}
var
  _DnsRecordCompare: Pointer;

function DnsRecordCompare;
begin
  GetProcedureAddress(_DnsRecordCompare, dnsapi, 'DnsRecordCompare');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsRecordCompare]
  end;
end;
{$ELSE}
function DnsRecordCompare; external dnsapi name 'DnsRecordCompare';
{$ENDIF DYNAMIC_LINK}

{$IFDEF DYNAMIC_LINK}
var
  _DnsRecordSetCompare: Pointer;

function DnsRecordSetCompare;
begin
  GetProcedureAddress(_DnsRecordSetCompare, dnsapi, 'DnsRecordSetCompare');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsRecordSetCompare]
  end;
end;
{$ELSE}
function DnsRecordSetCompare; external dnsapi name 'DnsRecordSetCompare';
{$ENDIF DYNAMIC_LINK}

{$IFDEF DYNAMIC_LINK}
var
  _DnsRecordSetDetach: Pointer;

function DnsRecordSetDetach;
begin
  GetProcedureAddress(_DnsRecordSetDetach, dnsapi, 'DnsRecordSetDetach');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsRecordSetDetach]
  end;
end;
{$ELSE}
function DnsRecordSetDetach; external dnsapi name 'DnsRecordSetDetach';
{$ENDIF DYNAMIC_LINK}

{$IFDEF DYNAMIC_LINK}
var
  _DnsFreeRecordListDeep: Pointer;

procedure DnsFreeRecordListDeep;
begin
  GetProcedureAddress(_DnsFreeRecordListDeep, dnsapi, 'DnsRecordListFree');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsFreeRecordListDeep]
  end;
end;
{$ELSE}
procedure DnsFreeRecordListDeep; external dnsapi name 'DnsRecordListFree';
{$ENDIF DYNAMIC_LINK}

{$IFDEF DYNAMIC_LINK}
var
  _DnsRecordListFree: Pointer;

procedure DnsRecordListFree;
begin
  GetProcedureAddress(_DnsRecordListFree, dnsapi, 'DnsRecordListFree');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsRecordListFree]
  end;
end;
{$ELSE}
procedure DnsRecordListFree; external dnsapi name 'DnsRecordListFree';
{$ENDIF DYNAMIC_LINK}

{$IFDEF DYNAMIC_LINK}
var
  _DnsFree: Pointer;

procedure DnsFree;
begin
  GetProcedureAddress(_DnsFree, dnsapi, 'DnsFree');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsFree]
  end;
end;
{$ELSE}
procedure DnsFree; external dnsapi name 'DnsFree';
{$ENDIF DYNAMIC_LINK}

{$IFDEF DYNAMIC_LINK}
var
  _DnsQuery_A: Pointer;

function DnsQuery_A;
begin
  GetProcedureAddress(_DnsQuery_A, dnsapi, 'DnsQuery_A');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsQuery_A]
  end;
end;
{$ELSE}
function DnsQuery_A; external dnsapi name 'DnsQuery_A';
{$ENDIF DYNAMIC_LINK}

{$IFDEF DYNAMIC_LINK}
var
  _DnsQuery_UTF8: Pointer;

function DnsQuery_UTF8;
begin
  GetProcedureAddress(_DnsQuery_UTF8, dnsapi, 'DnsQuery_UTF8');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsQuery_UTF8]
  end;
end;
{$ELSE}
function DnsQuery_UTF8; external dnsapi name 'DnsQuery_UTF8';
{$ENDIF DYNAMIC_LINK}

{$IFDEF DYNAMIC_LINK}
var
  _DnsQuery_W: Pointer;

function DnsQuery_W;
begin
  GetProcedureAddress(_DnsQuery_W, dnsapi, 'DnsQuery_W');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsQuery_W]
  end;
end;
{$ELSE}
function DnsQuery_W; external dnsapi name 'DnsQuery_W';
{$ENDIF DYNAMIC_LINK}
{$IFDEF UNICODE}

{$IFDEF DYNAMIC_LINK}
var
  _DnsQuery: Pointer;

function DnsQuery;
begin
  GetProcedureAddress(_DnsQuery, dnsapi, 'DnsQuery_W');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsQuery]
  end;
end;
{$ELSE}
function DnsQuery; external dnsapi name 'DnsQuery_W';
{$ENDIF DYNAMIC_LINK}
{$ELSE}

{$IFDEF DYNAMIC_LINK}
var
  _DnsQuery: Pointer;

function DnsQuery;
begin
  GetProcedureAddress(_DnsQuery, dnsapi, 'DnsQuery_A');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsQuery]
  end;
end;
{$ELSE}
function DnsQuery; external dnsapi name 'DnsQuery_A';
{$ENDIF DYNAMIC_LINK}
{$ENDIF}

{$IFDEF DYNAMIC_LINK}
var
  _DnsAcquireContextHandle_W: Pointer;

function DnsAcquireContextHandle_W;
begin
  GetProcedureAddress(_DnsAcquireContextHandle_W, dnsapi, 'DnsAcquireContextHandle_W');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsAcquireContextHandle_W]
  end;
end;
{$ELSE}
function DnsAcquireContextHandle_W; external dnsapi name 'DnsAcquireContextHandle_W';
{$ENDIF DYNAMIC_LINK}

{$IFDEF DYNAMIC_LINK}
var
  _DnsAcquireContextHandle_A: Pointer;

function DnsAcquireContextHandle_A;
begin
  GetProcedureAddress(_DnsAcquireContextHandle_A, dnsapi, 'DnsAcquireContextHandle_A');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsAcquireContextHandle_A]
  end;
end;
{$ELSE}
function DnsAcquireContextHandle_A; external dnsapi name 'DnsAcquireContextHandle_A';
{$ENDIF DYNAMIC_LINK}
{$IFDEF UNICODE}

{$IFDEF DYNAMIC_LINK}
var
  _DnsAcquireContextHandle: Pointer;

function DnsAcquireContextHandle;
begin
  GetProcedureAddress(_DnsAcquireContextHandle, dnsapi, 'DnsAcquireContextHandle_W');
  asm
    mov esp, ebp
    pop ebp
    jmp [_DnsAcquireContextHandle]
  end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -