I got a VM and MS DOS disket and I am making programs for MS DOS, I tried to make this one wich creates a file but it does not work? Can someone find the bug?




mov  ah, 09h
mov  dx, szMsg
int  21h

mov  ah, 0Ah
mov  dx, szString
int  21h

mov  ah, 3Ch
mov  dx, data
mov  cx, 0
int  21h
jc    errorOccured

mov  ah, 09h
mov  dx, szDne
int  21h
jmp  exit
   
errorOccured:

mov  ah, 09h
mov  dx, szErr
int  21h
jmp  exit

exit:

mov  ah, 4Ch
int  21h

szErr db 13, 10, "Failed to Create File", "$"
szDne db 13, 10, "File Created Successfully", "$"
szMsg db "Create File V1.0", 13, 10, "Made by ExtremeCoder", 13, 10, "Enter File Location and Name: ", 13, 10, "$"
hFile dd 0

szString:
max  db 30
count db 0
data  db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Posted on 2007-12-30 14:22:34 by ExtremeCoder
It's been a long time but did you "Close Handle"? You have to close handle or it won't take.
Posted on 2007-12-30 14:41:52 by mrgone
DOS Interrupt 0x21, Function 0x0A is buffered input which also takes the enter key (carriage return) as the last non-zero character.

So, if you type "TEST.TXT", you will actually have the ASCII numerical representation of "TEST.TXT" followed by 0x0D (carriage return)... perhaps even following with a 0x0A (line feed.)

Basically, you need to scan your string and eliminate any illegal (non-alphanumeric) characters. Anything outside of 0x2E (.), 0x30-0x39 (1-9), 0x41-0x5A (A-Z) and 0x5F (_) should be turned into zero. Also, 0x61-0x7A (a-z) should be turned into their uppercase equivalents (subtract 0x20) since true/legacy DOS only considers uppercase letters for file names.

For added protection/detection, you should then check if there are any zeros in between those legal (alphanumerical) ASCII characters, indicating a bad file name altogether.
Posted on 2007-12-30 14:58:05 by SpooK