GammaLoader V1.0 SourceCode

First thing to Know is that this software is coded by VS.NET 2005.
In the C# Language. As what KILDIN said.

Here is the Main thing we want to know or we going to need :

- The Resources File which is "GammaLoader.osupdate.txt" as what GreekSatid found.
- Procedure Name "bnLoad_Click" which is for load this File in the Nova_20070225.gam, and this File is written by Library Called XML.
- Procedure Name " bnCleancard_Click " which is for Cleaning the Card.
- Procedure Name "bnProgram_Click" which is For Programme the Card.
- Function Name "ReadATR" which will return the ATR of the Card, and this is the Check routine for the Card.
- Function Name "SendData" which in need in the main procedure.
- Function Name " SendString" which in need in the main procedure.
- Procedure Name "SendCMDs" Which is the Main Procedure of the Software.

All Other Procedure or function is from the VS.NET 2005 Designer or not that important.

Debug the Main procedure will Comment out every thing step by step:

// The main Procedure Here will be Called From the "bnProgram_Click" .. so the
// input inputObject as an object will be the List of Array of this Variable
" private ArrayList CardCMDs;" and this variables will be set in "bnLoad_Click"
Which is the 4 string we have seen before will Explain How the File Work Below.

private void SendCMDs(object inputObject)
{
// we have a variables Called "inputObject" which is the array list of : Control = [0], Command Line Arguments to send to the Card = [1], event for the status control = [2], event for the Progress bar = [3], and event to end the thread = [4].

// also the variables Scope are here which we will used it only inside this procedure.
ContainerControl control1 = null; // this control from VS.NET which is status label and the progress Bar.
object[] objArray1 = (object[]) inputObject; // here we will set inputObject to an object array
Delegate delegate1 = (Delegate) objArray1[2]; // this will changed or update the text we have seen in the status Like " Not Cleaned. Card has no ATR ".
Delegate delegate2 =  (Delegate) objArray1[3]; // this will changed or update the progress bar.
Delegate delegate3 = (Delegate) objArray1[4]; // this one will Enable or Disable the Control in the programme.
ArrayList list1 = (ArrayList) objArray1[1]; // we will set the CMD or Command line argument from the File to list1.
ArrayList list2 = new ArrayList(); // we will set the Resources Text File into this list2 .. when we need to update the OS of the Card.
control1 = (Form) objArray1[0]; // it just to set the control to refresh them or changed their value.
byte[] buffer1 = new byte[] { 2, 1, 0, 0, 0, 0x10, 0xd8, 0xde, 0x4a, 0x9a, 50, 160, 0x3d, 0xba, 0x5c, 0x73, 0x26, 0xbf, 0x3d, 0xf7, 0xeb, 0x70}; // the cleaning byte of the cards.
string text1 = ""; // we going to use it inside this as a variables.

      // the Check routine here is for when the user changed "6 MHz" true or false simply will changed the Baud Rate of the Serial Ports.
      if (this.chkBx6Mhz.Checked)
      {
            // we will get here when the "this.chkBx6Mhz" is equal to true.
            this.serialPort1.BaudRate = 0x2580;
      }
      else
      {
            // we will get here when the "this.chkBx6Mhz" is equal to false.
            this.serialPort1.BaudRate = 0x1658;
      }

     // here we will open the port let say it's : Com1
     this.serialPort1.Open();

      // Here the try it is a reserved word in VS.NET it must be followed with catch or finally.
      try
      {
                // here we will set the Max = 100 , Min = 0 to the progress bar Properties.
    control1.Invoke(delegate2, new object[] { 100, 0 });
       
                // here we will set the status label into " Getting ATR ".
                control1.Invoke(delegate1, new object[] { "Getting ATR" });
       
                text1 = this.ReadATR(); // here we will set the ATR of the Card to the text1.
           


               // check routine .
               if ((text1.Length > 0) && (text1.Substring(0, 0x1c) != "3B9F210E47414D4D414341524420"))
               {
                   // we will get here if the text1 is not empty and the card is not clean.
                   control1.Invoke(delegate1, new object[] { "cleaning Card" }); // here will set the status to " cleaning Card ".
                   this.SendString(buffer1, buffer1.Length); // here we will send the cleaning byte to the Cards.
               }
            text1 = this.ReadATR(); // Now we will read the ATR of the Cards again which will be clean.
            // Here we will check if the text1 is not empty. If it is empty we will get this "Card has no ATR".
            if (text1.Length > 0)
            {
    // we will get here if the text1 is not empty .
    // if the ATR we have got from the card is equal to "3B9F210E47414D4D414341524420". If not we will // get this " This is not a Gammacard. The Card ATR is "
                if (text1.Substring(0, 0x1c) == "3B9F210E47414D4D414341524420")
                {
                      control1.Invoke(delegate1, new object[] { "Card is empty" }); // we will set the status  to " Card is empty ".
                      control1.Invoke(delegate2, new object[] { list1.Count - 1, 0 }); // we will set the progress bar with // the command line argument length or size Now a checking statement which will seek this index "312E31" and report back the value if it is Higher than zero .. we will get inside the if, to update the Card OS fro the Resources Text.
                      if (text1.IndexOf("312E31") > 0)
                      {
                          control1.Invoke(delegate1, new object[] { "Card is beeing updated" }); // here will set the status to " Card is beeing updated ".

                          Stream stream1 = Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name.ToString() + ".osupdate.txt"); // here we will open the resources Text file which have a hexadecimal values to update the OS of the Card.
                          StreamReader reader1 = new StreamReader(stream1);
              // the while loop is to read the file line by line and we will set the value of it to our variables list2.
                          while ((text1 = reader1.ReadLine()) != null)
                          {
                                list2.Add(text1); // here we will add each line from the resouces text to our list2.
                          }
              // the for loop here we will send the data from the list2 one by one to the Card.
                          for (int num1 = 0; num1 < list2.Count; num1++)
                          {
                                text1 = this.SendData(list2[num1].ToString());
                                control1.Invoke(delegate2, new object[] { list2.Count - 1, num1 }); // update the progress Bar .
                                control1.Invoke(delegate1, new object[] { "Updating Card" }); update or change the status lable into "Updating Card".
                                Thread.Sleep(500); // just not to kill the performance of the software while we are still in the loop it is really heavy one.
                          }
              // this loop is for a user inform not that important.
                          for (int num2 = 30; num2 > 0; num2--)
                          {
                                control1.Invoke(delegate1, new object[] { "Card is working. Please wait. (" + num2.ToString() + ")" }); // just a user inform.
                                Thread.Sleep(0x3e8); // just not to kill the performance of the software while we are still in the loop it is really heavy one.
                          }
                          this.ReadATR(); // Now We will read the ATR of the Card if it fails the port Will close.
                          control1.Invoke(delegate1, new object[] { "Update is done" }); // update or change status lable
                        }
         // the for loop here we will gonna through the Command line Argument one by one
         // Send them to the Cards.
                     for (int num3 = 0; num3 < list1.Count; num3++)
                     {
                          text1 = this.SendData(list1[num3].ToString()); // here is the function which will send the CMD.
                          control1.Invoke(delegate2, new object[] { list1.Count - 1, num3 }); // update or change progress bar.
                          control1.Invoke(delegate1, new object[] { "Programming Card" });// update or change status.
              // here is a check statement if the text1 which is the return from " this.SendData" is empty, then we will see a " Card Timeout " and we will exit from the loop here.
                          if (text1 == "")
                          {
                               control1.Invoke(delegate1, new object[] { "Card Timeout" });
                               break;
                          }
                     }
                     control1.Invoke(delegate1, new object[] { "Successfully programmed" }); // Update or change the status.
                  }
                  else
                  {
            // we will get here if the text1 above is an empty.
                        control1.Invoke(delegate1, new object[] { "This is not a Gammacard. The Card ATR is " + text1 });
                  }   
            }
            else
            {
                  // we will get here if the text1 above is an empty.
    control1.Invoke(delegate1, new object[] { "Card has no ATR" });
            }
      }
      finally
      {
            this.serialPort1.Close(); // we will get here if this procedure is end or catche's an error.
      }
      control1.Invoke(delegate3); // here we will Enable the Control or button in the form.
}

}

Now the Read ATR Function which will be called from the Main Procedure:

private string ReadATR()
{
      // Here is the variable Scope.
      string text1 = ""; // we will use it to return back the Card ATR.
      byte[] buffer1 = new byte[0x100]; // buffer to read the the Data from the Card.
      this.serialPort1.RtsEnable = true; // I Suppose every body know what does : RTS, Mean.
      this.serialPort1.DiscardOutBuffer(); // don't know yet. but it is a reserved Words.
      this.serialPort1.DiscardInBuffer(); // don't know yet. but it is a reserved Words.
      this.serialPort1.RtsEnable = false;
      this.serialPort1.ReadTimeout = 0x3e8; // this the read time out to close the Port when we reach thisa Time in Hexadecimal.
      try
      {
            // The loop here is gonna read the data from the serial port which is Programmer that have the GammaCard on it.
            for (int num1 = 0; num1 < 0x20; num1++)
            {
                  this.serialPort1.Read(buffer1, 0, 1); // here we will read the data from the serial ports.
                  text1 = text1 + buffer1[0].ToString("X2"); // here we will set the two Hexadecimal to the text1 while we are in the loop. 
            }
      }
      catch
      {
      }
      return text1; // here we will return back the string we have got from the card which is the Card ATR.
}


Now SendData Function which will be called from the Main Procedure:

private string SendData(string DataOut)
{
      string text1 = ""; // we will use it to set our buffer.
      byte[] buffer1 = new byte[0x100]; // buffer to read from the serial ports.
      // the loop here to set the buffer from the DataOut.
      for (int num1 = 0; num1 < (DataOut.Length >> 1); num1++)
      {
            text1 = DataOut[num1 * 2].ToString();
            text1 = text1 + DataOut[(num1 * 2) + 1].ToString();
            buffer1[num1] = byte.Parse(text1, NumberStyles.HexNumber);
      }
      return this.SendString(buffer1, DataOut.Length >> 1); // we will call function name "SendString" which will return the string. also we will send our variables between () to it.
}

Now SendString Function wich will be called from the above.

private string SendString(byte[] Output, int OutLength)
{
      string text1 = "";
      byte[] buffer1 = new byte[0x100];
      this.serialPort1.Write(Output, 0, OutLength); // here we will send the data to the serial port or actually to the card.
      buffer1[0] = 0x3f; // here we will set the buffer zero into 0x3f.
      // here a loop which i didn't understand it very well. at least now.
      for (int num1 = 0; num1 < OutLength; num1++)
      {
            buffer1[0] = (byte) (buffer1[0] ^ Output[num1]); // buffer[0] XOR Output[num1] and Converted to byte.
      }
      this.serialPort1.Write(buffer1, 0, 1); // here we will send the data to the serial port or actually to the card.
      try
      {
            this.serialPort1.ReadTimeout = 0x1388; // here we will set the read time out to 0x1388.
           
            for (int num2 = 0; num2 < 0xff; num2++)
            {
                  this.serialPort1.Read(buffer1, num2, 1); // here we will read the byte from the serial port every time num2 changed until this number 0xff.
                  text1 += buffer1[num2].ToString("X2") + " "; // here we will set two Hexadecimal to the text every time num2 changed until this number 0xff.
      // Check statement if num2 is equal to OutLength then Clear text1.
                  if (num2 == OutLength)
                  {
                        text1 = "";
                  }
      // Check statement if num2 is higher than OutLength plus 3 then change the Read Time out to 100.
                  if (num2 > (OutLength + 3))
                  {
                        this.serialPort1.ReadTimeout = 100;
                  }
            }
      }
      catch
      {
      }
      return text1;  // here we will return back the string or hexadecimal we have got from the above procedure.
}

- About the button Load File .

All we need to know is just that is gonna read the File ...
and all the String or Hexadecimal Value in this Section between <cmd> Hexadecimal values </cmd> in either Nova_20070225.gam, Showtime_20070225.gam or any new file.
will be set into this public Variables : CardCMDs;

- Now the Clean Button :

private void bnCleancard_Click(object sender, EventArgs e)
{
      this.edtStatus.Text = ""; // we will set the Status Lable to empty.
      string text1 = ""; // we will need's it below.
      byte[] buffer1 = new byte[] { 2, 1, 0, 0, 0, 0x10, 0xd8, 0xde, 0x4a, 0x9a, 50, 160, 0x3d, 0xba, 0x5c, 0x73, 0x26, 0xbf, 0x3d, 0xf7, 0xeb, 0x70}; // this byte array is to clean the card which the same as the one we can found in the main procedure.
      // Check Statement the same as the one we can found in the main procedure.
      if (this.chkBx6Mhz.Checked)
      {
            this.serialPort1.BaudRate = 0x2580;
      }
      else
      {
            this.serialPort1.BaudRate = 0x1658;
      }
      this.serialPort1.PortName = this.cBxPort.Text.ToString(); // here we will set the port name properties.
      this.serialPort1.Open(); // here we will open the port.
      try
      {
            this.ReadATR(); // here we will read the Card ATR.
            this.SendString(buffer1, buffer1.Length); // here we will send the Cleaning byte to the Card.
            text1 = this.ReadATR(); // here we will read the Card ATR Again after we have Cleaned it.
            // Check Statement if the text1 is empty then we will see "Not Cleaned. Card has no ATR" in the status.
            if (text1.Length > 0)
            {
                  // Check Statement if the text1 from 0 to 0x1c .. is equal to "3B9F210E47414D4D414341524420" then we will see the "Card Cleaned" in the status otherwise "Not Cleaned. The Card ATR is" .
                  if (text1.Substring(0, 0x1c) == "3B9F210E47414D4D414341524420")
                  {
                        this.edtStatus.Text = "Card Cleaned";
                  }
                  else
                  {
                        this.edtStatus.Text = "Not Cleaned. The Card ATR is " + text1;
                  }
            }
            else
            {
                  // we will get here if the text1 is empty.
                  this.edtStatus.Text = "Not Cleaned. Card has no ATR";
            }
      }
      finally
      {
            // we will get here if the above procedure is done.
            this.serialPort1.Close();
      }
}

Sie besitzen nicht die Berechtigung, diese Datei herunterzuladen...

Um die datei zu Downloaden Loggen Sie sich im System ein, oder Regestrieren sie sich neu.


Möchten Sie sich neu registrieren? System Login


Sie k?nnen keine Kommentare abgeben!