Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Hex Edit Functions


  • Please log in to reply
16 replies to this topic

#1 Zinthose

Zinthose

    Adventurer

  • Active Members
  • PipPip
  • 132 posts

Posted 18 November 2008 - 10:21 PM

I needed a way to HexEdit / Patch a file to repair a common file corruption problem in a software package my company uses. I first used the AutoIt core FileOpen / FileWrite functions but this method required me to open the whole file into memory. The files I work with can be several hundred megabytes in size and easily cause out of memory errors. So, After searching / hacking I came up with this solution.

I hope someone finds it useful :mellow:

AutoIt         
#include <WinAPI.au3> _Demo() Func _Demo()     Local Const $TestFile_Path = @ScriptDir & "\Test.Bin"     Local $TestFile_ID, $bData, $Offset         ;## Hex offsets / lengths of the data stored in the file.         Local Const $Offset_Phone[2]    = [0x012,  4]         Local Const $Offset_NewToy[2]   = [0x1b6, 18]         Local Const $Offset_Recycle[2]  = [0x594, 24]     ;## Binary string of the test file.         Local Const $TestFile_Data = "0x" & _             "42494E000000000000000000000000000000867530900000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000446F6E27742054617A65206D" & _             "652042726F21000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000536F796C656E742067726565" & _             "6E2069732070656F706C6521000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000"     ;## Create Test File         $TestFile_ID = FileOpen($TestFile_Path, 14)         FileWrite($TestFile_ID, Binary($TestFile_Data))         FileClose($TestFile_ID)             ;## Read the Recycle Value         $bData = _HexRead($TestFile_Path, $Offset_Recycle[0], $Offset_Recycle[1])         ;## Convert data to a string and display.         MsgBox(4096, Default, "Recycle:" & @CRLF & BinaryToString($bData))         ;## Change the recycle value         $bData = StringToBinary("It Tastes like chicken!!")         _HexWrite($TestFile_Path, $Offset_Recycle[0], $bData)         ;## Read the Recycle Value         $bData = _HexRead($TestFile_Path, $Offset_Recycle[0], $Offset_Recycle[1])         ;## Convert data to a string and display.         MsgBox(4096, Default, "Recycle:" & @CRLF & BinaryToString($bData))             ;## Search for a specific value and display         $Offset = _HexSearch($TestFile_Path, $bData)         MsgBox(4096, "HexSearch Function", "Search performed to locate data stream: " & @CRLF & @TAB & $bData & @CRLF & "Result = 0x" & Hex($Offset, 3))            EndFunc #Region ;**** HexEdit Functions         Func _HexWrite($FilePath, $Offset, $BinaryValue)         Local $Buffer, $ptr, $bLen, $fLen, $hFile, $Result, $Written                 ;## Parameter Checks             If Not FileExists($FilePath)    Then    Return SetError(1, @error, 0)             $fLen = FileGetSize($FilePath)             If $Offset > $fLen              Then    Return SetError(2, @error, 0)             If Not IsBinary($BinaryValue)   Then    Return SetError(3, @error, 0)             $bLen = BinaryLen($BinaryValue)             If $bLen > $Offset + $fLen      Then    Return SetError(4, @error, 0)                 ;## Place the supplied binary value into a dll structure.             $Buffer = DllStructCreate("byte[" & $bLen & "]")                     DllStructSetData($Buffer, 1, $BinaryValue)             If @error Then Return SetError(5, @error, 0)                     $ptr = DllStructGetPtr($Buffer)                 ;## Open File             $hFile = _WinAPI_CreateFile($FilePath, 2, 4, 0)             If $hFile = 0 Then Return SetError(6, @error, 0)                 ;## Move file pointer to offset location             $Result = _WinAPI_SetFilePointer($hFile, $Offset)             $err = @error             If $Result = 0xFFFFFFFF Then                 _WinAPI_CloseHandle($hFile)                 Return SetError(7, $err, 0)             EndIf                     ;## Write new Value             $Result = _WinAPI_WriteFile($hFile, $ptr, $bLen, $Written)             $err = @error             If Not $Result Then                 _WinAPI_CloseHandle($hFile)                 Return SetError(8, $err, 0)             EndIf                 ;## Close File             _WinAPI_CloseHandle($hFile)             If Not $Result Then Return SetError(9, @error, 0)     EndFunc     Func _HexRead($FilePath, $Offset, $Length)         Local $Buffer, $ptr, $fLen, $hFile, $Result, $Read, $err, $Pos                 ;## Parameter Checks             If Not FileExists($FilePath)    Then    Return SetError(1, @error, 0)             $fLen = FileGetSize($FilePath)             If $Offset > $fLen              Then    Return SetError(2, @error, 0)             If $fLen < $Offset + $Length    Then    Return SetError(3, @error, 0)         ;## Define the dll structure to store the data.             $Buffer = DllStructCreate("byte[" & $Length & "]")             $ptr = DllStructGetPtr($Buffer)                 ;## Open File             $hFile = _WinAPI_CreateFile($FilePath, 2, 2, 0)             If $hFile = 0 Then Return SetError(5, @error, 0)                 ;## Move file pointer to offset location             $Pos = $Offset             $Result = _WinAPI_SetFilePointer($hFile, $Pos)             $err = @error             If $Result = 0xFFFFFFFF Then                 _WinAPI_CloseHandle($hFile)                 Return SetError(6, $err, 0)             EndIf                     ;## Read from file             $Read = 0             $Result = _WinAPI_ReadFile($hFile, $ptr, $Length, $Read)             $err = @error             If Not $Result Then                 _WinAPI_CloseHandle($hFile)                 Return SetError(7, $err, 0)             EndIf                 ;## Close File             _WinAPI_CloseHandle($hFile)             If Not $Result Then Return SetError(8, @error, 0)                     ;## Return Data             $Result = DllStructGetData($Buffer, 1)                         Return $Result     EndFunc     Func _HexSearch($FilePath, $BinaryValue, $StartOffset = Default)            Local $Buffer, $ptr, $hFile, $Result, $Read, $SearchValue, $Pos, $BufferSize = 2048                 ;## Parameter Defaults             If $StartOffset = Default       Then    $StartOffset = 0                 ;## Parameter Checks             If Not FileExists($FilePath)    Then    Return SetError(1, @error, 0)             $fLen = FileGetSize($FilePath)             If $StartOffset > $fLen         Then    Return SetError(2, @error, 0)             If Not IsBinary($BinaryValue)   Then    Return SetError(3, @error, 0)             If Not IsNumber($StartOffset)   Then    Return SetError(4, @error, 0)                 ;## Prep the supplied binary value for search             $SearchValue = BinaryToString($BinaryValue)                 ;## Define the dll structure to store the data.             $Buffer = DllStructCreate("byte[" & $BufferSize & "]")             $ptr = DllStructGetPtr($Buffer)         ;## Open File                 $hFile = _WinAPI_CreateFile($FilePath, 2, 2, 1)                 If $hFile = 0 Then Return SetError(5, @error, 0)                     ;## Move file pointer to offset location             $Result = _WinAPI_SetFilePointer($hFile, $StartOffset)             $err = @error             If $Result = 0xFFFFFFFF Then                 _WinAPI_CloseHandle($hFile)                 Return SetError(5, $err, 0)             EndIf                     ;## Track the file pointer's position             $Pos = $StartOffset                     ;## Start Search Loop             While True                                 ;## Read from file                     $Read = 0                     $Result = _WinAPI_ReadFile($hFile, $ptr, $BufferSize, $Read)                     $err = @error                     If Not $Result Then                         _WinAPI_CloseHandle($hFile)                         Return SetError(6, $err, 0)                     EndIf                                 ;## Prep read data for search                     $Result = DllStructGetData($Buffer, 1)                     $Result = BinaryToString($Result)                                 ;## Search the read data for first match                     $Result = StringInStr($Result, $SearchValue)                     If $Result > 0 Then ExitLoop                                 ;## Test for EOF and return -1 to signify value was not found                     If $Read < $BufferSize Then                         _WinAPI_CloseHandle($hFile)                         Return -1                     EndIf                                 ;## Value not found, Continue Tracking file pointer's position                     $Pos += $Read                                 WEnd         ;## Close File             _WinAPI_CloseHandle($hFile)             If Not $Result Then Return SetError(7, @error, 0)                     ;## Calculate the offset and return             $Result = $Pos + $Result - 1             Return $Result     EndFunc     Func _WinAPI_SetFilePointer($hFile, $nDistance, $nMethod = 0)         Local $nRet         $nRet = DllCall("kernel32.dll", "dword", "SetFilePointer", "ptr", $hFile, "long", $nDistance, "ptr", 0, "dword", $nMethod)                 Return $nRet[0]     EndFunc #EndRegion


** UPDATES **
  • Added new function: _HexSearch()

Edited by Zinthose, 21 November 2008 - 09:47 PM.

---
TTFN








#2 Jikoo

Jikoo

    Wayfarer

  • Active Members
  • Pip
  • 70 posts

Posted 20 November 2008 - 11:39 AM

Thank you Zinthose,

It's interesting ! It works very well ! :mellow:
My projects : GCS Search 1.07 (GUI Control Styles Search)* Multilingual tool to help about the old scripts, with a dynamic menu.* Easy way to find missing Include files in old scripts downloaded from forums !* Famous Monoceres script added and improved (visual, drag and drop, automatic)* There is an interactive color converter with palettes too, for fun !The best way to start Autoit3 development (for newbies).

#3 Zinthose

Zinthose

    Adventurer

  • Active Members
  • PipPip
  • 132 posts

Posted 20 November 2008 - 03:02 PM

Thank you Zinthose,

It's interesting ! It works very well ! :(


Thanks :mellow:

---
TTFN


#4 WeMartiansAreFriendly

WeMartiansAreFriendly

    Where's the kaboom?

  • Active Members
  • PipPipPipPipPipPip
  • 1,245 posts

Posted 20 November 2008 - 03:49 PM

You have an interesting coding style, it is very readable. :mellow:
Posted ImageDon't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

#5 Zinthose

Zinthose

    Adventurer

  • Active Members
  • PipPip
  • 132 posts

Posted 20 November 2008 - 04:30 PM

You have an interesting coding style, it is very readable. :mellow:


:( I'm humbled, but isn't that the point witting code? So the next guy, including yourself can make sence if it?

---
TTFN


#6 WeMartiansAreFriendly

WeMartiansAreFriendly

    Where's the kaboom?

  • Active Members
  • PipPipPipPipPipPip
  • 1,245 posts

Posted 20 November 2008 - 07:57 PM

:mellow: I'm humbled, but isn't that the point witting code? So the next guy, including yourself can make sence if it?


In this case yes, but it's not very common; appropriate and descriptive comments is quite rare. Yes I know what a message box does, no I don't know what this dllstruct is used for. :(
Posted ImageDon't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

#7 Digisoul

Digisoul

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 330 posts

Posted 21 November 2008 - 03:15 AM

I needed a way to HexEdit / Patch a file to repair a common file corruption problem is a software package my company uses. I first used the AutoIt core FileOpen/FileWrite functions but ran this method required me to open the whole file into memory. And the files I work with can be several hundred megabytes in size. After searching I came up with this solution.

I hope someone finds it useful :mellow:

AutoIt         
#include <WinAPI.au3> #include <File.au3> #include <String.au3> _Demo() Func _Demo()     Local Const $TestFile_Path = @ScriptDir & "\Test.Bin"     Local $TestFile_ID, $bData         ;## Hex offsets / lengths of the data stored in the file.         Local Const $Offset_Phone[2]        = [0x012,  4]         Local Const $Offset_NewToy[2]       = [0x1b6, 18]         Local Const $Offset_Recycle[2]      = [0x594, 24]     ;## Binary string of the test file.         Local Const $TestFile_Data = "0x" & _             "42494E000000000000000000000000000000867530900000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000446F6E27742054617A65206D" & _             "652042726F21000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000536F796C656E742067726565" & _             "6E2069732070656F706C6521000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" & _             "000000000000000000000000"     ;## Create Test File         $TestFile_ID = FileOpen($TestFile_Path, 14)         FileWrite($TestFile_ID, Binary($TestFile_Data))         FileClose($TestFile_ID)             ;## Read the Recycle Value         $bData = _HexRead($TestFile_Path, $Offset_Recycle[0], $Offset_Recycle[1])         ;## Convert data to a string and display.         MsgBox(4096, Default, "Recycle:" & @CRLF & BinaryToString($bData))         ;## Change the recycle value         $bData = StringToBinary("It Tastes like chicken!!")         _HexWrite($TestFile_Path, $Offset_Recycle[0], $bData)         ;## Read the Recycle Value         $bData = _HexRead($TestFile_Path, $Offset_Recycle[0], $Offset_Recycle[1])         ;## Convert data to a string and display.         MsgBox(4096, Default, "Recycle:" & @CRLF & BinaryToString($bData))      EndFunc #Region - HexEdit     Func _HexWrite($FilePath, $Offset, $BinaryValue)         Local $Buffer, $ptr, $bLen, $fLen, $hFile, $Result, $Written                 ;## Parameter Checks             If Not FileExists($FilePath)    Then    Return SetError(1, @error, 0)             $fLen = FileGetSize($FilePath)             If $Offset > $fLen              Then    Return SetError(2, @error, 0)             If Not IsBinary($BinaryValue)   Then    Return SetError(3, @error, 0)             $bLen = BinaryLen($BinaryValue)             If $bLen > $Offset + $fLen      Then    Return SetError(4, @error, 0)                 ;## Place the supplied binary value into a dll structure.             $Buffer = DllStructCreate("byte[" & $bLen & "]")                     DllStructSetData($Buffer, 1, $BinaryValue)             If @error Then Return SetError(5, @error, 0)                     $ptr = DllStructGetPtr($Buffer)                 ;## Open File             $hFile = _WinAPI_CreateFile($FilePath, 2, 4, 0)             If $hFile = 0 Then Return SetError(6, @error, 0)                 ;## Move file pointer to offset location             $Result = _WinAPI_SetFilePointer($hFile, $Offset)             $err = @error             If $Result = 0xFFFFFFFF Then                 _WinAPI_CloseHandle($hFile)                 Return SetError(7, $err, 0)             EndIf                     ;## Write new Value             $Result = _WinAPI_WriteFile($hFile, $ptr, $bLen, $Written)             $err = @error             If Not $Result Then                 _WinAPI_CloseHandle($hFile)                 Return SetError(8, $err, 0)             EndIf                 ;## Close File             _WinAPI_CloseHandle($hFile)             If Not $Result Then Return SetError(9, @error, 0)     EndFunc     Func _HexRead($FilePath, $Offset, $Length)         Local $Buffer, $ptr, $fLen, $hFile, $Result, $Read, $err, $Pos                 ;## Parameter Checks             If Not FileExists($FilePath)    Then    Return SetError(1, @error, 0)             $fLen = FileGetSize($FilePath)             If $Offset > $fLen              Then    Return SetError(2, @error, 0)             If $fLen < $Offset + $Length    Then    Return SetError(3, @error, 0)         ;## Define the dll structure to store the data.             $Buffer = DllStructCreate("byte[" & $Length & "]")             $ptr = DllStructGetPtr($Buffer)                 ;## Open File             $hFile = _WinAPI_CreateFile($FilePath, 2, 2, 0)             If $hFile = 0 Then Return SetError(5, @error, 0)                 ;## Move file pointer to offset location             $Pos = $Offset             $Result = _WinAPI_SetFilePointer($hFile, $Pos)             $err = @error             If $Result = 0xFFFFFFFF Then                 _WinAPI_CloseHandle($hFile)                 Return SetError(6, $err, 0)             EndIf                     ;## Read from file             $Read = 0             $Result = _WinAPI_ReadFile($hFile, $ptr, $Length, $Read)             $err = @error             If Not $Result Then                 _WinAPI_CloseHandle($hFile)                 Return SetError(7, $err, 0)             EndIf                 ;## Close File             _WinAPI_CloseHandle($hFile)             If Not $Result Then Return SetError(8, @error, 0)                     ;## Return Data             $Result = DllStructGetData($Buffer, 1)                         Return $Result     EndFunc     Func _WinAPI_SetFilePointer($hFile, $nDistance, $nMethod = 0)         Local $nRet         $nRet = DllCall("kernel32.dll", "dword", "SetFilePointer", "ptr", $hFile, "long", $nDistance, "ptr", 0, "dword", $nMethod)                 return $nRet[0]     EndFunc #EndRegion

Your Script is Quite usefull can you tell me if i have some binary data but don't have its offset then how can i creat its offset ?
73 108 111 118 101 65 117 116 111 105 116 Posted Image

#8 Zinthose

Zinthose

    Adventurer

  • Active Members
  • PipPip
  • 132 posts

Posted 21 November 2008 - 03:49 AM

Your Script is Quite usefull can you tell me if i have some binary data but don't have its offset then how can i creat its offset ?


You will need to know your way around a hex editor and be prepared to perform some file comparisons before and after a change to identify were the file change hex offsets are.

Hex editing is more art than science IMO. You just need to get a free hex editor, backup your files, and work the proverbial clay until it just clicks. If you do a Google search you might find a hex editor tutorial.

Anyway, Teaching binary file manipulations are probably out of the scope of the AutoIt forums.

---
TTFN


#9 Digisoul

Digisoul

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 330 posts

Posted 21 November 2008 - 03:06 PM

You will need to know your way around a hex editor and be prepared to perform some file comparisons before and after a change to identify were the file change hex offsets are.

Hex editing is more art than science IMO. You just need to get a free hex editor, backup your files, and work the proverbial clay until it just clicks. If you do a Google search you might find a hex editor tutorial.

Anyway, Teaching binary file manipulations are probably out of the scope of the AutoIt forums.

Wel i m using hackman 9 as hex editor. my quention is that is it possible to search any binary bytes if you don't know the offset, bcoz i want to search some bytes in random files. so i can't be sure about its offset.
73 108 111 118 101 65 117 116 111 105 116 Posted Image

#10 Zinthose

Zinthose

    Adventurer

  • Active Members
  • PipPip
  • 132 posts

Posted 21 November 2008 - 09:23 PM

Wel i m using hackman 9 as hex editor. my quention is that is it possible to search any binary bytes if you don't know the offset, bcoz i want to search some bytes in random files. so i can't be sure about its offset.

So you want an additional function to search a binary file and return the Offset if the value is found?

Func _HexSearch($FilePath, $BinaryValue, $StartOffset = Default)     ;## Perform Magic         Return Aberacadabera() EndFunc


EDIT: I created the _HexSearch function and added it to the original post. :mellow:

Edited by Zinthose, 21 November 2008 - 09:51 PM.

---
TTFN


#11 Digisoul

Digisoul

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 330 posts

Posted 27 November 2008 - 12:14 AM

EDIT: I created the _HexSearch function and added it to the original post. :)

Awesome ! :) thats the thing i want. Thankx for this function.
73 108 111 118 101 65 117 116 111 105 116 Posted Image

#12 Jango

Jango

    Polymath

  • Active Members
  • PipPipPipPip
  • 202 posts

Posted 27 November 2008 - 01:20 PM

You have an interesting coding style, it is very readable. :)


I agree, moreover it's really usefull (for me at least). Well done.

#13 karham

karham

    Seeker

  • New Members
  • 4 posts

Posted 14 June 2009 - 11:47 PM

Simply Awesome!

Hehehehe
Thnx a lot I've been needing something like it but i'm still learning so I couldnt make one like this one ;D

#14 goldenix

goldenix

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 738 posts

Posted 30 August 2009 - 03:02 PM

it works, thanx, all i need now is to convert hex to text.

nvm:

$data = _HexRead('chai_4-3.zip.torrent', '369', '20') ; 20 is the lenght of the output $data = StringTrimLeft($data,2) $data = _HexToString($data) ConsoleWrite($data & @CRLF)

Edited by goldenix, 30 August 2009 - 03:22 PM.


#15 Ashalshaikh

Ashalshaikh

    Wayfarer

  • Active Members
  • Pip
  • 97 posts

Posted 30 August 2009 - 06:44 PM

WOW !!!! :D
Realy Good !! :D
I Was Need It !! :D
Thanks !! :D

#16 goldenix

goldenix

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 738 posts

Posted 29 November 2009 - 07:43 PM

Question, Hex edit function does not work. What im doing wrong?

I have a file 50 4D 56 D2

Now I want to replace D2 With DE

I do this and nothing happens.

$result =  _HexWrite('sample.txt', 3, 'DE') ConsoleWrite($result & @CRLF)



EDIT Never mind:

it works this way:
    $_HexRead   = _HexRead('autosave.pmv', 3, 2)     ConsoleWrite($_HexRead & @CRLF)     $result =  _HexWrite('Riddle.pmv', 3, $_HexRead)

Edited by goldenix, 29 November 2009 - 08:09 PM.


#17 BinaryBrother

BinaryBrother

    Resourceful

  • Active Members
  • PipPipPipPipPipPip
  • 799 posts

Posted 05 January 2010 - 08:50 AM

For other newbies like me... On the _HexRead(file,offset,length) function... To actually get the 'offset' rather than the pointer, convert the offset to dec before parsing it through that function...

_HexRead($File,Dec($Offset),$Length)

I'm a complete newbie with Hex stuff, so it took me a few mins to figure it out... ;)

Edited by BinaryBrother, 05 January 2010 - 08:51 AM.

Meh...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users