Skip to content

Commit

Permalink
Add support for ReverseLongLong statements
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcaliburZero committed Nov 5, 2023
1 parent 8c672e2 commit 5a30af7
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 @@ -54,7 +54,7 @@ The following QuickBMS commands are currently supported by the langauge server.
* [ ] `ComType ALGO [DICT] [DICT_SIZE]`
* [x] `ReverseShort VAR [ENDIAN]`
* [x] `ReverseLong VAR [ENDIAN]`
* [ ] `ReverseLongLong VAR [ENDIAN]`
* [x] `ReverseLongLong VAR [ENDIAN]`
* [x] `Endian TYPE [VAR]`
* [ ] `FileXOR SEQ [OFFSET] [FILENUM]`
* [ ] `FileRot SEQ [OFFSET] [FILENUM]`
Expand Down
9 changes: 9 additions & 0 deletions src/server/keyword_docs/reverselonglong.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ReverseLongLong VAR [ENDIAN]

Classical swap that inverts a 32bit variable from
0x8877665544332211 to 0x1122334455667788 and vice versa.
This command works only with quickbms_4gb_files.exe

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 @@ -448,6 +448,10 @@ pub fn get_keyword_docs() -> HashMap<String, String> {
"reverselong".to_string(),
include_str!("keyword_docs/reverselong.txt").to_string(),
),
(
"reverselonglong".to_string(),
include_str!("keyword_docs/reverselonglong.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 @@ -40,6 +40,7 @@ module.exports = grammar({
$.encryption_statement,
$.reverseshort_statement,
$.reverselong_statement,
$.reverselonglong_statement,
),
set_statement: $ => seq(
$.set,
Expand Down Expand Up @@ -207,6 +208,11 @@ module.exports = grammar({
field("variable", $._expression),
field("endian", optional($._endian_type)),
),
reverselonglong_statement: $ => seq(
$.reverselonglong,
field("variable", $._expression),
field("endian", optional($._endian_type)),
),
comparison: $ => choice(
"<",
">",
Expand Down Expand Up @@ -312,6 +318,7 @@ module.exports = grammar({
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]/,
reverselonglong: $ => /[Rr][Ee][Vv][Ee][Rr][Ss][Ee][Ll][Oo][Nn][Gg][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/reverselonglong.bms
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
================================================================================
ReverseLongLong statements
================================================================================

reverselonglong REVERSE_CRC
reverselonglong REVERSE_CRC little
reverselonglong REVERSE_CRC big

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

(source_file
(reverselonglong_statement
(reverselonglong)
(identifier))
(reverselonglong_statement
(reverselonglong)
(identifier)
(little))
(reverselonglong_statement
(reverselonglong)
(identifier)
(big)))

0 comments on commit 5a30af7

Please sign in to comment.