Jump to content

(Zedna) Resources UDF + Encrypt & Decrypt


V3000
 Share

Recommended Posts

Hi Everyone

I Modified Zedna Project ( Resources UDF) , To Bring Secure To The Resources Files. :blink:^_^

Author .........: Zedna AutoIt MVPs(MVP)

Modified ......: V3000 AutoIt Member

This is The Original Resources UDF I Modified, Thanks To Zedna .

After Zedna Permission, ;) I Call iT [ Resources_v2.au3 ] ; The New Name of Project As Zedna Request [ Resources_Secure.au3 ] B)

The Complete iDea is:

1. The Resources is Encrypted, It's Completely Hard For One :) Want to Modified Your ExE File :)<= Extract Bitmap,Wave, etc. Or Modified String, And Put Another Resources.

2. Decrypt The Resources When You Want To Use iT With Only One Password . :mellow:

Functions Inside UDF:

_ResourceGet ( $ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4 )

_ResourceGetAsString ( $ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4 )

_ResourceGetAsStringW ( $ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4 )

_ResourceGetAsBytes ( $ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4 )

_ResourceGetAsImage ( $ResName, $ResType = $RT_RCDATA, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4 )

_ResourceGetAsBitmap ( $ResName, $ResType = $RT_RCDATA, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4 )

_ResourceSaveToFile ( $FileName, $ResName, $ResType = $RT_RCDATA, $ResLang = 0, $CreatePath = 0, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4 )

_ResourceSetImageToCtrl ( $CtrlId, $ResName, $ResType = $RT_RCDATA, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4, $hWnd_4Stretch )

_ResourcePlaySound ( $ResName, $Flag = 0, $DLL = -1, $ResType = 'sound', $Pass = '', $tALG_ID = $CALG_RC4 )

_SetBitmapToCtrl ( $CtrlId, $hBitmap, $hWnd_4Stretch )

Notes:

* The Default Encryption Method is $CALG_RC4 [RC4] .

* The AES Encryption Method in <Crypt.au3> Limited For Less Than 1MB, Bigger Than That It Will Be Corrupted ; I Think That is Bug. :)

* To Encrypt Files Use [Crypt Files.au3], You Can Even Decrypt It .

* If You Want To Encrypt BITMAP In $RT_BITMAP (Not In $RT_RCDATA) Then Use [Crypt Only Bitmap (BMP).au3] For Encrypt The Bitmap File .

* [Crypt Only Bitmap (BMP).au3] have ( Add_14_Byte ) After Encrypt And ( Remove_14_Byte ) Before Decrypt .

* You Can Encrypt BITMAP In $RT_RCDATA, Work Fine .

* If You Plan To Use The ' Stretch Mode ' Then Show The GUI After You Use The ' Stretch Mode '.

* WARNING: The Password is Case Sensitive .

Q. Why Use [Crypt Only Bitmap (BMP).au3] For Encrypt The Bitmap File, In $RT_BITMAP :

A. Windows Bitmap Resources => It Remove First 14 Byte, Struct BITMAPFILEHEADER & Save It In BITMAP Resources, :party:

. Yah, It Will Corrupt The Decrypt For Missing First 14 Byte. [Notes 4]

History:

2011-8-25
- Change The Name Of Project [ Resources_Secure.au3 ] As ( Zedna ) Request
- Fixed Using [ _WinAPI_FreeLibrary ] Before [ _Crypt_DecryptData ] ( Thanks To mesale0077 For Alert Me A Bug )

2011-8-26
- Fixed The Memory Leaks by [rover]

2011-8-27
- Add Stretch Mode by [mesale0077] Thanks.

Resource_Test.au3 - Complex Example Script Of Using UDF

; Author ........:  Zedna  AutoIt MVPs(MVP)
; Modified ......: [V3000] AutoIt Member
#AutoIt3Wrapper_Res_File_Add=TEST_TXT_1.txt.Encrypt, rt_rcdata, TEST_TXT_1
#AutoIt3Wrapper_Res_File_Add=TEST_RC_Bitmap.bmp.Encrypt, rt_rcdata, TEST_RC_Bitmap
#AutoIt3Wrapper_Res_File_Add=TEST_BIN_1.dat.Encrypt, rt_rcdata, TEST_BIN_1
#AutoIt3Wrapper_Res_File_Add=TEST_JPG_3.jpg.Encrypt, rt_rcdata, TEST_JPG_3
#AutoIt3Wrapper_Res_File_Add=TEST_BMP_2.bmp, rt_bitmap, TEST_BMP_2   ; The File is Not Encrypted
#AutoIt3Wrapper_Res_File_Add=TEST_BITMAP.bmp.Encrypt, rt_bitmap, TEST_BITMAP
#AutoIt3Wrapper_Res_File_Add=TEST_WAV_1.wav.Encrypt, sound, TEST_WAV_1
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_UseUpx=n ; For Fast Compiler, It's Only A Test!
#include "Resources_Secure.au3"
#include 
Global $GUI, $Pic1, $Pic2, $Pic3, $Pic4, $Pic5, $Pic6, $Label1, $Label2, $String, $hBmp, $Size1, $Size2
$GUI = GUICreate("Data From Encrypted Resources Example", 554, 380)
$Pic1 = GUICtrlCreatePic("", 8, 8, 265, 97)
$Pic2 = GUICtrlCreatePic("", 280, 8, 265, 97)
$Pic3 = GUICtrlCreatePic("", 8, 112, 265, 97)
$Pic4 = GUICtrlCreatePic("", 280, 112, 265, 97)
$Pic5 = GUICtrlCreatePic("", 56, 224, 169, 57)
$Pic6 = GUICtrlCreatePic("", 280, 216, 265, 97)
$Label1 = GUICtrlCreateLabel("", 20, 320, 380, 100)
$Label2 = GUICtrlCreateLabel("", 350, 320, 200, 100)

; GUISetState(@SW_SHOW) If You Plan To Use The ' Stretch Mode ' Then Show The GUI After You Use The ' Stretch Mode '.
; get encrypted string from resource
$String = _ResourceGetAsString("TEST_TXT_1", $RT_RCDATA, 0, -1, "V3000", $CALG_RC4) ;<= Default  $tALG_ID = $CALG_RC4
GUICtrlSetData($Label1, $String)

; set BMP image to picture control from encrypted resource bitmap
_ResourceSetImageToCtrl($Pic1, "TEST_BITMAP", $RT_BITMAP, -1, "V3000", $CALG_RC4) ;<= $Pass Set as "V3000" And It's In $RT_BITMAP, You Must Use [Crypt Only Bitmap (BMP).au3] For Encrypt The Bitmap File
; If You Want To Encrypt BITMAP In $RT_BITMAP (Not In $RT_RCDATA) Then Use [Crypt Only Bitmap (BMP).au3] For Encrypt The Bitmap File
_ResourceSetImageToCtrl($Pic2, "TEST_RC_Bitmap", $RT_RCDATA, -1, "V3000") ;<= Default  $tALG_ID = $CALG_RC4, And The Bitmap It's In $RT_RCDATA

; get bitmap from resource (as pointer)
$hBmp = _ResourceGet("TEST_BMP_2", $RT_BITMAP) ; TEST_BMP_2 <= It's Not Encrypted
; and use it for whatever you like
_SetBitmapToCtrl($Pic3, $hBmp, $GUI) ;<= This Func it's Not Support The Decrypt From _ResourceGet, Because It Will Return Full And Raw Bitmap File, Read  Line 242

; set JPG image to picture control from encrypted resource
_ResourceSetImageToCtrl($Pic4, "TEST_JPG_3", 10, -1, "V3000") ;<= JPG or BMP is Encrypted

; set image to picture control from external DLL resource
_ResourceSetImageToCtrl($Pic5, "#140", $RT_BITMAP, @SystemDir & "\shell32.dll", "", 0, $GUI) ;<= @SystemDir & "\shell32.dll" is Not Encrypt.
_ResourceSetImageToCtrl($Pic6, "#1", $RT_RCDATA, @ScriptDir & "\mesale0077.dll", "V3000", $CALG_RC4, $GUI) ; It's In DLL File And It's Encrypted, by [mesale0077]
GUISetState(@SW_SHOW) ; [V3000] Used After ' Stretch Mode ' If You Plant To Use It, by [mesale0077]

; get/use picture from resources as hImage type
$Size1 = _ResourceGetImageSize("TEST_BITMAP", $RT_BITMAP) ; TEST_BITMAP <= It's In $RT_BITMAP And It's Encrypted, <= With [Crypt Only Bitmap (BMP).au3]
$Size2 = _ResourceGetImageSize("TEST_JPG_3") ;<= JPG Was Encrypted, See Line 68 about The $Pass.
GUICtrlSetData($Label2, $Size1 & @CRLF & $Size2)

; save binary data or another type (image) from encrypted resource to file and get its size in bytes
$Size1 = _ResourceSaveToFile(@ScriptDir & "\TEST_BIN_1_SaveToFile.dat", "TEST_BIN_1", 10, 0, 8, -1, "V3000") ; $RT_RCDATA = 10
$Size2 = _ResourceSaveToFile(@ScriptDir & "\TEST_RC_Bitmap_SaveToFile.bmp", "TEST_RC_Bitmap", $RT_RCDATA, 0, 8, -1, "V3000")

; save binary data from encrypted resource to file (create not existing directory) '?
_ResourceSaveToFile(@ScriptDir & "\SaveToFile\NoExDr_TEST_BIN_1_SaveToFile.dat", "TEST_BIN_1", $RT_RCDATA, 0, 1, -1, "V3000")
_ResourceSaveToFile(@ScriptDir & "\SaveToFile\NoExDr_TEST_BITMAP_SaveToFile.bmp", "TEST_BITMAP", $RT_BITMAP, 0, 1, -1, "V3000")

; play WAV from resource (sync/async)
_ResourcePlaySound("TEST_WAV_1", 0, -1, 'sound', "V3000") ; 'SOUND' Or 'WAVE' It's Work Fine.
_ResourcePlaySound("TEST_WAV_1", $SND_ASYNC, -1, 'sound', "V3000") ;<= TEST_WAV_1 is Encrypted

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

Func _ResourceGetImageSize($ResName, $ResType = 10) ; $RT_RCDATA = 10
    ; get/use picture from resources as hImage type
    Local $hImage = _ResourceGetAsImage($ResName, $ResType, 0, -1, "V3000"); <= The Resources is Encrypt.
    _GDIPlus_Startup()
    Local $Width = _GDIPlus_ImageGetWidth($hImage)
    Local $Height = _GDIPlus_ImageGetHeight($hImage)
    _GDIPlus_Shutdown()

    Return "Size of " & $ResName & " is: " & $Width & "x" & $Height
EndFunc   ;==>_ResourceGetImageSize

Resources_Secure.zip - UDF + Examples + Sample Encrypt Resource Data For Examples

au3.user.calltips.api

au3.userudfs.properties

Crypt Files.au3

Crypt Only Bitmaps (BMP).au3

ReadMe.txt

Resources_Secure.au3

Examples\gif-Green-UFO.gif.Encrypt

Examples\Resource_Test.au3

Examples\Resource_Test_Ani_GIF.au3

Examples\Resource_Test_IE_It_Can't_Be_Secure_It.au3

Examples\Resource_Test_Min_1.au3

Examples\Resource_Test_Min_2.au3

Examples\test_1.gif

Examples\test_1.htm

Examples\TEST_BIN_1.dat.Encrypt

Examples\TEST_BITMAP.bmp.Encrypt

Examples\TEST_BMP_2.bmp

Examples\TEST_JPG_3.jpg.Encrypt

Examples\TEST_RC_Bitmap.bmp.Encrypt

Examples\TEST_TXT_1.txt.Encrypt

Examples\TEST_WAV_1.wav.Encrypt

Enjoy iT!

Resources_Secure.zip

Last Number Of Downloads: 40 + 19 + 17

Edited by V3000
Link to comment
Share on other sites

@V3000

Feel free to use/copy/modify my Resources UDF.

But your name Resources_v2 denotes some version relation to my Resources UDF.

Please can you just use some other name better relative to your modification?

My idea for better name for your derived UDF:

Resources_Secure, ResourcesSecure

Resources_Crypt, ResourcesCrypt

Resources_Pwd, ResourcesPwd

...

I have no versioning in my Resources UDF

so it can be confusing when people will ask questions about Resources UDF

and I will not know if they use mine or yours.

Your modification seems to be nice so I will probably incorporate it in some manner to my Resources in the future if you don't mind.

Thanks for sharing.

Edited by Zedna
Link to comment
Share on other sites

hi V3000

new Resources UDF

exe file no problem but dll file dont read ,new Resources UDF does not work in my pc (probably xp) maybe work w7 or vista

and attached this udf reading dll ,attached this (resources.au3) worked in my pc

please Can you add your code in this udf ,Can you edit the attached file

" _Crypt_DecryptData ",

..,.,.,..,$Pass = '', $tALG_ID = $CALG_RC4) your code

#include "resources.au3"
Global $gui, $pic1
$gui = GUICreate("Data from resources simple example 1", 400, 150)
$pic1 = GUICtrlCreatePic("", 0, 0, 400, 150)
 _ResourceSetImageToCtrl($pic1, "#1", $RT_RCDATA,@ScriptDir & "\MeeyDll.dll");can you add ,your code this code worked
GUISetState(@SW_SHOW)

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

thank you now

Sure ; Check The History in First Post . :mellow:

Fixed The Memory Leaks by [rover]
Link to comment
Share on other sites

hi V3000

nice code

changed

ı think new your udf

; 

#include-once
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <Memory.au3>
#include <Crypt.au3>
; Author ........:  Zedna  AutoIt MVPs(MVP) [http://www.autoitscript.com/forum/topic/51103-resources-udf/]
; Modified ......: [V3000] AutoIt Member    [http://www.autoitscript.com/forum/topic/132160-zedna-resources-udf-encrypt-decrypt/]
; Fixed The Memory Leaks by [rover]

Global Const $RT_CURSOR = 1
Global Const $RT_BITMAP = 2
Global Const $RT_ICON = 3
Global Const $RT_MENU = 4
Global Const $RT_DIALOG = 5
Global Const $RT_STRING = 6
Global Const $RT_FONTDIR = 7
Global Const $RT_FONT = 8
Global Const $RT_ACCELERATOR = 9
Global Const $RT_RCDATA = 10
Global Const $RT_MESSAGETABLE = 11
Global Const $RT_GROUP_CURSOR = 12
Global Const $RT_GROUP_ICON = 14
Global Const $RT_VERSION = 16
Global Const $RT_DLGINCLUDE = 17
Global Const $RT_PLUGPLAY = 19
Global Const $RT_VXD = 20
Global Const $RT_ANICURSOR = 21
Global Const $RT_ANIICON = 22
Global Const $RT_HTML = 23
Global Const $RT_MANIFEST = 24
Global Const $SND_RESOURCE = 0x00040004
Global Const $SND_SYNC = 0x0
Global Const $SND_ASYNC = 0x1
Global Const $SND_NODEFAULT = 0x2 ; [V3000]
Global Const $SND_MEMORY = 0x4
Global Const $SND_LOOP = 0x8
Global Const $SND_NOSTOP = 0x10
Global Const $SND_NOWAIT = 0x2000
Global Const $SND_PURGE = 0x40
Global $hInstance

; [V3000] If $Pass <> "" Then ( File is Encrypt <= $tALG_ID ), The File is Encrypted, Decrypted And Continue _ResourceGet()
Func _ResourceGet($ResName, $ResType = 10, $ResLang = 0, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4) ; $RT_RCDATA = 10 ; [V3000] $Pass , $tALG_ID
    Local Const $IMAGE_BITMAP = 0
    Local $hBitmap, $InfoBlock, $GlobalMemoryBlock, $MemoryPointer, $ResSize

    If $DLL = -1 Then
        $hInstance = _WinAPI_GetModuleHandle("")
    Else
        Local Const $LOAD_LIBRARY_AS_DATAFILE = 0x00000002
        Local Const $LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040
        Local Const $LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020
        Local $iFlags
        If @OSVersion = 'WIN_VISTA' Or @OSVersion = 'WIN_7' Then ; [V3000] OS Check ---\/
            $iFlags = $LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE + $LOAD_LIBRARY_AS_IMAGE_RESOURCE
        Else
            $iFlags = $LOAD_LIBRARY_AS_DATAFILE
        EndIf ; [V3000] ---^
        $hInstance = _WinAPI_LoadLibraryEx($DLL, $iFlags)
    EndIf
    If $hInstance = 0 Then Return SetError(1, 0, 0)

    If $ResType = $RT_BITMAP And StringLen($Pass) = 0 Then
        $hBitmap = _WinAPI_LoadImage($hInstance, $ResName, $IMAGE_BITMAP, 0, 0, 0)
        If @error Then Return SetError(2, 0, 0)
        Return $hBitmap ; returns handle to Bitmap
    EndIf
    ; [V3000] If $ResType A String as (WAVE, SOUND) etc. ---\/
    Local $TResName = "wstr"
    If IsNumber($ResName) Then $TResName = "int"
    Local $TResType = "wstr"
    If IsNumber($ResType) Then $TResType = "int"
    $InfoBlock = DllCall("kernel32.dll", "ptr", "FindResourceExW", "ptr", $hInstance, $TResType, $ResType, $TResName, $ResName, "short", $ResLang)
    ; [V3000]---^
    If @error Then Return SetError(3, 0, 0)
    $InfoBlock = $InfoBlock[0]
    If $InfoBlock = 0 Then Return SetError(4, 0, 0)

    $ResSize = DllCall("kernel32.dll", "dword", "SizeofResource", "ptr", $hInstance, "ptr", $InfoBlock)
    If @error Then Return SetError(5, 0, 0)
    $ResSize = $ResSize[0]
    If $ResSize = 0 Then Return SetError(6, 0, 0)

    $GlobalMemoryBlock = DllCall("kernel32.dll", "ptr", "LoadResource", "ptr", $hInstance, "ptr", $InfoBlock)
    If @error Then Return SetError(7, 0, 0)
    $GlobalMemoryBlock = $GlobalMemoryBlock[0]
    If $GlobalMemoryBlock = 0 Then Return SetError(8, 0, 0)

    $MemoryPointer = DllCall("kernel32.dll", "ptr", "LockResource", "ptr", $GlobalMemoryBlock)
    If @error Then Return SetError(9, 0, 0)
    $MemoryPointer = $MemoryPointer[0]
    If $MemoryPointer = 0 Then Return SetError(10, 0, 0)

    ; [V3000]---\/
    Local $struct = DllStructCreate("byte[" & $ResSize & "]", $MemoryPointer)
    Local $bBinary = DllStructGetData($struct, 1)
    If StringLen($Pass) <> 0 Then
        $bBinary = _Crypt_DecryptData($bBinary, $Pass, $tALG_ID)
        $ResSize = BinaryLen($bBinary)
        If $ResSize = 0 Then Return SetError(1, 0, 0)
        $MemoryPointer = _MemGlobalAlloc($ResSize, $GMEM_FIXED)
        If @error Or Not $MemoryPointer Then Return SetError(2, 0, 0)
        DllStructSetData(DllStructCreate("byte[" & $ResSize & "]", _MemGlobalLock($MemoryPointer)), 1, $bBinary)
        If @error Then
            _MemGlobalUnlock($MemoryPointer)
            _MemGlobalFree($MemoryPointer)
            Return SetError(3, 0, 0)
        EndIf
        _MemGlobalUnlock($MemoryPointer)
        $struct = 0
        $bBinary = 0
    EndIf
    SetExtended($ResSize)
    Return $MemoryPointer
EndFunc   ;==>_ResourceGet

; for ANSI strings
Func _ResourceGetAsString($ResName, $ResType = 10, $ResLang = 0, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4) ; $RT_RCDATA = 10 ; [V3000] $Pass , $tALG_ID
    Local $ResPointer, $ResSize, $struct, $Data

    $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL, $Pass, $tALG_ID)
    If @error Then
        SetError(1, 0, 0)
        Return ''
    EndIf
    $ResSize = @extended
    $struct = DllStructCreate("char[" & $ResSize & "]", $ResPointer)
    $Data = DllStructGetData($struct, 1) ; returns string
    If $DLL <> -1 Then _WinAPI_FreeLibrary($hInstance) ; by [rover]
    Return SetError(@error, 0, $Data)
EndFunc   ;==>_ResourceGetAsString

; for Unicode strings (Widechar)
Func _ResourceGetAsStringW($ResName, $ResType = 10, $ResLang = 0, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4) ; $RT_RCDATA = 10 ; [V3000] $Pass , $tALG_ID
    Local $ResPointer, $ResSize, $struct, $Data

    $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL, $Pass, $tALG_ID)
    If @error Then
        SetError(1, 0, 0)
        Return ''
    EndIf
    $ResSize = @extended
    $struct = DllStructCreate("wchar[" & $ResSize & "]", $ResPointer)
    $Data = DllStructGetData($struct, 1) ; returns string
    If $DLL <> -1 Then _WinAPI_FreeLibrary($hInstance) ; by [rover]
    Return SetError(@error, 0, $Data)
