Sign in to follow this  
Followers 0
Kyan

hex replace in autoit

9 posts in this topic

Hi everyone

I have 2 basic question about hex editing

- I have several texts with a common problem, in stead of having CRLF (carriage return+line feed) only had 0x0A (LF), how do I add 0D behind every 0x0A?

- Its possible to edit only the beginning of a file (speaking in large files that should't be loaded in memory) and save the changes?


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites



Hi everyone

I have 2 basic question about hex editing

- I have several texts with a common problem, in stead of having CRLF (carriage return+line feed) only had 0x0A (LF), how do I add 0D behind every 0x0A?

- Its possible to edit only the beginning of a file (speaking in large files that should't be loaded in memory) and save the changes?

For the first question maybe? :

$string = "First Line 0x0A Another Line"
$replace_string = StringReplace($string, "0x0A", "0Dx0A")
MsgBox(0,"", "After: " & $string & @CRLF & "Before: " & $replace_string)

For second question give a look _FileWriteToLine function in the help file:

#include <File.au3>
;Example: Write to line 3 of c:\test.txt REPLACING line 3
_FileWriteToLine("c:\test.txt", 3, "my replacement for line 3", 1)
;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3
_FileWriteToLine("c:\test.txt", 3, "my insertion", 0)

Hi!


My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Share this post


Link to post
Share on other sites

For the first question maybe? :

$string = "First Line 0x0A Another Line"
$replace_string = StringReplace($string, "0x0A", "0Dx0A")
MsgBox(0,"", "After: " & $string & @CRLF & "Before: " & $replace_string)

For second question give a look _FileWriteToLine function in the help file:

#include <File.au3>
;Example: Write to line 3 of c:\test.txt REPLACING line 3
_FileWriteToLine("c:\test.txt", 3, "my replacement for line 3", 1)
;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3
_FileWriteToLine("c:\test.txt", 3, "my insertion", 0)

Hi!

thanks for te effort :)

in your first example it replaces all the data without check if a CR (0x0D) exists before a LF (0x0A), it only needs to and a CR behind a LF which doesn't has a CR already

for the second, in case of bynary file, it would work correctly :s


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

thanks for te effort :)

in your first example it replaces all the data without check if a CR (0x0D) exists before a LF (0x0A), it only needs to and a CR behind a LF which doesn't has a CR already

for the second, in case of bynary file, it would work correctly :s

For the first example maybe is this?:

$string = "First Line 0x0D0x0A Another Line"
$replace_string = StringReplace($string, "0x0D0x0A", "0Dx0A")
MsgBox(0,"", "After: " & $string & @CRLF & "Before: " & $replace_string)

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Share this post


Link to post
Share on other sites

DiOgO,

I use this Regex to set every EOL possibility to @CRLF: ;)

#include <Array.au3>

$sText = "Line 1" & @CR & "Line 2" & @LF & "Line 3" & @CRLF & "Line 4" & @LF & "Line 5" & @CR & "Line 6" & @CRLF & "Line 8"

$aLines = StringSplit($sText, @CRLF, 1)
_ArrayDisplay($aLines, "Before")

$sText = StringRegExpReplace($sText, "((?<!\x0d)\x0a|\x0d(?!\x0a))", @CRLF)

$aLines = StringSplit($sText, @CRLF, 1)
_ArrayDisplay($aLines, "After")

It looks for @CR without a following @LF - and @LF without a leading @CR. I hope it helps. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

For the first example maybe is this?:

$string = "First Line 0x0D0x0A Another Line"
$replace_string = StringReplace($string, "0x0D0x0A", "0Dx0A")
MsgBox(0,"", "After: " & $string & @CRLF & "Before: " & $replace_string)

Hi!

not exactly, it is in hex code :)

DiOgO,

I use this Regex to set every EOL possibility to @CRLF: ;)

#include <Array.au3>

