2013-03-23 64 views
3

我有一個.pfa font file,我想讀取「算法」渲染字體。但是,大部分信息都隱藏在二進制中:如何「解碼」字體文件的eexec?

currentfile eexec 
743F8413F3636CA85A9FFEFB50B4BB27302A5F6C876586CCC1670A7EF5521E6ADE15AAB4 
DD2DDDB83735311FC63DB80D2C96AECFA05BB67F865EA35934B4B79A203A8DD489B09C79 
FF6EB9DBCFD889C3E73F8C94BC342AF671D6F688870A62EE1A0DF216E150FFEC64A8C2B7 
509AD05C011599C1AD84E6C4B668E07EA219BD72663D8AF4CA8EC8E23AA90DE90BE940C6 
6DB849CEDB3B64961365A7CCE47F4FC9E30FDEE4B14B90C2E0D8C344EBC974EABF417B3D 
28251A78ACEE2BFC4212B1E3E9C7EBC3262821EE98E538713C64DF0BC13C19337B1307DB 
D795D285F959C924FC14AEF7E9D406406CDEE1A35377887A16B13DD51717A86284369FA7 
6ABB6A4488B9174A561DA854C33821F3172E4CF956EC9B65F829D69E02BC0EE23044DB1D 
9A4D45A14A3998115BEE5DDC582F158DB2E.................. 

我們如何「解碼」這些信息?

回答

8

除非你真的想編寫自己的eexec解密,然後自己charstring類型解密,我建議你只需使用t1disasm即可。如果你是一個Linux發行版上運行,你也許能找到一個包,它應該包含這個t1utils,也可以在許多地方得到源(谷歌是你的朋友),這裏有一個:

http://freepcb.googlecode.com/svn/clibpdf/trunk/util/t1utils-1.9/t1disasm.c

如果您使用的是Windows,你可以看看這裏的t1utils包FOPR窗口:

http://gnuwin32.sourceforge.net/packages/t1utils.htm

+0

+1我完全忘記了OP出現的字符串障礙。我的回答在那裏沒有幫助。 – 2013-03-27 03:48:37

3

這被描述爲「Adobe類型1,字體格式」,出版物由Adobe Systems available on the web.

+0

是的,但首先我們需要解碼編碼的信息。當我將「743F8413F3636CA85A9FFEFB50B4BB ....」解碼爲ASCII碼時,我有「t? clcl û''0*_l e Ág........」。難道我做錯了什麼? – Pacerier 2013-03-23 06:57:57

+1

看看第7章「加密」 – Henry 2013-03-23 08:44:11

0

我認爲KenS的回答比較好,但是,作爲一個好奇心,這裏是一個emacs函數,它執行一個輔助輸入的eexec解密(即不解密十六進制輸入並且沒有字符串解密)。該算法來自亨利答案中的文件。

(defun eexec-decrypt() 
    "decrypt eexec binary block (see Type1 font); 
    NB: no charstring decryption" 
    (interactive) 
    (search-forward "currentfile eexec")(forward-char 1) 
    (with-output-to-temp-buffer (concat (buffer-name) "-eexec-decripted") 
    (setq r 55665) 
    (setq c1 52845) 
    (setq c2 22719) 
    (setq here (point)) 
    (setq count 4) 
    (while (< here (point-max)) ; I'm not really sure where to stop... 
     (setq cipher (get-byte here)) 
     (setq plain (logxor cipher (lsh r -8))) 
     (cond ((> count 0) ; skip first 4 bytes 
     (setq count (- count 1))) 
     (t (princ (byte-to-string plain)))) 

     (setq r (mod (+ c2 (* c1 (+ cipher r))) 65536)) 
     (setq here (+ 1 here))))) 
2

我解密eexec加密發現this document非常有幫助。在中使用上面提到的代碼的一個簡單示例。

#Getting the eexec binary, make sure you exclude the ascii part in the end, after the binary portion 
text = open('fontfile.pfa').read() 
raw_hex = text.split('eexec')[1] 
decarr = list() 
count = 0 
hex_code = str() 

#Converting pairs of the hexadecimal digits to decimal, e.g. ff -> 255, and storing it in an array decarr 
for i in range(len(raw_hex)): 
    if raw_hex[i] == '\n': 
     decarr.append(raw_hex[i]) 
     continue 
    else: 
     hex_code = hex_code + raw_hex[i] 
     count += 1 
     if count == 2: 
      decarr.append(int(hex_code, 16)) 
      count = 0 
      hex_code = str() 

一旦我們有了對十六進制數字的十進制等價物的陣列,我們執行解密如在Adobe Type 1 Font Format Specification第7章中提到。常數如說明書中所述。

c1 = 52845 
c2 = 22719 
R = 55665 
p = list() 
for i in range(0,len(decarr)): 
    if decarr[i] is not '\n': 
     p.append(decarr[i]^(R >> 8)) 
     R = ((decarr[i] + R)*c1 + c2) & ((1 << 16) - 1) 
    else: 
     p.append(decarr[i]) 
decrypted = list() 
for i in range(len(p)): 
    if p[i] is not '\n': 
     decrypted.append(chr(p[i])) 
    else: 
     decrypted.append(p[i]) 

希望它有幫助!