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)
Edit: There is probably a better viewer somewhere on these boards.
