Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 为什么这个masm汇编代码不能在循环中工作,代码第一次就可以完美地工作,但在循环中却不能工作_Windows_Assembly_Masm_Masm32 - Fatal编程技术网

Windows 为什么这个masm汇编代码不能在循环中工作,代码第一次就可以完美地工作,但在循环中却不能工作

Windows 为什么这个masm汇编代码不能在循环中工作,代码第一次就可以完美地工作,但在循环中却不能工作,windows,assembly,masm,masm32,Windows,Assembly,Masm,Masm32,嘿,我已经使用masm两周了,我正在尝试逐行读取一个文本文件,其中包含文件路径 example of text file C:\a.rar C:\a.txt C:\a.png 然后我想读入文件路径的全部内容,并得到文件路径的md5校验和 下面的代码第一次完美地工作(第一个消息框是文件路径,第二个是文件内容,第三个是md5校验和) 但在第一个循环之后,它读取第二个文件路径,但无法读取第二个文件的内容,然后崩溃,因为它与md5校验和无关 这一定是一个很容易的错误,不重置或不关闭的东西,但我已经花了

嘿,我已经使用masm两周了,我正在尝试逐行读取一个文本文件,其中包含文件路径

example of text file
C:\a.rar
C:\a.txt
C:\a.png
然后我想读入文件路径的全部内容,并得到文件路径的md5校验和

下面的代码第一次完美地工作(第一个消息框是文件路径,第二个是文件内容,第三个是md5校验和)

但在第一个循环之后,它读取第二个文件路径,但无法读取第二个文件的内容,然后崩溃,因为它与md5校验和无关

这一定是一个很容易的错误,不重置或不关闭的东西,但我已经花了大约20个小时在这方面,不能让它工作

例如,下面的代码在一个按钮中,当您按下按钮时,这就是它应该执行的操作

message box C:\a.rar
message box "contents of file"
message box 44644af7515bc4870d44fa688684798
message box C:\a.txt
message box "contents of file"
message box 6057f13c496ecf7fd777ceb9e79ae285
message box C:\a.png
message box "contents of file"
message box 01654ab48d84f484z446ba48453cb48
但事实就是这样

message box C:\a.rar
message box "contents of file"
message box 44644af7515bc4870d44fa688684798
message box C:\a.txt
blank contents cant read the contents of the file on loop (this is the problem)
message box blank because it cant md5 no contents
撞车

有人能帮忙吗

LOCAL Buffer3  :DWORD

invoke CreateFile, ADDR filestoscan, GENERIC_READ, 0, 0,OPEN_EXISTING, 0, 0
mov hFile, eax

invoke GetFileSize,hFile,NULL
mov Byteforstreamreader,eax
streamreader2:
.if Byteforstreamreader != 0
invoke ReadFile, hFile, ADDR Buffer2,1, ADDR BytesWritten, 0
.if Buffer2 == 13







invoke CreateFile, ADDR StringBuffer, GENERIC_READ, 0, 0,OPEN_EXISTING, 0, 0
mov hFile2, eax

invoke GetFileSize,hFile2,NULL
mov Bytes,eax

invoke ReadFile, hFile2, ADDR FileBuffer,Bytes, ADDR BytesWritten, 0
invoke CloseHandle,hFile2






invoke MessageBoxA, NULL, addr StringBuffer, offset BoxCaption, NULL
invoke MessageBoxA, NULL, addr FileBuffer, offset BoxCaption, NULL







invoke MD5_Startup
invoke MD5_Init, offset ctxt
invoke MD5_Read, offset ctxt, offset FileBuffer, Bytes
invoke MD5_Digest, offset ctxt, offset filehash
invoke MD52String, offset filehash, offset strn, 1


invoke MessageBoxA, NULL, addr strn, offset BoxCaption, NULL








mov FileBuffer,0
mov StringBuffer,0
dec Byteforstreamreader
jmp streamreader2
.endif
mov eax,offset Buffer2
mov Buffer3,eax



invoke lstrcat,ADDR StringBuffer,addr Buffer2

