Micorosoft が、ApplicationInspector という静的解析ツールを公開した記事が流れて来ました。
microsoft/ApplicationInspector: A source code analyzer built for surfacing features of interest and other characteristics to answer the question ‘what’s in it’ using static analysis with a json based rules engine. Ideal for scanning components before use or detecting feature level changes.いうツールで、ApplicationInspector のインストール、実行まで試してみたので手順をまとめます。


前提

  • OS の バージョン
    sw_vers
    ProductName:    Mac OS X
    ProductVersion: 10.14.6
    BuildVersion:   18G2022    
    

インストール、実行

インストール、及び実行方法について説明します。

インストール

Github の Releases ページから、最新版のMac OS X 向けのzip をダウンロードします。
* Releases · microsoft/ApplicationInspector

私がダウンロードした際は、以下のファイルをダウンロードしました。

ApplicationInspector_macos_1.0.24.zip


ダウンロードしたフォルダを移動する

Downloads ディレクトリに落ちてくるので、ツール置き場に移動します。
これは、別に実施しなくても動きます。

mv /Users/xxxxx/Downloads/ApplicationInspector_1.0.24 /Users/xxxxx/Programing/Tools/      


実行

  • ディレクトリ移動
    インストールディレクトリに移動します。

    cd /Users/xxxxx/Programing/Tools/ApplicationInspector_1.0.24/    
    

  • コマンドを実行
    試しに手元にあったJavaのMavenプロジェクトに対して、AppInspectorを実行してみました。

    ./AppInspector analyze -s /Users/xxxxx/Programing/Bitbucket/festivals4partypeople_java/      
    
    ちなみに、srcフォルダではなくpom.xmlのあるプロジェクトルートを指定しています。
    srcフォルダを指定した場合は、エラーにはなりませんでしたが、上手く動きませんでした。
    ツールを実行すると以下のログがコンソールに出力されます。
    Microsoft Application Inspector 1.0.24
    Analyze command running
    8% source files processedDecompressing files...
    100% source files processed
    Preparing report
    Opening default browser to output.html report
    Analyze command completed
    
    完了すると、自動でブラウザが起動し、以下の画面が表示されます。
    2020-01-27 1.35.49.png - Google ドライブ


ApplicationInspector のコマンドの説明

