Skip to content

Commit

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

Classical swap that inverts a 32bit variable from 0x44332211 to
0x11223344 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 @@ -444,6 +444,10 @@ pub fn get_keyword_docs() -> HashMap<String, String> {
"reverseshort".to_string(),
include_str!("keyword_docs/reverseshort.txt").to_string(),
),
(
"reverselong".to_string(),
include_str!("keyword_docs/reverselong.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 @@ -39,6 +39,7 @@ module.exports = grammar({
$.string_statement,
$.encryption_statement,
$.reverseshort_statement,
$.reverselong_statement,
),
set_statement: $ => seq(
$.set,
Expand Down Expand Up @@ -201,6 +202,11 @@ module.exports = grammar({
field("variable", $._expression),
field("endian", optional($._endian_type)),
),
reverselong_statement: $ => seq(
$.reverselong,
field("variable", $._expression),
field("endian", optional($._endian_type)),
),
comparison: $ => choice(
"<",
">",
Expand Down Expand Up @@ -305,6 +311,7 @@ module.exports = grammar({
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]/,
reverselong: $ => /[Rr][Ee][Vv][Ee][Rr][Ss][Ee][Ll][Oo][Nn][Gg]/,
question_mark: $ => /\?/,

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

reverselong REVERSE_CRC
reverselong REVERSE_CRC little
reverselong REVERSE_CRC big

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

(source_file
(reverselong_statement
(reverselong)
(identifier))
(reverselong_statement
(reverselong)
(identifier)
(little))
(reverselong_statement
(reverselong)
(identifier)
(big)))

0 comments on commit 8c672e2

Please sign in to comment.