joern-rust
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.9%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: congnghiahieu
- License: apache-2.0
- Language: Scala
- Default Branch: master
- Size: 7.76 MB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
Joern - The Bug Hunter's Workbench
Joern is a platform for analyzing source code, bytecode, and binary executables. It generates code property graphs (CPGs), a graph representation of code for cross-language code analysis. Code property graphs are stored in a custom graph database. This allows code to be mined using search queries formulated in a Scala-based domain-specific query language. Joern is developed with the goal of providing a useful tool for vulnerability discovery and research in static program analysis.
Website: https://joern.io
Documentation: https://docs.joern.io/
Specification: https://cpg.joern.io
News / Changelog
- Joern v2.0.0 upgrades from Scala2 to Scala3
- Joern v1.2.0 removes the
overflowdb.traversal.Traversalclass. This change is not completely backwards compatible. See here for a detailed writeup.
Requirements
- JDK 19 (other versions might work, but have not been properly tested)
- optional: gcc and g++ (for auto-discovery of C/C++ system header files if included/used in your C/C++ code)
Development Requirements
- mvn https://maven.apache.org/install.html
Quick Installation
```bash wget https://github.com/joernio/joern/releases/latest/download/joern-install.sh chmod +x ./joern-install.sh sudo ./joern-install.sh joern
██╗ ██████╗ ███████╗██████╗ ███╗ ██╗
██║██╔═══██╗██╔════╝██╔══██╗████╗ ██║
██║██║ ██║█████╗ ██████╔╝██╔██╗ ██║
██ ██║██║ ██║██╔══╝ ██╔══██╗██║╚██╗██║
╚█████╔╝╚██████╔╝███████╗██║ ██║██║ ╚████║
╚════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝
Version: 2.0.1
Type help to begin
joern> ```
If the installation script fails for any reason, try
bash
./joern-install --interactive
Docker based execution
bash
docker run --rm -it -v /tmp:/tmp -v $(pwd):/app:rw -w /app -t ghcr.io/joernio/joern joern
To run joern in server mode:
bash
docker run --rm -it -v /tmp:/tmp -v $(pwd):/app:rw -w /app -t ghcr.io/joernio/joern joern --server
Almalinux 9 requires the CPU to support SSE4.2. For kvm64 VM use the Almalinux 8 version instead.
bash
docker run --rm -it -v /tmp:/tmp -v $(pwd):/app:rw -w /app -t ghcr.io/joernio/joern-alma8 joern
Releases
A new release is created automatically once per day. Contributers can also manually run the release workflow if they need the release sooner.
Developers
Contribution Guidelines
Thank you for taking time to contribute to Joern! Here are a few guidelines to ensure your pull request will get merged as soon as possible:
- Try to make use of the templates as far as possible, however they may not suit all needs. The minimum we would like to see is:
- A title that briefly describes the change and purpose of the PR, preferably with the affected module in square brackets, e.g.
[javasrc2cpg] Addition Operator Fix. - A short description of the changes in the body of the PR. This could be in bullet points or paragraphs.
- A link or reference to the related issue, if any exists.
- A title that briefly describes the change and purpose of the PR, preferably with the affected module in square brackets, e.g.
- Do not:
- Immediately CC/@/email spam other contributors, the team will review the PR and assign the most appropriate contributor to review the PR. Joern is maintained by industry partners and researchers alike, for the most part with their own goals and priorities, and additional help is largely volunteer work. If your PR is going stale, then reach out to us in follow-up comments with @'s asking for an explanation of priority or planning of when it may be addressed (if ever, depending on quality).
- Leave the description body empty, this makes reviewing the purpose of the PR difficult.
- Remember to:
- Remember to format your code, i.e. run
sbt scalafmt Test/scalafmt - Add a unit test to verify your change.
- Remember to format your code, i.e. run
IDE setup
Intellij IDEA
- Download Intellij Community
- Install and run it
- Install the Scala Plugin - just search and install from within Intellij.
- Important: open
sbtin your local joern repository, runcompileand keep it open - this will allow us to use the BSP build in the next step - Back to Intellij: open project: select your local joern clone: select to open as
BSP project(i.e. notsbt project!) - Await the import and indexing to complete, then you can start, e.g.
Build -> build projector run a test
VSCode
- Install VSCode and Docker
- Install the plugin
ms-vscode-remote.remote-containers - Open Joern project folder in VSCode
Visual Studio Code detects the new files and opens a message box saying:
Folder contains a Dev Container configuration file. Reopen to folder to develop in a container. - Select the
Reopen in Containerbutton to reopen the folder in the container created by the.devcontainer/Dockerfilefile - Switch to
scalameta.metalssidebar in VSCode, and selectimport buildinBUILD COMMANDS - After
import buildsucceeds, you are ready to start writing code for Joern
QueryDB (queries plugin)
Quick way to develop and test QueryDB:
bash
sbt stage
./querydb-install.sh
./joern-scan --list-query-names
The last command prints all available queries - add your own in querydb, run the above commands again to see that your query got deployed. More details in the separate querydb readme
Thứ tự chạy
- joern-cli/frontends/x2cpg/src/main/scala/io/joern/x2cpg/X2Cpg.scala
X2CpgMain - joern-cli/frontends/x2cpg/src/main/scala/io/joern/x2cpg/X2Cpg.scala
main() - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/Main.scala
rustcpg.run(config) - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/parser/RustCpg.scala
createCpg - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/ast/GoModule.scala
loadModule() - joern-cli/frontends/x2cpg/src/main/scala/io/joern/x2cpg/passes/frontend/MetaDataPass.scala
MetaDataPass - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/passes/AstCreationPass.scala
AstCreationPass - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/passes/AstCreationPass.scala
generateParts - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/passes/AstCreationPass.scala
runOnPart - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/parser/JsonParser.scala
parse - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/parser/JsonParser.scala
mapParent(recursive) - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/astcreation/AstCreator.scala
AstCreator - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/astcreation/AstCreator.scala
createAst - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/astcreation/AstCreator.scala
astForTranslationUnit - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/astcreation/AstCreator.scala
astForPackageNode - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/astcreation/AstCreator.scala
astForGoAstNode - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/passes/TypeResolverPass.scala
TypeResolverPass - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/passes/TypeResolverPass.scala
run - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/passes/ModuleResolverPass.scala
ModuleResolverPass - joern-cli/frontends/rustsrc2cpg/src/main/scala/io/joern/rustsrc2cpg/passes/ModuleResolverPass.scala
run
convert below rust to scala in these line, with NOTE what:
- using
class - declare variable inside class curly brace
- do not generate constructor
- use None value for Option type
- Use
ListBufferto replaceVecandPunctuated - When you see attribute
skip_serializing_if, use Option as type wrapper - When you see attribute
#[serde(flatten)], using@JsonUnwrappedproperty of jackson for that field - When you see attribute
#[serde(transparent)], generate a comment above that variable - Replace
Boxtype withOptionin scala - Special notice for
renameattribute in#[serde(rename = "...")]. For example, have#[serde(rename = "stmts")], so usestmtsas variable name - Do not use
defaultness, usedefault - Do not use
unsafety, useunsafe - Do nut use
mutabilityusemut Dot not use
blockusestmtsWe already have
attrs, skip it
file:Item.scala apply all class (from ItemForeignMod) variable to these case, note that:
Given class, apply variable to these case, note that
- ignore variable
attrs - use variable name instead of
case _: - see above examples
- ignore variable that have been commented
- ignore variable
mac,unsafe,ident,move,label,const,static,async,dot2_token,lifetime - ignore variable that have type
String,Indent,Index,Option[Boolean],Boolean - For type
Item, usemapParentForItem - For type
Visibility, usemapParentForVisibility - For type
Fields, usemapParentForFields - For type
FieldsNamed, usemapParentForFieldsNamed - For type
FieldsUnnamed, usemapParentForFieldsUnnamed - For type
Type, usemapParentForType - For type
Pat, usemapParentForPat - For type
Expr, usemapParentForExpr - For type
Stmt, usemapParentForStmt - For type
FnArg, usemapParentForFnArg - For type
ReturnType, usemapParentForReturnType - For type
BoundLifetimes, usemapParentForBoundLifetimes - For type
GenericParam, usemapParentForGenericParam - For type
WherePredicate, usemapParentForWherePredicate - For type
TokenStream, usemapParentForTokenStream - For type
TokenTree, usemapParentForTokenTree - For type
ForeignItem, usemapParentForForeignItem - For type
ImplItem, usemapParentForImplItem - For type
TypeParamBound, usemapParentForTypeParamBound - For type
TraitItem, usemapParentForTraitItem - For type
UseTree, usemapParentForUseTree - For type
GenericArgument, usemapParentForGenericArgument For type
PathArguments, usemapParentForPathArgumentsconvert this to fit all below function, use
else ifinstead ofif. At the end put aelsecause that throw errorUse
astForfunction below, corresspoding their variable namesee #, # (function ``) and # , generate compatible file with the same pattern
convert this to fit all below function, use
else ifinstead ofif. At the end put aelsecause that throw errorDo not use
addChildgenerate 1 more trait CodeFor... based on this trait, function return String instead of Ast
With class of function, for example
ExprClosuregenerate missing code for each property of class. See above function as examplescreate a variable equal
NewTypeArgument(), then wrapped it inAst()use
NewTypeArgument()only, remove .namegive related information to
TraitItemConst....create a variable equal
New...()(NewLocal for example), then wrapped it inAst(NewMember())Use Ast(NewMember()).withChild(...)
Remove comment
rename all function name to pattern
astForPat...convert all the
if ... else Nilto using flatmap to check OptionCorrespoding variable then using
withChildreninstead ofwithChildSee this examples:
val annotationsAst = macroStmtInstance.attrs.toList.flatMap(_.map(astForAttribute(filename, parentFullname, _)))
For each function, generate the missing code:
- a variable typeFullname equal to corresspoding
typeFullnameForType...of function - a variable node equal
NewTypeRef()with.typeFullnameset to variabletypeFullnameabove - return
Ast(node) - see function
astForTypeArrayfor example
``
- Convert all code using.toList.flatMap(_.map)to usingmatch`
For example from this:
val annotationsAst = arrayExprInstance.attrs.toList.flatMap(_.map(astForAttribute(filename, parentFullname, _)))
Convert to:
val annotationsAst = arrayExprInstance.attrs match {
case Some(attrs) => attrs.map(astForAttribute(filename, parentFullname, \_)).toList
case None => List()
}
add annotationsAst vairable for all of these
For example:
val annotationsAst = arrayExprInstance.attrs match {
case Some(attrs) => attrs.map(astForAttribute(filename, parentFullname, _)).toList
case None => List()
}
Combile with return Ast, for example
controlStructureAst(armNode, Some(conditionAst), bodyAst) .withChildren(annotationsAst)
move val annotationsAst to head of function body
```
- convert all
val genericsAst = typeImplItemInstance.generics match {
case Some(generics) => List(astForGenerics(filename, parentFullname, generics))
case None => List()
}
to
val genericsAst = typeImplItemInstance.generics match {
case Some(generics) => astForGenerics(filename, parentFullname, generics)
case None => Ast()
}
and use withChild instead of withChildren for genericsAst
- replace
unknownNode(UnknownAst(), "")withunknownNode(variableName, "")
For example: unknownNode(UnknownAst(), "") to unknownNode(referencePatInstance, "")
Owner
- Name: Hiếu Cien
- Login: congnghiahieu
- Kind: user
- Repositories: 0
- Profile: https://github.com/congnghiahieu
Citation (CITATION.cff)
cff-version: 1.2.0 message: "If you use this software, please cite it as below. Reminder to update the `version` and `date-released` as needed." title: "Joern: The Bug Hunter's Workbench" authors: - given-names: joern.io url: "https://github.com/joernio/joern" version: 2.0 date-released: 2024-01-18
GitHub Events
Total
- Watch event: 1
- Push event: 3
Last Year
- Watch event: 1
- Push event: 3
Dependencies
- centos centos7.9.2009 build
- alpine 3.17.3 build