NPAPI plugin does not get loaded in Firefox

一曲冷凌霜 提交于 2019-12-08 07:47:08

问题


I'm writing an plugin and it gets into [INVALID] section in pluginreg.dat file on Windows. I think there is a problem in my npplugin.rc file.

In npplugin.def file everything is correct:

LIBRARY
EXPORTS
    NP_GetEntryPoints @1
    NP_Initialize @2
    NP_Shutdown @3

But neither NP_GetEntryPoints nor NP_Initialize is called.

To install plugin I put it into %APPDATA%/Mozilla/plugins directory.

Here is npplugin.rc code:

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

#if 0
/////////////////////////////////////////////////////////////////////////////
// Russian (Russia) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE 
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED

#endif    // Russian (Russia) resources
/////////////////////////////////////////////////////////////////////////////
#endif

/////////////////////////////////////////////////////////////////////////////
// English (United States) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 4,5
 PRODUCTVERSION 4,5
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x40004L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "CompanyName", "MyCompany Ltd."
            VALUE "FileExtents", "myext"
            VALUE "FileOpenName", "My File"
            VALUE "FileDescription", "NPPlugin for me"
            VALUE "FileVersion", "4.5"
            VALUE "InternalName", "npMyPlugin"
            VALUE "Language", "English (United States)"
            VALUE "LegalCopyright", "Copyright (C) MyCompany Ltd. 2012"
            VALUE "MIMEType", "application/x-myplugin"
            VALUE "OriginalFilename", "npMyPlugin.dll"
            VALUE "ProductName", "My NPPlugin"
            VALUE "ProductVersion", "4.5"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END

#endif    // English (United States) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED

My question is where is an error or what is missing?


回答1:


This is Chris from conedogers, glad to see that you found my blog useful.

Georg is correct. Firefox is not looking for a windows locale. It looks like Mozilla has their own internationalization which makes sense because their code is written for multiple platforms.

What is happening here is the BLOCK "040904e4" tells the binary how to process the strings contained below. Version information does not use C style struct to contain the strings. the block information is used to calculate the byte offsets and string characters types so you can extract the strings.

It appears that Firefox has been built for en-western so you need to do the same otherwise, as you found out, Firefox will not be able to load the version info to retrieve the mime-type and description strings.

MSDN article




回答2:


I don't really know what distinct modification made it work. The problem was really in the resource file or maybe in defines. I've changed the subblock 040904b0 to 040904e4, file and product versions to 4,5,0,0 (thus making them be 4-digit, I still do not know does it matter or not), added '\0's at the end of each VALUE, changed the format of string versions to '%d, %d, %d, %d', added some additional VALUEs and some additional defines (XP_WIN;XP_WIN32;MOZILLA_STRICT_API;XPCOM_GLUE).

All that "ideas" I've "borrowed" from

this article: http://conedogers.com/2012/11/08/npapi-plugin-sample-for-firefox/

and this source code sample: https://github.com/chrisDwarner/npruntimeSampleCode (is referenced in the article above).

Here is my final version of the npplugin.rc:

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

#if 0
/////////////////////////////////////////////////////////////////////////////
// Russian (Russia) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE 
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED

#endif    // Russian (Russia) resources
/////////////////////////////////////////////////////////////////////////////
#endif

/////////////////////////////////////////////////////////////////////////////
// English (United States) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 4,5,0,0
 PRODUCTVERSION 4,5,0,0
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x40004L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
#if 0
        BLOCK "040904b0"
#else
        BLOCK "040904e4"
#endif
        BEGIN
            VALUE "CompanyName", "MyCompany Ltd.\0"
            VALUE "FileExtents", "myfile\0"
            VALUE "FileOpenName", "My File\0"
            VALUE "FileDescription", "NPPlugin for me\0"
            VALUE "FileVersion", "4, 5, 0, 0\0"
            VALUE "InternalName", "npMyPlugin\0"
            VALUE "Language", "English (United States)\0"
            VALUE "LegalCopyright", "Copyright (C) MyCompany Ltd. 2012\0"
            VALUE "LegalTreademarks", " \0"
            VALUE "MIMEType", "application/x-myplugin\0"
            VALUE "OriginalFilename", "npMyPlugin.dll"
            VALUE "PrivateBuild", "\0"
            VALUE "ProductName", "My NPPlugin"
            VALUE "ProductVersion", "4, 5, 0, 0\0"
            VALUE "SpecialBuild", "\0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END

#endif    // English (United States) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED


来源:https://stackoverflow.com/questions/13859882/npapi-plugin-does-not-get-loaded-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!