daily pastebin goal
12%
SHARE
TWEET

Untitled

a guest Jan 13th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ========================================
  2. // 將有 記憶體禁訪 失敗問題
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. // ======================================
  8. #define FFLUSH() {while(getchar()!='\n');}
  9. #define YES 'y'
  10. #define NO 'n'
  11.  
  12. // ======================================
  13. // typedef variable
  14. typedef unsigned char       byte;
  15. typedef unsigned short      ushort;
  16. typedef unsigned int        uint;
  17. typedef unsigned long long  ulong;
  18.  
  19. typedef unsigned char       *addr1;
  20. typedef unsigned short      *addr2;
  21. typedef /*unsigned*/ int    *addr4;
  22. typedef unsigned long long  *addr8;
  23.  
  24.  
  25. // ======================================
  26. // global variable , save for key address
  27. #define MAX 2000
  28. #define LOW 0x00010000
  29. #define UP  0x7fffffff
  30. addr4 addr_rec[MAX]={NULL};
  31.  
  32. // ======================================
  33. // show addr_rec
  34. void show_addr()
  35. {
  36.     uint i=0;
  37.     addr4 ptr=addr_rec[0];
  38.     while(ptr!=NULL){
  39.        printf("%x:%8x(%d)\n",ptr, *ptr, *ptr);
  40.        ++ptr;
  41.     }
  42. }
  43.  
  44. // ======================================
  45. // search for target
  46. void search_target(int target)
  47. {
  48.     static int first = 1; // first to find
  49.     static int cur_cnt=0; // the addr_rec's count
  50.     uint i=0, cur_cnt2=0;
  51.     addr4 ptr=(addr4)LOW;
  52.  
  53.     if(first){
  54.        while(ptr!=(addr4)UP && cur_cnt!=MAX){        
  55.           if(*ptr==target) {             
  56.              addr_rec[cur_cnt] = ptr, ++cur_cnt;
  57.           }
  58.           ++ptr;
  59.           printf("%u\n", cur_cnt);
  60.        }
  61.     }    
  62. }
  63.  
  64. // ======================================
  65. // main function
  66. int main()
  67. {
  68.     int target=0;
  69.     char again=NO;
  70.  
  71.     do{
  72.        printf("input target:");
  73.        scanf("%d", &target);
  74.        search_target(target);
  75.        show_addr();
  76.  
  77.        printf("search again(y to again)? ");
  78.        again = getchar();
  79.        FFLUSH();
  80.     }while(again==YES);
  81.     return 0;
  82. }
RAW Paste Data
Top