Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement with statement #197

Merged
merged 3 commits into from
Sep 19, 2024
Merged

Conversation

TommYDeeee
Copy link
Contributor

@TommYDeeee TommYDeeee commented Sep 16, 2024

This expression would allow us to declare a local variable that will be used in remainder of a corresponding section.

condition: 
    with foo = <expr>, 
         bar = <expr> : (
       <a boolean expression where you can use identifiers foo and bar>
    )

Another advantage of this approach is that we can use it inside a loop.

for all offset in (10,20,30) : (
   with val = uint8(offset) | uint8(offset + 4) | uint8(offset + 8) : (
      val == 0x10000 or 
      val == 0x20000 or 
      val == 0x40000
   )
)

This implementation follows RFC proposal.

Copy link
Member

@plusvic plusvic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

lib/src/compiler/ir/mod.rs Outdated Show resolved Hide resolved
parser/src/ast/mod.rs Outdated Show resolved Hide resolved
parser/src/ast/mod.rs Outdated Show resolved Hide resolved
site/content/docs/writing_rules/differences.md Outdated Show resolved Hide resolved
parser/src/parser/mod.rs Outdated Show resolved Hide resolved
@TommYDeeee
Copy link
Contributor Author

Great job!

Thank you for a review. I have incorporated all the requested changes in: 3858aaf

hopefully it is all good now.

@plusvic plusvic merged commit c30b18a into VirusTotal:main Sep 19, 2024
17 checks passed
plusvic pushed a commit that referenced this pull request Sep 19, 2024
This expression would allow us to declare a local variable that will be used in remainder of a corresponding section. 

```
condition: 
    with foo = <expr>, 
         bar = <expr> : (
       <a boolean expression where you can use identifiers foo and bar>
    )
```

Another advantage of this approach is that we can use it inside a loop.

```
for all offset in (10,20,30) : (
   with val = uint8(offset) | uint8(offset + 4) | uint8(offset + 8) : (
      val == 0x10000 or 
      val == 0x20000 or 
      val == 0x40000
   )
)
```

This implementation follows [RFC](VirusTotal/yara#1783) proposal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants