Exetools  

Go Back   Exetools > General > General Discussion

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-13-2005, 16:51
redbull redbull is offline
Friend
 
Join Date: Mar 2004
Posts: 160
Rept. Given: 17
Rept. Rcvd 5 Times in 4 Posts
Thanks Given: 3
Thanks Rcvd at 6 Times in 6 Posts
redbull Reputation: 5
Calculating relative jnz opcode sizes in a custom code generator

Hi Guys,

I have a question and I cant seem to find answers (even in the compiler e-books available on the web). I think it is a ID10T error on my side

My problem is this (Appologies for this being a little badly worded)

I have a code generator written in delphi.

Lets say I generate a simple routine with it

<-- snip -->
Start1:
(..stuff..)
dec eax
jnz Position1

(..stuff)

Position1:
(..stuff..)

dec ecx
jnz Start1
<-- snip -->

Ok now my problem is I want to create a generic routine where I specify just to create a JNZ instruction but I dont care (at first pass) exactly which
JNZRel instruction size to use. (because I dont know how far apart the code is yet).

As you know there are several kinds of JNZ (RelJnzAddr32 and RelJnzAddr8 etc)

RelJnzAddr8 = 0x75 <byte>
RelJnzAddr32 = 0x0f 0x82 <dword>

Now I have code to handle flagging certain parts of the instruction and being able to change them. It is a class of mine called TRelocationHelper. It works fine and no problems. I can work out the distance between the instructions and patch the correct bytes.

The concern is, of course, is how to resolve which instruction to use.

I want to be able to mark that JNZ instruction and then come back to it later in the compile phase and insert the right instruction there (for the correct relative offset size).

I am not even sure where to begin.

At the moment I am using all my relative instructions as ADDR32 size; But this is less than optimal!!

I use structure lists and pointers to keep track of which memory area the instrusctions are targeting and which bytes to change to patch the relative addresses. So inserting larger opcodes etc is not a problem becuase I will still know where they point to.

Please post a few links to help me shed light on this matter




Redbull
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opcode Table wilson bibe General Discussion 23 04-09-2015 06:00
Calculating the size in bytes of a C++ function yaa General Discussion 8 11-07-2007 09:15
opcode generator johnq General Discussion 4 01-02-2004 07:11


All times are GMT +8. The time now is 08:31.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )