├── .gitignore ├── LICENSE.md ├── README.md ├── build_static_sqlite.sh ├── docker ├── .dockerignore ├── Build.sh └── Dockerfile └── src ├── README.md └── extensions └── rot47.c /.gitignore: -------------------------------------------------------------------------------- 1 | release/ 2 | dist/ 3 | misc/ 4 | temp/ 5 | .ssh/ 6 | .git 7 | .idea 8 | .vscode 9 | .aws 10 | .env 11 | *.pem 12 | *.key 13 | *.log 14 | *.lock 15 | *.tmp 16 | commit.sh 17 | authorized_keys 18 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | BSD 0-Clause License 2 | 3 | Copyright © CompuRoot. 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 14 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ``` 2 | ____ ___ _ _ _ _____ 3 | / ___| / _ \ | | (_) | |_ ___ |___ / 4 | \___ \ | | | | | | | | | __| / _ \ |_ \ 5 | ___) | | |_| | | |___ | | | |_ | __/ ___) | 6 | |____/ \__\_\ |_____| |_| \__| \___| |____/ 7 | 8 | ``` 9 | # static-sqlite3 10 | 11 | Compile a statically linked `sqlite3` for amd64 platforms due to absence of statically compiled `sqlite3` program for x86_64 Linux platforms on official site. 12 | 13 | ## Compilation Requirements 14 | Docker required (using official Linux distribution of alpine:latest) 15 | 16 | ## Running Requirements 17 | 18 | - Linux 19 | - compatible with classic `sh` shells, such as bash,dash,ash,etc 20 | 21 | - Optional: 22 | - OpenSSH 8.0+ (to use `ssh-keygen` to verify compiled files in [release][1] section) 23 | - `git` (to pull conveniently this repository) 24 | - `gpg` (to verify signed tar.gz and zip archives) 25 | 26 | ## Compiling 27 | 28 | ```bash 29 | git clone https://github.com/CompuRoot/static-sqlite3.git 30 | cd static-sqlite3 31 | ./build_static_sqlite.sh 32 | ``` 33 | Compiled file will be placed in your local `release` directory. 34 | 35 | ## Pre-compiled binary 36 | 37 | You can also download already compiled, `sqlite3` program from [releases][1].
38 | To check integrity and authenticity of pre-compiled program, - download both, `sqlite3` and its signature `sqlite3.sig`, 39 | and run following command in a download directory: 40 | ``` 41 | /dev/null 2>&1 33 | [ $? -ne 0 ] && { 34 | errMsg="$(printf '\n You are not authorized to run docker,')" 35 | errMsg="${errMsg}$(printf '\n try to "su -" into root account and try again.\n\n')" 36 | onErr "${errMsg}" 3 37 | } 38 | 39 | 40 | 41 | cd ./docker 42 | 43 | $SUDO $DOCKER build --rm --no-cache=true -t "${DockerImage}" . \ 44 | --build-arg URL_SQLITE_SOURCE_ZIP="${SQLITE_ZIP_URL}" \ 45 | --build-arg COMPRESS_SQLITE3="${SQLite_compressor}" 46 | cd .. 47 | 48 | printf "\n\n===== Taking ready to use static sqlite3 =======================================\n\n" 49 | 50 | arch="${SQLITE_ZIP_URL##*/}" 51 | workdir="${arch%.*}" 52 | 53 | [ ! -d release ] && mkdir release 54 | 55 | $SUDO $DOCKER run --rm -v $(pwd)/release:/release/ \ 56 | -it "${DockerImage}" \ 57 | cp -fv /app/${workdir}/sqlite3 /release/ 58 | 59 | cd release 60 | echo "==============================" 61 | ldd sqlite3 62 | echo "------------------------------" 63 | file sqlite3 64 | echo "------------------------------" 65 | echo '.version' | ./sqlite3 66 | echo "==============================" 67 | 68 | cd .. 69 | 70 | # Cleanup the built image 71 | $SUDO $DOCKER image rm "${DockerImage}" >/dev/null 2>&1 72 | 73 | -------------------------------------------------------------------------------- /docker/.dockerignore: -------------------------------------------------------------------------------- 1 | .ssh/ 2 | .git 3 | .idea 4 | .vscode 5 | .aws 6 | .env 7 | travis.yml 8 | *.pem 9 | *.key 10 | authorized_keys 11 | Dockerfile* 12 | docker-compose* 13 | README.md 14 | LICENSE 15 | config.json 16 | prerequisite.txt 17 | -------------------------------------------------------------------------------- /docker/Build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | src="${1}" # SQLITE_URL_SRC 4 | arch="${src##*/}" 5 | workdir="${arch%.*}" 6 | 7 | 8 | if [ ! -f "${arch}" ]; then 9 | wget -c "${src}" 10 | [ $? -ne 0 ] && { 11 | echo "===== FAILED ....... ===========================================================" 12 | printf "Can not download: %s\n\n" "${src}" 13 | exit 1 14 | } 15 | fi 16 | 17 | [ ! -f "${workdir}/sqlite3.c" ] && unzip ${arch} || exit 1 18 | 19 | cd "${workdir}" 20 | 21 | printf "\n\n===== Compiling... Please wait... ==============================================\n\n" 22 | 23 | gcc -O2 \ 24 | -DHAVE_USLEEP \ 25 | -DSQLITE_DQS=0 \ 26 | -DHAVE_READLINE \ 27 | -DSQLITE_USE_ALLOCA \ 28 | -DSQLITE_THREADSAFE=0 \ 29 | -DSQLITE_ENABLE_FTS4 \ 30 | -DSQLITE_ENABLE_FTS5 \ 31 | -DSQLITE_ENABLE_JSON1 \ 32 | -DSQLITE_ENABLE_RTREE \ 33 | -DSQLITE_ENABLE_GEOPOLY \ 34 | -DSQLITE_OMIT_DECLTYPE \ 35 | -DSQLITE_OMIT_DEPRECATED \ 36 | -DSQLITE_OMIT_SHARED_CACHE \ 37 | -DSQLITE_OMIT_LOAD_EXTENSION \ 38 | -DSQLITE_OMIT_PROGRESS_CALLBACK \ 39 | -DSQLITE_LIKE_DOESNT_MATCH_BLOBS \ 40 | -DSQLITE_ENABLE_EXPLAIN_COMMENTS \ 41 | -DSQLITE_ENABLE_MATH_FUNCTIONS \ 42 | shell.c sqlite3.c \ 43 | -static -lm \ 44 | -lreadline \ 45 | -lncursesw -o sqlite3 # On apline use ncursesw instead of ncurses (!!!) 46 | 47 | rc=$? 48 | if [ $rc -eq 0 ]; then 49 | cp -av sqlite3 sqlite3_orig # Keep naked, unstripped, unpacked version 50 | echo "===== Stripping sqlite3 ... ====================================================" 51 | strip --strip-unneeded sqlite3 52 | if [ -n "${2}" ]; then # $2 = name of compressor 53 | echo "===== Compressing... ===========================================================" 54 | $2 sqlite3 55 | fi 56 | else 57 | echo "================================ FAILED to compile =============================" 58 | exit 1 59 | fi 60 | 61 | echo "===================================== Done =====================================" 62 | 63 | exit 0 64 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | 3 | LABEL org.sqlite.static.binary.linux.x86_64.dockerfile.version="1.0.6" 4 | 5 | ARG URL_SQLITE_SOURCE_ZIP 6 | ARG COMPRESS_SQLITE3 7 | 8 | # Version of SQLite to download (full url to sqlite-amalgamation.zip) 9 | ENV SQLITE_URL_SRC="${URL_SQLITE_SOURCE_ZIP}" 10 | ENV COMPRESSOR="${COMPRESS_SQLITE3}" 11 | 12 | RUN echo >> /etc/apk/repositories && \ 13 | echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" \ 14 | >> /etc/apk/repositories && \ 15 | apk update && apk upgrade && \ 16 | apk add --no-cache fakeroot musl-dev linux-headers gcc libgcc ccache \ 17 | binutils upx file wget unzip zlib-dev zlib-static \ 18 | libhistory readline-static readline-dev \ 19 | ncurses-static ncurses-dev 20 | 21 | WORKDIR /app 22 | 23 | COPY Build.sh /app/ 24 | RUN chmod +x /app/Build.sh && ./Build.sh "${SQLITE_URL_SRC}" "${COMPRESSOR}" 25 | 26 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # Custom modification(s) and additions to SQLite 2 | 3 | This directory containing source codes related to `SQLite` and its 4 | extensions. 5 | -------------------------------------------------------------------------------- /src/extensions/rot47.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2021-12-05 3 | ** 4 | ** Copyright (C) 2021 by CompuRoot 5 | ** 6 | ** Permission to use, copy, modify, and/or distribute this software for any 7 | ** purpose with or without fee is hereby granted. 8 | ** 9 | ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | ** WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | ** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ** ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | ** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 15 | ** OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE 16 | ** 17 | ****************************************************************************** 18 | ** 19 | ** This SQLite extension implements a rot47() function and a rot47 20 | ** collating sequence. 21 | */ 22 | #include "sqlite3ext.h" 23 | 24 | SQLITE_EXTENSION_INIT1 25 | #include 26 | #include 27 | 28 | /* 29 | ** Perform rot47 monoalphabetic substitution on a single ASCII character. 30 | ** Encode all visible English ASCII 94 characters set in range 31 | ** ASCII DEC 33 to ASCII DEC 126 (regex [!-~]) using substitution cipher, 32 | ** similar to Caesar's cipher, that's why named as rot47 (94/2=47). 33 | ** Algorithm can be explained by modular arithmetic as: 33+((ASCII_char+14)%94) 34 | ** where ASCII_char is a single byte in range: 33-126 35 | ** Implementation don't use 33+((ASCII_char+14)%94) formula but faster analog. 36 | ** 37 | ** Most of the code is taken from official sqlite3 extension repository from 38 | ** ext/misc/rot13.c source file. The only rot47 function written from scratch. 39 | ** 40 | ** Lookup table for rot47: 41 | ** !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 42 | ** PQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO 43 | ** 44 | */ 45 | static unsigned char rot47(unsigned char c){ 46 | if(c>='!' && c<='O'){ 47 | c += 47; 48 | }else if(c>='P' && c<='~'){ 49 | c -= 47; 50 | } 51 | return c; 52 | } 53 | 54 | /* 55 | ** Implementation of the rot47() function. 56 | ** 57 | ** Rotate ASCII alphabetic characters by 47 character positions. 58 | ** Non-ASCII characters are unchanged. rot47(rot47(X)) should always 59 | ** equal X. 60 | */ 61 | static void rot47func( 62 | sqlite3_context *context, 63 | int argc, 64 | sqlite3_value **argv 65 | ){ 66 | const unsigned char *zIn; 67 | int nIn; 68 | unsigned char *zOut; 69 | unsigned char *zToFree = 0; 70 | int i; 71 | unsigned char zTemp[127]; 72 | assert( argc==1 ); 73 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; 74 | zIn = (const unsigned char*)sqlite3_value_text(argv[0]); 75 | nIn = sqlite3_value_bytes(argv[0]); 76 | if( nIn