2016-09-26 17:25:22 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "patcher.h"
|
2017-08-22 10:11:31 +00:00
|
|
|
#include <stdlib.h>
|
2016-09-26 17:25:22 +00:00
|
|
|
|
|
|
|
//***********************************************************************
|
|
|
|
//* Поиск сигнатуры и наложение патча
|
2017-08-22 10:11:31 +00:00
|
|
|
//*
|
|
|
|
//* ptype=0 - nop-патч
|
|
|
|
//* ptype=1 - br-патч
|
2016-09-26 17:25:22 +00:00
|
|
|
//***********************************************************************
|
2017-08-22 10:11:31 +00:00
|
|
|
uint32_t patch(struct defpatch fp, uint8_t* buf, uint32_t fsize, uint32_t ptype) {
|
2016-09-26 17:25:22 +00:00
|
|
|
|
|
|
|
// накладываемый патч - mov r0,#0
|
|
|
|
const char nop0[4]={0, 0, 0xa0, 0xe3};
|
|
|
|
uint32_t i;
|
2017-08-22 10:11:31 +00:00
|
|
|
uint8_t c;
|
2016-09-26 17:25:22 +00:00
|
|
|
|
|
|
|
for(i=8;i<(fsize-60);i+=4) {
|
|
|
|
if (memcmp(buf+i,fp.sig, fp.sigsize) == 0) {
|
|
|
|
// найдена сигнатура - накладываем патч и уходим
|
2017-08-22 10:11:31 +00:00
|
|
|
switch (ptype) {
|
|
|
|
case 0:
|
|
|
|
memcpy(buf+i+fp.sigsize+fp.poffset,nop0,4);
|
|
|
|
return i;
|
|
|
|
|
2017-09-14 14:57:34 +00:00
|
|
|
case 1:
|
|
|
|
c=*(buf+i+fp.sigsize+fp.poffset);
|
|
|
|
c|=0xe0;
|
|
|
|
*(buf+i+fp.sigsize+fp.poffset)=c;
|
|
|
|
return i;
|
|
|
|
|
2017-08-22 10:11:31 +00:00
|
|
|
default:
|
2017-09-14 14:57:34 +00:00
|
|
|
exit(11);
|
|
|
|
}
|
2016-09-26 17:25:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// сигнатрура не найдена
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//**********************************************
|
|
|
|
// Описатели патчей
|
|
|
|
//**********************************************
|
|
|
|
|
2017-08-22 10:11:31 +00:00
|
|
|
const char sigburn_v7r22[]={
|
|
|
|
0x12, 0x3B, 0xA0, 0xE3, 0x4A, 0x35, 0x4A, 0xE3, 0x00, 0x20, 0xA0, 0xE3,
|
|
|
|
0x78, 0x20, 0xC3, 0xE5, 0x79, 0x20, 0xC3, 0xE5, 0x7A, 0x20, 0xC3, 0xE5,
|
|
|
|
0x7B, 0x20, 0xC3, 0xE5, 0x00, 0x00, 0xA0, 0xE3};
|
|
|
|
|
2017-09-14 14:57:34 +00:00
|
|
|
const char sigburn_v7r22_2[]={
|
|
|
|
0x18, 0x30, 0x94, 0xE5, 0x10, 0x20, 0x94, 0xE5, 0x0D, 0x00, 0xA0, 0xE1,
|
|
|
|
0x30, 0x40, 0x84, 0xE2, 0x14, 0x30, 0x8D, 0xE5, 0x10, 0x20, 0x8D, 0xE5};
|
|
|
|
|
2019-07-03 11:34:51 +00:00
|
|
|
const char sigburn_v7r22_3[]={
|
|
|
|
0x10, 0x30, 0x94, 0xE5, 0x0D, 0x00, 0xA0, 0xE1, 0x10, 0x30, 0x8D, 0xE5,
|
|
|
|
0x18, 0x30, 0x94, 0xE5, 0x14, 0x30, 0x8D, 0xE5};
|
|
|
|
|
2016-09-26 17:25:22 +00:00
|
|
|
const char sigburn_v7r11[]={
|
|
|
|
0x00, 0x00, 0x50, 0xE3, 0x70, 0x80, 0xBD, 0x08, 0x00, 0x30, 0xA0, 0xE3,
|
|
|
|
0x4E, 0x26, 0x04, 0xE3, 0xE0, 0x3F, 0x44, 0xE3, 0x55, 0x22, 0x44, 0xE3,
|
|
|
|
0x4C, 0x01, 0x9F, 0xE5, 0x4E, 0xC6, 0x04, 0xE3, 0x48, 0x41, 0x9F, 0xE5,
|
|
|
|
0x02, 0x10, 0xA0, 0xE1, 0x4C, 0xC4, 0x44, 0xE3, 0x5C, 0x23, 0x83, 0xE5,
|
|
|
|
0x00, 0x00, 0x8F, 0xE0, 0x40, 0xC3, 0x83, 0xE5};
|
|
|
|
|
|
|
|
const char sigburn_v7r2[]={
|
|
|
|
0x00, 0x30, 0xA0, 0xE3, 0x9A, 0x3F, 0x07, 0xEE, 0xFF, 0x2F, 0x0F, 0xE3,
|
|
|
|
0xE1, 0x2F, 0x44, 0xE3, 0x07, 0x30, 0x02, 0xE5, 0x9A, 0x3F, 0x07, 0xEE,
|
|
|
|
0x00, 0x40, 0xA0, 0xE3, 0xE0, 0x4F, 0x44, 0xE3, 0x4E, 0x36, 0x04, 0xE3,
|
|
|
|
0x4C, 0x34, 0x44, 0xE3, 0x30, 0x33, 0x84, 0xE5};
|
2016-10-07 19:22:14 +00:00
|
|
|
|
|
|
|
const char sigburn_v7r1[]={
|
|
|
|
0x3D, 0xE2, 0xE0, 0xE3, 0x00, 0xE0, 0x9E, 0xE5, 0x5C, 0xC3, 0x9F, 0xE5,
|
|
|
|
0x0C, 0x00, 0x5E, 0xE1, 0x00, 0x00, 0x00, 0x0A};
|
2016-09-26 17:25:22 +00:00
|
|
|
|
|
|
|
const char sigbad[]={0x04, 0x10, 0x8D, 0xE2, 0x04, 0x00, 0xA0, 0xE1};
|
|
|
|
|
2017-08-22 10:11:31 +00:00
|
|
|
struct defpatch patch_v7r22={sigburn_v7r22, sizeof(sigburn_v7r22), -37};
|
2017-09-14 14:57:34 +00:00
|
|
|
struct defpatch patch_v7r22_2={sigburn_v7r22_2, sizeof(sigburn_v7r22_2), 0};
|
2019-07-03 11:34:51 +00:00
|
|
|
struct defpatch patch_v7r22_3={sigburn_v7r22_3, sizeof(sigburn_v7r22_3), 0};
|
2016-09-26 17:25:22 +00:00
|
|
|
struct defpatch patch_v7r11={sigburn_v7r11, sizeof(sigburn_v7r11), 4};
|
|
|
|
struct defpatch patch_v7r2={sigburn_v7r2, sizeof(sigburn_v7r2), 16};
|
2016-10-07 19:22:14 +00:00
|
|
|
struct defpatch patch_v7r1={sigburn_v7r1, sizeof(sigburn_v7r1), 0};
|
2016-09-26 17:25:22 +00:00
|
|
|
struct defpatch patch_erasebad={sigbad, sizeof(sigbad), 0};
|
|
|
|
|
|
|
|
|
|
|
|
//****************************************************
|
|
|
|
//* Процедуры патча под разные чипсеты и задачи
|
|
|
|
//****************************************************
|
|
|
|
|
2017-08-22 10:11:31 +00:00
|
|
|
uint32_t pv7r2 (uint8_t* buf, uint32_t fsize) { return patch(patch_v7r2, buf, fsize,0); }
|
|
|
|
uint32_t pv7r11 (uint8_t* buf, uint32_t fsize) { return patch(patch_v7r11, buf, fsize,0); }
|
|
|
|
uint32_t pv7r1 (uint8_t* buf, uint32_t fsize) { return patch(patch_v7r1, buf, fsize,0); }
|
|
|
|
uint32_t pv7r22 (uint8_t* buf, uint32_t fsize) { return patch(patch_v7r22, buf, fsize,1); }
|
2017-09-14 14:57:34 +00:00
|
|
|
uint32_t pv7r22_2 (uint8_t* buf, uint32_t fsize) { return patch(patch_v7r22_2, buf, fsize,0); }
|
2019-07-03 11:34:51 +00:00
|
|
|
uint32_t pv7r22_3 (uint8_t* buf, uint32_t fsize) { return patch(patch_v7r22_3, buf, fsize,0); }
|
2017-08-22 10:11:31 +00:00
|
|
|
uint32_t perasebad (uint8_t* buf, uint32_t fsize) { return patch(patch_erasebad, buf, fsize,0); }
|
2016-09-26 17:25:22 +00:00
|
|
|
|