Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // s_protect_info search by cielavenir
- // modified by goroh_kun (2011/11/23)
- #include <stdio.h>
- #include <stdint.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <linux/ioctl.h>
- typedef struct{
- uint64_t start;
- uint64_t end;
- uint32_t flg;
- } msm_nand_protect_area_info;
- unsigned int read32(const void *p){
- const unsigned char *x=(const unsigned char*)p;
- return x[0]|(x[1]<<8)|(x[2]<<16)|(x[3]<<24);
- }
- const unsigned int SIZE=0x1000000; //16MB
- int main(const int argc, const char **argv){
- char *file;
- unsigned char *mem;
- FILE *f;
- if(argc<2){fprintf(stderr,"nandinfo calc [boot|recovery]\n");return 1;}
- if(!strcmp(argv[1],"boot"))file="/dev/ubi1_0";
- else if(!strcmp(argv[1],"recovery"))file="/dev/ubi2_0";
- else{fprintf(stderr,"boot or recovery\n");return 2;}
- fprintf(stderr,"Opening %s... ",file);
- f=fopen(file,"rb");
- if(!f){fprintf(stderr,"Failed. non-root?\n");return 3;}
- fprintf(stderr,"Done.\n");
- fprintf(stderr,"Reading... ");
- mem=(unsigned char*)calloc(1,SIZE);
- if(!mem){fprintf(stderr,"cannot alloc memory.\n");fclose(f);return 4;}
- fread(mem,1,SIZE,f);
- fclose(f);
- fprintf(stderr,"Done.\n");
- fprintf(stderr,"Searching...\n");
- {
- unsigned int i=0,x=0;
- void *p=NULL;
- for(;i<SIZE-100;i+=4){
- if(
- mem[i+ 3]==0xe5&&mem[i+ 2]==0x9f && // ldr r*,=immediate
- mem[i+ 7]==0xe3&&mem[i+ 6]==0xa0&&mem[i+ 5]==0x10&&mem[i+ 4]==0x48 && // mov r1,#0x48
- mem[i+11]==0xe5&&(mem[i+10]&0xf0)==0x90 // ldr ...
- ){
- //fprintf(stderr,"%08x\n",i);
- //if(p){fprintf(stderr,"multiple hits (%p)\n");free(mem);return 10;}
- x=((mem[i+1]&0x0f)<<8)|mem[i];
- p=(void*)read32(mem+i+x+8);
- fprintf(stderr,"0x%08x\n",p);
- }
- }
- free(mem);
- if(!p){fprintf(stderr,"no hits (search error)\n");return 11;}
- fprintf(stderr,"found: 0x%08x.\n",p);
- return 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement