Leaderboard
Popular Content
Showing content with the highest reputation on 06/05/2023 in all areas
-
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.zip3 points
-
Xml2Json UDF - Transform XML to JSON
AspirinJunkie reacted to TheXman for a topic
The tools & UDF's used to parse and process JSON are much more flexible and powerful than the ones for XML. In general, they are also much faster. So I created this Xml2Json UDF to tranform XML to JSON. It consists of 2 functions, _Xml2Json() and _XmlFile2Json(). ;================================================================================================= ; _Xml2Json($sXml, $sXsl = Default) ; ; Author: TheXman (https://www.autoitscript.com/forum/profile/23259-thexman/?tab=field_core_pfield_11) ; ; Description: Transform XML string to JSON ; Parameter(s): $sXml - A string containing a valid XML document. ; $sXsl - [optional] A string containing the XSL stylesheet used for transform. ; Return Value(s): Success - A string containing JSON ; Failure - "" and sets @error to a non-zero value. ; @error 1 = Unable to create XML object ; 2 = Unable to create XSL object ; 3 = Unable to parse XML. Make sure XML is valid. ; 4 = Unable to parse XSL. Make sure XSL is valid. ; 5 = XML Transform failed. Make sure you are using a valid v1.0 stylesheet. ; ; Remarks: MSXML 6.0, the COM component used to do the tranformations, only processes ; XSLT 1.0 stylesheets. If you pass a version 2.0+ stylesheet, you WILL get an ; error. ; ; The XSL stylesheet used by default came from: ; https://www.bjelic.net/2012/08/01/coding/convert-xml-to-json-using-xslt/ ; MIT License - Copyright (c) 2012 Bojan Bjelic ;================================================================================================= ;================================================================================================= ; _XmlFile2Json($sXmlFile, $sXsl = Default) ; ; Author: TheXman (https://www.autoitscript.com/forum/profile/23259-thexman/?tab=field_core_pfield_11) ; ; Description: Transform XML file to JSON ; Parameter(s): $sXmlFile - A string containing a valid XML document file path. ; $sXsl - [optional] A string containing the XSL stylesheet used for transform. ; Return Value(s): Success - A string containing the transformed JSON. ; Failure - "" and sets @error to a non-zero value. ; @error -1 = File does not exist ; 1 = Unable to create XML object ; 2 = Unable to create XSL object ; 3 = Unable to parse XML. Make sure XML is valid. ; 4 = Unable to parse XSL. Make sure XSL is valid. ; 5 = XML Transform failed. Make sure you are using a valid v1.0 stylesheet. ; ; Remarks: MSXML 6.0, the COM component used to do the tranformations, only processes ; XSLT 1.0 stylesheets. If you pass a version 2.0+ stylesheet, you WILL get an ; error. ; ; The XSL stylesheet used by default came from: ; https://www.bjelic.net/2012/08/01/coding/convert-xml-to-json-using-xslt/ ; MIT License - Copyright (c) 2012 Bojan Bjelic ;================================================================================================= The transformation is done by doing an XML Transform using a xml-to-json XSL stylesheet. If you want to use your own xml-to-json XSL stylesheet instead of the default one, then you can supply it in the 2nd parameter. The only caveat is that all values are transformed to strings. That means that numeric XML values will be returned as a strings. For example, the numeric value 10.50 will be returned as "10.50". The UDF comes with a couple of example scripts. One example script, which is below, just shows a sample transformation using the included sample XML file. The second example does the transformation and queries the transformed JSON for information. Example-01 ( uses the included sample XML file, Books.xml ) #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #include <Constants.au3> #include "xml2json.au3" #include "jq.au3" ; (https://www.autoitscript.com/forum/files/file/502-jq-udf-a-powerful-flexible-json-processor/) example() Func example() Const $XML_FILE = "books.xml" Local $hTimer = -1 Local $sCmdOutput = "", _ $sJson = "" ;Initialize jq environment _jqInit("C:\Utils\JQ\jq-win64.exe") ;<== Path to jq exe If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to find jq executable - @error = " & @error) $hTimer = TimerInit() ;Convert XML to JSON $sJson = _XmlFile2Json($XML_FILE) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "_xmlfile2json() Error", "@error = " & @error) ConsoleWrite(StringFormat("Elapsed time to transform XML to JSON: %.3f seconds", TimerDiff($hTimer) / 1000) & @CRLF) ;Pretty-print JSON $sCmdOutput = _jqPrettyPrintJson($sJson, " ") If @error Then MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Pretty-print failed - @error = " & @error & " @extended = " & @extended) ConsoleWrite("ERROR:" & @CRLF & $sCmdOutput & @CRLF) Exit EndIf ConsoleWrite($sCmdOutput & @CRLF) EndFunc Output Elapsed time to transform XML to JSON: 0.003 seconds { "catalog": { "book": [ { "id": "bk101", "author": "Gambardella, Matthew", "title": "XML Developer's Guide", "genre": "Computer", "price": "44.95", "publish_date": "2000-10-01", "description": "An in-depth look at creating applications with XML." }, { "id": "bk102", "author": "Ralls, Kim", "title": "Midnight Rain", "genre": "Fantasy", "price": "5.95", "publish_date": "2000-12-16", "description": "A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world." }, { "id": "bk103", "author": "Corets, Eva", "title": "Maeve Ascendant", "genre": "Fantasy", "price": "5.95", "publish_date": "2000-11-17", "description": "After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society." }, { "id": "bk104", "author": "Corets, Eva", "title": "Oberon's Legacy", "genre": "Fantasy", "price": "5.95", "publish_date": "2001-03-10", "description": "In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant." }, { "id": "bk105", "author": "Corets, Eva", "title": "The Sundered Grail", "genre": "Fantasy", "price": "5.95", "publish_date": "2001-09-10", "description": "The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy." }, { "id": "bk106", "author": "Randall, Cynthia", "title": "Lover Birds", "genre": "Romance", "price": "4.95", "publish_date": "2000-09-02", "description": "When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled." }, { "id": "bk107", "author": "Thurman, Paula", "title": "Splish Splash", "genre": "Romance", "price": "4.95", "publish_date": "2000-11-02", "description": "A deep sea diver finds true love twenty thousand leagues beneath the sea." }, { "id": "bk108", "author": "Knorr, Stefan", "title": "Creepy Crawlies", "genre": "Horror", "price": "4.95", "publish_date": "2000-12-06", "description": "An anthology of horror stories about roaches, centipedes, scorpions and other insects." }, { "id": "bk109", "author": "Kress, Peter", "title": "Paradox Lost", "genre": "Science Fiction", "price": "6.95", "publish_date": "2000-11-02", "description": "After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum." }, { "id": "bk110", "author": "O'Brien, Tim", "title": "Microsoft .NET: The Programming Bible", "genre": "Computer", "price": "36.95", "publish_date": "2000-12-09", "description": "Microsoft's .NET initiative is explored in detail in this deep programmer's reference." }, { "id": "bk111", "author": "O'Brien, Tim", "title": "MSXML3: A Comprehensive Guide", "genre": "Computer", "price": "36.95", "publish_date": "2000-12-01", "description": "The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more." }, { "id": "bk112", "author": "Galos, Mike", "title": "Visual Studio 7: A Comprehensive Guide", "genre": "Computer", "price": "49.95", "publish_date": "2001-04-16", "description": "Microsoft Visual Studio 7 is explored in depth, looking at how Visual Basic, Visual C++, C#, and ASP+ are integrated into a comprehensive development environment." } ] } } Xml2Json UDF (2022-12-07).zip1 point -
Uggg don't get me started. Some stupid vendor we're unfortunately willing to accommodate has this weird damn structure that's a combination of data that produces that hex number. And when it gets transmitted back to them in volume it requires that piece of it converted back to decimal (which can vary) as part of the return data. It was a big enough pain putting this together with a piece of software. But then having to unravel this again which is a big enough pain to create to extract that specific section as part of the file that goes back to them. And of course I have to make all this junk work. Alternatively I could write these to a database as we create them with that decimal value in another column which probably makes more sense. But honestly nobody here gives a damn about any of these values so I'd rather not have yet another database to administer. If I can just have a script these users can feed an input file to (which contains a lot of unnecessary fields) process that and produce the final output going back stand alone I can live with that. I've though about a few other options but I can see users constantly screwing something up constantly lol. Thank you all for your help. I've done plenty in AutoIT but I have never had to deal with actual binary directly in AU3.1 point
-
What UDF to work with XML/HTML files?
littlebigman reacted to TheXman for a topic
I don't understand the question. Don't you already know the schema of the XML files that you are working with? The only way I can see that being an issue is when a parent node has an attribute name that's the same name as one of its child nodes. That would be rather illogical but I guess it could happen. Also, keep in mind that not all XML files lend themselves to being easily transformed into JSON. Some may need custom stylesheets or may need the XML file to be modified before transformation. One example that comes to mind are XML files that make use of CDATA. I don't think the default xsl stylesheet has rules for handling CDATA. With that said, If you need XML attribute names be transformed to JSON key names that identify them as attributes, then it just involves a small change to the default .xsl stylesheet that is used to do the transformations. I modified the attached xsl file below to prepend "attr_" to transformed attribute names. Since xsl stylesheets basically contains rules for how to transform XML, you could make the name look however you'd like (@id, _id, id_, id_attr, etc.) The, optional, second parameter of the _Xml2Json() function allows you to override the default xsl stylesheet that is used. Make the change below and put the modified xsl stylesheet in the script directory and it will produce the output below. You will also need to modify the jqFilter to user the "attr_" attribute names (i.e. .attr_lat). The _Xml2Json() function was already set up to allow the use of modified xsl stylesheets for scenarios like yours and other one-offs that users may desire. Change the existing _Xml2Json() line to: ;Transform XML to JSON $sJson = _Xml2Json($gkXML, FileRead(@ScriptDir & "\xml2json_identify_attrs.xsl")) JSON Output: { "gpx": { "metadata": { "name": "Some name" }, "trk": [ { "name": "Track 1", "trkseg": { "trkpt": [ { "attr_lat": "48.81782", "attr_lon": "2.24906", "ele": "123", "time": "Dummy time" }, { "attr_lat": "48.81784", "attr_lon": "2.24906", "ele": "456" } ] } }, { "name": "Track 2", "trkseg": { "trkpt": [ { "attr_lat": "48.81782", "attr_lon": "2.24906", "ele": "321" }, { "attr_lat": "48.81784", "attr_lon": "2.24906", "ele": "654" } ] } } ] } } xml2json_identify_attrs.xsl1 point -
#include <APIConstants.au3> #include <WinAPIEx.au3> ConsoleWrite(@CRLF & _CRC32ForFile(@ScriptFullPath) & @CRLF & @CRLF) ; basically this. You code the rest. ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CRC32ForFile ; Description ...: Calculates CRC32 value for the specific file. ; Syntax ........: _CRC32ForFile($sFilePath) ; Parameters ....: $sFilePath - Full path to the file to process. ; $iPercentageRead - [optional] Percentage of file to read. Default is 100. ; Return values .: Success - Returns CRC32 value in the form of a hex string ; - Sets @error to 0 ; Failure - Returns empty string and sets @error: ; |1 - CreateFile function or call to it failed. ; |2 - CreateFileMapping function or call to it failed. ; |3 - MapViewOfFile function or call to it failed. ; |4 - RtlComputeCrc32 function or call to it failed. ; Author ........: trancexx ; Modified ......: guinness ; Link ..........: http://www.autoitscript.com/forum/topic/95558-crc32-md4-md5-sha1-for-files/ ; Example .......: No ; =============================================================================================================================== Func _CRC32ForFile($sFilePath, $iPercentageRead = 100) $iPercentageRead = Int($iPercentageRead) If ($iPercentageRead > 100) Or ($iPercentageRead <= 0) Then $iPercentageRead = 100 EndIf $iPercentageRead = ($iPercentageRead / 100) * FileGetSize($sFilePath) Local $iError = 0 Local Const $hFilePath = _WinAPI_CreateFileEx($sFilePath, $OPEN_EXISTING, $GENERIC_READ, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $SECURITY_ANONYMOUS, 0, 0) If @error Then Return SetError(1, 0, '') EndIf Local Const $hFilePathMappingObject = _WinAPI_CreateFileMapping($hFilePath, 0, 0, $PAGE_READONLY) $iError = @error _WinAPI_CloseHandle($hFilePath) If $iError Then Return SetError(2, 0, '') EndIf Local Const $pFilePath = _WinAPI_MapViewOfFile($hFilePathMappingObject, 0, $iPercentageRead, $FILE_MAP_READ) $iError = @error _WinAPI_CloseHandle($hFilePathMappingObject) If $iError Then Return SetError(3, 0, '') EndIf Local Const $iBufferSize = $iPercentageRead ; FileGetSize($sFilePath) Local Const $iCRC32 = _WinAPI_ComputeCrc32($pFilePath, $iBufferSize) $iError = @error _WinAPI_UnmapViewOfFile($pFilePath) _WinAPI_CloseHandle($hFilePathMappingObject) If $iError Then Return SetError(4, 0, '') EndIf Return SetError(0, 0, Hex($iCRC32, 8)) EndFunc ;==>_CRC32ForFile This CRC32 should work without crashing if the file will fit in memory. Other than that, I'd use something coded just for that. You'll have to search online. Now if you like to use MD5 or SHA1 then you can use the _Crypt_HashFile() functions from the help file. That will give you a better collision resolution than CRC32.1 point
-
The only imposter here is you, pretending you know what you are talking about.1 point
-
I have mostly finished my program now, some possible tweaks aside as I test it further, and no writing to the copy or device 'KoboReader.sqlite' files yet. As you might notice, I have changed and added some more elements to the above Results window. 1. LOG button was relocated yet again, and resized to suit. This was because I decided I needed some folder open buttons. 2. FIX COVER IMAGE SIZE was renamed to FIX COVERS, and reduced in size, to allow for the other additions etc. 3. Added a button to open the device images folder, and another button to do the same with any Alternate Drive selected. These two small buttons are to the left of the Cover Image, at the bottom of the window. That RED colored line (row), was for the first column image being created and added ... file name with subs also inserted into that column. I've completed the code for the RELOCATE, REMOVE and CREATE buttons, including support for the Alternate Drive. This means all controls are now coded for. The CREATE button can only work if you have manually assigned sub-folders for the selected entry. I realized just after I went to bed last night, that I forgot to disable .jpg which I was using for visual testing with the GDIPlus code that created the placebo images. So that means yesterday's script upload has .jpg instead of .parsed enabled for placebo file creation. I fixed that today, and I also needed to rename all my created placebo .jpg files to .parsed, so I wrote a tiny bit of code to do that, first thing. I've tested the RELOCATE and REMOVE buttons code. Though I have done no testing with my Kobo device yet, just with the cloned folders setup. Full testing of everything with my Kobo device comes next, but maybe not today, as I have other things to concern myself with now, and I want the time etc to do it all properly. The following script has everything enabled, even though some of it as I said, remains untested at this point. That means the Test.jpg or Test.parsed files are not being used anymore. DOWNLOAD Kobo Cover Fixer.au3 (44 downloads) SEE THE FIRST POST in this topic for the latest version. 105.56 kB NOTE - I've only just realized now, after writing that comment about the RED line, that I should have assigned a different color when the CREATE button is used ... probably FUCHSIA ... just to differentiate what happened with what. RED = ADDED, LIME = FIXED. P.S. I also keep forgetting to remove the checkboxes from the ListView in column one. I did have some vague notion of maybe using them when I started.1 point
-
@HotKeyPressed Problem
Musashi reacted to pixelsearch for a topic
@andreik without the dummy function, you will find serious issues (try F1 or F3 or "a" as hotkeyset, instead of F5) As F5 is inactive while a script is executed in Scite, that's why it appears that you can get rid of the dummy function with the F5 test, but if you assign hotkey to keys that can be active in the Scite environment (F3, F1, "a" etc...) then you will see the difference. HotKeySet("{F5}", "Do_Nothing" has to be called as soon as possible (e.g 1st code line) after Case "{F5}" . If there are one or several lines before it, then issues may appear too. If I understood correctly OP, he simply wants that a long key press doesn't generate dozen of buffered key presses, e.g. a long key press needs to be assimilated to a single key press, without further display (or loop) consequences. As you said, let's wait OP to see if what we suggested is ok with him1 point -
Looking at your script and its output, it appears that you are still trying to get a good grasp of how to process XML nodes and how to get individual values. Personally, I find it much easier and faster to work with the actual XML DOM objects than to use XML UDF's. Plus, there's a lot less overhead. Below, you will find an example that produces the exact same array as my xml2json example above. Of course it could have been done in several different ways. I just chose to do it that way because it uses the exact same logic as what I used in the previous XML2JSON example. As you can see, working with the XML DOM objects is not that much different than using some of the XML UDF's. As you can also see, if you just need to get information from an XML file, the script using the xml2json method is far less code and much easier to create, modify and maintain. I hope the example helps you understand some of the concepts related to XML node processing. Example using XML DOM objects: #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #include <Constants.au3> #include <Array.au3> Const $gkXML = _ '<?xml version="1.0" encoding="UTF-8"?>' & _ '<gpx>' & _ ' <metadata>' & _ ' <name>Some name</name>' & _ ' </metadata>' & _ ' <trk>' & _ ' <name>Track 1</name>' & _ ' <trkseg>' & _ ' <trkpt lat="48.81782" lon="2.24906">' & _ ' <ele>123</ele>' & _ ' <time>Dummy time</time>' & _ ' </trkpt>' & _ ' <trkpt lat="48.81784" lon="2.24906">' & _ ' <ele>456</ele>' & _ ' </trkpt>' & _ ' </trkseg>' & _ ' </trk>' & _ ' <trk>' & _ ' <name>Track 2</name>' & _ ' <trkseg>' & _ ' <trkpt lat="48.81782" lon="2.24906">' & _ ' <ele>321</ele>' & _ ' </trkpt>' & _ ' <trkpt lat="48.81784" lon="2.24906">' & _ ' <ele>654</ele>' & _ ' </trkpt>' & _ ' </trkseg>' & _ ' </trk>undefinedundefinedundefined' & _ '</gpx>' xml_example() Func xml_example() Local $oComErr = ObjEvent("AutoIt.Error", "com_error_handler") #forceref $oComErr Local $oTrackNodes = Null, _ $oTrackPointNodes = Null Local $sTrackName = "" Local $aTrackPoints[0][5] With ObjCreate("Msxml2.DOMDocument.6.0") ;Load XML document object from the string .PreserveWhitespace = True .loadXML($gkXML) If .parseError.errorCode Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "XML PARSING ERROR", .parseError.reason) ;Select all track nodes $oTrackNodes = .selectNodes('//trk') If Not IsObj($oTrackNodes) Then Return MsgBox($MB_ICONERROR, "Error", "No track nodes found." & @error) ;For each track node For $oTrackNode in $oTrackNodes ;Save track name $sTrackName = $oTrackNode.selectSingleNode("./name").text ;Select all child segment track points $oTrackPointNodes = $oTrackNode.selectNodes('./trkseg/trkpt') If Not IsObj($oTrackNodes) Then Return MsgBox($MB_ICONERROR, "Error", "No track points found." & @error) ;For each child segment track point For $oTrackPointNode in $oTrackPointNodes With $oTrackPointNode ;Add specified values to the array _ArrayAdd($aTrackPoints, _ $sTrackName & "|" & _ .getAttribute("lat") & "|" & _ .getAttribute("lon") & "|" & _ .selectSingleNode("./ele").text & "|" & _ (IsObj(.selectSingleNode("./time")) ? .selectSingleNode("./time").text : "") _ ;Handle optional node ) EndWith Next Next EndWith ;Display array _ArrayDisplay($aTrackPoints, "GPS Exchange Info", "", 0, Default, "Name|Lat|Long|Elevation|Time") EndFunc Func com_error_handler($oError) With $oError ConsoleWrite(@CRLF & "COM ERROR DETECTED!" & @CRLF) ConsoleWrite(" Error ScriptLine....... " & .scriptline & @CRLF) ConsoleWrite(" Error Number........... " & StringFormat("0x%08x (%i)", .number, .number) & @CRLF) ConsoleWrite(" Error WinDescription... " & StringStripWS(.windescription, $STR_STRIPTRAILING) & @CRLF) ConsoleWrite(" Error RetCode.......... " & StringFormat("0x%08x (%i)", .retcode, .retcode) & @CRLF) ConsoleWrite(" Error Description...... " & StringStripWS(.description , $STR_STRIPTRAILING) & @CRLF) EndWith Exit EndFunc Resulting array:1 point
-
What is proper SciTE upgrade procedure?
littlebigman reacted to Melba23 for a topic
littlebigman, The SciTE that is distributed with the AutoIt package is a modified (by Jos) version of the "main" SciTE - trying to update it yourself would almost certainly end in tears. If you do want to get a more up-to-date SciTE could I point you the this thread: I have been using it in Alpha and Beta for months without problems. M231 point -
@kpdozer & @n3wbie I have updated my original responses with more information.1 point
-
@n3wbie You're welcome. You have expressed yourself a little differently than in your DM. I can't help but to think you are going a bit overboard and being a bit facetious. A simple "thanks" would've been more than enough. The encryption/decryption algorithms that you provided in your example script above are a bit different than the ones used in some of the JavaScript snippets that you DM'd me. As I mentioned in the DM, my intentions are to help people learn and/or understand AutoIt-related and IT-related subject matter in order for them to be able to accomplish their goals on their own, it is not to provide full solutions. If you are interested in getting a better understanding of what's involved so you can do it yourself, I'm always willing to try and help. If you are just looking for solutions or if the subject matter is beyond your capabilities, then I suggest you hire someone to port the code for you or maybe you can find someone else in the forum to provide you what you're looking for. The main differences between the example script that I originally provided and the one needed to decrypt the data that you DM'd me, are how the IV, Salt, and Encrypted Message are parsed from the data in the file. The IV is created from the 1st 32 characters of the file, converted from its hex string representation to its binary form, which will yield the 128-bit (16-byte) binary value. The Salt is created from the next 32 characters, converted the same way as the IV. Lastly, the encrypted message/JSON is created from the remaining characters, which need to be decoded from base64 back to binary before decryption. If you have a problem implementing the changes that I outlined, feel free to ask for additional help.1 point
-
I can go into more detail and give you some sources with verified information but I'll just let you be for now... I will let you live in your placebo world where you are right0 points