News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

binary to ascii

Started by hfheatherfox07, December 21, 2012, 03:44:57 PM

Previous topic - Next topic

hfheatherfox07

Quote from: dedndave on January 03, 2013, 04:56:31 AM
i am writing my own - lol
this is what i'm using for a test string...
szTest      db '1001000 1100101 1101100 1101100 01101111 100000 01001000011001010110000101110100011010000110010101110010',0

might be the leading 0 - i will play with it, later

@dedndave
I think I am starting to understand this a little ....as MichaelW posted here http://masm32.com/board/index.php?PHPSESSID=417435d04dc4625d2de9d4f3ae67b9a1&topic=1122.45

01000001b is the ASCII character code for "A", 01000010b the ASCII character code for "B", etc....
as I found here http://www.ascii-code.com/

Remember that question you asked me about defining a rule  and I had no idea how to answer ?
I think that is the rule as MichaelW stated , That is just how they are represented
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

I realize that we have a solution by Donkey ....
But I still would like to make a version that decodes binary ASCII string using a Look Up Table ...
Now that MichaelW  explained how Characters are represented in Binary I thought it should be easy ,
But I am Getting an empty result , I have no experience with LUT'S Does any body know why I am not Showing  'ABC' ?
010000010100001001000011 Should give ABC answer !
I put ebx in the result so you can see that it is looking up the table and it is giving 'A' the fiest value in the table
invoke MessageBox,NULL, ebx,addr szCapt,MB_OK
I know it should be
invoke MessageBox,NULL, addr mybuffer,addr szCapt,MB_OK

Also I have modified the first three entries in a hex table as it is time consuming and until I can get this to work I did not want to spend too much time make a full table

Thank You !

.486p
.model flat,stdcall
option casemap:none

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

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

Bin2ASCII proto :DWORD,:DWORD

.data
szCapt   db "Binary To ASCII", 0
szBinaryString  db "010000010100001001000011" ; ABC
.data?
mybuffer db 4096 dup(?) ; total converted string
buffer   db 4096 dup(?) ; buffer

.code

start:

invoke Bin2ASCII,addr szBinaryString,addr buffer
invoke lstrcat, addr mybuffer, addr buffer
invoke MessageBox,NULL, ebx,addr szCapt,MB_OK
Invoke ExitProcess,0
Bin2ASCII proc  uses edi esi pszString:DWORD,pBuffer:DWORD


pushad                 ;save all cpu registers
xor ecx,ecx
mov edi,[pszString]    ;point to source
mov esi,[pBuffer] ;point to destination
   
mov ecx,sizeof  szBinaryString -1 ; movec ounter length to ecx


lea ebx,Binary_table      ;get the address of the lookup table

test ecx,ecx             ;test it's not 0
jz short done

;now do the work
ALIGN 16      ;make sure the next instruction starts on a 16 byte boundary.
lop:

movzx eax,byte ptr [esi]   ;get next byte
mov edx,[4*eax+ebx]        ;look up Binary

mov [edi],dx               ;write the output
add edi,3                  ;update destination pointer
     
inc esi                    ;update pointer
dec ecx                    ;update count

jns short lop               ;go back for next character on this line

done:
xor eax, eax
ret
popad                      ;restore all cpu registers

ALIGN 16  ;make sure the lookup table is aligned in memory
Binary_table:
;01000001b = A 01000010 = B 01000011 = C
dd  01000001b,01000010b,01000011b,"  30","  40","  50","  60","  70"
dd "  80","  90","  A0","  B0","  C0","  D0","  E0","  F0"
dd "  01","  11","  21","  31","  41","  51","  61","  71"
dd "  81","  91","  A1","  B1","  C1","  D1","  E1","  F1"
dd "  02","  12","  22","  32","  42","  52","  62","  72"
dd "  82","  92","  A2","  B2","  C2","  D2","  E2","  F2"
dd "  03","  13","  23","  33","  43","  53","  63","  73"
dd "  83","  93","  A3","  B3","  C3","  D3","  E3","  F3"
dd "  04","  14","  24","  34","  44","  54","  64","  74"
dd "  84","  94","  A4","  B4","  C4","  D4","  E4","  F4"
dd "  05","  15","  25","  35","  45","  55","  65","  75"
dd "  85","  95","  A5","  B5","  C5","  D5","  E5","  F5"
dd "  06","  16","  26","  36","  46","  56","  66","  76"
dd "  86","  96","  A6","  B6","  C6","  D6","  E6","  F6"
dd "  07","  17","  27","  37","  47","  57","  67","  77"
dd "  87","  97","  A7","  B7","  C7","  D7","  E7","  F7"
dd "  08","  18","  28","  38","  48","  58","  68","  78"
dd "  88","  98","  A8","  B8","  C8","  D8","  E8","  F8"
dd "  09","  19","  29","  39","  49","  59","  69","  79"
dd "  89","  99","  A9","  B9","  C9","  D9","  E9","  F9"
dd "  0A","  1A","  2A","  3A","  4A","  5A","  6A","  7A"
dd "  8A","  9A","  AA","  BA","  CA","  DA","  EA","  FA"
dd "  0B","  1B","  2B","  3B","  4B","  5B","  6B","  7B"
dd "  8B","  9B","  AB","  BB","  CB","  DB","  EB","  FB"
dd "  0C","  1C","  2C","  3C","  4C","  5C","  6C","  7C"
dd "  8C","  9C","  AC","  BC","  CC","  DC","  EC","  FC"
dd "  0D","  1D","  2D","  3D","  4D","  5D","  6D","  7D"
dd "  8D","  9D","  AD","  BD","  CD","  DD","  ED","  FD"
dd "  0E","  1E","  2E","  3E","  4E","  5E","  6E","  7E"
dd "  8E","  9E","  AE","  BE","  CE","  DE","  EE","  FE"
dd "  0F","  1F","  2F","  3F","  4F","  5F","  6F","  7F"
dd "  8F","  9F","  AF","  BF","  CF","  DF","  EF","  FF"

Bin2ASCII 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

I took the time to complete the whole Binary table ...
Still No Go  :(
I would appropriate any help
Thank you !

.486p
.model flat,stdcall
option casemap:none

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

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

Bin2ASCII proto :DWORD,:DWORD,:DWORD

.data
szCapt   db "Binary To ASCII", 0
szBinaryString  db "010000010100001001000011" ; ABC
.data?
mybuffer db 4096 dup(?) ; total converted string
buffer   db 4096 dup(?) ; buffer

.code

start:

invoke Bin2ASCII,addr szBinaryString,addr buffer,sizeof szBinaryString-1
invoke lstrcat, addr mybuffer, addr buffer
invoke MessageBox,NULL,addr mybuffer ,addr szCapt,MB_OK
Invoke ExitProcess,0
Bin2ASCII proc   sourcedata:DWORD, targetstring:DWORD, sourcelength:DWORD



pushad                 ;save all cpu registers

mov esi, [sourcedata]  ;point to source
mov edi, [targetstring]  ;point to destination
mov ecx, [sourcelength]   ;counter into source file


lea ebx,Binary_table      ;get the address of the lookup table

or ecx,ecx             ;test it's not 0
jz short done

;now do the work
ALIGN 16      ;make sure the next instruction starts on a 16 byte boundary.
lop:

movzx eax,byte ptr [esi]   ;get next byte
mov edx,[4*eax+ebx]        ;look up Binary

mov [edi],dx               ;write the output
add edi,3                  ;update destination pointer
     
inc esi                    ;update pointer
dec ecx                    ;update count

jns short lop               ;go back for next character on this line

done:

ret
popad                      ;restore all cpu registers
;all done, now the answer is in the buffer pointed to by destination [edi]
ALIGN 16  ;make sure the lookup table is aligned in memory
Binary_table:

dd  00000000b,00000001b,00000010b,00000011b,00000100b,00000101b,00000110b,00000111b
dd  00001000b,00001001b,00001010b,00001011b,00001100b,00001101b,00001110b,00001111b
dd  00010000b,00010001b,00010010b,00010011b,00010100b,00010101b,00010110b,00010111b
dd  00011000b,00011001b,00011010b,00011011b,00011100b,00011101b,00011110b,00011111b
dd  00100000b,00100001b,00100010b,00100011b,00100100b,00100101b,00100110b,00100111b
dd  00101000b,00101001b,00101010b,00101011b,00101100b,00101101b,00101110b,00101111b
dd  00110000b,00110001b,00110010b,00110011b,00110100b,00110101b,00110110b,00110111b
dd  00111000b,00111001b,00111010b,00111011b,00111100b,00111101b,00111110b,00111111b
dd  01000000b,01000001b,01000010b,01000011b,01000100b,01000101b,01000110b,01000111b
dd  01001000b,01001001b,01001010b,01001011b,01001100b,01001101b,01001110b,01001111b
dd  01010000b,01010001b,01010010b,01010011b,01010100b,01010101b,01010110b,01010111b
dd  01011000b,01011001b,01011010b,01011011b,01011100b,01011101b,01011110b,01011111b
dd  01100000b,01100001b,01100010b,01100011b,01100100b,01100101b,01100110b,01100111b
dd  01101000b,01101001b,01101010b,01101011b,01101100b,01101101b,01101110b,01101111b
dd  01110000b,01110001b,01110010b,01110011b,01110100b,01110101b,01110110b,01110111b
dd  01111000b,01111001b,01111010b,01111011b,01111100b,01111101b,01111110b,01111111b
dd  10000000b,10000001b,10000010b,10000011b,10000100b,10000101b,10000110b,10000111b
dd  10001000b,10001001b,10001010b,10001011b,10001100b,10001101b,10001110b,10001111b 
dd  10010000b,10010001b,10010010b,10010011b,10010100b,10010101b,10010110b,10010111b
dd  10011000b,10011001b,10011010b,10011011b,10011100b,10011101b,10011110b,10011111b
dd  10100000b,10100001b,10100010b,10100011b,10100100b,10100101b,10100110b,10100111b
dd  10101000b,10101001b,10101010b,10101011b,10101100b,10101101b,10101110b,10101111b
dd  10110000b,10110001b,10110010b,10110011b,10110100b,10110101b,10110110b,10110111b
dd  10111000b,10111001b,10111010b,10111011b,10111100b,10111101b,10111110b,10111111b
dd  11000000b,11000001b,11000010b,11000011b,11000100b,11000101b,11000110b,11000111b
dd  11001000b,11001001b,11001010b,11001011b,11001100b,11001101b,11001110b,11001111b
dd  11010000b,11010001b,11010010b,11010011b,11010100b,11010101b,11010110b,11010111b
dd  11011000b,11011001b,11011010b,11011011b,11011100b,11011101b,11011110b,11011111b
dd  11100000b,11100001b,11100010b,11100011b,11100100b,11100101b,11100110b,11100111b
dd  11101000b,11101001b,11101010b,11101011b,11101100b,11101101b,11101110b,11101111b
dd  11110000b,11110001b,11110010b,11110011b,11110100b,11110101b,11110110b,11110111b
dd  11111000b,11111001b,11111010b,11111011b,11111100b,11111101b,11111110b,11111111b

Bin2ASCII 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

Looking at argbynum.asm from masm32\m32lib for reference ...
Am I writing my table right ?

when should I use   dd as oppose to db ALIGN 16 as oppose ALIGN 4 ?

:(

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.

Dubby

what about building tiny tables...?  ;)  :badgrin: :idea: :idea:

grab the logic here: http://www.wikihow.com/Convert-Binary-to-Hexadecimal 


.486p
.model flat,stdcall
option casemap:none

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

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

BinaryToACSII proto input:LPDWORD, output:LPDWORD
RetrieveHexValueFromTable proto input:LPDWORD
RetrieveHexValue proto input:LPDWORD

.data?

.data

szTest db "01001000011001010110110001101100011011110010000001001000011001010110000101110100011010000110010101110010",0
Output db 4096 dup(?)
.code
start:
invoke BinaryToACSII, Addr szTest, Addr Output
Invoke MessageBox,NULL, Addr Output, NULL, MB_OK
invoke ExitProcess,NULL


BinaryToACSII proc uses esi edi ebx input:LPDWORD, output:LPDWORD
; STRICT rules:
; binary lenght must be able to be divided by 8


local len:DWORD


local lpStrTemp[4]:DWORD

mov esi, input
mov edi, output
invoke lstrlen, esi
mov len, eax
mov ecx, eax
mov ebx, 8
cdq
div ebx

.if (edx)
.data
MalformerdBin db "Malformed Binary string",13,"Binary lenght must be able to be divided by 8",0
.code
Invoke MessageBox, NULL, Addr MalformerdBin, NULL, MB_OK
ret
.endif
mov Ebx, len

.while  Ebx > 0
invoke RtlZeroMemory, Addr lpStrTemp, sizeof lpStrTemp
Invoke MemCopy, esi, Addr lpStrTemp, 8
Invoke RetrieveHexValue, Addr lpStrTemp
Mov Byte ptr [edi], AL
Inc Edi
Add Esi, 8
Sub Ebx, 8
.endw
ret
BinaryToACSII endp

RetrieveHexValue proc uses esi edi input:LPDWORD
local String[2]:DWORD

Mov esi, input
Invoke RtlZeroMemory, Addr String, sizeof String
Invoke MemCopy, esi, Addr String, 4
Invoke RetrieveHexValueFromTable, Addr String
Mov Edi, Eax
Shl Edi, 4
Add Esi, 4
Invoke MemCopy, esi, Addr String, 4
Invoke RetrieveHexValueFromTable, Addr String
Or Edi, Eax
Mov Eax, Edi
ret
RetrieveHexValue endp

RetrieveHexValueFromTable Proc uses esi ebx input:LPDWORD

mov esi, OFFSET hextables
; ebx counter
xor ebx, ebx
Dec Ebx
xor eax, eax
inc eax
.while (eax != 0 )
invoke lstrcmp, input, esi
add esi, 5
inc ebx
.break .if ebx > 16  || byte ptr [esi] == 0
.endw
mov eax, ebx

ret
RetrieveHexValueFromTable endp

hextables:
db '0000',0 ; 0
db '0001',0 ; 1
db '0010',0 ; 2
db '0011',0 ; 3
db '0100',0 ; 4
db '0101',0 ; 5
db '0110',0 ; 6
db '0111',0 ; 7
db '1000',0 ; 8
db '1001',0 ; 9
db '1010',0 ; 0A
db '1011',0 ; 0B
db '1100',0 ; 0C
db '1101',0 ; 0D
db '1110',0 ; 0E
db '1111',0 ; 0F
db 00,00,00,00,00 ; null terminating block

end start

Feel free to optimize or develop..

dedndave

a look-up table does not seem to be a logical solution to this type of problem
this is more of a "parsing a stream of bytes" problem
once you have the 8 bits in a single byte, the "look-up" part is done for you by way of the definition of the ASCII table
all you have to do is plop the byte down and go to the next one   :P

a little understanding of how look-up tables are beneficial might help
let's say we want to convert a binary dword into an ascii decimal string
rather than dividing by 10 and converting each remainder to an ascii character,
you might divide by 10000 and use the remainder as an index into a look-up table
that index would then yield 4 ascii characters that you can place into the resulting string
the result is very fast, although, the look-up table is 40,000 bytes in size
that would be ok if you had millions of numbers to convert
as it happens, Drizz wrote a little snippet that converts a binary value of 0-9999 to 4 ascii chars in about 18 cycles

that type of conversion just isn't practical for what you want to do

hfheatherfox07

@ Dubby thanks I will look at it and see what I can learn about LUT's

@ dedndave 
Even though this is solved and we have a routine to convert binary to ascii text a few post back
I never did any thing with LUT , I wanted some experience with it as practice
I agree that Donkeys method is fast and efficient!
This was just perfect opportunity for me to get a little experience with it
It should have been straight forward , I will mess with it some more...
I don't know what I am doing wrong
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 January 03, 2013, 01:57:29 PMBut I am Getting an empty result

Get some sleep ;-)
With a few changes, it shows something, see below. But you should really, really use OllyDbg - it is much easier than trial & error.

        invoke MessageBox,NULL, addr buffer, addr szCapt,MB_OK
...
        mov esi, pszString    ; point to source
        mov edi, pBuffer    ; point to destination
...
        mov [edi], dx    ; write the output
        add edi, 2    ; update destination pointer

hfheatherfox07

Yes I should go to sleep it is 5:40 Am

I am a little embarrassed :redface:
By my brain fart .... I used a template of an ASCII to hex string LUT
Looking back at Donkey's example he uses
Mov ecx, 7 since each ASCII character is represented by 7 '0' and '1'
And I was using movzx eax,byte ptr [esi]   ;get next byte
No wonder it did not work lol

Wops  :icon_redface:
I will take a fresh look at later when I wake up lol
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.

dedndave

#84
ok - here is my little routine
it may not be as fast as Edgar's,
but, the destination buffer size is tested and not exceeded
and, it uses all non-binary chars as delimiters
or, if there are no delimiters, it will use 8 binary digits for each byte
if it gets to the end and there aren't 8, it assumes them to be low-order bits
if the result of a byte is 0, it makes it a space
it only terminates the output string when the input string has been fully converted
or if there would be a buffer over-run
it returns the output string length in EAX
it will handle a messy input string like this one
szTest      db ' 1001000 01100101 1101100 01101100 1101111 0100000 01001000011001010110000101110100011010000110010101110010',0

