Jump to content

Recommended Posts

Posted (edited)

I am trying to get a list of all the resources in a file using dll calls. I have come up with the following code but it isn't returning anything and I can't see why. I think I require the help of a dll expert as I'm not sure the parameter types are correct. Anybody able to take a look?

I ultimatly want to be able to find out the resource index from the name. The autoit functions seem to not work if resource names are strings which are not numbers only (or just work with negitive index).

Cheers

#include <Constants.au3>
#include <WinAPI.au3>

; Load the .exe whose resources you want to list
Local $ResourceFile = @SystemDir & "\shell32.dll"
Local $hExe = _WinAPI_LoadLibraryEx($ResourceFile, $LOAD_LIBRARY_AS_DATAFILE)

; Create callback function
Local $CallbackHandle = DLLCallbackRegister ("_EnumTypesFunc", "int", "int;int;lparam") 

; Find all the types in the resource $hExe
Local $Success = DllCall("user32.dll", "int", "EnumResourceTypes", "int", $hExe, "ptr", DllCallbackGetPtr($CallbackHandle), "lparam", 0)

; Delete callback function
DllCallbackFree($CallbackHandle)

; Unload the executable file whose resources were enumerated
_WinAPI_FreeLibrary($hExe)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func _EnumTypesFunc($hExe, $Type, $Param)

    ConsoleWrite("Type: " & $Type & @LF)

; Create callback function
    Local $CallbackHandle = DLLCallbackRegister ("_EnumNamesFunc", "int", "int;int;int;lparam")   

; Find the names of all resources of type $Type.
    Local $Success = DllCall("user32.dll", "int", "EnumResourceNames", "int", $hExe, "int", $Type, "ptr", DllCallbackGetPtr($CallbackHandle), "lparam", 0)

 
    ; Delete callback function
    DllCallbackFree($CallbackHandle)

    Return 1          ; Return 1 to continue enumeration
EndFunc

Func _EnumNamesFunc($hExe, $Type, $Name, $Param)

    ConsoleWrite("Name: " & $Name & @LF)

; Create callback function
    Local $CallbackHandle = DLLCallbackRegister ("_EnumLangsFunc", "int", "int;int;int;int;lparam")   

; Find the language of resource of type $Type and of name $Name.
    Local $Success = DllCall("user32.dll", "int", "EnumResourceLanguages", "int", $hExe, "int", $Type, "int", $Name, "ptr", DllCallbackGetPtr($CallbackHandle), "lparam", 0)

; Delete callback function
    DllCallbackFree($CallbackHandle)

    Return 1          ; Return 1 to continue enumeration
EndFunc

Func _EnumLangsFunc($hExe, $Type, $Name, $Lang, $Param)

    ConsoleWrite("Language: " & $Lang & @LF)

    Return 1          ; Return 1 to continue enumeration

EndFunc
Edited by adamski
Posted

The problem is that they are not exist in "user32.dll" ;] but "kernel32.dll" and you may also want to develop another approach to enumerate them because even though it seems right this script is doomed to run for ever, or until it'll eventually crash.

Posted

Authenticity:

"kernel32.dll"! How did I manage to miss that?! Thanks for pointing it out - I have it working now.

trancexx:

Thanks for pointing me to that. After downloading it I realised I had downloaded it before, probably when searching the forums before starting this topic. I had unfortunately forgotten about it and not actually unzipped it and tried it out. It's good work - wish I'd looked at it earlier.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...