AddOn Signing ctypes open

Hi,

I currently moved my addon from a binary c++ xpcom to a extension created with the AddOn Sdk that uses ctypes, and managed to get a successful preliminary review.

I read that if the binary component isn’t packed in the xpi there is no need to upload the source code.
But now I would like to know what is the best way to “load” the dll inside the extension, my extension isn’t listed and is installed by unziping the xpi to a folder and creating a registry key.

If I move the DLL to the unzipeed folder as expected the signing will fail, but I really don’t want to use “full paths” in the scripts, since the software can be installed in machines with diferent languages so it can be inside “Program Files”, “Programas”, etc…

So my original code was something like this:

    Cu.import("resource://gre/modules/Services.jsm");
    const ResProtocolHandler = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
    const ChromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
    function resolveToFile(uri) {
        switch (uri.scheme) {
            case "chrome":
                return resolveToFile(ChromeRegistry.convertChromeURL(uri));
            case "resource":
                return resolveToFile(Services.io.newURI(ResProtocolHandler.resolveURI(uri), null, null));
            case "file":
                return uri.QueryInterface(Ci.nsIFileURL).file;
            default:
               throw new Error("cannot resolve");
        }
    }

    const {data} = require("sdk/self");
    let dll = data.url("ff40panel.dll");
    dll = resolveToFile(Services.io.newURI(dll, null, null));
    var ff40panellib = ctypes.open(dll.path);

So is there a way to know in the script for example enviroment folders (program data, program files), etc… so that I could use something like:

var ff40panellib =
    ctypes.open("{{ProgramFiles}}\\Marktest\\Netpanel\\Components\\ff-v40.x.x\\ff40panel.dll");

Thanks.
João Augusto

1 Like

Give this a look: Getting files in special directories.

Thanks.

Did you see this article: https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Using_js-ctypes/ctypes.open

Also here is a bunch of special keys and paths: https://gist.github.com/Noitidart/715840fa5008ee032017

Im trying to collect for all OS’s, those keys are like 98% of the special keys i might have missed some.

When getting special paths I recommend Services.dirsvc.get('key_here', Ci.nsIFile).path over FileUtils.getFile('key_here', []).path because the dirsvc method caches them so its faster and better for memory.

Hi,

Thanks for the reply, I already updated the addon to use the FileUtils to obtain the common app data.
And it’s now signed (preliminary) and working properly.

Thanks.

Can you copy paste the code, im interested :slight_smile:

Nothing special…

var {FileUtis} = Cu.import("resource://gre/modules/FileUtils.jsm");
var file = FileUtils.getFile("CmAppData", ["Marktest", "Netpanel", "FF40Panel", "ff40panel.dll"]);
var ff40panellib = ctypes.open(file.path);

Cool stuff, so on install of your addon you copy this dll ot the cmapdat/…/… folder?

The extension is installed by a service on the machines, on the service startup it copies(if needed) the DLL to a specific folder inside the %programdata% that can be accesed in the addon by using the “CmAppData”.