Leaderboard
Popular Content
Showing content with the highest reputation on 11/21/2023 in all areas
-
Map data from/to file
ioa747 and one other reacted to AspirinJunkie for a topic
Briefly to understand: The map $mMap is to be read from a file in its nested structure and then written again with the corresponding changes? If yes: The term for this is serialize/deserialize. Basically, you are completely free to do this. You can write something of your own for the special structure. However, it is easier to use the corresponding ones. You have already mentioned one of these: >>JSON<< That would be very suitable for this. Basically, you only need one call to fill $mMap from a file and only one call to write the file again. That should also answer your question: You don't need to worry about the structure of the JSON file. It is automatically structured according to the structure of your nested AutoIt map. JSON is a text format. If you prefer a binary format that produces smaller files, you can also take a look at >>CBOR<<. The operation is basically exactly the same as in the case of JSON: One call to serialize the map into a file and one to read it back from the file. Let me give you a basic example of how this would work in your case with CBOR: #include "CBOR.au3" ; initial data if not exists already If not FileExists("myData.bin") Then Local $mMap[] Local $mPerson[] $mPerson["no"] = 42; $mPerson["first"] = "Jerry" $mPerson["name"] = "Mouse" $mMap[42] = $mPerson $mPerson["no"] = 43; $mPerson["first"] = "Tom" $mPerson["name"] = "Cat" $mMap[43] = $mPerson ; save $mMap in file FileDelete("myData.bin") FileWrite("myData.bin", _cbor_encode($mMap)) EndIf ; --------- read data from file --------------- Local $mMap = _cbor_decode(FileRead("myData.bin")) ; -------- add data (example for changing data) ------------------- Local $mPerson[] $mPerson["no"] = 44; $mPerson["first"] = "Bucks" $mPerson["name"] = "Bunny" $mMap[44] = $mPerson ; ------- save the new $mMap into file ---------- FileDelete("myData.bin") FileWrite("myData.bin", _cbor_encode($mMap)) ; ------- The next time the program is called, $mMap contains the updated data ---------- ; print the data to see if ok For $no In MapKeys($mMap) ConsoleWrite($no & @CRlF) $mP = $mMap[$no] For $key in MapKeys($mP) ConsoleWrite(@TAB & $key & ": " & $mP[$key] & @CRLF) Next Next And for JSON, the process is basically almost the same: #include "JSON.au3" ; initial data if not exists already If not FileExists("myData.json") Then Local $mMap[] Local $mPerson[] $mPerson["no"] = "42"; $mPerson["first"] = "Jerry" $mPerson["name"] = "Mouse" $mMap["42"] = $mPerson $mPerson["no"] = 43; $mPerson["first"] = "Tom" $mPerson["name"] = "Cat" $mMap["43"] = $mPerson ; save $mMap in file FileWrite("myData.json", _JSON_GenerateCompact($mMap)) EndIf ; --------- read data from file --------------- Local $sFile = FileRead("myData.json") Local $mMap = _JSON_Parse($sFile) ; -------- add data (example for changing data) ------------------- Local $mPerson[] $mPerson["no"] = 44; $mPerson["first"] = "Bucks" $mPerson["name"] = "Bunny" $mMap["44"] = $mPerson ; ------- save the new $mMap into file ---------- FileDelete("myData.json") FileWrite("myData.json", _JSON_GenerateCompact($mMap)) ; ------- The next time the program is called, $mMap contains the updated data ---------- ; print the data to see if ok For $no In MapKeys($mMap) ConsoleWrite($no & @CRlF) $mP = $mMap[$no] For $key in MapKeys($mP) ConsoleWrite(@TAB & $key & ": " & $mP[$key] & @CRLF) Next Next2 points -
read and write xlsx files without Excel
funkey reacted to AspirinJunkie for a topic
This UDF provides 2 functions to read data directly from xlsx files or to output data as xlsx file. Only the cell contents are considered - no cell formatting and the like. It is therefore explicitly not a full replacement for the Excel UDF, since its scope goes well beyond that. But to quickly read in data or to work with xlsx files without having Excel installed, the UDF can be quite useful. There may also be specially formatted xlsx files which I have not yet encountered during testing and which may cause problems. In this case it is best to make a message about it here and upload the file. Note: xlsx files must be unpacked for reading. To make this as fast as possible it is recommended to put a >>7za.exe<< file into the script directory, otherwise a slow alternative will be used. Otherwise an example says more than 1000 words: >>sourcecode and download on github<< Changelog:1 point -
Probably not before we do The only way I learn is through trail and error. You are doing great. As for where to put the body of the debug function out(), that is difficult for me to specify. You could make a new script called Debug.au3 and copy the function definition there (to the new script). Then you can: #include "Debug.au3"; Quotes "" because it's a custom include file Inside any script you wish to use your custom debug functions. However you can name the Debug.au3 any unique name you wish. You could alternatively copy the function body to any script that would call 'out()'. I don't see the need to tell you how to structure your code at this time. I also do not want to pigeon hole you into my coding practices, as they might not be right for you at this stage of your development. It's your code, Sir.1 point
-
1 point
-
I needed a tool to test simple assembly code so I end up with this. This is written using fasmg (a bare assembly engine) to generate binary code for various CPU architectures and you can directly call (test) the code with few parameters. Even if it can generate code for various CPUs, use the call/execute functionality just in 32-bit mode (really, don't try to run 64-bit code and then ask why it doesn't work or why it's crashing ). Basically write the asm code in the left edit control and binary code will be generated automatic in the right panel (if you don't have errors). Before writting the asm code make sure you included cpu/x64.inc (or whatever CPU architecture is your CPU) and maybe one of the directive use16, use32, use64 (use32 if you want to execute the code from application). Also if you want to resolve the offset for each line (this is not mandatory), include line.inc after you included all other includes (example below). #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Comment=Real Time Assembler #AutoIt3Wrapper_Res_Description=Real Time Assembler #AutoIt3Wrapper_Res_Fileversion=1.0.0.3 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Res_ProductVersion=1 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include 'BinaryCall.au3' #include 'Fasmg.au3' If @AutoItX64 Then MsgBox(0x10, 'Error', 'This application can run just in 32-bit mode.') ; MB_ICONERROR Exit EndIf Global $hMain, $cCode, $cAsm, $hCode Global $cParam1, $cParam2, $cParam3, $cParam4, $cParam5, $cResult Global $sFont = 'Segoe UI', $iFontSize = 12 Global Const $ParamTypes = 'none|byte|boolean|short|ushort|word|int|long|' & _ 'bool|uint|ulong|dword|int64|uint64|ptr|hwnd|handle|float|double|int_ptr|' & _ 'long_ptr|lresult|lparam|uint_ptr|ulong_ptr|dowrd_ptr|wparam|str|wstr|struct' $hMain = GUICreate('Real Time Assembler', 1000, 600) $cCode = GUICtrlCreateEdit('', 10, 10, 385, 580, 0x00201000) ; WS_VSCROLL + ES_WANTRETURN $cAsm = GUICtrlCreateEdit('', 405, 10, 385, 580, 0x00200800) ; WS_VSCROLL + ES_READONLY $cParamLabel = GUICtrlCreateLabel('Parameters', 800, 10, 200, 20, 0x200) ; SS_CENTERIMAGE $cType1 = GUICtrlCreateCombo('', 800, 40, 190, 30, 0x03) ; CBS_DROPDOWNLIST $cParam1 = GUICtrlCreateInput('', 800, 80, 190, 30) $cType2 = GUICtrlCreateCombo('', 800, 120, 190, 30, 0x03) ; CBS_DROPDOWNLIST $cParam2 = GUICtrlCreateInput('', 800, 160, 190, 30) $cType3 = GUICtrlCreateCombo('', 800, 200, 190, 30, 0x03) ; CBS_DROPDOWNLIST $cParam3 = GUICtrlCreateInput('', 800, 240, 190, 30) $cType4 = GUICtrlCreateCombo('', 800, 280, 190, 30, 0x03) ; CBS_DROPDOWNLIST $cParam4 = GUICtrlCreateInput('', 800, 320, 190, 30) $cType5 = GUICtrlCreateCombo('', 800, 360, 190, 30, 0x03) ; CBS_DROPDOWNLIST $cParam5 = GUICtrlCreateInput('', 800, 400, 190, 30) $cResultLabel = GUICtrlCreateLabel('Result', 800, 440, 190, 20, 0x200) ; SS_CENTERIMAGE $cRetType = GUICtrlCreateCombo('', 800, 470, 190, 30, 0x03) ; CBS_DROPDOWNLIST $cResult = GUICtrlCreateLabel('', 800, 510, 190, 30, 0x1000) ; SS_SUNKEN $cRun = GUICtrlCreateButton('Execute', 845, 560, 100, 30) $hCode = GUICtrlGetHandle($cCode) GUICtrlSetBkColor($cAsm, 0xFFFFFF) GUICtrlSetFont($cCode, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cAsm, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cParamLabel, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cType1, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cType2, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cType3, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cType4, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cType5, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cRetType, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cParam1, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cParam2, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cParam3, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cParam4, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cParam5, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cRun, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cResultLabel, $iFontSize, Default, Default, $sFont) GUICtrlSetFont($cResult, $iFontSize, Default, Default, $sFont) GUICtrlSendMsg($cParam1, 0x1501, False, 'Param# 1') ; EM_SETCUEBANNER GUICtrlSendMsg($cParam2, 0x1501, False, 'Param# 2') ; EM_SETCUEBANNER GUICtrlSendMsg($cParam3, 0x1501, False, 'Param# 3') ; EM_SETCUEBANNER GUICtrlSendMsg($cParam4, 0x1501, False, 'Param# 4') ; EM_SETCUEBANNER GUICtrlSendMsg($cParam5, 0x1501, False, 'Param# 5') ; EM_SETCUEBANNER GUICtrlSetData($cType1, $ParamTypes, 'none') GUICtrlSetData($cType2, $ParamTypes, 'none') GUICtrlSetData($cType3, $ParamTypes, 'none') GUICtrlSetData($cType4, $ParamTypes, 'none') GUICtrlSetData($cType5, $ParamTypes, 'none') GUICtrlSetData($cRetType, $ParamTypes, 'none') GUISetState(@SW_SHOW, $hMain) EnvSet('INCLUDE', @ScriptDir & '\include') $hFasmg = Memory_DllOpen(Base64($Fasmg, False)) ConsoleWrite('Fasmg version: ' & Memory_DllCall($hFasmg, 'str', 'fasmg_GetVersion')[0] & @CRLF) GUIRegisterMsg(0x0111, "WM_COMMAND") ; WM_COMMAND While True Switch GUIGetMsg() Case -3 ; GUI_EVENT_CLOSE ExitLoop Case $cRun CallFunction() EndSwitch Sleep(10) WEnd Memory_DllClose($hFasmg) Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg If $lParam = $hCode And BitShift($wParam, 16) = 0x0300 Then ; EN_CHANGE Local $sBinaryCode = Compile(GUICtrlRead($cCode)) GUICtrlSetData($cAsm, $sBinaryCode) EndIf Return 'GUI_RUNDEFMSG' EndFunc Func Compile($sCode, $iBufferSize = 5000) If Not $sCode Then Return Local $iCodeLines = 0, $iPrefix = 0 Local $iLine = StringRegExp($sCode, '^([\s\S]*)(include ''line.inc'')([\s\S]*)$', 0) Local $iDirective = StringRegExp($sCode, '^([\s\S]*)(use16|use32|use64)([\s\S]*)$', 0) If $iLine Then Local $aCode = StringSplit($sCode, @CRLF, 1) For $Index = 1 To $aCode[0] If StringStripWS($aCode[$Index], 7) = 'include ''line.inc''' Then $iCodeLines = $aCode[0] - $Index + 1 $iPrefix = $aCode[0] - $iCodeLines ExitLoop EndIf Next EndIf Local $tMemory = DllStructCreate('byte Code[' & $iBufferSize & ']') Local $pMemory = DllStructGetPtr($tMemory) Local $tFasmg = DllStructCreate('dword Address; dword Size;') DllStructSetData($tFasmg, 'Address', $pMemory) DllStructSetData($tFasmg, 'Size', DllStructGetSize($tMemory)) Local $aCall = Memory_DllCall($hFasmg, 'int', 'fasmg_Assemble', 'str', $sCode, 'str', Null, 'ptr', DllStructGetPtr($tFasmg), 'str', Null, 'handle', Null, 'handle', Null) If $aCall[0] = 0 Then Local $sResult = '' If $iLine And $iDirective And $iCodeLines Then Local $NextOffset = 1, $CurrentOffset = 0, $PrevOffset = 0 Local $iActualCodeSize = DllStructGetData($tFasmg, 'Size') - ($iCodeLines * 4) Local $tActualCode = DllStructCreate('byte Code[' & $iActualCodeSize & ']', $pMemory) Local $sBinary = DllStructGetData($tActualCode, 'Code') Local $iOffsets = (DllStructGetData($tFasmg, 'Size') - $iActualCodeSize) / 4 Local $tOffsets = DllStructCreate('dword Offset[' & $iOffsets & ']', $pMemory + $iActualCodeSize) For $Index = $iOffsets - 2 to 1 Step -1 $CurrentOffset = Number(DllStructGetData($tOffsets, 'Offset', $Index)) $sResult &= Stylize(BinaryMid($sBinary, $NextOffset, $CurrentOffset - $PrevOffset)) $NextOffset += $CurrentOffset - $PrevOffset $PrevOffset = $CurrentOffset Next For $Index = 1 To $iPrefix + 2 $sResult = @CRLF & $sResult Next Else Local $tCode = DllStructCreate('byte Code[' & DllStructGetData($tFasmg, 'Size') & ']', $pMemory) $sResult = Stylize(DllStructGetData($tCode, 'Code')) EndIf Return $sResult Else Return '' EndIf EndFunc Func Stylize($sBinaryCode) Local $sCode = StringTrimLeft(StringStripWS(String($sBinaryCode), 3), 2) Local $iLen = StringLen($sCode) If Mod($iLen, 2) <> 0 Then Return @CRLF & @CRLF Local $sResult For $Index = 1 To $iLen Step 2 $sResult &= StringMid($sCode, $Index, 2) & ' ' Next Return StringStripWS($sResult, 3) & @CRLF EndFunc Func CallFunction() If @AutoItX64 Or StringInStr(GUICtrlRead($cCode), 'use64') Then GUICtrlSetData($cResult, 'No!') Return EndIf Local $sCode = StringStripWS(GUICtrlRead($cAsm), 8) If Not $sCode Then Return Local $aRet Local $sRetType = GUICtrlRead($cRetType) Local $sType1 = GUICtrlRead($cType1) Local $vParam1 = GUICtrlRead($cParam1) Local $sType2 = GUICtrlRead($cType2) Local $vParam2 = GUICtrlRead($cParam2) Local $sType3 = GUICtrlRead($cType3) Local $vParam3 = GUICtrlRead($cParam3) Local $sType4 = GUICtrlRead($cType4) Local $vParam4 = GUICtrlRead($cParam4) Local $sType5 = GUICtrlRead($cType5) Local $vParam5 = GUICtrlRead($cParam5) Local $dCode = Binary('0x' & $sCode) Local $iSize = BinaryLen($dCode) Local $tCode = DllStructCreate('byte Code[' & $iSize & ']') DllStructSetData($tCode, 'Code', $dCode) Local $sCall = 'DllCallAddress(''' & $sRetType & ''',' & DllStructGetPtr($tCode) & ',' If $vParam1 Then $sCall &= '''' & $sType1 & ''',' & (($sType1 = 'str' Or $sType1 = 'wstr') ? ('''' & $vParam1 & '''') : $vParam1) & ',' EndIf If $vParam2 Then $sCall &= '''' & $sType2 & ''',' & (($sType2 = 'str' Or $sType2 = 'wstr') ? ('''' & $vParam2 & '''') : $vParam2) & ',' EndIf If $vParam3 Then $sCall &= '''' & $sType3 & ''',' & (($sType3 = 'str' Or $sType3 = 'wstr') ? ('''' & $vParam3 & '''') : $vParam3) & ',' EndIf If $vParam4 Then $sCall &= '''' & $sType4 & ''',' & (($sType4 = 'str' Or $sType4 = 'wstr') ? ('''' & $vParam4 & '''') : $vParam4) & ',' EndIf If $vParam5 Then $sCall &= '''' & $sType5 & ''',' & (($sType5 = 'str' Or $sType5 = 'wstr') ? ('''' & $vParam5 & '''') : $vParam5) & ',' EndIf $sCall = StringTrimRight($sCall, 1) & ')' $aRet = Execute($sCall) GUICtrlSetData($cResult, IsArray($aRet) ? $aRet[0] : '') EndFunc To make this work I rewrite ward's BinaryCall UDF to use DllCallAddress() and get rid of kernel API hack, but this can work without this UDF with fasmg.dll as a file (I just prefer to load it from memory). Probably it have some bugs but right now it's a tool that can be used for fast debug of assembly code. A simple example: include 'cpu/x64.inc' include 'line.inc' use32 mov eax, [esp+4] add eax, [esp+8] ret 8 This is a simple function that add two integers Add(int a, int b) and return an integer as result. RTA.zip1 point