The MASM Forum

General => The Campus => Topic started by: hfheatherfox07 on November 30, 2012, 09:33:09 AM

Title: ASCII to HEX and HEX2ASCII Converter Tool
Post by: hfheatherfox07 on November 30, 2012, 09:33:09 AM
Hi
I decided to make a tool that converts ASCII to HEX  and one that converts HEX2ASCII
I got the ASCII to HEX working but
i can not get the HEX2ASCII converter tool working  :(
I searched the forum and found this which was no help  :( http://www.masmforum.com/board/index.php?PHPSESSID=786dd40408172108b65a5a36b09c88c0&topic=2017.0 

I am using a proc that I found to convert HEX2ASCII ( I included that original _hexstr2ASCIIstr.inc with the source )

I would also like to know how to use the method  htodw - Convert hex string to DWORD and than ltoa - Convert signed DWORD to ascii string

Thank you
Title: Re: ASCII to HEX and HEX2ASCII Converter Tool
Post by: jj2007 on November 30, 2012, 09:46:39 AM
rsrc.rc( 8 ) : fatal error RC1015: cannot open include file 'include'.
*** Resource "rsrc.rc" could not be created ***
:(

You want something like this, I suppose?

include \masm32\MasmBasic\MasmBasic.inc   ; download (http://masm32.com/board/index.php?topic=94.0)
   Init
   mov eax, 12345678h
   mov ecx, Cat$(Hex$(eax)+"h")
   PrintLine "Hex=", ecx
   Inkey Str$("Dec=%i", Val(ecx))
   Exit
end start

Output:
Hex=12345678h
Dec=305419896
Title: Re: ASCII to HEX and HEX2ASCII Converter Tool
Post by: hfheatherfox07 on November 30, 2012, 09:52:56 AM
LOL  jj2007
I have #include "C:/masm32/include/resource.h" in the rsrc.rc
if you do not have masm32 in C like me that would give you that
and no I want to convert hex back to ascii string LOL using that proc that I have ....
For example :
hfheatherfox07 = 68 66 68 65 61 74 68 65 72 66 6F 78 30 37
I want 68 66 68 65 61 74 68 65 72 66 6F 78 30 37 to -> hfheatherfox07
I am trying to fix HEX2ASCII Converter Tool !!!


Title: Re: ASCII to HEX and HEX2ASCII Converter Tool
Post by: hfheatherfox07 on November 30, 2012, 03:04:39 PM
OK I am trying a simple  htodw from the masm32.lib
Why can i not get ascii from hex????  :(

.386
.model flat,stdcall
option casemap:none

include  \masm32\include\windows.inc
include  \masm32\include\kernel32.inc
include  \masm32\include\user32.inc
include  \masm32\include\masm32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\masm32.lib

.data
cpt   db "Result ASCII:" , 0
input db "68 66 68 65 61 74 68 65 72 66 6F 78 30 37",0

.data?
output   db 4096 dup(?) ; total converted string
mybuffer db 4096 dup(?) ; total converted string
.code

start:

; ----------------------------------------------------------------------
; Convert hex string to DWORD with result in the EAX register
; ----------------------------------------------------------------------
invoke htodw,addr input
;invoke RtlZeroMemory, ADDR mybuffer, 4096 ; empty buffer
invoke lstrcat, ADDR output , ADDR input
; -----------------------------------------------------------------------
; rewrite the result Convert DWORD to ascii string
; -----------------------------------------------------------------------
   invoke dwtoa,eax,addr output

invoke MessageBox, NULL, addr output , addr cpt, MB_OK

invoke ExitProcess, NULL

end start
Title: Re: ASCII to HEX and HEX2ASCII Converter Tool
Post by: hfheatherfox07 on November 30, 2012, 04:55:07 PM
Ok I figured out the example from here :
http://www.masmforum.com/board/index.php?PHPSESSID=786dd40408172108b65a5a36b09c88c0&topic=2017.0

If I can figure how to make it take a whole string ?

.386
.model flat,stdcall
option casemap:none

include  \masm32\include\windows.inc
include  \masm32\include\kernel32.inc
include  \masm32\include\masm32.inc
include  \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib  \masm32\lib\masm32.lib

.data
number dd 61h

cpt db "Result:" , 0
.data?
buffer db 64 dup (?)
.code
start:
mov eax, number
mov byte ptr [buffer],al

invoke MessageBox, NULL, addr buffer, addr cpt, MB_OK

invoke ExitProcess, NULL

end start

Title: Re: ASCII to HEX and HEX2ASCII Converter Tool
Post by: nidud on November 30, 2012, 06:11:23 PM
deleted
Title: Re: ASCII to HEX and HEX2ASCII Converter Tool
Post by: hfheatherfox07 on November 30, 2012, 06:19:58 PM
@ nidud thanks!!!  :t

.386
.model flat,stdcall
option casemap:none

include  \masm32\include\windows.inc
include  \masm32\include\kernel32.inc
include  \masm32\include\user32.inc
include  \masm32\include\masm32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\masm32.lib
hextoa proto :ptr byte
.data
cpt   db "Result ASCII:" , 0
input db "68 66 68 65 61 74 68 65 72 66 6F 78 30 37",0

.data?
output   db 4096 dup(?) ; total converted string
mybuffer db 4096 dup(?) ; total converted string
.code

start:

; ----------------------------------------------------------------------
; Convert hex string to DWORD with result in the EAX register
; ----------------------------------------------------------------------
invoke hextoa,addr input

invoke lstrcat, ADDR output , ADDR input


invoke MessageBox, NULL, addr output , addr cpt, MB_OK

invoke ExitProcess, NULL
hextoa proc uses esi edi string:ptr byte
mov edi,string
mov esi,edi
.repeat
    mov ax,[esi]
    inc esi
    .continue .if al == ' '
    inc esi
    mov dl,ah
    .break .if !al
    sub ax,'00'
    .if al > 9
sub al,7
    .endif
    shl al,4
    .if ah > 9
sub ah,7
    .endif
    or  ah,al
    mov [edi],ah
    inc edi
.until !dl
sub al,al
mov [edi],al
mov eax,string
ret
hextoa endp
end start
Title: Re: ASCII to HEX and HEX2ASCII Converter Tool
Post by: hfheatherfox07 on November 30, 2012, 06:48:33 PM
Thanks again nidud !!1  :greenclp: :greenclp:
Now we got some examples .....
Here are the ASCII to HEX and HEX to ASCII Converter Tool
Title: Re: ASCII to HEX and HEX2ASCII Converter Tool
Post by: jj2007 on November 30, 2012, 06:50:56 PM
Quote from: hfheatherfox07 on November 30, 2012, 09:52:56 AM
I have #include "C:/masm32/include/resource.h" in the rsrc.rc
if you do not have masm32 in C like me that would give you that

Yes indeed. But there is a cheap trick that avoids this problem:
#include "\masm32\include\resource.h"

;)
Title: Re: ASCII to HEX and HEX2ASCII Converter Tool
Post by: hfheatherfox07 on November 30, 2012, 06:53:01 PM
Quote from: jj2007 on November 30, 2012, 06:50:56 PM
Quote from: hfheatherfox07 on November 30, 2012, 09:52:56 AM
I have #include "C:/masm32/include/resource.h" in the rsrc.rc
if you do not have masm32 in C like me that would give you that

Yes indeed. But there is a cheap trick that avoids this problem:
#include "\masm32\include\resource.h"

;)


Duh (http://www.beeskneesdance.com/bees_knees/wp-content/uploads/2011/01/homer-simpson-doh-255x234.gif)
Title: Re: ASCII to HEX and HEX2ASCII Converter Tool
Post by: frktons on November 30, 2012, 09:43:19 PM
Quote from: hfheatherfox07 on November 30, 2012, 09:52:56 AM
LOL  jj2007
I have #include "C:/masm32/include/resource.h" in the rsrc.rc
if you do not have masm32 in C like me  ....


Oh my God, after the thread about Assembly and C, I was
assuming you have masm32 in the C language, and I wondered
who the hell had written it. :)
This is because I usually see C: to indicate the Main Disk, but
things change. ::)