PureBasic Constant Sniffer

Share your advanced PureBasic knowledge/code with the community.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2810
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

PureBasic Constant Sniffer

Post 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
thefool
Always Here
Always Here
Posts: 5881
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

thanks :D
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: PureBasic Constant Sniffer

Post by NoahPhense »

Very nice.. thanks.. great tool

- np
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Is there an updated version of this little tool?
With this version only a few constants are catched.

Thanks
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post 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.
Amateur Radio, D-STAR/VK3HAF
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post 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...
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post 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.
Amateur Radio, D-STAR/VK3HAF
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post 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.
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post 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]
:wink:


EDIT:
Changed code to avoid writing of this 7 special String Constants.
Now 595 constants are written.
Thanks Freak.
Last edited by fsw on Wed Feb 15, 2006 5:10 am, edited 1 time in total.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post 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?
Amateur Radio, D-STAR/VK3HAF
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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.
quidquid Latine dictum sit altum videtur
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post 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.
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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.
quidquid Latine dictum sit altum videtur
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Now I understand...

You tricked me :wink:

:lol:

EDIT:
Changed code above to avoid writing of this 7 special String Constants.
Now 595 constants are written.
Thanks again Freak.
User avatar
Deeem2031
Enthusiast
Enthusiast
Posts: 216
Joined: Sat Sep 20, 2003 3:57 pm
Location: Germany
Contact:

Post 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
irc://irc.freenode.org/#purebasic
Post Reply