News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

How do I create a manifest within the .asm file and embed it in the final exe?

Started by jimg, November 25, 2018, 08:35:47 AM

Previous topic - Next topic

jimg

The intent is to have only a .asm file, without any .rc file.  I usually create my controls and such in asm code rather than using a resource compiler.


I briefly asked about this in the thread http://masm32.com/board/index.php?topic=7526.msg82341#msg82341. Sharing values.

Rather than hijacking that thread any further, I'm starting the topic here for us manifest noobs.

TImoVJL said:

Quote from: TimoVJL on November 24, 2018, 11:11:07 PM
search -manifest:embed link.exe commandline option for latest linkers.
OPTION DOTNAME

.drectve SEGMENT INFO DISCARD
db "-subsystem:console "
db 34,"-manifestdependency:type=",39,"Win32",39
db " name=",39,"Microsoft.Windows.Common-Controls",39
db " version=",39,"6.0.0.0",39
db " processorArchitecture=",39,"*",39
db " publicKeyToken=",39,"6595b64144ccf1df",39
db " language=",39,"*",39,34
;db " -manifest:embed "
.drectve ENDS


1. I don't understand the purpose of using a name starting with a dot, is this required?
2. When searching the masm programmers reference manual, I could find no mention of DISCARD as an option to a SEGMENT statement.
3. I've never used a Segment statement, so a lot of this is pretty nebulous to me.
4. How does one use the option manifest:embed to point at the segment?

I'm using polink 8.00.02 in which the help says "MANIFEST[:{NO|EMBED[,ID=#]}]", so I called it with
/SUBSYSTEM:WINDOWS /RELEASE /MANIFEST:EMBED,ID=drectve
    (I also tried it with .drectve and without any ID)
     ( it looks like it might want a number for the ID, but I have no idea what that might be)

but using SigCheck from SysInternalsSuite,  I only got this in all attempts-

F:\WinAsm\Progs\Ascii\withlog\striped\Ascii.exe:
Verified: Unsigned
Link date: 12:27 PM 11/24/2018
Publisher: n/a
Company: n/a
Description: n/a
Product: n/a
Prod version: n/a
File version: n/a
MachineType: 32-bit
Manifest:
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>


So I'm only getting a stock manifest and not what I put in the code.

Clearly I'm making some noobish mistake here I can't seem to find.

Any enlightenment will be appreciated :)

jimg

In response to jj's post-
Quote from: jj2007 on November 25, 2018, 06:04:46 AM
Quote from: jimg on November 24, 2018, 03:49:54 PMI have searched in vain how to get around manifests, how do you do it without a resource file?

Jim,

It's not impossible but impractical, see the Weird problem with UpdateResource thread. You can indeed add a resource to an existing exe, but it requires elevation, i.e. you need to insert the admin password every time you build a project as a normal user. At that point, having a standard manifest.rc is much easier.

I'm not concerned about having to enter a password, so I'd still like to do it in code. 

hutch--

Jim,

We all have our own dispositions and while many find having to add a manifest a pain, with practice its easy enough to do if you use a resource compiler, either Pelle's or Microsoft's and with a resource compiler you can also add a version control block. Do both of these properly and you are close to free from crappy AV scanners, many of which will flag your binary as suspicious if it does not find both.

They were one of Microsoft's tricks to trash older programs so the user had to buy a new one. One mod they did made sense, even though it involved having to re-write many programs was the DEP that prevented code being stored and executed as data.

One of the great advantages of using RC.EXE is you can manually edit both the manifest and RC script before it is compiled into a resource and RC.EXE will also read a UNICODE script if you want to use exotic characters or symbols from unusual fonts.

jj2007

I did some tests, and this works fine with polink - and only with polink, the M$ linkers don't recognise the -embed:manifest, even version 14.10 doesn't like it:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  Inkey "This exe uses common controls version ", ComCtl32$()

  OPTION DOTNAME
  .drectve SEGMENT INFO
        db 34,"-manifestdependency:type='Win32'"
        db " name='Microsoft.Windows.Common-Controls'"
        db " version='6.0.0.0'"
        db " processorArchitecture='*'"
        db " publicKeyToken='6595b64144ccf1df'"
        db " language='*'", 34
        db " -manifest:embed "  ; polink only!
  .drectve ENDS
EndOfCode

jimg

Hutch-  Certainly a valid opinion, just not what I'm trying to figure out here.

jj-
using polink-
I found that the db" -manifest:embed" line did nothing.
Without /MANIFEST:EMBED switch on the polink command line, I did not get a manifest embeded.
With this switch, I get the stock manifest I showed above, whether or not I included the db line.

sinsi

You can use a link.exe switch, see http://masm32.com/board/index.php?topic=6046.msg64054#msg64054
Not sure of the link version you need though.

jj2007

For me, it works fine without any commandline fumbling. With polink only, though. Which version do you have? Mine is Pelles Linker, Version 8.00.2

jimg

Okay, I got it to work.   I had tried so many variations along the way I didn't see a change I made that was keeping it from working.

jimg

For those mystified like me, the .drectve sectin is defined in the PE Format specification -
https://docs.microsoft.com/en-us/windows/desktop/Debug/pe-format#the-drectve-section-object-only

QuoteThe .drectve Section (Object Only)

A section is a directive section if it has the IMAGE_SCN_LNK_INFO flag set in the section header and has the .drectve section name. The linker removes a .drectve section after processing the information, so the section does not appear in the image file that is being linked.

A .drectve section consists of a string of text that can be encoded as ANSI or UTF-8. If the UTF-8 byte order marker (BOM, a three-byte prefix that consists of 0xEF, 0xBB, and 0xBF) is not present, the directive string is interpreted as ANSI. The directive string is a series of linker options that are separated by spaces. Each option contains a hyphen, the option name, and any appropriate attribute. If an option contains spaces, the option must be enclosed in quotes. The .drectve section must not have relocations or line numbers.

jimg

And thank you TimoVJL.  What you told me was correct from the beginning.  I just fouled something up at the start and floundered for a while :(

Works with Polink.  I don't have any of the later Microsoft linkers to test with.


jimg

Also, it doesn't work with masm 6.14/6.15 as the assembler complains about the INFO entry in the SEGMENT line.  Works with UASM :)


hutch--

Urrrrgh,
When "masm 6.14/6.15" were introduced, manifests were not in common use.  :biggrin:

aw27

Quote from: hutch-- on November 26, 2018, 12:12:06 AM
Urrrrgh,
When "masm 6.14/6.15" were introduced, manifests were not in common use.  :biggrin:
Yeap, only the communist manifest has been invented at the time.  :lol:

jimg

Here's an interesting result---

I tried the program on https://www.virustotal.com/#/home/upload

Without the manifest, three virus checkers complain.
WITH the manifest, fifteen checkers complain.
???