- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个 c++ 代码来读取网页的源代码。
#include "stdafx.h"
#include <winsock2.h>
#include <windows.h>
#include <iostream>
#include <fstream>
#pragma comment(lib,"ws2_32.lib")
using namespace std;
int main(){
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
cout << "WSAStartup failed.\n";
system("pause");
return 1;
}
SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
struct hostent *host;
host = gethostbyname("www.last.fm");
SOCKADDR_IN SockAddr;
SockAddr.sin_port = htons(80);
SockAddr.sin_family = AF_INET;
SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
cout << "Connecting...\n";
if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0){
cout << "Could not connect";
system("pause");
return 1;
}
cout << "Connected.\n";
send(Socket, "GET /music/Taylor+swift/+albums?order=reach&page=1 HTTP/1.1\r\nHost: www.last.fm\r\nConnection: close\r\n\r\n", strlen("GET /music/taylor+swift/+albums?order=reach&page=1 HTTP/1.1\r\nHost: www.cplusplus.com\r\nConnection: close\r\n\r\n"), 0);
char buffer[10000];
int nDataLength;
while ((nDataLength = recv(Socket, buffer, 10000, 0)) > 0){
int i = 0;
while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r') {
cout << buffer[i];
i += 1;
}
}
closesocket(Socket);
WSACleanup();
system("pause");
return 0;
}
我试图将其转换为 fasm 程序集,但没有成功。有人可以帮我把它转换成汇编吗?谢谢(请注意,我以前从未在 asm 中使用过套接字,所以我不确定这段代码是否接近,我认为它连接了,但它给出了一个空白的消息框而不是网页源代码)
format PE GUI 4.0
entry start
include '\Fasm\INCLUDE\win32ax.inc'
section '.data' data readable writeable
IPPROTO_TCP = 6
wsadata WSADATA
_caption db 'Client application',0
_igang db 'The client has started very well.',13,10,'It is now going to connect to your own computer',0
_hostname db 'Wrong hostname',0
hostname db 'www.lastfm.com',0
hSock dd ?
saddr sockaddr_in
sizesaddr = $-saddr
buffer rb 0x3000
sender db 'GET /music/Taylor+swift/+albums?order=reach&page=1 HTTP/1.1\r\nHost: www.last.fm\r\nConnection: close\r\n\r\n',13,10
rb 0x100
section '.code' code readable executable
start:
invoke WSAStartup,0101h,wsadata ; initialiserer winsock-bibliotek
invoke ws_gethostbyname,hostname
or eax,eax
jz bad_hostname
virtual at eax
.host hostent
end virtual
mov eax,[.host.h_addr_list]
mov eax,[eax]
mov eax,[eax]
mov [saddr.sin_addr],eax
invoke MessageBox,0,_igang,_caption,0
mov al,00
mov ah,80 ; port 80
mov [saddr.sin_port],ax
mov [saddr.sin_family],AF_INET
invoke ws_socket, AF_INET, SOCK_STREAM, IPPROTO_TCP
mov [hSock], eax
xchg eax, esi
invoke ws_connect, esi, saddr, sizesaddr
.if eax = 0
invoke MessageBox,0, "connected", _caption,0
.endif
.if eax <> 0
invoke MessageBox,0, "not connected", _caption,0
.endif
mov ebx, buffer
invoke ws_send,esi,sender,109,0
invoke ws_recv, esi, ebx, 1000, 0
invoke MessageBox,0, buffer, _caption,0
.connectSucceeded:
invoke ws_closesocket,esi
invoke WSACleanup
jmp stopp
bad_hostname:
invoke MessageBox,0,_hostname,_caption,0
jmp stopp
stopp:
invoke ExitProcess,0
section '.idata' import data readable writeable
library kernel,'KERNEL32.DLL',\
winsock,'WSOCK32.DLL',\
user,'USER32.DLL'
import kernel,\
ExitProcess,'ExitProcess'
import winsock,\
WSAStartup,'WSAStartup',\
ws_socket,'socket',\
ws_connect,'connect',\
ws_gethostbyname,'gethostbyname',\
ws_send,'send',\
ws_recv,'recv',\
ws_closesocket,'closesocket',\
WSACleanup,'WSACleanup'
import user,\
MessageBox,'MessageBoxA'
最佳答案
这是我的 inet 函数,也许会对你有所帮助。
push cookie
push post
push url
push buffer
call connectHTTP
结果放在缓冲区中。功能未优化,但运行稳定。
; ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~
;
; inet.asm
;
; HFT -> inet functions
;
; Copyright (C) 2013 Ilya M. Chirkunov (cheebeez@yandex.ru)
;
; - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ - ~ -
format ELF
include 'cdecl.inc'
public connectHTTP
extrn gethostbyname
extrn socket
extrn htons
extrn connect
extrn send
extrn recv
extrn close
extrn strcpy2
extrn strcat2
extrn strpos
extrn strlen2
extrn hex2decascii
extrn push_ad
extrn pop_ad
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; С Е К Ц И Я К О Д А
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
section '.text' executable
; ------------------------------------- HTTP запрос
proc connectHTTP
call push_ad
pop eax ; сохраняем адрес возврата
pop edi esi ecx edx ; edi - buffer, esi - url, ecx - post, edx - cookie
push eax ; восстанавливаем адрес возврата
; (составляем запрос)
sub esp,10000
mov ebx,esp ; в ebx будем собирать запрос
cmp dword[esi],"http"
jne _not_http
add esi,7 ; убираем "http://"
_not_http:
push szPOST
push ebx
call strcpy2 ; "POST "
cmp ecx,0
jnz _is_post
push szGET
push ebx
call strcpy2 ; "GET "
_is_post:
push szSlash
push ebx
call strcat2 ; "GET /"
push esi
push edi
call strcpy2 ; копируем url в буффер
push szSlash
push edi
call strpos ; ищем URI
cmp eax,-1
je _only_host
mov byte[edi+eax],0 ; в edi - host
add esi,eax ; в esi - uri
inc esi
push esi
push ebx
call strcat2 ; "GET /full_uri HTTP/1.0"
_only_host:
push szHTTP10
push ebx
call strcat2 ; "GET / HTTP/1.0"
push szDA
push ebx
call strcat2 ; "GET / HTTP/1.0",0xD,0xA
push szHost
push ebx
call strcat2 ; "GET / HTTP/1.0",0xD,0xA,"Host: "
push edi
push ebx
call strcat2 ; "GET / HTTP/1.0",0xD,0xA,"Host: sphost.org"
push szDA
push ebx
call strcat2 ; "GET / HTTP/1.0",0xD,0xA,"Host: sphost.org",0xD,0xA
cmp ecx,0
jz _finish_query_string
push szContType
push ebx
call strcat2 ; "POST / HTTP/1.0",0xD,0xA,"Host: sphost.org",0xD,0xA,"Content-Type: application/x-www-form-urlencoded"
push szDA
push ebx
call strcat2 ; "POST / HTTP/1.0",0xD,0xA,"Host: sphost.org",0xD,0xA,"Content-Type: application/x-www-form-urlencoded",0xD,0xA
push szLength
push ebx
call strcat2 ; "POST / HTTP/1.0",0xD,0xA,"Host: sphost.org",0xD,0xA,"Content-Length: "
push ecx
call strlen2
push eax
push szSize
call hex2decascii
push szSize
push ebx
call strcat2 ; "POST / HTTP/1.0",0xD,0xA,"Host: sphost.org",0xD,0xA,"Content-Length: 64"
push szDA
push ebx
call strcat2 ; "POST / HTTP/1.0",0xD,0xA,"Host: sphost.org",0xD,0xA,"Content-Length: 64",0xD,0xA
push szDA
push ebx
call strcat2 ; "POST / HTTP/1.0",0xD,0xA,"Host: sphost.org",0xD,0xA,"Content-Length: 64",0xD,0xA,0xD,0xA
push ecx
push ebx
call strcat2 ; "POST / HTTP/1.0",0xD,0xA,"Host: sphost.org",0xD,0xA,"Content-Length: 64",0xD,0xA,0xD,0xA,"post"
push szDA
push ebx
call strcat2 ; "POST / HTTP/1.0",0xD,0xA,"Host: sphost.org",0xD,0xA,"Content-Length: 64",0xD,0xA,0xD,0xA,"post",0xD,0xA
_finish_query_string:
push szDA
push ebx
call strcat2 ; "GET / HTTP/1.0",0xD,0xA,"Host: sphost.org",0xD,0xA,0xD,0xA
; (отправляем запрос)
ccall gethostbyname, edi
;cmp eax,0
;jz _ret_conHTTP
mov eax,[eax+16]
mov eax,[eax]
mov eax,[eax]
mov dword[sin_addr],eax
ccall socket, 2, 1, 6 ; AF_INET, SOCK_STREAM, IPPROTO_TCP
;cmp eax, -1
;je _ret_conHTTP
mov dword[sockfd],eax
ccall htons, 80
mov word[sin_port],ax
mov word[sin_family],2
ccall connect, dword[sockfd], sin_family, 16
;cmp eax,0
;jnz _ret_conHTTP
push ebx
call strlen2
ccall send, dword[sockfd], ebx, eax, 0
add esp,10000
; (получаем ответ)
_getURL_recv:
ccall recv, dword[sockfd], edi, 1024, 0
add edi,eax
cmp eax,0
jnz _getURL_recv
mov byte[edi],0
ccall close,dword[sockfd]
_ret_conHTTP:
call pop_ad
ret
endp
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; С Е К Ц И Я Д А Н Н Ы Х
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
section '.data' writeable
szGET db "GET ", 0
szPOST db "POST ", 0
szSlash db "/",0
szHTTP10 db " HTTP/1.0",0
szDA db 0xD,0xA,0
szHost db "Host: ", 0
szContType db "Content-Type: application/x-www-form-urlencoded",0
szLength db "Content-Length: ", 0
szSize db 12 dup (0)
sockfd dd 0
; sockaddr_in db 16 dup (0)
sin_family db 2 dup (0)
sin_port db 2 dup (0)
sin_addr db 4 dup (0)
sin_zero db 8 dup (0)
关于c++ - 读取 fasm 或 nasm 网页的源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23848734/
我想使用Fasm使用简单的MsgBox编译x64应用程序。我已经编写了代码,它可以成功编译,但是当我运行它时,没有显示任何内容,并且程序刚刚结束。怎么了? format PE64 GUI 4.0 en
所以我正在阅读有关如何创建结构的手册。 起初,我是这样做的: struc point X, Y { .X dw X .Y dw Y } section '.code' code reada
“消息” block 和它的输出有问题(print_less、print_more、print_equal、print_final)。我真的不知道如何存储字符串,所以这就是为什么我在输出中获取所有字符
这是我在 FASM 中使用的代码: format PE console entry main include '..\MACRO\import32.inc' section '.data' data
我对这一件事真的很困惑。我正在阅读 x86 处理器的程序集编程一书,并且正在阅读有关 mov 指令及其工作原理的信息。所以,作者说下面的指令是有效的mov mem,reg .....基本上将寄存器值移
我正在用 FASM 汇编程序编写程序,想看看所有宏展开后生成的代码是什么。通常可以使用 objdump -d 来反汇编二进制文件,但是对于由 fasm 生成的二进制文件,它只输出以下内容: $ cat
bios 中断函数 21h (ah = 1h) 应该从标准输入中读取一个字符并回显它。 我的阅读功能: mov ah, 1h int 21h 所以,如果我按下一个键,它会意识到这一点,
如何将参数传递给 Assembly 中的函数?我确实推送了最后一个参数,推送了第二个参数,推送了第一个参数.. 但是我无法访问 Meh 函数中的参数..我正在做的事情使程序崩溃了.. format P
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
使用 FASM 我正在尝试使用 SHR 指令移动双字,该指令应该将位移动到右附加零。这是代码: format ELF executable 3 entry start segment readab
维基百科指出: High-level assemblers in computing are assemblers for assembly language that incorporate fea
我有一个使用以下代码在 Delphi XE2 中编码的 dll: procedure xMain(MSG:String);export; begin MessageBox(0,PWideChar(
我已经完成了ARM汇编编程,并且想学习Intel Assembler。我一直听到所有提到的所有这些F / M / N / ASM,但是我不确定它们与我希望达到的目标之间有何关系? 有人可以帮我确定我需
我尝试在 FASM 中编译以下代码: mov DWORD PTR [ebp - 4], 1234567 它给了我一个“无效表达式”错误。但是以下代码有效: mov DWORD [ebp - 4],
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
只是想知道是否有一种方法可以将数字打印到控制台通过调用。它可以是 10 进制,也可以是十六进制,我不介意。 我想看看一些函数返回的格式。 我宁愿不使用 WriteConsole 和大量 asm 来做这
这个问题在这里已经有了答案: What are the calling conventions for UNIX & Linux system calls (and user-space funct
Flat Assembler 中的 win32a、win32ax、win32axp、win32w、win32wx 和 win32wxp .inc 文件有什么区别?我试图在 FASM 文档中找到它,但找
我想将寄存器 si 中存储的用户输入与另一个字符串进行比较。 顺便说一句,我正在使用 FASM。这是用户输入后到目前为止我的代码。 如果我使用 repe cmpsb 命令,我知道我必须使用额外的段,但
有谁知道如何添加FASM支持CMake?我试过原始指南 here ,但这对我不起作用。 最佳答案 因此,我设法添加了三个文件,如 here 所述在我的 CMake\share\cmake-3.7\Mo
我是一名优秀的程序员,十分优秀!