News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

mailto x64

Started by Biterider, March 12, 2018, 05:53:18 AM

Previous topic - Next topic

Biterider

Hi
I'm having troubles with a simple line of code

invoke ShellExecute, 0, NULL, $OfsCStr("mailto:pepe@gmail.com"), NULL, NULL, SW_SHOWDEFAULT

It makes what it should under 32 bit, bit in x64 it fails with an exception.
I haven't found any useful help with Google. Maybe you have an indication of what's going wrong here.

Regards, Biterider


aw27

Biterider,
Interesting macro name $ofsCStr which I never heard about before.

However this works:
invoke ShellExecute, 0, NULL, chr$("mailto:pepe@gmail.com"), NULL, NULL, SW_SHOWDEFAULT when you include the masm64rt.inc, which we are believing was your idea.

Biterider

Hi
I copied the line of code 1 to 1 and unfortunately it fails again.


invoke CoInitializeEx, NULL, COINIT_APARTMENTTHREADED or COINIT_DISABLE_OLE1DDE
invoke ShellExecuteA, 0, NULL, chr$("mailto:pepe@gmail.com"), NULL, NULL, SW_SHOWDEFAULT


using


    chr$ MACRO dbdata:VARARG
      LOCAL tname,ptxt
      .data
        tname db dbdata,0
        ptxt dq tname
      .code
      EXITM <ptxt>
    ENDM


I would look into your code and exe to see if it is my system... I tested the code on 2 machines with 2 different mail clients (Thunderbird & Outlook).

Biterider

jj2007

Quote from: Biterider on March 12, 2018, 05:53:18 AMIt makes what it should under 32 bit, bit in x64 it fails with an exception.

Post the exe... this works fine:

include \Masm32\MasmBasic\Res\JBasic.inc
Init           ; OPT_64 1      ; put 0 for 32 bit, 1 for 64 bit assembly
  jinvoke ShellExecute, 0, 0, Chr$("mailto:pepe@gmail.com?Subject=Greetings%20from%20Assembler&Body=That%20was%20easy"), 0, 0, SW_SHOWDEFAULT
  Inkey Chr$("This code was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format")
EndOfCode


Project attached, requires Masm32, UAsm64 and MasmBasic (and nothing else :P).

Raistlin

See also on the old forum - http://www.masmforum.com/board/index.php?topic=6578.0 - might help.
Are you pondering what I'm pondering? It's time to take over the world ! - let's use ASSEMBLY...

Biterider

Hello
I tested JJ's code and mine on a third machine and both work fine.
I suspect now that the problem lies somewhere on my dev PC.
Thanks for your help.

Biterider

jj2007

Quote from: Raistlin on March 12, 2018, 04:13:48 PM
See also on the old forum - http://www.masmforum.com/board/index.php?topic=6578.0 - might help.

Draakie... hmmm... should we know this member? ;-)

Nice code btw. I've been inspired to Send mail with attachments. Attention Micros**t is trying to declare MAPISendMail obsolete, and replace it with MAPISendMailW, which will not work on Win7 and older. Redmond, we are watching you 8)

aw27

Quote from: jj2007 on March 12, 2018, 09:27:31 PM
Attention Micros**t is trying to declare MAPISendMail obsolete, and replace it with MAPISendMailW, which will not work on Win7 and older. Redmond, we are watching you 8)
They want you to be able to read subject lines like this one: ☁❄☃☀☺☂☹✝
which you could not using the obsolete mapi.
Anyway, real programmers don't use mapi, they work it out through winsock.

jj2007

Quote from: aw27 on March 12, 2018, 09:53:42 PMAnyway, real programmers don't use mapi.

Why does almost every post of you contain some form of insult? Too much spare time, José?

aw27

Quote from: jj2007 on March 12, 2018, 09:55:41 PM
Quote from: aw27 on March 12, 2018, 09:53:42 PMAnyway, real programmers don't use mapi.

Why does almost every post of you contain some form of insult? Too much spare time, José?
Not an insult, mapi is for VB, and script kids programmers. ASM programmers need it rough.
Anyway, it is easy to do as well and will provide a learning experience which you will not have using receipts prepared for lazy people.

Biterider

Hello
I still struggle with this trivial code.
It would be very helpful if someone could test the code and provide feedback.
I am getting the following error on Win10 Home Edition and Thunderbird as an email client.
Thanks!
Biterider

jj2007

