24 posts in this topic
Well the plan is to use the power of regular expressions engine of AutoIT for patching binary data.
Something like this: StringRegExp( $BinaryData, "(?s)\x55\x8B.."
<cut> ... Okay straight to question/problem
... certain bytes that are in the range from 0x80 to 0xA0 won't match.
Hmm seem to be a char encoding problem. In detail these are 27 chars: 0x80, 0x82~8C, 0x8E, 0x91~9C, 0x9E,0x9F
Here's a small code snippet to explore / explain this problem:
#include "StringConstants.au3" $TestData = BinaryToString("0x7E7F808182") ;Okay $match = StringRegExp( $TestData ,'\x7E' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Okay $match = StringRegExp( $TestData ,'\x7F' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Error no match $match = StringRegExp( $TestData ,'\x80' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Okay $match = StringRegExp( $TestData ,'\x81' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Error no match $match = StringRegExp( $TestData ,'\x82' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;~ output: ;~ @extended = 2 $match = ;~ @extended = 3 $match = ;~ @extended = 0 $match = 1 ;~ @extended = 5 $match = ;~ @extended = 0 $match = 1 Hmm what to do? Go back and use the 'numberstring monster' implementation or just omit that range of 'unsafe bytes'. What is the root of this problem?
Any idea how to fix this?
Update: Okay I know a byte is not a character.
But StringRegExp operates on String and so character level.
Okay as long as you stay at Ansi encoding and only use /x00 - /X7F in the search pattern using StringRegExp works well to search for binary data.
What bytes can be matched that are in the range from /X7F - /xFF is also depending on the code page.
So this avoid to search for bytes in the range from 0x80-0xa0 only applies to Germany.
I just change this country setting:
to Thai and now near all bytes from /X7F - /xFF fails to match.
Text in a file, read into var with fileread:
<> <> <> <> < J please look > <> <> <> Hi,
I want a RegExp to select around 'please', back to the previous < and forward to the next >. I can select the line of text. Then I add in (?s) and it selects the whole text. I think I want to make it not greedy, (?U) , that seems to make it ungreedy after, but it still selects all the previous lines.
$sPattern = "(?s)<.*please.*>" ; 1 $sPattern = "(?s)<(?U).*please.*>" ; 2 $sPattern = "(?s)<(?U).*please(?U).*>" ; 3 $sAry = StringRegExp($sHTML, $sPattern, 3)
I want to rename every new instance of notepad to notepad(random number)
If I use WinSetTitle ( "notepad", "", "notepad("&$randomnumber&")" )
this will work pretty good, because if more windows match the search entry it will take the newest. But what if this code runs, but there is no new instance of notepad. It will rename one that was already assigned a number. So I would like to check whether it is already renamed. For example by excluding titles that contain a ")".
How do I do that.
Read this, but that is pretty confusing: http://stackoverflow.com/questions/406230/regular-expression-to-match-line-that-doesnt-contain-a-word?rq=1
You can now use your favorite html tags in a richedit control!
<b></b> (bold) <i></i> (italic) <s></s> (strike) <u></u> (underline) <color=#nnnnnn></color> (color text) <color=0xnnnnn></color> (color text) <bkcolor=#nnnnnn></color> (color background text) <bkcolor=0xnnnnnn></color> (color background text) <font name="Font name" size=n></font> (Font name is the only one that has to have quotes around it. They can be double quotes or single, it doesn't matter. color, bkcolor, and size can also use quotes but they're optional)
Does not support (but I may add later)
<align> <a href=""> <img>
; Functions _GUICtrlRichEdit_AppendHtmlText _StringToRichEditArray __GetArrayFromRegex __GetRichEditAttrFromChar __GUICtrlRichEdit_AppendTextColored __GUICtrlRichEdit_SetTextColor (I'm sure someone can come up with some better names for this lol)
You can use a formatted (<color=0xNNNNNN>Formatted</color>) or non-formatted (Non-formatted) string with calling _GUICtrlRichEdit_AppendHtmlText and _StringToRichEditArray. _StringToRichEditArray will just set the attributes, font name, font size, and colors to the current attributes of the RichEdit Control (At least it should... RichEdit can be picky about setting the font and char attributes correctly....).
Calling _StringToRichEditArray will return a 2d array with n amount of rows.
[n] - String [n] - Font name for the  string. [n] - Font size for the  string. [n] - Character attributes for the  string. [n] - Text color for the  string. [n] - Back color for the  string. It seems I was too hasty in my release and this still wasn't working 100% . I guess I'll try to work on it tomorrow and see if I can get it working the way tags are supposed to work. It's not a complete waste, it's close but not perfect and I know why.
Formatted RichEdit Array V2.rar
#include <Array.au3> If @Compiled Then Exit Global Enum $FUNC_OUTER, $FUNC_NAME, $FUNC_PARAM, $FUNC_INNER _Example() Func _Example() Local $sIncludeDir = StringTrimRight(@AutoItExe, StringLen('AutoIt3.exe')) & 'Include\' Local $aOuterArray = _GetFunctionsToArray($sIncludeDir & 'Color.au3') If Not @error Then For $iOuter_idx = 0 To UBound($aOuterArray) - 1 _ArrayDisplay($aOuterArray[$iOuter_idx], ($aOuterArray[$iOuter_idx])[$FUNC_NAME]) Next EndIf EndFunc ;==>_Example Func _GetFunctionsToArray($sUDF_FileFullPath) Local $sUDFContent = FileRead($sUDF_FileFullPath) Local $aResult = StringRegExp($sUDFContent, '(?is)\RFunc (.*?)\((.*?)\)\v\R(.*?)\REndFunc', $STR_REGEXPARRAYGLOBALFULLMATCH) Return SetError(@error, @extended, $aResult) EndFunc ;==>_GetFunctionsToArray