As already mentioned
earlier on Habré, FireBreath is a framework for developing cross-platform plug-ins using NPAPI [1] technologies and ActiveX Control hosts, which will allow using the plug-in in the following browsers: Gecko / Firefox, Google Chrome, Apple Safari, Opera, Microsoft Internet Explorer 6, 7, and 8.
I found this framework useful for the following: in the project (web application) a Java applet was used to print Pdf files directly to the printer, but due to various problems with Java Policy and rights, the applet + various small bugs could not be stable somehow capture the applet focus after loading or hang browser during printing. Perhaps just the hands are crooked. In general, printing worked, then not, and this did not suit anyone.
As an option, it was decided to try to write a plugin that will get rid of the applet and print files quickly and securely. Actually, printing now performs the same Java code, rewritten as a jar file. However, the layer that interacts between Java and client code is the browser plugin.
')
Now we will write a simple “count, do nothing” plugin that will write data to a file in the local file system.
Install Firebreath
- Download the FireBreath sources using Git or the FireBreath archive [2]:
git clone git://github.com/firebreath/FireBreath.git -b firebreath-1.5 firebreath-1.5
- Go to the folder with the downloaded Firebreath and generate an empty project. To do this, we need to install Python:
python fbgen.py
fbgen.py will ask us for some plugin data (for example, name and description) and create a folder with the plugin sources in the projects / pluginName folder. Next, the console output when performing these operations:
alex@alex-laptop:~$ git clone git://github.com/firebreath/FireBreath.git -b firebreath-1.5 firebreath-1.5
Initialized empty Git repository in /home/alex/firebreath-1.5/.git/
remote: Counting objects: 16089, done.
remote: Compressing objects: 100% (4841/4841), done.
remote: Total 16089 (delta 12322), reused 14495 (delta 11066)
Receiving objects: 100% (16089/16089), 11.28 MiB | 535 KiB/s, done.
Resolving deltas: 100% (12322/12322), done.
alex@alex-laptop:~$ cd firebreath-1.5/
alex@alex-laptop:~/firebreath-1.5$ python fbgen.py
Plugin Name []: readFile
Plugin Identifier [readFile]:
Plugin Prefix [RFI]:
Plugin MIME type [application/x-readfile]:
Plugin Description []:
Invalid syntax: Description must be one or more characters long!
Plugin Description []: Read test.txt from ~ folder
Plugin has no UI [false]:
Company Name []:
Invalid syntax: Name must be at least one character, and may not contain carriage returns.
Company Name []: Takeforce
Company Identifier [Takeforce]:
Company Domain [takeforce.com]:
Done. Files placed in /home/alex/firebreath-1.5/projects/readFile
- Now we will write the code that will write data to the file (for example, /home/alex/log.txt). We will need to make changes to the code of the files readFileAPI.cpp and readFileAPI.h, which, as the name implies, describe and implement the plug-in interface:
The method that will write to the file (forgive my C ++ :)):
FB::variant readFileAPI::write(const FB::variant& msg) { string message; if (msg.is_of_type<FB::JSObjectPtr>()) { message = msg.cast<FB::JSObjectPtr>()->Invoke("ToString", FB::variant_list_of()).convert_cast<std::string > (); } else { message = msg.convert_cast<std::string > (); } ofstream myfile; myfile.open ("/home/alex/log.txt"); myfile << message; myfile.close(); return msg; }
- Let's also add the method signature in the .h file and register the method in the class constructor:
registerMethod("write", make_method(this, &readFileAPI::write))
Plugin build
We will need the following packages to work:
- CMake version 2.8
- libgtk2.0-dev
- Git
In Ubuntu / Debian, you can install using the command:
apt-get install cmake libgtk2.0-dev git
- First you need to prepare the build code by running prepmake.sh in the FireBreath root folder.
- The build folder will be created, go to it and execute the make command.
Implementation
As a result, we will have in the build / bin / readFile folder a file, npreadFile.so, which needs to be copied ~ / .mozilla / plugins, where chrome and firefox can find it. After that, you can start the browser and open the file build / projects / readFile / gen / FBControl.htm
The page will say that the plugin has successfully loaded and now you can try it in the console - we write:
plugin().write('Hello');
And look at our file /home/alex/log.txt, in which “Hello” appeared.
findings
If you need to perform something on the client with browser rights that could not be done in other ways, or perform some heavy operations, and at the same time, you are satisfied that you need to install software on the client computer, it makes sense to look towards FireBreath.
I checked that the plugin created in FireBreath works in Google Chome, Mozilla Firefox and IE8 version. It is also stated that it works in Opera, Safari and IE6-7, but I did not check it.
References:
1)
en.wikipedia.org/wiki/NPAPI2)
www.firebreath.org