using System; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using System.Text; using OpenOptions.FileSpecification; using OpenOptions.dnaFusion.Flex.Common; class Program { static int Main(string[] args) { // ---- 1. Determine the real OOFile header size (no guesswork) ---- var ooType = typeof(OOFile); var headerType = ooType.GetNestedType("Header", BindingFlags.Public); int headerSize = Marshal.SizeOf(headerType); Console.WriteLine($"[info] OOFile header size = {headerSize} bytes"); // ---- 2. Build the JSON payload (short [JsonProperty] names) ---- // BM BossMode true -> per-method checks always pass // LF LicensedFeature "Flex"-> self-creates dboFlexIntegration, passes stub license // SI SystemId 1 // N Name "AllFeatures" // D Description // DP DevicePlatform 2 (Windows) -> skips iOS/Android device-count checks // Dt DeviceType 3 (NotSpecified) // DM DenyMethods [] -> nothing denied // AA AlwaysAllowMethods [] string json = "{\"BM\":true,\"LF\":\"Flex\",\"SI\":1,\"N\":\"AllFeatures\",\"D\":\"Full access key\",\"DP\":2,\"Dt\":3,\"DM\":[],\"AA\":[]}"; byte[] payload = new UTF8Encoding(false).GetBytes(json); // ---- 3. Wrap in a real OOFile (raw, uncompressed, unencrypted) ---- var file = new OOFile(); file.Signature = "FAPIK"; file.Version = 2; // != 1 => JSON path in APIKey.Load file.IsRaw = true; // Format='R'(82), ExtendedFormat=0 file.Data.Write(payload, 0, payload.Length); file.Data.Seek(0, SeekOrigin.Begin); var ms = new MemoryStream(); file.SaveToStream(ms); byte[] all = ms.ToArray(); string b64 = Convert.ToBase64String(all); Console.WriteLine($"[info] total = {all.Length} bytes (header {headerSize} + payload {payload.Length})"); Console.WriteLine("[info] header hex = " + BitConverter.ToString(all, 0, headerSize)); Console.WriteLine("[info] payload = " + json); // ---- 4. Round-trip verify with the real APIKey.Load ---- try { APIKey key = APIKey.Load(b64); if (key == null) { Console.WriteLine("[FAIL] APIKey.Load returned null (signature/version mismatch)"); return 1; } Console.WriteLine("[OK] APIKey.Load round-trip succeeded:"); Console.WriteLine($" BossMode = {key.BossMode}"); Console.WriteLine($" LicensedFeature= {key.LicensedFeature}"); Console.WriteLine($" SystemId = {key.SystemId}"); Console.WriteLine($" Name = {key.Name}"); Console.WriteLine($" DevicePlatform = {key.DevicePlatform}"); Console.WriteLine($" DeviceType = {key.DeviceType}"); Console.WriteLine($" DenyMethods = [{string.Join(",", key.DenyMethods ?? new System.Collections.Generic.List())}]"); Console.WriteLine($" AlwaysAllow = [{string.Join(",", key.AlwaysAllowMethods ?? new System.Collections.Generic.List())}]"); Console.WriteLine(); Console.WriteLine("APIKEY=" + b64); return 0; } catch (Exception e) { Console.WriteLine($"[FAIL] round-trip threw: {e.GetType().Name}: {e.Message}"); return 1; } } }