Skip to content

Commit

Permalink
remove META-INF/*
Browse files Browse the repository at this point in the history
  • Loading branch information
JustOff committed Jan 16, 2017
1 parent ff0d89e commit 3a65241
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,44 @@ function main(aWindow) {
srcFile.copyTo(tmpDir, "test-" + srcFile.leafName);
var tmpFile = tmpDir.clone();
tmpFile.append("test-" + srcFile.leafName);

var zr = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(Ci.nsIZipReader);
zr.open(tmpFile);

if (!zr.hasEntry(instName)) {
alert("Invalid XPI file!");
zr.close();
throw "Invalid XPI";
}


var metainfs = zr.findEntries("META-INF/*"), metaArr = [];
while (metainfs.hasMore()) {
metaArr.push(metainfs.getNext());
}
var instFile = zr.getEntry(instName);
var inputStream = zr.getInputStream(instName);
var sis = Cc['@mozilla.org/scriptableinputstream;1'].createInstance(Ci.nsIScriptableInputStream);
sis.init(inputStream);
var instData = sis.read(instFile.realSize);
sis.close();
zr.close();

instData = instData.replace(/<em:targetApplication>[\s\S]+?<\/em:targetApplication>/ig, "");
instData = instData.replace(/<em:updateURL>[\s\S]+?<\/em:updateURL>/ig, "");
instData = instData.replace(/<em:name>/i, "<em:updateURL>https://localhost/update.xml</em:updateURL><em:targetApplication><Description><em:id>{8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4}</em:id><em:minVersion>27.0</em:minVersion><em:maxVersion>*</em:maxVersion></Description></em:targetApplication><em:name>[TEST] ");
// Cu.reportError(instData);


var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
inputStream = converter.convertToInputStream(instData);

var zw = Cc['@mozilla.org/zipwriter;1'].createInstance(Ci.nsIZipWriter);
zw.open(tmpFile, pr.PR_RDWR);
for (var metainf of metaArr) {
if (metainf != "META-INF/") {
zw.removeEntry(metainf, false);
}
}
zw.removeEntry(instName, false);
zw.addEntryStream(instName, Date.now(), Ci.nsIZipWriter.COMPRESSION_DEFAULT, inputStream, false);
zw.close();
Expand Down Expand Up @@ -106,19 +114,19 @@ var installListener = {
onDownloadCancelled: function (aAddonInstall, aAddon) {
clearTemp();
},

onDownloadFailed: function (aAddonInstall, aAddon) {
clearTemp();
},

onInstallEnded: function (aAddonInstall, aAddon) {
clearTemp();
},

onInstallCancelled: function (aAddonInstall, aAddon) {
clearTemp();
},

onInstallFailed: function (aAddonInstall, aAddon) {
clearTemp();
}
Expand Down

0 comments on commit 3a65241

Please sign in to comment.