Skip to content

Commit

Permalink
Add support for ReverseShort statements
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcaliburZero committed Nov 5, 2023
1 parent 4bb35d6 commit 66cb9cc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The following QuickBMS commands are currently supported by the langauge server.
* [x] `EndIf`
* [ ] `GetCT VAR TYPE CHAR [FILENUM]`
* [ ] `ComType ALGO [DICT] [DICT_SIZE]`
* [ ] `ReverseShort VAR [ENDIAN]`
* [x] `ReverseShort VAR [ENDIAN]`
* [ ] `ReverseLong VAR [ENDIAN]`
* [ ] `ReverseLongLong VAR [ENDIAN]`
* [x] `Endian TYPE [VAR]`
Expand Down
9 changes: 9 additions & 0 deletions src/server/keyword_docs/reverseshort.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ReverseShort VAR [ENDIAN]

Classical swap that inverts a 16bit variable from 0x2211 to
0x1122
and vice versa.

Arguments:
VAR variable to flip
ENDIAN desired endianess like little or big
4 changes: 4 additions & 0 deletions src/server/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ pub fn get_keyword_docs() -> HashMap<String, String> {
"encryption".to_string(),
include_str!("keyword_docs/encryption.txt").to_string(),
),
(
"reverseshort".to_string(),
include_str!("keyword_docs/reverseshort.txt").to_string(),
),
]
.iter()
.cloned()
Expand Down
7 changes: 7 additions & 0 deletions tree-sitter-quickbms/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = grammar({
$.putarray_statement,
$.string_statement,
$.encryption_statement,
$.reverseshort_statement,
),
set_statement: $ => seq(
$.set,
Expand Down Expand Up @@ -195,6 +196,11 @@ module.exports = grammar({
),
)),
),
reverseshort_statement: $ => seq(
$.reverseshort,
field("variable", $._expression),
field("endian", optional($._endian_type)),
),
comparison: $ => choice(
"<",
">",
Expand Down Expand Up @@ -298,6 +304,7 @@ module.exports = grammar({
getarray: $ => /[Gg][Ee][Tt][Aa][Rr][Rr][Aa][Yy]/,
putarray: $ => /[Pp][Uu][Tt][Aa][Rr][Rr][Aa][Yy]/,
encryption: $ => /[Ee][Nn][Cc][Rr][Yy][Pp][Tt][Ii][Oo][Nn]/,
reverseshort: $ => /[Rr][Ee][Vv][Ee][Rr][Ss][Ee][Ss][Hh][Oo][Rr][Tt]/,
question_mark: $ => /\?/,

identifier: $ => /[a-zA-Z_\\]+[a-zA-Z0-9_\-\\]*/,
Expand Down
22 changes: 22 additions & 0 deletions tree-sitter-quickbms/test/corpus/reverseshort.bms
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
================================================================================
ReverseShort statements
================================================================================

reverseshort REVERSE_CRC
reverseshort REVERSE_CRC little
reverseshort REVERSE_CRC big

--------------------------------------------------------------------------------

(source_file
(reverseshort_statement
(reverseshort)
(identifier))
(reverseshort_statement
(reverseshort)
(identifier)
(little))
(reverseshort_statement
(reverseshort)
(identifier)
(big)))

0 comments on commit 66cb9cc

Please sign in to comment.