Masm32 SDK description, downloads and other helpful links
Started by GuruSR, August 08, 2016, 12:45:25 PM
.Data?bQuote Byte ? ; Whether or not we're in "Quotes".bLast Byte ? ; Last character, used to see if we have crlf or \"Write DWord ? ; Current offset in the Buffer where I'm writing/reading.EndBF DWord ? ; End of the buffer (Buffer + BufferLen)Count DWord ? ; It'll be 1 or 0 (0 meaning nothing left).ReadToCRLFQ Proc Uses Ebx Ecx Edx Esi FileID:DWord, BufferLen:DWord, Buffer:DWord Mov Edi, DWord Ptr [Buffer] Mov Write, Edi Mov Eax, Edi Add Eax, DWord Ptr [BufferLen] Mov EndBF, Eax Mov Count, 0H Mov bLast, 0H Mov bQuote, 0H CldReadLoop: Push 0 Lea Eax, Count Push Eax Push 1 Push Edi ; Buffer Mov Eax, DWord Ptr [FileID] ; Supplied hFile. Push Eax Call ReadFile Cmp Count, 0 Je Split ; Nothing left Mov Al, [Edi] ; Get the character. Mov Bl, bLast ; Check last. Cmp Al, Quote ; if "... Jne NoQuote Cmp Bl, Slash ; if \, ignore it, it's "not a quote". Je NoQuote Mov Cl, bQuote ; Get bQuote Xor Cl, 01h ; Toggle it on, since we're "in quotes". Mov bQuote, Cl ; Store it.NoQuote: Mov Cl, bQuote Cmp Cl, 0 Jne NotLF ; We're inside a quote. Cmp Al, LF ; Check for Line Feed (CR is in last) Jne NotLF Cmp Bl, CR ; If it's a carridge return, we should stop. Je Split ; Done, found the end of line.NotLF: Mov bLast, Al ; Store the last one, so we're keeping track of things. Inc Edi ; Increase. Inc Edi ; Unicode increase. Cmp Edi, EndBF Jl ReadLoop ; Keep going until we run out of buffer space.Split: Mov Eax, Edi Sub Eax, Write Shr Eax, 1H ; Take the Unicode off. Cld Ret ;0ChReadToCRLFQ EndP
"Welcome" = "Welcome to this nightmare!""Goodbye" = "You died, have a nice afterlife!""UserName" = "Dead Sucker"
Quote from: jj2007 on August 08, 2016, 02:01:55 PMWithout seeing the complete code (from "include" to "end start"), and a text file for testing, it is almost impossible to diagnose your problem. So this is just a guess: "Unicode increase" could be the culprit. In your loop, you read one byte, but you advance two bytes in your buffer. So if you read "a text", buffer will be a,0,32,0,t,0,e,0,x,0,tIs that intentional?Re Olly: an int 3 before ReadFile can do miracles 8)
Quote from: mineiro on August 08, 2016, 11:06:13 PMThis is just supposition because I don't see full source code.If you deal with ascii/ansi you read just 1 byte (1byte == 1 letter/symbol). If you deal with Unicode things you should read at least 2 bytes (2 bytes == 1 letter/symbol).So, you can adjust this thing on ReadFile, and on other parts of program too like " Mov Al, [Edi] ; Get the character.". So, you don't need change that 'inc edi, inc edi'.Other point is that texts ends with zero (00h). So, on unicode should be a double zeros (0000h). When your code find (00h or 0000h) it should stop.
Quote from: mineiro on August 08, 2016, 11:06:13 PMI don't get the point about usage of "bl" register. Maybe you're assuming that text will start with quotes, try to remove quotes as first symbol on text and do tests.
Quote from: mineiro on August 08, 2016, 11:06:13 PMIf you have troubles understanding ansi/unicode, just copy that text supplied and paste on notepad. When you go to save, that window that ask name of file, look for options on that window and you will see that have options to save as unicode/ansi. So, as an example, hit "enter"(crlf) 3 times on text and save as enterA.txt using ansi way. After saved, save again with other name, enterU.txt, but this time using unicode. Next step is open that files using hexadecimal editor, you will see that on ansi that is just "crlfcrlfcrlf" sequence, but on unicode you will see some zeros.Have functions on windows .dll that convert unicode to ansi and vice-versa.