ApplicationInspector/README.md at master · microsoft/ApplicationInspector見る限り、以下のコマンドがありました。

  • Analyze
    ソースコードの解析を実行するコマンドです。

  • Tagdiff
    ソースコードをbefore、after で指定し before、after 間での警告の差分を比較できます。

  • TagTest
    ソースコードに指定したルールの警告が出力されないかチェックできます。
    デフォルトのルールでチェックできるか試してみましたが、カスタムルールを指定しないとエラーになります。

    ./AppInspector tagtest -s /Users/xxxxx/Programing/Bitbucket/festivals4partypeople_java/          
    Microsoft Application Inspector 1.0.24
    No rules specified.  At least one valid rules path required..  Please see log file for more information.
    
    カスタムルールの作り方はHome · microsoft/ApplicationInspector Wiki記載されているのと、デフォルトルールファイルは、ApplicationInspector/AppInspector/rules/default at master · microsoft/ApplicationInspector 配下にjsonファイル格納されているので、それらを参考にすれば作成はできそうに思います。

  • ExportTags
    タグの一覧が出力できるコマンドです。出力されるファイルはルールファイルではありません。
    オプション指定なしで実行すると、デフォルトルールの一覧が出力できます。

    ./AppInspector exporttags 
    Microsoft Application Inspector 1.0.24
    Exporttags command running
    Authentication.General
    Authentication.Google
    Authentication.HTMLForm
    Authentication.JWT
    Authentication.LDAP
    Authentication.Microsoft.Online
    Authentication.Microsoft.Windows.ActiveDirectory
    Authentication.Microsoft.Windows.Kerberos
    Authentication.Microsoft.Windows.NTLM
    Authentication.Oauth
    Authentication.OpenIDConnect
    Authentication.SAML
    Authorization.Claims
    Authorization.General
    Authorization.Microsoft.Azuze.SAS
    Authorization.Permissions
    Authorization.RBAC
    CloudServices.AdvertisingNetwork.Google.Adsense
    CloudServices.AdvertisingNetwork.Microsoft.BingAds
    CloudServices.AdvertisingNetwork.Outbrain
    CloudServices.Application.Microsoft.O365
    CloudServices.Application.Microsoft.Telemetry
    CloudServices.Application.SendGrid.Mail
    CloudServices.BigData.Analytics.DataBricks
    CloudServices.DataStorage.Amazon.S3
    CloudServices.DataStorage.DropBox
    CloudServices.DataStorage.Google.Drive
    CloudServices.DataStorage.MediaFire
    CloudServices.DataStorage.Microsoft.Azure
    CloudServices.DataStorage.Microsoft.AzureKeyVault
    CloudServices.DataStorage.Microsoft.OneDrive
    CloudServices.DataStorage.PasteBin
    CloudServices.Finance.eCommerce
    CloudServices.Hosting.Microsoft.Azure
    CloudServices.SocialMedia.Facebook
    CloudServices.SocialMedia.Instagram
    CloudServices.SocialMedia.Misc
    CloudServices.SocialMedia.Twitter
    CloudServices.SocialMedia.YouTube
    CloudServices.Web.Analytics.Facebook
    CloudServices.Web.Analytics.Google.GTag
    CloudServices.Web.Analytics.Microsoft.Bing
    CloudServices.Web.Analytics.Outbrain
    CloudServices.Web.Analytics.Pinterest
    CloudServices.Web.Analytics.Twitter
    Component.Executable.Adobe.Flash
    Component.Executable.Adobe.PDF
    Component.Executable.Microsoft.ActiveX
    Component.Executable.Microsoft.COM
    Component.Executable.Microsoft.DLL
    Component.Executable.Microsoft.Silverlight
    Cryptography.Cipher.3DES
    Cryptography.Cipher.AES
    Cryptography.Cipher.CipherMode
    Cryptography.Cipher.RC
    Cryptography.Cipher.RSA
    Cryptography.CryptoCurrency
    Cryptography.Encoding.Base64
    Cryptography.Encryption.General
    Cryptography.HashAlgorithm.General
    Cryptography.HashAlgorithm.Legacy
    Cryptography.HashAlgorithm.Misc
    Cryptography.HashAlgorithm.Other
    Cryptography.HashAlgorithm.PBKDF1
    Cryptography.HashAlgorithm.SHA2
    Cryptography.HashAlgorithm.SHA3
    Cryptography.Implementation
    Cryptography.Implementation.MD5
    Cryptography.Implementation.SHA1
    Cryptography.Implementation.SHA256
    Cryptography.KeyDerivation.General
    Cryptography.KeyDerivation.PBKDF1
    Cryptography.KeyDerivation.PBKDF2
    Cryptography.Library.Microsoft.NET
    Cryptography.Library.TLS.BoringSSL
    Cryptography.Library.TLS.BouncyCastle
    Cryptography.Library.TLS.LibreSSL
    Cryptography.Library.TLS.mbedTLS
    Cryptography.Library.TLS.OpenSSL
    Cryptography.Library.Win32
    Cryptography.Protocol.KeyExchange
    Cryptography.Protocol.SSH
    Cryptography.Protocol.TLS
    Cryptography.Protocol.TLS.WeakSSL
    Cryptography.Randomness.PRNG
    Cryptography.Signing.Code
    Cryptography.Signing.Data
    Cryptography.X509Certificates.ClientAuth
    Cryptography.X509Certificates.Create
    Cryptography.X509Certificates.Keyfile
    Cryptography.X509Certificates.Use
    Data.DBMS.Connection.ODBC
    Data.DBMS.General
    Data.DBMS.NoSQL
    Data.DBMS.ORM.Django
    Data.DBMS.ORM.SQLAlchemy
    Data.DBMS.PostgreSQL
    Data.DBMS.SQL
    Data.DBMS.SQL.ADO
    Data.DBMS.SQL.Oracle
    Data.DBMS.SQLite
    Data.Deserialization
    Data.Deserialization.Signal.Bluetooth
    Data.Deserialization.Signal.Cellular
    Data.Deserialization.Signal.Ethernet
    Data.Deserialization.Signal.Modem
    Data.Deserialization.Signal.USB
    Data.Media.Audio
    Data.Media.Video
    Data.Parsing.JSON
    Data.Parsing.Media
    Data.Parsing.XML
    Data.Parsing.XSLT
    Data.Sensitive.Credentials
    Data.Sensitive.Financial.BankAccount
    Data.Sensitive.Financial.CreditCard
    Data.Sensitive.Financial.Currency
    Data.Sensitive.Financial.General
    Data.Sensitive.Financial.Payroll
    Data.Sensitive.Financial.Salesdata
    Data.Sensitive.Identification
    Data.Sensitive.Medical
    Data.Sensitive.ProductKey
    Data.Sensitive.Secret
    Data.Sensitive.UserAccount
    Data.Serialization
    Data.Zipfile
    Dependency.SourceInclude
    Framework.CMS.Drupal
    Framework.CMS.Joomla
    Framework.CMS.Sharepoint
    Framework.CMS.Wordpress
    Framework.Development.AngularJS
    Framework.Development.ApacheStruts
    Framework.Development.ApacheTapestry
    Framework.Development.Aurelia
    Framework.Development.Backbone
    Framework.Development.Blade
    Framework.Development.Bottle
    Framework.Development.CherryPy
    Framework.Development.CubicWeb
    Framework.Development.Django
    Framework.Development.DropWizard
    Framework.Development.EmberJS
    Framework.Development.Flask
    Framework.Development.Giotto
    Framework.Development.Google.API
    Framework.Development.Grails
    Framework.Development.GWT
    Framework.Development.Hibernate
    Framework.Development.JHipster
    Framework.Development.jQuery
    Framework.Development.JSF
    Framework.Development.Library.Boost
    Framework.Development.Library.StandardC
    Framework.Development.Logging.Log4j
    Framework.Development.Logging.Log4Net
    Framework.Development.Logging.NLog
    Framework.Development.Logging.Serilog
    Framework.Development.Logging.ULog
    Framework.Development.Logging.Winston
    Framework.Development.Meteor
    Framework.Development.Microsoft.ADO
    Framework.Development.Microsoft.Azure
    Framework.Development.Microsoft.COM
    Framework.Development.Microsoft.Linq
    Framework.Development.Microsoft.MFC
    Framework.Development.Microsoft.Mono
    Framework.Development.Microsoft.NET.ASP
    Framework.Development.Microsoft.NETCore
    Framework.Development.Microsoft.NETStandard
    Framework.Development.Microsoft.Server.Dynamics
    Framework.Development.Microsoft.Server.Exchange
    Framework.Development.Microsoft.Server.IIS
    Framework.Development.Microsoft.WCF
    Framework.Development.Microsoft.WindowsSDK
    Framework.Development.Mithril
    Framework.Development.MyBatis
    Framework.Development.OWL
    Framework.Development.PHP
    Framework.Development.PlayFramework
    Framework.Development.Polymer
    Framework.Development.PrimeFaces
    Framework.Development.Pryamid
    Framework.Development.Pylons
    Framework.Development.Rails
    Framework.Development.RDF
    Framework.Development.React
    Framework.Development.Redux
    Framework.Development.Redux-Saga
    Framework.Development.RITEWay
    Framework.Development.RQL
    Framework.Development.Sanic
    Framework.Development.Spark
    Framework.Development.Spring
    Framework.Development.Tornado
    Framework.Development.TurboGears
    Framework.Development.Vaadin
    Framework.Development.Vertx
    Framework.Development.Vue
    Framework.Development.Web2Py
    Framework.Development.Wicket
    Framework.Testing.AceUnit
    Framework.Testing.Andit
    Framework.Testing.Arquillian
    Framework.Testing.Artos
    Framework.Testing.AssertJ
    Framework.Testing.AutoTest
    Framework.Testing.Autounit
    Framework.Testing.Ava
    Framework.Testing.Bacon
    Framework.Testing.BeanSpec
    Framework.Testing.BeanTest
    Framework.Testing.Boost
    Framework.Testing.BugEye
    Framework.Testing.BusterJS
    Framework.Testing.Cactus
    Framework.Testing.Catch
    Framework.Testing.Catch2
    Framework.Testing.Catsrunner
    Framework.Testing.Cedar
    Framework.Testing.Cfix
    Framework.Testing.Cgreen
    Framework.Testing.Chai
    Framework.Testing.Concordion
    Framework.Testing.Concutest
    Framework.Testing.Crosscheck
    Framework.Testing.Cucumber
    Framework.Testing.Cuppa
    Framework.Testing.DbUnit
    Framework.Testing.Doctest
    Framework.Testing.DOH
    Framework.Testing.EasyMock
    Framework.Testing.EnhanceJS
    Framework.Testing.Eryn
    Framework.Testing.EtlUnit
    Framework.Testing.EvoSuite
    Framework.Testing.fast-check
    Framework.Testing.FireUnit
    Framework.Testing.GHUnit
    Framework.Testing.Gmock
    Framework.Testing.GrandTestAuto
    Framework.Testing.GroboUtils
    Framework.Testing.HavaRunner
    Framework.Testing.Instinct
    Framework.Testing.Intern
    Framework.Testing.J3Unit
    Framework.Testing.Jasmine
    Framework.Testing.JasUnit
    Framework.Testing.JBehave
    Framework.Testing.JDave
    Framework.Testing.Jest
    Framework.Testing.JExample
    Framework.Testing.JGiven
    Framework.Testing.JMock
    Framework.Testing.JMockit
    Framework.Testing.Jnario
    Framework.Testing.Js-test-runner
    Framework.Testing.JSNUnit
    Framework.Testing.JSpec
    Framework.Testing.JSSpec
    Framework.Testing.JSST
    Framework.Testing.JSTest
    Framework.Testing.JSTestDriver
    Framework.Testing.JSUnit
    Framework.Testing.jsUnitTest
    Framework.Testing.jsUnity
    Framework.Testing.JSUS
    Framework.Testing.Jtest
    Framework.Testing.Jukito
    Framework.Testing.JUnit
    Framework.Testing.JUnitEE
    Framework.Testing.JWalk
    Framework.Testing.Kiwi
    Framework.Testing.Lighttest
    Framework.Testing.Microtest
    Framework.Testing.Minitest
    Framework.Testing.Mocha
    Framework.Testing.Mockito
    Framework.Testing.Mockrunner
    Framework.Testing.Needle
    Framework.Testing.Nodeunit
    Framework.Testing.Nose
    Framework.Testing.NUTester
    Framework.Testing.ObjcUnit
    Framework.Testing.OCUnit
    Framework.Testing.OpenPojo
    Framework.Testing.Pester
    Framework.Testing.PowerMock
    Framework.Testing.PyTest
    Framework.Testing.quick
    Framework.Testing.QUnit
    Framework.Testing.Randoop
    Framework.Testing.RhinoUnit
    Framework.Testing.RhUnit
    Framework.Testing.RSpec
    Framework.Testing.screw-unit
    Framework.Testing.Shoulda
    Framework.Testing.ShouldDSL
    Framework.Testing.SinonJS
    Framework.Testing.SOAtest
    Framework.Testing.Specta
    Framework.Testing.Spock
    Framework.Testing.SpryTest
    Framework.Testing.SureAssert
    Framework.Testing.Tacinga
    Framework.Testing.Tape
    Framework.Testing.Teenytest
    Framework.Testing.Test.Simple
    Framework.Testing.TestCase
    Framework.Testing.testdouble.js
    Framework.Testing.TestIt
    Framework.Testing.TestNG
    Framework.Testing.TestUnit
    Framework.Testing.TMF
    Framework.Testing.Tyrtle
    Framework.Testing.Unitils
    Framework.Testing.UnitJS
    Framework.Testing.unittest
    Framework.Testing.UnitTesting
    Framework.Testing.Vows
    Framework.Testing.WallabyJS
    Framework.Testing.WOTest
    Framework.Testing.wru
    Framework.Testing.XCTest
    Framework.Testing.XMLUnit
    Framework.Testing.XPyUnit
    Framework.Testing.YUITest
    Hardware.Accessory.Microsoft.Kinex
    Hardware.ReferenceDesign
    Metadata.Application.Author
    Metadata.Application.Container.CRI-O
    Metadata.Application.Container.Docker
    Metadata.Application.Container.Kubernetes
    Metadata.Application.Container.Microsoft.Core
    Metadata.Application.Container.Microsoft.Hyper-V
    Metadata.Application.Container.rktlet
    Metadata.Application.Description
    Metadata.Application.Name
    Metadata.Application.Output.Type
    Metadata.Application.Publisher
    Metadata.Application.Target.Framework
    Metadata.Application.Target.Processor
    Metadata.Application.Type.Client.Service.Windows
    Metadata.Application.Type.Client.Windows
    Metadata.Application.Type.Client.Winforms
    Metadata.Application.Type.Web.Application
    Metadata.Application.Type.Web.Service
    Metadata.Application.Version
    Metadata.CloudServices.Code.CI.CircleCI
    Metadata.CloudServices.Code.CI.Microsoft.Azure
    Metadata.CloudServices.Code.CI.TravisCI
    Metadata.CloudServices.Code.Repo.BitBucket
    Metadata.CloudServices.Code.Repo.GitHub
    Metadata.CloudServices.Code.Repo.GitLab
    Metadata.CloudServices.Code.Repo.LaunchPad
    Metadata.CloudServices.Code.Repo.Microsoft.NuGet
    Metadata.CloudServices.Code.Repo.NPM
    Metadata.CloudServices.Code.Repo.PyPI
    Metadata.CloudServices.Code.Repo.Savannah
    Metadata.CloudServices.Code.Repo.SourceForge
    Metadata.CloudServices.Code.Repo.VisualStudio
    Metadata.CloudServices.Hosting.Amazon.AWS
    Metadata.CloudServices.Hosting.Apple.iCloud
    Metadata.CloudServices.Hosting.DigitalOcean
    Metadata.CloudServices.Hosting.Google
    Metadata.CloudServices.Hosting.Microsoft.AppStore
    Metadata.CloudServices.Hosting.Microsoft.Azure
    Metadata.Development.Build.Ant
    Metadata.Development.Build.Bamboo
    Metadata.Development.Build.Gradle
    Metadata.Development.Build.Grape
    Metadata.Development.Build.Ivy
    Metadata.Development.Build.Jenkins
    Metadata.Development.Build.Leiningen
    Metadata.Development.Build.Maven
    Metadata.Development.Build.SBT
    Metadata.Development.Build.TeamCity
    Metadata.Development.Build.VisualStudio
    Metadata.OS.ACL.Write.Unsafe
    Metadata.Platform.Device.IOT
    Metadata.Platform.Device.Mobile
    Metadata.Platform.Microsoft.Mono
    Metadata.Platform.Microsoft.NETCore
    Metadata.Platform.Microsoft.NETStandard
    Metadata.Platform.OS.Apple.iOS
    Metadata.Platform.OS.Apple.MacOS
    Metadata.Platform.OS.Google.Android
    Metadata.Platform.OS.Linux.Distro
    Metadata.Platform.OS.Microsoft.WindowsCE
    Metadata.Platform.OS.Microsoft.WindowsServer
    Metadata.Platform.OS.Microsoft.WindowsStandard
    Metadata.Platform.OS.Microsoft.WindowsUniversalPlatform
    Metadata.Platform.OS.Microsoft.XBox
    Metric.Code.Class.Defined
    Metric.Code.Exception.Caught
    Metric.Code.Function.Defined
    Metric.Code.HTMLForm.Defined
    Metric.Code.Logging.Call
    Metric.Code.SampleCode
    Metric.Code.URL
    Miscellaneous.CodeHygiene.Comment.Fix
    Miscellaneous.CodeHygiene.Comment.Suspicious
    Miscellaneous.CodeHygiene.Comment.Todo
    Miscellaneous.OpenSourceLicense.Apache
    Miscellaneous.OpenSourceLicense.BSD
    Miscellaneous.OpenSourceLicense.CreativeCommons
    Miscellaneous.OpenSourceLicense.Eclipse
    Miscellaneous.OpenSourceLicense.GPL
    Miscellaneous.OpenSourceLicense.LGPL
    Miscellaneous.OpenSourceLicense.Microsoft
    Miscellaneous.OpenSourceLicense.MIT
    Miscellaneous.OpenSourceLicense.Mozilla
    OS.ACL.Impersonation
    OS.ACL.TokenImpersonation
    OS.ACL.Write
    OS.ACL.Write.AppContainer
    OS.ACL.Write.Audit
    OS.ACL.Write.FileSecurity
    OS.ACL.Write.General
    OS.ACL.Write.SystemToken.
    OS.Environment.Windows.RegistryLocation
    OS.Environment.Write
    OS.FileOperation.Delete
    OS.FileOperation.Read
    OS.FileOperation.Write
    OS.Network.Connection.Cellular
    OS.Network.Connection.General
    OS.Network.Connection.Http
    OS.Network.Connection.Http.Ajax
    OS.Network.Connection.Miscellaneous
    OS.Network.Connection.Modem
    OS.Network.Connection.RPC
    OS.Network.Connection.Socket
    OS.Network.Connection.Tcp
    OS.Process.DynamicExecution
    OS.Process.ListRequest
    OS.Process.Multiprocessing
    OS.SystemRegistry.ACL
    OS.SystemRegistry.Read
    OS.SystemRegistry.Write
    OS.UserAccount.Write
    Exporttags command completed
    

  • Verify
    ルールの妥当性を検証するコマンドです。


