예제 #1
0
        public static string Decrypt(string Data, byte[] Key, byte[] IV)
        {
            try
            {

                MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(Data));

                // Create a CryptoStream using the MemoryStream
                // and the passed key and initialization vector (IV).
                CryptoStream csDecrypt = new CryptoStream(msDecrypt,
                    new TripleDESCryptoServiceProvider().CreateDecryptor(Key, IV),
                    CryptoStreamMode.Read);

                // Create buffer to hold the decrypted data.
                byte[] fromEncrypt = new byte[Data.Length];

                // Read the decrypted data out of the crypto stream
                // and place it into the temporary buffer.
                csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);

                //Convert the buffer into a string and return it.
                string ReturnValue = new ASCIIEncoding().GetString(fromEncrypt);
                if (ReturnValue.Contains("\0\0\0"))
                {
                    ReturnValue = ReturnValue.Remove(ReturnValue.IndexOf("\0\0\0"));
                }
                return ReturnValue;
            }
            catch (CryptographicException e)
            {
                Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
                return null;
            }
        }
예제 #2
0
        private void setButtons_labels()
        {
            byte x = 0;
            byte mbc = rom[0x0147];
            for(int i=0x0134; i<=0x014C; i++)
            {
                x = (byte)(x-rom[i]-1);
            }
            if(x == rom[0x014D])
            {
                DumpROM_b.Enabled = true;
                if(mbc == 0x03 || mbc == 0x06 || mbc == 0x09 || mbc == 0x0D || mbc == 0x0F || mbc == 0x10 || mbc == 0x13 || mbc == 0x17 || mbc == 0x1B || mbc == 0x1E || mbc == 0xFF)
                {
                    DumpRAM_b.Enabled = true;
                    WriteRAM_b.Enabled = true;
                }

                switch(rom[0x0148])
                {
                    case 0: { banks = 2; break; }
                    case 1: { banks = 4; break; }
                    case 2: { banks = 8; break; }
                    case 3: { banks = 16; break; }
                    case 4: { banks = 32; break; }
                    case 5: { if(mbc <= 3) banks = 63; else banks = 64; break; }
                    case 6: { if(rom[0x147] <= 3) banks = 125; else banks = 128; break; }
                    case 7: { banks = 255; break; }
                    default: break;
                }

                Banks_l.Text = "Banks: " + banks.ToString();

                byte[] Title = new byte[16];
                for (int i = 0; i < 16; i++)
                    Title[i] = rom[0x0134 + i];
                //System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
                //System.Text.UTF8Encoding
                ROM_Title = new System.Text.ASCIIEncoding().GetString(Title);
                if(ROM_Title.LastIndexOf('?') != -1)
                    ROM_Title.Remove(ROM_Title.LastIndexOf('?') - 4);
                System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding();
                Title_l.Text = "Title: " + enc.GetString(Title);

                rom_size = rom[0x0148];
                byte ram_size = rom[0x0149];

                switch (rom[0x0148])
                {
                    case 0x00: {Size_l.Text = "Size: 32 KBytes"; rom = new byte[32768]; break;}
                    case 0x01: {Size_l.Text = "Size: 64 KBytes"; rom = new byte[65536]; break;}
                    case 0x02: {Size_l.Text = "Size: 128 KBytes"; rom = new byte[131072]; break;}
                    case 0x03: {Size_l.Text = "Size: 256 KBytes"; rom = new byte[262144]; break;}
                    case 0x04: {Size_l.Text = "Size: 512 KBytes"; rom = new byte[524288]; break;}
                    case 0x05: {Size_l.Text = "Size: 1 MBytes"; rom = new byte[1048576]; break;}
                    case 0x06: {Size_l.Text = "Size: 2 MBytes"; rom = new byte[2097152]; break;}
                    case 0x07: {Size_l.Text = "Size: 4 MBytes"; rom = new byte[4194304]; break;}
                    case 0x52: {Size_l.Text = "Size: 1.1 MBytes"; rom = new byte[32768]; break;}
                    case 0x53: {Size_l.Text = "Size: 1.2 MBytes"; rom = new byte[32768]; break;}
                    case 0x54: { Size_l.Text = "Size: 1.5 MBytes"; rom = new byte[1572864]; break; }
                }

                switch (ram_size)
                {
                    case 0x00: {RAM_l.Text = "RAM Size: None"; break;}
                    case 0x01: {RAM_l.Text = "RAM Size: 2 KBytes"; RAM = new byte[2048]; break;}
                    case 0x02: {RAM_l.Text = "RAM Size: 8 KBytes"; RAM = new byte[8192]; break;}
                    case 0x03: { RAM_l.Text = "RAM Size: 32 KBytes"; RAM = new byte[32768]; break; }
                }

                MBC_l.Text = "MBC: None";
                if (mbc <= 0x03 && mbc > 0x00)
                    MBC_l.Text = "MBC: MBC1";
                if(mbc <= 0x06 && mbc > 0x03)
                    MBC_l.Text = "MBC: MBC2";
                if(mbc <= 0x13 && mbc > 0x0D)
                    MBC_l.Text = "MBC: MBC3";
                if(mbc <= 0x17 && mbc > 0x13)
                    MBC_l.Text = "MBC: MBC4";
                if(mbc <= 0x0D && mbc > 0x09)
                    MBC_l.Text = "MBC: MMM01";
                if(mbc <= 0x1E && mbc > 0x17)
                    MBC_l.Text = "MBC: MBC5";
                if(mbc == 0xFD)
                    MBC_l.Text = "MBC: BANDAI TAMA5";
                if(mbc == 0xFE)
                    MBC_l.Text = "MBC: HuC3";
                if(mbc == 0xFF)
                    MBC_l.Text = "MBC: HuC1";
                if(mbc == 0xFC)
                    MBC_l.Text = "MBC: POCKET CAMERA";
            }
        }
예제 #3
0
파일: SX1276.cs 프로젝트: kaaLabs15/LoRa
 public bool SKGetVersion()
 {
     lock (syncThread)
     {
         byte local_0 = (byte)1;
         SX1276.HidCommandsStatus local_1 = SX1276.HidCommandsStatus.SX_ERROR;
         ulong local_2 = ulong.MaxValue;
         byte[] local_3 = new byte[17];
         byte[] local_4 = new byte[2];
         try
         {
             usbDevice.TxRxCommand(local_0, local_4, ref local_3);
             local_1 = (SX1276.HidCommandsStatus)local_3[0];
             local_2 = (ulong)((long)local_3[1] << 56 | (long)local_3[2] << 48 | (long)local_3[3] << 40 | (long)local_3[4] << 32 | (long)local_3[5] << 24 | (long)local_3[6] << 16 | (long)local_3[7] << 8) | (ulong)local_3[8];
             if (local_1 != SX1276.HidCommandsStatus.SX_OK || (int)local_3[9] < 5)
                 return false;
             Array.Copy((Array)local_3, 10, (Array)local_3, 0, (int)local_3[9]);
             Array.Resize<byte>(ref local_3, (int)local_3[9]);
             string local_6 = new ASCIIEncoding().GetString(local_3);
             fwVersion = local_6.Length <= 5 ? new Version(local_6) : new Version(local_6.Remove(4, 1));
             return true;
         }
         finally
         {
             Console.WriteLine("{0} ms: {1} with status {2}", (object)local_2, (object)Enum.GetName(typeof(SX1276.HidCommands), (object)(SX1276.HidCommands)local_0), (object)Enum.GetName(typeof(SX1276.HidCommandsStatus), (object)local_1));
         }
     }
 }
예제 #4
0
파일: SX1276LR.cs 프로젝트: kaaLabs15/LoRa
        /// <summary>
        ///	[Status(U8)][Timeout(U32)][Length(U8)][Version(U8 * Length)]
        /// </summary>
        /// <returns></returns>
        public bool SKGetVersion()
        {
            lock (syncThread)
            {
                byte command = (byte)HidCommands.HID_SK_GET_VERSION;
                SX1276LR.HidCommandsStatus status = SX1276LR.HidCommandsStatus.SX_ERROR;
                ulong timeout = ulong.MaxValue;
                byte[] inData = new byte[17];
                byte[] outData = new byte[2];
                try
                {
                    usbDevice.TxRxCommand(command, outData, ref inData);
                    status = (SX1276LR.HidCommandsStatus)inData[0];
                    timeout = ((ulong)inData[1] << 56 | (ulong)inData[2] << 48 | (ulong)inData[3] << 40 | (ulong)inData[4] << 32 | (ulong)inData[5] << 24 | (ulong)inData[6] << 16 | (ulong)inData[7] << 8 | (ulong)inData[8]);
                    if (status != SX1276LR.HidCommandsStatus.SX_OK || inData[9] < 5)
                        return false;

                    Array.Copy(inData, 10, inData, 0, inData[9]);
                    Array.Resize<byte>(ref inData, inData[9]);
                    string version = new ASCIIEncoding().GetString(inData);
                    fwVersion = version.Length <= 5 ? new Version(version) : new Version(version.Remove(4, 1));
                    return true;
                }
                finally
                {
                    Console.WriteLine(
                        "{0} ms: {1} with status {2}",
                        timeout,
                        Enum.GetName(typeof(SX1276LR.HidCommands), (SX1276LR.HidCommands)command),
                        Enum.GetName(typeof(SX1276LR.HidCommandsStatus), status)
                        );
                }
            }
        }