flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Specific FASM compatibility with MSVC generated assembly

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 17 Apr 2008, 11:45
Hello guys,

I have seem that MSVC usually generates an ASM code (MASM compatible) like this:

_num$ = 8
_outlen$ = 12
MyProc PROC

push esi
push edi
mov edi, DWORD PTR _num$[esp+4]
mov eax, DWORD PTR _outlen$[esp]
...
...

MyProc ENDP

Look at the local variable access like "_num$[esp+4]" and "_outlen$[esp]" which is equivalent to:

[esp + _num$ + 4]
[esp + _outlen$]

Which is (after substitution):

[esp + 8 + 4]
[esp + 12]


My question is if there is any MACRO in FASM that it's able to accept expressions like the above to access to local parameters:

_num$[esp+4]
_outlen$[esp]


Thanks in advance!!!
Post 17 Apr 2008, 11:45
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Apr 2008, 11:53
I don't think this is possible. what do you need it for?
Post 17 Apr 2008, 11:53
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 17 Apr 2008, 12:02
I usually convert some C code to assembly to include it in ASM source files and modify the ASM output.

So, it would be great if a macro can do the job instead of going line by line to replace it to FASM syntax.

Thanks,
Post 17 Apr 2008, 12:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 17 Apr 2008, 13:02
You need to catch all cases of memory instructions, mov/add/sub/etc.

I think I can be done, but for big files you might run out of memory.

Code:
macro mov dest,source {
  match =DWORD =PTR offset[reg],source \{
    ... ;just a framework idea, you can finish it off Wink
  \}
}    
Post 17 Apr 2008, 13:02
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Apr 2008, 13:09
can't you get NASM output? that is pretty close to FASM.

Otherwise, I suggest rewriting. MASM syntax is context-dependent bitch. For example "mov eax, something", this can be both memory access, or moving immediate value to eax, depending on how "something" is defined. Things like this can't be solved with some search-replace or macro trickery.
Post 17 Apr 2008, 13:09
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 17 Apr 2008, 13:15
Quote:

You need to catch all cases of memory instructions, mov/add/sub/etc.

I think I can be done, but for big files you might run out of memory.


Code:
macro mov dest,source {
match =DWORD =PTR offset[reg],source \{
... ;just a framework idea, you can finish it off
\}
}


Thanks a lot!! I don't have much knowledge of those advance macro definiton (only basic macros definition Sad )

I will be delight if you can continue the macro just for one case, so, I can continue it off. I'm a bit stuck (damn!)


Quote:

can't you get NASM output? that is pretty close to FASM.

Otherwise, I suggest rewriting. MASM syntax is context-dependent bitch. For example "mov eax, something", this can be both memory access, or moving immediate value to eax, depending on how "something" is defined. Things like this can't be solved with some search-replace or macro trickery.


Nothing, MSVC only outputs MASM compatible code.

Rewriting is quite painful. I already rewrite the output code, but there are so many "contants[esp]" access that it's a total nightmare to change them all. And we have a computer in front of us with the power of FASM macros to do painful works, right? Very Happy


Thanks!!!
Post 17 Apr 2008, 13:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 17 Apr 2008, 13:15
vid wrote:
... "mov eax, something", this can be both memory access, or moving immediate value to eax, depending on how "something" is defined. ...
Oh yeah, thanks for reminding me. I had forgotten just how terrible MASM really is. I have been spoiled with TASM ideal mode, and now fasm's only mode.
Post 17 Apr 2008, 13:15
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 17 Apr 2008, 13:17
vid wrote:
Things like this can't be solved with some search-replace or macro trickery.
I still think it can be solved, you can open a virtual section and place the code, then examine the opcode. This is done in the pushd macro included in the windows download.
Post 17 Apr 2008, 13:17
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Apr 2008, 13:33
Just trying to solve it is quite bad idea, for any purpose except macro practice Wink

MASM has such shitload of features that macro solution is not realistic
Post 17 Apr 2008, 13:33
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 17 Apr 2008, 13:37
vid wrote:
MASM has such shitload of features that macro solution is not realistic
Okay, but for the topic here the macro only needs to support the C compiler output. I think the output will be quite predictable and probably wouldn't use all the weird advanced features.
Post 17 Apr 2008, 13:37
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 17 Apr 2008, 14:41
Thanks guys for the information.

I know it's quite of shitty stuff, but it's also good for macro practise as "vid" says Wink

But cannot FASM do like a replace for:

constant_name$[esp

is replaced by:

[esp + constant_name$


I think that's the only thing that need to be done, right?

Thanks!
Post 17 Apr 2008, 14:41
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Apr 2008, 14:53
it can't
Post 17 Apr 2008, 14:53
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 17 Apr 2008, 15:12
alorent wrote:
Thanks guys for the information.

I know it's quite of shitty stuff, but it's also good for macro practise as "vid" says Wink

But cannot FASM do like a replace for:

constant_name$[esp

is replaced by:

[esp + constant_name$


I think that's the only thing that need to be done, right?

Thanks!
It can, that is what the 'match' is for, to separate the various bits into temporary equates and then you can place the parts back in a different order.
Post 17 Apr 2008, 15:12
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 17 Apr 2008, 15:36
Thanks revolution!!! I was starting of thinking the idea of coding a tool to manually search and replace...

I'm a bit stuck with the match command. Once I match the string, how can I use part of the matched string?

So, I match:

Myvar$[esp

now, how can I just get "Myvar$" to be able to construct:

[esp + Myvar$

If you can just give me any similar example, I will be delighted!

Thanks tons!
Post 17 Apr 2008, 15:36
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 17 Apr 2008, 15:39
Code:
macro mov dest,source {
  match x[reg],source\{
    mov dest,[reg+x]
  \}
  ...
  ;handle other cases not matched above
  ....
}    
Post 17 Apr 2008, 15:39
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 17 Apr 2008, 15:45
Thanks a lot revolution! You are my hero! Very Happy

Is there any way to create just a single case that matches all instructions?

I mean, there are also:

push var1$[esp]
dec var2$[esp]
add eax, var3$[esp]

etc...

Making cases for all types of instructions would be a nightmare, don't you think?

Thanks a lot for your fast help!
Post 17 Apr 2008, 15:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 17 Apr 2008, 15:47
Code:
irp instr,mov,sub,add,xor {
  macro instr dest,source \{
    match x[reg],source\\{
      instr dest,[reg+x]
    \\}
    ...
    ;handle other cases not matched above
    ....
  \}
}    
Post 17 Apr 2008, 15:47
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 17 Apr 2008, 15:55
Thanks revolution! I'm going to try that out and see how it goes!

THANKS!!!!!!!!
Post 17 Apr 2008, 15:55
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 17 Apr 2008, 16:40
Quote:
Thanks a lot revolution! You are my hero!
Quote:
Thanks revolution!...THANKS!!!!!!!!
Hmm, pretty much summarizes the feelings of people around here... Could you add more alorent? Like:

Alorent:
Quote:
I love you Revolution!
Post 17 Apr 2008, 16:40
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 17 Apr 2008, 16:48
Oh er, I am humbled by that. Remember that my handle is all lower case. It is not a proper name you know, just a handle with no meaning.
Post 17 Apr 2008, 16:48
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.