Guidance
指路人
g.yi.org
software / rapidq / examples / gui / Edit & Richedit / editor / HexEditor.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'from: Gérald_VERDIER  Tue, 11 May 2004 23:25:39 +0200
' HeX editor
'From: daxziz  Tuesday, May 11, 2004 2:22 PM

     $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 'to stock your open file = file$
     DECLARE SUB edit2 'to copy hex characters in RichEdit2
     DECLARE SUB saveF 'to save your file if you want ...

     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 'to read binary files
       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
'RichEdit3.LoadFromFile (OPENHEXFILEDIALOG.FileName)
'RichEdit2.Text = STR$(HEX$(RichEdit3.Text))
'RichEdit1.Text = ""
'END IF
'ShowMessage OPENHEXFILEDIALOG.FileName+" successfully loaded!"
'END SUB




     SUB OPENFILEFORHEXEDITING  'if you open an exe file you can see it in RichEdit 2 and 3
      IF OPENHEXFILEDIALOG.EXECUTE THEN
'RichEdit3.LoadFromFile (OPENHEXFILEDIALOG.FileName) 'for text files
       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$ ' for binary files
      SHOWMESSAGE OPENHEXFILEDIALOG.FileName+" successfully loaded!"
      memhexF.CLOSE
      c$=""
     END SUB

     SUB saveF 'you can save binary files
      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
掌柜推荐
 
 
¥1,380.00 ·
 
 
¥950.00 ·
 
 
¥487.00 ·
 
 
¥920.00 ·
 
 
¥1,160.00 ·
 
 
¥489.00 ·
© Mon 2024-11-25  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2004-05-12 20:01:20