$INCLUDE "RAPIDQ.INC"
DIM FONTSETTINGS AS QFONT
FONTSETTINGS.COLOR = &hFFFFFF
FONTSETTINGS.AddStyles(0)
DIM hexF AS QFILESTREAM
DIM MemhexF AS QMEMORYSTREAM
DIM sz AS LONG
DIM File$
DIM OPENHEXFILEDIALOG AS QOPENDIALOG
DECLARE SUB OPENFILEFORHEXEDITING
DECLARE SUB stockF
DECLARE SUB edit2
DECLARE SUB saveF
CREATE Form AS QFORM
CAPTION = "HeX Editor"
Width = 495
Height = 416
Center
BorderStyle = 4
CREATE HEXMENU AS QMAINMENU
CREATE HEXFILEMENU AS QMENUITEM
CAPTION = "File"
CREATE HEXFILEMENUOPENFILE AS QMENUITEM
CAPTION = "Open File"
OnClick = OPENFILEFORHEXEDITING
END CREATE
CREATE HEXFILEMENUSAVEFILE AS QMENUITEM
CAPTION = "Save File"
OnClick = saveF
END CREATE
CREATE HEXFILEMENUQUIT AS QMENUITEM
CAPTION = "Quit"
END CREATE
END CREATE
END CREATE
CREATE RichEdit1 AS QRICHEDIT
Left = 0
Top = 20
Width = 89
Height = 369
Align = 3
ReadOnly = 1
END CREATE
CREATE RichEdit2 AS QRICHEDIT
Left = 89
Top = 20
Width = 200
Height = 369
Align = 3
TabOrder = 1
END CREATE
CREATE RichEdit3 AS QRICHEDIT
Left = 289
Top = 20
Width = 200
Height = 369
Align = 3
TabOrder = 2
Wordwrap = 1
PlainText = 1
END CREATE
CREATE Panel1 AS QPANEL
Left = 0
Top = 0
Width = 490
Height = 20
BevelOuter = 0
Align = AlTop
TabOrder = 3
COLOR = &h000000
CREATE Label1 AS QLABEL
CAPTION = "Offset"
Left = 29
Top = 4
FONT = FONTSETTINGS
END CREATE
CREATE Label2 AS QLABEL
CAPTION = "HeX"
Left = 173
Top = 4
Width = 28
FONT = FONTSETTINGS
END CREATE
CREATE Label3 AS QLABEL
CAPTION = "ASCII"
Left = 381
Top = 4
Width = 28
FONT = FONTSETTINGS
END CREATE
END CREATE
END CREATE
Form.SHOWMODAL
SUB OPENFILEFORHEXEDITING
IF OPENHEXFILEDIALOG.EXECUTE THEN
f$ = OPENHEXFILEDIALOG.FileName
hexF.OPEN(f$, FmOpenRead)
Form.CAPTION = f$
END IF
sz = hexF.Size
stockF
END SUB
SUB stockF
MemhexF.CopyFrom(hexF,sz )
MemhexF.Position = 0
hexF.Position = 0
File$ = MemhexF.ReadStr(sz)
hexF.CLOSE
Edit2
END SUB
SUB Edit2
FOR n& = 1 TO LEN(File$)
t$ = MID$(File$,n&,1)
c = ASC(t$)
IF t$ < CHR$(32) OR t$ > CHR$(126) THEN t$ = "."
IF t$ > CHR$(31) AND < CHR$(127) THEN ascii$ = ascii$ + t$
c$ = c$ + RIGHT$(HEX$(c),2)+" "
NEXT n&
RichEdit2.Text = c$
RichEdit3.Text = ascii$
SHOWMESSAGE OPENHEXFILEDIALOG.FileName+" successfully loaded!"
memhexF.CLOSE
c$=""
END SUB
SUB saveF
FOR n& = 1 TO LEN(File$)
t$ = MID$(File$,n&,1)
c = ASC(t$)
ch$ = ch$ + CHR$(c)
NEXT n&
hexF.OPEN("myFile.exe", fmCreate)
hexF.WriteBinStr(ch$,LEN(ch$))
hexF.CLOSE
END SUB
|