mac book air 编译sqlcipher

编译SQLCipher

  • 0x01. 编译成静态库
$ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" \
    LDFLAGS="/opt/local/lib/libcrypto.a"

错误:

clang: error: no such file or directory: '/opt/local/lib/libcrypto.a'
...
configure:2922: error: in `/Users/panjing/github/sqlcipher':
configure:2924: error: C compiler cannot create executables
See `config.log' for more details
  • 0x02. 编译成动态库

第一步顺利通过

$ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" \
    LDFLAGS="-lcrypto"

第二步出错:

$ make

错误信息:

sqlite3.c:18280:10: fatal error: 'openssl/rand.h' file not found

重新安装openssl

Last login: Sat Jun  9 16:53:04 on ttys000
➜  ~ brew uninstall --force openssl
➜  ~ brew cleanup --force -s openssl
➜  ~ brew prune
Pruned 0 symbolic links and 1 directories from /usr/local
➜  ~ brew install openssl
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
ace                        heroku                     ngspice
apache-spark               hg-fast-export             nomad
ballerina                  hugo                       nsd
bitrise                    imagemagick                passenger
buildifier                 imagemagick@6              pgpool-ii
byacc                      infer                      phoronix-test-suite
cglm                       iozone                     php-cs-fixer
clhep                      jenkins                    plantuml
conan                      json-fortran               ponyc
dfix                       krakend                    pre-commit
docker-squash              libgit2                    pyvim
exiftool                   libngspice                 restic
eye-d3                     libplctag                  s3-backer
fibjs                      libraw                     saldl
flac                       linkerd                    spotbugs
folly                      mikutter                   stella
fonttools                  minetest                   terraform_landscape
fzf                        mingw-w64                  treefrog
genact                     mkdocs                     unbound
gnupg@1.4                  mkvtoolnix                 webpack
goreleaser                 mypy                       youtube-dl
gsoap                      nco                        zita-convolver
hadolint                   nesc
==> Deleted Formulae
aws-cloudsearch

==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2o_1.high_sierr
######################################################################## 100.0%
==> Pouring openssl-1.0.2o_1.high_sierra.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
?  /usr/local/Cellar/openssl/1.0.2o_1: 1,791 files, 12.3MB
➜  ~ 

根据提示执行:

echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
  • 0x03. 重新静态编译

修正libcrypto.a的路径,重新编译:

➜  sqlcipher git:(master) ✗ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" \
        LDFLAGS="/usr/local/opt/openssl/lib/libcrypto.a"

error:

sqlite3.c:21628:10: fatal error: 'openssl/rand.h' file not found
#include 
         ^~~~~~~~~~~~~~~~
1 error generated.
make: *** [sqlite3.lo] Error 1

文件存在,但是路径不对。

➜  sqlcipher git:(master) ✗ ls /usr/local/opt/openssl/include/openssl 
aes.h         des.h         idea.h        pem2.h        ssl2.h
asn1.h        des_old.h     krb5_asn.h    pkcs12.h      ssl23.h
asn1_mac.h    dh.h          kssl.h        pkcs7.h       ssl3.h
asn1t.h       dsa.h         lhash.h       pqueue.h      stack.h
bio.h         dso.h         md4.h         rand.h        symhacks.h
blowfish.h    dtls1.h       md5.h         rc2.h         tls1.h
bn.h          e_os2.h       mdc2.h        rc4.h         ts.h
buffer.h      ebcdic.h      modes.h       ripemd.h      txt_db.h
camellia.h    ec.h          obj_mac.h     rsa.h         ui.h
cast.h        ecdh.h        objects.h     safestack.h   ui_compat.h
cmac.h        ecdsa.h       ocsp.h        seed.h        whrlpool.h
cms.h         engine.h      opensslconf.h sha.h         x509.h
conf.h        err.h         opensslv.h    srp.h         x509_vfy.h
conf_api.h    evp.h         ossl_typ.h    srtp.h        x509v3.h
crypto.h      hmac.h        pem.h         ssl.h

