Form1.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms;
  4. namespace FileAnalysis
  5. {
  6. public partial class Form1 : Form
  7. {
  8. public Form1()
  9. {
  10. InitializeComponent();
  11. }
  12. private void Analysis_Click(object sender, EventArgs e)
  13. {
  14. Result.Clear();
  15. int[] list = GetDecimalData(ReturnData.Text, new int[] { 8, 8, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4 }, new int[] { 6 });
  16. for (int i = 0; i < list.Length; i++)
  17. {
  18. Result.AppendText(list[i] + "\n");
  19. }
  20. }
  21. public static int[] GetDecimalData(string HexStr, int[] DataSize, int[] NotShow)
  22. {
  23. List<int> ReturnData = new List<int>();
  24. try
  25. {
  26. //去除前面的指令字符和数据长度字符
  27. HexStr = HexStr.Replace(":", "");
  28. if (HexStr != "")
  29. {
  30. int ValueDataSize = Convert.ToInt32("0x" + (HexStr.Substring(4, 2)), 16) * 2;
  31. string RealData = HexStr.Substring(6);
  32. RealData = RealData.Substring(0, ValueDataSize);
  33. int SubIndex = 0;
  34. for (int i = 0; i < DataSize.Length; i = i + 1)
  35. {
  36. if (SubIndex + DataSize[i] < RealData.Length)
  37. {
  38. bool notshow = false;
  39. for (int j = 0; j < NotShow.Length; j++)
  40. {
  41. if (i == NotShow[j])
  42. notshow = true;
  43. }
  44. if (notshow)
  45. {
  46. SubIndex += DataSize[i];
  47. continue;
  48. }
  49. if (DataSize[i] == 8)
  50. {
  51. Console.WriteLine("0x" + (RealData.Substring(SubIndex, DataSize[i]).Substring(4, 4)) + (RealData.Substring(SubIndex, DataSize[i]).Substring(0, 4)));
  52. ReturnData.Add(Convert.ToInt32("0x" + (RealData.Substring(SubIndex, DataSize[i]).Substring(4, 4)) + (RealData.Substring(SubIndex, DataSize[i]).Substring(0, 4)), 16));
  53. }
  54. else if (DataSize[i] == 4)
  55. {
  56. Console.WriteLine("0x" + (RealData.Substring(SubIndex, DataSize[i])));
  57. ReturnData.Add(Convert.ToInt32("0x" + (RealData.Substring(SubIndex, DataSize[i])), 16));
  58. }
  59. }
  60. SubIndex += DataSize[i];
  61. }
  62. }
  63. }
  64. catch (Exception ex)
  65. {
  66. Console.WriteLine(ex.Message);
  67. }
  68. return ReturnData.ToArray();
  69. }
  70. private void Form1_Load(object sender, EventArgs e)
  71. {
  72. }
  73. }
  74. }