dhscanner-bitcode 2.4.0 → 2.5.0
raw patch · 2 files changed
+212/−211 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Fqn: ReturnTypeOf :: Location -> Fqn -> Fqn
Files
- dhscanner-bitcode.cabal +82/−82
- src/Fqn.hs +130/−129
dhscanner-bitcode.cabal view
@@ -1,82 +1,82 @@-cabal-version: 3.12 -name: dhscanner-bitcode -category: sast -synopsis: Intermediate language for static code analysis -description: - - The [intermediate language \/ intermediate representation \/ bitcode](https://en.wikipedia.org/wiki/Intermediate_representation#Intermediate_language) - (IL \/ IR \/ bitcode) is a data structure able to represent code originating from /multiple/ - programming languages. Its main purpose is to enable an efficient and uniform /static code analysis/, - as part of the [dhscanner](https://github.com/OrenGitHub/dhscanner) framework - for [CI/CD](https://en.wikipedia.org/wiki/CI/CD) container security checks. - As part of that framework, it targets mostly languages used for /cloud native applications/: - __Python__, __Ruby__, __Php__, __Javascript__, __Typescript__, __Java__, __C#__ and __Golang__. - Typically, a collection of files are first parsed using relevant - [parsers](https://github.com/OrenGitHub/dhscanner.1.parsers), then, - the resulting collection of abstract syntax trees is sent to code generation, - where it is translated into a collection of /callables/. - A callable is a sequence of commands corresponding to either a function, a method - or (in languages like python) a script. The design of commands was done with simplicity - in mind. The commands resemble an abstract RISC-style assembley, motivated by keeping - later-phases analyses as simple as possible. - -version: 2.4.0 -license: GPL-3.0-only -license-file: LICENSE -author: OrenGitHub -maintainer: Oren Ish Shalom -copyright: (c) 2024 Oren Ish Shalom -homepage: https://github.com/OrenGitHub/dhscanner -stability: experimental -build-type: Simple - -common ghc_options - ghc-options: -Wall -Werror=incomplete-patterns -O2 - -library - - import: - ghc_options - - exposed-modules: - Bitcode, - Callable, - Cfg, - Fqn - - build-depends: - aeson >= 2.2 && < 2.4, - base >= 4.22 && < 4.23, - containers >= 0.8 && < 0.9, - dhscanner-ast >= 1.6.0 - - hs-source-dirs: - src - - default-language: - GHC2024 - -test-suite dhscanner-bitcode-test - - import: - ghc_options - - type: - exitcode-stdio-1.0 - - hs-source-dirs: - test - - main-is: - Main.hs - - build-depends: - base, - dhscanner-ast, - dhscanner-bitcode, - containers, - QuickCheck, - random - - default-language: - GHC2024 +cabal-version: 3.12+name: dhscanner-bitcode+category: sast+synopsis: Intermediate language for static code analysis+description:++ The [intermediate language \/ intermediate representation \/ bitcode](https://en.wikipedia.org/wiki/Intermediate_representation#Intermediate_language)+ (IL \/ IR \/ bitcode) is a data structure able to represent code originating from /multiple/+ programming languages. Its main purpose is to enable an efficient and uniform /static code analysis/,+ as part of the [dhscanner](https://github.com/OrenGitHub/dhscanner) framework+ for [CI/CD](https://en.wikipedia.org/wiki/CI/CD) container security checks.+ As part of that framework, it targets mostly languages used for /cloud native applications/:+ __Python__, __Ruby__, __Php__, __Javascript__, __Typescript__, __Java__, __C#__ and __Golang__.+ Typically, a collection of files are first parsed using relevant+ [parsers](https://github.com/OrenGitHub/dhscanner.1.parsers), then,+ the resulting collection of abstract syntax trees is sent to code generation,+ where it is translated into a collection of /callables/.+ A callable is a sequence of commands corresponding to either a function, a method+ or (in languages like python) a script. The design of commands was done with simplicity+ in mind. The commands resemble an abstract RISC-style assembley, motivated by keeping+ later-phases analyses as simple as possible.++version: 2.5.0+license: GPL-3.0-only+license-file: LICENSE+author: OrenGitHub+maintainer: Oren Ish Shalom+copyright: (c) 2024 Oren Ish Shalom+homepage: https://github.com/OrenGitHub/dhscanner+stability: experimental+build-type: Simple++common ghc_options+ ghc-options: -Wall -Werror=incomplete-patterns -O2++library++ import:+ ghc_options++ exposed-modules:+ Bitcode,+ Callable,+ Cfg,+ Fqn++ build-depends:+ aeson >= 2.2 && < 2.4,+ base >= 4.22 && < 4.23,+ containers >= 0.8 && < 0.9,+ dhscanner-ast >= 1.6.0++ hs-source-dirs:+ src++ default-language:+ GHC2024++test-suite dhscanner-bitcode-test++ import:+ ghc_options++ type:+ exitcode-stdio-1.0++ hs-source-dirs:+ test++ main-is:+ Main.hs++ build-depends:+ base,+ dhscanner-ast,+ dhscanner-bitcode,+ containers,+ QuickCheck,+ random++ default-language:+ GHC2024
src/Fqn.hs view
@@ -1,129 +1,130 @@-{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE OverloadedStrings #-} - -module Fqn - -where - --- project imports -import Location -import qualified Token - --- general imports -import Data.Aeson -import GHC.Generics - --- | --- --- * Fully qualified name --- * Resolution at the /file/ level --- * Unidirectional resolution only ( one pass ) --- -data Fqn - = NativeTypeInt - | NativeTypeString - | NativeTypeBool - | NativeTypeNull - | NativeTypeConstInt Int - | NativeTypeConstStr String - | NativeTypeConstBool Bool - | ClassName ClassNameContent - | ClassInstance ClassInstanceContent - | FieldedAccess Fqn Token.FieldName - | CallMethodOfClass Location String Token.ClassName - | CallMethodOfUntypedNamedParam Location String Token.ParamName - | CallFuncFromImportedDir Location String FilePath - | CallFuncFromImportedFile Location String FilePath - | FirstPartyImport FirstPartyImportContent - | FirstPartyDirImport FirstPartyDirImportContent - | ThirdPartyImport ThirdPartyImportContent - | Unknown - deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON ) - -data FirstPartyImportContent - = FirstPartyImportContent - { - firstPartyImportedLocation :: FilePath, - firstPartyImportedName :: Maybe String - } - deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON ) - -data FirstPartyDirImportContent - = FirstPartyDirImportContent - { - firstPartyDirImportLocation :: FilePath, - firstPartyDirImportAlias :: Maybe String - } - deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON ) - --- | --- --- ==== __Examples:__ --- --- * Entire third party package import --- --- @ --- # thirdPartyImportedPackageName == "urllib3" --- # thirdPartyImportedPartsFromPackage == [] --- # thirdPartyImportJustOneName == Nothing --- # thirdPartyImportWithAlias == Nothing --- import urllib3 --- @ --- --- * Specific third party import --- --- @ --- # thirdPartyImportedPackageName == "scipy" --- # thirdPartyImportedPartsFromPackage == [ "linalg" ] --- # thirdPartyImportJustOneName == Nothing --- # thirdPartyImportWithAlias == Nothing --- import scipy.linalg --- @ --- --- * Named third party import --- --- @ --- # thirdPartyImportedPackageName == "django" --- # thirdPartyImportedPartsFromPackage == [ "db" ] --- # thirdPartyImportJustOneName == "models" --- # thirdPartyImportWithAlias == Nothing --- from django.db import models --- @ --- -data ThirdPartyImportContent - = ThirdPartyImportContent - { - thirdPartyImportedPackageName :: String, - thirdPartyImportedPartsFromPackage :: [ String ], - thirdPartyImportJustOneName :: Maybe String, - thirdPartyImportWithAlias :: Maybe String - } - deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON ) - -data ClassInstanceContent - = ClassInstanceContent - { - instanceName :: InstanceName, - instanceOfClass :: Token.ClassName - } - deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON ) - -data InstanceName - = Self -- ^ Python, Ruby - | This -- ^ Java, Php, Javascript, Typescript - deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON ) - -data InstanceAttribute - = InstanceAttribute - { - attributeName :: Token.FieldName - } - deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON ) - -data ClassNameContent - = ClassNameContent - { - classNameContent :: Token.ClassName - } - deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON ) +{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE OverloadedStrings #-}++module Fqn++where++-- project imports+import Location+import qualified Token++-- general imports+import Data.Aeson+import GHC.Generics++-- |+--+-- * Fully qualified name+-- * Resolution at the /file/ level+-- * Unidirectional resolution only ( one pass )+--+data Fqn+ = NativeTypeInt+ | NativeTypeString+ | NativeTypeBool+ | NativeTypeNull+ | NativeTypeConstInt Int+ | NativeTypeConstStr String+ | NativeTypeConstBool Bool+ | ClassName ClassNameContent+ | ClassInstance ClassInstanceContent+ | FieldedAccess Fqn Token.FieldName+ | CallMethodOfClass Location String Token.ClassName+ | CallMethodOfUntypedNamedParam Location String Token.ParamName+ | CallFuncFromImportedDir Location String FilePath+ | CallFuncFromImportedFile Location String FilePath+ | ReturnTypeOf Location Fqn+ | FirstPartyImport FirstPartyImportContent+ | FirstPartyDirImport FirstPartyDirImportContent+ | ThirdPartyImport ThirdPartyImportContent+ | Unknown+ deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )++data FirstPartyImportContent+ = FirstPartyImportContent+ {+ firstPartyImportedLocation :: FilePath,+ firstPartyImportedName :: Maybe String+ }+ deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )++data FirstPartyDirImportContent+ = FirstPartyDirImportContent+ {+ firstPartyDirImportLocation :: FilePath,+ firstPartyDirImportAlias :: Maybe String+ }+ deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )++-- |+--+-- ==== __Examples:__+--+-- * Entire third party package import+--+-- @+-- # thirdPartyImportedPackageName == "urllib3"+-- # thirdPartyImportedPartsFromPackage == []+-- # thirdPartyImportJustOneName == Nothing+-- # thirdPartyImportWithAlias == Nothing+-- import urllib3+-- @+--+-- * Specific third party import+--+-- @+-- # thirdPartyImportedPackageName == "scipy"+-- # thirdPartyImportedPartsFromPackage == [ "linalg" ]+-- # thirdPartyImportJustOneName == Nothing+-- # thirdPartyImportWithAlias == Nothing+-- import scipy.linalg+-- @+--+-- * Named third party import+--+-- @+-- # thirdPartyImportedPackageName == "django"+-- # thirdPartyImportedPartsFromPackage == [ "db" ]+-- # thirdPartyImportJustOneName == "models"+-- # thirdPartyImportWithAlias == Nothing+-- from django.db import models+-- @+--+data ThirdPartyImportContent+ = ThirdPartyImportContent+ {+ thirdPartyImportedPackageName :: String,+ thirdPartyImportedPartsFromPackage :: [ String ],+ thirdPartyImportJustOneName :: Maybe String,+ thirdPartyImportWithAlias :: Maybe String+ }+ deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )++data ClassInstanceContent+ = ClassInstanceContent+ {+ instanceName :: InstanceName,+ instanceOfClass :: Token.ClassName+ }+ deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )++data InstanceName+ = Self -- ^ Python, Ruby+ | This -- ^ Java, Php, Javascript, Typescript+ deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )++data InstanceAttribute+ = InstanceAttribute+ {+ attributeName :: Token.FieldName+ }+ deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )++data ClassNameContent+ = ClassNameContent+ {+ classNameContent :: Token.ClassName+ }+ deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )