News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

ASCII to HEX and HEX2ASCII Converter Tool

Started by hfheatherfox07, November 30, 2012, 09:33:09 AM

Previous topic - Next topic

hfheatherfox07

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
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

jj2007

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
   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

hfheatherfox07

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 !!!


Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

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
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

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

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

nidud

#5
deleted

hfheatherfox07

@ 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
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

Thanks again nidud !!1  :greenclp: :greenclp:
Now we got some examples .....
Here are the ASCII to HEX and HEX to ASCII Converter Tool
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

jj2007

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"

;)

hfheatherfox07

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
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

frktons

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. ::)
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama