News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Hex to ASCII

Started by ChillyWilly, September 13, 2008, 07:01:05 AM

Previous topic - Next topic

RuiLoureiro

Quote from: ChillyWilly on September 14, 2008, 04:03:23 AM
the string looks like this:

"68 00 65 00 6c 00 6c 00 6f 00 00 00 77 00 6f 00 72 00 6c 00 64 00 00 00"

where the first word 'hello' is 68 00 65 00 6c 00 6c 00 6f 00 00 00
so the string ends with  00 00 00

the second word is 77 00 6f 00 72 00 6c 00 64 00 00 00
and also ends with 00 00 00

ChillyWilly,
                 I think you are making a confusion when you say «so the string ends with  00 00 00»
Then it means sometimes each char are 2 bytes and at the end only 1 byte. Why ?
                    68 00    65 00    6c 00    6c 00    6f 00          00 00      (so it ends with 2 bytes)
                       h           e          l            l          o      so       0
Rui

ChillyWilly

so is there a function to seperate a unicode string into 2 parts

Mark Jones

See MSDN: MultiByteToWideChar & WideCharToMultiByte  for conversion between UNICODE and ASCII text formats.

See \masm32\help\MASMLIB.CHM for a list of library functions for manipulating string data, both UNICODE and ASCII.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

hutch--

ChillyWilly,

The separator between the two words says its not a normal unicode string, you need to write the algo yourself.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ChillyWilly

would it be easier to convert the unicode to hex then parse it?
the problem m running into since the string contains nulls it terminates the procedure because its searching for the 0 at the end of the string to stop the search

PBrennick

Changing it to hex is not going to help you because you will still have an indeterminate number of zeroes.

-- Paul
The GeneSys Project is available from:
The Repository or My crappy website

RuiLoureiro

Quote from: ChillyWilly on September 14, 2008, 07:47:27 PM
would it be easier to convert the unicode to hex then parse it?
ChillyWilly,
            Sorry, i didnt understand your problem ! You dont solve the
            problem "how to convert the unicode to hex" and you want
            to think about "how to parse it". The example you gave us
            is correct or there are more behind it ?

Quote
            As Hutch said, «The separator between the two words says its not a
                      normal unicode string
, you need to write the algo yourself.»
            And if your case is not a normal unicode string, you should see
            what is your case and then try to write your own procedure. Do you Know
            how many bytes/words it has ?
                       
            Take a look at the following code. Does it help you ?                     
;**************************************************************************
; Console Assemble & Link
; *******************
include \masm32\include\masm32rt.inc
CvWordAscii      proto :DWORD,:DWORD,:DWORD
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
_unicode    db 68h, 00, 65h, 00, 6ch, 00, 6ch, 00, 6fh, 00, 00, 00   ; text word 1
            db 77h, 00, 6fh, 00, 72h, 00, 6ch, 00, 64h, 00, 00, 00   ; text word 2
_ascii1     db 120 dup (?)          ; buffer for text word 1
_ascii2     db 120 dup (?)          ; buffer for text word 2
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:    invoke  CvWordAscii, offset _unicode, offset _ascii1, offset _ascii2 
           print   offset _ascii1,13,10
           print   offset _ascii2,13,10
           inkey   
           exit
; «««««««««««««««««« procedure «««««««««««««««««««««««««««««
; pSrc = pointer to Source                  -> example: offset _unicode
; pDst1= pointer to Destination buffer 1    -> example: offset _ascii1
; pDst2= pointer to Destination buffer 2
;
CvWordAscii     proc    pSrc:DWORD, pDst1:DWORD, pDst2:DWORD

                mov     ecx, pDst1
                mov     edx, pSrc
       
@@:         movzx   eax, word ptr [edx]
                mov     byte ptr [ecx], al
                add      edx, 2
                inc       ecx
       
                cmp     ax, 0       ; is 0000h ?
                jne      @B         

                mov     ecx, pDst2

@@:         movzx   eax, word ptr [edx]
                mov     byte ptr [ecx], al
                add      edx, 2
                inc       ecx
       
                cmp     ax, 0       ; is 0000h ?
                jne      @B

                ret
CvWordAscii     endp
; ««««««««««««««««««««««««««««««««««««
end start

Rui

ChillyWilly

yes this is exactly what i needed  :U

RuiLoureiro

Quote from: ChillyWilly on September 15, 2008, 04:59:39 PM
yes this is exactly what i needed  :U
              Have a good work  :U
RuiLoureiro