| Author |
Message |
|
Carsomyr
BBDinosaur
Joined: Wed Dec 13, 2006 7:33 pm Posts: 263 Location: Pretoria, South Africa
|
Well, glad you found the culprit. I've been trying to get a build going which could help debug the socket closing, but haven't had any luck yet. Luckily that won't be neccesary any more. (if it is, let me know and I'll try and finish that)
I should have a new version in a few days incorperating all the features tresni did (as soon as I get my head around the code) as well as additional notifications (such as BB_DESKTOPINFO messages and others) and more control over the information sent to the attached processes (in case you don't want BB_DESKTOPINFO messages or even bro@ms being sent to you).
I'm also finishing work on a system to parse the arguments for functions to make adding the rest of the API functions easier.
|
| Thu Dec 28, 2006 8:20 pm |
|
 |
|
Google
Sponsored Links
|
|
 |
|
tresni
Site Admin
Joined: Sun Dec 05, 2004 8:59 pm Posts: 1316 Location: Boise, Idaho
|
Here's my build with the SendMessage to avoid the erroneous feedback from bro@ms due to PostMessage. I think that's really the only change. *shrug*  Figured this would be handy though so that the plugin was actually usable. Basiclly I'll bug fix what I've done, but there will be no new features added, for that you will have to wait for the next release from Carsomyr 
Attachments:
File comment: binary
bbSocket.dll [22.5 KiB]
Downloaded 150 times
File comment: source
bbSocket.cpp [15.27 KiB]
Downloaded 129 times
_________________ -- Brian ♠ ♥ ♣
|
| Thu Dec 28, 2006 8:56 pm |
|
 |
|
crowmag
Moderator
Joined: Sat Dec 11, 2004 12:06 am Posts: 1310 Location: Violent Paradise
|
It was most defiantly BBSky, since I unloaded it, my little test app has been working flawlessly: Code: connect success: Thu Dec 28 11:23:23 2006 success - bro@m sent: Thu Dec 28 11:23:26 2006 success - bro@m sent: Thu Dec 28 12:59:15 2006 success - bro@m sent: Thu Dec 28 14:38:39 2006 success - bro@m sent: Thu Dec 28 15:15:40 2006 success - bro@m sent: Thu Dec 28 16:35:44 2006
My idea of parsing Yahoo Weather is on hold until I can figure out how to provide an interface for it, can't seem to think of a way to get the info into a BBInterface control.  Anyone else want to take their shot at it, be my guest. Maybe bbTcl? Info is here:
http://developer.yahoo.com/python/python-xml.html
_________________ I'll have the roast duck... with mango sauce and a large helping of BB4Win Wiki: http://wiki.bb4win.org/wiki/Main_Page
|
| Thu Dec 28, 2006 10:02 pm |
|
 |
|
tresni
Site Admin
Joined: Sun Dec 05, 2004 8:59 pm Posts: 1316 Location: Boise, Idaho
|
Here's my first ever stab at python + bbinterface + bbsocket for a simple weather replacement. It's ass, but it'll work for the moment. You do have to edit the weather.py file (it's commented) but it should be fairly easy to understand.
Attachments:
File comment: bbPyInterWeatherExtraviganza!
weather.zip [167.88 KiB]
Downloaded 148 times
_________________ -- Brian ♠ ♥ ♣
|
| Fri Dec 29, 2006 6:46 am |
|
 |
|
crowmag
Moderator
Joined: Sat Dec 11, 2004 12:06 am Posts: 1310 Location: Violent Paradise
|
tresni wrote: Here's my first ever stab at python + bbinterface + bbsocket for a simple weather replacement. It's ass, but it'll work for the moment. You do have to edit the weather.py file (it's commented) but it should be fairly easy to understand.
As we used to say in the old days... FAR OUT !
"ass" my ass, beautifully done! I was trying to strip the XML using html2text which was very akward and un-pythonic - that was ass. Why didn't I think about just putting the tags in a list  , makes a lot more sense.
Guess this isn't your first day with python tresni, 'cause if it is, I am awe struck
I'll see about modding this to use a config file tonight so it's can be used generically and then packaging it with py2exe so our non-scripters can enjoy it too! 
_________________ I'll have the roast duck... with mango sauce and a large helping of BB4Win Wiki: http://wiki.bb4win.org/wiki/Main_Page
|
| Fri Dec 29, 2006 2:03 pm |
|
 |
