Jump to content

TechCoder

Active Members
  • Posts

    185
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by TechCoder

  1. sorry, that was 'untested' code (and one of the constant issues I have in working in AutoIt one minute and php the next - forgetting the language differences! change to add the 'Then' on the 'If' line..... If ($sec > 60) Then (of course, the error tells you that......)
  2. I'm pretty new around here, and I kinda got into this 'new and improved' message - though the part about 'open source AutoIt' - well............. Hope all have had a 'Happy.....' day....
  3. and, to have the update every hour...... Local $dif, $sec While 1 $sec = Round(TimerDiff($adtimer) / 1000, 2) If ($sec > 60) ; READ YOUR TEXT FILE, PROCESS IT, ETC...... ; ADD THE LABEL UPDATE HERE (like BrewManNH said...) GUICtrlSetData($Label_02, "the data you want the label to show") EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd
  4. nice little function - I'm adding it to my 'snipit' file - could come in handy......
  5. sounds more like most of the programmers I know.......
  6. and, of course, there is a function for that...... http://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayUnique.htm
  7. one 'super simple' way..... Local $gotit = 0 While 1 $accept = TCPAccept($socket) $recive = TCPRecv($accept, 1000000) If Not $gotit And $recive = "hi" Then $gotit = 1 _ArrayAdd($Array,$recive) GUICtrlSetData($list, _ArrayToString($Array)) EndIf WEnd
  8. I'm really not understanding your post - again, please put in the full code because your message is mixed - "works!" and "not" in one - not sure if you took out something or what from the code I gave you, which works fine and as expected on my system. And, yes, you do have to add in the jsmn_get function to the UDF (I did that in my copy the first day - forgot about that.... - the one that coded it said he would add it but it is not in the first post download - yes, you have to have it as well - either in the UDF or in the program you are using....) - though if you are not getting errors on that, it seems you have that function (pulled from another post is what I use.) Is that the problem you are discussing? Again, just not clear (I'm in the middle of a big project and can only glance at the replies - if they aren't 'easy' to figure out, I have to move on {i.e., helping others with their coding issue is not my primary job - but I do what I can...}) When asking for help, I try to follow a tip an old-timer told me years ago "Before you post, check to make sure a 3rd grader can understand it" - then, there is no guessing for the person trying to help you.
  9. Yeah, I now see what it is...... - you are trying too hard! Not sure what all that Array stuff is - you don't need it when working with JSON - it, by definition, is an array-decrypter (of sorts) - whatever you call it, JSON is a method in/of itself and you are trying to tear it apart yourself, then looking for the tools to do the work. Don't try so hard! Basically, all you need when using this UDF: 1. take the incoming JSON code (in your case, coming from a .txt file - it might come from a result or anywhere... - but LEAVE IT ALONE AS JSON) 2. JSMN_DECODE it to an object. 3. use JSMN_GET. That's it! This works (using the demo from JSMN and your data to show you the full results) - notice you only need ONE include, which is this UDF! #include "JSMN.au3" local $Json1 $Json1 = FileRead("TestHistory.txt") Local $Data1 = Jsmn_Decode($Json1) ; ************************************************************************************ ; these lines are NOT NEEDED in your live system, just here to show the output Local $Json2 = Jsmn_Encode($Data1, $JSMN_UNQUOTED_STRING) Local $Data2 = Jsmn_Decode($Json2) Local $Json3 = Jsmn_Encode($Data2, $JSMN_PRETTY_PRINT, " ", "\n", "\n", "") ConsoleWrite("Test3 Unquoted Result: " & $Json2 & @CRLF) ConsoleWrite("Test3 Pretty Result: " & $Json3 & @CRLF) ; the above lines are not needed in a live system ; ************************************************************************************ $resault = Jsmn_Get($Data1, '[0]["Sysinfo"][0]["Properties"][0]["Name"]') ConsoleWrite($resault & @CRLF) and, for future reference, when you post code - go ahead and put in the #includes you are using (makes it simpler for someone testing your code, as well as know what you are using - it might be that you have the wrong includes sometimes....) So, end result - let the tool do the work. (BTW, my 'tip' on going step at a time didn't work on this - because it starts off with an array - the data I have been working with is a bit different and that stepping through worked for me - guess it all depends on the data However, the 'replace [{ with [0] works on your data as well as mine, so that seems a good 'rule'... )
  10. Not sure what you are trying to get from the string (as your code shows you asking for the result name, not the variable...) you will see that, at the end (if not before) you are asking for the "User Application Tool Space", which is the RESULT - you should be asking for, perhaps 'Name' there - so the result can come back - example on that below Here is a tip on how I got used to using the UDF and JSON in general. Take it a step at a time! instead of $resault = Jsmn_Get($Obj1, '[0]["Sysinfo"]["0"]["7"]["User Application Total Space"]') just go to $resault = Jsmn_Get($Obj1, '[0]') and see what you get (should be something you recognize) then, the next bit (once you select what you really want) $resault = Jsmn_Get($Obj1, '[0]["Sysinfo"]') etc. Like the old saying - you CAN eat an elephant, just take it in small bites - and keep at it until you are done. the way I look at it is, for a START, 1. replace [{ with a [0] (start with 0 and go from there until you get what you want...) 2. if you find the variable you want in the list, add that to your 'get' string 3. go back to step 1 when needed Now, to get the result of "User Application Tool Space" as I believe you are looking for in your example, you need to look at; [0]['Sysinfo'][[0]['Properties'][0]['Name'] More simple now?
  11. found it! "name":"" the UDF doesn't like the empty string - it wants ==>null<== or some with-character(s) string. So, the 'fix' - I did a quick StringReplace...... $string2test = StringReplace($string2test,'""','null') puts everything back in place.
  12. Great UDF, been using it to work with JSON much easier than other functions. I'm also using Jsmn_Get (which is a massive time saver). However, getting this one string to decode properly has me stumped. The Decode function shows no error (which there isn't that I can find separating it manually - see the commented section), though $JSMN_PRETTY_PRINT does not break the "groups" out properly (at least, that is what it seems to me). What am I missing? #Include "JSMN.au3" Test3() Func Test3() Local $string2test = '{"id":"6","username":"USERNAME","firstName":"FirstName","lastName":"LastName","emailAddress":"[email protected]","phoneNumber":"","lastLogin":"","statusId":"1","timezone":"America\/Chicago","organization":"","position":"","language":"en_us","icsUrl":null,"customAttributes":[{"id":"5","label":"user attribute","value":null,"links":[{"href":"https:\/\/p.rizon.top:443\/http\/example.com\/Attributes\/5","title":"get_custom_attribute"}],"message":null}],"permissions":[{"id":"1","name":"","links":[{"href":"https:\/\/p.rizon.top:443\/http\/example.com\/Resources\/1","title":"get_resource"}],"message":null},{"id":"2","name":"","links":[{"href":"https:\/\/p.rizon.top:443\/http\/example.com\/Resources\/2","title":"get_resource"}],"message":null}],"groups":[{"links":[{"href":"https:\/\/p.rizon.top:443\/http\/example.com\/Groups\/1","title":"get_group"}],"message":null,"id":"1","name":"Administrators"},{"links":[{"href":"https:\/\/p.rizon.top:443\/http\/example.com\/Groups\/5","title":"get_group"}],"message":null,"id":"5","name":"Students"}],"links":[],"message":null}' Local $Json1 = $string2test Local $Data1 = Jsmn_Decode($Json1) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Data1 = ' & $Data1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $Json2 = Jsmn_Encode($Data1, $JSMN_UNQUOTED_STRING) Local $Data2 = Jsmn_Decode($Json2) Local $Json3 = Jsmn_Encode($Data2, $JSMN_PRETTY_PRINT, " ", "\n", "\n", "") Local $Data3 = Jsmn_Decode($Json3) Local $Json4 = Jsmn_Encode($Data1, $JSMN_STRICT_PRINT) ConsoleWrite("Test3 Unquoted Result: " & $Json2 & @CRLF) ConsoleWrite("Test3 Pretty Result: " & $Json3 & @CRLF) Return (StringLen($Json3) >= StringLen($Json1)) EndFunc #cs Here is how the string breaks down (manually) NOTE HOW GROUPS COMES OUT CORRECTLY { "id":"6", "username":"USERNAME", "firstName":"FirstName", "lastName":"LastName", "emailAddress":"[email protected]", "phoneNumber":"", "lastLogin":"", "statusId":"1", "timezone":"America\/Chicago", "organization":"", "position":"", "language":"en_us", "icsUrl":null, "customAttributes": [ { "id":"5", "label":"user attribute", "value":null, "links":[ { "href":"https:\/\/p.rizon.top:443\/http\/example.com\/Attributes\/5", "title":"get_custom_attribute" } ], "message":null } ], "permissions":[ { "id":"1", "name":"", "links":[ { "href":"https:\/\/p.rizon.top:443\/http\/example.com\/Resources\/1", "title":"get_resource" } ], "message":null }, { "id":"2", "name":"", "links":[ { "href":"https:\/\/p.rizon.top:443\/http\/example.com\/Resources\/2", "title":"get_resource" } ], "message":null } ], "groups":[ <<<<======= HERE, IT IS CORRECT - THOUGH CHECK YOUR CONSOLE OUTPUT! { "links":[ { "href":"https:\/\/p.rizon.top:443\/http\/example.com\/Groups\/1", "title":"get_group" } ], "message":null, "id":"1", "name":"Administrators" }, { "links":[ { "href":"https:\/\/p.rizon.top:443\/http\/example.com\/Groups\/5", "title":"get_group" } ], "message":null, "id":"5", "name":"Students" } ], "links":[], "message":null } #ce
  13. Once you have good data to work with, it doesn't take long......... Here's a fully functioning AutoIt to php encryption/decryption set for you to get started with! (minimal credits to me - I only put it together - everyone else worked out the hard parts! AUTOIT CODE (change line 16 from http://example.com/your.php to your php location) #include <Crypt.au3> #include <IE.au3> Global $error Global $extended Local $str = "hello world!" ConsoleWrite("string to encrypt/decrypt is " & $str & @crlf& @crlf) ConsoleWrite("starting ENCRYPTION" & @crlf) Local $encrypted = _Cryptshun($str) if @error or @extended Then ConsoleWrite("error on encryption is " & @error & @crlf & "extended is " & @extended & @crlf & "decrypted = " & BinaryToString($encrypted) & @crlf&@CRLF) else ConsoleWrite("$encrypted is " & $encrypted & @crlf&@CRLF) EndIf $oIE = _IECreate("http://example.com/your.php?data="&$encrypted,0,0,1) Local $sText = _IEBodyReadText($oIE) _IEQuit($oIE) $decrypted = _DeCryptshun($sText) if @error or @extended Then ConsoleWrite("error on decryption is " & @error & @crlf & "extended is " & @extended & @crlf & "decrypted = " & BinaryToString($decrypted) & @crlf& @crlf) else ConsoleWrite("decrypted raw = " & BinaryToString($decrypted) & @crlf& @crlf) EndIf Func _Cryptshun($str) ; function to match up with php side encryption/decryption ; from http://www.autoitscript.com/forum/topic/150967-aes-256-encryption-in-autoit-php/ Dim Const $KP_MODE = 4 Dim Const $CRYPT_MODE_ECB = 2 _Crypt_Startup() $key = "abcdefghijuklmno" $key = _Crypt_ImportKey($CALG_AES_128, $key) _Crypt_SetKeyParam($key, $KP_MODE, $CRYPT_MODE_ECB) $s = _Crypt_EncryptData($str, $key, $CALG_USERKEY) if @error or @extended then $error = @error $extended = @extended EndIf _Crypt_DestroyKey($key) _Crypt_Shutdown() $s = _B64Encode($s) Return SetError($error,$extended,$s) EndFunc Func _DeCryptshun($str) Dim Const $KP_MODE = 4 Dim Const $CRYPT_MODE_ECB = 2 _Crypt_Startup() $key = "abcdefghijuklmno" $key = _Crypt_ImportKey($CALG_AES_128, $key) _Crypt_SetKeyParam($key, $KP_MODE, $CRYPT_MODE_ECB) $str = _B64Decode($str) $s = _Crypt_DecryptData($str, $key, $CALG_USERKEY) if @error or @extended then $error = @error $extended = @extended EndIf _Crypt_DestroyKey($key) _Crypt_Shutdown() Return SetError($error,$extended,$s) EndFunc ;Author: ProgAndy, rewritten by FireFox ;return value: key handle Func _Crypt_ImportKey($iALG_ID, $sKey) Local Const $PLAINTEXTKEYBLOB = 0x8 ;The key is a session key. Local Const $CUR_BLOB_VERSION = 2 Local $bKey = Binary($sKey), $iKeyLen = BinaryLen($bKey) Local $tagPUBLICKEYBLOB = "struct; BYTE bType; BYTE bVersion; WORD reserved; dword aiKeyAlg; dword keysize; byte key[" & $iKeyLen & "]; endstruct;" Local $tBLOB = DllStructCreate($tagPUBLICKEYBLOB) DllStructSetData($tBLOB, "bType", $PLAINTEXTKEYBLOB) DllStructSetData($tBLOB, "bVersion", $CUR_BLOB_VERSION) DllStructSetData($tBLOB, "aiKeyAlg", $iALG_ID) DllStructSetData($tBLOB, "keysize", $iKeyLen) DllStructSetData($tBLOB, "key", Binary($bKey)) Local $aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptImportKey", "handle", __Crypt_Context(), "ptr", DllStructGetPtr($tBLOB), "dword", DllStructGetSize($tBLOB), "ptr", 0, "dword", 0, "ptr*", 0) If @error Then Return SetError(2, @error) Return SetError(Not $aRet[0], 0, $aRet[6]) EndFunc ;==>_Crypt_ImportKey ;Author: ProgAndy, rewritten by FireFox ;return value: int (bool) Func _Crypt_SetKeyParam($hKey, $iParam, $vData, $iFlags = 0, $sDataType = Default) If Not $sDataType Or $sDataType = Default Then $sDataType = "ptr" Local $aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptSetKeyParam", "handle", $hKey, "dword", $iParam, $sDataType, $vData, "dword", $iFlags) If @error Then Return SetError(2, @error) Return SetError(Not $aRet[0], 0, $aRet[0]) EndFunc ;==>_Crypt_SetKeyParam Func _B64Encode($sSource) ;####### (BinaryStrLen = 272) ######################################################################################################################## Local Static $Opcode = '0xC80000008B451499B903000000F7F189C18B5D108B75088B7D0C83FA007401418B060FC8C1E806C0E802D7884703C1E806C0E802D7884702C1E806C0E802D7884701C1E806C0E802D7880783C60383C704E2CD83FA0074288B46FD0FC883FA027411C1E8142430D78847FD66C747FE3D3DEB0DC1E80E243CD78847FEC647FF3DC60700C9C21000' Local Static $aMemBuff = DllCall("kernel32.dll", "ptr", "VirtualAlloc", "ptr", 0, "ulong_ptr", BinaryLen($Opcode), "dword", 4096, "dword", 64) Local Static $tMem = DllStructCreate('byte[' & BinaryLen($Opcode) & ']', $aMemBuff[0]) Local Static $set = DllStructSetData($tMem, 1, $Opcode) ;#################################################################################################################################################################################### $sSource = Binary($sSource) Local $iLen = BinaryLen($sSource) $tSource = DllStructCreate('byte[' & $iLen & ']') DllStructSetData($tSource, 1, $sSource) Local $tOutput = DllStructCreate('char[' & Ceiling($iLen * (4 / 3) + 3) & ']') DllCall("kernel32.dll", "bool", "VirtualProtect", "struct*", $tOutput, "dword_ptr", DllStructGetSize($tOutput), "dword", 0x00000004, "dword*", 0) Local $sTable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' DllCallAddress('none', DllStructGetPtr($tMem), 'struct*', $tSource, 'struct*', $tOutput, 'str', $sTable, 'uint', $iLen) Return DllStructGetData($tOutput, 1) EndFunc ;==>_B64Encode #cs Source Func _B64Encode($sSource) _FasmFunc('str, $sSource, str, $sDest, str, $sTable, uint, $iLen') _FasmAdd('mov eax, $iLen') ; div $iLen / 3 to calculate number of loops _FasmAdd('cdq') _FasmAdd('mov ecx, 3') _FasmAdd('div ecx') _FasmAdd('mov ecx, eax') ; Set loops _Fasmadd('mov ebx, $sTable') ; move table to ebx. Used in xlatb instruction _Fasmadd('mov esi, $sSource') ; set esi = source string _Fasmadd('mov edi, $sDest') ; set edi = output string _FasmJumpIf('edx = 0, EncodeNext') ; need one extra loop if mod <> 0 _FasmAdd('inc ecx') _FasmAdd('EncodeNext:') _Fasmadd('mov eax, [esi]') ; move 4 bytes from source string to dex _FasmAdd('bswap eax') ; reverse bytes. ex :(Man) 00000000 01101110 01100001 01001101 -> 01001101 01100001 01101110 00000000 _FasmAdd('shr eax, 6') _FasmAdd('shr al, 2') _FasmAdd('xlatb') _FasmAdd('mov [edi+3], al') _FasmAdd('shr eax, 6') _FasmAdd('shr al, 2') _FasmAdd('xlatb') _FasmAdd('mov [edi+2], al') _FasmAdd('shr eax, 6') _FasmAdd('shr al, 2') _FasmAdd('xlatb') _FasmAdd('mov [edi+1], al') _FasmAdd('shr eax, 6') _FasmAdd('shr al, 2') _FasmAdd('xlatb') _FasmAdd('mov [edi], al') _Fasmadd('add esi, 3') ; increase source by 3 bytes _fasmadd('add edi, 4') ; increase destination by 4 bytes _Fasmadd('loop EncodeNext') _FasmJumpIf('edx = 0, Finished') _Fasmadd('mov eax, [esi-3]') ; _FasmAdd('bswap eax') _FasmJumpIf('edx = 2, TWO') ; If there was only one significant input byte, only the first two base64 digits are picked (12 bits) _FasmAdd("ONE:") ; the four least significant bits of the final 6-bit block are set to zero _FasmAdd('shr eax, 20') _FasmAdd("and al, 48") ;00110000 _FasmAdd('xlatb') _FasmAdd('mov [edi-3], al') _FasmAdd("mov [edi-2], word 15677"); '==' _FasmAdd("jmp Finished") ; if there were two significant input bytes, the first three base64 digits are picked (18 bits). _FasmAdd("TWO:") ; the two least significant bits of the final 6-bit block are set to zero _FasmAdd("shr eax, 14") _FasmAdd("and al, 60") ; 60 : 00111100 _FasmAdd('xlatb') _FasmAdd('mov [edi-2], al') _FasmAdd('mov [edi-1], byte 61') ; '=' _FasmAdd('Finished:') _Fasmadd(' mov [edi], byte 0') ; terminate string with null _FasmEndFunc() Return _FasmCompileMC('_B64Encode') $sSource = Binary($sSource) Local $iLen = BinaryLen($sSource) $tSource = DllStructCreate('byte[' & $iLen & ']') DllStructSetData($tSource, 1, $sSource) Local $tOutput = DllStructCreate('char[' & Ceiling($iLen * (4 / 3) + 3) & ']') DllCall("kernel32.dll", "bool", "VirtualProtect", "struct*", $tOutput, "dword_ptr", DllStructGetSize($tOutput), "dword", 0x00000004, "dword*", 0) Local $sTable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' ConsoleWrite(StringInStr($sTable, '4') & @LF) _FasmQuickCall('none', 0, 'struct*', $tSource, 'struct*', $tOutput, 'str', $sTable, 'uint', $iLen) Return DllStructGetData($tOutput, 1) EndFunc ;==>_B64Encode #ce Func _B64Decode($sSource) Local Static $Opcode, $tMem, $tRevIndex, $fStartup = True If $fStartup Then If @AutoItX64 Then $Opcode = '0xC800000053574D89C74C89C74889D64889CB4C89C89948C7C10400000048F7F148C7C10300000048F7E14989C242807C0EFF3D750E49FFCA42807C0EFE3D750349FFCA4C89C89948C7C10800000048F7F14889C148FFC1488B064989CD48C7C108000000D7C0C0024188C349C1E30648C1E808E2EF49C1E308490FCB4C891F4883C7064883C6084C89E9E2CB4C89D05F5BC9C3' Else $Opcode = '0xC8080000FF75108B7D108B5D088B750C8B4D148B06D7C0C00288C2C1E808C1E206D7C0C00288C2C1E808C1E206D7C0C00288C2C1E808C1E206D7C0C00288C2C1E808C1E2060FCA891783C70383C604E2C2807EFF3D75084F807EFE3D75014FC6070089F85B29D8C9C21000' EndIf Local $aMemBuff = DllCall("kernel32.dll", "ptr", "VirtualAlloc", "ptr", 0, "ulong_ptr", BinaryLen($Opcode), "dword", 4096, "dword", 64) $tMem = DllStructCreate('byte[' & BinaryLen($Opcode) & ']', $aMemBuff[0]) DllStructSetData($tMem, 1, $Opcode) Local $aRevIndex[128] Local $aTable = StringToASCIIArray('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/') For $i = 0 To UBound($aTable) - 1 $aRevIndex[$aTable[$i]] = $i Next $tRevIndex = DllStructCreate('byte[' & 128 & ']') DllStructSetData($tRevIndex, 1, StringToBinary(StringFromASCIIArray($aRevIndex))) $fStartup = False EndIf Local $iLen = StringLen($sSource) Local $tOutput = DllStructCreate('byte[' & $iLen + 8 & ']') DllCall("kernel32.dll", "bool", "VirtualProtect", "struct*", $tOutput, "dword_ptr", DllStructGetSize($tOutput), "dword", 0x00000004, "dword*", 0) Local $tSource = DllStructCreate('char[' & $iLen + 8 & ']') DllStructSetData($tSource, 1, $sSource) Local $aRet = DllCallAddress('uint', DllStructGetPtr($tMem), 'struct*', $tRevIndex, 'struct*', $tSource, 'struct*', $tOutput, 'uint', (@AutoItX64 ? $iLen : $iLen / 4)) Return BinaryMid(DllStructGetData($tOutput, 1), 1, $aRet[0]) EndFunc ;==>_B64Decode and the php (to put in http://example.com/your.php)
  14. partial step complete! Using the B64DEcode from and B64Encode from further down the post returns the SAME data. Though the code is still not fully working, it gets me past that issue and I can continue - THANKS.
  15. looks like...... I had seen that thread, though didn't follow it on - will look into it there. thanks for the tip - will see how it goes.
  16. Been working with this and the encryption side works great. However, to implement everything, the DECRYPT side is needed as well. I have the php side working, though having issues with the AutoIt decrypt side and need some help.... Here's the full code - I'll describe the bits below #include <Crypt.au3> #include "Base64.au3" Global $error Global $extended Local $str = "hello world!" ConsoleWrite("string to encrypt/decrypt is " & $str & @crlf& @crlf) ConsoleWrite("starting ENCRYPTION" & @crlf) Local $encrypted = _Cryptshun($str) if @error or @extended Then ConsoleWrite("error on encryption is " & @error & @crlf & "extended is " & @extended & @crlf & "decrypted = " & BinaryToString($encrypted) & @crlf&@CRLF) else ConsoleWrite("$encrypted is " & $encrypted & @crlf&@CRLF) EndIf ConsoleWrite("starting DECRYPTION (Binary)" & @crlf) Local $decrypted = _DeCryptshun($encrypted) if @error or @extended Then ConsoleWrite("error on decryption is " & @error & @crlf & "extended is " & @extended & @crlf & "decrypted = " & BinaryToString($decrypted) & @crlf&@CRLF) else ConsoleWrite("decrypted raw = " & BinaryToString($decrypted) & @crlf&@CRLF) EndIf ; Things work to here - at least encrypt/decrypt ; We now know that to get the decrypt to work, we need BINARY data ; However, in order to match to the PHP, we need _Base64Encode ; try it with encoding (required to match to the PHP) ConsoleWrite("starting DECRYPTION with ENCODING , DECODING to binary" & @crlf) Local $encoded = _Base64Encode($encrypted) ConsoleWrite("base64encoded is " & $encoded & @crlf) ; at this point I can send to the php and get the correct decrypt, match a code, etc. (php function) ; then return encrypted data (base64encoded) - all that works ; emulating that in this program to simply get DECRYPT to work on this encrypted data Local $decoded = _Base64Decode($encoded) ConsoleWrite("base64decoded is " & $decoded & @crlf) ; this is where things fall apart - WHY IS THE DECODE NOT THE SAME AS THE ORIGINAL DATA? ; my thought is that _Base64Decode is broken, but see below - it works fine ; when the data from the ENCODED is simply copied, but it does NOT work when ; run through directly ; this code SHOULD work - once the decode is correct (I think...) Local $decoded2bin = StringToBinary($decoded) ConsoleWrite("base64decoded2bin is " & $decoded2bin & @crlf) $decrypted = _DeCryptshun($decoded2bin) if @error or @extended Then ConsoleWrite("error on decryption is " & @error & @crlf & "extended is " & @extended & @crlf & "decrypted = " & BinaryToString($decrypted) & @crlf& @crlf) else ConsoleWrite("decrypted raw = " & BinaryToString($decrypted) & @crlf& @crlf) EndIf ConsoleWrite("TESTING _BASE64ENCODE/DECODE"&@crlf) $str = "dSbB0RQtD//8xY0fvpso8Q==" ConsoleWrite("string is " & $str & @crlf) ConsoleWrite("base64encoded = " & _Base64Encode($str) & @crlf) ConsoleWrite("base64decoded = " & _Base64Decode(_Base64Encode($str)) & @crlf) Func _Cryptshun($str) ; function to match up with php side encryption/decryption ; from http://www.autoitscript.com/forum/topic/150967-aes-256-encryption-in-autoit-php/ Dim Const $KP_MODE = 4 Dim Const $CRYPT_MODE_ECB = 2 _Crypt_Startup() $key = "abcdefghijuklmno" $key = _Crypt_ImportKey($CALG_AES_128, $key) _Crypt_SetKeyParam($key, $KP_MODE, $CRYPT_MODE_ECB) $s = _Crypt_EncryptData($str, $key, $CALG_USERKEY) if @error or @extended then $error = @error $extended = @extended EndIf _Crypt_DestroyKey($key) _Crypt_Shutdown() ;$s = _Base64Encode($s) Return SetError($error,$extended,$s) EndFunc Func _DeCryptshun($str) Dim Const $KP_MODE = 4 Dim Const $CRYPT_MODE_ECB = 2 _Crypt_Startup() $key = "abcdefghijuklmno" $key = _Crypt_ImportKey($CALG_AES_128, $key) _Crypt_SetKeyParam($key, $KP_MODE, $CRYPT_MODE_ECB) ;$str = _Base64Decode($str) ;ConsoleWrite("base64 decoded string - " & $str & @crlf) ;$str = StringToBinary($str) ;ConsoleWrite("stringtobinary = " & $str & @crlf) $s = _Crypt_DecryptData($str, $key, $CALG_USERKEY) if @error or @extended then $error = @error $extended = @extended EndIf _Crypt_DestroyKey($key) _Crypt_Shutdown() Return SetError($error,$extended,$s) EndFunc ;Author: ProgAndy, rewritten by FireFox ;return value: key handle Func _Crypt_ImportKey($iALG_ID, $sKey) Local Const $PLAINTEXTKEYBLOB = 0x8 ;The key is a session key. Local Const $CUR_BLOB_VERSION = 2 Local $bKey = Binary($sKey), $iKeyLen = BinaryLen($bKey) Local $tagPUBLICKEYBLOB = "struct; BYTE bType; BYTE bVersion; WORD reserved; dword aiKeyAlg; dword keysize; byte key[" & $iKeyLen & "]; endstruct;" Local $tBLOB = DllStructCreate($tagPUBLICKEYBLOB) DllStructSetData($tBLOB, "bType", $PLAINTEXTKEYBLOB) DllStructSetData($tBLOB, "bVersion", $CUR_BLOB_VERSION) DllStructSetData($tBLOB, "aiKeyAlg", $iALG_ID) DllStructSetData($tBLOB, "keysize", $iKeyLen) DllStructSetData($tBLOB, "key", Binary($bKey)) Local $aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptImportKey", "handle", __Crypt_Context(), "ptr", DllStructGetPtr($tBLOB), "dword", DllStructGetSize($tBLOB), "ptr", 0, "dword", 0, "ptr*", 0) If @error Then Return SetError(2, @error) Return SetError(Not $aRet[0], 0, $aRet[6]) EndFunc ;==>_Crypt_ImportKey ;Author: ProgAndy, rewritten by FireFox ;return value: int (bool) Func _Crypt_SetKeyParam($hKey, $iParam, $vData, $iFlags = 0, $sDataType = Default) If Not $sDataType Or $sDataType = Default Then $sDataType = "ptr" Local $aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptSetKeyParam", "handle", $hKey, "dword", $iParam, $sDataType, $vData, "dword", $iFlags) If @error Then Return SetError(2, @error) Return SetError(Not $aRet[0], 0, $aRet[0]) EndFunc ;==>_Crypt_SetKeyParam Now, to break it down..... I found that, to decrypt the data we just encrypted, we need to have the BINARY data to send to _Crypt_DecryptData up to line 24, that works However, to go to the PHP side, we need base64encoded data Taking the encrypted data into _Base64Encode, we come up with "dSbB0RQtD//8xY0fvpso8Q==" - that works when sent to the php decode. However, it does NOT work when I send it to _Base64Decode - I don't get the same binary data back _Base64Decode(_Base64Encode($EncryptedData)) = $EncryptedData should be the equation, shouldn't it??? Testing the _Base64Encode and then _Base64Decode on that string works (line 54-58, where the string was copied from the console screen into the code), though it is not working when sent directly. I am sure this is some sort of declaration on strings that I'm missing, though I have tried all the StringX() functions and not come up with anything (coming from the php world I'm not used to these declarations yet....) What it boils down to is - How do I get the same data to come out? (hopefully I'm making sense - been on this for two days and just really stuck!)
  17. Seems like you are on the right track. You will get a lot more help, though, when you go through the code and discuss what problems you have. Simply posting the shell makes it difficult for anyone to do much (unless they have all the programs you have, etc.) Be more direct on the issues you have and there are plenty of people that will help.
  18. KyS, Thanks for messing with it - works great! And, what a fantastic first post! Welcome to this forum! I am using AutoIt a lot, though these Dll things have me stumped (seems way too complicated to me..) - I see what you did and will learn from it. I'm actually working with another section that also uses dlls - perhaps this will work there as well (if not, be looking on the forum for my post about that...... - great to have this resource when you really get stuck!) Thanks again.
  19. YEAH! Much easier to read when things stay put! (though, I could try to take the advise of "don't make long lines in the code"....... - NOT!) and, mLipok, I was using F1......
  20. I've looked in lots of places, tried multiple settings and nothing has helped so far, so I turn to the forum (for a likely super simple thing....) The help for SciTE takes me to AutoIt help (which is not what I need - at the moment...) How do I turn OFF this auto-resizing in SciTE? It drives me crazy, jumping around all over the place. I try to scroll up a line to see some function and all of a sudden, it moves everything around. I prefer a 'simple' view - one that I control, not the program....... (yes, I will calm down....... - when I can stop the flashing screen!)
  21. Granted, waiting for Windows to start is a great example of 'a good time to have a long sleep'......... However, instead of sleep(), I would rather consider alternatives like WinWait - i.e., watch some 'trigger'. You might use a sleep(x) (some small number) in a loop if that is what you need (for instance, you require Internet to be active, so do a "While $not_connected" or something), I just prefer to be more pro-active and look for the event, not just sleep() as a first command. But, that is why there are many options in the code - each person has their own preference - none 'wrong', just different ways of looking at things.
  22. Like any new adventure, the LAST thing you should do is 'sleep'! (think of visiting a new place, new city, new country!) First thing you would want to do is 'look around' a bit and see what might be 'interesting' - if nothing else, at least set some bearings and/or 'rules'.......... So, what mikell suggested is quite valid - first, set up some 'rules' (i.e., parameters) and THEN do some 'looking around' - in this case, check out "from 1 to 10" - and, possibly, then (maybe even AS you are counting, if it makes sense...) do some 'sleep' but, IMHO, a program should NEVER begin with SLEEP!
  23. one other thing (and I was as guilty as you on this.....) - - - - - be sure when you are giving credit, that you PROPERLY state the user name of the person that contributed......... guinness contributed that one bit of dll code, not "Guiness" as you stated, nor 'guiness' that I stated. My official apologies........
  24. project is a commercially available product (sorry, can't/won't discuss that publicly, though the snippet is now 'open source'... - funny enough, 'clearly' explained at )'>)
  25. May be 'simplified', however, as stated in that post, my 'vote' is for the way guiness presented it - reads the dll the same as MS products - i.e., doesn't consume more resources and is 'equivalent' for many purposes. When I get some time I'm going to study your multi-methods a bit more for one project I have (my program is faster than MS and works great for special purposes) and see if there is some 'combo' that makes for a better fit, though, lacking additional tests, I would say that a choice between the dll method and the 'fast' one that mirrors what Windows does (only with your own timer) seems to be the best. Oh, on the VPN - sorry, can't help you, but I understand/feel that pain - being behind a router that is still running, but no internet connection is what caused me to research and get that function going. BTW, I posted on this as I like your GUI idea (though would like to see it smaller - like 150 px high or something - would make a neat horizontal or vertical 'light' bar maybe?)
×
×
  • Create New...