Hi ich suche eine möglichkeit C++ code in ASM umzuwandeln?
(nicht mit Virsual Studio)
Zum compielen benutze ich gcc.
mfg Dark Snake
(nicht mit Virsual Studio)
Zum compielen benutze ich gcc.
mfg Dark Snake
Zuletzt bearbeitet:
Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
#include <windows.h>
#include <winsock2.h>
#include <stdio.h>
//Prototypen
int startWinsock(void);
int main()
{
long rc;
SOCKET s;
SOCKADDR_IN addr;
char buf[256];
// Winsock starten
rc=startWinsock();
if(rc!=0)
{
printf("Fehler: startWinsock, fehler code: %d\n",rc);
return 1;
}
else
{
printf("Winsock gestartet!\n");
}
// Socket erstellen
s=socket(AF_INET,SOCK_STREAM,0);
if(s==INVALID_SOCKET)
{
printf("Fehler: Der Socket konnte nicht erstellt werden, fehler code: %d\n",WSAGetLastError());
return 1;
}
else
{
printf("Socket erstellt!\n");
}
// Verbinden
memset(&addr,0,sizeof(SOCKADDR_IN)); // zuerst alles auf 0 setzten
addr.sin_family=AF_INET;
addr.sin_port=htons(12345); // wir verwenden mal port 12345
addr.sin_addr.s_addr=inet_addr("127.0.0.1"); // zielrechner ist unser eigener
rc=connect(s,(SOCKADDR*)&addr,sizeof(SOCKADDR));
if(rc==SOCKET_ERROR)
{
printf("Fehler: connect gescheitert, fehler code: %d\n",WSAGetLastError());
return 1;
}
else
{
printf("Verbunden mit 127.0.0.1..\n");
}
while(rc!=SOCKET_ERROR)
{
rc=recv(s,buf,256,0);
if(rc==0)
{
printf("Server hat die Verbindung getrennt..\n");
break;
}
if(rc==SOCKET_ERROR)
{
printf("Fehler: recv, fehler code: %d\n",WSAGetLastError());
break;
}
buf[rc]='\0';
printf("\nServer antwortet: %s\n",buf);
}
closesocket(s);
WSACleanup();
return 0;
}
int startWinsock(void)
{
WSADATA wsa;
return WSAStartup(MAKEWORD(2,0),&wsa);
}
C++ to ASM:.file "main.cpp"
.intel_syntax
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
.align 4
LC0:
.ascii "Fehler: startWinsock, fehler code: %d\12\0"
LC1:
.ascii "Winsock gestartet!\12\0"
.align 4
LC2:
.ascii "Fehler: Der Socket konnte nicht erstellt werden, fehler code: %d\12\0"
LC3:
.ascii "Socket erstellt!\12\0"
LC4:
.ascii "127.0.0.1\0"
.align 4
LC5:
.ascii "Fehler: connect gescheitert, fehler code: %d\12\0"
LC6:
.ascii "Verbunden mit 127.0.0.1..\12\0"
.align 4
LC7:
.ascii "Server hat die Verbindung getrennt..\12\0"
.align 4
LC8:
.ascii "Fehler: recv, fehler code: %d\12\0"
LC9:
.ascii "\12Server antwortet: %s\12\0"
.text
.align 2
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
push ebp
mov ebp, esp
sub esp, 344
and esp, -16
mov eax, 0
add eax, 15
add eax, 15
shr eax, 4
sal eax, 4
mov DWORD PTR [ebp-316], eax
mov eax, DWORD PTR [ebp-316]
call __alloca
call ___main
call __Z12startWinsockv
mov DWORD PTR [ebp-12], eax
cmp DWORD PTR [ebp-12], 0
je L2
mov eax, DWORD PTR [ebp-12]
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], OFFSET FLAT:LC0
call _printf
mov DWORD PTR [ebp-300], 1
jmp L1
L2:
mov DWORD PTR [esp], OFFSET FLAT:LC1
call _printf
mov DWORD PTR [esp+8], 0
mov DWORD PTR [esp+4], 1
mov DWORD PTR [esp], 2
call _socket@12
sub esp, 12
mov DWORD PTR [ebp-16], eax
cmp DWORD PTR [ebp-16], -1
jne L4
call _WSAGetLastError@0
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], OFFSET FLAT:LC2
call _printf
mov DWORD PTR [ebp-300], 1
jmp L1
L4:
mov DWORD PTR [esp], OFFSET FLAT:LC3
call _printf
mov DWORD PTR [esp+8], 16
mov DWORD PTR [esp+4], 0
lea eax, [ebp-40]
mov DWORD PTR [esp], eax
call _memset
mov WORD PTR [ebp-40], 2
mov DWORD PTR [esp], 12345
call _htons@4
sub esp, 4
mov WORD PTR [ebp-38], ax
mov DWORD PTR [esp], OFFSET FLAT:LC4
call _inet_addr@4
sub esp, 4
mov DWORD PTR [ebp-36], eax
mov DWORD PTR [esp+8], 16
lea eax, [ebp-40]
mov DWORD PTR [esp+4], eax
mov eax, DWORD PTR [ebp-16]
mov DWORD PTR [esp], eax
call _connect@12
sub esp, 12
mov DWORD PTR [ebp-12], eax
cmp DWORD PTR [ebp-12], -1
jne L6
call _WSAGetLastError@0
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], OFFSET FLAT:LC5
call _printf
mov DWORD PTR [ebp-300], 1
jmp L1
L6:
mov DWORD PTR [esp], OFFSET FLAT:LC6
call _printf
L8:
cmp DWORD PTR [ebp-12], -1
je L9
mov DWORD PTR [esp+12], 0
mov DWORD PTR [esp+8], 256
lea eax, [ebp-296]
mov DWORD PTR [esp+4], eax
mov eax, DWORD PTR [ebp-16]
mov DWORD PTR [esp], eax
call _recv@16
sub esp, 16
mov DWORD PTR [ebp-12], eax
cmp DWORD PTR [ebp-12], 0
jne L10
mov DWORD PTR [esp], OFFSET FLAT:LC7
call _printf
jmp L9
L10:
cmp DWORD PTR [ebp-12], -1
jne L11
call _WSAGetLastError@0
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], OFFSET FLAT:LC8
call _printf
jmp L9
L11:
lea eax, [ebp-8]
add eax, DWORD PTR [ebp-12]
sub eax, 288
mov BYTE PTR [eax], 0
lea eax, [ebp-296]
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], OFFSET FLAT:LC9
call _printf
jmp L8
L9:
mov eax, DWORD PTR [ebp-16]
mov DWORD PTR [esp], eax
call _closesocket@4
sub esp, 4
call _WSACleanup@0
mov DWORD PTR [ebp-300], 0
L1:
mov eax, DWORD PTR [ebp-300]
leave
ret
.align 2
.globl __Z12startWinsockv
.def __Z12startWinsockv; .scl 2; .type 32; .endef
__Z12startWinsockv:
push ebp
mov ebp, esp
sub esp, 424
lea eax, [ebp-408]
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], 2
call _WSAStartup@8
sub esp, 8
leave
ret
.def _WSAStartup@8; .scl 2; .type 32; .endef
.def _WSACleanup@0; .scl 2; .type 32; .endef
.def _closesocket@4; .scl 2; .type 32; .endef
.def _recv@16; .scl 2; .type 32; .endef
.def _connect@12; .scl 2; .type 32; .endef
.def _inet_addr@4; .scl 2; .type 32; .endef
.def _htons@4; .scl 2; .type 32; .endef
.def _memset; .scl 2; .type 32; .endef
.def _WSAGetLastError@0; .scl 2; .type 32; .endef
.def _socket@12; .scl 2; .type 32; .endef
.def _printf; .scl 2; .type 32; .endef
g++ -S -masm=intel -O0 main.cpp -lws2_32
g++ main.s -lws2_32
g++ -lws2_32 -Wamsyntax=intel -Wammnemonic=intel main.s
.file "main.cpp"
.intel_syntax
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
.align 4
LC0:
.ascii "Fehler: startWinsock, fehler code: %d\12\0"
LC1:
.ascii "Winsock gestartet!\12\0"
.align 4
LC2:
.ascii "Fehler: Der Socket konnte nicht erstellt werden, fehler code: %d\12\0"
LC3:
.ascii "Socket erstellt!\12\0"
LC4:
.ascii "127.0.0.1\0"
.align 4
LC5:
.ascii "Fehler: connect gescheitert, fehler code: %d\12\0"
LC6:
.ascii "Verbunden mit 127.0.0.1..\12\0"
.align 4
LC7:
.ascii "Server hat die Verbindung getrennt..\12\0"
.align 4
LC8:
.ascii "Fehler: recv, fehler code: %d\12\0"
LC9:
.ascii "\12Server antwortet: %s\12\0"
.text
.align 2
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
push ebp
mov ebp, esp
sub esp, 344
and esp, -16
mov eax, 0
add eax, 15
add eax, 15
shr eax, 4
sal eax, 4
mov DWORD PTR [ebp-316], eax
mov eax, DWORD PTR [ebp-316]
call __alloca
call ___main
call __Z12startWinsockv
mov DWORD PTR [ebp-12], eax
cmp DWORD PTR [ebp-12], 0
je L2
mov eax, DWORD PTR [ebp-12]
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], OFFSET FLAT:LC0
call _printf
mov DWORD PTR [ebp-300], 1
jmp L1
L2:
mov DWORD PTR [esp], OFFSET FLAT:LC1
call _printf
mov DWORD PTR [esp+8], 0
mov DWORD PTR [esp+4], 1
mov DWORD PTR [esp], 2
call _socket@12
sub esp, 12
mov DWORD PTR [ebp-16], eax
cmp DWORD PTR [ebp-16], -1
jne L4
call _WSAGetLastError@0
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], OFFSET FLAT:LC2
call _printf
mov DWORD PTR [ebp-300], 1
jmp L1
L4:
mov DWORD PTR [esp], OFFSET FLAT:LC3
call _printf
mov DWORD PTR [esp+8], 16
mov DWORD PTR [esp+4], 0
lea eax, [ebp-40]
mov DWORD PTR [esp], eax
call _memset
mov WORD PTR [ebp-40], 2
mov DWORD PTR [esp], 12345
call _htons@4
sub esp, 4
mov WORD PTR [ebp-38], ax
mov DWORD PTR [esp], OFFSET FLAT:LC4
call _inet_addr@4
sub esp, 4
mov DWORD PTR [ebp-36], eax
mov DWORD PTR [esp+8], 16
lea eax, [ebp-40]
mov DWORD PTR [esp+4], eax
mov eax, DWORD PTR [ebp-16]
mov DWORD PTR [esp], eax
call _connect@12
sub esp, 12
mov DWORD PTR [ebp-12], eax
cmp DWORD PTR [ebp-12], -1
jne L6
call _WSAGetLastError@0
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], OFFSET FLAT:LC5
call _printf
mov DWORD PTR [ebp-300], 1
jmp L1
L6:
mov DWORD PTR [esp], OFFSET FLAT:LC6
call _printf
L8:
cmp DWORD PTR [ebp-12], -1
je L9
mov DWORD PTR [esp+12], 0
mov DWORD PTR [esp+8], 256
lea eax, [ebp-296]
mov DWORD PTR [esp+4], eax
mov eax, DWORD PTR [ebp-16]
mov DWORD PTR [esp], eax
call _recv@16
sub esp, 16
mov DWORD PTR [ebp-12], eax
cmp DWORD PTR [ebp-12], 0
jne L10
mov DWORD PTR [esp], OFFSET FLAT:LC7
call _printf
jmp L9
L10:
cmp DWORD PTR [ebp-12], -1
jne L11
call _WSAGetLastError@0
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], OFFSET FLAT:LC8
call _printf
jmp L9
L11:
lea eax, [ebp-8]
add eax, DWORD PTR [ebp-12]
sub eax, 288
mov BYTE PTR [eax], 0
lea eax, [ebp-296]
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], OFFSET FLAT:LC9
call _printf
jmp L8
L9:
mov eax, DWORD PTR [ebp-16]
mov DWORD PTR [esp], eax
call _closesocket@4
sub esp, 4
call _WSACleanup@0
mov DWORD PTR [ebp-300], 0
L1:
mov eax, DWORD PTR [ebp-300]
leave
ret
.align 2
.globl __Z12startWinsockv
.def __Z12startWinsockv; .scl 2; .type 32; .endef
__Z12startWinsockv:
push ebp
mov ebp, esp
sub esp, 424
lea eax, [ebp-408]
mov DWORD PTR [esp+4], eax
mov DWORD PTR [esp], 2
call _WSAStartup@8
sub esp, 8
leave
ret
.def _WSAStartup@8; .scl 2; .type 32; .endef
.def _WSACleanup@0; .scl 2; .type 32; .endef
.def _closesocket@4; .scl 2; .type 32; .endef
.def _recv@16; .scl 2; .type 32; .endef
.def _connect@12; .scl 2; .type 32; .endef
.def _inet_addr@4; .scl 2; .type 32; .endef
.def _htons@4; .scl 2; .type 32; .endef
.def _memset; .scl 2; .type 32; .endef
.def _WSAGetLastError@0; .scl 2; .type 32; .endef
.def _socket@12; .scl 2; .type 32; .endef
.def _printf; .scl 2; .type 32; .endef
Ich meine das auch irgendwo gelesen zu haben (Mailing/Bugliste), finde die Referenz allerdings auf Anhieb nicht wieder.Kann theoretisch aber auch sein, dass das ganze ein Bug vom GNU ASM ist, da ja der g++ intern mit AT&T arbeitet.
Naja, MS VC++ compiler sollten mit /FA Option auch Asm Code ausgeben.gibt es eine alternative, einen anderen Compieler für Windows