【发布时间】:2015-12-14 22:07:31
【问题描述】:
我必须编写应该以 64 字节块从 .txt 文件中读取文本的代码,加密每个块,然后将其写入另一个 .txt 文件。现在,我希望能够读取 64 字节块并写入它们,而无需对目标文件进行任何更改。我知道我的代码存在很多问题,但我不知道如何解决它们,因此非常感谢任何帮助和建议。这是我设法做到的。
.386
.model flat, stdcall
includelib msvcrt.lib
extern exit: proc
extern printf: proc
extern scanf: proc
extern fscanf: proc
extern fprintf: proc
extern fopen: proc
extern fclose: proc
public start
.data
type_read db "r",0
type_write db "w", 0
destination db "destination.txt",0 ;name of destination file
fscanf_format db "%lld",0
fprintf_format db "%lld",0
msg_start db "Source file path:",0
source dd 0 ;name of source file
source_format db "%s", 0
block64 dq 0
pointer_source db 0
pointer_destination dd 0
.code
start:
mov eax,0
push offset msg_start
call printf
add esp,4
; read name source file
push offset source
push offset source_format
call scanf
add esp,8
; open source file
push offset type_read
push offset sursa
call fopen
add esp,8
mov pointer_source,eax ;save source pointer eax
; open destination file
push offset type_write
push offset destination
call fopen
add esp,8
mov pointer_destination,ebx
reading:
;file reading
push offset block64 ;offset of qword variable
push offset fscanf_format ;format string "%lld",0
push pointer_source ;file pointer
call fscanf
add esp,16
;i tried to write what i've read to file destination.txt but i am not sure how to
pop ebx
sub esp,8
cmp eax,0ffffffffh;end of file?
je finish
end reading
finish:
push 0
call exit
end finish
end start
【问题讨论】:
-
您的问题有被关闭的危险。您可能需要重新阅读有关如何正确提出问题的说明,尤其是在清楚地描述问题以及您到目前为止所做的事情时。 “这不起作用,告诉我为什么”甚至还没有接近。 :)
-
显然这是作业。你应该只使用C库吗?如果是这样,则在二进制文件上使用 fopen/fread/frwite 进行 I/O。 scanf/fscanf 解析输入数据,所以你只想用它来获取文件名(或者更好,将文件名作为命令行参数)。
-
@DavidHoelzer OP 提供了程序要做什么的描述,完整的源代码 [主要工作,AFAICT],并在代码注释中描述了他具体遇到问题的行。如果他将评论提升到帖子顶部,那一切都会好起来的。但是,对于任何 asm 人来说,已经有足够的信息来给出答案 [他得到了一个]。随着 1 分的发布,我看到的情况要糟糕得多。
-
@CraigEstey 我是一名装配人员。我不必费力地通过代码来弄清楚“我知道我的代码存在很多问题,但我不知道如何解决它们”的含义。这对我来说不是一个明确的问题陈述。 :) 对不起,如果我冒犯了。
-
我要质疑的是第 3 方 (David Tansey) 将 64 位块更改为 64 字节块。如果是 OP 做出改变,我可能会理解。我有点不清楚 OP 想要回答的原始问题是什么。