|
tresni
Site Admin
Joined: Sun Dec 05, 2004 8:59 pm Posts: 1316 Location: Boise, Idaho
|
second day with python  I just did a lot of google for concepts and copied/pasted the code together till it resembled what I wanted. Then tweaked until it was what I wanted.  At first I used regular expressions on the xml feed's description tag to get the image, but the realized I could just get the code and feed that to a string so.. It wasn't too bad. Anyway..
The timer was the funnest part to figure out. You can stop it with a simple stop_timer() Otherwise it updates the weather every 30 minutes
_________________ -- Brian ♠ ♥ ♣
|
| Fri Dec 29, 2006 3:30 pm |
|
 |
|
Carsomyr
BBDinosaur
Joined: Wed Dec 13, 2006 7:33 pm Posts: 263 Location: Pretoria, South Africa
|
 New release
Heres the newest build of BBSocket, thought I'd upload it before calling it a day. Thanks to tresni for authorization and other additions. This build uses the same entries in the rc file as tresni's build (bbSocket.port: integer, bbSocket.localHostOnly: bool and the auth entries)
A major change from tresni's build is that all string arguments to functions (like MakeMenu) MUST now be enclosed in quotes. The quotes will be stripped by BBSocket before the strings are passed to blackbox. Returned strings are now also enclosed in quotes.
The authorization function is present, so a plugin must call send("AUTHORIZE plugin_name") to obtain user authorization after it connects (quotes around the plugin name will not be stripped and only a single space should be used between AUTHORIZE and the plugin name. The authorization is saved in the rc file, so the user is only prompted once for each plugin.
All plugins will by default recieve bro@ms BBSocket once they are authorised. This can be disabled (though I'm not sure if anyone would want to) by sending Code: unsubscribe("BB_BROADCAST") A plugin can also choose to recieve BB_RECONFIGURE and BB_DESKTOPINFO message (more to come) by using Code: subscribe("BB_RECONFIGURE") subscribe("BB_DESKTOPINFO") Theses notifications can also be unsubscribed and the messages sent over the socket will then look like this (see the GetDesktopInfo() function for an explanation of the data) Code: @@BB_RECONFIGURE @@BB_DESKTOPINFO <"alpha",1,0,4,"alpha","beta","gamma","delta"> Supported API functionsAs a reference a string is enclosed in quotes ("A string"), an integer is a number, a bool is 1 for true and 0 for false. The following function are available for reading/writing to rc files: Code: ReadBool(string RCpath , string key, bool defaultValue) returns a bool ReadInt((string RCpath , string key, integer defaultValue) returns an integer ReadString(string RCpath , string key, string defaultValue) returns a string WriteBool(string RCpath , string key, bool Value) returns nothing WriteInt((string RCpath , string key, integer Value) returns nothing WriteString(string RCpath , string key, string Value) returns nothing The following menu functions are available (with some differences from tresni's build, but his code did help a lot). These functions return nothing on success unless indicated, on failure they will return ERROR: (error description). BBSocket stores menuID's seperately for each connected plugin and will return an error if you attempt to use an invalid menuID. MenuID's are recycled after they are no longer valid, so you should recieve the same small range each time you construct your menu. Code: MakeMenu(string title) returns a menuid(integer) MakeNamedMenu(string title, string unique_name, bool popup) returns a menuid(integer) MakeSubMenu(int menuid, int submenuid, string title) NOTE: the submenuid becomes invalid after this function is called MakeMenuItem(int menuid, string title, string cmd, bool indicator) MakeMenuItemInt(int menuid, string title, string cmd, int val, int minval, int maxval) MakeMenuItemString(int menuid, string title, string cmd, string val) MakeMenuNop(int menuid, string title) ShowMenu(int menuid) NOTE:The menuid becomes invalid after this function is called DelMenu(int menuid) NOTE:The menuid becomes invalid after this function is called Other functions available are: Code: GetBBVersion() returns a string GetOSInfo() returns a string GetBBWnd() returns the blackbox window handle as a hexadecimal number GetDesktopInfo() returns a structure enclose in angle brackets the elements are <string workspaceName, bool isCurrentworkspace(always true), integer workspaceNumber(starts at 0), integer nmberOfWorspaces, string workspace1Name, string workspace2Name ... , string workspaceNName>
The only place case will make a difference is the text you supply to name menus or menu entries, all functions are case insensitive(including AUTHORIZE). Any amount of whitespace may be present between function arguments, they must just be seperated by commas.
I think that about covers everything
Attachments:
File comment: Plugin (0.0.3)
BBSocket.dll [59.5 KiB]
Downloaded 149 times
File comment: Source (0.0.3)
BBSocket_src.zip [6.8 KiB]
Downloaded 141 times
|
| Fri Dec 29, 2006 8:43 pm |
|
 |
|
tresni
Site Admin
Joined: Sun Dec 05, 2004 8:59 pm Posts: 1316 Location: Boise, Idaho
|
 Re: New release
Carsomyr wrote: Theses notifications can also be unsubscribed and the messages sent over the socket will then look like this (see the GetDesktopInfo() function for an explanation of the data) Code: @@BB_RECONFIGURE @@BB_DESKTOPINFO <"alpha",1,0,4,"alpha","beta","gamma","delta"> Just a suggestion but use something other than @, that way it is easy to distinguish between broams and internal commands.. Then agian nothing says a broam has to start with @, they just do by convention. Still, I would use a completely differant character, or encapsulate (I seriously thought about doing a mock xml thing when I was hackin on this, but decided not to  ) Quote: Code: MakeSubMenu(int menuid, int submenuid, string title) NOTE: the submenuid becomes invalid after this function is called ... ShowMenu(int menuid) NOTE:The menuid becomes invalid after this function is called
From a old BB4Win dev standpoint this is a bad idea, iirc a menu can be modified after it has been made a submenu up until the point the main menu has been ShowMenu()'d. Also ShowMenu() does not remove the memory allocated for the menu. DelMenu can be used after show menu to hide a menu as well (to make sure it is not still visible or whatever). So invalidating after ShowMenu() removes this ability.
Hope you don't mind the constructive critisism.. You are doing an awesome job!! Now bbPyInterWeatherExtraviganza can store its settings in rc instead of having to modify the python file! woot! woot! I'll make an update and post it tomorrow morning. For now I have to get a 2 month old to bed. 
_________________ -- Brian ♠ ♥ ♣
|
| Sat Dec 30, 2006 6:40 am |
|
 |
|
crowmag
Moderator
Joined: Sat Dec 11, 2004 12:06 am Posts: 1310 Location: Violent Paradise
|
 Re: New release
tresni wrote: Now bbPyInterWeatherExtraviganza can store its settings in rc instead of having to modify the python file! woot! woot! I'll make an update and post it tomorrow morning. For now I have to get a 2 month old to bed. 
tresni, here is some info you may find useful:
If you have the ctypes module installed, here is super easy way to produce a message box (can be used in-line): Code: import os, sys, ctypes
ctypes.windll.user32.MessageBoxA(0, "This is the message", "This is the title", 0x30) If you want to package bbPyInterWeatherExtraviganza into an exe with py2exe, you may find that running a packaged console script will do just that - produce a console. Plus, Blackbox (at least bbLean) dosn't like to launch them from a menu (or BBInterface button) for some reason. I ran into those problems with bbLeanTheme and after much googleling I never got a definative answer so, I had to experiment with all the various setup script syntax until I came up with this generic script I use that will run the program hidden (nobody wants to tell you how to do that). To make it work, use the ' pyw' extension on the script your going to package instead of ' py'. Put the edited 'setup.py' below in the same dir as your script, data resources and icon then at a command prompt: python setup.py py2exe You can then UPX the exe, dll(s) and icon in the 'dist' directory if you want. Code: #!python # setup.py
from distutils.core import setup import py2exe import sys
# If run without args, build executables, in quiet mode. if len(sys.argv) == 1: sys.argv.append("py2exe") sys.argv.append("-q")
class Target: def __init__(self, **kw): self.__dict__.update(kw) # for the versioninfo resources self.version = "THE_VERSION_NUMBER_HERE" self.copyright = "THE_COPYRIGHT_NOTICE_HERE" self.name = "THE_APP_NAME_HERE"
THE_APP_NAME_HERE = Target( # used for the versioninfo resource description = "SHORT_DESCRIPTION_USED_ON_EXPLOER_ICON",
# what to build script = "THE_SCRIPT_FILENAME_HERE", icon_resources = [(1, "THE_ICON_FILENAME_HERE")], dest_base = "THE_APP_NAME_HERE")
################################################################
setup( options = {"py2exe": {"compressed": 1, "optimize": 2, "bundle_files": 1, "packages": ["encodings"],}}, zipfile = None, data_files=[(".", ["RESOURCE_OR_COINFIG_FILENAME_HERE"])], windows = [THE_APP_NAME_HERE], # no quotes )
_________________ I'll have the roast duck... with mango sauce and a large helping of BB4Win Wiki: http://wiki.bb4win.org/wiki/Main_Page
|
| Sat Dec 30, 2006 12:17 pm |
|
 |
|
crowmag
Moderator
Joined: Sat Dec 11, 2004 12:06 am Posts: 1310 Location: Violent Paradise
|

Figured I list some additional sources so anyone looking for ideas for a python project to work with bbSocket.
win32inet: http://www.itamarst.org/software/
Python module for Windows, lets you check if the computer is connected to the Internet. MIT license.
win32taskbar: http://www.itamarst.org/software/
Create a windows tray app (needs ActivePython or Win32 module installed). Import win32taskbar.py (import win32taskbar) to make use of the Taskbar class. Win9x\ME compatable. MIT license. See sHTTPd source for an example: http://www.lostinthebox.com/viewtopic.php?t=2162
SysTrayIcon: http://www.brunningonline.net/simon/blo ... ython.html
(search the page for 'SysTrayIcon')
Create a windows tray app with menu (needs ActivePython or Win32 module installed) - Win9x\ME don't like it.
Boatload of scripts that list Win32 system resources:
http://www.thescriptlibrary.com/default ... age=Python
Python Cron: http://sourceforge.net/projects/pycron/
Clone of the well-known cron job scheduler for the unix flavored operating systems. Platform-independant.
Fetching and Parsing HTML Sites with Python (not necessarily porn):
http://codeboje.de/blog/archives/Movieg ... -that.html
Fetch MP3's (w\o downloading them) and play them through WinAmp or other player:
http://sebsauvage.net/python/programs.html (scroll down to myradioplayer.py')
NOTE: the Tkinter callback in the script is broken - but you don't want that anyway, control it with bbInterface.
Other sebsauvage snippets here: http://sebsauvage.net/python/snyppets/index.html
Use the PyMedia module to play audio\video: http://pymedia.org/
NOTE: the only tutorial that worked for me was 'Playing a WAV file', the others had bogus info. Here is the correct code (found in the forum) to play a MP3 file: Code: #!python # play_MP3.py
import pymedia import time
def play_MP3(filename): demuxer = pymedia.muxer.Demuxer('mp3') f = open(filename, 'rb') spot = f.read() frames = demuxer.parse(spot) decoder = pymedia.audio.acodec.Decoder(demuxer.streams[0]) frame = decoder.decode(spot) sound = pymedia.audio.sound song = sound.Output( frame.sample_rate, frame.channels, 16 ) while len(spot) > 0: try: if frame: song.play(frame.data) spot = f.read(512) frame = decoder.decode(spot) except: pass while song.isPlaying(): time.sleep(.05) print 'Done Playing ', filename
def main(): filename = raw_input('Path to the MP3 file you want to play:\n') play_MP3(filename)
if __name__ == '__main__': main()
Well, hope that gives some inspiration for others experimenting with Python to join in here.
_________________ I'll have the roast duck... with mango sauce and a large helping of BB4Win Wiki: http://wiki.bb4win.org/wiki/Main_Page
|
| Sat Dec 30, 2006 3:42 pm |
|
 |
|
noccy
BBDinosaur
Joined: Fri Jan 27, 2006 4:16 am Posts: 794 Location: Karlstad, Sweden
|

tresni wrote: Quote: You should however (if you havent already) add an option for "Bind IP" in the configuration, and default to 127.0.0.1. Also, the port should be configurable. It would suck if some skript-kiddie wrote a worm that scanned for bbSocket and executed the shutdown broam I agree. In my pm to Carsomyr I told him that I thought every script/plugin accessing the server should have to be "authorized" by the user on first usage, just like skype does for 3rd party programs. This way there would be little chance of something maliciously hijacking your computer through the socket. At the current time there is little that can be done I personally believe given that the only API function that could be malicious is not accessible (BBExecute) through bbSocket. Now a combinations of plugins with bbSocket could lead to issues (BBRunBox, broambox, uberbox, or any other plugin that accepts a command through bro@m) but that would require a theme or something similar to exploit at this time.
Well there is only one way to do that in a reliable way. public/private keys. The server somehow has to challenge the client, which should in turn send back a info chunk and a certificate. And that, i think, would remove the simplicity that makes this project so tempting. However, a clean and nice solution would be:
1. Implement binding, and make the entire TCP mechanism optional in the settings.
2. Implement named pipes to do the exact same thing. Iirc named pipes can only be used like this under Win2K/XP (i might be wrong tho!) but this would probably be the prefered way of doing things on a 2K/XP system. Primarily since it would give more control over who is connected, and it would allow the server to manage a list of executables that are allowed to chat with it
I'm not 100% sure (i'm not a C++ dev), but isnt sockets treated as regular files? The same goes for named pipes (which technically are virtual files in the VFS root) so that shouldn't require too much modifications?
Cheers,
Christopher
_________________ Don't forget to check the BlackBox FAQs.
Jabber: noccy@jabber.se | Web: www.noccy.com | Blog: Minimal Security
|
| Sat Dec 30, 2006 5:22 pm |
|
 |
|
tresni
Site Admin
Joined: Sun Dec 05, 2004 8:59 pm Posts: 1316 Location: Boise, Idaho
|

noccy wrote: 1. Implement binding, and make the entire TCP mechanism optional in the settings. Already done and by default it only binds to localhost, so over the intersplice connects are only possible if the bbsocket.rc file is changed. Quote: 2. Implement named pipes to do the exact same thing. Iirc named pipes can only be used like this under Win2K/XP (i might be wrong tho!) but this would probably be the prefered way of doing things on a 2K/XP system. Primarily since it would give more control over who is connected, and it would allow the server to manage a list of executables that are allowed to chat with it  Only 2K/XP yes. Bluebox is built entirely on named pipes. Quote: I'm not 100% sure (i'm not a C++ dev), but isnt sockets treated as regular files? The same goes for named pipes (which technically are virtual files in the VFS root) so that shouldn't require too much modifications?
in some languages, but not all. a socket is not a file descriptor in [edit. Guess I should have specified C\C++ in Windows enviroments  ] C\C++ (at least not to my understanding and knowledge.) It is not handle the same and file functions are not able to be used in conjunction with sockets.
_________________ -- Brian ♠ ♥ ♣
Last edited by tresni on Sun Dec 31, 2006 12:21 am, edited 1 time in total.
|
| Sat Dec 30, 2006 8:01 pm |
|
 |
|
Carsomyr
BBDinosaur
Joined: Wed Dec 13, 2006 7:33 pm Posts: 263 Location: Pretoria, South Africa
|
Quote: 2. Implement named pipes to do the exact same thing. I can look into adding them in addition to the socket interface, but i've never worked with them before. I don't know if named pipes support the kind of asynchronous notification currently used by the socket interface either. Quote: I'm not 100% sure (i'm not a C++ dev), but isnt sockets treated as regular files? The same goes for named pipes (which technically are virtual files in the VFS root) so that shouldn't require too much modifications?
Under *nix sockets are treated as regular files (just like almost everything else), but microsoft decided they didn't agree with the idea so in windows sockets use an entirely seperate (but very similar) set of functions.
|
| Sat Dec 30, 2006 8:28 pm |
|
 |
|
noccy
BBDinosaur
Joined: Fri Jan 27, 2006 4:16 am Posts: 794 Location: Karlstad, Sweden
|

Carsomyr wrote: Quote: 2. Implement named pipes to do the exact same thing. I can look into adding them in addition to the socket interface, but i've never worked with them before. I don't know if named pipes support the kind of asynchronous notification currently used by the socket interface either. I've only read up on the topic, and you should be able to work them like regular files. This page has some info on the topic: http://msdn.microsoft.com/library/defau ... _pipes.aspAlso managed to find this wrapper class while googling on the topic http://www.codeguru.com/cpp/w-p/system/ ... 5771/#moreCarsomyr wrote: Quote: I'm not 100% sure (i'm not a C++ dev), but isnt sockets treated as regular files? The same goes for named pipes (which technically are virtual files in the VFS root) so that shouldn't require too much modifications? Under *nix sockets are treated as regular files (just like almost everything else), but microsoft decided they didn't agree with the idea so in windows sockets use an entirely seperate (but very similar) set of functions.
Ah, yes, I looked it up  I'm a VB6 Developer, but I'm using a wrapper around the native windows socket API so I haven't really delt much with those calls... My mistake
Cheers,
Christopher
_________________ Don't forget to check the BlackBox FAQs.
Jabber: noccy@jabber.se | Web: www.noccy.com | Blog: Minimal Security
|
| Sat Dec 30, 2006 10:15 pm |
|
 |
|
tresni
Site Admin
Joined: Sun Dec 05, 2004 8:59 pm Posts: 1316 Location: Boise, Idaho
|
I've run into an issue I want to see if it is duplicatable. Check this on any system with Python + bbSocket. I'm finding that the first group of send/recv (or recvfrom) time out unless I put a print between them. [this call being the "AUTHORIZE plugin" call.] Subsequent calls seem to execute fine. Attached is a slightly modified sendBroam() that has the AUTHORIZE statement added. The first sendBroam() fails with a timeout every time, but each subsequent statement works. Honestly I'm at a loss, utterly at a loss.. I'm going to try writing something in C to see if I can replicate the behavior, the only thing I can really figure is that the initial 'AUTHORIZE ...' is blocking too long. But then why does each subsequent call work? Each and every sendBroam() does the exact same thing, so I don't see any logic as to why the first fails and the others work. It really doesn't make a whole lot of sense to me.
Testprog.exe does not seem to exhibit the same behavior as far as I can tell..
Attachments:
File comment: sendBroam
sendBroam.zip [608 Bytes]
Downloaded 103 times
_________________ -- Brian ♠ ♥ ♣
|
| Sun Dec 31, 2006 12:35 am |
|
 |
|
Google
Sponsored Links
|
|
 |
|
Who is online |
Users browsing this forum: No registered users and 1 guest |
|
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 You cannot post attachments in this forum
|
|