from .GenPcdDb import CreatePcdDatabaseCode\r
from .IdfClassObject import *\r
\r
+import json\r
+import secrets\r
+\r
## PCD type string\r
gItemTypeStringDatabase = {\r
TAB_PCDS_FEATURE_FLAG : TAB_PCDS_FIXED_AT_BUILD,\r
def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer, StringIdf, IdfGenCFlag, IdfGenBinBuffer):\r
CreateHeaderCode(Info, AutoGenC, AutoGenH)\r
\r
+ # The only 32 bit archs we have are IA32 and ARM, everything else is 64 bit\r
+ Bitwidth = 32 if Info.Arch == 'IA32' or Info.Arch == 'ARM' else 64\r
+\r
+ if GlobalData.gStackCookieValues64 == [] and os.path.exists(os.path.join(Info.PlatformInfo.BuildDir, "StackCookieValues64.json")):\r
+ with open (os.path.join(Info.PlatformInfo.BuildDir, "StackCookieValues64.json"), "r") as file:\r
+ GlobalData.gStackCookieValues64 = json.load(file)\r
+ if GlobalData.gStackCookieValues32 == [] and os.path.exists(os.path.join(Info.PlatformInfo.BuildDir, "StackCookieValues32.json")):\r
+ with open (os.path.join(Info.PlatformInfo.BuildDir, "StackCookieValues32.json"), "r") as file:\r
+ GlobalData.gStackCookieValues32 = json.load(file)\r
+\r
+ try:\r
+ if Bitwidth == 32:\r
+ CookieValue = int(GlobalData.gStackCookieValues32[hash(Info.Guid) % len(GlobalData.gStackCookieValues32)])\r
+ else:\r
+ CookieValue = int(GlobalData.gStackCookieValues64[hash(Info.Guid) % len(GlobalData.gStackCookieValues64)])\r
+ except:\r
+ EdkLogger.warn("build", "Failed to get Stack Cookie Value List! Generating random value.", ExtraData="[%s]" % str(Info))\r
+ if Bitwidth == 32:\r
+ CookieValue = secrets.randbelow (0xFFFFFFFF)\r
+ else:\r
+ CookieValue = secrets.randbelow (0xFFFFFFFFFFFFFFFF)\r
+\r
+ AutoGenH.Append((\r
+ '#define STACK_COOKIE_VALUE 0x%XULL\n' % CookieValue\r
+ if Bitwidth == 64 else\r
+ '#define STACK_COOKIE_VALUE 0x%X\n' % CookieValue\r
+ ))\r
+\r
CreateGuidDefinitionCode(Info, AutoGenC, AutoGenH)\r
CreateProtocolDefinitionCode(Info, AutoGenC, AutoGenH)\r
CreatePpiDefinitionCode(Info, AutoGenC, AutoGenH)\r
from linecache import getlines\r
from subprocess import Popen,PIPE, STDOUT\r
from collections import OrderedDict, defaultdict\r
+import json\r
+import secrets\r
\r
from AutoGen.PlatformAutoGen import PlatformAutoGen\r
from AutoGen.ModuleAutoGen import ModuleAutoGen\r
iau.CreateDepsTarget()\r
return "%dms" % (int(round((time.time() - BeginTime) * 1000)))\r
\r
+def GenerateStackCookieValues():\r
+ if GlobalData.gBuildDirectory == "":\r
+ return\r
+\r
+ # Check if the 32 bit values array needs to be created\r
+ if not os.path.exists(os.path.join(GlobalData.gBuildDirectory, "StackCookieValues32.json")):\r
+ StackCookieValues32 = [secrets.randbelow(0xFFFFFFFF) for _ in range(0, 100)]\r
+ with open (os.path.join(GlobalData.gBuildDirectory, "StackCookieValues32.json"), "w") as file:\r
+ json.dump(StackCookieValues32, file)\r
+\r
+ # Check if the 64 bit values array needs to be created\r
+ if not os.path.exists(os.path.join(GlobalData.gBuildDirectory, "StackCookieValues64.json")):\r
+ StackCookieValues64 = [secrets.randbelow(0xFFFFFFFFFFFFFFFF) for _ in range(0, 100)]\r
+ with open (os.path.join(GlobalData.gBuildDirectory, "StackCookieValues64.json"), "w") as file:\r
+ json.dump(StackCookieValues64, file)\r
+\r
## The smallest unit that can be built in multi-thread build mode\r
#\r
# This is the base class of build unit. The "Obj" parameter must provide\r
self.UniFlag,\r
self.Progress\r
)\r
+ GenerateStackCookieValues()\r
self.Fdf = Wa.FdfFile\r
self.LoadFixAddress = Wa.Platform.LoadFixAddress\r
self.BuildReport.AddPlatformReport(Wa)\r
self.Progress,\r
self.ModuleFile\r
)\r
+ GenerateStackCookieValues()\r
self.Fdf = Wa.FdfFile\r
self.LoadFixAddress = Wa.Platform.LoadFixAddress\r
Wa.CreateMakeFile(False)\r
self.UniFlag,\r
self.Progress\r
)\r
+ GenerateStackCookieValues()\r
self.Fdf = Wa.FdfFile\r
self.LoadFixAddress = Wa.Platform.LoadFixAddress\r
self.BuildReport.AddPlatformReport(Wa)\r