Assembly 32位汇编语言创建输出文件故障

Assembly 32位汇编语言创建输出文件故障,assembly,masm,irvine32,Assembly,Masm,Irvine32,使用此程序一段时间后,它会在创建输出文件后继续停止。我正在使用VisualBasic2010,在这方面我还是个初学者。家庭作业的问题是: 说明(对称加密): 编码 要求用户键入一些文本 要求用户键入此范围[1-255]内的私钥。执行范围有效性检查 使用提供的私钥加密输入文本,将密码文本放入由用户命名的文件中 解码 要求用户指定要解码的文件 从该文件加载密码文本并尝试对其进行描述,而不假定私钥与编码中使用的私钥相同 将所有试验结果放在用户指定的单独文件中 d。找出最合理的结果(或原始明文)是

使用此程序一段时间后,它会在创建输出文件后继续停止。我正在使用VisualBasic2010,在这方面我还是个初学者。家庭作业的问题是:

说明(对称加密):

  • 编码

    • 要求用户键入一些文本
    • 要求用户键入此范围[1-255]内的私钥。执行范围有效性检查
    • 使用提供的私钥加密输入文本,将密码文本放入由用户命名的文件中
  • 解码

    • 要求用户指定要解码的文件
    • 从该文件加载密码文本并尝试对其进行描述,而不假定私钥与编码中使用的私钥相同
    • 将所有试验结果放在用户指定的单独文件中
    • d。找出最合理的结果(或原始明文)是什么
  • 我知道如何加密文本,但在使用位于此教科书地址的库创建输出文件时遇到问题:

    我将在下面包含我的代码,并通过评论材料展示我在这方面做了多少次尝试。这本书没有很好地向我解释,所以如果我能看到它想说什么,那将非常有帮助

    提前谢谢

    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-In 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
    的源代码,它说它在成功时返回一个文件句柄,请将其保存在某个地方。当您完成对文件的写入时,可将其与
    CloseFile
    一起使用。如果它没有成功创建文件,它将返回
    无效的\u句柄\u值

    您正在使用Visual Basic 2010在汇编程序中编程?是的,我们只需要使用Visual Basic 2010 Express,没有其他要求。好的,popad防止了它崩溃。我不理解的是创建文件并用用户键入的名称命名。要做到这一点,需要采取哪些步骤?缓冲区是否进入edx?打开irvine32.asm,您将看到所有进程,以及关于每个进程接收和返回内容的注释。我已经阅读了这些注释,从我的理解来看,它需要使用edx来完成一些事情。很抱歉,我是这方面的新手,不明白书上和老师是怎么说的。是否:mov edx,BUFFER bufFile,然后是mov ecx,filename?这是CreateOutputFile所说的:创建一个新文件并以输出模式打开它;接收:EDX指向文件名;返回:如果文件创建成功,EAX;包含有效的文件句柄。否则,EAX;等于无效的\u句柄\u值。尝试加入聊天,但它不允许我使用,因为我有10分害羞使用它