-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove license header template in .editorconfig * Update csharp_style_var in .editorconfig * Add IsValidDictionaryId extension methdo * Hard code ObfuscatorLib name instead using reflection * Use `IsValidDictionaryId()` in dictionary .ctor * Implement deobfuscation * Add unit tests * Add DaxText.ToString override * Making VpaxObfuscator impl methods static * Making Common .ctors public * Bump version 0.2-beta
- Loading branch information
1 parent
62ab62c
commit 71817f2
Showing
19 changed files
with
704 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/Dax.Vpax.Obfuscator/DaxModelDeobfuscator.DeobfuscateExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using Dax.Vpax.Obfuscator.Extensions; | ||
using System.Text; | ||
using TabularEditor.Dax.Tokenizer; | ||
|
||
namespace Dax.Vpax.Obfuscator; | ||
|
||
internal sealed partial class DaxModelDeobfuscator | ||
{ | ||
internal string DeobfuscateExpression(string expression) | ||
{ | ||
var tokens = DaxTokenizer.Tokenize(expression, DaxLocale.US, includeHidden: true); | ||
var builder = new StringBuilder(expression.Length); | ||
|
||
foreach (var token in tokens) | ||
{ | ||
var tokenText = token.Text; | ||
|
||
if (tokenText.Length == 0) | ||
{ | ||
switch (token.Type) | ||
{ | ||
case DaxToken.STRING_LITERAL: | ||
builder.Append("\"\""); | ||
break; | ||
case DaxToken.TABLE: | ||
builder.Append("''"); | ||
break; | ||
} | ||
continue; | ||
} | ||
|
||
switch (token.Type) | ||
{ | ||
case DaxToken.SINGLE_LINE_COMMENT: | ||
case DaxToken.DELIMITED_COMMENT: | ||
tokenText = _dictionary.GetValue(tokenText); | ||
break; | ||
case DaxToken.COLUMN_OR_MEASURE when token.IsReservedExtensionColumn(): | ||
tokenText = token.Replace(expression, tokenText); | ||
break; | ||
case DaxToken.STRING_LITERAL when token.IsExtensionColumnName(): | ||
tokenText = ReplaceExtensionColumnName(token); | ||
break; | ||
case DaxToken.TABLE_OR_VARIABLE when token.IsVariable(): | ||
case DaxToken.TABLE: | ||
case DaxToken.COLUMN_OR_MEASURE: | ||
case DaxToken.STRING_LITERAL: | ||
case DaxToken.UNTERMINATED_COLREF: | ||
case DaxToken.UNTERMINATED_TABLEREF: | ||
case DaxToken.UNTERMINATED_STRING: | ||
tokenText = token.Replace(expression, _dictionary.GetValue(tokenText)); | ||
break; | ||
} | ||
|
||
builder.Append(tokenText); | ||
} | ||
|
||
return builder.ToString(); | ||
|
||
string ReplaceExtensionColumnName(DaxToken token) | ||
{ | ||
var (tableName, columnName) = token.GetExtensionColumnNameParts(); | ||
tableName = _dictionary.GetValue(tableName); | ||
columnName = _dictionary.GetValue(columnName); | ||
|
||
var value = $"{tableName.DaxEscape()}[{columnName.DaxEscape()}]"; | ||
return token.Replace(expression, value, escape: true); | ||
} | ||
} | ||
} |
Oops, something went wrong.