Residents dumper

Everything else that doesn't fall into one of the other PB categories.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Residents dumper

Post by Dare2 »

Just for fun.

Dumps residents (but not Interface*.res) structures and constants.

Code: Select all

; Dare2
; PureBasic residents (.res) viewer. Rough and ragged. Needs version 4.00

; Dumps only:  Structures and constants.

; Assumes these are the first two 'sections' of a file
;   (Should really check the header keys)

; Seems to work with:
;  Windows.res, PureBasic.res, WindowsUnicode.res

; Fails with (and I haven't checked them out so may be major or minor)
;  Interface.res, InterfaceDX.res

#srcFile = 0
#dstFile = 1

Procedure bombOut(msg.s)
  MessageRequester("ERROR",msg,#MB_ICONERROR)
  If IsFile(#srcFile):CloseFile(#srcFile):EndIf
  If IsFile(#dstFile):CloseFile(#dstFile):EndIf
  End
EndProcedure

Define sName.s
Define oName.s

; - Need input & output names.

;sName.s = "Path\To\NameOf.res"
;oName.s = "Path\To\NameOf.res.txt"

If sName = "" Or oName = ""
  bombOut("YOU NEED TO HARD-CODE THE FILE NAMES")
EndIf
If Not ReadFile(#srcFile,sName)
  bombOut("UNABLE TO OPEN FILE"+Chr(10)+sName)
EndIf
If Not CreateFile(#dstFile,oName)
  bombOut("UNABLE TO CREATE FILE"+Chr(10)+oName)
EndIf

magic.l = ReadLong(#srcFile)

If magic <> $50555245
  bombOut("MAGIC WORD NOT 'ERUP'")             ; Not PURE, not even backwards!
EndIf

int4.l = ReadLong(#srcFile)
int4.l = ReadLong(#srcFile)
int4.l = ReadLong(#srcFile)
SysConsts.l = ReadLong(#srcFile)

While Loc(#srcFile) < SysConsts And Loc(#srcFile) < Lof(#srcFile)
                                                           ; Structure Start
  Struc.s = LSet("Structure " + ReadString(#srcFile),50)
  sSize.w = ReadWord(#srcFile)
  int2.w = ReadWord(#srcFile)
  elems.w = ReadWord(#srcFile)
  Struc + "; SizeOf structure: "+Str(sSize) + ", with " + Str(elems) + " fields."
  WriteStringN(#dstFile,Struc)
                                                           ; Per field
  pp = 1
  For i = 1 To elems
    p = Loc(#srcFile) + 20 + pp
    FileSeek(#srcFile,p)
    pp = 0
    arrElms.l = ReadLong(#srcFile)
    fld.s = "  " + ReadString(#srcFile) + "." + ReadString(#srcFile)
    If arrElms > 1
      fld + "[" + Str(arrElms) + "]"
    EndIf
    WriteStringN(#dstFile,Fld)
  Next
  WriteStringN(#dstFile,"EndStructure")
  WriteStringN(#dstFile,"")
Wend

int4 = ReadLong(#srcFile)
EndConst = Loc(#srcFile) + ReadLong(#srcFile)

While Loc(#srcFile) < EndConst - 1
  const.s = "#" + ReadString(#srcFile) + " = "
  int1 = ReadByte(#srcFile)
  If int1 = 0
    v = ReadByte(#srcFile) & $FF
    const + Str(v)
  ElseIf int1 = 1
    v = ReadWord(#srcFile)
    const + Str(v)
  ElseIf int1 = 2
    v = ReadLong(#srcFile)
    const = LSet(const + "$" + Hex(v),55) + "; " + Str(v)
  ElseIf int1 = 3
    v1.q = ReadQuad(#srcFile)
    const = LSet(const + "$" + Hex(v1),55) + "; " + Str(v1)
  ElseIf int1 = 4
    v4.f = ReadDouble(#srcFile)
    const = const + StrF(v4)
  ElseIf int1 = 5
    v5.d = ReadDouble(#srcFile)
    const = const + StrD(v5)
  ElseIf int1 = 6                       ; String. Some faffing around with non-print chars
    p.l = Loc(#srcFile)                 ;         and null
    vs.s = ReadString(#srcFile)
    vw.s = Left(vs,1) + Chr(1)
    If vs = "" Or Asc(vw) < 32 Or Asc(vw) = 34 Or Asc(vw) = 127
      FileSeek(#srcFile,p)
      w.s=""
      Repeat
        int1 = ReadByte(#srcFile) & $FF
        If int1 <> 0
          w + " + Chr($" + RSet(Hex(int1),2,"0") + ")"
          int1 = ReadByte(#srcFile) & $FF
        EndIf
      Until int1 = 0
      If w = ""
        w = " + Chr$(0)"
      EndIf
      const + Mid(w,3,Len(w))
    Else
      const + Chr('"') + vs + Chr('"')
    EndIf
  Else
    bombOut("@ "+Hex(Loc(#srcFile)) + " Constant of " + Str(int1)+ " (Hmmmm?)")
  EndIf
  WriteStringN(#dstFile,const)
Wend

CloseFile(#srcFile)
CloseFile(#dstFile)
Don't expect coding magic, it comes as written as I was exploring the windows.res and I chucked a few comments in afterwards. For a start, it should really read in the whole source and parse properly. But it dumps the desired (for me) info.

Edit: There is probably a better viewer somewhere on these boards. :)
@}--`--,-- A rose by any other name ..
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Residents dumper

Post by Kwai chang caine »

Yes ....it's a little bit later :oops:

But i search to have all the constants in a TXT, i see in the tools of native IDE (Tools\Structure Viewver\Constants)
I have search on the forum and find this nice code.

But i have two problem

1/ There are a bug at line 104
p.l = Loc(#srcFile) ; and null

2/ I don't know where is this list...in wich RES ???
ImageThe happiness is a road...
Not a destination
Post Reply