It crashes on Win7-64, i.e. it throws an exception in ShellExecuteExW :(

My version (identical source):
000000014000100C   | BA 06 00 00 00            | mov edx,6                               |
0000000140001011   | 33 C9                     | xor ecx,ecx                             |
0000000140001013   | FF 15 6F 03 00 00         | call qword ptr ds:[<&CoInitializeEx>]   |
0000000140001019   | 41 BA 0A 00 00 00         | mov r10d,A                              | A:'\n'
000000014000101F   | 4C 89 54 24 28            | mov qword ptr ss:[rsp+28],r10           |
0000000140001024   | 45 33 D2                  | xor r10d,r10d                           |
0000000140001027   | 4C 89 54 24 20            | mov qword ptr ss:[rsp+20],r10           |
000000014000102C   | 45 33 C9                  | xor r9d,r9d                             |
000000014000102F   | 4C 8D 05 A3 01 00 00      | lea r8,qword ptr ds:[1400011D9]         | r8:"mailto:pepe@hotmail.com", 1400011D9:"mailto:pepe@hotmail.com"
0000000140001036   | 48 8D 15 97 01 00 00      | lea rdx,qword ptr ds:[1400011D4]        | rdx:"open", 1400011D4:"open"
000000014000103D   | 33 C9                     | xor ecx,ecx                             |
000000014000103F   | FF 15 4B 03 00 00         | call qword ptr ds:[<&ShellExecuteA>]    |


Your version:
0000000001151004 | 33 C9                             | xor ecx, ecx                      |
0000000001151006 | BA 06 00 00 00                    | mov edx, 6                        | edx:"open"
000000000115100B | FF 15 EF 0F 00 00                 | call qword ptr ds:[<&CoInitialize |
0000000001151011 | 33 C9                             | xor ecx, ecx                      |
0000000001151013 | 48 BA 20 20 15 01 00 00 00 00     | movabs rdx, test_shellexecute.115 | rdx:"open", 1152020:"open"
000000000115101D | 49 B8 25 20 15 01 00 00 00 00     | movabs r8, test_shellexecute.1152 | r8:"mailto:pepe@hotmail.com", 1152025:"mailto:pepe@hotmail.com"
0000000001151027 | 45 33 C9                          | xor r9d, r9d                      |
000000000115102A | 48 C7 44 24 20 00 00 00 00        | mov qword ptr ss:[rsp+20], 0      |
0000000001151033 | C7 44 24 28 0A 00 00 00           | mov dword ptr ss:[rsp+28], A      |
000000000115103B | FF 15 CF 0F 00 00                 | call qword ptr ds:[<&ShellExecute |


Stack alignment is OK and identical for both versions. Right now I am too tired to dig deeper, and can't see any significant differences here. A mystery 8)

fearless

I had a look at this and dived down the rabbit hole to see it returned exceptions after WaitForMultipleObjects down to NTWaitForMultipleObjects.

I built an example using Uasm with radasm for x64 and pretty much copied the code as is, and ran my copy and it worked ok, got a msgbox about no default mail handler and it opened internet explorer with address bar with the mailto string - so all seemed ok.

I compared both exes with CFF explorer to check imports etc matched, they did. Both showed as PE64. AMD64 as machine in file header was same, characteristics have one difference: Mine had the app can handle >2gb address space, whereas the Test_ShellExecute did not have this checked. Optional headers had a minor difference in DLLCharacteristics 8160 vs 8140 for Test_ShellExecute. My test app had a .data section no debug section - probably not the issue. I would guess something to do with the linker your using maybe?

Im using Microsoft (R) Incremental Linker Version 12.00.31101.0 with:
\UASM\Bin\LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /MACHINE:X64 /LIBPATH:"\UASM\Lib\x64" /OUT:"mailtest.exe" "mailtest.obj" "mailtest.res"

Not sure if that will help, hope it does

aw27

As fearless found and as JJ disassembly shows the file appears to have been linked with the switch /LARGEADDRESSAWARE:NO, which is something that should not be done in 64-bit unless there are reasons for that (which I never found to this date).

jj2007

Right, I just tested it and that switch makes it crash. Good point, José :t

I wonder, though, why it crashes; when using the switch, the exe gets loaded low, i.e. at 401000h like a 32-bit exe. And the 32-bit version doesn't crash. Can anybody see a good reason why ShellExecute can't handle 403004h?

Perhaps Mikl has an idea why his use of ShellExecute with /LARGEADDRESSAWARE:NO works but ours not?

With switch /LARGEADDRESSAWARE:NO:
000000000040100B   | CC                        | int3                                    |
000000000040100C   | 41 BA 0A 00 00 00         | mov r10d,A                              | r10d:&"P.-w", A:'\n'
0000000000401012   | 4C 89 54 24 28            | mov qword ptr ss:[rsp+28],r10           |
0000000000401017   | 45 33 D2                  | xor r10d,r10d                           | r10d:&"P.-w"
000000000040101A   | 4C 89 54 24 20            | mov qword ptr ss:[rsp+20],r10           |
000000000040101F   | 45 33 C9                  | xor r9d,r9d                             |
0000000000401022   | 4C 8D 05 DB 1F 00 00      | lea r8,qword ptr ds:[403004]            | ###### 403004:"mailto:pepe@gmail
0000000000401029   | 33 D2                     | xor edx,edx                             |
000000000040102B   | 33 C9                     | xor ecx,ecx                             |
000000000040102D   | FF 15 A5 21 00 00         | call qword ptr ds:[<&ShellExecuteA>]    |


No switch:
000000014000100B   | CC                        | int3                                    |
000000014000100C   | 41 BA 0A 00 00 00         | mov r10d,A                              | r10d:&"P.-w", A:'\n'
0000000140001012   | 4C 89 54 24 28            | mov qword ptr ss:[rsp+28],r10           |
0000000140001017   | 45 33 D2                  | xor r10d,r10d                           | r10d:&"P.-w"
000000014000101A   | 4C 89 54 24 20            | mov qword ptr ss:[rsp+20],r10           |
000000014000101F   | 45 33 C9                  | xor r9d,r9d                             |
0000000140001022   | 4C 8D 05 DB 1F 00 00      | lea r8,qword ptr ds:[140003004]         | ###### 140003004:"mailto:pepe@gmail
0000000140001029   | 33 D2                     | xor edx,edx                             |
000000014000102B   | 33 C9                     | xor ecx,ecx                             |
000000014000102D   | FF 15 A5 21 00 00         | call qword ptr ds:[<&ShellExecuteA>]


Btw putting the address into a register doesn't help - but PrintLine alias crt_printf has no problem:
  mov rsi, Chr$("mailto:pepe@gmail.com?Subject=Greetings%20from%20Assembler&Body=That%20was%20easy")
  PrintLine rsi
  jinvoke ShellExecute, 0, 0, rsi, 0, 0, SW_SHOWDEFAULT


So it's probably a bug design feature of ShellExecuteExW 8)