Advertisement
goroh_kun

nandinfocalcのソースコード

Jan 20th, 2012
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. // s_protect_info search by cielavenir
  2. // modified by goroh_kun (2011/11/23)
  3.  
  4. #include <stdio.h>
  5. #include <stdint.h>
  6. #include <unistd.h>
  7. #include <fcntl.h>
  8. #include <linux/ioctl.h>
  9.  
  10. typedef struct{
  11. uint64_t start;
  12. uint64_t end;
  13. uint32_t flg;
  14. } msm_nand_protect_area_info;
  15.  
  16. unsigned int read32(const void *p){
  17. const unsigned char *x=(const unsigned char*)p;
  18. return x[0]|(x[1]<<8)|(x[2]<<16)|(x[3]<<24);
  19. }
  20.  
  21. const unsigned int SIZE=0x1000000; //16MB
  22. int main(const int argc, const char **argv){
  23. char *file;
  24. unsigned char *mem;
  25. FILE *f;
  26.  
  27. if(argc<2){fprintf(stderr,"nandinfo calc [boot|recovery]\n");return 1;}
  28. if(!strcmp(argv[1],"boot"))file="/dev/ubi1_0";
  29. else if(!strcmp(argv[1],"recovery"))file="/dev/ubi2_0";
  30. else{fprintf(stderr,"boot or recovery\n");return 2;}
  31.  
  32. fprintf(stderr,"Opening %s... ",file);
  33. f=fopen(file,"rb");
  34. if(!f){fprintf(stderr,"Failed. non-root?\n");return 3;}
  35. fprintf(stderr,"Done.\n");
  36.  
  37. fprintf(stderr,"Reading... ");
  38. mem=(unsigned char*)calloc(1,SIZE);
  39. if(!mem){fprintf(stderr,"cannot alloc memory.\n");fclose(f);return 4;}
  40. fread(mem,1,SIZE,f);
  41. fclose(f);
  42. fprintf(stderr,"Done.\n");
  43.  
  44. fprintf(stderr,"Searching...\n");
  45. {
  46. unsigned int i=0,x=0;
  47. void *p=NULL;
  48. for(;i<SIZE-100;i+=4){
  49. if(
  50. mem[i+ 3]==0xe5&&mem[i+ 2]==0x9f && // ldr r*,=immediate
  51. mem[i+ 7]==0xe3&&mem[i+ 6]==0xa0&&mem[i+ 5]==0x10&&mem[i+ 4]==0x48 && // mov r1,#0x48
  52. mem[i+11]==0xe5&&(mem[i+10]&0xf0)==0x90 // ldr ...
  53. ){
  54. //fprintf(stderr,"%08x\n",i);
  55. //if(p){fprintf(stderr,"multiple hits (%p)\n");free(mem);return 10;}
  56. x=((mem[i+1]&0x0f)<<8)|mem[i];
  57. p=(void*)read32(mem+i+x+8);
  58. fprintf(stderr,"0x%08x\n",p);
  59. }
  60. }
  61. free(mem);
  62. if(!p){fprintf(stderr,"no hits (search error)\n");return 11;}
  63. fprintf(stderr,"found: 0x%08x.\n",p);
  64. return 0;
  65. }
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement