It is currently Sat Jan 23, 2021 6:15 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: PureBasic Constant Sniffer
PostPosted: Sat May 01, 2004 3:13 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:51 pm
Posts: 2809
Location: Portugal, Lisbon
Code updated for 5.20+

This little project reads out all of the PB contants present in .res files.

Code:
; 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:
Quote:
#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

_________________
Elevator Maintenance: http://central-elevadores.pt
Good web hosting![/size]


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat May 01, 2004 3:17 pm 
Offline
Always Here
Always Here
User avatar

Joined: Sat Aug 30, 2003 5:58 pm
Posts: 5883
Location: Denmark
thanks :D


Top
 Profile  
Reply with quote  
 Post subject: Re: PureBasic Constant Sniffer
PostPosted: Sat May 01, 2004 9:06 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Oct 16, 2003 8:30 pm
Posts: 1998
Location: North Florida
Very nice.. thanks.. great tool

- np


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 14, 2006 2:19 am 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1488
Location: North by Northwest
Is there an updated version of this little tool?
With this version only a few constants are catched.

Thanks


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 14, 2006 3:26 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4598
Location: Not Sydney!!! (Bad water, no goats)
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 14, 2006 4:19 am 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1488
Location: North by Northwest
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...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 14, 2006 6:07 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4598
Location: Not Sydney!!! (Bad water, no goats)
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 14, 2006 5:45 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1488
Location: North by Northwest
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 14, 2006 11:42 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1488
Location: North by Northwest
Because I wanted to have a list (in a file) I changed Num3's code to work properly with V4.

Code:
; 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.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 15, 2006 1:13 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4598
Location: Not Sydney!!! (Bad water, no goats)
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 15, 2006 1:45 am 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5818
Location: Germany
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 15, 2006 2:14 am 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1488
Location: North by Northwest
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 15, 2006 2:47 am 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5818
Location: Germany
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Feb 15, 2006 4:48 am 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1488
Location: North by Northwest
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Apr 09, 2006 11:15 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Sep 20, 2003 3:57 pm
Posts: 216
Location: Germany
Why you dont read the values for the constants, too?

Code:
; 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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: Denis and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye