You are viewing our Forum Archives. To view or take place in current topics click here.
[C#] Xval Decryption Class
Posted:

[C#] Xval Decryption ClassPosted:

CLK
  • Wise One
Status: Offline
Joined: Jun 12, 201014Year Member
Posts: 531
Reputation Power: 33
Status: Offline
Joined: Jun 12, 201014Year Member
Posts: 531
Reputation Power: 33
Stumbled upon this over at [ Register or Signin to view external links. ] and decided to port it to C# today.

If you use this, PLEASE give credits to Redline99 for his work. He's an awesome guy and deserves the recognition.

Note, I haven't tested it with a bad Xval since I don't have any Xboxes that are flagged or whatnot, but it should work just fine.

If you aren't familiar with Xval, read this [ Register or Signin to view external links. ]

[ Register or Signin to view external links. ]

or...

/* Xval Decrypter class written (ported) by CLK
 * Original code by Redline99 http://www.xboxhacker.org/index.php?topic=16401.msg125000#msg125000
 * Big thanks to him for all he's done for everyone in the Xbox scene
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Xval_Decrypt
{
    public static class Xval
    {
        public static uint[] Decrypt(string xval, string Serial)
        {
            // Remove formatting
            xval = xval.Replace("-", "");
            // Convert the xval and serial to a byte array to use
            byte[] x = new byte[0x8];
            byte[] s = new byte[0xD];
            char[] sC = Serial.ToCharArray();
            for (int i = 0, j = 0; j < 0xC; i += 2, j++)
            {
                if (i < 0x10)
                {
                    x[j] = byte.Parse(xval.Substring(i, 2), System.Globalization.NumberStyles.HexNumber);
                }
                s[j] = (byte)sC[j];
            }
            return Decrypt(x, s);
        }

        public static uint[] Decrypt(byte[] xval, byte[] Serial)
        {
            // If the serial isn't 0xD and xval isn't 0x8, throw an exception
            if (xval.Length != 8)
            {
                throw new ArgumentException("Xval length invalid!", "xval");
            }
            if (Serial.Length != 0xD)
            {
                throw new ArgumentException("Serial length invalid!", "Serial");
            }
            // Create the new instance of the hmac class
            HMAC hmac = HMACSHA1.Create();
            // Set the key
            hmac.Key = Serial;
            // Compute that ****
            byte[] deskeytemp = hmac.ComputeHash(Encoding.ASCII.GetBytes("XBOX360SSB"));
            byte[] deskey = new byte[0x8];
            Array.Copy(deskeytemp, deskey, 8);
            deskeytemp = null;
            // If the des key does not equal 8, throw an exception
            if (deskey.Length != 8)
            {
                throw new Exception("Invalid DES key");
            }
            // Create a new instance of the DES crytpo class
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            // Set the key
            des.Key = deskey;
            // Create the output buffer
            byte[] Decrypted = new byte[8];
            // Decrypt the data
            des.CreateDecryptor().TransformBlock(xval, 0, xval.Length, Decrypted, 0);
            // Convert the array to a long
            Array.Reverse(Decrypted);
            uint lower32 = BitConverter.ToUInt32(new byte[] { Decrypted[0], Decrypted[1], Decrypted[2], Decrypted[3] }, 0);
            uint upper32 = BitConverter.ToUInt32(new byte[] { Decrypted[4], Decrypted[5], Decrypted[6], Decrypted[7] }, 0);
            return new uint[] { upper32, lower32 };
        }

        public static string[] ReadDecryptedXval(uint[] Data)
        {
            uint highXval = Data[0];
            uint lowXval = Data[1];
            List<string> Flags = new List<string>();
            if (highXval == 0 && lowXval == 0)                                          // nothing is flagged in secdata.bin, all is good from this standpoint      
                return new string[] { "Secdata is Clean" };
            else if (highXval == 0xFFFFFFFF && lowXval == 0xFFFFFFFF)                   // secdata was prob tampered with
                return new string[] { "Secdata is invalid" };
            else if (highXval != 0 && lowXval != 0)                                       // most likely the serial or xval is incorrect
                return new string[] { "Secdata decryption error" };
            else
            {                                                                           // the high dword = 0 and low dword not 0
                // afaik best check. have to look at disassembly more
                if ((lowXval & (int)XFlags.FLAG_SSB_AUTH_EX_FAILURE) != 0)
                    Flags.Add("AuthEx Challenge Failure");                               // AP25 related
                if ((lowXval & (int)XFlags.FLAG_SSB_AUTH_EX_NO_TABLE) != 0)
                    Flags.Add("AuthEx Table missing");                                  // AP25 related
                if ((lowXval & (int)XFlags.FLAG_SSB_AUTH_EX_RESERVED) != 0)
                    Flags.Add("AuthEx Reserved Flag");                                  // AP25 related
                if ((lowXval & (int)XFlags.FLAG_SSB_INVALID_DVD_GEOMETRY) != 0)
                    Flags.Add("Invalid DVD Geometry");
                if ((lowXval & (int)XFlags.FLAG_SSB_INVALID_DVD_DMI) != 0)
                    Flags.Add("Invalid DVD DMI");
                if ((lowXval & (int)XFlags.FLAG_SSB_DVD_KEYVAULT_PAIR_MISMATCH) != 0)
                    Flags.Add("DVD Keyvault Pair Mismatch");
                if ((lowXval & (int)XFlags.FLAG_SSB_CRL_DATA_INVALID) != 0)
                    Flags.Add("Invalid CRL Data");
                if ((lowXval & (int)XFlags.FLAG_SSB_CRL_CERTIFICATE_REVOKED) != 0)
                    Flags.Add("CRL Certificate Revoked");
                if ((lowXval & (int)XFlags.FLAG_SSB_UNAUTHORIZED_INSTALL) != 0)
                    Flags.Add("Unauthorized Install");
                if ((lowXval & (int)XFlags.FLAG_SSB_KEYVAULT_POLICY_VIOLATION) != 0)
                    Flags.Add("Keyvault Policy Violation");
                if ((lowXval & (int)XFlags.FLAG_SSB_CONSOLE_BANNED) != 0)
                    Flags.Add("Console Banned");
                if ((lowXval & (int)XFlags.FLAG_SSB_ODD_VIOLATION) != 0)
                    Flags.Add("ODD Violation");
                if ((lowXval & 0xFFFFF000) != 0)                                        // mask for bits we dont have a description for,
                                                                                        // note: we are not looking at the hi dword yet
                    Flags.Add("Unknown Violation(s)");
            }
            return Flags.ToArray();
        }

        private enum XFlags
        {
            FLAG_SSB_NONE                           = 0x0000,
            FLAG_SSB_AUTH_EX_FAILURE                = 0x0001,
            FLAG_SSB_AUTH_EX_NO_TABLE               = 0x0002,
            FLAG_SSB_AUTH_EX_RESERVED               = 0x0004,
            FLAG_SSB_INVALID_DVD_GEOMETRY           = 0x0008,
            FLAG_SSB_INVALID_DVD_DMI                = 0x0010,
            FLAG_SSB_DVD_KEYVAULT_PAIR_MISMATCH     = 0x0020,
            FLAG_SSB_CRL_DATA_INVALID               = 0x0040,
            FLAG_SSB_CRL_CERTIFICATE_REVOKED        = 0x0080,
            FLAG_SSB_UNAUTHORIZED_INSTALL           = 0x0100,
            FLAG_SSB_KEYVAULT_POLICY_VIOLATION      = 0x0200,
            FLAG_SSB_CONSOLE_BANNED                 = 0x0400,
            FLAG_SSB_ODD_VIOLATION                  = 0x0800,
        }
    }
}
#2. Posted:
DustyBIGJosh
  • New Member
Status: Offline
Joined: Jan 14, 201014Year Member
Posts: 37
Reputation Power: 1
Status: Offline
Joined: Jan 14, 201014Year Member
Posts: 37
Reputation Power: 1
Nice work CLK!

I am never on my Xbox360 enough to really use this, but thanks for the insite into how it works.

Also how do you get on XboxHacker?

For a long time now I always get the error "Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 16406482 bytes) in /home/xbh360/public_html/index.php on line 26".
#3. Posted:
CLK
  • Wise One
Status: Offline
Joined: Jun 12, 201014Year Member
Posts: 531
Reputation Power: 33
Status: Offline
Joined: Jun 12, 201014Year Member
Posts: 531
Reputation Power: 33
I have no idea what XboxHacker's doing that, but I'll be sure to pass the word along SiliconIce/Redline and see if they can do anything about it.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.