ApplicationInspectorの使用用途について

少し触ってみて、ApplicationInspector の以下のような使用用途があると考えました。

  • ソースコードリーディングを始める前に実行して概要を掴む
    Githubからライブラリ、アプリケーションのソースコードをダウンロードして、ApplicationInspector を実行、出力される Tags List を見ることで、ライブラリがどのような機能を使っているのか概要が掴めそうに思いました。手元のJavaプロジェクトは、Dropwizard を使っていますが、以下のようなTag が出力されていました。

    Framework.Development.DropWizard     
    
    ApplicationInspector/java.json at master · microsoft/ApplicationInspectorJava のフレームワークのルールファイルがありますが、メジャーどころはだいたい検出してくれるようです。

  • ソースコードレビュー前に実行して、問題が多そうな部分を特定する
    ソースコードレビューの物量が膨大だとどこにパワーを使うかで迷います。
    Confidence High且つ、Importance Critical出力された箇所を重点的に見るのが良いかと思います。
    SonarQube、PMD、Findbugs 等との違いは、SonarQube、PMD、Findbugs が厳密にソースコードの良くない箇所を検知するのに対して、ApplicationInspectorはもっと大雑把に、問題があるかもしれない部分を検知してくれます。
    チェックの順番としては、SonarQube、PMD、Findbugs のチェックを突破したプログラムに対して、ApplicationInspector を実行するのが良さそうです。

  • ライブラリの責務違反を検知する
    TagTest を CI に組み込んでカスタムルールを定義することで、ライブラリの責務に反する処理が追加された場合、ビルドを失敗させることができるかと思います。

ApplicationInspectorの使い方について書きました。
現状、ブラウザが起動してしまうので、Analyzeコマンドのレポート自体をCIには組み込むのは現状難しそうです。
オプションが追加されたら、試してみようかと思います。

以上です。

コメント