Help Please!

Hi,

I am learning basic Xor encryption of files, so I am trying to create a simple program to encrypt all of the files in the current directory. Heres part of the program, with the result of Int21h Function4Eh (FindFirstFile) stored in a variable named FNAME.

SEARCH_1:
jc FINISHED
mov ax,3D02h
mov dx,FNAME
int 21h

After opening the file like this for read/write, I need to store the number of bytes in the file in a variable named BUFFER. However, the only way I know of doing this is Int21h Fnction3F (ReadFromFile). This requires the number of bytes to be read set in CX. Obviously I don't know how many there will be.

Can anyone help please?

Comments

  • : Hi,
    :
    : I am learning basic Xor encryption of files, so I am trying to create a simple program to encrypt all of the files in the current directory. Heres part of the program, with the result of Int21h Function4Eh (FindFirstFile) stored in a variable named FNAME.
    :
    : SEARCH_1:
    : jc FINISHED
    : mov ax,3D02h
    : mov dx,FNAME
    : int 21h
    :
    : After opening the file like this for read/write, I need to store the number of bytes in the file in a variable named BUFFER. However, the only way I know of doing this is Int21h Fnction3F (ReadFromFile). This requires the number of bytes to be read set in CX. Obviously I don't know how many there will be.
    :
    : Can anyone help please?
    :
    [blue]I do not see your problem here. Declare a buffer in a .DATA section, like so:
    [code]
    .DATA
    fileBuffer Db 1024 Dup (0) ; 1Kb here
    [/code]
    And read into it with AH=3Fh - obviously, put 1024 into CX, because that is maximum you have, and AFTER AH=3Fh will return - you will have the real count which is filled from file inside AX. The last part of the file will have less bytes then others. Now encrypt the bytes in 'fileBuffer' with XOR and then write it into output file. When all finished (AH=3Fh will return 0 bytes) remove the file you were reading from and rename the file you were writing to into the name you were reading from. And do so for all files.

    Also, I am not sure this code is so simple...[/blue]
  • [code]
    ; ========================= FOCSIZE.INC =========================
    ; Nasm procedure FOCSIZE
    ;
    ; Call with, BX = File handle of just Opened or Created file.
    ;
    ; Returns, SIZE of file in DX:AX
    ; (on return near, SP-10 holds the Dword in temp memory)
    ; ( MOV BX,SP-10 MOV EAX,[BX] )
    ;
    align 16
    FOCSIZE:
    PUSH BX
    PUSH CX

    MOV AX,4202h ;; AL=2 end of file
    XOR CX,CX
    XOR DX,DX ;; CX:DX offset of origin of new file position
    INT 21h
    PUSH DX
    PUSH AX
    XOR CX,CX
    XOR DX,DX ;; offset of origin
    MOV AX,4200h ;; AL=0 start of file
    INT 21h
    POP AX
    POP DX ;; Dword DX:AX holds the file size

    POP CX
    POP BX
    RET
    [/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories