flat assembler
Message board for the users of flat assembler.

Index > Windows > How to embed an icon in the .asm source?

Author
Thread Post new topic Reply to topic
Meowthist



Joined: 30 Aug 2021
Posts: 3
Meowthist 30 Aug 2021, 22:16
Hello!
Could you help me please?
I have a small icon - only 125 bytes size. And I don't want to use the external file 'filename.ico', I would like just write a text in my source.asm file - I mean the data definition.

I want something like this:

Code:
icon main_icon,icon_data,myarray

myarray db 0,0,1,0,1,0,0,0,2,0,1,0,1,0,103,0,0,0,22,0,0,0,137,80,78
db 71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,1,0,0,0,1,0,1,3,0,0,0,102
db 188,58,37,0,0,0,3,80,76,84,69,214,58,242,88,100,57,17,0,0,0,31,73
db 68,65,84,120,1,237,193,1,1,0,0,8,2,160,254,175,238,70,41,48,0,0,0
db 0,0,0,0,0,207,45,33,0,0,1,132,95,242,171,0,0,0,0,73,69,78,68,174
db 66,96,130
    


I think I should modify the icon macro but I don't have enough knowledge for this. Could anyone please help?


Last edited by Meowthist on 31 Aug 2021, 02:50; edited 2 times in total
Post 30 Aug 2021, 22:16
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1040
Location: Russia
macomics 30 Aug 2021, 23:48
macro icon group,[label,icon_file]
{ common local count
count = 0
forward local data,size,position
label dd RVA data,size,0,0
virtual at 0
file icon_file:6,16
load size dword from 8
load position dword from 12
end virtual
data file icon_file:position,size
count = count+1
common local header
align 4
group dd RVA header,6+count*14,0,0
header dw 0,1,count
forward
file icon_file:6,12
dw label#.resid
common
align 4 }

This line includes the data in the program

It can be replaced with a construction of the following type

Code:
if icon_file eqtype ""
   data file icon_file:position,size
end if
    

//--------------
Code:
    label dd RVA data,size,0,0 
    virtual at 0
     file icon_file:6,16
     load size dword from 8
     load position dword from 12
    end virtual
    

This piece reads the location of the icon data and their length from the file header
It can be replaced with . . .
Code:
if icon_file eqtype ""
    label dd RVA data,size,0,0 
    virtual at 0
     file icon_file:14,8
     load size dword from 0
     load position dword from 4
    end virtual
else
    label dd RVA icon_file,icon_file.#sizeof,0,0 
end if
    


//-----------------
Code:
    file icon_file:6,12
    

This line adds a description of the icon in the resources
It can be replaced with . . .
Code:
if icon_file eqtype ""
  file icon_file:6,12
else
  dq icon_file#.header_data
  dd icon_file#.sizeof
end if
    


//------------------------
And then you can pass a label to your data array instead of the file name (or file name), and you should define two values for the array
Code:
  myarray db ... (any icon data) ...
  .sizeof = $ - myarray
  .header_data = (Icon header values, 8-byte)
    
Post 30 Aug 2021, 23:48
View user's profile Send private message Reply with quote
Meowthist



Joined: 30 Aug 2021
Posts: 3
Meowthist 31 Aug 2021, 01:31
Thanks so much!

Forgive me please, I didn't say that my icon data bytes are the whole content of the icon file.
Therefore .sizeof = $ - myarray - 22.

And .header_data are 8 bytes beginning from the 6th byte of the array, I figured out, great!


Last edited by Meowthist on 31 Aug 2021, 04:18; edited 2 times in total
Post 31 Aug 2021, 01:31
View user's profile Send private message Reply with quote
Meowthist



Joined: 30 Aug 2021
Posts: 3
Meowthist 31 Aug 2021, 02:49
Many thanks again!
I have just rewritten the code AND I SEE IT WORKS!

Code:
format PE GUI 4.0
include 'INCLUDE\win32a.inc'
ret

macro myicon group,[label] {
align 4
label dd RVA iconbody,103,0,0
iconbody db 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,1,0,0
db 0,1,0,1,3,0,0,0,102,188,58,37,0,0,0,3,80,76,84,69,214,58,242,88
db 100,57,17,0,0,0,31,73,68,65,84,120,1,237,193,1,1,0,0,8,2,160,254
db 175,238,70,41,48,0,0,0,0,0,0,0,0,207,45,33,0,0,1,132,95,242,171
db 0,0,0,0,73,69,78,68,174,66,96,130

align 4
group dd RVA header,20,0,0
header dw 0,1,1
db 0,0,2,0,1,0,1,0,103,0,0,0
dw label#.resid }

section '.rsrc' resource data readable
  directory 3,icons,14,group_icons
  resource icons,1,0,icon_data
  resource group_icons,17,0,main_icon
  myicon main_icon,icon_data    
Post 31 Aug 2021, 02:49
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.