dhscanner-bitcode 0.1.0.1 → 0.1.0.2
raw patch · 3 files changed
+60/−19 lines, 3 filesdep ~dhscanner-astPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: dhscanner-ast
API changes (from Hackage documentation)
- Bitcode: callInputs :: CallContent -> [TmpVariable]
- Bitcode: inputs' :: InstructionContent -> Set Variable
- Bitcode: inputs :: InstructionContent -> Set TmpVariable
+ Bitcode: inputs :: InstructionContent -> Set Variable
Files
- dhscanner-bitcode.cabal +2/−2
- src/Bitcode.hs +57/−17
- src/Callable.hs +1/−0
dhscanner-bitcode.cabal view
@@ -20,7 +20,7 @@ in mind. The commands resemble an abstract RISC-style assembley, motivated by keeping later-phases analyses as simple as possible. -version: 0.1.0.1 +version: 0.1.0.2 license: GPL-3.0-only license-file: LICENSE author: OrenGitHub @@ -48,7 +48,7 @@ aeson >= 2.2.3 && < 2.3, base >= 4.17.2 && < 4.18, containers >= 0.6.7 && < 0.7, - dhscanner-ast >= 0.1.0 && < 0.2, + dhscanner-ast >= 0.1.0.3 && < 0.2, hs-source-dirs: src
src/Bitcode.hs view
@@ -1,3 +1,37 @@+-- | +-- +-- * The [intermediate language (IL) \/ intermediate representation (IR) \/ bitcode](https://en.wikipedia.org/wiki/Intermediate_representation#Intermediate_language) +-- are all synonyms for: +-- +-- * a data structure able to represent code originating from /multiple/ programming languages. +-- +-- * Its main purpose is to serve as the: +-- +-- * second step for /static code analysis/ +-- * part of the [dhscanner](https://github.com/OrenGitHub/dhscanner) framework for +-- CI\/CD container security checks 🔒 and +-- [PII](https://en.wikipedia.org/wiki/Personal_data) leaks detection 🪪 +-- +-- * As part of the [dhscanner](https://github.com/OrenGitHub/dhscanner) framework: +-- +-- * targets mostly languages used for /cloud native applications/ ☁️ +-- * Python, Ruby 💎, Php, Javascript, Typescript, Java ☕️, C# and Golang. +-- +-- * Typical flow: +-- +-- * the 'Asts' (collection of all 'Ast' objects from some code base) are sent for code generation +-- +-- * received through REST API as a JSON http request +-- * 'Callable' entities are identified +-- * each 'Callable' is associated with its control flow graph ('Cfg') +-- +-- * the collection of all 'Callables' is returned +-- +-- * Non Haskell parogrammers note: +-- +-- * Each 'Callable' object is /immutable/ ( like everything else in Haskell ... ) +-- + {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE OverloadedStrings #-} @@ -22,7 +56,7 @@ -- | -- * All instructions have an associated location -- --- * That is true also for instrumented instructions (like `Nop` and `Assume`) +-- * That is also true for instrumented instructions (like `Nop` and `Assume`) -- data Instruction = Instruction @@ -32,8 +66,9 @@ } deriving ( Show, Eq, Generic, ToJSON, FromJSON, Ord ) --- | A minimal instruction set to translate /any/ programming language --- to an intermediate langauge ready for static analysis +-- | +-- A minimal instruction set for translating cloud native programming languages and +-- enabling easier static analysis data InstructionContent = Nop | Call CallContent @@ -132,9 +167,6 @@ } deriving ( Show, Eq, Generic, ToJSON, FromJSON, Ord ) -callInputs :: CallContent -> [ TmpVariable ] -callInputs callContent = [] - data BinopContent = BinopContent { @@ -246,27 +278,35 @@ deriving ( Show, Eq, Generic, ToJSON, FromJSON, Ord ) --- some instructions don't have an output variable --- at any case, there is at most one output (unlike inputs) +-- | +-- +-- * some instructions don't have an output variable +-- +-- * 'Nop', 'Assume', 'Return' etc. +-- +-- * other instructions have /exactly one/ output variable +-- output :: InstructionContent -> Maybe Variable output (Unop c) = Just $ unopOutput c +output (Call c) = Just $ callOutput c output (Binop c) = Just $ binopOutput c output (Assign c) = Just $ assignOutput c output (FieldRead c) = Just $ fieldReadOutput c output (SubscriptRead c) = Just $ subscriptReadOutput c output _ = Nothing --- some instructions don't have an input variable --- there can be /multiple/ input variables to an instruction -inputs :: InstructionContent -> Set TmpVariable -inputs (Call c) = Data.Set.fromList $ callInputs c +-- | +-- +-- * some instructions don't have input variables /at all/ +-- +-- * other instructions have /multiple/ input variables +-- +inputs :: InstructionContent -> Set Variable +inputs (Call c) = Data.Set.fromList (args c) inputs _ = Data.Set.empty -inputs' :: InstructionContent -> Set Variable -inputs' = (Data.Set.map TmpVariableCtor) . inputs - variables :: InstructionContent -> Set Variable variables instruction = case output instruction of - Nothing -> inputs' instruction - Just output' -> (Data.Set.singleton output') `Data.Set.union` (inputs' instruction) + Nothing -> inputs instruction + Just oneOutput -> (Data.Set.singleton oneOutput) `Data.Set.union` (inputs instruction)
src/Callable.hs view
@@ -30,6 +30,7 @@ -- project imports import Cfg +import Fqn import Token import Location