Author Topic: mailto x64  (Read 1888 times)

Biterider

  • Member
  • ***
  • Posts: 254
  • ObjAsm32 - ObjAsm64
    • ObjAsm64
mailto x64
« on: March 12, 2018, 05:53:18 AM »
Hi
I'm having troubles with a simple line of code

Code: [Select]
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


AW

  • Member
  • *****
  • Posts: 1606
  • Let's Make ASM Great Again!
Re: mailto x64
« Reply #1 on: March 12, 2018, 06:42:36 AM »
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

  • Member
  • ***
  • Posts: 254
  • ObjAsm32 - ObjAsm64
    • ObjAsm64
Re: mailto x64
« Reply #2 on: March 12, 2018, 07:13:58 AM »
Hi
I copied the line of code 1 to 1 and unfortunately it fails again.

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

using

Code: [Select]
    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

  • Member
  • *****
  • Posts: 8893
  • Assembler is fun ;-)
    • MasmBasic
Re: mailto x64
« Reply #3 on: March 12, 2018, 08:33:30 AM »
It 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

  • Member
  • ***
  • Posts: 387
Re: mailto x64
« Reply #4 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.
Are you pondering what I'm pondering? It's time to take over the world ! - let's use ASSEMBLY...

Biterider

  • Member
  • ***
  • Posts: 254
  • ObjAsm32 - ObjAsm64
    • ObjAsm64
Re: mailto x64
« Reply #5 on: March 12, 2018, 07:01:58 PM »
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

  • Member
  • *****
  • Posts: 8893
  • Assembler is fun ;-)
    • MasmBasic
Re: mailto x64
« Reply #6 on: March 12, 2018, 09:27:31 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)

AW

  • Member
  • *****
  • Posts: 1606
  • Let's Make ASM Great Again!
Re: mailto x64
« Reply #7 on: March 12, 2018, 09:53:42 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

  • Member
  • *****
  • Posts: 8893
  • Assembler is fun ;-)
    • MasmBasic
Re: mailto x64
« Reply #8 on: March 12, 2018, 09:55:41 PM »
Anyway, real programmers don't use mapi.

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

AW

  • Member
  • *****
  • Posts: 1606
  • Let's Make ASM Great Again!
Re: mailto x64
« Reply #9 on: March 12, 2018, 09:58:14 PM »
Anyway, 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

  • Member
  • ***
  • Posts: 254
  • ObjAsm32 - ObjAsm64
    • ObjAsm64
Re: mailto x64
« Reply #10 on: March 16, 2018, 06:31:44 AM »
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

  • Member
  • *****
  • Posts: 8893
  • Assembler is fun ;-)
    • MasmBasic
Re: mailto x64
« Reply #11 on: March 16, 2018, 07:52:38 AM »
It crashes on Win7-64, i.e. it throws an exception in ShellExecuteExW :(

My version (identical source):
Code: [Select]
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:
Code: [Select]
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

  • Member
  • ***
  • Posts: 366
    • LetTheLightIn
Re: mailto x64
« Reply #12 on: March 16, 2018, 09:17:41 AM »
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:
Code: [Select]
\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
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

www.LetTheLight.in  My Github  Twitter

AW

  • Member
  • *****
  • Posts: 1606
  • Let's Make ASM Great Again!
Re: mailto x64
« Reply #13 on: March 16, 2018, 03:25:31 PM »
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

  • Member
  • *****
  • Posts: 8893
  • Assembler is fun ;-)
    • MasmBasic
Re: mailto x64
« Reply #14 on: March 16, 2018, 07:18:24 PM »
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
  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)