今天我在爲Chrome創建一個新的主題創建器時遇到了一個問題。如您所知,Chrome使用稱爲CRX的「新」文件格式來管理其插件和主題。這是一個基本的zip文件,但有點修改:如何用C#代碼替換openSSL調用?
「CR24」 + derkey +簽名+壓縮文件
這裏來的問題。只有兩個用Ruby或Python編寫的CRX創建器。我不太瞭解這兩種語言(儘管在Python中有一些基本的經驗,但主要是使用PyS60),所以我想請你幫助我將這個Python應用程序轉換爲不依賴於外部程序的C#代碼。
而且,這裏是crxmake.py來源:
#!/usr/bin/python
# Cribbed from http://github.com/Constellation/crxmake/blob/master/lib/crxmake.rb
# and http://src.chromium.org/viewvc/chrome/trunk/src/chrome/tools/extensions/chromium_extension.py?revision=14872&content-type=text/plain&pathrev=14872
# from: http://grack.com/blog/2009/11/09/packing-chrome-extensions-in-python/
import sys
from array import *
from subprocess import *
import os
import tempfile
def main(argv):
arg0,dir,key,output = argv
# zip up the directory
input = dir + ".zip"
if not os.path.exists(input):
os.system("cd %(dir)s; zip -r ../%(input)s . -x '.svn/*'" % locals())
else:
print "'%s' already exists using it" % input
# Sign the zip file with the private key in PEM format
signature = Popen(["openssl", "sha1", "-sign", key, input], stdout=PIPE).stdout.read();
# Convert the PEM key to DER (and extract the public form) for inclusion in the CRX header
derkey = Popen(["openssl", "rsa", "-pubout", "-inform", "PEM", "-outform", "DER", "-in", key], stdout=PIPE).stdout.read();
out=open(output, "wb");
out.write("Cr24") # Extension file magic number
header = array("l");
header.append(2); # Version 2
header.append(len(derkey));
header.append(len(signature));
header.tofile(out);
out.write(derkey)
out.write(signature)
out.write(open(input).read())
os.unlink(input)
print "Done."
if __name__ == '__main__':
main(sys.argv)
請你能幫助我嗎?