/programs/network/airc/trunk/macros.inc |
---|
File deleted |
\ No newline at end of file |
Property changes: |
Deleted: svn:eol-style |
-native |
\ No newline at end of property |
/programs/network/airc/trunk/airc.asm |
---|
9,8 → 9,12 |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
version equ '0.4' |
version equ '0.5' |
;__DEBUG__ equ 1 |
;__DEBUG_LEVEL__ equ 1 |
use32 |
org 0x0 |
23,8 → 27,10 |
dd 0x100000 |
dd 0,0 |
include "lang.inc" |
;include "macros.inc" |
include "..\..\..\macros.inc" |
;include "fdo.inc" |
include "eth.inc" |
;include "lang.inc" |
irc_server_ip db 83,149,74,246 ;server: kolibrios.org |
39,7 → 45,7 |
mov eax,40 |
mov ebx,10000111b |
int 0x40 |
mcall |
mov edi,I_END |
mov ecx,60*120 |
61,10 → 67,10 |
mov eax,5 |
mov ebx,1 |
int 0x40 |
mcall |
mov eax,11 ; wait here for event |
int 0x40 |
mcall |
call print_status |
105,12 → 111,12 |
button: ; button |
mov eax,17 ; get id |
int 0x40 |
mcall |
cmp ah,1 ; close program |
jne noclose |
mov eax,-1 |
int 0x40 |
mcall |
noclose: |
call socket_commands |
125,7 → 131,7 |
mov eax,53 |
mov ebx,6 |
mov ecx,[socket] |
int 0x40 |
mcall |
mov [status],eax |
140,7 → 146,7 |
mov ebx,450*65536+30 |
mov ecx,231*65536+10 |
mov edx,0xffffff |
int 0x40 |
mcall |
pop ecx |
mov eax,47 |
147,7 → 153,7 |
mov ebx,2*65536 |
mov edx,450*65536+231 |
mov esi,0x000000 |
int 0x40 |
mcall |
nopr: |
164,7 → 170,7 |
cmp ah,22 ; open socket |
jnz tst3 |
mov eax,3 |
int 0x40 |
mcall |
mov ecx,eax |
mov eax,53 |
mov ebx,5 |
171,7 → 177,7 |
mov edx,6667 |
mov esi,dword [irc_server_ip] |
mov edi,1 |
int 0x40 |
mcall |
mov [socket], eax |
ret |
tst3: |
185,7 → 191,7 |
mov ecx,[socket] |
mov edx,string0l-string0 |
mov esi,string0 |
int 0x40 |
mcall |
mov eax,53 ; |
mov ebx,7 |
192,7 → 198,7 |
mov ecx,[socket] |
mov edx,[user_real_name] |
mov esi,user_real_name+4 |
int 0x40 |
mcall |
mov eax,53 ; |
mov ebx,7 |
199,12 → 205,12 |
mov ecx,[socket] |
mov edx,2 |
mov esi,line_feed |
int 0x40 |
mcall |
mov eax,5 |
mov ebx,10 |
int 0x40 |
mcall |
mov eax,53 ; nick |
mov ebx,7 |
211,7 → 217,7 |
mov ecx,[socket] |
mov edx,string1l-string1 |
mov esi,string1 |
int 0x40 |
mcall |
mov eax,53 ; |
mov ebx,7 |
218,7 → 224,7 |
mov ecx,[socket] |
mov edx,[user_nick] |
mov esi,user_nick+4 |
int 0x40 |
mcall |
mov eax,53 ; |
mov ebx,7 |
225,7 → 231,7 |
mov ecx,[socket] |
mov edx,2 |
mov esi,line_feed |
int 0x40 |
mcall |
ret |
240,7 → 246,7 |
mov eax,53 |
mov ebx,8 |
mov ecx,[socket] |
int 0x40 |
mcall |
ret |
no_24: |
251,7 → 257,7 |
main_window_key: |
mov eax,2 |
int 0x40 |
mcall |
shr eax,8 |
298,7 → 304,7 |
mov ebx,415*65536+6*13 |
mov ecx,27*65536+12*10 |
mov edx,0xffffff |
int 0x40 |
mcall |
mov eax,4 |
mov ebx,415*65536+27 |
307,7 → 313,7 |
newch: |
movzx esi,byte [edx+31] |
and esi,0x1f |
int 0x40 |
mcall |
add edx,32 |
add ebx,12 |
cmp edx,channel_list+32*10 |
374,7 → 380,7 |
mov ebx,415*65536+6*13 |
mov ecx,27*65536+12*10 |
mov edx,0xffffff |
int 0x40 |
mcall |
popa |
mov eax,4 |
398,7 → 404,7 |
mov ecx,[index_list_2] |
no_op: |
int 0x40 |
mcall |
inc ebp |
cmp ebp,10 |
509,7 → 515,7 |
mov eax, 53 ; write channel |
mov ebx, 7 |
mov ecx, [socket] |
int 0x40 |
mcall |
mov esi,send_string |
mov edx,[xpos] |
520,7 → 526,7 |
mov eax, 53 ; write message |
mov ebx, 7 |
mov ecx, [socket] |
int 0x40 |
mcall |
jmp send_done |
602,33 → 608,41 |
cmp [send_string+1],dword 'aser' |
jne no_set_server |
; pusha |
; mov edi,irc_server_ip |
; mov esi,send_string+7 |
; mov eax,0 |
; mov edx,[xpos] |
; add edx,send_string-1 |
; newsip: |
; cmp [esi],byte '.' |
; je sipn |
; cmp esi,edx |
; jg sipn |
; movzx ebx,byte [esi] |
; inc esi |
; imul eax,10 |
; sub ebx,48 |
; add eax,ebx |
; jmp newsip |
; sipn: |
; mov [edi],al |
; xor eax,eax |
; inc esi |
; cmp esi,send_string+30 |
; jg sipnn |
; inc edi |
; cmp edi,irc_server_ip+3 |
; jbe newsip |
; sipnn: |
; popa |
pusha |
mov edi,irc_server_ip |
mov esi,send_string+7 |
mov eax,0 |
mov edx,[xpos] |
add edx,send_string-1 |
newsip: |
cmp [esi],byte '.' |
je sipn |
cmp esi,edx |
jg sipn |
movzx ebx,byte [esi] |
inc esi |
imul eax,10 |
sub ebx,48 |
add eax,ebx |
jmp newsip |
sipn: |
mov [edi],al |
xor eax,eax |
inc esi |
cmp esi,send_string+30 |
jg sipnn |
inc edi |
cmp edi,irc_server_ip+3 |
jbe newsip |
sipnn: |
mov eax,send_string |
add eax,[xpos] |
mov dword[eax],0 |
resolve send_string+7,dword[irc_server_ip] |
;DEBUGF 1,'%u.%u.%u.%u\n',1[irc_server_ip],1[irc_server_ip+1],1[irc_server_ip+2],1[irc_server_ip+3] |
popa |
mov ecx,[xpos] |
715,7 → 729,7 |
mov eax, 53 ; write server command |
mov ebx, 7 |
mov ecx, [socket] |
int 0x40 |
mcall |
send_done: |
726,12 → 740,12 |
jne no_quit_server |
mov eax,5 |
mov ebx,200 |
int 0x40 |
mcall |
mov eax, 53 ; close socket |
mov ebx, 8 |
mov ecx, [socket] |
int 0x40 |
mcall |
mov ecx,[max_windows] |
mov edi,I_END |
842,11 → 856,11 |
mov ebx,1 |
mov ecx,channel_thread |
mov edx,[thread_stack] |
int 0x40 |
mcall |
mov eax,5 |
mov ebx,10 |
int 0x40 |
mcall |
add [thread_stack],0x4000 |
add [thread_screen],120*80 |
864,7 → 878,7 |
mov ebx,8*65536+6*80 |
mov ecx,151*65536+13 |
mov edx,0xffffff |
int 0x40 |
mcall |
mov eax,4 |
mov ebx,8*65536+154 |
871,7 → 885,7 |
mov ecx,0x000000 |
mov edx,send_string |
mov esi,[xpos] |
int 0x40 |
mcall |
popa |
886,7 → 900,7 |
mov eax,9 |
mov ebx,0xe0000 |
mov ecx,-1 |
int 0x40 |
mcall |
mov edx,[blink] |
and edx,1 |
907,7 → 921,7 |
mov bx,cx |
mov ecx,151*65536+163 |
mov eax,38 |
int 0x40 |
mcall |
popa |
919,7 → 933,7 |
mov ebx,8*65536+6*60 |
mov ecx,151*65536+13 |
mov edx,0xffffff |
int 0x40 |
mcall |
popa |
1072,7 → 1086,7 |
mov edx,command |
mov esi,[cmd] |
mov [command+esi-1],word '**' |
; int 0x40 |
; mcall |
mov eax,53 |
mov ebx,7 |
1081,7 → 1095,7 |
sub edx,2 |
and edx,255 |
mov esi,command |
int 0x40 |
mcall |
mov eax,53 |
mov ebx,7 |
1088,7 → 1102,7 |
mov ecx,[socket] |
mov edx,2 |
mov esi,linef |
int 0x40 |
mcall |
popa |
ret |
1655,6 → 1669,7 |
db $90,$91,$92,$93,$94,$95,$96,$97 , $98,$99,$9A,$9B,$9C,$9D,$9E,$9F ; D |
db $A0,$A1,$A2,$A3,$A4,$A5,$A6,$A7 , $A8,$A9,$AA,$AB,$AC,$AD,$AE,$AF ; E |
db $E0,$E1,$E2,$E3,$E4,$E5,$E6,$E7 , $E8,$E9,$EA,$EB,$EC,$ED,$EE,$EF ; F |
; 0 1 2 3 4 5 6 7 8 9 A B C D E F |
cp866_table: |
db $C0,$C1,$C2,$C3,$C4,$C5,$C6,$C7 , $C8,$C9,$CA,$CB,$CC,$CD,$CE,$CF ; 8 |
1665,8 → 1680,8 |
db '?','?','?','?','?','?','?','?' , '?','?','?','?','?','?','?','?' ; D |
db $F0,$F1,$F2,$F3,$F4,$F5,$F6,$F7 , $F8,$F9,$FA,$FB,$FC,$FD,$FE,$FF ; E |
db $A8,$B8,'?','?','?','?','?','?' , '?','?','?','?','?','?','?','?' ; F |
; 0 1 2 3 4 5 6 7 8 9 A B C D E F |
print_character: |
pusha |
1790,7 → 1805,7 |
mov eax, 53 |
mov ebx, 2 |
mov ecx, [socket] |
int 0x40 |
mcall |
mov ecx,-1 |
1800,7 → 1815,7 |
mov eax, 53 |
mov ebx, 3 |
mov ecx, [socket] |
int 0x40 |
mcall |
cmp bl,0x80 |
jb @f |
1822,69 → 1837,55 |
mov eax,12 |
mov ebx,1 |
int 0x40 |
mcall |
mov [old_status],300 |
mov eax,0 ; draw window |
xor eax,eax ; draw window |
mov ebx,5*65536+499 |
mov ecx,5*65536+345 |
mov edx,[wcolor] |
add edx,0x03ffffff |
mov esi,0x80555599 |
mov edi,0x00ffffff |
int 0x40 |
add edx,0x13ffffff |
mov edi,title |
mcall |
mov eax,4 ; label |
mov ebx,9*65536+8 |
mov ecx,0x10ffffff |
mov edx,labelt |
mov esi,labellen-labelt |
int 0x40 |
mov eax,8 ; button: open socket |
mov ebx,43*65536+22 |
mov ecx,229*65536+10 |
mov edx,22 |
mov esi,[main_button] |
int 0x40 |
mcall |
mov eax,8 ; button: send userinfo |
;mov eax,8 ; button: send userinfo |
mov ebx,180*65536+22 |
mov ecx,229*65536+10 |
mov edx,23 |
int 0x40 |
mcall |
mov eax,8 ; button: close socket |
;mov eax,8 ; button: close socket |
mov ebx,317*65536+22 |
mov ecx,229*65536+10 |
mov edx,24 |
int 0x40 |
mcall |
mov eax,38 ; line |
mov ebx,5*65536+494 |
mov ecx,148*65536+148 |
mov edx,[main_line] |
int 0x40 |
mcall |
add ecx,1*65536+1 |
; mov edx,0x5555cc |
; int 0x40 |
mov eax,38 ; line |
mov ebx,5*65536+494 |
mov ecx,166*65536+166 |
int 0x40 |
mcall |
add ecx,1*65536+1 |
; mov edx,0x5555cc |
; int 0x40 |
mov eax,38 ; line |
mov ebx,410*65536+410 |
mov ecx,22*65536+148 |
int 0x40 |
mcall |
add ebx,1*65536+1 |
; mov edx,0x5555cc |
; int 0x40 |
mov ebx,25*65536+183 ; info text |
mov ecx,0x000000 |
1892,7 → 1893,7 |
mov esi,70 |
newline: |
mov eax,4 |
int 0x40 |
mcall |
add ebx,12 |
add edx,70 |
cmp [edx],byte 'x' |
1903,7 → 1904,7 |
mov eax,12 |
mov ebx,2 |
int 0x40 |
mcall |
popa |
1916,8 → 1917,8 |
text: |
db ' Real name : KolibriOS User - change with eg /areal Jill User ' |
db ' Nick : kolibri_user - change with eg /anick Jill ' |
db ' Server : 83.149.74.246 - change with eg /aserv 192.168.1.24 ' |
db ' Nick : KolibriOS User - change with eg /anick Jill ' |
db ' Server : kolibrios.org - change with eg /aserv irc.by ' |
db ' ' |
db ' 1) Open socket 2) Send userinfo Close socket ' |
db ' ' |
1974,7 → 1975,7 |
mov dword [channel_list+edi],dword ' ' |
mov byte [channel_list+edi+31],byte 1 |
mov eax,-1 |
int 0x40 |
mcall |
no_channel_leave: |
call check_mouse |
1981,7 → 1982,7 |
mov eax,23 |
mov ebx,1 |
int 0x40 |
mcall |
cmp eax,1 |
jne no_draw_window |
1996,7 → 1997,7 |
cmp eax,3 |
jne no_end |
mov eax,17 |
int 0x40 |
mcall |
mov eax,ebp |
imul eax,120*80 |
add eax,I_END |
2008,7 → 2009,7 |
mov [eax],dword ' ' |
mov [eax+31],byte 1 |
mov eax,-1 |
int 0x40 |
mcall |
not_close: |
mov [text_start],eax |
mov eax,nocl |
2047,7 → 2048,7 |
mov eax,37 |
mov ebx,1 |
int 0x40 |
mcall |
mov ebx,eax |
shr eax,16 |
2073,7 → 2074,7 |
call print_user_list |
mov eax,5 |
mov ebx,8 |
int 0x40 |
mcall |
jmp no_mouse |
no_plus: |
2088,7 → 2089,7 |
call print_user_list |
mov eax,5 |
mov ebx,8 |
int 0x40 |
mcall |
no_minus: |
2104,7 → 2105,7 |
thread_key: |
mov eax,2 |
int 0x40 |
mcall |
shr eax,8 |
2139,7 → 2140,7 |
wait_for_sending: |
mov eax,5 |
mov ebx,1 |
int 0x40 |
mcall |
cmp [send_to_server],1 |
je wait_for_sending |
call draw_channel_text |
2172,7 → 2173,7 |
mov bx,word [rxs] |
imul bx,6 |
mov edx,0xffffff |
int 0x40 |
mcall |
popa |
push ecx |
mov eax,4 |
2191,7 → 2192,7 |
jne no_blue |
mov ecx,0x0000ff |
no_blue: |
int 0x40 |
mcall |
add edx,[rxs] |
add ebx,10 |
pop ecx |
2210,7 → 2211,7 |
mov eax,12 |
mov ebx,1 |
int 0x40 |
mcall |
mov ebx,ebp ; draw window |
shl ebx,16+4 |
2231,7 → 2232,7 |
mov esi,0x80555599 |
mov edi,0x00ffffff |
int 0x40 |
mcall |
mov eax,ebp ; label |
add eax,48 |
2252,30 → 2253,30 |
mov ebx,9*65536+8 |
mov ecx,0x00ffffff |
mov edx,labelc |
int 0x40 |
mcall |
mov eax,38 ; line |
mov ebx,5*65536+494 |
mov ecx,148*65536+148 |
mov edx,[channel_line_sun] |
int 0x40 |
mcall |
add ecx,1*65536+1 |
mov edx,[channel_line_shadow] |
int 0x40 |
mcall |
mov eax,38 ; line |
;mov eax,38 ; line |
mov ebx,410*65536+410 |
mov ecx,22*65536+148 |
mov edx,[channel_line_sun] |
int 0x40 |
mcall |
add ebx,1*65536+1 |
mov edx,[channel_line_shadow] |
int 0x40 |
mcall |
mov eax,12 |
mov ebx,2 |
int 0x40 |
mcall |
popa |
2282,7 → 2283,6 |
ret |
; DATA AREA |
socket dd 0x0 |
2376,9 → 2376,13 |
wcolor dd 0x000000 |
labelc db 'AIRC - WINDOW X: #xxx ' |
labelt db 'IRC client ',version |
labellen: |
title db 'IRC client ',version,0 |
;include_debug_strings ; ALWAYS present in data section |
dnsMsg: rb 512 ; buffer used by DNS client |
;; |
;; Channel data at I_END |
;; |
/programs/network/airc/trunk/eth.inc |
---|
0,0 → 1,670 |
; |
; ETH.INC |
; |
; made by hidnplayr (hidnplayr@gmail.com) for KolibriOS and DEX4U |
; |
; The given code before every macro is only a simple example |
; |
; Change the OS value to DEX4U or MEOS |
; |
; HISTORY |
; |
; v1.0: 18 august 2006 |
; |
MEOS equ 1 ; Dont change these ! |
DEX4U equ 2 ; |
OS equ MEOS ; Change these instead ;) |
TIMEOUT equ 60 ; timeout for DNS request |
BUFFER equ 512 ; Buffer size for DNS |
macro int1 { |
if OS eq MEOS |
mcall |
else if OS eq DEX4U |
int 0x52 |
end if |
} |
macro int2 { |
if OS eq MEOS |
mcall |
else if OS eq DEX4U |
int 0x53 |
end if |
} |
macro mov arg1,arg2 { |
if arg1 eq arg2 |
else |
mov arg1,arg2 |
end if |
} |
; eth.get_IP eax |
; |
; gets the current IP that is defined in Stack (return in eax in this example) |
macro eth.get_IP IP { |
if OS eq MEOS |
mov eax,52 |
end if |
mov ebx,1 |
int1 |
mov IP ,eax |
} |
; eth.get_GATEWAY eax |
; |
; gets the current GATEWAY that is defined in Stack (return in eax in this example) |
macro eth.get_GATEWAY GATEWAY { |
if OS eq MEOS |
mov eax,52 |
end if |
mov ebx,9 |
int1 |
move GATEWAY ,eax |
} |
; eth.get_SUBNET eax |
; |
; gets the current SUBNET that is defined in Stack (return in eax in this example) |
macro eth.get_SUBNET SUBNET { |
if OS eq MEOS |
mov eax,52 |
end if |
mov ebx,10 |
int1 |
mov SUBNET ,eax |
} |
; eth.get_DNS eax |
; |
; gets the current DNS that is defined in Stack (return in eax in this example) |
macro eth.get_DNS DNS { |
if OS eq MEOS |
mov eax,52 |
end if |
mov ebx,13 |
int1 |
mov DNS ,eax |
} |
; eth.set_IP eax |
; |
; set a new IP in stack (input in eax in this example) |
macro eth.set_IP IP { |
mov ecx,IP |
if OS eq MEOS |
mov eax,52 |
end if |
mov ebx,3 |
int1 |
} |
; eth.set_GATEWAY eax |
; |
; set a new GATEWAY in stack (input in eax in this example) |
macro eth.set_GATEWAY GATEWAY { |
mov ecx,GATEWAY |
if OS eq MEOS |
mov eax,52 |
end if |
mov ebx,11 |
int1 |
} |
; eth.set_SUBNET eax |
; |
; set a new SUBNET in stack (input in eax in this example) |
macro eth.set_SUBNET SUBNET { |
mov ecx,SUBNET |
if OS eq MEOS |
mov eax,52 |
end if |
mov ebx,12 |
int1 |
} |
; eth.set_DNS eax |
; |
; set a new DNS in stack (input in eax in this example) |
macro eth.set_DNS DNS { |
mov ecx,DNS |
if OS eq MEOS |
mov eax,52 |
end if |
mov ebx,14 |
int1 |
} |
; eth.open eax,80,ebx,[socket] |
; |
; open a socket on local port in eax to port 80 on server on ebx |
; the socketnumber will be returned in [socket] (dword) |
macro eth.open local,remote,ip,socket { |
mov ecx, local |
mov edx, remote |
mov esi, ip |
if OS eq MEOS |
mov eax,53 |
end if |
mov ebx, 0 |
int2 |
mov socket,eax |
} |
; eth.close [socket] |
; |
; closes socket on socketnumber [socket] |
macro eth.close socket { |
mov ecx, socket |
if OS eq MEOS |
mov eax,53 |
end if |
mov ebx, 1 |
int2 |
} |
; eth.poll [socket],eax |
; |
; polls [socket] for data |
; eax = 0 when there is data |
macro eth.poll socket,result { |
mov ecx, socket |
if OS eq MEOS |
mov eax,53 |
end if |
mov ebx, 2 |
int2 |
mov result, eax |
} |
; eth.read_byte [socket], bl |
; |
; reads a byte from the socket and returns in bl |
macro eth.read_byte socket, result { |
mov ecx, socket |
if OS eq MEOS |
mov eax,53 |
end if |
mov ebx, 3 |
int2 |
mov result,bl |
} |
; eth.write [socket],12,msg |
; msg db 'hello world!' |
; |
; send message msg to socket |
macro eth.write socket,length,msg { |
mov ecx, socket |
mov edx, length |
mov esi, msg |
if OS eq MEOS |
mov eax,53 |
end if |
mov ebx, 4 |
int2 |
} |
; eth.open_tcp 80,80,eax,0,[socket] |
; |
; opens a tcp socket on port 80 to port 80 on IP eax with passive open |
; returns socket number in eax |
macro eth.open_tcp local,remote,ip,passive,socket { |
pusha |
mov ecx, local |
mov edx, remote |
mov esi, ip |
mov edi, passive ; 0 = PASSIVE open |
if OS eq MEOS |
mov eax,53 |
end if |
mov ebx, 5 |
int2 |
popa |
mov socket,eax |
} |
; eth.socket_status [socket],eax |
; |
; returns socket status in eax |
macro eth.socket_status socket,result { |
mov ecx, socket |
if OS eq MEOS |
mov eax,53 |
end if |
mov ebx, 6 |
int2 |
mov result,eax |
} |
; eth.write_tcp [socket],12,msg |
; |
; msg db 'hello world!' |
; |
; send message to TCP socket |
macro eth.write_tcp socket,length,msg { |
mov ecx, socket |
mov edx, length |
mov esi, msg |
if OS eq MEOS |
mov eax,53 |
end if |
mov ebx, 7 |
int2 |
} |
; eth.close_tcp [socket] |
; |
; closes tcp socket [socket] |
macro eth.close_tcp socket { |
mov ecx, socket |
if OS eq MEOS |
mov eax,53 |
end if |
mov ebx, 8 |
int2 |
} |
; eth.check_port 165,eax |
; |
; checks if port 165 is used |
; return is 0 when port is free |
macro eth.check_port port,result { |
if OS eq MEOS |
mov eax,53 |
end if |
mov ebx, 9 |
mov ecx, port |
int2 |
mov result,eax |
} |
; eth.status eax |
; |
; returns socket status in eax |
macro eth.status status { |
if OS eq MEOS |
mov eax,53 |
end if |
mov ebx, 255 |
mov ecx, 6 |
int2 |
mov status,eax |
} |
; eth.search 165,edx |
; |
; searches a free local port starting from 166 (165 + 1 !) |
; returns in edx |
macro eth.search_port port,result { |
mov edx,port |
@@: |
inc edx |
eth.check_port edx,eax |
cmp eax,0 |
je @r |
mov result,edx |
} |
; eth.read_data [socket],buffer,512 |
; buffer rb 512 |
; socket dd ? |
; |
; reads data from socket into a buffer, stops when there is no more data or buffer is full. |
macro eth.read_data socket,dest,endptr,bufferl { |
mov eax, dest |
mov endptr, eax |
; we have data - this will be the response |
@@: |
mov eax,endptr |
cmp eax,bufferl |
jg @f |
mov eax, 53 |
mov ebx, 3 |
mov ecx, socket |
mcall ; read byte - block (high byte) |
; Store the data in the response buffer |
mov eax, endptr |
mov [eax], bl |
inc dword endptr |
mov eax, 53 |
mov ebx, 2 |
mov ecx, socket |
mcall ; any more data? |
cmp eax, 0 |
jne @r ; yes, so get it |
@@: |
} |
; eth.wait_for_data [socket],60,abort |
; eth.read_data .... |
; abort: |
; |
; Waits for data with timeout |
macro eth.wait_for_data socket,TIMEOUT,abort { |
mov edx,TIMEOUT |
@@: |
eth.poll socket,eax |
cmp eax,0 |
jne @f |
dec edx |
jz abort |
if OS eq MEOS |
mov eax,5 ; wait here for event |
mov ebx,100 |
mcall |
else if OS eq DEX4U |
mov ax,18 |
call [SetDelay] |
call dword[stack_handler] |
end if |
jmp @r |
@@: |
} |
; The function 'resolve' resolves the address in edx and puts the resulting IP in eax. |
; When the input is an IP-adress, the function will output this IP in eax. |
; If something goes wrong, the result in eax should be 0 |
; |
; example: |
; |
; resolve query1,IP |
; resolve '192.168.0.1',IP |
; resolve query2,IP |
; |
; query1 db 'www.google.com',0 |
; query2 db '49.78.84.45',0 |
; IP dd ? |
macro resolve query,result { |
if query eqtype 0 |
mov edx,query |
else |
local ..string, ..label |
jmp ..label |
..string db query,0 |
..label: |
mov edx,..string |
end if |
call __resolve |
mov result,eax |
} |
if used __resolve |
__resolve: |
;DEBUGF 1,'Resolving started\n' |
; This code validates if the query is an IP containing 4 numbers and 3 dots |
push edx ; push edx (query address) onto stack |
xor al, al ; make al (dot count) zero |
@@: |
cmp byte[edx],'0' ; check if this byte is a number, if not jump to no_IP |
jl no_IP ; |
cmp byte[edx],'9' ; |
jg no_IP ; |
inc edx ; the byte was a number, so lets check the next byte |
cmp byte[edx],0 ; is this byte zero? (have we reached end of query?) |
jz @f ; jump to next @@ then |
cmp byte[edx],'.' ; is this byte a dot? |
jne @r ; if not, jump to previous @@ |
inc al ; the byte was a dot so increment al(dot count) |
inc edx ; next byte |
jmp @r ; lets check for numbers again (jump to previous @@) |
@@: ; we reach this when end of query reached |
cmp al,3 ; check if there where 3 dots |
jnz no_IP ; if not, jump to no_IP (this is where the DNS will take over) |
; The following code should convert this IP into a dword and output it in eax |
pop esi ; edx (query address) was pushed onto stack and is now popped in esi |
xor edx, edx ; result |
xor eax, eax ; current character |
xor ebx, ebx ; current byte |
.outer_loop: |
shl edx, 8 |
add edx, ebx |
xor ebx, ebx |
.inner_loop: |
lodsb |
test eax, eax |
jz .finish |
cmp al, '.' |
jz .outer_loop |
sub eax, '0' |
imul ebx, 10 |
add ebx, eax |
jmp .inner_loop |
.finish: |
shl edx, 8 |
add edx, ebx |
bswap edx |
mov eax, edx |
;DEBUGF 1,'The query was an IP: %x.%x.%x.%x\n',dh,dl,al,ah |
ret |
no_IP: |
pop edx |
; The query is not an IP address, we will send the query to a DNS server and hope for answer ;) |
;DEBUGF 1,'The query is no ip, Building request string from:%u\n',edx |
; Build the request string |
mov eax, 0x00010100 |
mov [dnsMsg], eax |
mov eax, 0x00000100 |
mov [dnsMsg+4], eax |
mov eax, 0x00000000 |
mov [dnsMsg+8], eax |
; domain name goes in at dnsMsg+12 |
mov esi, dnsMsg + 12 ; location of label length |
mov edi, dnsMsg + 13 ; label start |
mov ecx, 12 ; total string length so far |
td002: |
mov [esi], byte 0 |
inc ecx |
td0021: |
mov al, [edx] |
cmp al, 0 |
je td001 ; we have finished the string translation |
cmp al, '.' |
je td004 ; we have finished the label |
inc byte [esi] |
inc ecx |
mov [edi], al |
inc edi |
inc edx |
jmp td0021 |
td004: |
mov esi, edi |
inc edi |
inc edx |
jmp td002 |
; write label len + label text |
td001: |
mov [edi], byte 0 |
inc ecx |
inc edi |
mov [edi], dword 0x01000100 |
add ecx, 4 |
mov [dnsMsgLen], ecx ; We'll need the length of the message when we send it |
; Now, lets send this and wait for an answer |
eth.search_port 1024,edx ; Find a free port starting from 1025 and store in edx |
eth.get_DNS esi ; Read DNS IP from stack into esi |
eth.open edx,53,esi,[socketNum] ; First, open socket |
; DEBUGF 1,'Socket opened: %u (port %u)\n',[socketNum],ecx |
eth.write [socketNum],[dnsMsgLen],dnsMsg ; Write to socket ( request DNS lookup ) |
; DEBUGF 1,'Data written, length:%u offset:%u\n',[dnsMsgLen],dnsMsg |
; DEBUGF 1,'Waiting for data: (timeout is %us)\n',TIMEOUT |
eth.wait_for_data [socketNum],TIMEOUT,no_data; Now, we wait for data from remote |
eth.read_data [socketNum],dnsMsg,[dnsMsgLen],dnsMsg+BUFFER ; Read the data into the buffer |
; DEBUGF 1,'Data received, offset:%u buffer size:%u length:%u\n',dnsMsg,BUFFER,esi-dnsMsg |
eth.close [socketNum] ; We're done, close the socket |
; DEBUGF 1,'Closed Socket\n' |
; Now parse the message to get the host IP. Man, this is complicated. It's described in RFC 1035 |
; 1) Validate that we have an answer with > 0 responses |
; 2) Find the answer record with TYPE 0001 ( host IP ) |
; 3) Finally, copy the IP address to the display |
; Note: The response is in dnsMsg, the end of the buffer is pointed to by [dnsMsgLen] |
mov esi, dnsMsg |
mov al, [esi+2] ; Is this a response to my question? |
and al, 0x80 |
cmp al, 0x80 |
jne abort |
;DEBUGF 1,'It was a response to my question\n' |
mov al, [esi+3] ; Were there any errors? |
and al, 0x0F |
cmp al, 0x00 |
jne abort |
;DEBUGF 1,'There were no errorst\n' |
mov ax, [esi+6] ; Is there ( at least 1 ) answer? |
cmp ax, 0x00 |
je abort |
; Header validated. Scan through and get my answer |
add esi, 12 ; Skip to the question field |
call skipName ; Skip through the question field |
add esi, 4 ; skip past the questions qtype, qclass |
ctr002z: |
; Now at the answer. There may be several answers, find the right one ( TYPE = 0x0001 ) |
call skipName |
mov ax, [esi] |
cmp ax, 0x0100 ; Is this the IP address answer? |
jne ctr002c |
add esi, 10 ; Yes! Point eax to the first byte of the IP address |
mov eax,[esi] |
;DEBUGF 1,'Found First Byte of IP\n' |
ret |
ctr002c: ; Skip through the answer, move to the next |
add esi, 8 |
movzx eax, byte [esi+1] |
mov ah, [esi] |
add esi, eax |
add esi, 2 |
cmp esi, [dnsMsgLen] ; Have we reached the end of the msg? This is an error condition, should not happen |
jl ctr002z ; Check next answer |
abort: |
;DEBUGF 1,'Something went wrong, aborting\n' |
xor eax,eax |
ret |
skipName: |
; Increment esi to the first byte past the name field |
; Names may use compressed labels. Normally do. |
; RFC 1035 page 30 gives details |
mov al, [esi] |
cmp al, 0 |
je sn_exit |
and al, 0xc0 |
cmp al, 0xc0 |
je sn001 |
movzx eax, byte [esi] |
inc eax |
add esi, eax |
jmp skipName |
sn001: |
add esi, 2 ; A pointer is always at the end |
ret |
sn_exit: |
inc esi |
ret |
no_data: |
eth.close [socketNum] |
xor eax,eax |
ret |
dnsMsgLen: dd 0 |
socketNum: dd 0xFFFF |
if ~defined dnsMsg |
dnsMsg: rb BUFFER |
end if |
end if |
/programs/network/airc/trunk/fdo.inc |
---|
0,0 → 1,343 |
; |
; Formatted Debug Output (FDO) |
; Copyright (c) 2005-2006, mike.dld |
; Created: 2005-01-29, Changed: 2006-07-20 |
; |
; For questions and bug reports, mail to mike.dld@gmail.com |
; |
; Available format specifiers are: %s, %d, %u, %x (with partial width support) |
; |
; to be defined: |
; __DEBUG__ equ 1 |
; __DEBUG_LEVEL__ equ 5 |
macro debug_func name { |
if used name |
name@of@func equ name |
} |
macro debug_beginf { |
align 4 |
name@of@func: |
} |
debug_endf fix end if |
macro DEBUGS _sign,[_str] { |
common |
pushf |
pushad |
local ..str,..label,is_str |
is_str = 0 |
forward |
if _str eqtype '' |
is_str = 1 |
end if |
common |
if is_str = 1 |
jmp ..label |
..str db _str,0 |
..label: |
add esp,4*8+4 |
mov edx,..str |
sub esp,4*8+4 |
call fdo_debug_outstr |
else |
mov edx,_str |
call fdo_debug_outstr |
end if |
popad |
popf |
} |
macro DEBUGD _sign,_dec { |
pushf |
pushad |
if _dec eqtype eax |
if _dec in <ebx,ecx,edx,esi,edi,ebp,esp> |
mov eax,_dec |
else if ~_dec eq eax |
if _sign = 1 |
movsx eax,_dec |
else |
movzx eax,_dec |
end if |
end if |
else if _dec eqtype 0 |
mov eax,_dec |
else |
add esp,4*8+4 |
local tp |
tp equ 0 |
match _num[_arg],_dec \{ |
if _num = 1 |
if _sign = 1 |
movsx eax,byte[_arg] |
else |
movzx eax,byte[_arg] |
end if |
else if _num = 2 |
if _sign = 1 |
movsx eax,word[_arg] |
else |
movzx eax,word[_arg] |
end if |
else |
mov eax,dword[_arg] |
end if |
tp equ 1 |
\} |
match =0 [_arg],tp _dec \{ |
mov eax,dword[_arg] |
\} |
sub esp,4*8+4 |
end if |
mov cl,_sign |
call fdo_debug_outdec |
popad |
popf |
} |
macro DEBUGH _sign,_hex { |
pushf |
pushad |
if _hex eqtype eax |
if _hex in <eax,ebx,ecx,edx,esi,edi,ebp,esp> |
if ~_hex eq eax |
mov eax,_hex |
end if |
mov edx,8 |
else if _hex in <ax,bx,cx,dx,si,di,bp,sp> |
if ~_hex eq ax |
movzx eax,_hex |
end if |
shl eax,16 |
mov edx,4 |
else if _hex in <al,ah,bl,bh,cl,ch,dl,dh> |
if ~_hex eq al |
movzx eax,_hex |
end if |
shl eax,24 |
mov edx,2 |
end if |
else if _hex eqtype 0 |
mov eax,_hex |
mov edx,8 |
else |
add esp,4*8+4 |
local tp |
tp equ 0 |
match _num[_arg],_hex \{ |
mov eax,dword[_arg] |
mov edx,_num |
tp equ 1 |
\} |
match =0 [_arg],tp _hex \{ |
mov eax,dword[_arg] |
mov edx,8 |
\} |
sub esp,4*8+4 |
end if |
call fdo_debug_outhex |
popad |
popf |
} |
;----------------------------------------------------------------------------- |
debug_func fdo_debug_outchar |
debug_beginf |
pushad |
mov cl,al |
mov ebx,1 |
mov eax,63 |
mcall |
popad |
ret |
debug_endf |
debug_func fdo_debug_outstr |
debug_beginf |
mov eax,63 |
mov ebx,1 |
.l1: mov cl,[edx] |
or cl,cl |
jz .l2 |
mcall |
inc edx |
jmp .l1 |
.l2: ret |
debug_endf |
debug_func fdo_debug_outdec |
debug_beginf |
or cl,cl |
jz @f |
or eax,eax |
jns @f |
neg eax |
push eax |
mov al,'-' |
call fdo_debug_outchar |
pop eax |
@@: push 10 |
pop ecx |
push -'0' |
.l1: xor edx,edx |
div ecx |
push edx |
test eax,eax |
jnz .l1 |
.l2: pop eax |
add al,'0' |
jz .l3 |
call fdo_debug_outchar |
jmp .l2 |
.l3: ret |
debug_endf |
debug_func fdo_debug_outhex |
__fdo_hexdigits db '0123456789ABCDEF' |
debug_beginf |
mov cl,dl |
neg cl |
add cl,8 |
shl cl,2 |
rol eax,cl |
.l1: rol eax,4 |
push eax |
and eax,0x0000000F |
mov al,[__fdo_hexdigits+eax] |
call fdo_debug_outchar |
pop eax |
dec edx |
jnz .l1 |
ret |
debug_endf |
;----------------------------------------------------------------------------- |
macro DEBUGF _level,_format,[_arg] { |
common |
if __DEBUG__ = 1 & _level >= __DEBUG_LEVEL__ |
local ..f1,f2,a1,a2,c1,c2,c3,..lbl |
_debug_str_ equ __debug_str_ # a1 |
a1 = 0 |
c2 = 0 |
c3 = 0 |
f2 = 0 |
repeat ..lbl-..f1 |
virtual at 0 |
db _format,0,0 |
load c1 word from %-1 |
end virtual |
if c1 = '%s' |
virtual at 0 |
db _format,0,0 |
store word 0 at %-1 |
load c1 from f2-c2 |
end virtual |
if c1 <> 0 |
DEBUGS 0,_debug_str_+f2-c2 |
end if |
c2 = c2 + 1 |
f2 = %+1 |
DEBUGF_HELPER S,a1,0,_arg |
else if c1 = '%x' |
virtual at 0 |
db _format,0,0 |
store word 0 at %-1 |
load c1 from f2-c2 |
end virtual |
if c1 <> 0 |
DEBUGS 0,_debug_str_+f2-c2 |
end if |
c2 = c2 + 1 |
f2 = %+1 |
DEBUGF_HELPER H,a1,0,_arg |
else if c1 = '%d' | c1 = '%u' |
local c4 |
if c1 = '%d' |
c4 = 1 |
else |
c4 = 0 |
end if |
virtual at 0 |
db _format,0,0 |
store word 0 at %-1 |
load c1 from f2-c2 |
end virtual |
if c1 <> 0 |
DEBUGS 0,_debug_str_+f2-c2 |
end if |
c2 = c2 + 1 |
f2 = %+1 |
DEBUGF_HELPER D,a1,c4,_arg |
else if c1 = '\n' |
c3 = c3 + 1 |
end if |
end repeat |
virtual at 0 |
db _format,0,0 |
load c1 from f2-c2 |
end virtual |
if (c1<>0)&(f2<>..lbl-..f1-1) |
DEBUGS 0,_debug_str_+f2-c2 |
end if |
virtual at 0 |
..f1 db _format,0 |
..lbl: |
__debug_strings equ __debug_strings,_debug_str_,<_format>,..lbl-..f1-1-c2-c3 |
end virtual |
end if |
} |
macro __include_debug_strings dummy,[_id,_fmt,_len] { |
common |
local c1,a1,a2 |
forward |
if defined _len & ~_len eq |
_id: |
a1 = 0 |
a2 = 0 |
repeat _len |
virtual at 0 |
db _fmt,0,0 |
load c1 word from %+a2-1 |
end virtual |
if (c1='%s')|(c1='%x')|(c1='%d')|(c1='%u') |
db 0 |
a2 = a2 + 1 |
else if (c1='\n') |
dw $0A0D |
a1 = a1 + 1 |
a2 = a2 + 1 |
else |
db c1 and 0x0FF |
end if |
end repeat |
db 0 |
end if |
} |
macro DEBUGF_HELPER _letter,_num,_sign,[_arg] { |
common |
local num |
num = 0 |
forward |
if num = _num |
DEBUG#_letter _sign,_arg |
end if |
num = num+1 |
common |
_num = _num+1 |
} |
macro include_debug_strings { |
if __DEBUG__ = 1 |
match dbg_str,__debug_strings \{ |
__include_debug_strings dbg_str |
\} |
end if |
} |