EndFunc   ;==>_ResourceGetAsStringW

; _ResourceGetAsBytes() doesn't work for RT_BITMAP type
; because _ResourceGet() returns hBitmap instead of memory pointer in this case
Func _ResourceGetAsBytes($ResName, $ResType = 10, $ResLang = 0, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4) ; $RT_RCDATA = 10 ; [V3000] $Pass , $tALG_ID
    Local $ResPointer, $ResSize

    $ResPointer = _ResourceGet($ResName, $ResType, $ResLang, $DLL, $Pass, $tALG_ID)
    If @error Then Return SetError(1, 0, 0)
    $ResSize = @extended
    Return DllStructCreate("byte[" & $ResSize & "]", $ResPointer) ; returns struct with bytes
EndFunc   ;==>_ResourceGetAsBytes

; returned hImage can be used in many GDI+ functions:
; $width =  _GDIPlus_ImageGetWidth ($hImage)
; $height = _GDIPlus_ImageGetHeight($hImage)
Func _ResourceGetAsImage($ResName, $ResType = 10, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4) ; $RT_RCDATA = 10 ; [V3000] $Pass , $tALG_ID
    Local $ResData, $nSize, $hData, $pData, $pStream, $hImage

    $ResData = _ResourceGet($ResName, $ResType, 0, $DLL, $Pass, $tALG_ID)
    If @error Then Return SetError(1, 0, 0)
    $nSize = @extended
    _GDIPlus_Startup()

    If $ResType = $RT_BITMAP And StringLen($Pass) = 0 Then
        ; $ResData is hBitmap type
        $hImage = _GDIPlus_BitmapCreateFromHBITMAP($ResData)
    Else
        ; $ResData is memory pointer
        ; thanks ProgAndy
        $hData = _MemGlobalAlloc($nSize, 2)
        $pData = _MemGlobalLock($hData)
        _MemMoveMemory($ResData, $pData, $nSize)
        _MemGlobalUnlock($hData)
        $pStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "ptr", $hData, "int", 1, "ptr*", 0)
        $pStream = $pStream[3]
        $hImage = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromStream", "ptr", $pStream, "ptr*", 0)
        $hImage = $hImage[2]
        _WinAPI_DeleteObject($pStream)
        ; next line must be commented otherwise animated GIFs will not work
        ;_MemGlobalFree($hData)
    EndIf

    Return $hImage ; hImage type
EndFunc   ;==>_ResourceGetAsImage

Func _ResourceGetAsBitmap($ResName, $ResType = 10, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4) ; $RT_RCDATA = 10 ; [V3000] $Pass , $tALG_ID
    Local $hImage = _ResourceGetAsImage($ResName, $ResType, $DLL, $Pass, $tALG_ID)
    If @error Then Return SetError(1, 0, 0)
    _GDIPlus_Startup()
    Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    Return $hBitmap ; hBitmap type
EndFunc   ;==>_ResourceGetAsBitmap

