Author Topic: Extra characters  (Read 1702 times)

Magnum

  • Member
  • *****
  • Posts: 2235
Extra characters
« on: July 19, 2013, 11:09:22 AM »
This is adding additional characters beyond the sting + 0dbh.

I have a 16 bit program that works fine, but don't know what is amiss here.

Andy

Code: [Select]
;
; crypt.asm  CONSOLE PROGRAM Help from dedndave a.k.a. SuperDave :-),
;            Encrypts a string and writes to a file
;            Useful for hiding strings
;
;            NEED SOME ERROR CHECKING, if string isn't ended with Alt 219 (0dbh) Û, the debugger
;            makes an entrance. :-)
;
include \masm32\include\masm32rt.inc 

CTEXT macro Text
    local szText
    .data
    szText byte Text, 0
    .code
    exitm <offset szText>   
endm


.data

szPrompt db 10,13,"Type string of up to 127 characters to be encrypted",10,13
         db "and end with Alt 219 (0dbh).",0 ; Û

WaterMark   db "SiegeWorks"
%Date       db " &@Date " ; Compile date

.data?

txtinput   db    128 dup(?)  ; contains plain text
storage    db    128 dup(?) ; contains encrypted string
dwBytes    dw    ?


.code

start:

print   offset szPrompt
INVOKE  StdIn,offset txtinput,sizeof txtinput

mov     ebx, offset storage
mov     esi, offset txtinput
mov     byte ptr [ebx+(sizeof storage-1)],'$' xor 0FFh

descramble:

lodsb
not     al                    ; flip bits
mov     [ebx], al
inc     ebx
cmp     al,'$'                ; not Û = $  0dbh = Alt 219 (end of string marker)
jnz     descramble
mov     byte ptr [ebx-1],0    ; the '$'

dec     bx                    ; backspace and write a Û
mov     al,0dbh     
mov     [ebx],al             


invoke CreateFile,CTEXT("Encrypted_String.txt"), GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, \
0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0

mov ebx, eax ; move file handle into ebx
invoke WriteFile, ebx, ADDR storage, SIZEOF storage, addr dwBytes, 0

invoke CloseHandle, ebx
   
invoke ExitProcess,0

end start

Take care,
                   Andy

Ubuntu-mate-16.04-desktop-amd64

http://www.goodnewsnetwork.org