diff options
| author | Robert Stepinski <rob.stepinski@gmail.com> | 2019-10-11 11:30:32 -0400 |
|---|---|---|
| committer | Tim Foley <tfoleyNV@users.noreply.github.com> | 2019-10-11 08:30:32 -0700 |
| commit | deeb8647012fc6362f1bb33842cf0842e16f13b7 (patch) | |
| tree | e733f025426516ce74e440e232bb444d2d3aa9f5 /source/slang | |
| parent | 9a09e2ed2c06ac5532488c418badec98ef362ca9 (diff) | |
Add ability to obfuscate name when generating GLSL/HLSL source (#1075)
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-compiler.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 27 | ||||
| -rw-r--r-- | source/slang/slang-options.cpp | 4 |
3 files changed, 27 insertions, 7 deletions
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index ad90bb5ee..ebde8b6d3 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1636,6 +1636,9 @@ namespace Slang // bool useUnknownImageFormatAsDefault = false; + // Remove name hints to help obfuscate code + // + bool obfuscateCode = false; private: RefPtr<ComponentType> m_program; }; diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 6b828085e..991540782 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -637,7 +637,7 @@ String CLikeSourceEmitter::generateName(IRInst* inst) // if(auto nameHintDecoration = inst->findDecoration<IRNameHintDecoration>()) { - // The name we output will basically be: + // The (non-obfuscated) name we output will basically be: // // <nameHint>_<uniqueID> // @@ -645,15 +645,28 @@ String CLikeSourceEmitter::generateName(IRInst* inst) // and we will omit the underscore if the (scrubbed) // name hint already ends with one. // - - String nameHint = nameHintDecoration->getName(); - nameHint = scrubName(nameHint); + // The obfuscated name we output will simply be: + // + // _<uniqueID> + // StringBuilder sb; - sb.append(nameHint); - // Avoid introducing a double underscore - if(!nameHint.endsWith("_")) + if (!m_compileRequest->obfuscateCode) + { + + String nameHint = nameHintDecoration->getName(); + nameHint = scrubName(nameHint); + + sb.append(nameHint); + + // Avoid introducing a double underscore + if (!nameHint.endsWith("_")) + { + sb.append("_"); + } + } + else { sb.append("_"); } diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 94f82ef31..31a5c7c7f 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -775,6 +775,10 @@ struct OptionsParser { requestImpl->getBackEndReq()->useUnknownImageFormatAsDefault = true; } + else if (argStr == "-obfuscate") + { + requestImpl->getBackEndReq()->obfuscateCode = true; + } else if (argStr == "-file-system") { String name; |