解决办法:

➜  sqlcipher git:(master) ✗ brew link openssl --force
Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
  -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
➜  sqlcipher git:(master) ✗ 

// 下面命令才解决问题,上面命令没用
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto" CPPFLAGS="-I/usr/local/opt/openssl/include"

编译:

➜  sqlcipher git:(master) ✗ clear 

➜  sqlcipher git:(master) ✗ make
./libtool --mode=compile --tag=CC gcc -I/usr/local/opt/openssl/include  -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -DSQLITE_OS_UNIX=1 -I. -I/Users/panjing/github/sqlcipher/src -I/Users/panjing/github/sqlcipher/ext/rtree -I/Users/panjing/github/sqlcipher/ext/icu -I/Users/panjing/github/sqlcipher/ext/fts3 -I/Users/panjing/github/sqlcipher/ext/async -I/Users/panjing/github/sqlcipher/ext/session -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG  -DSQLITE_THREADSAFE=1    -DSQLITE_TEMP_STORE=2 -c sqlite3.c
libtool: compile:  gcc -I/usr/local/opt/openssl/include -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -DSQLITE_OS_UNIX=1 -I. -I/Users/panjing/github/sqlcipher/src -I/Users/panjing/github/sqlcipher/ext/rtree -I/Users/panjing/github/sqlcipher/ext/icu -I/Users/panjing/github/sqlcipher/ext/fts3 -I/Users/panjing/github/sqlcipher/ext/async -I/Users/panjing/github/sqlcipher/ext/session -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_TEMP_STORE=2 -c sqlite3.c  -fno-common -DPIC -o .libs/sqlite3.o
libtool: compile:  gcc -I/usr/local/opt/openssl/include -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -DSQLITE_OS_UNIX=1 -I. -I/Users/panjing/github/sqlcipher/src -I/Users/panjing/github/sqlcipher/ext/rtree -I/Users/panjing/github/sqlcipher/ext/icu -I/Users/panjing/github/sqlcipher/ext/fts3 -I/Users/panjing/github/sqlcipher/ext/async -I/Users/panjing/github/sqlcipher/ext/session -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DSQLITE_TEMP_STORE=2 -c sqlite3.c -o sqlite3.o >/dev/null 2>&1
./libtool --mode=link gcc -I/usr/local/opt/openssl/include  -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -DSQLITE_OS_UNIX=1 -I. -I/Users/panjing/github/sqlcipher/src -I/Users/panjing/github/sqlcipher/ext/rtree -I/Users/panjing/github/sqlcipher/ext/icu -I/Users/panjing/github/sqlcipher/ext/fts3 -I/Users/panjing/github/sqlcipher/ext/async -I/Users/panjing/github/sqlcipher/ext/session -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG  -DSQLITE_THREADSAFE=1    -lcrypto  -no-undefined -o libsqlcipher.la sqlite3.lo -lcrypto   \
         -rpath "/usr/local/lib" -version-info "8:6:8"
libtool: link: gcc -dynamiclib  -o .libs/libsqlcipher.0.dylib  .libs/sqlite3.o   -lcrypto    -install_name  /usr/local/lib/libsqlcipher.0.dylib -compatibility_version 9 -current_version 9.6 -Wl,-single_module
libtool: link: (cd ".libs" && rm -f "libsqlcipher.dylib" && ln -s "libsqlcipher.0.dylib" "libsqlcipher.dylib")
libtool: link: ar cru .libs/libsqlcipher.a  sqlite3.o
libtool: link: ranlib .libs/libsqlcipher.a
libtool: link: ( cd ".libs" && rm -f "libsqlcipher.la" && ln -s "../libsqlcipher.la" "libsqlcipher.la" )
./libtool --mode=link gcc -I/usr/local/opt/openssl/include  -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -DSQLITE_OS_UNIX=1 -I. -I/Users/panjing/github/sqlcipher/src -I/Users/panjing/github/sqlcipher/ext/rtree -I/Users/panjing/github/sqlcipher/ext/icu -I/Users/panjing/github/sqlcipher/ext/fts3 -I/Users/panjing/github/sqlcipher/ext/async -I/Users/panjing/github/sqlcipher/ext/session -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG  -DSQLITE_THREADSAFE=1    -lcrypto  -DHAVE_READLINE=0  -DHAVE_EDITLINE=1 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION -DSQLITE_ENABLE_STMTVTAB \
        -o sqlcipher /Users/panjing/github/sqlcipher/src/shell.c libsqlcipher.la \
        -ledit  -lcrypto   -rpath "/usr/local/lib"
libtool: link: gcc -I/usr/local/opt/openssl/include -DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -DSQLITE_OS_UNIX=1 -I. -I/Users/panjing/github/sqlcipher/src -I/Users/panjing/github/sqlcipher/ext/rtree -I/Users/panjing/github/sqlcipher/ext/icu -I/Users/panjing/github/sqlcipher/ext/fts3 -I/Users/panjing/github/sqlcipher/ext/async -I/Users/panjing/github/sqlcipher/ext/session -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -DSQLITE_THREADSAFE=1 -DHAVE_READLINE=0 -DHAVE_EDITLINE=1 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION -DSQLITE_ENABLE_STMTVTAB -o .libs/sqlcipher /Users/panjing/github/sqlcipher/src/shell.c  ./.libs/libsqlcipher.dylib -ledit -lcrypto

查看编译结果:

➜  sqlcipher git:(master) ✗ ls
CHANGELOG.md                  config.h.in                   fts5parse.out                 manifest.uuid                 sqlcipher                     sqlite3.lo
LICENSE                       config.log                    fts5parse.y                   mkkeywordhash                 sqlcipher-1.1.8-testkey.db    sqlite3.o
Makefile                      config.status                 install-sh                    mkso.sh                       sqlcipher-2.0-be-testkey.db   sqlite3ext.h
Makefile.in                   config.sub                    keywordhash.h                 mptest                        sqlcipher-2.0-beta-testkey.db sqlite3session.h
Makefile.linux-gcc            configure                     lemon                         opcodes.c                     sqlcipher-2.0-le-testkey.db   src
Makefile.msc                  configure.ac                  lempar.c                      opcodes.h                     sqlcipher-3.0-testkey.db      test
README.md                     contrib                       libsqlcipher.la               parse.c                       sqlcipher.1                   tool
VERSION                       doc                           libtool                       parse.h                       sqlcipher.pc                  tsrc
aclocal.m4                    ext                           ltmain.sh                     parse.h.temp                  sqlcipher.pc.in               vsixtest
art                           fts5.c                        macosx                        parse.out                     sqlcipher.xcodeproj
autoconf                      fts5.h                        magic.txt                     parse.y                       sqlite.pc.in
config.guess                  fts5parse.c                   main.mk                       shell.c                       sqlite3.c
config.h                      fts5parse.h                   manifest                      spec.template                 sqlite3.h

运行:

➜  sqlcipher git:(master) ✗ ./sqlcipher
SQLCipher version 3.20.1 2017-08-24 16:21:36
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .exit
➜  sqlcipher git:(master) ✗ 

安装sqlcipher

sqlcipher git:(master)brew install sqlcipher

破解微信数据库:

➜  Downloads sqlcipher
SQLCipher version 3.20.1 2017-08-24 16:21:36
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open EnMicroMsg.db
sqlite> pragma key='f4d27d4';
sqlite> pragma cipher_use_hmac=off;
sqlite> pragma cipher_page_size=1024;
sqlite> pragma kdf_iter=4000;
sqlite> attach database 'MicroMsg.db' as wc key '';
sqlite> select sqlcipher_export('wc');

sqlite> detach database wc;
sqlite> .quit

参考

https://github.com/sqlcipher/sqlcipher/issues/146

你可能感兴趣的:(数据库,macbook,air)