as an added feature, i used LODSB and STOSB so that Hutch won't like me, either  :lol:
;***********************************************************************************************

Abin2Achr PROC USES EBX ESI EDI lpSrc:LPSTR,lpDest:LPSTR,dwDestSize:DWORD

        mov     ebx,dwDestSize  ;size of destination buffer
        xor     eax,eax
        mov     edi,lpDest      ;pointer to destination buffer
        or      ebx,ebx
        mov     ecx,eax
        mov     esi,lpSrc       ;pointer to source string
        jz      Ab2Ac7

        add     ebx,edi
        dec     ebx
        jmp short Ab2Ac3

Ab2Ac0: xor     al,30h
        shl     edx,1
        cmp     al,1
        jbe     Ab2Ac5

        cmp     cl,8
        jz      Ab2Ac3

        shr     edx,1

Ab2Ac1: or      dl,dl
        jnz     Ab2Ac2

        mov     dl,20h

Ab2Ac2: mov     al,dl
        stosb

Ab2Ac3: cmp     edi,ebx
        mov     al,ch
        jz      Ab2Ac6

        mov     cl,8
        mov     dl,ch

Ab2Ac4: lodsb
        or      al,al
        jz      Ab2Ac6

        xor     al,30h
        cmp     al,1
        ja      Ab2Ac4

Ab2Ac5: sbb     dl,-1
        dec     ecx
        jz      Ab2Ac1

        lodsb
        or      al,al
        jnz     Ab2Ac0

        cmp     cl,8
        jz      Ab2Ac6

        cmp     edi,ebx
        jz      Ab2Ac6

        or      dl,dl
        jz      Ab2Ac6

        mov     al,dl
        stosb
        mov     al,ch

Ab2Ac6: mov     edx,edi
        stosb
        xchg    eax,edx
        sub     eax,lpDest      ;return string length

Ab2Ac7: ret

Abin2Achr ENDP

;***********************************************************************************************

hfheatherfox07

 :icon_redface:

Hello , I am still having some difficulty with the LUT
My plan is too look up the segment of 8 ascii Binary characters that represent an ascii charter in the LUT
Copy to buffer , when done than print buffer
Any ideas I am stuck , and just want to have an LUT version working as well

Thank you

.486p
.model flat,stdcall
option casemap:none

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

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

Bin2ASCII proto :DWORD,:DWORD,:DWORD

.data
szCapt   db "Binary To ASCII", 0
szBinaryString  db "010000010100001001000011" ; ABC
align 16 ;make sure the lookup table is aligned in memory