Func _ResourceSaveToFile($FileName, $ResName, $ResType = 10, $ResLang = 0, $CreatePath = 0, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4) ; $RT_RCDATA = 10 ; [V3000] $Pass , $tALG_ID
    Local $ResStruct, $ResSize, $FileHandle, $hImage

    If $CreatePath Then $CreatePath = 8 ; mode 8 = Create directory structure if it doesn't exist in FileOpen()

    If $ResType = $RT_BITMAP Then
        ; workaround: for RT_BITMAP _ResourceGetAsBytes() doesn't work so use _ResourceGetAsImage()
        $hImage = _ResourceGetAsImage($ResName, $ResType, $DLL, $Pass, $tALG_ID) ; Forgotten The $DLL
        If @error Then Return SetError(10, 0, 0)

        ; create filepath if doesn't exist
        $FileHandle = FileOpen($FileName, 2 + 16 + $CreatePath)
        If @error Then Return SetError(11, 0, 0)
        FileClose($FileHandle)
        If @error Then Return SetError(12, 0, 0)
        _GDIPlus_Startup()
        _GDIPlus_ImageSaveToFile($hImage, $FileName)
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        $ResSize = FileGetSize($FileName)
    Else
        ; standard way
        $ResStruct = _ResourceGetAsBytes($ResName, $ResType, $ResLang, $DLL, $Pass, $tALG_ID)
        If @error Then Return SetError(1, 0, 0)
        $ResSize = DllStructGetSize($ResStruct)

        $FileHandle = FileOpen($FileName, 2 + 16 + $CreatePath)
        If @error Then Return SetError(2, 0, 0)
        FileWrite($FileHandle, DllStructGetData($ResStruct, 1))
        If @error Then Return SetError(3, 0, 0)
        FileClose($FileHandle)
        If @error Then Return SetError(4, 0, 0)
    EndIf

    Return $ResSize
EndFunc   ;==>_ResourceSaveToFile

Func _ResourceSetImageToCtrl($Wnd,$CtrlId, $ResName, $ResType = 10, $DLL = -1, $Pass = '', $tALG_ID = $CALG_RC4) ; $RT_RCDATA = 10 ; [V3000] $Pass , $tALG_ID
    
    $ResData = _ResourceGet($ResName, $ResType, 0, $DLL, $Pass, $tALG_ID)
    If @error Then Return SetError(1, 0, 0)
    $nSize = @extended

    If $ResType = $RT_BITMAP And StringLen($Pass) = 0 Then ; [V3000] _ResourceGet($RT_BITMAP + $Pass) = Read Full And Raw Bitmap File, That Will Not Work With _SetBitmapToCtrl.
        _SetBitmapToCtrl($Wnd,$CtrlId, $ResData)
        If @error Then Return SetError(2, 0, 0)
    Else
        ; thanks ProgAndy
        ; for other types than BITMAP use GDI+ for converting to bitmap first
        $hData = _MemGlobalAlloc($nSize, 2)
        $pData = _MemGlobalLock($hData)
        _MemMoveMemory($ResData, $pData, $nSize)
        _MemGlobalUnlock($hData)
        $pStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "ptr", $hData, "int", 1, "ptr*", 0)
        $pStream = $pStream[3]
        _GDIPlus_Startup()
        $pBitmap = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromStream", "ptr", $pStream, "ptr*", 0)
        $pBitmap = $pBitmap[2]
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
        _SetBitmapToCtrl($Wnd,$CtrlId, $hBitmap)
        If @error Then SetError(3, 0, 0)
        _GDIPlus_BitmapDispose($pBitmap)
        _GDIPlus_Shutdown()
        _WinAPI_DeleteObject($pStream)
        _MemGlobalFree($hData)
    EndIf

    Return 1
EndFunc   ;==>_ResourceSetImageToCtrl

; internal helper function
; thanks for improvements Melba
Func _SetBitmapToCtrl($Wnd,$CtrlId, $hBitmap)

    Local Const $STM_SETIMAGE = 0x0172
    Local Const $BM_SETIMAGE = 0xF7
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0x0E
    Local Const $BS_BITMAP = 0x0080
    Local Const $GWL_STYLE = -16

    Local $hWnd, $hPrev, $Style, $iCtrl_SETIMAGE, $iCtrl_BITMAP
