Converting a binary file to hex>>file
This would be a project to read a binary file such dat files or exe files or even dlls but i found this extremely slow doing it. A 100kb file was taking ~1 minute, 1 mb file..well i gave up and closed the process.
I would like to see this working faster if there is a way to do it..
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim arItems() As Byte
Dim sText$
Dim sTemp$
Dim i As Double
Open "tmp001.dat" For Binary As #1
ReDim arItems(LOF(1))
Get #1, , arItems
Close #1
For i = LBound(arItems) To UBound(arItems) - 1
sText = sText & Hex(arItems(i))
Next i
Open "hex_output.txt" For Append As #2
For i = 1 To Len(sText) Step 32
sTemp = Mid(sText, i, 32)
Print #2, sTemp
Next i
Close #2
End Sub
Re: Converting a binary file to hex>>file
I never understood this fascination about HEX...
I don't see any purpose whatsoever to convert a file to a HEX file...
I would understand if you want to display the contents in HEX... but converting to another file in HEX, it will make the file size double !
Anyways, the following should be better, but there is still room for improvement:
VB Code:
Dim arItems() As Byte
Dim K As Long, BPos As Long, SPos As Long, FileSize As Long
Dim OutData As String
Open "c:\test.txt" For Binary Access Read As #1
FileSize = LOF(1)
ReDim arItems(FileSize - 1)
Get #1, , arItems
Close #1
OutData = String(FileSize * 2 + (FileSize \ 16) * 2, "-")
BPos = 0
SPos = 1
Do Until BPos + 16 >= UBound(arItems)
For K = 1 To 16
Mid$(OutData, SPos, 2) = Right$("0" & Hex$(arItems(BPos)), 2)
BPos = BPos + 1
SPos = SPos + 2
Next K
Mid$(OutData, SPos, 2) = vbNewLine
SPos = SPos + 2
Loop
For K = 0 To UBound(arItems) - BPos
Mid$(OutData, SPos, 2) = Right$("0" & Hex$(arItems(BPos)), 2)
BPos = BPos + 1
SPos = SPos + 2
Next K
Open "c:\hex_output.txt" For Binary Access Write As #2
Put #2, , OutData
Close #2
Re: Converting a binary file to hex>>file
I can explain it better, my idea is to build some sort of program that will allow to write a backup program. This program will be written with default values that i plan to replace. All this heavy work is because i can't have with me all the time a notebook with vb installed to recompile the backup program with diferent values. Also i don't want that ppl change the paramethers or i would make the backup program to use a ini. Some times, ppl who don't know what they are doing, damage the program and then the backups aren't correctly donne. (I'v tryed the ini before and ppl changed/damaged the defenitions).
Now i'm facing a bigger problem. Changing the hex values and writing the executable backup is easy, the hard part is how will i be able to include the huge hexed backup inside the main program...any idea?
Re: Converting a binary file to hex>>file
So, in short what you want to do, is to save some settings, but you don't want the user to be able to modify the settings ?
Re: Converting a binary file to hex>>file
Re: Converting a binary file to hex>>file
Quote:
Originally Posted by TDQWERTY
exactly.
Well, if you would have said that from the beginning, it would've been much easier...
Did you consider Encryption ? (I'm the king of encryption :D )
Or to make the file(s) hidden to the user (And ADS file...) ?
Re: Converting a binary file to hex>>file
yes, i did, they deleted the ini file :\ i guess that didn't worked very well :(
It's sad to say this but there are ppl that are totaly stupid and can't accept what we tell them, "Do not change anything inside this folder X" - well, they deleted the folder... :(
It would be way simple if all i had to use was one file that they can't touch the configs...
Re: Converting a binary file to hex>>file
Make an ADS file:
VB - How to use Alternate Data Stream files
Or put your settings in the Registry, and don't use names that are the same as the application name. That way it's more difficult for them to find the keys/values.
Re: Converting a binary file to hex>>file
Regestry is out of question, i don't want to use that, it gives me more work to change when i need. The Alternate Data Stream files are a possibility too...and i will probably use it. I didn't knew that method :)
Edit:
Two things that i didn't understood that you said:
Could i also protect the program?
An other question is, could i use a ini file using the ADS method too?
I'm not sure if i understood 100% of what/how it does/it works.. :thumb:
Edit2: Is that considered a virus? :eek: