当前位置:   article > 正文

mac book air 编译sqlcipher_/opt/local/lib/libcrypto.a

/opt/local/lib/libcrypto.a

编译SQLCipher

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

错误:

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 0x02. 编译成动态库

第一步顺利通过

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

第二步出错:

$ make
  • 1

错误信息:

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

重新安装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
➜  ~ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61

根据提示执行:

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

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

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

error:

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

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

➜  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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

解决办法:

➜  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"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

编译:

➜  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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

查看编译结果:

➜  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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

运行:

➜  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) ✗ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

安装sqlcipher

sqlcipher git:(master)brew install sqlcipher
  • 1

破解微信数据库:

➜  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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

参考

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/492406
推荐阅读
相关标签
  

闽ICP备14008679号