Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/11/2014 in all areas

  1. Hello, I wrapped the two functions CryptProtectData and CryptUnprotectData to protect passwords. MSDN says: Typically, only a user with the same logon credential as the user who encrypted the data can decrypt the data. In addition, the encryption and decryption usually must be done on the same computer. For detailed information visit MSDN: * CryptProtectData: http://msdn.microsoft.com/en-us/library/aa380261(v=vs.85).aspx * CryptUnprotectData: http://msdn.microsoft.com/en-us/library/aa380882(v=vs.85).aspx I hope that there are no memory leaks, if you find one, please tell me! Have fun!!! #include <WinAPI.au3> ;When this flag is set, it associates the data encrypted with the current computer instead of with an individual user. ;Any user on the computer on which CryptProtectData is called can use CryptUnprotectData to decrypt the data. Global Const $CRYPTPROTECT_LOCAL_MACHINE = 0x4 ;This flag is used for remote situations where presenting a user interface (UI) is not an option. When this flag is set ;and a UI is specified for either the protect or unprotect operation, the operation fails and GetLastError returns the ERROR_PASSWORD_RESTRICTION code. Global Const $CRYPTPROTECT_UI_FORBIDDEN = 0x1 ;This flag generates an audit on protect and unprotect operations. Global Const $CRYPTPROTECT_LOCAL_AUDIT = 0x10 Global Const $CRYPTPROTECT_VERIFY_PROTECTION = 0x40 ;This flag is used to provide the prompt for the protect phase. Global Const $CRYPTPROTECT_PROMPT_ON_PROTECT = 0x2 ;This flag can be combined with CRYPTPROTECT_PROMPT_ON_PROTECT to enforce the UI (user interface) policy of the caller. ;When CryptUnprotectData is called, the dwPromptFlags specified in the CryptProtectData call are enforced. Global Const $CRYPTPROTECT_PROMPT_ON_UNPROTECT = 0x1 Global Const $ERROR_INVALID_DATA = 13 Global Const $tagDATA_BLOB = "DWORD cbData;ptr pbData;" Global Const $tagCRYPTPROTECT_PROMPTSTRUCT = "DWORD cbSize;DWORD dwPromptFlags;HWND hwndApp;ptr szPrompt;" Global $hDLL_CryptProtect = DllOpen("crypt32.dll") Global $sString2Hide = "This is a test string to protect!" Global $bData, $sData, $sDesc = "" $bData = _CryptProtectData($sString2Hide, "Some information") ConsoleWrite("Error protecting: " & @error & " - " & @extended & @LF) ConsoleWrite("Protected data: " & $bData & @LF) $sData = _CryptUnprotectData($bData, $sDesc) ConsoleWrite("Error unprotecting: " & @error & " - " & @extended & @LF) ConsoleWrite("Unprotected string: " & $sData & @LF) ConsoleWrite("Unprotected description: " & $sDesc & @LF) ConsoleWrite(@LF & @LF) $bData = _CryptProtectData($sString2Hide, "Some other information", "pass") ConsoleWrite("Error protecting: " & @error & " - " & @extended & @LF) ConsoleWrite("Protected data: " & $bData & @LF) $sData = _CryptUnprotectData($bData, $sDesc, "") ConsoleWrite("Error unprotecting: " & @error & " - " & @extended & @LF) ConsoleWrite("Unprotected string: " & $sData & @LF) ConsoleWrite("Unprotected description: " & $sDesc & @LF) ConsoleWrite(@LF & @LF) $bData = _CryptProtectData($sString2Hide, "Some other information", "pwd") ConsoleWrite("Error protecting: " & @error & " - " & @extended & @LF) ConsoleWrite("Protected data: " & $bData & @LF) $sData = _CryptUnprotectData($bData, $sDesc, "pwd") ConsoleWrite("Error unprotecting: " & @error & " - " & @extended & @LF) ConsoleWrite("Unprotected string: " & $sData & @LF) ConsoleWrite("Unprotected description: " & $sDesc & @LF) ConsoleWrite(@LF & @LF) Global $sPromptString = "Data protection will be done" Global $tPromptString = DllStructCreate("wchar szPrompt[256]") DllStructSetData($tPromptString, "szPrompt", $sPromptString) Global $tPrompt = DllStructCreate($tagCRYPTPROTECT_PROMPTSTRUCT) DllStructSetData($tPrompt, "cbSize", DllStructGetSize($tPrompt)) DllStructSetData($tPrompt, "dwPromptFlags", BitOR($CRYPTPROTECT_PROMPT_ON_PROTECT, $CRYPTPROTECT_PROMPT_ON_UNPROTECT)) DllStructSetData($tPrompt, "szPrompt", DllStructGetPtr($tPromptString)) $bData = _CryptProtectData($sString2Hide, "Protection example with Gui", "pwd", 0, DllStructGetPtr($tPrompt)) ConsoleWrite("Error protecting: " & @error & " - " & @extended & @LF) ConsoleWrite("Protected data: " & $bData & @LF) $sPromptString = "Data unprotection will be done" DllStructSetData($tPromptString, "szPrompt", $sPromptString) $sData = _CryptUnprotectData($bData, $sDesc, "pwd", 0, DllStructGetPtr($tPrompt)) ConsoleWrite("Error unprotecting: " & @error & " - " & @extended & @LF) ConsoleWrite("Unprotected string: " & $sData & @LF) ConsoleWrite("Unprotected description: " & $sDesc & @LF) DllClose($hDLL_CryptProtect) ;http://msdn.microsoft.com/en-us/library/aa380261(v=vs.85).aspx Func _CryptProtectData($sString, $sDesc = "", $sPwd = "", $iFlag = 0, $pPrompt = 0) ;funkey 2014.08.11th Local $aRet, $iError, $tEntropy, $tDesc, $pEntropy = 0, $pDesc = 0 Local $tDataIn = _DataToBlob($sString) If $sPwd <> "" Then $tEntropy = _DataToBlob($sPwd) $pEntropy = DllStructGetPtr($tEntropy) EndIf If $sDesc <> "" Then $tDesc = DllStructCreate("wchar desc[" & StringLen($sDesc) + 1 & "]") DllStructSetData($tDesc, "desc", $sDesc) $pDesc = DllStructGetPtr($tDesc) EndIf Local $tDataBuf = DllStructCreate($tagDATA_BLOB) $aRet = DllCall($hDLL_CryptProtect, "BOOL", "CryptProtectData", "struct*", $tDataIn, "ptr", $pDesc, "ptr", $pEntropy, "ptr", 0, "ptr", $pPrompt, "DWORD", $iFlag, "struct*", $tDataBuf) $iError = @error _WinAPI_LocalFree(DllStructGetData($tDataIn, "pbData")) If $sPwd <> "" Then _WinAPI_LocalFree(DllStructGetData($tEntropy, "pbData")) If $iError Then Return SetError(1, 0, "") If $aRet[0] = 0 Then Return SetError(2, _WinAPI_GetLastError(), "") Local $tDataOut = DllStructCreate("byte data[" & DllStructGetData($tDataBuf, "cbData") & "]", DllStructGetData($tDataBuf, "pbData")) Local $bData = DllStructGetData($tDataOut, "data") _WinAPI_LocalFree(DllStructGetData($tDataBuf, "pbData")) Return $bData EndFunc ;==>_CryptProtectData ;http://msdn.microsoft.com/en-us/library/aa380882(v=vs.85).aspx Func _CryptUnprotectData($bData, ByRef $sDesc, $sPwd = "", $iFlag = 0, $pPrompt = 0) ;funkey 2014.08.11th Local $aRet, $iError, $tEntropy, $pEntropy = 0 Local $tDataIn = _DataToBlob($bData) $sDesc = "" If $sPwd <> "" Then $tEntropy = _DataToBlob($sPwd) $pEntropy = DllStructGetPtr($tEntropy) EndIf Local $tDataBuf = DllStructCreate($tagDATA_BLOB) Local $tDesc = DllStructCreate("ptr desc") Local $pDesc = DllStructGetPtr($tDesc) $aRet = DllCall($hDLL_CryptProtect, "BOOL", "CryptUnprotectData", "struct*", $tDataIn, "ptr*", $pDesc, "ptr", $pEntropy, "ptr", 0, "ptr", $pPrompt, "DWORD", $iFlag, "struct*", $tDataBuf) $iError = @error _WinAPI_LocalFree(DllStructGetData($tDataIn, "pbData")) If $sPwd <> "" Then _WinAPI_LocalFree(DllStructGetData($tEntropy, "pbData")) If $iError Then Return SetError(1, 0, "") If $aRet[0] = 0 Then Return SetError(2, _WinAPI_GetLastError(), "") Local $tDataOut = DllStructCreate("char data[" & DllStructGetData($tDataBuf, "cbData") & "]", DllStructGetData($tDataBuf, "pbData")) Local $sData = DllStructGetData($tDataOut, "data") Local $aLen = DllCall("msvcrt.dll", "UINT:cdecl", "wcslen", "ptr", $aRet[2]) Local $tDesc = DllStructCreate("wchar desc[" & $aLen[0] + 1 & "]", $aRet[2]) $sDesc = DllStructGetData($tDesc, "desc") _WinAPI_LocalFree($aRet[2]) _WinAPI_LocalFree(DllStructGetData($tDataBuf, "pbData")) Return $sData EndFunc ;==>_CryptUnprotectData ;Creates a DATA_BLOB structure where the function stores the decrypted data. ;When you have finished using the DATA_BLOB structure, free its pbData member by calling the _WinAPI_LocalFree function. Func _DataToBlob($data) ;funkey 2014.08.11th Local $iLen, $tDataIn, $tData, $aMem Local Const $LMEM_ZEROINIT = 0x40 Select Case IsString($data) $iLen = StringLen($data) Case IsBinary($data) $iLen = BinaryLen($data) Case Else Return SetError(1, 0, 0) EndSelect $tDataIn = DllStructCreate($tagDATA_BLOB) $aMem = DllCall("Kernel32.dll", "handle", "LocalAlloc", "UINT", $LMEM_ZEROINIT, "UINT", $iLen) $tData = DllStructCreate("byte[" & $iLen & "]", $aMem[0]) DllStructSetData($tData, 1, $data) DllStructSetData($tDataIn, "cbData", $iLen) DllStructSetData($tDataIn, "pbData", DllStructGetPtr($tData)) Return $tDataIn EndFunc ;==>_DataToBlob Edit: Added example for using CRYPTPROTECT_PROMPTSTRUCT. CryptProtect.zip
    1 point
  2. sahsanu

    Title Renamer

    As I said, I've never used ID3 tags, I tested the script with 10 mp3 songs and it worked fine on all of them. You should take a deep look into ID3 UDF functions or open a new post asking for help for this issue with your mp3 files. An advise, if you ask for help on this issue, it should be great if you could provide a mp3 (without Copyright of course) where the problem could be reproduced, your chances to get help will raise up. The best way to check whether that will work is to test it. Anyway, yes, it should work
    1 point
  3. Version 3.7! New features: Improved toolbox LUT Curve & Lens Correction (slooow) effects Blend brushes Pen properties Download
    1 point
  4. I am working on a device driver managment script im calling Infinity.DriverManager. It's function is to download/update DriverPacks in the 7z format, read all INFs, and build a database containing all HWIDs, and device specific information. After the initialization stage/first run, the script will: -If running in WinPE, it will detect devices, extract drivers, then load them using drvload/DriverImportPE. -If running on a normal system...detect devices, extract drivers, install/update drivers. Along with console paramaters to import/export drivers from online/offline systems, import/export preloaded configurations, virtual disk images containing drivers to load on boot for a familiar system in WinPE mode.
    1 point
  5. The And relation in If statements is not & but And. Local $sTime = @HOUR & ":" & @MIN & ":" & @SEC While 1 If @HOUR = 14 And @MIN = 35 And @SEC = 00 Then MsgBox(0, "", @HOUR & "h " & @MIN & "m " & @SEC & "s", 10) Sleep(1500) ElseIf @HOUR = 14 And @MIN = 37 And @SEC = 00 Then MsgBox(0, "", @HOUR & "h " & @MIN & "m " & @SEC & "s", 10) Sleep(1500) ElseIf @HOUR = 14 And @MIN = 39 And @SEC = 00 Then MsgBox(0, "", @HOUR & "h " & @MIN & "m " & @SEC & "s", 10) Sleep(1500) EndIf Sleep(500) WEnd Jos
    1 point
  6. sahsanu

    Title Renamer

    Hello, As far as I know, yes, the example script I posted should do what you want (read a list of mp3 files and write and ID3 with the Title and Artist readed from their own file name). The script does: 1.- Get the list of mp3 files in the same folder as the script and put them into an array. 2.- Loop the array extracting the Artist and Title from the mp3 file name and put them into variables. 3.- Inside the loop it also write the ID3 tags for every mp3 found. Regarding StringRegExpReplace, it's just another approach to extract the artist and title using regular expressions. Of course, you can use your own StrimTrim etc. functions. Here an example: #include <File.au3> #include <ID3_v3.4.au3> $aListMP3Files = _FileListToArray(@ScriptDir, "*.mp3") If @error Then ConsoleWrite("Error retrieving file list" & @CRLF) Exit EndIf For $i = 1 To $aListMP3Files[0] $iPosition = StringInStr($aListMP3Files[$i], " - ") $sTemp = StringTrimLeft($aListMP3Files[$i], $iPosition + 2) $sTitle = StringTrimRight($sTemp, 4) $sTemp = StringReverse($aListMP3Files[$i]) $iPosition2 = StringInStr($sTemp, " - ") $sTemp = StringTrimLeft($sTemp, $iPosition2) $sArtist = StringReverse(StringTrimLeft($sTemp, 2)) If $sArtist = $aListMP3Files[$i] Or $sTitle = $aListMP3Files[$i] Then ContinueLoop _WriteID3_TitleArtist($aListMP3Files[$i], $sTitle, $sArtist) If @error Then ConsoleWrite("Error trying to write ID3 tags in file " & $aListMP3Files[$i] & @CRLF) Next Func _WriteID3_TitleArtist($sID3File, $sID3Title, $sID3Artist) If $sID3File = Null Or $sID3Title = Null Or $sID3Artist = Null Then Return SetError(1, 1, 1) _ID3ReadTag($sID3File, 3) ;must read in existing tag first to ensure other fields are saved _ID3SetTagField("Title", $sID3Title) _ID3SetTagField("TIT2", $sID3Title) _ID3SetTagField("Artist", $sID3Artist) _ID3SetTagField("TPE1", $sID3Artist) _ID3WriteTag($sID3File) ;by default this will write both ID3v1 and ID3v2 If @error Then Return SetError(2, 2, 2) EndFunc ;==>_WriteID3_TitleArtist Regarding your question, What does the [$i] in the string mean?. $aListMP3Files[] is an array containing the list of mp3 files found on the folder. The $i is a variable assigned in the loop starting from 1, so in every loop $i adds +1, 1, 2, 3, 4, .... so in every loop $aListMP3Files[$i] means that the variable contain the data in the array in position $i. I know may explanation isn't really good so take a look in the help file and search for Array and Loops (that is one the first things you should do if you want to learn to programm with AutoIt). Regarding, what is the "(.+)s-s.+", "$1") doing?. That is a Regular Expression and this is the exaplanation: (.+)\s-\s.+ Match the regex below and capture its match into backreference number 1 «(.+)» Match any single character that is NOT a line break character (line feed) «.+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» Match a single character that is a “whitespace character” (any Unicode separator, tab, line feed, carriage return, vertical tab, form feed, next line) «\s» Match the character “-” literally «-» Match a single character that is a “whitespace character” (any Unicode separator, tab, line feed, carriage return, vertical tab, form feed, next line) «\s» Match any single character that is NOT a line break character (line feed) «.+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» $1 Insert the text that was last matched by capturing group number 1 «$1» Anyway, If you understand StringReverse, StringTrim, etc. functions, go ahead, forgot for now Regular Expressions (you'll have time to learn them in the future). Cheers, sahsanu
    1 point
×
×
  • Create New...