I'm trying to use Firefox to read the SSH banner. ie. when you initially connect to an SSH server the server sends you its banner, identifying the server software and you send the SSH server your banner, identifying your client software.
To do so I'm using the example at this URL:
Is there nsiClientSocket in firefox extension javascript?
Here's my code:
'use strict';
const {Cc,Ci} = require("chrome")
const prefs = require("simple-prefs");
exports.main = function(options,callbacks) {
var transport = Components.classes["@mozilla.org/network/socket-transport-service;1"]
.getService(Components.interfaces.nsISocketTransportService)
.createTransport(null, 0, "localhost", 22, null);
//var output = transport.openOutputStream(0, 0, 0);
var input = transport.openInputStream(0, 0, 0);
var data = "test";
dump(stream.read());
//stream.write(data, data.length);
//stream.close();
dump("all done!");
};
When I do cfx xpi with that I get this:
The following lines from file C:\path\to\lib\main.js:
8: var transport = Components.classes["@mozilla.org/network/socket-transport-service;1"]
9: .getService(Components.interfaces.nsISocketTransportService) use 'Components' to access chrome authority. To do so, you need to add a line somewhat like the following:
const {Cc,Ci} = require("chrome");
Then you can use any shortcuts to its properties that you import from the 'chrome' module ('Cc', 'Ci', 'Cm', 'Cr', and 'Cu' for the 'classes', 'interfaces', 'manager', 'results', and 'utils' properties, respectively. And `components` for `Components` object itself).
So I try this instead:
'use strict';
const {Cc,Ci} = require("chrome")
const prefs = require("simple-prefs");
exports.main = function(options,callbacks) {
var transport = components.classes["@mozilla.org/network/socket-transport-service;1"]
.getService(interfaces.nsISocketTransportService)
.createTransport(null, 0, "localhost", 22, null);
//var output = transport.openOutputStream(0, 0, 0);
var input = transport.openInputStream(0, 0, 0);
var data = "test";
dump(stream.read());
//stream.write(data, data.length);
//stream.close();
dump("all done!");
};
ie. I make Components components (lowercase) and Components.interfaces just interfaces. But then I get this error on the console:
var transport = components.classes["@mozilla.org/network/socket-transport-service;1"]
ReferenceError: components is not defined
Any ideas?
You should use Cc
instead of Components.classes
and Ci
instead of Components.interfaces
- these are the variables you imported from the chrome
module and they are defined. Should you ever need to use the Components
object itself (unlikely) you can import it as well:
const {components, Cc, Ci} = require("chrome");
For reference: chrome authority
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.