Local $kk=""
local $kk=$CtrlId&"_1"
$kk = ControlGetPos($Wnd, "", $CtrlId)
    $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)

    $CtrlId = _WinAPI_GetDlgCtrlID($hWnd) ; support for $CtrlId = -1
    If @error Then Return SetError(2, 0, 0)

    ; determine control class and adjust constants accordingly
    Switch _WinAPI_GetClassName($CtrlId)
        Case "Button" ; button,checkbox,radiobutton,groupbox
            $iCtrl_SETIMAGE = $BM_SETIMAGE
            $iCtrl_BITMAP = $BS_BITMAP
        Case "Static" ; picture,icon,label
            $iCtrl_SETIMAGE = $STM_SETIMAGE
            $iCtrl_BITMAP = $SS_BITMAP
        Case Else
            Return SetError(3, 0, 0)
    EndSwitch

    ; set SS_BITMAP/BS_BITMAP style to the control
    $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    If @error Then Return SetError(4, 0, 0)
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($Style, $iCtrl_BITMAP))
    If @error Then Return SetError(5, 0, 0)

    ; set image to the control
    $hPrev = _SendMessage($hWnd, $iCtrl_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
    If @error Then Return SetError(6, 0, 0)
    If $hPrev Then _WinAPI_DeleteObject($hPrev)
ControlMove($Wnd, "", $CtrlId,$kk[0],$kk[1],$kk[2], $kk[3])
    Return 1
EndFunc   ;==>_SetBitmapToCtrl

; thanks Larry,ProgAndy
; MSDN: http://msdn2.microsoft.com/en-us/library/ms712879.aspx
; default flag is $SND_SYNC = 0
Func _ResourcePlaySound($ResName, $Flag = 0, $DLL = -1, $ResType = 'sound', $Pass = '', $tALG_ID = $CALG_RC4); [V3000] $Pass , $tALG_ID
    Local $hInstance, $Ret
    If $DLL = -1 Then
        $hInstance = 0
    Else
        Local Const $LOAD_LIBRARY_AS_DATAFILE = 0x00000002
        Local Const $LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040
        Local Const $LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020
        Local $iFlags
        If @OSVersion = 'WIN_VISTA' Or @OSVersion = 'WIN_7' Then ; [V3000] OS Check ---\/
            $iFlags = $LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE + $LOAD_LIBRARY_AS_IMAGE_RESOURCE
        Else
            $iFlags = $LOAD_LIBRARY_AS_DATAFILE
        EndIf ; [V3000] ---^
        $hInstance = _WinAPI_LoadLibraryEx($DLL, $iFlags)
    EndIf

    If StringLen($Pass) = 0 Then
        $Ret = DllCall("winmm.dll", "int", "PlaySound", "str", $ResName, "hwnd", $hInstance, "int", BitOR($SND_RESOURCE, $Flag))
        If @error Then Return SetError(1, 0, 0)
        If $DLL <> -1 Then _WinAPI_FreeLibrary($hInstance)
        If @error Then Return SetError(2, 0, 0)
        Return $Ret[0]
    Else; [V3000]---\/
        Local $ResWav = _ResourceGet($ResName, $ResType, 0, $DLL, $Pass, $tALG_ID)
        Local $SoundFlag = BitOR($SND_MEMORY, $Flag)
        $Ret = DllCall("winmm.dll", "int", "sndPlaySound", "ptr", $ResWav, "int", $SoundFlag)
        If $DLL <> -1 Then _WinAPI_FreeLibrary($hInstance)
        If @error Then Return SetError(2, 0, 0)
        Return $Ret[0]
    EndIf; [V3000]---^
EndFunc   ;==>_ResourcePlaySound

thank you now

test all

; Author ........:  Zedna  AutoIt MVPs(MVP)
; Modified ......: [V3000] AutoIt Member
#AutoIt3Wrapper_Res_File_Add=TEST_TXT_1.txt.Encrypt, rt_rcdata, TEST_TXT_1
#AutoIt3Wrapper_Res_File_Add=TEST_RC_Bitmap.bmp.Encrypt, rt_rcdata, TEST_RC_Bitmap
#AutoIt3Wrapper_Res_File_Add=TEST_BIN_1.dat.Encrypt, rt_rcdata, TEST_BIN_1
#AutoIt3Wrapper_Res_File_Add=TEST_JPG_3.jpg.Encrypt, rt_rcdata, TEST_JPG_3
#AutoIt3Wrapper_Res_File_Add=TEST_BMP_2.bmp, rt_bitmap, TEST_BMP_2   ; The File is Not Encrypted
#AutoIt3Wrapper_Res_File_Add=TEST_BITMAP.bmp.Encrypt, rt_bitmap, TEST_BITMAP
#AutoIt3Wrapper_Res_File_Add=TEST_WAV_1.wav.Encrypt, sound, TEST_WAV_1
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_UseUpx=n ; For Fast Compiler, It's Only A Test!
#include "Resources_Secure.au3"
#include <GUIConstantsEx.au3>
Global $gui, $Pic1, $Pic2, $Pic3, $Pic4, $Pic5, $Label1, $Label2, $string, $hBmp, $size1, $size2
$gui = GUICreate("Data From Encrypted Resources Example", 554, 380)
$Pic1 = GUICtrlCreatePic("", 8, 8, 265, 97)
$Pic2 = GUICtrlCreatePic("", 280, 8, 265, 97)
$Pic3 = GUICtrlCreatePic("", 8, 112, 265, 97)
$Pic4 = GUICtrlCreatePic("", 280, 112, 265, 97)
$Pic5 = GUICtrlCreatePic("", 56, 224, 169, 57)
$Pic6 = GUICtrlCreatePic("", 272, 224, 257, 73)
$Label1 = GUICtrlCreateLabel("", 20, 320, 380, 100)
$Label2 = GUICtrlCreateLabel("", 350, 320, 200, 100)


; get encrypted string from resource
_ResourceSetImageToCtrl($gui,$pic6, "#1", $RT_RCDATA,@ScriptDir & "\MEEEyDll.dll","V3000")
$string = _ResourceGetAsString("TEST_TXT_1", $RT_RCDATA, 0, -1, "V3000", $CALG_RC4) ;<= Default  $tALG_ID = $CALG_RC4
GUICtrlSetData($Label1, $string)

; set BMP image to picture control from encrypted resource bitmap
_ResourceSetImageToCtrl($gui,$Pic1, "TEST_BITMAP", $RT_BITMAP, -1, "V3000") ;<= $Pass Set as "V3000" And It's In $RT_BITMAP, You Must Use [Crypt Only Bitmap (BMP).au3] For Encrypt The Bitmap File
; If You Want To Encrypt BITMAP In $RT_BITMAP (Not In $RT_RCDATA) Then Use [Crypt Only Bitmap (BMP).au3] For Encrypt The Bitmap File
_ResourceSetImageToCtrl($gui,$Pic2, "TEST_RC_Bitmap", $RT_RCDATA, -1, "V3000") ;<= Default  $tALG_ID = $CALG_RC4, And The Bitmap It's In $RT_RCDATA

; get bitmap from resource (as pointer)
$hBmp = _ResourceGet("TEST_BMP_2", $RT_BITMAP) ; TEST_BMP_2 <= It's Not Encrypted
; and use it for whatever you like
_SetBitmapToCtrl($gui,$Pic3, $hBmp) ;<= This Func it's Not Support The Decrypt From _ResourceGet, Because It Will Return Full And Raw Bitmap File, Read <Resources_v3.au3> Line 242

; set JPG image to picture control from encrypted resource
_ResourceSetImageToCtrl($gui,$Pic4, "TEST_JPG_3", 10, -1, "V3000") ;<= JPG or BMP is Encrypted

; set image to picture control from external DLL resource
_ResourceSetImageToCtrl($gui,$Pic5, "#140", $RT_BITMAP, @SystemDir & "\shell32.dll") ;<= @SystemDir & "\shell32.dll" is Not Encrypt.
GUISetState(@SW_SHOW)
; get/use picture from resources as hImage type
$size1 = _ResourceGetImageSize("TEST_BITMAP", $RT_BITMAP) ; TEST_BITMAP <= It's In $RT_BITMAP And It's Encrypted, <= With [Crypt Only Bitmap (BMP).au3]
$size2 = _ResourceGetImageSize("TEST_JPG_3") ;<= JPG Was Encrypted, See Line 68 about The $Pass.
GUICtrlSetData($Label2, $size1 & @CRLF & $size2)

; save binary data or another type (image) from encrypted resource to file and get its size in bytes
$size1 = _ResourceSaveToFile(@ScriptDir & "\TEST_BIN_1_SaveToFile.dat", "TEST_BIN_1", 10, 0, 8, -1, "V3000") ; $RT_RCDATA = 10
$size2 = _ResourceSaveToFile(@ScriptDir & "\TEST_RC_Bitmap_SaveToFile.bmp", "TEST_RC_Bitmap", $RT_RCDATA, 0, 8, -1, "V3000")

; save binary data from encrypted resource to file (create not existing directory) '?
_ResourceSaveToFile(@ScriptDir & "\SaveToFile\NoExDr_TEST_BIN_1_SaveToFile.dat", "TEST_BIN_1", $RT_RCDATA, 0, 1, -1, "V3000")
_ResourceSaveToFile(@ScriptDir & "\SaveToFile\NoExDr_TEST_BITMAP_SaveToFile.bmp", "TEST_BITMAP", $RT_BITMAP, 0, 1, -1, "V3000")

; play WAV from resource (sync/async)
_ResourcePlaySound("TEST_WAV_1", 0, -1, 'sound', "V3000") ; 'SOUND' Or 'WAVE' It's Work Fine.
_ResourcePlaySound("TEST_WAV_1", $SND_ASYNC, -1, 'sound', "V3000") ;<= TEST_WAV_1 is Encrypted

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

Func _ResourceGetImageSize($ResName, $ResType = 10) ; $RT_RCDATA = 10
    ; get/use picture from resources as hImage type
    Local $hImage = _ResourceGetAsImage($ResName, $ResType, 0, -1, "V3000"); <= The Resources is Encrypt.
    _GDIPlus_Startup()
    Local $width = _GDIPlus_ImageGetWidth($hImage)
    Local $height = _GDIPlus_ImageGetHeight($hImage)
    _GDIPlus_Shutdown()

    Return "Size of " & $ResName & " is: " & $width & "x" & $height
EndFunc   ;==>_ResourceGetImageSize
Edited by mesale0077
Link to comment
Share on other sites

hi V3000

I found a code

#include <Memory.au3>
#include <WinApi.au3>
#include <GDIPlus.au3>

Global $bSoundEnabled = True
Global $hBassDll = DllOpen(@ScriptDir & "\BASS.dll")
Global $hBassFXDll = DllOpen(@ScriptDir & "\BASS_FX.dll")

Func _ResourceLoadSound($DLL, $ResName, $Loop = 0, $Tempo = False)
       Local $hInstance, $InfoBlock, $GlobalMemoryBlock, $MemoryPointer, $ResSize, $SampleLoop = 0, $StreamHandle, $TempoHandle
       If $Loop Then $SampleLoop = 4
       $hInstance = DllCall("kernel32.dll", "int", "LoadLibrary", "str", $DLL)
       $InfoBlock = DllCall("kernel32.dll", "int", "FindResourceA", "int", $hInstance[0], "str", $ResName, "long", 10)
       $ResSize = DllCall("kernel32.dll", "dword", "SizeofResource", "int", $hInstance[0], "int", $InfoBlock[0])
       $GlobalMemoryBlock = DllCall("kernel32.dll", "int", "LoadResource", "int", $hInstance[0], "int", $InfoBlock[0])
       $MemoryPointer = DllCall("kernel32.dll", "int", "LockResource", "int", $GlobalMemoryBlock[0])
       DllCall("Kernel32.dll", "int", "FreeLibrary", "str", $hInstance[0])
       Switch $Tempo
               Case True
                       $StreamHandle = _BASS_StreamCreateFile($hBassDll, True, $MemoryPointer[0], 0, $ResSize[0], 0x200000); Decoding Channel
                       $TempoHandle = _BASS_FX_TempoCreate($hBassDll, $hBassFXDll, $StreamHandle, BitOR($SampleLoop, 0x10000)); Free StreamHandle as well
                       SetExtended($MemoryPointer[0])
                       Return $TempoHandle
               Case Else
                       $StreamHandle = _BASS_StreamCreateFile($hBassDll, True, $MemoryPointer[0], 0, $ResSize[0], $SampleLoop); Decoding Channel
                       SetExtended($MemoryPointer[0])
                       Return $StreamHandle
       EndSwitch
EndFunc   ;==>_ResourceLoadSound

Func _BASS_StreamCreateFile($bass_dll, $mem, $file, $offset, $length, $flags)
       If $hBassDll < 0 Then Return
       $BASS_ret_ = DllCall($bass_dll, "dword", "BASS_StreamCreateFile", "int", $mem, "ptr", $file, "uint64", $offset, "uint64", $length, "DWORD", $flags)
       Return SetError(0, "", $BASS_ret_[0])
EndFunc   ;==>_BASS_StreamCreateFile

Func _BASS_FX_TempoCreate($bass_dll, $bassfx_dll, $chan, $flags)
       If $hBassDll < 0 Or $bassfx_dll < 0 Then Return
       Local $BASS_ret_ = DllCall($bassfx_dll, "dword", "BASS_FX_TempoCreate", "dword", $chan, "dword", $flags)
       Local $BS_ERR = _BASS_ErrorGetCode($bass_dll)
       If $BS_ERR <> 0 Then
               Return SetError($BS_ERR, "", 0)
       Else
               Return SetError(0, "", $BASS_ret_[0])
       EndIf
EndFunc   ;==>_BASS_FX_TempoCreate

Func _BASS_ChannelSetAttribute($bass_dll, $handle, $attrib, $value)
       If Not $bSoundEnabled Or $hBassDll < 0 Then Return
       DllCall($bass_dll, "int", "BASS_ChannelSetAttribute", "DWORD", $handle, "DWORD", $attrib, "float", $value)
EndFunc   ;==>_BASS_ChannelSetAttribute

Func _BASS_ChannelPlay($bass_dll, $handle, $restart)
       If Not $bSoundEnabled Or $hBassDll < 0 Then Return
       DllCall($bass_dll, "int", "BASS_ChannelPlay", "DWORD", $handle, "int", $restart)
EndFunc   ;==>_BASS_ChannelPlay

Func _BASS_ChannelStop($bass_dll, $handle)
       If $hBassDll < 0 Then Return
       DllCall($bass_dll, "int", "BASS_ChannelStop", "DWORD", $handle)
EndFunc   ;==>_BASS_ChannelStop

Func _BASS_StreamFree($bass_dll, $handle)
       If $hBassDll < 0 Then Return
       DllCall($bass_dll, "int", "BASS_StreamFree", "dword", $handle)
EndFunc   ;==>_BASS_StreamFree

Func _BASS_SetVolume($bass_dll, $volume)
       If $hBassDll < 0 Then Return
       DllCall($bass_dll, "int", "BASS_SetVolume", "float", $volume)
EndFunc   ;==>_BASS_SetVolume

Func _BASS_GetVolume($bass_dll)
       If $hBassDll < 0 Then Return
       Local $BASS_ret_ = DllCall($bass_dll, "float", "BASS_GetVolume")
       Return $BASS_ret_[0]
EndFunc   ;==>_BASS_GetVolume

Func _BASS_ChannelGetPosition($bass_dll, $handle, $mode)
       If $hBassDll < 0 Then Return -1
       $BASS_ret_ = DllCall($bass_dll, "UINT", "BASS_ChannelGetPosition", "DWORD", $handle, "DWORD", $mode)
       $bass_error = _BASS_ErrorGetCode($bass_dll)
       If $bass_error <> 0 Then
               Return SetError($bass_error, "", 0)
       Else
               Return SetError(0, "", $BASS_ret_[0])
       EndIf
EndFunc   ;==>_BASS_ChannelGetPosition

Func _BASS_ChannelSetPosition($bass_dll, $handle, $pos, $mode)
       If Not $bSoundEnabled Or $hBassDll < 0 Then Return
       DllCall($bass_dll, "int", "BASS_ChannelSetPosition", "DWORD", $handle, "UINT64", $pos, "DWORD", $mode)
EndFunc   ;==>_BASS_ChannelSetPosition

Func _BASS_ChannelIsActive($bass_dll, $handle)
       If $hBassDll < 0 Then Return 0
       Local $BASS_ret_ = DllCall($bass_dll, "int", "BASS_ChannelIsActive", "DWORD", $handle)
       Local $bass_error = _BASS_ErrorGetCode($bass_dll)
       If $bass_error <> 0 Then
               Return SetError($bass_error, "", 0)
       Else
               Return SetError(0, "", $BASS_ret_[0])
       EndIf
EndFunc   ;==>_BASS_ChannelIsActive

Func _BASS_Init($bass_dll, $flags, $device = -1, $freq = 44100, $win = 0, $clsid = "")
       If $hBassDll < 0 Then Return SetError(1, 0, 0)
       Local $BASS_ret_ = DllCall($bass_dll, "int", "BASS_Init", "int", $device, "dword", $freq, "dword", $flags, "hwnd", $win, "hwnd", $clsid)
       Local $bass_error = _BASS_ErrorGetCode($bass_dll)
       If $bass_error <> 0 Then
               Return SetError($bass_error, "", 0)
       Else
               Return SetError(0, "", $BASS_ret_[0])
       EndIf
EndFunc   ;==>_BASS_Init

Func _BASS_ErrorGetCode($bass_dll)
       If Not $bSoundEnabled Or $hBassDll < 0 Then Return
       Local $BASS_ret_ = DllCall($bass_dll, "int", "BASS_ErrorGetCode")
       Return SetError(0, "", $BASS_ret_[0])
EndFunc   ;==>_BASS_ErrorGetCode

Func _BASS_Free($bass_dll)
       If $hBassDll < 0 Then Return
       DllCall($bass_dll, "int", "BASS_Free")
EndFunc   ;==>_BASS_Free

Func _ResourceFree($handle)
       If $handle = 0 Then Return
       DllCall("kernel32.dll", "int", "FreeResource", "int", $handle)
EndFunc   ;==>_ResourceFree

Func _ResourceLoadImage($DLL, $ResName); THX to Progandy, Zedna
       Local $hInstance, $InfoBlock, $GlobalMemoryBlock, $MemoryPointer, $ResSize, $hData, $pData, $pStream, $dll2, $pBitmap
       $hInstance = DllCall("kernel32.dll", "int", "LoadLibrary", "str", $DLL)
       $InfoBlock = DllCall("kernel32.dll", "int", "FindResourceA", "int", $hInstance[0], "str", $ResName, "long", 10)
       $ResSize = DllCall("kernel32.dll", "dword", "SizeofResource", "int", $hInstance[0], "int", $InfoBlock[0])
       $GlobalMemoryBlock = DllCall("kernel32.dll", "int", "LoadResource", "int", $hInstance[0], "int", $InfoBlock[0])
       $MemoryPointer = DllCall("kernel32.dll", "int", "LockResource", "int", $GlobalMemoryBlock[0])
       DllCall("Kernel32.dll", "int", "FreeLibrary", "str", $hInstance[0])
       $hData = _MemGlobalAlloc($ResSize[0], 2)
       $pData = _MemGlobalLock($hData)
       _MemMoveMemory($MemoryPointer[0], $pData, $ResSize[0])
       _MemGlobalUnlock($hData)
       $pStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "int", $hData, "long", 1, "Int*", 0)
       $pBitmap = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromStream", "ptr", $pStream[3], "int*", 0)
       $DLL = DllStructCreate("Uint", $pStream[3])
       $dll2 = DllStructCreate("uInt", DllStructGetData($DLL, 1) + 8)
       DllCall("", "UInt", DllStructGetData($dll2, 1), "UInt", $pStream[3])
       _WinAPI_DeleteObject($pStream[3])
       $pStream[3] = 0
       _MemGlobalFree($hData)
       Return $pBitmap[2]
EndFunc   ;==>_ResourceLoadImage

thank you

Nice code

Edited by mesale0077
Link to comment
Share on other sites

  • 4 weeks later...

Just one request: I see that, obviously, the password when you call the resource it's clear (V3000 in your this case).

So if someone can .exe -> au3 he can read the code and, recursively, go back to the original crypted file.

Correct?

If this assumption is true, is there a way to ensure the crypting of the password itself in the main .au3?

M.

Link to comment
Share on other sites

  • 7 months later...

How to write the serial number of HD within the executable when run the first time?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...