Jump to content
Sign in to follow this  
V3000

Resources UDF + Encrypt & Decrypt

Recommended Posts

V3000

Hi Everyone

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

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

Modified ......: V3000 AutoIt Member

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

Resources UDF embed/use any data/files into/from AutoIt compiled EXE files

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)

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

_SetBitmapToCtrl($CtrlId, $hBitmap)

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 .

* 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 )

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, $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)
$Label1 = GUICtrlCreateLabel("", 20, 320, 380, 100)
$Label2 = GUICtrlCreateLabel("", 350, 320, 200, 100)

GUISetState(@SW_SHOW)
; 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") ;<= $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) ;<= 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") ;<= @SystemDir  & "\shell32.dll" is Not Encrypt.

; 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!

Hi Everyone

I like to secure my resources from being exporting & viewed .

This is Resources UDF I used in my script, Thanks to Zedna .

My Request:

Can I secure my resources with Encrypt & Decrypt method ?, like:

;(1)
;-------Original
_ResourceSetImageToCtrl($CtrlId, $ResName, $ResType = 10, $DLL = -1)
;-------Code I Want
_ResourceSetImageToCtrl($CtrlId, $ResName, $ResType = 10, $DLL = -1, $Password = "")
;$Password -> If StringLen($Password) <> 0 Then ;Image was Encrypt - do Decrypt & SetImageToCtrl.

;(2)
;-------Original
_ResourceSaveToFile($FileName, $ResName, $ResType = 10, $ResLang = 0, $CreatePath = 0, $DLL = -1)
;-------Code I Want
_ResourceSaveToFile($FileName, $ResName, $ResType = 10, $ResLang = 0, $CreatePath = 0, $DLL = -1, $Password = "")
;$Password -> If StringLen($Password) <> 0 Then ;File was Encrypt - do Decrypt & SaveToFile.

;(3)
;-------Original
_ResourcePlaySound($ResName, $Flag = 0, $DLL = -1)
;-------Code I Want
_ResourcePlaySound($ResName, $Flag = 0, $DLL = -1, $Password = "")
;$Password -> If StringLen($Password) <> 0 Then ;Sound was Encrypt - do Decrypt & PlaySound.

;(4)
;-------Original
_ResourceGetAsString($ResName, $ResType = 10, $ResLang = 0, $DLL = -1)
;-------Code I Want
_ResourceGetAsString($ResName, $ResType = 10, $ResLang = 0, $DLL = -1, $Password = "")
;$Password -> If StringLen($Password) <> 0 Then ;String was Encrypt - do Decrypt & GetAsString.

And Edit 'Resources.au3' For All Resources to be secured And Without Saving Decrypt To Temp File. <- That Not secure ! ^_^

Thanks. And Sorry For My Bad English !

Edited by V3000

Share this post


Link to post
Share on other sites
Zedna

You can modify my Resources UDF to do this by using functions from standard Crypt UDF.

I think it should be no problem for strings. But I'm not sure if it will be easy for other types like images/sounds

because for these types of resources I internally use resource Windows API functions which will not understand encrypted data.

But it's only my quick thought here, maybe it will not be hard at all ...

Share this post


Link to post
Share on other sites
V3000

Thank You Very Much :)

I Will Try & Do My Best ...

:mellow::)

Share this post


Link to post
Share on other sites
V3000

:mellow:It's Too Complicated For A Beginner !

Please Help Me..

I Like Use AES Encrypt Method, Thanks to Ward .

Another Crypto Method, Thanks to Ejoc .

Secure Resources With Password

I'm Completely Lost :)

Share this post


Link to post
Share on other sites
V3000
[ Resources_v2 ] It's Complete Check First Post :mellow:

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  

×