Here is part of the code I'm working on right now

I'm just opening a file and then reading from it. So if "Edx" is 0 then it would return 0x4d (or whatever the first hex number is of the file)



.data
hexnumber db '0x%lx',0
.code

...


invoke GlobalAlloc, GHND, hSize
mov hMem, eax

invoke GlobalLock, eax
mov pMem, eax

invoke ReadFile, hFile, pMem, hSize, addr hTmp, 0

mov ecx, pMem

xor eax, eax
xor edx, edx
mov edx, temp ;offset of where to start in the file
mov al, byte ptr [ecx+edx]
invoke wsprintf,addr buffer,offset hexnumber,eax
invoke SetDlgItemText, hWnd, IDC_VALUE, ADDR buffer



What I want to do is return a list of hex numbers, but I don't know how to do that.

Inotherwords I can display: 0x4d

but I want to be able to display: 0x4d 0x5a 0x90 0x0 0x3 ... etc

I'm not sure I even know how to fill something like:
hexlisting db '0x%lx 0x%lx',0

so any help or example of how to store multiple values to a buffer when you don't have those values to beging with is helpful :)

Sliver
Posted on 2002-01-01 12:53:57 by Sliver
Windows will do the '0x' for you with the right tempate string. You need two buffers:
_hex db '%#lx',0

tempBuffer db '0x00000000',0 ; this might overflow?
finalBuffer db 4096 dup (0)

...

invoke wsprintf,addr tempBuffer,offset _hex,eax

; find end of finalBuffer and copy tempBuffer there.
invoke lstrlen, offset finalBuffer
invoke lstrcpy, offset finalBuffer[eax], offset tempBuffer
Posted on 2002-01-01 13:04:21 by bitRAKE
Hi bitRake,

why not using lstrcat addr finalbuffer,addr tempbuffer instead of lstrlen + lstrcpy ;) ?

japheth
Posted on 2002-01-02 09:32:30 by japheth
------edit------
figured it out so I just got rid of the whole thing

(it would seem that my post spanned many pages to the left anyway...)

-Sliver
Posted on 2002-01-03 01:04:21 by Sliver
If I understood what do you need?
You want to translate some array of values into their simbolic hex
representation and then display them.
Before you can get any solution you need to be a little bit more explicit on following details:
1. In what TYPE of data you want the symolic string to be represented.
For example if you have in the file a string: 'The Svin'

in bytes it would be:
54 68 65 20 53 76 69 6E

in words:
6854 2065 7653 6E69

in dwords:
20656854 6E697653

2. You need to decide on format
for example it might be
0x54
or
54h
or just
54

3. Then you need to decide on how many simbols you want to
be in one line.

Any particular algorithm must be build with the mensioned data
known.

Answer and only then you can get an example of how to...
Posted on 2002-01-03 02:14:55 by The Svin
Thanks :)

I was using 0x## as db
(anyways solved that problem)

but since I may have your attention...

my new problem is:

0x4d 0x5a 0x90 0x0 0x3 0x0 0x0 0x0 0x4 0x0 0x0 0x0 0xff 0xff 0x0 0x0 0xb8 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x40 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0xc0 0x0 0x0 0x0 0xe 0x1f 0xba 0xe 0x0 0xb4 0x9 0xcd 0x21 0xb8 0x1 0x4c 0xcd 0x21 0x54 0x68 0x69 0x73 0x20 0x70 0x72 0x6f 0x67 0x72 0x61 0x6d 0x20 0x63 0x61 0x6e 0x6e 0x6f 0x74 0x20 0x62 0x65

This is the dump I get with my program :( I really would like to organize this into something like


0x4d 0x5a 0x90 0x0 0x3 0x0 0x0 0x0 -- 0x4 0x0 0x0 0x0 0xff 0xff 0x0 0x0
0xb8 0x0 0x0 0x0 0x0 0x0 0x0 0x0 -- 0x40 0x0 0x0 0x0 0x0 0x0 0x0 0x0 ... etc


but how do I add a return code at the end of my string and format it the way I want

here is the code so far:




invoke ReadFile, hFile, pMem, hSize, addr hTmp, 0

mov ebx, pMem
mov edx, temp

mov al, byte ptr [ebx+edx]

invoke wsprintf,addr tempBuffer,offset _hex,eax
invoke SetDlgItemText, hWnd, IDC_VALUE, ADDR tempBuffer
invoke lstrcpy, addr finalBuffer, offset tempBuffer

mov ecx, 1
.while ecx < 100
push ecx

xor eax, eax
mov ebx, pMem
mov edx, temp
add edx, ecx
mov al, byte ptr [ebx+edx]

invoke wsprintf, addr tempBuffer,addr _hex,eax
invoke lstrlen, addr finalBuffer
invoke lstrcpy, addr finalBuffer[eax], addr tempBuffer

pop ecx
inc ecx
.endw

invoke SetDlgItemText, hWnd, TEXT_OUT, ADDR finalBuffer



please forgive the lack of clear coding... I'm not at that stage yet :)

-SLiver
Posted on 2002-01-03 03:03:46 by Sliver
I suggest you make all symbols that represent byte value in HEX
the same size.
Then you can avoid shifting look
so instead of:
0x1 0x23 0x0
0x23 0x1 0x23
that way:
0x01 0x23 0x00
0x23 0x01 0x23

I think it looks better.
Now to your problem.
You need to arrange data in rows. (That was question 3 in my post)
As I see from your example of how did you want the symbols to look, you need to make convertions in circles for each 16 bytes.
Inserting 13,10 after each iteration.
I'll write you an example if you can clarify for me:
Do you need to display all bytes from file or a particular (variable)
number of them?
Posted on 2002-01-03 03:37:09 by The Svin
Originally posted by The Svin
I suggest you make all symbols that represent byte value in HEX
the same size.
Then you can avoid shifting look
so instead of:
0x1 0x23 0x0
0x23 0x1 0x23
that way:
0x01 0x23 0x00
0x23 0x01 0x23

Not sure how to do this... can this be done more easily with the windows api? like wsprintf?


As I see from your example of how did you want the symbols to look, you need to make convertions in circles for each 16 bytes.
Inserting 13,10 after each iteration.
I'll write you an example if you can clarify for me:
Do you need to display all bytes from file or a particular (variable)
number of them?


I'm not exactly sure how to add 13,10 into the buffer either... I've only done the adding of 13,10 when defining a string to display...

right now the number is arbitary... I'm just getting it to work... I use 120 because it filles dialog box that I display the values in..

I figure I can display 16 hex values on a given row (and displaying 7 rows in the dislog box)

Sliver

ps. I hope I've helped clarify some things
Posted on 2002-01-03 04:03:52 by Sliver