flat assembler
Message board for the users of flat assembler.

Index > Main > Can't perform calculations on addresses?

Author
Thread Post new topic Reply to topic
rangerelf



Joined: 30 Oct 2003
Posts: 1
Location: México
rangerelf
I'm currently writing a token interpreter using Fasm 1.49, and I'm having some trouble encoding execution tokens based on a declared label, which is the address of the routine who's token I wish to encode.

The token is a 32-bit code, where the top 2 bits have special functions and are shifted out of the token by the inner interpreter, and the remaining bits (after the two shifts) is the address to a dword-align function.

So, a token is created by something like:

dd (FunctionLabel shr 2) + bits

BUT, when I include something like this in the source:

dd (Bye shr 2) + $80000000 ; execute Bye

fasm returns the following message:

"Error: Invalid Expression".

and highlights the line.

What am I doing wrong? I've tried many different ways, up to defining a macro to do the calculations.

Any help will be much appreciated.

-gustavo
Post 30 Oct 2003, 00:59
View user's profile Send private message Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7796
Location: Kraków, Poland
Tomasz Grysztar
Such thing happens when you use output format that uses the relocatable labels, like PE. If you are using PE and don't plan to include the relocations in your program, you can use the solution that was provided here: http://board.flatassembler.net/topic.php?t=37#395.
Post 30 Oct 2003, 01:04
View user's profile Send private message Visit poster's website Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
I have this problem with an ELF file that I don't need to be relocated. However, format ELF at 0x00100000 gives me "extra characters on line". What can I do?
Post 18 Nov 2007, 11:03
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
If possible use "format elf executable" instead. I think there is no solution for object ELF since fasm always construct them relocatable.

Well, there is one, but no idea if you can trust the calculated address on run-time

Code:
format elf

section 'text' executable
  _start:

;  a = _start xor $deadbeef Fuck! we can't do that

  virtual at 0
    dd _start
    load  b dword from 0
  end virtual

  a = b xor $deadbeef ; Now we can Very Happy    
Post 18 Nov 2007, 13:30
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Code:
  virtual at 0 
    dd _start 
    load  b dword from 0 
  end virtual    

good catch! "load" shouldn't be allowed from relocated data. But i am not sure if this is possible in current FASM Sad
Post 18 Nov 2007, 13:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
> If possible use "format elf executable" instead.
Then sections doesn't seem to work. But never mind, I just fill in the data at run time.
Post 18 Nov 2007, 13:54
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Plue, but you can use segments instead, no?

vid, that trick is ancient, I even robbed it from cris' assembly listing generator. I think it would be very painfull for fasm to keep tracking of memory content to check when load can be allowed so this "backdoor" will hardly dissapear.

And looking at the FAQ I see another much simpler method (but disables relocations completely)
Code:
format elf

section 'text' executable
org $8040000
  _start:

  a = _start xor $deadbeef; Now works!    


But how do you ensure that section 'text' will be loaded at $8040000 is the question...
Post 18 Nov 2007, 14:30
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
But how do you ensure that section 'text' will be loaded at $8040000 is the question...

at runtime, "call / pop eax" and check address, no?
Post 18 Nov 2007, 15:20
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
But then, for what was useful to precalc the XOR operation if then it must be corrected by a delta?

You can also check and exit if the address is not the desired one but that is not a very descent program and would be better to calculate operations with labels at run-time instead.
Post 18 Nov 2007, 15:38
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
But then, for what was useful to precalc the XOR operation if then it must be corrected by a delta?

not corrected.

Quote:
You can also check and exit if the address is not the desired one but that is not a very descent program and would be better to calculate operations with labels at run-time instead.

that is what i meant. and of course, it is a stupid idea Smile
Post 18 Nov 2007, 16:01
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.