flat assembler
Message board for the users of flat assembler.

Index > Windows > Problem with embedded resource / Buttons in WIN 7 style

Author
Thread Post new topic Reply to topic
CodeBreaker



Joined: 15 Oct 2019
Posts: 3
CodeBreaker
I'm relatively new to assembler coding and have no clue, what went wrong. I was playing around with the simple Window example (see full code below). I was trying to add a manifest.xml as embedded resource, to give the button the win 7 look. .

Here's the code:


Code:
; Example of 64-bit PE program

format PE64 GUI
entry start

section '.text' code readable executable

  start:
        sub     rsp,8*5         ; reserve stack for API use and make stack dqword aligned

        mov     r9d,0
        lea     r8,[_caption]
        lea     rdx,[_message]
        mov     rcx,0
        call    [MessageBoxA]

        mov     ecx,eax
        call    [ExitProcess]

section '.data' data readable writeable

  _caption db 'Win64 assembly program',0
  _message db 'Hello World!',0

section '.idata' import data readable writeable

  dd 0,0,0,RVA kernel_name,RVA kernel_table
  dd 0,0,0,RVA user_name,RVA user_table
  dd 0,0,0,0,0

  kernel_table:
    ExitProcess dq RVA _ExitProcess
    dq 0
  user_table:
    MessageBoxA dq RVA _MessageBoxA
    dq 0

  kernel_name db 'KERNEL32.DLL',0
  user_name db 'USER32.DLL',0

  _ExitProcess dw 0
    db 'ExitProcess',0
  _MessageBoxA dw 0
    db 'MessageBoxA',0
    



section '.rsrc' resource data readable

directory 24,manifest
  
resource manifest,\
         1,LANG_NEUTRAL,man
         
resdata man
         db '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',13,10
         db '<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">',13,10
         db '<assemblyIdentity name="x.x.x" processorArchitecture="x86" version="5.1.0.0" type="win32"/> ',13,10
         db '<description>no</description>',13,10
         db '<dependency>',13,10
         db '<dependentAssembly>',13,10
         db '<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*" />',13,10
         db '</dependentAssembly>',13,10
         db '</dependency>',13,10
         db '</assembly>',13,10
endres                                              
    



However, when compiling the code, an error occurs, saying: "Error: Illegal instruction. directory 24, manifest". What can I do?



I'm using Fasm 1.71 on a WIN 7.

Thanks in advance
Post 15 Oct 2019, 11:11
View user's profile Send private message Reply with quote
Walter



Joined: 26 Jan 2013
Posts: 143
Walter
Add the include that will pull in Resource.inc for the directory macro.

Code:
format PE64 GUI
entry start

include 'win64a.inc'

section '.text' code readable executable 
    
Post 15 Oct 2019, 14:15
View user's profile Send private message Reply with quote
CodeBreaker



Joined: 15 Oct 2019
Posts: 3
CodeBreaker
Walter, Thank you very much for your reply.

Yes, I forgot to include the file. I fixed it.

I also revised the manifest section, to make it more 64-Bit like.

Here's the new version. This fixed version is working fine and is also rendering the OK Button in WIN 7 style.
Code:

; Example of 64-bit PE program

format PE64 GUI
entry start

include 'win64a.inc'

section '.text' code readable executable

  start:
        sub     rsp,8*5         ; reserve stack for API use and make stack dqword aligned


        mov     r9d,0
        lea     r8,[_caption]
        lea     rdx,[_message]
        mov     rcx,0
        call    [MessageBoxA]

        mov     ecx,eax
        call    [ExitProcess]

section '.data' data readable writeable

  _caption db 'Win64 assembly program',0
  _message db 'Hello World!',0

section '.idata' import data readable writeable

  dd 0,0,0,RVA kernel_name,RVA kernel_table
  dd 0,0,0,RVA user_name,RVA user_table
  dd 0,0,0,0,0

  kernel_table:
    ExitProcess dq RVA _ExitProcess
    dq 0
  user_table:
    MessageBoxA dq RVA _MessageBoxA
    dq 0

  kernel_name db 'KERNEL32.DLL',0
  user_name db 'USER32.DLL',0

  _ExitProcess dw 0
    db 'ExitProcess',0
  _MessageBoxA dw 0
    db 'MessageBoxA',0
    



section '.rsrc' resource data readable

directory 24,manifest
  
resource manifest,\
         1,LANG_NEUTRAL,man
         
resdata man
db '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',13,10
db '<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">',13,10
db '<dependency>',13,10
db '   <dependentAssembly>',13,10
db '     <assemblyIdentity',13,10
db '       type="win32"',13,10
db '        name="Microsoft.Windows.Common-Controls" ',13,10
db '        version="6.0.0.0"',13,10
db '        publicKeyToken="6595b64144ccf1df" ',13,10
db '        language="*" ',13,10
db '        processorArchitecture="*"/>',13,10
db '    </dependentAssembly>',13,10
db '  </dependency>',13,10
db '  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">',13,10
db '    <security>',13,10
db '      <requestedPrivileges>',13,10
db '        <requestedExecutionLevel',13,10
db '          level="asInvoker" ',13,10
db '          uiAccess="false"/>',13,10
db '        </requestedPrivileges>',13,10
db '    </security>',13,10
db '  </trustInfo>',13,10
db ' </assembly>'
endres                                       
     




Thank you very much for your help.
Post 15 Oct 2019, 16:40
View user's profile Send private message Reply with quote
Walter



Joined: 26 Jan 2013
Posts: 143
Walter
See if this works in Windows 7. I'm using Windows 10, and the reference to comctl32 was not needed.

Code:
;*************
;* Msg64.asm *
;*************

format PE64 GUI 4.0
entry start

include 'win64a.inc'

section '.text' code readable executable

  start:

        sub     rsp,8*5
        invoke  InitCommonControls
        invoke  MessageBox,0,strMessage,strCaption,0
        invoke  ExitProcess,0

section '.data' data readable writeable

  strCaption db 'Msg64',0
  strMessage db 'Hello!',0


section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL',\
          comctl32,'COMCTL32.DLL'

  import kernel,\
         ExitProcess,'ExitProcess'

  import user,\
         MessageBox,'MessageBoxA'

  import comctl32,\
         InitCommonControls,'InitCommonControls'

section '.rsrc' resource data readable

  directory RT_MANIFEST,manifest

  resource manifest,1,LANG_NEUTRAL,man

  resdata man
    db '<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">'
    db '<dependency><dependentAssembly><assemblyIdentity '
    db 'type="win32" name="Microsoft.Windows.Common-Controls" '
    db 'version="6.0.0.0" processorArchitecture="*" '
    db 'publicKeyToken="6595b64144ccf1df" language="*" />'
    db '</dependentAssembly></dependency></assembly>'
   endres   
    
Post 15 Oct 2019, 18:49
View user's profile Send private message Reply with quote
CodeBreaker



Joined: 15 Oct 2019
Posts: 3
CodeBreaker
It works like a charm. That's perfect. Thank you very much indeed.
Post 15 Oct 2019, 19:15
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


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

Website powered by rwasa.