Page 1 of 2
PureBasic Constant Sniffer
Posted: Sat May 01, 2004 3:13 pm
by Num3
Code updated for 5.20+
This little project reads out all of the PB contants present in .res files.
Code: Select all
; PB Resident Sniffer
open.s=OpenFileRequester("Res Sniffer","*.res","*.res",1)
If ReadFile(0,open)
size=Lof(0)
buffer=AllocateMemory(size)
ReadData(0,buffer,size)
CloseFile(0)
If CreateFile(1,"output.txt")
For a=0 To size
line.s=Trim(PeekS(buffer+a))
If Mid(line,1,3)="PB_"
WriteStringN(1,"#"+line)
EndIf
a+Len(line)
Next
CloseFile(1)
EndIf
EndIf
This outputs the following:
#PB_3DArchive_FileSystem
#PB_3DArchive_Zip
#PB_Any
#PB_Button_Left
#PB_Button_MultiLine
#PB_Button_Right
#PB_Button_Toggle
#PB_Camera_Orthographic
#PB_Camera_Perspective
#PB_Camera_Plot
#PB_Camera_Textured
#PB_Camera_Wireframe
#PB_CheckBox_Center
#PB_CheckBox_Right
#PB_Clipboard_Image
#PB_ClipboardImage
...
...
...
etc
Posted: Sat May 01, 2004 3:17 pm
by thefool
thanks

Re: PureBasic Constant Sniffer
Posted: Sat May 01, 2004 9:06 pm
by NoahPhense
Very nice.. thanks.. great tool
- np
Posted: Tue Feb 14, 2006 2:19 am
by fsw
Is there an updated version of this little tool?
With this version only a few constants are catched.
Thanks
Posted: Tue Feb 14, 2006 3:26 am
by Fangbeast
fsw wrote:Is there an updated version of this little tool?
With this version only a few constants are catched.
Thanks
The reason for this is that there are resident files for all situations such as the Windows API, Linx Mac and other author's own residents and they all start with anything but PB_ so you have to analyse the format of the res file to grab all these others. Num3's routine only grabs (and looks for) all the obvious PB ones.
Have a look at one of the biggest res files with a hex viewer and you will soon see the format you need to grab.
Posted: Tue Feb 14, 2006 4:19 am
by fsw
Fangbeast wrote:...Num3's routine only grabs (and looks for) all the obvious PB ones...
Fangles,
that's exactly what's needed for.
There are so many new PB constants - it would be nice to get a complete list. But Num3's tool only catches a few.
Hoped to find a PB_Constants Listviewer in the new IDE or a file in the compiler directory...
Posted: Tue Feb 14, 2006 6:07 am
by Fangbeast
fsw wrote:Fangbeast wrote:...Num3's routine only grabs (and looks for) all the obvious PB ones...
Fangles,
that's exactly what's needed for.
There are so many new PB constants - it would be nice to get a complete list. But Num3's tool only catches a few.
Hoped to find a PB_Constants Listviewer in the new IDE or a file in the compiler directory...
I went looking in the IDE and there is a constants viewer and it lists thousands. I went and counted the number of PB ones, came out to 608.
Go to TOOLS/STRUCTURE VIEWER and then the CONSTANTS tab and see if that's the one you wanted.
Posted: Tue Feb 14, 2006 5:45 pm
by fsw
Fangbeast wrote:I went looking in the IDE and there is a constants viewer and it lists thousands. I went and counted the number of PB ones, came out to 608.
Go to TOOLS/STRUCTURE VIEWER and then the CONSTANTS tab and see if that's the one you wanted.
That's exactly it, thanks Fangles.
Take care
PS. It shows that I didn't do anything with Pure in almost a year... Thanks again.
Posted: Tue Feb 14, 2006 11:42 pm
by fsw
Because I wanted to have a list (in a file) I changed Num3's code to work properly with V4.
Code: Select all
; PB Resident Sniffer for "PB_" constants
open.s=OpenFileRequester("Res Sniffer","*.res","*.res",1)
If ReadFile(0,open)
size.l=Lof(0)
open = GetFilePart(open)
If CreateFile(1,open +".txt")
For a=0 To size ;Step 1
Number.b = ReadByte(0)
If Number = 80 ;Hex = 50
Number.b = ReadByte(0)
If Number = 66 ;Hex = 42
Number.b = ReadByte(0)
If Number = 95 ;Hex = 5F
StartPoint.l = Loc(0) - 3
Repeat
Number.b = ReadByte(0)
If Number = 0
EndPoint.l = Loc(0)
Break
EndIf
ForEver
BufferSize.l = EndPoint - StartPoint
buffer=AllocateMemory(BufferSize)
FileSeek(0, StartPoint)
ReadData(0,buffer,BufferSize)
line.s=PeekS(buffer)
If line = "PB_Explorer_Column_Accessed" ;do nothing
ElseIf line = "PB_Explorer_Column_Attributes" ;do nothing
ElseIf line = "PB_Explorer_Column_Created" ;do nothing
ElseIf line = "PB_Explorer_Column_Modified" ;do nothing
ElseIf line = "PB_Explorer_Column_Name" ;do nothing
ElseIf line = "PB_Explorer_Column_Size" ;do nothing
ElseIf line = "PB_Explorer_Column_Type" ;do nothing
Else
WriteStringN(1,"#"+line)
EndIf
EndIf
EndIf
EndIf
Next
CloseFile(1)
EndIf
CloseFile(0)
EndIf
FreeMemory(-1)
MessageRequester("HI", "ALL DONE")
End
[crap]
With this code I get 602 constants, 7 of them are not even recognized by the compiler:
#PB_Explorer_Column_Accessed
#PB_Explorer_Column_Attributes
#PB_Explorer_Column_Created
#PB_Explorer_Column_Modified
#PB_Explorer_Column_Name
#PB_Explorer_Column_Size
#PB_Explorer_Column_Type
[/crap]
EDIT:
Changed code to avoid writing of this 7 special String Constants.
Now 595 constants are written.
Thanks Freak.
Posted: Wed Feb 15, 2006 1:13 am
by Fangbeast
Fred must have forgotten to put those int he latest beta because I remember with 3.94 that you could remove collumns in an ExplorerListIcon and add custom types using those constants (or similar) to create system specific collumn types.
These are the current ones that 3.94 understood.
#PB_Explorer_Name : displays the name of the file/directory
#PB_Explorer_Size : displays the filesize in Kb
#PB_Explorer_Type : displays a string describing the filetype
#PB_Explorer_Attributes : displays the attributes of the file/directory
#PB_Explorer_Created : displays the time the file/directory was created
#PB_Explorer_Modified : displays the time the file/directory was last modified
#PB_Explorer_Accessed : displays the time the file/directory was last accessed
Compare those to the ones you just found:
#PB_Explorer_Column_Accessed
#PB_Explorer_Column_Attributes
#PB_Explorer_Column_Created
#PB_Explorer_Column_Modified
#PB_Explorer_Column_Name
#PB_Explorer_Column_Size
#PB_Explorer_Column_Type
Almost sounds like he has changed; or is planning to change the old format to be more consistent to these new examples. Witht he word "Column" in the constant name, it makes more sense.
@Fred Have you changed; or are you planning to change; the old constants names to these new ones? Will they be in a later beta or the full release?
Posted: Wed Feb 15, 2006 1:45 am
by freak
These constants were there for a long time and have not changed.
They are string constants actually with values like "PB_Explorer_Column_Name",
thats why your tool is probably mistaken the values themselves to be constants.
Just look up #PB_Explorer_Name in the IDE's Structureviewer and you will see.
Posted: Wed Feb 15, 2006 2:14 am
by fsw
Place these constants in your code:
#PB_Explorer_Column_Accessed
#PB_Explorer_Column_Attributes
#PB_Explorer_Column_Created
#PB_Explorer_Column_Modified
#PB_Explorer_Column_Name
#PB_Explorer_Column_Size
#PB_Explorer_Column_Type
and try to compile.
The compiler says:
"Line X: Constant not found: #PB_Explorer_Column_Accessed"
That's why I said the compiler doesn't recognizes them.
It seems weird because they are in the RES file, so the compiler should know them.
Posted: Wed Feb 15, 2006 2:47 am
by freak
They are NOT in the resident. Your extraction code is wrong.
Just look up #PB_Explorer_Name in the IDE Strueture/Constant viewer and you will see where the confusion comes from.
Posted: Wed Feb 15, 2006 4:48 am
by fsw
Now I understand...
You tricked me
EDIT:
Changed code above to avoid writing of this 7 special String Constants.
Now 595 constants are written.
Thanks again Freak.
Posted: Sun Apr 09, 2006 11:15 pm
by Deeem2031
Why you dont read the values for the constants, too?
Code: Select all
; PB Resident Sniffer for "PB_" constants
open.s=OpenFileRequester("Res Sniffer","C:\Purebasic\Residents\","*.res",1)
If ReadFile(0,open)
size.l=Lof(0)
open = GetFilePart(open)
If CreateFile(1,open +".txt")
For a=0 To size ;Step 1
Number.b = ReadByte(0)
If Number = 80 ;Hex = 50
Number.b = ReadByte(0)
If Number = 66 ;Hex = 42
Number.b = ReadByte(0)
If Number = 95 ;Hex = 5F
StartPoint.l = Loc(0) - 3
Repeat
Number.b = ReadByte(0)
If Number = 0
EndPoint.l = Loc(0)
Break
EndIf
ForEver
BufferSize.l = EndPoint - StartPoint - 1
buffer=AllocateMemory(BufferSize)
FileSeek(0, StartPoint)
ReadData(0,buffer,BufferSize)
line.s=PeekS(buffer,BufferSize)
FreeMemory(buffer)
If line = "PB_Explorer_Column_Accessed" ;do nothing
ElseIf line = "PB_Explorer_Column_Attributes" ;do nothing
ElseIf line = "PB_Explorer_Column_Created" ;do nothing
ElseIf line = "PB_Explorer_Column_Modified" ;do nothing
ElseIf line = "PB_Explorer_Column_Name" ;do nothing
ElseIf line = "PB_Explorer_Column_Size" ;do nothing
ElseIf line = "PB_Explorer_Column_Type" ;do nothing
Else
ReadWord(0)
WriteStringN(1,"#"+line+" = "+Str(ReadLong(0)))
;Debug "#"+line+" = "+Str(ReadLong(0))
EndIf
EndIf
EndIf
EndIf
Next
CloseFile(1)
EndIf
CloseFile(0)
EndIf
MessageRequester("HI", "ALL DONE")
End