Binary_table \
db  00000000b,00000001b,00000010b,00000011b,00000100b,00000101b,00000110b,00000111b
db  00001000b,00001001b,00001010b,00001011b,00001100b,00001101b,00001110b,00001111b
db  00010000b,00010001b,00010010b,00010011b,00010100b,00010101b,00010110b,00010111b
db  00011000b,00011001b,00011010b,00011011b,00011100b,00011101b,00011110b,00011111b
db  00100000b,00100001b,00100010b,00100011b,00100100b,00100101b,00100110b,00100111b
db  00101000b,00101001b,00101010b,00101011b,00101100b,00101101b,00101110b,00101111b
db  00110000b,00110001b,00110010b,00110011b,00110100b,00110101b,00110110b,00110111b
db  00111000b,00111001b,00111010b,00111011b,00111100b,00111101b,00111110b,00111111b
db  01000000b,01000001b,01000010b,01000011b,01000100b,01000101b,01000110b,01000111b
db  01001000b,01001001b,01001010b,01001011b,01001100b,01001101b,01001110b,01001111b
db  01010000b,01010001b,01010010b,01010011b,01010100b,01010101b,01010110b,01010111b
db  01011000b,01011001b,01011010b,01011011b,01011100b,01011101b,01011110b,01011111b
db  01100000b,01100001b,01100010b,01100011b,01100100b,01100101b,01100110b,01100111b
db  01101000b,01101001b,01101010b,01101011b,01101100b,01101101b,01101110b,01101111b
db  01110000b,01110001b,01110010b,01110011b,01110100b,01110101b,01110110b,01110111b
db  01111000b,01111001b,01111010b,01111011b,01111100b,01111101b,01111110b,01111111b
db  10000000b,10000001b,10000010b,10000011b,10000100b,10000101b,10000110b,10000111b
db  10001000b,10001001b,10001010b,10001011b,10001100b,10001101b,10001110b,10001111b 
db  10010000b,10010001b,10010010b,10010011b,10010100b,10010101b,10010110b,10010111b
db  10011000b,10011001b,10011010b,10011011b,10011100b,10011101b,10011110b,10011111b
db  10100000b,10100001b,10100010b,10100011b,10100100b,10100101b,10100110b,10100111b
db  10101000b,10101001b,10101010b,10101011b,10101100b,10101101b,10101110b,10101111b
db  10110000b,10110001b,10110010b,10110011b,10110100b,10110101b,10110110b,10110111b
db  10111000b,10111001b,10111010b,10111011b,10111100b,10111101b,10111110b,10111111b
db  11000000b,11000001b,11000010b,11000011b,11000100b,11000101b,11000110b,11000111b
db  11001000b,11001001b,11001010b,11001011b,11001100b,11001101b,11001110b,11001111b
db  11010000b,11010001b,11010010b,11010011b,11010100b,11010101b,11010110b,11010111b
db  11011000b,11011001b,11011010b,11011011b,11011100b,11011101b,11011110b,11011111b
db  11100000b,11100001b,11100010b,11100011b,11100100b,11100101b,11100110b,11100111b
db  11101000b,11101001b,11101010b,11101011b,11101100b,11101101b,11101110b,11101111b
db  11110000b,11110001b,11110010b,11110011b,11110100b,11110101b,11110110b,11110111b
db  11111000b,11111001b,11111010b,11111011b,11111100b,11111101b,11111110b,11111111b
.data?

buffer   db 4096 dup(?) ; buffer

.code

start:

invoke Bin2ASCII,addr szBinaryString,addr buffer,sizeof szBinaryString
invoke MessageBox,NULL, addr buffer,addr szCapt,MB_OK
Invoke ExitProcess,0

Bin2ASCII proc  sourcedata:DWORD, stringbuffer:DWORD, sourcelength:DWORD


    push ebx ; register
    push esi ; register
    push edi ; register
mov esi, [sourcedata]    ;point to source
mov edi, [stringbuffer]  ;point to destination
mov ecx, [sourcelength]   ;counter into source file


mov BYTE PTR [edi], 0           ; set destination buffer to zero length

xor ebx, ebx  ; clear ebx

; scan table
align 16      ;make sure the next instruction starts on a 16 byte boundary.
scan:

movzx eax, BYTE PTR [esi]
    add esi, 1
    cmp BYTE PTR [Binary_table+eax],8    ; delimiting character
    je scan
copystring:
; copy table
mov [edi],dx               ;write the output
add edi,3                  ;update destination pointer
     
inc esi                    ;update pointer
dec ecx                    ;update count
jnz copystring
    xor eax, eax                   
ret

    pop edi  ;restore registers
    pop esi  ;restore registers
    pop ebx  ;restore registers




Bin2ASCII 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

I really Need help with the LUT format !!!!

As you can see I read the3 LUT with ebx

.486p
.model flat,stdcall
option casemap:none

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

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

Bin2ASCII proto :DWORD,:DWORD

.data
szCapt   db "Binary To ASCII", 0
szBinaryString  db "010000010100001001000011",0 ; ABC
.data?
buffer   db 4096 dup(?) ; buffer

.code

start:

invoke Bin2ASCII,addr szBinaryString,addr buffer
invoke MessageBox,NULL, ebx,addr szCapt,MB_OK
Invoke ExitProcess,0
Bin2ASCII proc   pszString:DWORD,pBuffer:DWORD


pushad                 ;save all cpu registers



lea ebx,Binary_table      ;get the address of the lookup table


ALIGN 16      ;make sure the next instruction starts on a 16 byte boundary.


mov edx,[8*eax+ebx]        ;look up Binary

; at this Point the LUT values are ebx
xor eax, eax
ret
popad                      ;restore all cpu registers

ALIGN 16  ;make sure the lookup table is aligned in memory
Binary_table:
;01000001b = A 01000010 = B 01000011 = C   
db  01000001b,01000010b,01000011b,"  30","  40","  50","  60","  70"
db "  80","  90","  A0","  B0","  C0","  D0","  E0","  F0"
db "  01","  11","  21","  31","  41","  51","  61","  71"
db "  81","  91","  A1","  B1","  C1","  D1","  E1","  F1"
db "  02","  12","  22","  32","  42","  52","  62","  72"
db "  82","  92","  A2","  B2","  C2","  D2","  E2","  F2"
db "  03","  13","  23","  33","  43","  53","  63","  73"
db "  83","  93","  A3","  B3","  C3","  D3","  E3","  F3"
db "  04","  14","  24","  34","  44","  54","  64","  74"
db "  84","  94","  A4","  B4","  C4","  D4","  E4","  F4"
db "  05","  15","  25","  35","  45","  55","  65","  75"
db "  85","  95","  A5","  B5","  C5","  D5","  E5","  F5"
db "  06","  16","  26","  36","  46","  56","  66","  76"
db "  86","  96","  A6","  B6","  C6","  D6","  E6","  F6"
db "  07","  17","  27","  37","  47","  57","  67","  77"
db "  87","  97","  A7","  B7","  C7","  D7","  E7","  F7"
db "  08","  18","  28","  38","  48","  58","  68","  78"
db "  88","  98","  A8","  B8","  C8","  D8","  E8","  F8"
db "  09","  19","  29","  39","  49","  59","  69","  79"
db "  89","  99","  A9","  B9","  C9","  D9","  E9","  F9"
db "  0A","  1A","  2A","  3A","  4A","  5A","  6A","  7A"
db "  8A","  9A","  AA","  BA","  CA","  DA","  EA","  FA"
db "  0B","  1B","  2B","  3B","  4B","  5B","  6B","  7B"
db "  8B","  9B","  AB","  BB","  CB","  DB","  EB","  FB"
db "  0C","  1C","  2C","  3C","  4C","  5C","  6C","  7C"
db "  8C","  9C","  AC","  BC","  CC","  DC","  EC","  FC"
db "  0D","  1D","  2D","  3D","  4D","  5D","  6D","  7D"
db "  8D","  9D","  AD","  BD","  CD","  DD","  ED","  FD"
db "  0E","  1E","  2E","  3E","  4E","  5E","  6E","  7E"
db "  8E","  9E","  AE","  BE","  CE","  DE","  EE","  FE"
db "  0F","  1F","  2F","  3F","  4F","  5F","  6F","  7F"
db "  8F","  9F","  AF","  BF","  CF","  DF","  EF","  FF"

Bin2ASCII endp
end start


Why Is it when I add the full table it won't read it any more????
db  00000000b,00000001b,00000010b,00000011b,00000100b,00000101b,00000110b,00000111b
db  00001000b,00001001b,00001010b,00001011b,00001100b,00001101b,00001110b,00001111b
db  00010000b,00010001b,00010010b,00010011b,00010100b,00010101b,00010110b,00010111b
db  00011000b,00011001b,00011010b,00011011b,00011100b,00011101b,00011110b,00011111b
db  00100000b,00100001b,00100010b,00100011b,00100100b,00100101b,00100110b,00100111b
db  00101000b,00101001b,00101010b,00101011b,00101100b,00101101b,00101110b,00101111b
db  00110000b,00110001b,00110010b,00110011b,00110100b,00110101b,00110110b,00110111b
db  00111000b,00111001b,00111010b,00111011b,00111100b,00111101b,00111110b,00111111b
db  01000000b,01000001b,01000010b,01000011b,01000100b,01000101b,01000110b,01000111b
db  01001000b,01001001b,01001010b,01001011b,01001100b,01001101b,01001110b,01001111b
db  01010000b,01010001b,01010010b,01010011b,01010100b,01010101b,01010110b,01010111b
db  01011000b,01011001b,01011010b,01011011b,01011100b,01011101b,01011110b,01011111b
db  01100000b,01100001b,01100010b,01100011b,01100100b,01100101b,01100110b,01100111b
db  01101000b,01101001b,01101010b,01101011b,01101100b,01101101b,01101110b,01101111b
db  01110000b,01110001b,01110010b,01110011b,01110100b,01110101b,01110110b,01110111b
db  01111000b,01111001b,01111010b,01111011b,01111100b,01111101b,01111110b,01111111b
db  10000000b,10000001b,10000010b,10000011b,10000100b,10000101b,10000110b,10000111b
db  10001000b,10001001b,10001010b,10001011b,10001100b,10001101b,10001110b,10001111b 
db  10010000b,10010001b,10010010b,10010011b,10010100b,10010101b,10010110b,10010111b
db  10011000b,10011001b,10011010b,10011011b,10011100b,10011101b,10011110b,10011111b
db  10100000b,10100001b,10100010b,10100011b,10100100b,10100101b,10100110b,10100111b
db  10101000b,10101001b,10101010b,10101011b,10101100b,10101101b,10101110b,10101111b
db  10110000b,10110001b,10110010b,10110011b,10110100b,10110101b,10110110b,10110111b
db  10111000b,10111001b,10111010b,10111011b,10111100b,10111101b,10111110b,10111111b
db  11000000b,11000001b,11000010b,11000011b,11000100b,11000101b,11000110b,11000111b
db  11001000b,11001001b,11001010b,11001011b,11001100b,11001101b,11001110b,11001111b
db  11010000b,11010001b,11010010b,11010011b,11010100b,11010101b,11010110b,11010111b
db  11011000b,11011001b,11011010b,11011011b,11011100b,11011101b,11011110b,11011111b
db  11100000b,11100001b,11100010b,11100011b,11100100b,11100101b,11100110b,11100111b
db  11101000b,11101001b,11101010b,11101011b,11101100b,11101101b,11101110b,11101111b
db  11110000b,11110001b,11110010b,11110011b,11110100b,11110101b,11110110b,11110111b
db  11111000b,11111001b,11111010b,11111011b,11111100b,11111101b,11111110b,11111111b

:( :( :(

If anybody knows I would appreciate it



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.

MichaelW

I don't understand the purpose of the second LUT. What would be the point of looking up a value in a table where the indexed value is equal to the index?

Well Microsoft, here's another nice mess you've gotten us into.

hfheatherfox07

Quote from: MichaelW on January 05, 2013, 06:44:40 PM
I don't understand the purpose of the second LUT. What would be the point of looking up a value in a table where the indexed value is equal to the index?


I feel a llittle dumb .... :redface:
I have no idea what do you means?
The first LUT is a Hex table LUT that I modified to include
3 binary values only ....A B C
If you run that little snippet above it you will see that it successfully shows  ABC than all the hex
Does that make senesce?
I do not know why I can't get the second proper LUT
to work the same ? It should ? 
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.

MichaelW

Quote from: hfheatherfox07 on January 05, 2013, 06:56:14 PM
I feel a llittle dumb .... :redface:

Everyone makes mistakes. The key is to catch them before you post :biggrin:

Quote
I have no idea what do you means?

For an example of a working LUT look in masm32\m32lib\bintbl.asm. To use that table you start with a byte value (a number between 0 and 255 inclusive) and use the value as an index into the table, and read the 8-byte binary string representation of the number. See b2b_ex.asm in the same directory for an example of using the table.

In the linked example, the translation is between the string on the left and a larger string of binary digits on the right, were each 8-digit group represents the character code of a character from the string on the left. So the translation, either way, starts and ends with a string.

So it looks like an easy way to translate from text to binary would be to loop through the characters in the text passing each character code to byt2bin_ex along with an appropriate buffer address. Your buffer will need to be large enough to accommodate 8 bytes per character, plus a terminating null. And after each character you will need to add 8 to the buffer address.

And to translate from binary to text you could loop through the binary 8-digits at a time, passing the address of each 8-digit group to bin2byte_ex, and then used the returned values, each a character code, to construct your text string.

Sorry, I don't have time to actually test any of this.

Or you could use your own LUTs and procedures, to do essentially the same thing.
Well Microsoft, here's another nice mess you've gotten us into.