Sign in to follow this  
Followers 0
jvds

read from resources

2 posts in this topic

I'm trying to read from the resource of a exe file, but cant get to read the manifest info from the file
i got so far as locating the resource, but not reading its content

at the moment i only need to read the description located in the manifest like this
<description>Windows Shell</description> but if i can get at least the entire xml string it will be fine a swell

#include <WinAPIRes.au3>

consolewrite('$RT_MANIFEST='&$RT_MANIFEST&@crlf)

$hInstance = _WinAPI_LoadLibraryEx(@SystemDir&'\notepad.exe', $LOAD_LIBRARY_AS_DATAFILE)
consolewrite('$hInstance='&$hInstance&@crlf)
$hResource = _WinAPI_FindResource($hInstance, $RT_MANIFEST, 1);read manifest from file resource
consolewrite('$hResource='&$hResource&@crlf)

;tests
$hData = _WinAPI_LoadResource($hInstance, $hResource)
consolewrite('$hData='&$hData&@crlf)

_WinAPI_LoadIndirectString ( $hData )
consolewrite('$hData='&$hData&@crlf)

$sText = _WinAPI_LoadStringEx($hResource,'<description>')
consolewrite('$sText='&$sText&@crlf)

$sText = _WinAPI_LoadString($hResource,'<description>')
consolewrite('$sText='&$sText&@crlf)

 

Share this post


Link to post
Share on other sites



I've just followed the patterns i saw in the rest of the Resources examples, and got it working, i do not completely understand what i did after the ;test line to extract the xml file, but luckily it works good enough, now i used the xml reader creaded by dexto to read the values but i fail to read 2 values, any tips on how to correctly read them?

thnx

#include <WinAPIRes.au3>

$hInstance = _WinAPI_LoadLibraryEx(@SystemDir&'\notepad.exe', $LOAD_LIBRARY_AS_DATAFILE)
;consolewrite('$hInstance='&$hInstance&@crlf)
$hResource = _WinAPI_FindResource($hInstance, $RT_MANIFEST, 1);read manifest from file resource
;consolewrite('$hResource='&$hResource&@crlf)
Local $iSize = _WinAPI_SizeOfResource($hInstance, $hResource)

;tests
$hData = _WinAPI_LoadResource($hInstance, $hResource)
;consolewrite('$hData='&$hData&@crlf)

Local $pData = _WinAPI_LockResource($hData)
;consolewrite('$pData='&$pData&@crlf)

Local $tData = DllStructCreate('byte[' & $iSize & ']', $pData)
$out =  DllStructGetData($tData, 1)
;consolewrite('$out='&$out&@crlf)

$out = BinaryToString($out)
consolewrite('$out='&$out&@crlf)



;~ $out = FileRead('data.xml')
$out = StringReplace($out, @LF, '')
$out = StringSplit($out, @CR, 1)

MsgBox(0, 'DONE!!!', XMLget($out, 'description'))
MsgBox(0, 'DONE!!!', XMLget($out, 'trustInfo\security\requestedPrivileges\requestedExecutionLevel'))
MsgBox(0, 'DONE!!!', XMLget($out, 'application\windowsSettings\dpiAware'))

;how do i read this two?
MsgBox(0, 'DONE!!!', XMLget($out, 'assembly\assemblyIdentity\name'))
MsgBox(0, 'DONE!!!', XMLget($out, 'dependency\dependentAssembly\assemblyIdentity\type'))

Func XMLget($file, $Path); XMLget($file,'adc_database\currentconditions\realfeel')
    $Path = StringSplit($Path, '/\|', 0)
    $lastline = 0
    For $lvl = 1 To $Path[0] Step 1
        For $line = $lastline To $file[0] Step 1
            $lastline = $line
            $hstart = StringInStr($file[$line], '<' & $Path[$lvl] & '>', 0)
            $hstarta = StringInStr($file[$line], '<' & $Path[$lvl] & ' ', 0)
            If $hstart Or $hstarta Then
                If $lvl == $Path[0] Then
                    If $hstart Then
                        $end = StringInStr($file[$line], '</' & $Path[$lvl] & '>', 0)
                        If $end Then
                            $hstart = $hstart + StringLen('<' & $Path[$lvl] & '>')
                            Return StringMid($file[$line], $hstart, $end - $hstart)
                        EndIf
                    EndIf
                    If $hstarta Then
                        $end = StringInStr($file[$line], '/>', 0)
                        If $end Then
                            $hstarta = $hstarta + StringLen('<' & $Path[$lvl] & ' ')
                            $return = StringMid($file[$line], $hstarta, $end - $hstarta)
                            Return $return
                        EndIf
                        $ends = StringInStr($file[$line], '>', 0)
                        If $ends Then
                            $hstart = $ends + 1
                            $end = StringInStr($file[$line], '</' & $Path[$lvl] & '>', 0)
                            If $end Then
                                $return = StringMid($file[$line], $hstart, $end - $hstart)
                                Return $return
                            EndIf
                        EndIf
                    EndIf
                EndIf
                ContinueLoop 2
            EndIf
        Next
        If $line == $file[0] Then ExitLoop
    Next
    Return 'not found'
EndFunc ;==>XMLget

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0