//fixAddr:要修复的地址 //hashAddr:使用的hash的地址xiuf //stepLen:修复滚步步长 //times:目标次数 void FixDataBlock(uint8_t fixAddr, uint8_t hashAddr, uint16_t stepLen, uint8_t loopTimes, uint8_t leftTiems) { uint8_t i; RomData_ReadBytes(hashAddr, ref RomDatas, 8); if ((loopTimes != 0) && (stepLen != 0)) { for (i = 0; i < 8; i++) { lcyHashIn[i] = RomDatas[7 - i]; } // for (i = 0; i < loopTimes; i++) // { // //lcyHashIn=LCYHashCal.HashCal(lcyHashIn, stepLen); // HashCalc_N(stepLen); // } // for (i = 0; i < 8; i++) // { // RomDatas[7 - i] = lcyHashOut[i]; // } for (i = 0; i < loopTimes; i++) { lcyHashIn = LCYHashCal.HashCal(lcyHashIn, stepLen); } for (i = 0; i < 8; i++) { RomDatas[7 - i] = lcyHashIn[i]; } } RomDatas[8] = leftTiems; RomDatas[9] = Verify.GetVerify_byteXOR(RomDatas, 9); //GetVerify_byteXOR(RomDatas,9); RomData_WriteBytes(fixAddr, RomDatas, 10); //写入当前次数段,且使其匹配 }
void GetKeyParam() { uint8_t i, x; RomData_ReadBytes(0x9e, ref RomDatas, 2); if ((RomDatas[0] == 0xff && RomDatas[1] == 0xff) || (RomDatas[0] == 0x00 && RomDatas[1] == 0x00)) //尚未初始化 { BAT_ON(); RomDatas[0] = ROM_9E; RomDatas[1] = ROM_9F; RomData_WriteBytes(0x9e, RomDatas, 2); //初始化ROM版本 } RomData_ReadBytes(0x9e, ref RomDatas, 2); x = RomDatas[0]; x += RomDatas[1]; // RomStateFlags.bRomWrited = 0; // RomStateFlags.bStudy = 0; // if (x != 0) // NVIC_SystemReset();//存储区无法初始化,系统复位 // if (GetBit(RomDatas[0], 2) != 0)//写过了 // { // RomStateFlags.bRomWrited = 1; // } // if (GetBit(RomDatas[0], 4) != 0)//学习过 // { // RomStateFlags.bStudy = 1; // } // if (RomStateFlags.bRomWrited)//写过了,获取系统参数 // { EE00 = RomData_ReadByte(0x00); EE00 >>= 6; RomData_ReadBytes(0x01, ref PSW, 8); RomData_ReadBytes(0x09, ref SSID, 4); //使用次数低位 //获得69~70存储区中第一个不为0xff的单元,其数据为计算次数 //70-6f-6e-6d-6c-6b-6a-69-70 GetCalcTimes69(); //使用次数高位 GetLeftTimeBlock(LeftTimesH); //使用次数中位 GetLeftTimeBlock(LeftTimesM); //使用次数低位所用段,同时找到当前hash GetLeftTimeBlock(LeftTimesL); RomData_ReadBytes(LeftTimesAddr[LeftTimesL], ref RomDatas, 8); x = (uint8_t)(LeftTimes69 & 0x03); if (x == 0) { for (i = 0; i < 8; i++) { curHash[i] = RomDatas[7 - i]; } } else { for (i = 0; i < 8; i++) { lcyHashIn[i] = RomDatas[7 - i]; } //lcyHashCalc(x); lcyHashOut = LCYHashCal.HashCal(lcyHashIn, x); for (i = 0; i < 8; i++) { curHash[i] = lcyHashOut[i]; } } int step = LeftTimes[LeftTimesH] * 32 * 128 + LeftTimes[LeftTimesM] * 128 + LeftTimes69; byte[] need = needHash[step]; for (int ww = 0; ww < 8; ww++) { if (curHash[ww] != need[ww]) { bExit = true; MessageBox.Show("出错了"); break; } } this.Invoke((EventHandler)(delegate { textBox1.Text = step.ToString(); //progressBar1.PerformStep(); })); }