Jump to content

...TO HEX


Recommended Posts

Hi, guys! [sorry for bad ENG.]

#Include <EditConstants.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>
    Global $sFile, $hFile, $iSize, $sData, $tData, $iRead
$sFile = @SCRIPTDir & '\TEST.rar'
$iSize = FileGetSize($sFile)
$tData = DllStructCreate('byte[' & $iSize & ']')
$hFile = _WinAPI_CreateFile($sFile, 2, 2, 2)
_WinAPI_ReadFile($hFile, DllStructGetPtr($tData), $iSize, $iRead)
_WinAPI_CloseHandle($hFile)
$sData = ''
    For $i = 1 To $iSize
        $sData &= Hex(DllStructGetData($tData, 1, $i), 2)
        If Mod($i, 16) = 0 Then
            $sData &= @CRLF
        Else
            $sData &= ' '
        EndIf
    Next
$sData = StringTrimRight($sData, 2)
FileWrite("hextext.txt", $sData)

I wonna write large text file in "hex"

from file whose size is <100Mb

I`am tried...without success -> low memory

BUT. "HHD_Hex_Editor" opening that large rar file in 5.sec and exporting for a short time, similar "hextext.txt"

Some help? :x

Link to comment
Share on other sites

  • Moderators

BoRisk,

I hope this does what you want: :P

; Open the file and read as bytes
$hFile = FileOpen("test.rar", 16)
$sByteContent = FileRead($hFile)
FileClose($hFile)

; Convert the bytes to hex and remove the leading 0x
$sHexContent = Stringtrimleft(StringToBinary($sByteContent), 2)

; Write the file
$hFile = FileOpen("hextext.txt", 2)
FileWrite($hFile, $sHexContent)
FileClose($hFile)

Please come back if not. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I am here again :P/First, Thank you for the attempt to help/I have appended two screenshot...First is the Error, i talked about that in the first postThe same is happening with my script. But its work with file smaller than ~~100KbSecond scrs. shows what I thought. Your hex_content compared with my._WinAPI, <-- There lies the secret.I would like to solve this. :x

Link to comment
Share on other sites

  • Moderators

BoRisk,

First problem: I have no idea why your code produces that error on your machine. Does mine? :P

Second problem: My fault, sorry. I removed the leading 0x and converted the binary - I only needed to do one or the other. :x Try this code:

; Open the file and read as bytes
$hFile = FileOpen("test.rar", 16)
$sByteContent = FileRead($hFile)
FileClose($hFile)

; Remove leading 0x
$sHexContent = StringTrimLeft($sByteContent, 2)

; Write the file
$hFile = FileOpen("hextext.txt", 2)
FileWrite($hFile, $sHexContent)
FileClose($hFile)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Again the same problem. Error allocating memory, your code-my code similarly :x

I have idea. I'm going to try on another pc,

Please test my script with file of 100Mb,

If work, please tell me how much time he should, and what your machine configuration..

Tomorrow I will tell if it works on another machine.

Link to comment
Share on other sites

@Melba23, Hex() is to be used for that.

As for memory problem, that's perfectly normal. BoRisk you are storing 100MB into a variable. Don't do that. That goes directly into RAM.

Your HHD_Hex_Editor is using simple trick. It reads just enough bytes you can see at time, and when you scroll that control it moves file pointer forward or back and reads at that position.

♡♡♡

.

eMyvnE

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...