The MASM Forum

Microsoft 64 bit MASM => MASM64 SDK => Topic started by: greenozon on March 23, 2024, 07:46:27 AM

Title: Compile IDA generated asm in MASM64
Post by: greenozon on March 23, 2024, 07:46:27 AM
hitting most probably some kid issues like

test.exe4.asm(1473) : error A2008:syntax error : near
test.exe4.asm(2505) : error A2008:syntax error : retn

those are coming from the IDA style like generating the

sub_1400016F0   proc near 
.........

                retn

sub_1400016F0   endp


are there any easy/generic way to calm masm64 down?
as I"ve got tons of those near/retn  cases...
Title: Re: Compile IDA generated asm in MASM64
Post by: sinsi on March 23, 2024, 08:34:51 AM
near textequ <>
retn textequ <ret>
Untested, but that's what I would try.
Title: Re: Compile IDA generated asm in MASM64
Post by: greenozon on March 23, 2024, 08:48:29 PM
Good point, sinsi, thanks!

I added this at the top of my .asm

include \masm64\include64\masm64rt.inc

near textequ <>
retn textequ <ret>



but masm64 still doesn't like it:


test.exe4.asm(3) : error A2008:syntax error : near
test.exe4.asm(977) : error A2008:syntax error : near



I need smth like in C/C++
#define near   //empty macros

anymore ideas?
Title: Re: Compile IDA generated asm in MASM64
Post by: greenozon on March 23, 2024, 08:58:47 PM
it turned out "near" is a reserved keyword in MASM64...
what is the the correct usage of it?
why does IDA generate an .asm that has broken usage?..
Title: Re: Compile IDA generated asm in MASM64
Post by: greenozon on March 23, 2024, 09:08:13 PM
Another question in the IDA regard:

algn_1400025CE:                         ; DATA XREF: .pdata:000000014035D00C↓o
                align 20h


masm64 complains:


: error A2189:invalid combination with segment alignment : 32

and I've got hundreds of these kind of issues...


Interestingly, it does not bark on this one:
                align 10h
Title: Re: Compile IDA generated asm in MASM64
Post by: sinsi on March 23, 2024, 09:35:48 PM
Quote from: greenozon on March 23, 2024, 08:58:47 PMit turned out "near" is a reserved keyword in MASM64...
what is the the correct usage of it?
why does IDA generate an .asm that has broken usage?..
You could try
option nokeyword:nearThat would disable any use of near
Title: Re: Compile IDA generated asm in MASM64
Post by: jj2007 on March 23, 2024, 10:29:47 PM
Quote from: sinsi on March 23, 2024, 08:34:51 AMnear textequ <>
retn textequ <ret>
Untested, but that's what I would try.

Another option is a replace all, deleting near completely and turting retn into ret. Preferably with an editor that allows full word search.
Title: Re: Compile IDA generated asm in MASM64
Post by: greenozon on March 23, 2024, 11:53:20 PM
Great! thanks for fast replies!

1) when I've added this to the top of .asm

option nokeyword:near

I've hit it as well...

test.exe4.asm(4) : error A2008:syntax error : near

so most probably the best way would be to just replace 'proc near' with 'proc'

this is not the best option (as I plan to have lots of iterations IDA -> produce .asm -> compile using masm64 -> ... again

interestingly that the retn is gone with TEXTEQU replacement :)
thanks
Title: Re: Compile IDA generated asm in MASM64
Post by: greenozon on March 23, 2024, 11:54:49 PM
hm-hm
MS guys shed some light, so the initial hint was right!

https://developercommunity.visualstudio.com/t/masm-option-nokeyword-should-accept-non-keywords-f/1057286 (https://developercommunity.visualstudio.com/t/masm-option-nokeyword-should-accept-non-keywords-f/1057286)

this works like a charm:

option NoKeyword:<near>

kudos!
Title: Re: Compile IDA generated asm in MASM64
Post by: greenozon on March 23, 2024, 11:57:12 PM
Now much bigger and painful error:

its declaration of Unicode strings in data segments..
there are thousands of strings like


asc_1401AAFF8:                          ; DATA XREF: sub_1400016F0+CEF↑o
                text "UTF-16LE", ', ',0

of course masm64 chokes on this..

any ideas how easily one could align existing IDA string syntax into masm64 compatible one?
provided that strings are Unicode, not a regular ANSI ones..
Title: Re: Compile IDA generated asm in MASM64
Post by: sinsi on March 24, 2024, 12:09:32 AM
Older versions of IDA used to write a macro to take care of unicode strings, check the ASM output file.
Title: Re: Compile IDA generated asm in MASM64
Post by: greenozon on March 24, 2024, 04:27:22 AM
wow, very interesting!
do you mean Ida embeds the body of the "text" macro when creating .asm output?
it is not the case in my case... (IDA 8.3)
Title: Re: Compile IDA generated asm in MASM64
Post by: greenozon on March 24, 2024, 04:32:24 AM
masm64 also doesn't like local vars in procedures named as
Format
Size

and some others
Title: Re: Compile IDA generated asm in MASM64
Post by: jj2007 on March 24, 2024, 10:25:06 AM
Write a little parser and replace all offending words with Masm64-compatible stuff. Btw reverse engineering is not allowed here :cool:
Title: Re: Compile IDA generated asm in MASM64
Post by: greenozon on March 24, 2024, 04:02:51 PM
10 years in prison or what?
do you know what I"m working on?