$sText = "Line 1" & @CR & "Line 2" & @LF & "Line 3" & @CRLF & "Line 4" & @LF & "Line 5" & @CR & "Line 6" & @CRLF & "Line 8"

$aLines = StringSplit($sText, @CRLF, 1)
_ArrayDisplay($aLines, "Before")

$sText = StringRegExpReplace($sText, "((?<!\x0d)\x0a|\x0d(?!\x0a))", @CRLF)

$aLines = StringSplit($sText, @CRLF, 1)
_ArrayDisplay($aLines, "After")

It looks for @CR without a following @LF - and @LF without a leading @CR. I hope it helps. :)

M23

yeah, but what means ?<! and ?! and why is a capture group inside a capture group? (like capturing it 2times xD

btw, you don't know how can a file be edited in a address (0x000024 and lenght 0x2A for i.e.,) and saved without having to copy to another location/file?


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

DiOgO,

yeah, but what means ?<! and ?! and why is a capture group inside a capture group? (like capturing it 2times

As I explained, the Regex looks ahead and behind to see if there is the other part of a @CRLF - in which case it does nothing. Let me try and explain:

Follow the numbers in order

(?<!\x0d)     - 2 - Look behind (the ?>! part) and make sure it is NOT preceded by @CR (0x0D)
\x0a        - 1 - Look for @LF (which is 0x0A) then 
|         - 3 - Or
\x0d        - 4 - We look for @CR and then
(?!\x0a)    - 5 - Look ahead (?!) and make sure it is NOT followed by @LF

The parts in () are non-capturing negative lookbehind/lookahead - and are well explained in my favourite Regex tutorial at http://www.regular-expressions.info/tutorial.html.

The whole thing needs to be in () so that it is a capturing group for the SRER to replace.

Any clearer? :D

M23

Edited by Melba23
Fixed url

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

DiOgO,

As I explained, the Regex looks ahead and behind to see if there is the other part of a @CRLF - in which case it does nothing. Let me try and explain:

Follow the numbers in order

(?<!\x0d) - 2 - Look behind (the ?>! part) and make sure it is NOT preceded by @CR (0x0D)
\x0a - 1 - Look for @LF (which is 0x0A) then
| - 3 - Or
\x0d - 4 - We look for @CR and then
(?!\x0a) - 5 - Look ahead (?!) and make sure it is NOT followed by @LF

The parts in () are non-capturing negative lookbehind/lookahead - and are well explained in my favourite Regex tutorial at http://www.regular-expressions.info/tutorial.html.

The whole thing needs to be in () so that it is a capturing group for the SRER to replace.

Any clearer? :D

M23

got it, anyone with doubts check this link http://www.regular-expressions.info/quickstart.html (at the bottom page..."Lookaround")

thanks Melba23:D, to ask something about sql/timestamps, should I create another thread?


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

Yes please new topic = new thread


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Skysnake
      By Skysnake
      Scite comes up occasional, almost incidentally, in some support topics.  I have not found a "Scite" topic in the forums, so this is where I will start.  I have recently been using Scite intensively, specifically with a large project and I have certain issues.  I know that Scite is not an AutoIt product, but it is so closely integrated to the core release that it makes sense to raise issues and request support here.  If this is not the right please refer me to the right forum.
      Thx
       
      Skysnake
    • P3rsp3ctiv3
      By P3rsp3ctiv3
      Hello how can I send a {Enter} into the edit window ($cmd)? I tried it first with:
      GUICtrlSetData($cmd, "Line 1" + "{ENTER}")
      but it doesn´t work. Can someone help me please?
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> $Admin = GUICreate("Admin", 234, 168, 192, 229, $GUI_SS_DEFAULT_GUI, BitOR($WS_EX_OVERLAPPEDWINDOW,$WS_EX_TRANSPARENT,$WS_EX_WINDOWEDGE)) GUISetBkColor(0xB4B4B4) $exit = GUICtrlCreateButton("Close", 160, 136, 65, 25) $cmd = GUICtrlCreateEdit("",0, 0, 225, 137, $ES_AUTOVSCROLL + $WS_VSCROLL) GUICtrlSetData(-1, "") GUICtrlSetFont(-1, 10, 400, 0, "Candara") GUICtrlSetBkColor(-1, 0xE3E3E3) $cmd_clear = GUICtrlCreateButton("Clear", 9, 136, 65, 25) GUISetState(@SW_SHOW) HotKeySet("{f1}", CMD_1) HotKeySet("{f2}", CMD_2) While 1 $msg = GUIGetMsg(1) Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $exit GUIDelete($Admin) Exit EndSwitch WEnd Func CMD_1(); GUICtrlSetData($cmd, "Line 1" & "{ENTER}") GUICtrlSetData($cmd, "Line 2" & "{ENTER}") EndFunc Func CMD_2(); GUICtrlSetData($cmd, "Line 3" & "{ENTER}") GUICtrlSetData($cmd, "Line 4" & "{ENTER}") EndFunc
    • nacerbaaziz
      By nacerbaaziz
      hello
      please i need to link a progress bar with a time can you help me?
      e.g
      i want to set a progress bar for 10 sec
      am waiting for your answers
      thank you.
    • AdminC
      By AdminC
      #RequireAdmin
      #include <SendMessage.au3>
      #include <WinAPI.au3>
      #include <WindowsConstants.au3>
      #include <GDIPlus.au3>
      #include <GUIConstantsEx.au3>
      #include <WinAPIGdi.au3>
      #include <Array.au3>
      #include <WinAPIDiag.au3>
      $Imglocation = @ScriptDir&"\Image\testimg.bmp"
      _GDIPlus_Startup()
      Local $Bitmap = _GDIPlus_BitmapCreateFromFile($Imglocation)
      Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap)
      Local $imgSize = _WinAPI_GetBitmapDimension($hBitmap)
      Local $imgBits = DllStructCreate('dword[' & ($imgSize.X * $imgSize.Y) & ']')
      _WinAPI_GetBitmapBits($hBitmap, DllStructGetSize($imgBits), DllStructGetPtr($imgBits))
      _WinAPI_DisplayStruct($imgBits)
      MsgBox(0, "", DllStructGetData($imgBits, 1, 1)) 
      _GDIPlus_Shutdown()
      DllstructGetData can't get data color B, G, R value. Who's know that? teach me plz
       
    • Miliardsto
      By Miliardsto
      Hello. Im trying to make my scripts safe - unnable to decompile. I search for obfuscators and other security methods but the search has come to nothing.
      Then one guy gave that idea below. If I rightly understood this idea lets we talk about example program with this secutiy method.
      Program have two parts, first is only login gui and the second part is the main program Second part (main program) is uploaded on ftp server lets say that on http://xxx/autoit/main_program.au3 So we have the first gui with login, we put correctly login and pass and this is the moment when code from http://xxx/autoit/main_program.au3 will be downloaded and executed Finally main program will be appear This is the similiar way like new games are protected by cracking.
      I have few questions in this moment about this:
      Is something like that even possible to do with the autoit? First part of program (login gui) must have somewhere given that link to download the rest of code - http://xxx/autoit/main_program.au3 to make it execute. As we know this first part of program is easy able to hack and retrieve this web url http://xxx/autoit/main_program.au3 where located is main part of program. Is the way to encrypt or secure it? If only code will be stored in .php we know it cannot be previewed. So it could for example get code from .php file instead of .au3 I know that methods works in other languages (I dont know exactly how) thats becouse I only speculates, maybe something may looks different in these solution? Other way would be compiling second part of code on web server (there are available web autoit servers) maybe this way is possible? Tell me anything U know about this ideas and if its even possible to achieve.
      Thanks for ur any response, advice or thoughts