Jump to content

lowbattery

Active Members
  • Posts

    22
  • Joined

  • Last visited

Everything posted by lowbattery

  1. Thank you for your response jchd. It is much appreciated! I have one follow-up question based on what you said. I receive JSON via a CLI curl which was sent to my script in UTF8 format. Upon receipt, I have been running BinaryToString($sReceivedData, $SB_UTF8). So it is correct to assume that the data is in UTF8 format upon using the BinaryToString() conversion I just mentioned? It seems that way. Your English is better than mine and I'm a native speaker! But the proposal would be: If you only need to convert UTF8 to/from native AutoIt strings you can use this $sUTF8String = "Hello Χαίρετε こんにちは Привет xin chào हैलो مرحبا 你好 שלום வணக்கம்" $sANSIString = BinaryToString(StringToBinary($sUTF8String & @LF, 4), 1) ; reverse conversion: $sBackToUTF8 = BinaryToString(StringToBinary($sUTF8String & @LF, 1), 4) Is the @LF needed in StringToBinary() as it seems to work without it? But I'm also not very smart lol, so I probably am missing something. Also, is $sANSIString basically UCS2? I don't see any conversions functions to/from UCS2, but again, not very smart, so I'm probably missing something.
  2. The docs say that native AutoIt strings use UCS-2. But when I run this code: $sString1 = "Hello" MsgBox(0, '', $sString1) $sString2 = $sString1 & " こんにちは" MsgBox(0, '', $sString2) I get this: So isn't the string in UTF8 already and not USC-2? Also, referring back to those linked docs: But isn't $sMyString already in UTF8? It seems that $sUTF8String is actually a conversion to ANSI since the output gives: Which makes sense because BinaryToString() is using option 1 for ANSI. So does the latest version of AutoIt run in UTF8+BOM by default and the docs are wrong? Or am I not understating what a "native" string is in AutoIt?
  3. I have a monster script of a program. About 35,000 lines. In a given situation, the memory starts increasing as a certain (complex) operation is performed. It goes from 150mb eventually to about 1,500mb over the span of a few hours. As far as I'm aware, I'm not deliberately storing data that I'm processing in memory. After I process it, I dump it into a file and move onto the next task. But there are so many moving parts, that it's hard for me to pinpoint what's causing the memory growth. So is there any way to check what variables in a program are growing, or where a potential leak is coming from?
  4. Wow. Claude Sonnet 3.5 doesn't fail to impress me! Func EncodeUnicode($sText) Local $aResult = "" Local $iLen = StringLen($sText) Local $i = 1 While $i <= $iLen Local $iCode = AscW(StringMid($sText, $i, 1)) ; Check if this is a high surrogate (first part of surrogate pair) If $iCode >= 0xD800 And $iCode <= 0xDBFF And $i < $iLen Then ; Get the low surrogate (second part) Local $iLowSurrogate = AscW(StringMid($sText, $i + 1, 1)) If $iLowSurrogate >= 0xDC00 And $iLowSurrogate <= 0xDFFF Then ; Valid surrogate pair - encode both parts $aResult &= "\u" & StringLower(Hex($iCode, 4)) & "\u" & StringLower(Hex($iLowSurrogate, 4)) $i += 2 ; Skip the next character as weve already processed it ContinueLoop EndIf EndIf ; Handle regular characters If $iCode > 127 Then $aResult &= "\u" & StringLower(Hex($iCode, 4)) Else $aResult &= StringMid($sText, $i, 1) EndIf $i += 1 WEnd Return $aResult EndFunc ; Helper function to test the encoding Func TestEncoding() Local $aTestCases[][2] = [ _ ["🐒", "\ud83d\udc12"], _ ["💧", "\ud83d\udca7"], _ ["Hello 👋 World", "Hello \ud83d\udc4b World"], _ ["🌍", "\ud83c\udf0d"], _ ["😀", "\ud83d\ude00"] _ ] For $i = 0 To UBound($aTestCases) - 1 Local $sInput = $aTestCases[$i][0] Local $sExpected = $aTestCases[$i][1] Local $sResult = EncodeUnicode($sInput) ConsoleWrite("Input: " & $sInput & @CRLF) ConsoleWrite("Expected: " & $sExpected & @CRLF) ConsoleWrite("Got: " & $sResult & @CRLF) ConsoleWrite("Match: " & ($sResult = $sExpected) & @CRLF & @CRLF) Next EndFunc
  5. I've been using code for a long time to escape unicode text: Execute(StringRegExpReplace($sData, '(.)', '(AscW("$1")>127?"\\u"&StringLower(Hex(AscW("$1"),4)):"$1")&') & "''") But it seems to return incorrect data on certain characters. For example: 🐒 Should encode to: \ud83d\udc12 But that code is encoding it to: \ud83d As another example: 💧 Should encode to: \ud83d\udca7 But the autoit code is encoding it to: \ud83d Any ideas on what's going on and how I can adjust the autoit code to properly encode the emojis?
  6. Forgive my ignorance, but how do I run au3stripper. I tried in the past, but the docs point to a directory inside SciTE that doesn't exist. I also tried adding #Au3Stripper_Parameters=/MergeOnly to the top of my Au3 and compiled it but that didn't seem to do anything either. I truly have looked into it but gave up after about an hour and haven't tried again until now. Edit: Nevermind. It seems that your bio link has a link to the portable version which has au3stripper. For waterer reason the SciTE that comes with AutoIt install lacks it.
  7. Yeah, that's what's happening. But at 13,000 lines, and lots of Redim, it can get tricky. Oh well. I figured there might be something easier.
  8. Some of my end users might occasionally get the dreaded "subscript used on non-accessible variable" message with a line number that's only relevant to the compiled version. Usually debugging this is therefore a nightmare for me. Is there an easier solution to debug this issue? Obviously it's things that SciTE's Syntax Check doesn't catch.
  9. WOW! It works! Thank you so much TheXMan! The DllStruct functions are totally foreign to me and I would have never solved that on my own! $tImgData = DllStructCreate(StringFormat("byte bytes[%i];", $iImgSize)) $tImgData.bytes = FileRead($sImgFilePath) That's like ninja level stuff. Is there somewhere I can learn more about the techniques you're using here? I can't make the mental leap from the DLLStructureCreate docs to what you created here, and the $tImgdata.bytes buffer.
  10. I use the CLI a lot but since some windows installs don’t come with curl or have a differently compiled version, I provide it to end users. However, some of their systems view it as a virus. Other systems flag it as a virus when I make requests through SSL (which I think might be avoided with libcurl). Another reason for wanting to switch to the UDF is that the CLI through shell execution has length limits for some things (as far as I know). So worst case, I could use the UDF for most things and the CLI for images, but having everything done one way would be a benefit.
  11. Just a follow-up. I can use the UDF to make a new post. The code below does work. It even works if we add the Curl_Easy_Setopt($Curl, $CURLOPT_HTTP_VERSION, $CURL_HTTP_VERSION_1_1) line. It's just the image code above that I'm still stuck on. Local $jsonData _JSON_addChangeDelete($jsonData, "title", 'test article') _JSON_addChangeDelete($jsonData, "content", 'test content') _JSON_addChangeDelete($jsonData, "status", 'draft') $jData = _JSON_GenerateCompact($jsonData) $WPAppUser = "wordpress user name" $WPAppPW = "wordpress app password for the user name" Local $Curl = Curl_Easy_Init() If Not $Curl Then Return Local $Html = $Curl ; any number as identify Local $Header = $Curl + 1 ; any number as identify Local $arrHeaders = Curl_Slist_Append(0, "Accept: application/json") $arrHeaders = Curl_Slist_Append($arrHeaders, "Content-Type: application/json") Curl_Easy_Setopt($Curl, $CURLOPT_URL, "https://www.mysite.com/wp-json/wp/v2/posts") Curl_Easy_Setopt($Curl, $CURLOPT_ACCEPT_ENCODING, '') Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_DataWriteCallback()) Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $Html) Curl_Easy_Setopt($Curl, $CURLOPT_MAXREDIRS, 10) Curl_Easy_Setopt($Curl, $CURLOPT_TIMEOUT, 30) Curl_Easy_Setopt($Curl, $CURLOPT_USERPWD, $WPAppUser&':'&$WPAppPW) Curl_Easy_Setopt($Curl, $CURLOPT_FOLLOWLOCATION, 1) Curl_Easy_Setopt($Curl, $CURLOPT_HTTPHEADER, $arrHeaders) Curl_Easy_Setopt($Curl, $CURLOPT_POST, '1L') Curl_Easy_Setopt($Curl, $CURLOPT_COPYPOSTFIELDS, $jData) ;peer verification curl_easy_setopt($Curl, $CURLOPT_CAINFO, @ScriptDir & '\curl-ca-bundle.crt') ; curl_easy_setopt($Curl, $CURLOPT_SSL_VERIFYPEER, 1) Local $Code = Curl_Easy_Perform($Curl) If $Code = $CURLE_OK Then ConsoleWrite("Content Type: " & Curl_Easy_GetInfo($Curl, $CURLINFO_CONTENT_TYPE) & @LF) ;ConsoleWrite("Download Size: " & Curl_Easy_GetInfo($Curl, $CURLINFO_SIZE_DOWNLOAD) & @LF) ConsoleWrite('Header: ' & @CRLF & BinaryToString(Curl_Data_Get($Header)) & @LF) MsgBox(0, 'Html', BinaryToString(Curl_Data_Get($Html))) Else ConsoleWrite(Curl_Easy_StrError($Code) & @LF) EndIf Curl_Slist_Free_All($arrHeaders) Curl_Easy_Cleanup($Curl) Curl_Data_Cleanup($Header) Curl_Data_Cleanup($Html)
  12. I am seeing the same thing. Not sure what to do. Hmm. I have tried this: Curl_Easy_Setopt($Curl, $CURLOPT_POSTFIELDS, '@Curlx64/hardware_store.jpg') and with $CURL_HTTP_VERSION_1_1 I get a file uploaded, it's the correct size (likely due to the $sFileSize), but it's not a valid JPG. So it seems that the file isn't being uploaded. I tried that because https://stackoverflow.com/questions/10322646/how-does-one-post-a-binary-file-stored-locally-using-php-curl suggested something like that might be possible. But in PHP they insert the file link as an array. Not sure how array('file' => '@foo.ext') translates to AutoIt though...
  13. Oops. I have to apologize. I have so many UDFs I got it confused. Yes, that rewrite by @Beege is the one I'm using. I'm sorry about that mix-up. I re-titled the form post to reflect it.
  14. Hi KaFu. I'm 100% positive because when I run it, and refresh my media library, I see the image uploaded. Your message is likely because you haven't created an application password for a particular user on your WP site. Go to the user's account, scroll all the way to the bottom, and you can make an application password. I attached a screenshot to show you what it looks like. Now the $WPAppUser variable is your user's username, but the $WPAppPW is the user's application password you just made (not their account password). As for the URL, it's simply "https://www.mysite.com/wp-json/wp/v2/media" (replacing mysite with your domain). You shouldn't add any trailing destination as the filename is handled by the headers. Just note that the test.jpg file needs to be in your script directory, otherwise you need to @somedir/test.jpg to get to it. As for the UDF, it's something to do with either the file read or the $CURLOPT_POSTFIELDSIZE. When I don't specify CURLOPT_POSTFIELDSIZE I get a "{"code":"rest_upload_no_data","message":"No data supplied.","data":{"status":400}}Done." response. I also got it to upload a file into the media library (I forget how) but it was just an empty file. Nothing inside of it and so it wasn't a valid image. When I add CURLOPT_POSTFIELDSIZE, using the binary length (which I believe is the requirement for binary files), I get a HTML response with a H1 message saying 400 - Bad Request. I'm stumped.
  15. I'm trying to upload a JPG image to my WordPress site. I have the command line curl working. It successfully uploads the jpg image. $str = 'curl.exe -s --request POST --url https://www.mysite.com/wp-json/wp/v2/media --header "cache-control: no-cache" --header "content-disposition: attachment; filename=file.jpg" --header "authorization: Basic '&base64($WPAppUser&':'&$WPAppPW)&' " --header "content-type: image/jpg" --data-binary "@hardware_store.jpg" --location' $iPidCurl = Run($str, '', @SW_HIDE, $STDERR_MERGED) But when I try to replicate it in Beege's UDF, I get a "400 - Bad Request" response from my server. Here is what I have for the UDF code: $imageLoc = @ScriptDir & "\hardware_store.jpg" Local $hFileOpen = FileOpen($imageLoc, 16) Local $sFileRead = FileRead($hFileOpen) $sFileSize = BinaryLen($sFileRead) FileClose($hFileOpen) Local $Curl = Curl_Easy_Init() If Not $Curl Then Return Local $arrHeaders = Curl_Slist_Append(0, "Cache-Control: no-cache") $arrHeaders = Curl_Slist_Append($arrHeaders, "Content-Type: image/jpg") $arrHeaders = Curl_Slist_Append($arrHeaders, "Content-Disposition: attachment; filename=test.jpg") Curl_Easy_Setopt($Curl, $CURLOPT_URL, "https://www.mysite.com/wp-json/wp/v2/media") Curl_Easy_Setopt($Curl, $CURLOPT_HTTPHEADER, $arrHeaders) Curl_Easy_Setopt($Curl, $CURLOPT_ACCEPT_ENCODING, '') Curl_Easy_Setopt($Curl, $CURLOPT_USERAGENT, "AutoIt/Curl") Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_DataWriteCallback()) Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $Curl) Curl_Easy_Setopt($Curl, $CURLOPT_MAXREDIRS, 10) Curl_Easy_Setopt($Curl, $CURLOPT_TIMEOUT, 30) Curl_Easy_Setopt($Curl, $CURLOPT_USERPWD, $WPAppUser&':'&$WPAppPW) Curl_Easy_Setopt($Curl, $CURLOPT_FOLLOWLOCATION, 1) Curl_Easy_Setopt($Curl, $CURLOPT_POSTFIELDS, $sFileRead) Curl_Easy_Setopt($Curl, $CURLOPT_POSTFIELDSIZE, $sFileSize) ;peer verification curl_easy_setopt($Curl, $CURLOPT_CAINFO, @ScriptDir & '\curl-ca-bundle.crt') ; curl_easy_setopt($Curl, $CURLOPT_SSL_VERIFYPEER, 1) Local $Code = Curl_Easy_Perform($Curl) If $Code <> $CURLE_OK Then Return ConsoleWrite(Curl_Easy_StrError($Code) & @LF) ConsoleWrite(BinaryToString(Curl_Data_Get($Curl))) I've tried just about everything, but I can't figure out what's causing it not to work.
  16. I'm trying to send some -d data (json actually) but I can't figure it out. I don't know which global Enum_ function to use. Can someone point me in the right direction? Also, while I'm using the Curl rewrite UDF, I did see this post here which referred to using Ward's version. But I still can't make heads or tail of how to use it.
  17. I made some GUIs in my application and some of them use Opt("GUICoordMode", 2). But it seems when this is set, the buttons in _ExtMsgBox basically break as they appear off-menu. The easiest way to replicate this issue is to simply open ExtMsgBox_Example_1.au3 and change this code: Case $hButton1 ; Set the centred value and font size, leave colours and font name unchanged, set default sizes and change default focus button character ;_ExtMsgBoxSet(2, $SS_CENTER, -1, -1, 9, -1, Default, Default, "#") Opt("GUICoordMode", 2) $sMsg = "This is centred on 'EMB Test' with the AutoIt icon, 4 buttons, centred text,a Taskbar button and TOPMOST not set" & @CRLF & @CRLF $sMsg &= "The width is set to maximum by the requirement for 4 buttons and the text will wrap if required to fit in" & @CRLF & @CRLF $sMsg &= "Button 4 is set as default and will action on 'Enter' or 'Space'" & @CRLF & @CRLF $sMsg &= "It will not time out" $iRetValue = _ExtMsgBox(@AutoItExe, "OK|Cancel", "Test 1", $sMsg, 0, $hTest_GUI) ; Note changed focus button character ConsoleWrite("Test 1 returned: " & $iRetValue & @CRLF) ; Reset to default, including default focus button character _ExtMsgBoxSet(Default) By adding that Opt("GUICoordMode", 2), it breaks the demo as the buttons now appear offscreen. EDIT: I solved this by adding Local $oldCoord = Opt("GUICoordMode", 1) to the beginning of _ExtMsgBox and Opt("GUICoordMode", $oldCoord) to the end. Is that the best approach?
  18. Fantastic! I am somewhat new to the scrollbars functions. Those recommendations did the trick. Thanks!
  19. I have a long vertical menu that the user can add and remove items from. The vertical spacing between items is all dynamically recomputed based on how many items they've added. When they add items, I delete the $hGUI and regenerate it. I'm not sure that's the best solution, but it's where I am at the moment. The only trouble I'm running into is the default scroll position when I regenerate the GUI and _GUIScrollbars_Generate is the very top. So I want to store the current scroll position in a global and then just jump back to that position when the GUI is regenerated. I was looking through the GUIScrollbars_Ex code but I can't seem to figure it out. Is this possible? Thanks!
  20. Bitdefender is flagging the CMD as a virus. "....cmd.prog is infected with Gen:Heur.PHM.1. The threat has been successfully blocked, your device is safe." Any recommendations?
  21. I was excited to finally finish my program, compiled it to exe, soft-launched it and... BOOM. Windows defender kept removing it from people's computers, along with malwarebytes, and some other virus scanners. This is a big pain in the butt because I'm having a big launch soon and can't have people (who struggle to do a lot of tech things) go through steps of un-quarantining the file. So I dug around on these forums and have a few questions that maybe some veterans could help me understand. Is compiling to an A3X (instead of an exe) the recommended approach for both stopping windows defender and virus scanners from being annoying? Also, is it just as secure from preventing a decompile as if I were to have compiled it to an exe? I also read that some people suggested running Au3Stripper first before compiling to A3X. Is this necessary? If so, I can't for the life of me find it in SciTE. Where is it? Finally, I also read a thread about a fellow who created an AU3toCMD script. So you'd create an all-in-1 CMD file in lieu of the A3X route above. Is this even better to avoid triggering virus scanners and windows defender?
×
×
  • Create New...