Security.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. class Security
  7. {
  8. private:
  9. Func *func;
  10. public:
  11. Security(Func * func) : func(func) {}
  12. void EncodeLargeConstants();
  13. void InsertNOPs();
  14. static bool DontEncode(IR::Opnd *opnd);
  15. static void InsertRandomFunctionPad(IR::Instr * instrBeforeInstr);
  16. private:
  17. void EncodeOpnd(IR::Instr *instr, IR::Opnd *opnd);
  18. IntConstType EncodeValue(IR::Instr *instr, IR::Opnd *opnd, IntConstType constValue, IR::RegOpnd ** pNewOpnd);
  19. #ifdef _M_X64
  20. size_t EncodeAddress(IR::Instr *instr, IR::Opnd *opnd, size_t value, IR::RegOpnd **pNewOpnd);
  21. #endif
  22. // Large constants have more than 16 significant bits.
  23. // Constants except these are considered large: 0x0000????, 0xffff????, 0x????0000, 0x????ffff
  24. static bool IsLargeConstant(int32 value) { return static_cast<int16>(value) != 0 && static_cast<int16>(value) != -1 && (value >> 16) != 0 && (value >> 16) != -1; }
  25. void InsertNOPBefore(IR::Instr *instr);
  26. int GetNextNOPInsertPoint();
  27. // Insert 1-4 bytes of NOPs
  28. static void InsertSmallNOP(IR::Instr * instrBeforeInstr, DWORD nopSize);
  29. };