Advertisement
Guest User

Untitled

a guest
Aug 27th, 2014
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10.  
  11. namespace _3DS_Rom_Decryptor_Key_Generator
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         string FileLocation;
  21.         string aesString;
  22.         string ctrString;
  23.         byte[] aes = new byte[16];
  24.         byte[] titleID = new byte[8];
  25.         private void button1_Click(object sender, EventArgs e)
  26.         {
  27.             OpenFileDialog ofd = new OpenFileDialog();
  28.             ofd.Filter = "3DS Rom File (*.3ds)|*.3ds|Gateway 3DS 3DZ Rom File (*.3dz)|*.3dz";
  29.             if (ofd.ShowDialog() == DialogResult.OK)
  30.             {
  31.                 FileLocation = ofd.FileName;
  32.             }
  33.         }
  34.  
  35.         private void button2_Click(object sender, EventArgs e)
  36.         {
  37.             if (comboBox1.SelectedIndex != -1)
  38.             {
  39.                 GetKey();
  40.             }
  41.             else
  42.             {
  43.                 MessageBox.Show("Please select an archive type.");
  44.             }
  45.         }
  46.  
  47.         private void GetKey()
  48.         {
  49.             aesString = "";
  50.             ctrString = "";
  51.             FileStream fs = new FileStream(FileLocation, FileMode.Open);
  52.             fs.Seek(0x4000, SeekOrigin.Begin);
  53.             fs.Read(aes, 0, 16);
  54.             fs.Seek(0x4108, SeekOrigin.Begin);
  55.             fs.Read(titleID, 0, 8);
  56.             aesString = aes[3].ToString("X2") + aes[2].ToString("X2") + aes[1].ToString("X2") + aes[0].ToString("X2")
  57.                 + " " + aes[7].ToString("X2") + aes[6].ToString("X2") + aes[5].ToString("X2") + aes[4].ToString("X2")
  58.                 + " " + aes[11].ToString("X2") + aes[10].ToString("X2") + aes[9].ToString("X2") + aes[8].ToString("X2")
  59.                 + " " + aes[15].ToString("X2") + aes[14].ToString("X2") + aes[13].ToString("X2") + aes[12].ToString("X2");
  60.             ctrString = titleID[4].ToString("X2") + titleID[5].ToString("X2") + titleID[6].ToString("X2") + titleID[7].ToString("X2")
  61.                 + " " + titleID[0].ToString("X2") + titleID[1].ToString("X2") + titleID[2].ToString("X2") + titleID[3].ToString("X2");
  62.             switch (comboBox1.SelectedIndex)
  63.             {
  64.                 case 0:
  65.                     ctrString += " 00000001 00000000";
  66.                     break;
  67.                 case 1:
  68.                     ctrString += " 00000002 00000000";
  69.                     break;
  70.                 case 2:
  71.                     ctrString += " 00000003 00000000";
  72.                     break;
  73.             }
  74.             textBox1.Text = "AES Key: " + aesString + Environment.NewLine + "CTR Key: " + ctrString;
  75.             button3.Enabled = true;
  76.             fs.Close();
  77.         }
  78.  
  79.         private void button3_Click(object sender, EventArgs e)
  80.         {
  81.             SaveFileDialog sfd = new SaveFileDialog();
  82.             sfd.Filter = "Text file (*.txt)|*.txt";
  83.             if (sfd.ShowDialog() == DialogResult.OK)
  84.             {
  85.                 StreamWriter sw = new StreamWriter(sfd.FileName);
  86.                 sw.Write(textBox1.Text);
  87.                 sw.Close();
  88.             }
  89.         }
  90.  
  91.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  92.         {
  93.             if (comboBox1.SelectedIndex != -1)
  94.             {
  95.                 button2.Enabled = true;
  96.             }
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement