T
T
Type Programmer2019-09-16 21:30:43
assembler
Type Programmer, 2019-09-16 21:30:43

Assembler WriteConsole not outputting text?

I was looking for an error for a long time, don’t think what I wrote here right away)
I checked it through the debugger, it receives data on the socket, all the parameters seem to fit, and I use exactly the same way to display text in the server, but it works there ...
PS: That's all the time some problems with this WriteConsole already tired)...

Format PE GUI 4.0
include "win32ax.inc"

proc Thread_Receiv arg1
.p0:
invoke ReadConsole,[STDI],buff_send,4096,lenght,0
mov eax,0
mov ax,[lenght]
invoke send,[socket_client],buff_send,eax,0
jmp .p0
ret
endp

connect_socket:
invoke WSAStartup,0202h,WSA
cmp eax,00
jz .p0
invoke WriteConsole,[STDO],err3,19,0,0
jmp $
.p0:
invoke socket,2,1,0
cmp eax,-1
jnz .p1
invoke WriteConsole,[STDO],err1,22,0,0
jmp $
.p1:
mov [socket_client],eax
invoke connect,eax,addr,sizeof.sockaddr_in
cmp eax,0
jnz error
ret

input_output:
invoke WriteConsole,[STDO],mes1,51,0,0
invoke ReadConsole,[STDI],buff,255,lenght,0
xor ebx,ebx
mov bx,[lenght]
add ebx,buff
mov byte [ebx-1],0
mov byte [ebx-2],0
invoke inet_addr,buff
mov [addr.sin_addr.ip],eax
ret

error:
invoke WriteConsole,[STDO],err2,33,0,0
jmp $

start:
invoke AllocConsole
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov [STDO],eax
invoke GetStdHandle,STD_INPUT_HANDLE
mov [STDI],eax
call input_output
call connect_socket
invoke CreateThread,0,0,Thread_Receiv,0,0,thread
.p01:
invoke recv,[socket_client],buffer,4096,0
push 0
push 0
push eax
push buffer
push [STDO]
mov eax,0
call [WriteConsoleA]                                         
;; invoke WriteConsoleA,[STDO],buffer,eax,0,0 ;; ВОТ ТУТ НЕ РАБОТАЕТ сверху эта же функция только без invoke
jmp .p01
.end start


mes1 db '                        TCP-Client by ASMcoder',10,13,'IP:'
mes2 db 'Port:'
err1 db 'Create socket error!',10,13
err2 db 'Connect socket error!',10,13
err3 db 'WSAStartup error!',10,13


struc WSAdata
{
.wVersion       dw ?
.wHighVersion   dw ?
.szDescriotion  db 257 dup (?)
.szSystemStatus db 129 dup (?)
.iMaxSockets    dw ?
.iMaxUdpDg      dw ?
.lpVendorInfo   dd ?
}

struc sockaddr_in
{
.sin_family dw 2
.sin_port   dw 1300
.sin_addr   IP
.sin_zero   db 8 dup (?)
}

struc IP
{
.ip:
.a_b1 db ?
.a_b2 db ?
.a_b3 db ?
.a_b4 db ?
}

socket_client dd 0
thread db 0
lenght dw 0
STDO  dd 0
STDI  dd 0
addr  sockaddr_in
WSA   WSAdata
null dd 0

buff db 512 dup(0)
buff_send db 4096 dup(0)
buffer db 4096 dup(0)

Also, I don’t know, maybe the server will be useful :
Format PE GUI 4.0
include "win32ax.inc"

proc Thread_Receiv arg1
.p0:
invoke ReadConsole,[STDI],buff_send,4096,lenght,0
invoke send,[socket_client],buff_send,eax,0
jmp .p0
ret
endp

connect_socket:
invoke WSAStartup,0202h,WSA
cmp eax,00
jz .p0
invoke WriteConsole,[STDO],err3,19,0,0
jmp $
.p0:
invoke socket,2,1,0
cmp eax,-1
jnz .p1
invoke WriteConsole,[STDO],err1,22,0,0
jmp $
.p1:
mov [socket_server],eax
invoke bind,[socket_server],addr,sizeof.sockaddr_in
invoke listen,[socket_server],5
mov eax,sizeof.sockaddr_in
mov [lenght_addr],eax
invoke accept,[socket_server],addr_client,lenght_addr
mov [socket_client],eax
invoke WriteConsole,[STDO],mes1,19,0,0
ret

error:
invoke WriteConsole,[STDO],err2,33,0,0
jmp $

start:
invoke AllocConsole
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov [STDO],eax
invoke GetStdHandle,STD_INPUT_HANDLE
mov [STDI],eax
call connect_socket
invoke CreateThread,0,0,Thread_Receiv,0,0,thread
.p01:
invoke recv,[socket_client],buffer,4096,0
push 0
push 0
push eax
push buffer
push [STDO]
mov eax,0
call [WriteConsoleA]
jmp .p01
.end start

mes1 db 'Client connected!',10,13
err1 db 'Create socket error!',10,13
err2 db 'Connect socket error!',10,13
err3 db 'WSAStartup error!',10,13


struc WSAdata
{
.wVersion       dw ?
.wHighVersion   dw ?
.szDescriotion  db 257 dup (?)
.szSystemStatus db 129 dup (?)
.iMaxSockets    dw ?
.iMaxUdpDg      dw ?
.lpVendorInfo   dd ?
}

struc sockaddr_in
{
.sin_family dw 2
.sin_port   dw 1300
.sin_addr   IP
.sin_zero   db 8 dup (?)
}

struc IP
{
.ip:
.a_b1 db ?
.a_b2 db ?
.a_b3 db ?
.a_b4 db ?
}

socket_client dd 0
socket_server dd 0
thread db 0
lenght dw 0
lenght_addr dd 0
STDO  dd 0
STDI  dd 0
addr  sockaddr_in
addr_client sockaddr_in
WSA   WSAdata

buff db 512 dup(0)
buff_send db 4096 dup(0)
buffer db 4096 dup(0)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2019-09-16
@MegaCraZy6

WriteConsole not outputting text

What does it return? What about GetLastError? And what about buffer and eax before calling WriteConsole?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question