Leaderboard
Popular Content
Showing content with the highest reputation on 05/23/2023 in all areas
-
Latest update just released. See below for change log.2 points
-
Help with best way to do this function
pixelsearch and one other reacted to Andreik for a topic
In case you ever want to customize these functions (maybe modifying to start from 1 as minimum, not from 0) here is the code for assembly functions. [Fill struct] mov esi, [esp + 4] mov ecx, [esp + 8] next: mov dword[esi], 0FFFFFFFFh add esi, 4 loop next ret 8 [Find minimum] mov esi, [esp + 4] mov ecx, [esp + 8] xor edx, edx next: lodsd cmp eax, edx je increase loop next jmp exit increase: mov esi, [esp + 4] mov ecx, [esp + 8] inc edx jmp next exit: mov eax, edx ret 8 [Write minimum] mov esi, [esp + 4] mov ecx, [esp + 8] mov edx, [esp + 0Ch] next: lodsd cmp eax, 0FFFFFFFFh je update loop next mov eax, 0FFFFFFFFh jmp exit update: mov dword[esi-4], edx mov eax, 0 exit: ret 122 points -
Or maybe some low level code: #include <WinAPIDiag.au3> Global $hListView, $cListView Global $tData = DllStructCreate('int Data[20000]') $hMain = GUICreate('Sample code', 400, 400) $cListView = GUICtrlCreateListView('Numbers', 10, 10, 380, 380, 0x0C, 0x21) ; LVS_SINGLESEL, LVS_SHOWSELALWAYS, LVS_EX_GRIDLINES, LVS_EX_FULLROWSELECT $hListView = GUICtrlGetHandle($cListView) GUISetState(@SW_SHOW, $hMain) FillStruct($tData) LoadSomeTestNumbers($cListView, $tData) GUIRegisterMsg(0x004E, 'WM_NOTIFY') Do Sleep(10) Until GUIGetMsg() = -3 ; GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $iCode = DllStructGetData($tNMHDR, "Code") If $hListView = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) And $iCode = -2 Then ; NM_CLICK Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam) ; When I click a particular cell (let's say 4th cell of the listview) If DllStructGetData($tNMITEMACTIVATE, 'Index') = 3 Then Local $Minimum = GetMinimum($tData) GUICtrlCreateListViewItem($Minimum, $cListView) WriteNumber($tData, $Minimum) EndIf EndIf Return 'GUI_RUNDEFMSG' EndFunc Func LoadSomeTestNumbers($cListView, $tStruct) Local $aNumbers[10] = [15, 1, 6, 5, 7, 9, 3, 8, 12, 25] For $Index = 0 To 9 GUICtrlCreateListViewItem($aNumbers[$Index], $cListView) WriteNumber($tData, $aNumbers[$Index]) Next EndFunc Func FillStruct($tStruct) Local $Code = Binary('0x8B7424048B4C2408C706FFFFFFFF83C604E2F5C20800') Local $iSize = BinaryLen($Code) Local $tCode = DllStructCreate('byte Code[' & $iSize & ']') DllStructSetData($tCode, 'Code', $Code) Local $aCall = DllCallAddress('int', DllStructGetPtr($tCode), 'ptr', DllStructGetPtr($tStruct), 'int', DllStructGetSize($tStruct) / 4) EndFunc Func GetMinimum($tStruct) Local $Code = Binary('0x8B7424048B4C240831D2AD39D07404E2F9EB0B8B7424048B4C240842EBEC89D0C20800') Local $iSize = BinaryLen($Code) Local $tCode = DllStructCreate('byte Code[' & $iSize & ']') DllStructSetData($tCode, 'Code', $Code) Local $aCall = DllCallAddress('int', DllStructGetPtr($tCode), 'ptr', DllStructGetPtr($tStruct), 'int', DllStructGetSize($tStruct) / 4) Return $aCall[0] EndFunc Func WriteNumber($tStruct, $Minimum) Local $Code = Binary('0x8B7424048B4C24088B54240CAD83F8FF7409E2F8B8FFFFFFFFEB088956FCB800000000C20C00') Local $iSize = BinaryLen($Code) Local $tCode = DllStructCreate('byte Code[' & $iSize & ']') DllStructSetData($tCode, 'Code', $Code) Local $aCall = DllCallAddress('int', DllStructGetPtr($tCode), 'ptr', DllStructGetPtr($tStruct), 'int', DllStructGetSize($tStruct) / 4, 'int', $Minimum) Return $aCall[0] EndFunc On my PC to get (and then write) 10 minimum integers on a reserved memory that holds 20k integers take less then 1 ms. Is that fast enough?2 points
-
Help with best way to do this function
pixelsearch reacted to Andreik for a topic
Glad you made the test and you got your answer. It's a naive approach but I will explain anyway how I got this to work. FillStruct is straight forward and fill the entire structure with 0xFFFFFFFF (or -1 if we talk about signed integers). It's some kind of initialization of the array. FindMinimum check if a given number is already saved in the structure. How it does that? It starts from 0 and compare each 4 bytes (an integer) if it's equal with zero. If 0 is found somewhere in that array, it means 0 it's not the minimum so will increase the number by one and starts again from the beginning of the struct and go through the same process and check every single integer in the structure. If that number is not found anywhere, it means we got the minimum value. WriteNumber basically check for the first "empty/unwritten" integer with value 0xFFFFFFFF and write the value at that address.1 point -
Help with best way to do this function
Danyfirex reacted to pixelsearch for a topic
@Andreik nicely done, though I don't understand a single word in assembly language I wanted to make sure that your code really compared each and every element of the [20000] array (as it's so fast !) so this is what I did, on a smaller array (40 elements => structure $tdata is now 160 bytes length) ; Global $tData = DllStructCreate('int Data[20000]') ; structure is 80.000 length (4 * 20000) Global $tData = DllStructCreate('int Data[40]') ; structure is 160 length (4 * 40) When we create the structure, it's filled with 0's (normal behavior) then your function FillStruct() immediately replaces all 0's with 0xFF, so far so good. 1) Normal Andreik script (smaller struct for the pics) Upper part of the pic : the 10 tests numbers have been added to the structure, e.g [15, 1, 6, 5, 7, 9, 3, 8, 12, 25] . First one (15) is 0x0F 00 00 00 and last one (25) is 0x19 00 00 00 . We also notice that 0 and 2 are not part of tests numbers. Lower part of the pic, left side : 1st clic on 3rd row (e.g. 4th element) in LV and 0x00 00 00 00 is correctly added in the structure Lower part of the pic, right side : 2nd clic in LV and 0x02 00 00 00 is correctly added in the structure. From now on, it would be the same pattern after each click (I got another pic where 0x04 00 00 00 is correctly added etc...) To make sure that the script didn't stop the search when the 1st 0xFF FF FF FF is quickly found (and apart from checking the assembly code), this is what I did : 2) Altered Andreik script (added 0 at end of struc) I added 1 line to the script, at the very end of the LoadSomeTestNumbers function : DllStructSetData($tData, 'Data', 0, 40) ; write 0x00 in last element [40] replacing 4 last 0xFF with 4 0x00 Which means that before the 1st click in LV, there is now an additional "test number" 0x00 (placed at the very end of the structure). What will be the value displayed in LV after the 1st click (e.g returned from the assembly function GetMinimum), will it be 0 or 2 ? The answer is 2, as shown in LV and on the right side of the pic. So yes, all elements of the array have been correctly checked (40 in my case, 20.000 in the original script), well done Andreik1 point -
If only I had a dollar for every time someone asks me if I code in the D programming language1 point
-
Again sorry, I solved this by myself. wchar* will do the work.1 point
-
Huffman encoding/decoding + helpers for binary data
kurtykurtyboy reacted to AspirinJunkie for a topic
Introduction The following UDF can be used to compress a string into a binary via Huffman encoding. To keep the overhead for the huff table integrated in the binary as small as possible, the canonical form of the huffman table was implemented. The UDF accesses many functionalities of the UDF "BinaryHelpers.au3". This is also part of the repository and offers functionalities for simplified handling of binary data in AutoIt. How to use? the following script: #include "Huffman.au3" ; read out the autoitscript.com page as example string Global $sString = BinaryToString(InetRead("https://autoitscript.com")) ConsoleWrite("Original Size: " & BinaryLen(StringToBinary($sString)) & " Bytes" & @CRLF) ; encode the string with a canonical huffman encoding Global $bEncoded = _huff_encodeString($sString) ConsoleWrite("Encoded Size: " & BinaryLen($bEncoded) & " Bytes" & @CRLF & _ "Compress ratio: " & Round((1 - (BinaryLen($bEncoded) / BinaryLen(StringToBinary($sString)))) * 100.0, 1) & ' %' & @CRLF) ; decode the string out of the binary Global $sStringDecoded = _huff_decodeBinary($bEncoded) ; check if original and decoded string are the same ConsoleWrite("$sString == $sStringDecoded: " & ($sString == $sStringDecoded) & @CRLF) produces: Original Size: 157081 Bytes Encoded Size: 102833 Bytes Compress ratio: 34.5 % $sString == $sStringDecoded: True How to further increase the compression potential? Huffman encoding is just a step to be able to compress data. In combination with further steps you can compress the data even more. For example, you can pre-compress the data at the text level and only then encode the data using Huffman. The following extends the above example with a (simple) word repetition compression: which leads to the following result: Original Size: 157081 Bytes Encoded Size: 73333 Bytes Compress ratio: 53.3 % $sString == $sStringDecoded: True >>sourcecode and download on github<<1 point -
Find out CPU (used) Time of processes.
Jemboy reacted to argumentum for a topic
hmm, I have a user that has chrome browser hang in the background. Another has a WinWord hang in the background. These slowdown the PCs and the only way around is to close the process. Even tho you're right, at times something like this solves these annoying problems to save us from having to do it manually after a user's unhappy phone call. I tell users that "I did not code that application" but until the developer fixes it, meh, it's a workaround.1 point -
He also provide Bans.1 point
-
I'd go this route: #include <Array.au3> $xml = "<Servers>" & _ "<ServerInfo><Server_Name>MyServerName1</Server_Name><User>user_name1</User><Password>0x8534C1E508D4CF29AC17a</Password></ServerInfo>" & _ "<ServerInfo><Server_Name>MyServerName2</Server_Name><User>user_name2</User><Password>0x8534C1E508D4CF29AC17b</Password></ServerInfo>" & _ "<ServerInfo><Server_Name>MyServerName3</Server_Name><User>user_name3</User><Password>0x8534C1E508D4CF29AC17b</Password></ServerInfo>" & _ "</Servers>" Global Enum $iServerName, $iUser, $iPassword, $iUBound Local $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.LoadXML($xml) $oServers = $oXML.selectNodes("//ServerInfo") Local $a For $oServer In $oServers If IsArray($a) Then ReDim $a[UBound($a)+1][$iUBound] Else Local $a[1][$iUBound] EndIf $a[UBound($a)-1][$iServerName] = $oServer.selectSingleNode("./Server_Name").text $a[UBound($a)-1][$iUser] = $oServer.selectSingleNode("./User").text $a[UBound($a)-1][$iPassword] = $oServer.selectSingleNode("./Password").text Next _ArrayDisplay($a)1 point