⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtkfilenamelenpatcheryamadabellyakumo.c

📁 不知如何使用,哪个会用的指教一下,谢谢QQ547873739
💻 C
字号:


#include <stdio.h>

// ----------------------------------------------------------------------------------------

unsigned char patternScrollBar [] = { 0x74, 0x01, 0xF0, 0xA3, 0x74, 0x50, 0xF0, 0x90 };
unsigned int  sizeScrollBar = 8;

unsigned char patternSelectionBar [] = { 0x00, 0x1A, 0x00, 0x3E, 0x01, 0x36, 0x00, 0x5C, 0x00, 0x1A, 0x00, 0x5E, 0x01, 0x36, 0x00, 0x7C };
unsigned int  sizeSelectionBar = 16;

unsigned char patternListClearing [] = { 0x7B, 0x1E, 0x7A, 0x00, 0x7D, 0x1C, 0x7C, 0x01, 0x7F, 0x0E };
unsigned int  sizeListClearing = 10;

unsigned char patternListClearingYakumo [] = { 0x7B, 0x1E, 0x7A, 0x00, 0x7D, 0x1C, 0x7C, 0x01, 0x7F, 0x0F };
unsigned int  sizeListClearingYakumo = 10;

unsigned char patternListClearingBell [] = { 0x7F, 0x0E, 0x7D, 0x1C, 0x7C, 0x01, 0x7B, 0x1E, 0x7A, 0x00 };
unsigned int  sizeListClearingBell = 10;

unsigned char patternFileNameSize [] = { 0xD3, 0x94, 0x0E, 0x40, 0x03, 0x74, 0x0E, 0xF0 };
unsigned int  sizeFileNameSize = 8;

// ----------------------------------------------------------------------------------------

char* outputFileName = "MTK-modifiedFileBrowser.BIN";
unsigned char *mem;
FILE *inputFileHandle, *outputFileHandle;
size_t inputFileLength, bytesRead;

unsigned short scrollX2 = 586;
unsigned short selBarX2 = 578;
unsigned char sFilenameLen = 42;

char errorList[][80] = {
   "Failed to read input file %s",                                                                                                         // 1
   "Can't allocate enough memory to load file %s",                                                                // 2
   "Not all sections found - cannot patch, sorry."                                                                // 3
   };

unsigned char getHighByte(unsigned short value)
{
                return value / 0x100;
}

unsigned char getLowByte(unsigned short value)
{
                return value % 0x100;
}

int findOffset(int startOffset, unsigned char * pattern, unsigned int patternSize)
{
        int i, j, eqFlag;

        for (i=startOffset; i < inputFileLength; i++)
        {
                eqFlag = 1;
                for (j=0; j < patternSize; j++)
                {
// printf("comparing %x and %x\n", pattern[j], mem[i+j]);
                        if (pattern[j] != mem[i+j])
                        {
                                eqFlag = 0;
                                break;
                        }
                }
                if (eqFlag)
                {
                        return i;
                }
        }
        return -1;
}

void patchByte(int offset, unsigned char byte)
{
        if (mem[offset] != byte)
        {
                printf(" patched at %06x: %02x => %02x\n", offset, mem[offset], byte);
                mem[offset] = byte;
        }
}

// ----- Clean up memory and close files -----
void cleanUp()
{
   if (mem)                free(mem);
   if (inputFileHandle)                fclose(inputFileHandle);
   if (outputFileHandle)        fclose(outputFileHandle);
}

// ----- Exit with given error number & message -----
void exitOnErrorText(int errorNum, char* text)
{
   cleanUp();

   printf("\nERROR: ");
   printf(errorList[errorNum-1], text);
   printf("\n");
   exit(errorNum);
}

// ----- write the packed version of converted file -----
void writeFile(char* fileName)
{
        FILE *outHandle;
        outHandle = fopen(fileName, "wb");
        fwrite(mem, 1, inputFileLength, outHandle);
        fclose(outHandle);
}

// ----- Open the input file -----
void openInputFile(char* fileName)
{
   int i;
   // Open, check size, allocate memory and read input file
   inputFileHandle = fopen(fileName, "rb");
   if (!inputFileHandle)                                        {exitOnErrorText(1, fileName);}

   if (fseek(inputFileHandle, 0, SEEK_END))        {exitOnErrorText(1, fileName);}

   inputFileLength = (size_t)ftell(inputFileHandle);
   if (fseek(inputFileHandle, 0, SEEK_SET))        {exitOnErrorText(1, fileName);}

   mem = (unsigned char*) malloc(inputFileLength);
   if (!mem)                                        {exitOnErrorText(2, fileName);}

   bytesRead = fread(mem, sizeof(unsigned char), inputFileLength, inputFileHandle);
   if (bytesRead != inputFileLength)                {exitOnErrorText(1, fileName);}

}

// Main routine ----------------------------------------------------------------

