dont worry
this is my last post today  ;)

i have this jump table :
dword @_0000
dword @_0001
dword @_0002
dword @_0003
dword @_0004
dword @_0005
dword @_0006

when i make the calcs to get my address :

movzx eax,word ptr
mov ebx,jump_table
shl eax,2
add ebx,eax
mov eax,dword ptr
                call eax

is there any way to know when the jump is invalid ?
i mean, outside, out of range or really invalid ??

ie: i am 1 byte dealign , if i jump ill be in the wrong place...

is there any way to detect that?

thanks again!!!
Posted on 2006-06-02 19:41:14 by GR33d
Greed by name Greed by ?Lol man
Maybe put the highest and lowest value into a registers and test them?

sub highest value jnz
test val,val ?
I'm a beginner so ..
Good luck
Posted on 2006-06-02 19:46:40 by gavin_
heh lol
no problem at all :)

im just having a brainstorm lol
and ure helping me out

my prob kinda is :
lets say that the right jump address is : 0040000
if im 1 byte dealign i would jump to : 0040001

i guess thats jusk asking too much but...

is there any way to know that im dealigned to the jump table? cause it is made of dwords, so i guess that may be something that we can do to know when we are dealigned ...

Posted on 2006-06-02 19:56:43 by GR33d
dword is 4 bytes so check for every 32?
Or check if it's an odd number?
Posted on 2006-06-02 20:00:42 by gavin_
I'm not quite sure I understand what you mean but here's my take on it.

I assume you want to grab a value of a dword aligned jumptable. By dealigned you mean that you would grab a part of one dword and a part of another inside that jumptable - so you basically mean: How do I know if I am dword aligned to access the correct value inside the jumptable. (uff ;))

You could use the following

mov eax, Value
add eax, 3 ; Align Value - 1
and eax, -4 ; Negative Align Value

Now eax is Aligned to a boundary of 4. (Rounded up)

Real Life example:

movzx eax,word ptr
mov ebx,jump_table
shl eax,2
add ebx,eax ; Here you are unsure if the value is dword aligned
add ebx, 3 ; Align Value - 1
and ebx, -4 ; Negative Align Value
mov eax,dword ptr
call eax

You should also add code checking for the upper and lower boundaries of your jumptable - surround your table by labels named JumpTableStart and JumpTableEnd and check ebx if it's inbetween those boundaries, that will ensure that you get valid data.
Posted on 2006-06-02 20:19:36 by JimmyClif
    Goodness me. I just cannot figure what the problem is.  What is all that shift'n and shuffle'n about?  If you want to align your jump table to a DWORD boundary, then use the ALIGN DWORD directive and be done with it.  See the sample code where the jump table starts correctly, even when the data address in not on a DWORD boundary.  Do a bounds check before you use the jump table and it will be hard to go wrong.  Ratch

DWORD @_0000
DWORD @_0001
DWORD @_0002
DWORD @_0003
DWORD @_0004
DWORD @_0005
DWORD @_0006

; ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл


  INVOKE ExitProcess,EAX

00000000 .DATA
00000000  00 BYTE 0
00000004  0000000C R DWORD @_0000
00000008  0000000C R DWORD @_0001
0000000C  0000000C R DWORD @_0002
00000010  0000000C R DWORD @_0003
00000014  0000000C R DWORD @_0004
00000018  0000000C R DWORD @_0005
0000001C  0000000C R DWORD @_0006

; ллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл
00000000 .CODE
00000000 START:
00000000  0F B7 06 MOVZX EAX,WORD PTR
00000003  8B 04 85 MOV EAX,
  00000004 R
0000000A  FF E0 JMP EAX

0000000C @_0000:
0000000C @_0001:
0000000C @_0002:
0000000C @_0003:
0000000C @_0004:
0000000C @_0005:
0000000C @_0006:

0000000C EXIT:
  INVOKE ExitProcess,EAX
0000000C  50   *     push  eax
0000000D  E8 00000000 E  *     call  ExitProcess
00000012 END START
Posted on 2006-06-02 22:25:47 by Ratch
Also, you don't have to move to EAX first - you can
"jmp dword ptr " or "call dword ptr "
Posted on 2006-06-03 03:38:01 by f0dder
    Right on.  I should have caught that myself.  Ratch
Posted on 2006-06-03 07:40:01 by Ratch
So, on the topic:

movzx eax,word ptr
cmp eax,(end_jump_table - jump_table)/4
jge @F
call dword ptr

Posted on 2006-06-03 12:05:06 by Ultrano
Now that's optimisation?   :)
Posted on 2006-06-03 12:48:16 by JimmyClif
In case you want max-speed (2-3 cycles faster), you'll have to trade-in some RAM:
- 256 dwords if you have no more than 256 functions
- 65536 dwords otherwise

But you'll need such speed (and the added complexity for some extra-speed) only if you're writing something like a good Java VM/emulator :)
Posted on 2006-06-03 13:35:01 by Ultrano

counting how much funcs tat i have in the jump table and checking if greather did the trick :)

dunno why i didnt think in that :P

Posted on 2006-06-04 08:42:21 by GR33d