dec Byteforstreamreader
jmp streamreader2
.endif
.if Byteforstreamreader == 0
invoke CloseHandle,hFile
.endif

.data
filestoscan      db "myfiles.txt",0
FileBuffer        DB 50000 DUP(?)
Bytes dd ?
Bytes2 dd ?
BytesWritten dd ?
BytesWritten3 dd ?
hFile dd ?
hFile2 dd ?

.data ?
hFile dd ?
Byteforstreamreader dd ?  
BytesWritten2 dd ?
StringBuffer DB 100 DUP(?)
Buffer2  db 500 dup (?)
ctxt db 1000 dup (?)
filehash db 1000 dup (?)
strn db 33 dup(?) ; use dw for unicode
另外一个附带问题是,如果有人能回答,我觉得必须在filebuffer上保留50000字节以便打开50000字节或更小的文件是不对的。我如何在不保留所有内存的情况下打开任何大小的文件,因为其中一些文件可能是100 mb或更大


谢谢您

这里是您的
streamreader2
循环的一个稍加注释的版本:

streamreader2:
.if Byteforstreamreader != 0
    invoke ReadFile, hFile, ADDR Buffer2,1, ADDR BytesWritten, 0

    ; check for end-of-line (CR)
    .if Buffer2 == 13

        ; open the file named in Buffer2 and 
        ; do a bunch of stuff to it to get the MD5
        ;
        ; ...

        mov FileBuffer,0
        mov StringBuffer,0
        dec Byteforstreamreader
        jmp streamreader2
    .endif

    ; I don't know what the purpose of these two lines are
    mov eax,offset Buffer2
    mov Buffer3,eax

    ; append the character just read from hFile to StringBuffer
    invoke lstrcat,ADDR StringBuffer,addr Buffer2

    dec Byteforstreamreader
    jmp streamreader2
.endif

因此,除了13(CR)之外,从
hFile
读取的字符都不会被专门处理。但是,我认为该文件中的行尾很有可能是CRLF,因此当打开下一个文件时,名称的开头将有一个LF控制字符。因此,
CreateFile
fopen
调用将无法打开文件。

如果代码没有那么长,请将其粘贴到,选择全部并按Ctrl+K将其转换为一个代码块。好的,我现在得到了他们的代码。至于你的一个问题,关于如何在没有巨大静态缓冲区的情况下处理大型文件-想想你在C中可以如何做到这一点。通常,你不会将整个文件读入单个缓冲区,相反,您有一个循环,它将文件块读入一个较小的缓冲区,并一次一个块地处理文件。我从未见过像
mov hFile2,fopen(addr StringBuffer)
-MASM是否支持以某种方式调用函数来获取move指令的源数据?我原以为您需要显式调用
fopen()
函数(可能使用
invoke
指令),然后是
movhfile2,eax
指令。我必须说,我不太喜欢流控制和函数调用的“扩展”MASM指令;线路代替了高级fopen。我尝试使用fopen的唯一原因是想看看它是否能更好地解决撞车问题。非常感谢Michael Burr的工作!我在代码的.if Buffer2==13部分下添加了另一个invoke ReadFile,hFile,ADDR Buffer2,1,ADDR byteswrited,0以使其工作。另一个快速的问题是,如果我有一个20mb大的文件,我如何将其读入FileBuffer,因为您无法保留20971520字节(20mb),如果我将其拆分为块,我将如何将它们合并为一个块以md5。也许,如果迈克尔·伯尔或任何人有一个好办法,他们可以发布它。谢谢@patchariadog:我不知道您正在使用的MD5库的详细信息,但通常有一个函数可以计算中间MD5值,您可以一个缓冲区一个缓冲区地传递给它。看起来库中的
MD5_Read()
函数可能是这样的;如果是这样,只需将从文件读取的每个缓冲区的内容(和长度)传递到
MD5_read()
,然后在调用
MD5_Digest()
时,它将完成MD5。请记住,我只是在猜测MD5库的行为。但考虑到你有
MD5_Init()
/
MD5_Digest()
“bookends”,我认为这是一个合理的猜测。