CodeQL CLI是一個(gè)命令行工具,用于在開(kāi)源軟件項(xiàng)目上本地運(yùn)行CodeQL進(jìn)程??梢允褂肅LI做:運(yùn)行CodeQL分析、創(chuàng)造CodeQL數(shù)據(jù)庫(kù)、開(kāi)發(fā)和測(cè)試自定義CodeQL查詢(xún)。
CodeQL CLI安裝
1. 下載
下載CodeQL CLI zip壓縮包,這個(gè)CodeQL CLI 包 是一個(gè) zip 包, 包含scripts, 各種文件。
如果系統(tǒng)是linux、windows、macOS10.14("Mojave")或者更早的版本,下載地址
download the zip archive 。
2.創(chuàng)造工作目錄
創(chuàng)建一個(gè)新目錄,您可以在其中放置CLI和您想要使用的任何查詢(xún)和庫(kù)。例如,$HOME/codeql-home
cd project
mkdir codeql-home
3. 拉取CodeQL queries到工作目錄
第一種方式:
在上面創(chuàng)建的codeql-home目錄下,從github上拉取codeql庫(kù)并重新命名為codeql-repo。命令如下
git clone git@github.com:github/codeql.git codeql-repo。
第二種方式:
如果git clone的網(wǎng)絡(luò)不好的話(huà),也可以自己下載下來(lái)后把zip包放到codeql-home目錄下,然后重新命名codeql文件為codeql-repo。即mv codeql codeql-repo 。
注釋?zhuān)阂驗(yàn)閏odeql和codeql-cli解壓后的文件名稱(chēng)都是codeql,為了后續(xù)有沖突,所以把codeql庫(kù)拉下來(lái)后重新命名為codeql-repo。
4. Extract the zip archive
把Code CLI包解壓后放入codeql-home目錄下。解壓后可以看到文件名稱(chēng)為codeql。所以要知道這里的codeql是指codeql-cli。后續(xù)的codeql,都是指codeql-cli。
5. 配置 codeql(即指配置codeql-cli工具)
添加<extraction-root>/codeql 到 PATH環(huán)境, 添加完成后就可以執(zhí)行codeql命令.步驟如下:
筆者此處的<extraction-root>路徑為/Users/codeql-home
5.1 編輯
vi ~/.profile #打開(kāi)文件.profile
export PATH=$PATH:/Users/codeql-home/codeql #追加這行命令,記得/Users/codeql-home這個(gè)路徑換成自己的目錄
5.2 生效
退出編輯,執(zhí)行:
source ~/.profile #生效上面添加的編輯內(nèi)容
5.3 驗(yàn)證
在終端,執(zhí)行codeql命令,可以看到下面的內(nèi)容,就說(shuō)明PATH配置成功。
Usage: codeql <command> <argument>...
Create and query CodeQL databases, or work with the QL language.
GitHub makes this program freely available for the analysis of open-source
software and certain other uses, but it is not itself free software. Type
codeql --license to see the license terms.
--license Show the license terms for the CodeQL toolchain.
Common options:
-h, --help Show this help text.
-v, --verbose Incrementally increase the number of progress
messages printed.
-q, --quiet Incrementally decrease the number of progress
messages printed.
Some advanced options have been hidden; try --help -v for a fuller view.
Commands:
query Compile and execute QL code.
bqrs Get information from .bqrs files.
database Create, analyze and process CodeQL databases.
6. codeql命令
codeql resolve languages #顯示數(shù)據(jù)庫(kù)支持哪些語(yǔ)言
codeql resolve qlpacks #顯示CLI可以找到哪些QL packs