How to Read a File in Hex Code.....(Hex Edit Style....)

Share your advanced PureBasic knowledge/code with the community.
darklordz
Enthusiast
Enthusiast
Posts: 119
Joined: Wed May 21, 2003 1:44 pm
Location: Netherlands
Contact:

How to Read a File in Hex Code.....(Hex Edit Style....)

Post by darklordz »

Code updated for 5.20+

Code: Select all

#File = 0

Procedure.s _ReadHEX(Filename.s)
	If OpenFile(#File,Filename.s)
		Repeat
			CurPos.l = FileSeek(#File,Loc(#File))
			RetVal.s = RetVal.s+Hex(ReadByte(#File))+" "
		Until Eof(#File)
		CloseFile(#File)
	EndIf
	ProcedureReturn RetVal.s
EndProcedure

Debug _ReadHEX("c:\test2.bck")
Same for Unsigned Binary..

Code: Select all

#File = 0

Procedure.s _ReadBIN(Filename.s)
	If OpenFile(#File,Filename.s)
		Repeat
			CurPos.l = FileSeek(#File,Loc(#File))
			RetVal.s = RetVal.s+Str(ReadByte(#File))+" "
		Until Eof(#File)
		CloseFile(#File)
	EndIf
	ProcedureReturn RetVal.s
EndProcedure

Debug _ReadBIN("c:\test2.bck")
Proteus
Enthusiast
Enthusiast
Posts: 113
Joined: Wed Sep 17, 2003 8:04 pm
Location: The Netherlands

Post by Proteus »

Strings can't be larger than 64000 characters, if I remember right. You could try:
A) Reading it in blocks of 64k chars or less.
B) Putting it in a buffer.
P4 2.4GHz, 256 MB, WinXP Pro, onboard video&audio.
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
Post Reply