flat assembler
Message board for the users of flat assembler.

Index > Windows > Extract Icon from File

Author
Thread Post new topic Reply to topic
thirteen



Joined: 17 Oct 2004
Posts: 15
thirteen 06 Dec 2004, 17:51
Hello all,

I want to extract a Icon from a file (.exe .dll) and set this icon to another application. Theoretical it must look like this:

1. LoadLibrary
2. FindResource
3. SizeofResource
4. BeginUpdateResource
5. UpdateResource
6. EndUpdateSource


My problem is now the following, FindResource failed because i dont know lpName for a Icon. Here is the code i have written at this time:

Code:
include "%fasminc%\win32ax.inc"

.data
        IconSource      db "Icon.exe",0
        IconDestination db "Test.exe",0
        FileHandle      dd ?
        ResourceName    db "???",0
        ResourceHandle  dd ?
        ResourceSize    dd ?
        UpdateHandle    dd ?
        ResType         db "RT_ICON",0
        ResName         db "??? (it is not neccesary how it is named?!)",0


.code
start:
        invoke LoadLibrary,\
               IconSource
        mov dword [FileHandle], eax

        invoke FindResource,\
               dword [FileHandle],\
               ResourceName,\
               RT_ICON
        mov dword [ResourceHandle], eax

        invoke SizeofResource,\
               dword [FileHandle],\
               dword [ResourceHandle]
        mov dword [ResourceSize], eax

        invoke BeginUpdateResource,\
               IconDestination,\
               0
        mov dword [UpdateHandle], eax

        invoke UpdateResource,\
               dword [UpdateHandle],\
               ResType,\
               ResName,\
               LANG_ENGLISH,\
               dword [ResourceHandle],\
               dword [ResourceSize]

        invoke EndUpdateResource,\
               dword [UpdateHandle],\
               0

Exit:
        invoke ExitProcess,\
               0

.end start    


Hope someone can help me to get this code working, thx at this time!

regards, thirteen
Post 06 Dec 2004, 17:51
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 07 Dec 2004, 02:44
That's your problem - you don't know which icon exactly you want to extract from executable. It may contain many of them... Anyway, try using ExtractIcon to extract icon from file using its index.
Post 07 Dec 2004, 02:44
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 07 Dec 2004, 07:12
from PSDK

If all bits except the least significant 16 bits of the lpName or lpType parameter are zero, the low-order word specifies the integer identifier of the name or type of the given resource. Otherwise, those parameters are long pointers to null-terminated strings. If the first character of the string is a pound sign (#), the remaining characters represent a decimal number that specifies the integer identifier of the resource's name or type. For example, the string "#258" represents the integer identifier 258.

An application should reduce the amount of memory required for the resources by referring to them by integer identifier instead of by name.

An application can use FindResource to find any type of resource, but this function should be used only if the application must access the binary resource data when making subsequent calls to LockResource.

To use a resource immediately, an application should use one of the following resource-specific functions to find and load the resources in one call

well, i suggest you to get a PSDK from microsoft, it is FREE download.
Post 07 Dec 2004, 07:12
View user's profile Send private message Visit poster's website Reply with quote
thirteen



Joined: 17 Oct 2004
Posts: 15
thirteen 07 Dec 2004, 13:53
@mike.dld: Yes, I know ExtractIcon, but how to get the Resource Size then? I only want to extract first icon from the file...

@vbVeryBeginner: of course i have the psdk from microsoft, but it only say a example, and not the specific name for the icon. ("#???",0)
Post 07 Dec 2004, 13:53
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 08 Dec 2004, 06:50
well, if u did read the PSDK carefully, you might found the EnumResourceNames function under the resource reference.

i quote part of its saying.
The EnumResourceNames function searches a module for each resource of the specified type and passes either the name or the ID of each resource it locates to an application-defined callback function.

well, u could use the EnumResourceTypes first then EnumResourceNames to get all resources an executable or dll provided.

wonder why u didn't use these two function in ur .exe?

Quote:

mov dword [FileHandle], eax
;u could just simplify it
mov [FileHandle],eax
;coz mostly function in winapi r using dword as their parameter
Post 08 Dec 2004, 06:50
View user's profile Send private message Visit poster's website Reply with quote
thirteen



Joined: 17 Oct 2004
Posts: 15
thirteen 08 Dec 2004, 19:45
Hmm, well, I see this functions, but dont think they are not neccesary if someone know what name stands for icon resource. So can you give me an example how to handle with this callback? I know that it is nearly the same with createing a window...but i dont try to create a window yet Rolling Eyes

and i like mov dword [Name], eax more then simply mov [Name], eax. I only use this for better source looking (in my opinion) Very Happy

thx, thirteen
Post 08 Dec 2004, 19:45
View user's profile Send private message Reply with quote
gnomen



Joined: 07 Oct 2003
Posts: 13
gnomen 08 Dec 2004, 20:01
Quote:
... but dont think they are not neccesary if someone know what name stands for icon resource.


look at this page for all the predefined resource types:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/WindowsUserInterface/Resources/IntroductiontoResources/resourcereference/resourcetypes.asp[/quote]
Post 08 Dec 2004, 20:01
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 09 Dec 2004, 03:11
Quote:

FindResource failed because i dont know lpName for a Icon

Quote:

I see this functions, but dont think they are not neccesary if someone know what name stands for icon resource


the EnumResourceNames is basically to loop a particular resource type (RT_ICON) on an executable so that you could use its result as lpName or lpIconName pair with LoadIcon to get the handle for that Icon.

if u use ExtractIcon, u don't have to get the identifier for icon coz it is index based.
Post 09 Dec 2004, 03:11
View user's profile Send private message Visit poster's website Reply with quote
thirteen



Joined: 17 Oct 2004
Posts: 15
thirteen 09 Dec 2004, 14:38
ok, when i use ExtractIcon API i have the handle for the icon, but whats about the size i need for UpdateResource? I search for some example, and see some post at win32asm community forum, he asks the same question but not really a answer... Best would be if i see a working example...but dont find it yet.

thx, thirteen
Post 09 Dec 2004, 14:38
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 10 Dec 2004, 13:19
Quote:

but whats about the size i need for UpdateResource

did u notice the SizeofResource function?
Post 10 Dec 2004, 13:19
View user's profile Send private message Visit poster's website Reply with quote
thirteen



Joined: 17 Oct 2004
Posts: 15
thirteen 10 Dec 2004, 14:28
i did! but with ExtractIcon handle it dont work... this fails:
Quote:
hResInfo

Identifies the resource. This handle must be created by using the FindResource or FindResourceEx function.


thirteen
Post 10 Dec 2004, 14:28
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 11 Dec 2004, 05:53
Code:
HICON ExtractIcon(
  HINSTANCE hInst,          // instance handle
  LPCTSTR lpszExeFileName,  // file name
  UINT nIconIndex           // icon index
);
    


it would be nice if u plez elaborate ur problem Smile
did u have PSDK?
Post 11 Dec 2004, 05:53
View user's profile Send private message Visit poster's website Reply with quote
thirteen



Joined: 17 Oct 2004
Posts: 15
thirteen 13 Dec 2004, 18:02
i am sorry, i think we misunderstand us Smile yes, of course i have the api reference, i know how to handle ExtractIcon! But my problem now is that SizeofResource API dont work with handle of the icon get'n from ExtractIcon. OK, here is the code with the extracticon api, it fails on getting the size of the resource....:
Code:
include "%fasminc%\win32ax.inc"

.data
        ModuleHandle    dd ?
        IconSource      db "Icon.exe",0
        IconHandle      dd ?
        ResourceSize    dd ?
        UpdateFile      db "test.exe",0
        UpdateHandle    dd ?
        ResType         db "RT_ICON",0
        ResName         db "test",0

.code
start:

        invoke GetModuleHandle,\
               0
        mov dword [ModuleHandle], eax

        invoke ExtractIcon,\
               dword [ModuleHandle],\   ;module handle
               IconSource,\             ;extract icon from this
               0                        ;first icon
        mov dword [IconHandle], eax

        invoke SizeofResource,\
               dword [ModuleHandle],\
               dword [IconHandle]       ;resource handle:
                                        ;hResInfo
                                        ;Identifies the resource. This handle must be created by using
                                        ;the FindResource or FindResourceEx function.
        mov dword [ResourceSize], eax

        invoke BeginUpdateResource,\
               UpdateFile,\             ;update this file
               0                        ;change only icon, no other resource
        mov dword [UpdateHandle], eax

        invoke UpdateResource,\
               dword [UpdateHandle],\
               ResType,\                ;RT_ICON
               ResName,\
               LANG_ENGLISH,\
               dword [IconHandle],\
               dword [ResourceSize]

        invoke EndUpdateResource,\
               dword [UpdateHandle],\
               0

        invoke ExitProcess,\
               0

.end start    


sorry if i steal your time, but much thx for helping
Post 13 Dec 2004, 18:02
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 14 Dec 2004, 05:33
it should be
Code:
invoke GetModuleHandle,IconSource
invoke SizeofResource,\ 
           eax,\ 
           dword [IconHandle]       ;resource handle: 
                                        ;hResInfo 
                                        ;Identifies the resource. This handle must be created by using 
                                        ;the FindResource or FindResourceEx function. 
    

i try ur example, i guess u have to use the FindResource as remark by the PSDK Sad
so, i guess u need to EnumResourceNames
Post 14 Dec 2004, 05:33
View user's profile Send private message Visit poster's website Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 14 Dec 2004, 08:42
IIRC GetModuleHandle returns all the same values on NT systems so you'll get handle of you own module Wink
Post 14 Dec 2004, 08:42
View user's profile Send private message Visit poster's website ICQ Number 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.