Page 1 of 1

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

Posted: Tue Dec 09, 2003 1:03 am
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")

Posted: Thu Dec 11, 2003 2:28 pm
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.