8 using System.Runtime.InteropServices;
9 using System.Collections.Generic;
35 private const int SIGNATURE_MAX_LEN = 128;
36 private const string APP_SIGNATURE_FILE_NAME =
"ApplicationSignature.xml";
38 private string applicationId;
47 public void setAppIdAndSignature()
49 makeAppIdFromAssemblyDll();
50 createSignatureFileIfNeeded();
51 resetAppIdAndSignature();
52 setSignatureFromFile();
55 private void makeAppIdFromAssemblyDll()
57 string assemblyFilePath = null;
59 if (Application.platform == RuntimePlatform.WindowsPlayer)
61 assemblyFilePath = Application.dataPath +
"/Managed/" +
"Assembly-CSharp.dll";
63 else if (Application.platform == RuntimePlatform.OSXPlayer)
65 assemblyFilePath = Application.dataPath +
"/Resources/Data/Managed/" +
"Assembly-CSharp.dll";
69 FileStream assemblyFS = File.Open(assemblyFilePath, FileMode.Open);
70 byte[] assemblyBytes =
new byte[1024];
71 assemblyFS.Read(assemblyBytes, 0, assemblyBytes.Length);
74 int size = Marshal.SizeOf(assemblyBytes[0]) * assemblyBytes.Length;
76 IntPtr unmanagedArrayPtr = Marshal.AllocHGlobal(size);
81 Marshal.Copy(assemblyBytes, 0, unmanagedArrayPtr, assemblyBytes.Length);
88 byte[] appIdBytes = Enumerable.Repeat((byte)0x00, SIGNATURE_MAX_LEN).ToArray();
89 int[] appIdLength =
new int[1];
95 byte[] newAppIdBytes =
new byte[appIdLength[0]];
97 Array.Copy(appIdBytes, newAppIdBytes, appIdLength[0]);
99 applicationId = Encoding.Default.GetString(newAppIdBytes);
101 Marshal.FreeHGlobal(unmanagedArrayPtr);
104 private void createSignatureFileIfNeeded()
106 if (!File.Exists(Directory.GetCurrentDirectory() +
"/" + APP_SIGNATURE_FILE_NAME))
108 XmlDocument doc =
new XmlDocument();
109 XmlNode docNode = doc.CreateXmlDeclaration(
"1.0",
"UTF-8", null);
110 doc.AppendChild(docNode);
112 XmlNode rootNode = doc.CreateElement(
"MaxstARSDK");
113 doc.AppendChild(rootNode);
115 XmlNode appIdElement = doc.CreateElement(
"AppId");
116 appIdElement.InnerText = applicationId;
117 rootNode.AppendChild(appIdElement);
119 XmlNode appSigElement = doc.CreateElement(
"AppSignature");
120 appSigElement.InnerText =
"_Invalid_Signature_";
121 rootNode.AppendChild(appSigElement);
123 doc.Save(Directory.GetCurrentDirectory() +
"/" + APP_SIGNATURE_FILE_NAME);
127 private void resetAppIdAndSignature()
129 XmlDocument xmldoc =
new XmlDocument();
130 xmldoc.Load(Directory.GetCurrentDirectory() +
"/" + APP_SIGNATURE_FILE_NAME);
131 XmlElement docRoot = xmldoc.DocumentElement;
133 XmlNode appIdNode = docRoot.SelectSingleNode(
"AppId");
134 XmlNode appSigNode = docRoot.SelectSingleNode(
"AppSignature");
136 string previousAppId = appIdNode.InnerText;
138 if (String.Compare(previousAppId, applicationId) != 0)
140 appIdNode.InnerText = applicationId;
141 appSigNode.InnerText =
"_Invalid_Signature_";
142 xmldoc.Save(Directory.GetCurrentDirectory() +
"/" + APP_SIGNATURE_FILE_NAME);
146 private void setSignatureFromFile()
148 XmlDocument xmldoc =
new XmlDocument();
149 xmldoc.Load(Directory.GetCurrentDirectory() +
"/" + APP_SIGNATURE_FILE_NAME);
150 XmlElement docRoot = xmldoc.DocumentElement;
152 XmlNode appIdNode = docRoot.SelectSingleNode(
"AppId");
153 XmlNode appSigNode = docRoot.SelectSingleNode(
"AppSignature");
155 string signature = appSigNode.InnerText;
156 if (signature != null && signature.Length > 0)