OpenSSL和Qt打架了?ssf2fcitx改進(jìn)版 帶24個(gè)搜狗熱皮
〔 下 載 〕
ssf2fcitx在轉(zhuǎn)換部分.ssf文件(如【SUNDAY】黑色炫酷)時(shí),openssl的庫(kù)里出錯(cuò):
Program received signal SIGSEGV, Segmentation fault. #0 0x00007ffff7ad2543 in AES_cbc_encrypt () from /lib/x86_64-linux-gnu/libcrypto.so.3 AES_cbc_encrypt(ssfbin + 8, out, static_cast<size_t>(size - 8), &key, iv, AES_DECRYPT);
王小川超過(guò)王小云啦?搜狗會(huì)造讓OpenSSL崩潰的數(shù)據(jù)啦?What a black day.
它fread文件到char*,解密,調(diào)用Qt解壓,寫(xiě)入QByteArray. 在libcrypto里出錯(cuò)時(shí),后面那些事都還沒(méi)干呢。
改成了不用Qt(調(diào)用zlib),能成功解密解壓。
不過(guò), 黑色炫酷解壓后共14個(gè)文件,有1個(gè).png,看圖軟件EOM說(shuō)CRC Error.
ssf2dir把name.ssf文件解密、解壓到name目錄中。do-all-ssf.sh批量干這個(gè)。
原來(lái)的ssf2fcitx被改成了只處理目錄,名字改為do-dir,do-all-dir.sh干這個(gè)。
每個(gè)皮膚一個(gè)目錄,里面除了圖片 (.png)文件,還有.ini配置文件。do-dir把.ini轉(zhuǎn)換為fctix的conf文件。雖然都是INI格式,但key-value等不同。
do-all-dir.sh還把處理完的目錄mv到~/.config/fcitx/skin下。
修改配置文件~/.config/fcitx/conf/fcitx-classic-ui.config的最后一行,把SkinType改成<皮膚目錄名>。
注銷/重啟/關(guān)機(jī)時(shí),fcitx會(huì)重寫(xiě)上述配置文件,所以改之前先killall fcitx,改完再fcitx.
比如我這里有兩個(gè):
5284 ? 00:00:04 fcitx
5299 ? 00:00:00 fcitx-dbus-watc
pkill fcitx后再啟動(dòng)它,和舊的fcitx-dbus-watc不能配合,輸入法就出不來(lái)了。
fcitx -d run as daemon(default) 所以不用fcitx&,啟動(dòng)它后按下回車鍵,就看到shell提示符了。
killall -HUP fcitx 不重新加載配置文件 (完全可以理解,麻煩),輸入法沒(méi)了。
ssf2fcitx要裝qtbase5-dev 下載幾M,安裝幾十M,圖形部分只是用QImg獲取下png文件的大小。
我想把轉(zhuǎn)換部分也去Qt化,get_png_size()寫(xiě)好了 (libpng-dev)。
QSettings用map<string, string>基本寫(xiě)好了,然后發(fā)現(xiàn)要轉(zhuǎn)換的行太多了,煩了,把半成品放進(jìn)包里,收工了。
- 試了一圈后,本人還是用無(wú)圖版dark
- ssf2fcitx的作者說(shuō)有些.ssf其實(shí)是沒(méi)加密的.zip
- 解密后iv被修改,再次用它解密結(jié)果不對(duì)
- openssl/evp.h:const EVP_CIPHER *EVP_aes_256_cbc(void)
- 本例不調(diào)用EVP_CIPHER_CTX_cleanup沒(méi)事
- 函數(shù)參數(shù)設(shè)計(jì)成void*和const void*,用戶就不必reinterpret_cast<const unsigned char*>buf了。應(yīng)把麻煩留給自己
- 有人說(shuō)加密和解密是一樣的,本例把Decrypt換成Encrypt,結(jié)果不一樣
- mkdir時(shí)別忘了0755(八進(jìn)制)而不是755(十進(jìn)制)
匿名變量作用域演示:
struct MyClass { ~MyClass () { puts("~MyClass"); } void print () const { puts("xxx"); } }; void fn (const MyClass& m) { m.print(); } int main () { fn(MyClass()); puts("---"); } xxx ~MyClass ---
ssf2dir舊源碼(包里的有mkdir等):
#include <stdio.h> #include <string.h> #include <locale.h> #include <openssl/aes.h> #include <openssl/evp.h> #include <zlib.h> int AES256_decrypt(void* out_, const void* in_, int n, const void* key, void* iv) { const int BS = AES_BLOCK_SIZE * 1024; //const int BS = n; EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new(); auto cipher = EVP_aes_256_cbc(); if (!EVP_DecryptInit_ex(ctx, cipher, NULL, (const uint8_t*)key, (uint8_t*)iv)) return 0; uint8_t* out = (uint8_t*)out_; const uint8_t* in = (const uint8_t*)in_; int total = 0, len; while (n > 0) { int m = n > BS ? BS : n; EVP_DecryptUpdate(ctx, out, &len, in, m); if (len != m) printf("update: %d %d %d\n", total, len, m); out += len; total += len; in += m; n -= m; } EVP_DecryptFinal_ex(ctx, out + total, &len); printf("final: %d\n", len); EVP_CIPHER_CTX_cleanup(ctx); EVP_CIPHER_CTX_free(ctx); return total + len; } const uint8_t key[] = { 0x52, 0x36, 0x46, 0x1A, 0xD3, 0x85, 0x03, 0x66, 0x90, 0x45, 0x16, 0x28, 0x79, 0x03, 0x36, 0x23, 0xDD, 0xBE, 0x6F, 0x03, 0xFF, 0x04, 0xE3, 0xCA, 0xD5, 0x7F, 0xFC, 0xA3, 0x50, 0xE4, 0x9E, 0xD9 }; uint8_t iv[] = { 0xE0, 0x7A, 0xAD, 0x35, 0xE0, 0x90, 0xAA, 0x03, 0x8A, 0x51, 0xFD, 0x05, 0xDF, 0x8C, 0x5D, 0x0F }; char x[8 * 1024 * 1024]; int y[2 * 1024 * 1024]; struct QDataStream { uint8_t* p; int pos; QDataStream (void* p_) { p = (uint8_t*)p_; pos = 0; } QDataStream& operator >> (int &n) { n = *((int*)(p + pos)); pos += 4; return *this; } void seek (int pos_) { pos = pos_; } void utf162mbs (char* mbs, int n) { wchar_t wcs[256]; wcs[n] = 0; for (int i = 0; i < n; i++) { wcs[i] = *((uint16_t*)(p + pos)); pos += 2; } wcstombs(mbs, wcs, n + 1); // 其實(shí)全是英文名 } operator uint8_t* () { return p + pos; } }; int main (int argc, char* argv[]) { setlocale(LC_ALL, ""); // FILE* fp = fopen("SUNDAY黑色炫酷.ssf", "rb"); FILE* fp = fopen("一二.ssf", "rb"); if (!fp) return 1; fseek(fp, 0, SEEK_END); int size = ftell(fp); rewind(fp); fread(x, 1, size, fp); fclose(fp); int n = AES256_decrypt(y, x + 8, size - 8, key, iv); printf("%d decryped\n", n); size = *y; *y = __builtin_bswap32(size); uLongf _ = size; uncompress((uint8_t*)x, &_, (const uint8_t*)y + 4, n - 4); printf("%d uncompressed\n", size); QDataStream ds(x); ds >> size >> n; n /= 4; printf("%d files\n", n); int ofs[256]; for (int i = 0; i < n; i++) ds >> ofs[i]; for (int i = 0; i < n; i++) { ds.seek(ofs[i]); int len; ds >> len; char name[256], path[256]; ds.utf162mbs(name, len / 2); ds >> len; printf(" %s %d\n", name, len); sprintf(path, "out/%s", name); if (FILE* fp = fopen(path, "w")) fwrite(ds, 1, len, fp), fclose(fp); } }

浙公網(wǎng)安備 33010602011771號(hào)