int main(int argc, char *argv[])
{
   int offset, i, patches = 0;
   int patchedScrollBar=0,patchedSelectionBar=0,patchedListClearing=0,patchedListClearingYakumo=0,patchedListClearingBell=0,patchedFileNameSize=0;

   printf("\n     MTK file browser patcher v0.2 (c) borus a.k.a cax and fix bei fualex");
   printf("\n  ----------------------------------------------------------------------------");
   printf("\n 				 (many thanks to OpenMTK group for patching info secrets)");
   printf("\n");

   // output help hint
   if (argc <= 1)
   {
      printf("\nUsage: %s firmware_filename [[[scrollbar_offset] filename_length] selection_bar_offset]\n", argv[0]);
             exit(1);
   }

   if (argc > 2)
   {
             scrollX2 = atoi(argv[2]);
   }

   if (argc > 3)
   {
             sFilenameLen = atoi(argv[3]);
   }


   if (argc > 4)
   {
             selBarX2 = atoi(argv[4]);
   }

   printf("\nUsing scrollbar at %d(0x%02x),filename len %d(0x%02x),selection bar at %d(0x%02x)\n", scrollX2, scrollX2, sFilenameLen, sFilenameLen, selBarX2, selBarX2);

   // open file
   openInputFile(argv[1]);
   printf("\nOpened firmware file %s, %d bytes\n", argv[1], inputFileLength);

   // start patching
   printf("\nPatching scrollbar position:\n");
   for(offset=0; (offset = findOffset(offset, patternScrollBar, sizeScrollBar)) > 0; offset++)
   {
            if (! (mem[offset+1] == 0x01 && mem[offset+5] == 0x50
                && mem[offset+11]== 0x01 && mem[offset+15]== 0x60))
            {
                        continue;
                }

                patchByte(offset+ 1, getHighByte(scrollX2));
                patchByte(offset+ 5, getLowByte(scrollX2));
                patchByte(offset+11, getHighByte(scrollX2+0x10));
                patchByte(offset+15, getLowByte(scrollX2+0x10));

                patchedScrollBar=1;
   }

   if (! patchedScrollBar)
   {
           printf("\n\tERROR: Can't find scrollbar position section\n");
   }

   printf("\nPatching selection bar size:\n");
   for(offset=0; (offset = findOffset(offset, patternSelectionBar, sizeSelectionBar)) > 0; offset++)
   {
                for (i=0; i<6; i++)
                {
                        patchByte(offset+i*8+4, getHighByte(selBarX2));
                        patchByte(offset+i*8+5, getLowByte(selBarX2));
                }

                patchedSelectionBar=1;
   }


   if (! patchedSelectionBar)
   {
           printf("\n\tERROR: Can't find selection bar section\n");
   }

   printf("\nPatching file list clearing routine for Yamada:\n");
      for(offset=0; (offset = findOffset(offset, patternListClearing, sizeListClearing)) > 0; offset++)
   {
                patchByte(offset+7, getHighByte(selBarX2-0x1A));
                patchByte(offset+5, getLowByte(selBarX2-0x1A));

                patchedListClearing=1;
   }

   if (! patchedListClearing)
   {
           printf("\n\tERROR: Can't find file list clearing routine for Yamada\n");

   }

   if (! patchedListClearing)
   {
      printf("\nPatching file list clearing routine for Bell:\n");
         for(offset=0; (offset = findOffset(offset, patternListClearingBell, sizeListClearingBell)) > 0; offset++)
         {
            patchByte(offset+5, getHighByte(selBarX2-0x1A));
            patchByte(offset+3, getLowByte(selBarX2-0x1A));

            patchedListClearingBell=1;
         }

         if (! patchedListClearingBell)
         {
            printf("\n\tERROR: Can't find file list clearing routine for Bell\n");
         }
   }

      if (! patchedListClearingBell)
   {
      printf("\nPatching file list clearing routine for Yakumo:\n");
         for(offset=0; (offset = findOffset(offset, patternListClearingYakumo, sizeListClearingYakumo)) > 0; offset++)
         {
                patchByte(offset+7, getHighByte(selBarX2-0x1A));
                patchByte(offset+5, getLowByte(selBarX2-0x1A));

            patchedListClearingYakumo=1;
         }

         if (! patchedListClearingYakumo)
         {
            printf("\n\tERROR: Can't find file list clearing routine for Yakumo\n");
         }
   }

   printf("\nPatching file name size:\n");
   for(offset=0; (offset = findOffset(offset, patternFileNameSize, sizeFileNameSize)) > 0; offset++)
   {
                patchByte(offset+2, sFilenameLen);
                patchByte(offset+6, sFilenameLen);

                patchedFileNameSize=1;
   }

   if (! patchedFileNameSize)
   {
           printf("\n\tERROR: Can't find Patching file name size section\n");
   }

   if (patchedScrollBar+patchedSelectionBar+patchedListClearing+patchedFileNameSize != 4 &&
            patchedScrollBar+patchedSelectionBar+patchedListClearingYakumo+patchedFileNameSize != 4 &&
                 patchedScrollBar+patchedSelectionBar+patchedListClearingBell+patchedFileNameSize != 4)
   {
                   exitOnErrorText(3, "");
   }

   writeFile(outputFileName);
   printf("\nUpdated firmware saved to: %s", outputFileName);
   printf("\n");
   printf("\nDON'T FORGET to do the following BEFORE flashing:");
   printf("\n");
   printf("\n replace MPEG Block->MPEG 3 in MTKReMaker with more suitable");
   printf("\n and resave this firmware with corrected checksum.");
   printf("\n Good luck !\n");


   cleanUp();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -