[英]32 bit Assembly Language create an output file trouble
經過一段時間的使用,該程序在創建輸出文件后一直保持停止狀態。 我使用的是Visual Basic 2010,現在仍然是初學者。 作業問題是這樣的:
說明(對稱加密):
編碼方式
解碼
我可以弄清楚如何加密文本,但是使用位於此教科書地址的庫創建輸出文件時遇到了麻煩: http : //www.kipirvine.com/asm/examples/index.htm
我將在下面包含我的代碼,並通過評論的材料顯示我對此進行了多少次嘗試。 這本書對我的解釋不是很好,所以如果我能看到它要說的內容,那將非常有幫助!
提前致謝!
INCLUDE Irvine32.inc
BUFMAX = 128 ; maximum buffer size
KEYMAX = 128 ; maximum buffer size
BUFFER_SIZE = 5000
.data
sPrompt BYTE "Enter some text message: ", 0
keyPrompt BYTE "Enter a private key [1-255]: ", 0
cFile BYTE "Enter a filename for cypher text: ", 0
sEncrypt BYTE "Cypher text ", 0
sDecrypt BYTE "Decrypted: ", 0
error BYTE "The key must be within 1 - 255! ", 0
buffer BYTE BUFMAX + 1 DUP(0)
bufSize DWORD ?
keyStr BYTE KEYMAX + 1 DUP(0)
keySize DWORD ?
key DWORD ?
filename BYTE "newfile.txt ", 0
fileHdl DWORD ?
bufFile BYTE BUFFER_SIZE DUP (?)
.code
main PROC
call InputTheString ; input the plain text
call InputTheKey ; input the security key
call CypherFile ; input a cypher filename
;call TranslateBuffer ; encrypt the buffer
;mov edx, OFFSET sEncrypt ; display encrypted message
;call DisplayMessage
;call TranslateBuffer ; decrypt the buffer
;mov edx, OFFSET sDecrypt ; display decrypted message
;call DisplayMessage
exit
main ENDP
InputTheKey PROC
pushad ; save 32-bit registers
LK: mov edx, OFFSET keyPrompt ; display a prompt
call WriteString ; Enter a private key [1-255]
call Crlf ; start a new line
call ReadInt ; read int into system
mov key, eax ; store int into keyStr
cmp eax, 255 ; compare newly read int
ja LC ; jump if above 255 to LC
cmp eax, 1 ; compare newly read int
jb LC ; jump if below 1 to LC
jmp LR ; if between range jump to LR
LC: mov edx, OFFSET error ; The key must be within 1 - 255!
call WriteString ; Display the error
call Crlf ; start a new line
loop LK ; loop back to enter the security key
LR: popad ; restore the registers
ret
InputTheKey ENDP
CypherFile PROC
pushad
mov edx, OFFSET cFile ; "Enter a filename for cypher text
call WriteString ; Enter a name for encrypted file
call Crlf
call ReadString ; Store the filename in eax
;mov filename, eax
mov edx, OFFSET filename
;push eax
;mov eax, fileHdl
;mov edx, OFFSET bufFile
;mov ecx, BUFFER_SIZE
;mov edx, "C:\outputtext.txt"
call CreateOutputFile
;mov edx, OFFSET filename
;mov ecx, SIZEOF filename
;push eax
;mov eax, bufSize
call WriteToFile
pop eax
;call CloseFile
ret
CypherFile ENDP
InputTheString PROC
pushad ; save 32-bit registers
mov edx, OFFSET sPrompt ; display a prompt
call WriteString ; "Enter some text message"
call Crlf ; start a new line
mov ecx, BUFMAX ; maximum character count
mov edx, OFFSET buffer ; point to the buffer
call ReadString ; input the string
mov bufSize, eax ; save the length
popad
ret
InputTheString ENDP
COMMENT !
DisplayMessage PROC
pushad
call WriteString
mov edx, OFFSET buffer ; display the buffer
call WriteString
call Crlf
call Crlf
popad
ret
DisplayMessage ENDP
TranslateBuffer PROC
pushad
mov ecx, bufSize ; loop counter
mov esi, 0 ; index 0 in buffer
mov edi, 0 ; index 0 in the key
L1:
mov al, keyStr[edi] ; get a character from encryption key
xor buffer[esi], al ; translate a byte
inc esi ; point to next byte
inc edi ; go to next position in key
cmp edi, keySize ; compare if equal to size of the key
jb L2
mov edi, 0 ; reset to beginning of the key
L2: loop L1
popad
ret
TranslateBuffer ENDP
!
END main
從哪里開始?
您是否缺少ReadString的一些參數? 也許是指向輸入文件名存儲位置的指針? 接收文件名的緩沖區大小?
CypherFile
使用pushad
將所有寄存器壓入堆棧,但最后只pop eax
。 那里的大問題,應該popad
就目前而言,由於WriteToFile的參數已被注釋掉,因此它不向輸出文件寫入任何內容。
編輯-違反我的“僅僅給出代碼”,您需要告訴ReadString在哪里保存輸入的文件名和緩沖區大小。 然后將其傳遞給CreateOutputFile-在CyperFile proc中-
mov edx, offset buffer ; you are missing a buffer for filename
mov ecx, BUFMAX ; buffer size
call ReadString
mov edx, offset buffer ; Pass this to CreateOutputFile
call CreateOutputFile
現在閱讀CreateOutputFile
的源CreateOutputFile
,它說成功返回一個文件句柄,並將其保存在某個地方。 完成寫入文件后,可將其與CloseFile
一起使用。 如果未成功創建文件,它將返回INVALID_HANDLE_VALUE
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.